Changeset 5276
- Timestamp:
- 2011-12-16 15:20:48 (17 months ago)
- Location:
- trunk/cr/repository/impl
- Files:
-
- 3 edited
-
pom.xml (modified) (1 diff)
-
src/main/java/org/lilyproject/repository/avro/AvroConverter.java (modified) (21 diffs)
-
src/main/java/org/lilyproject/repository/avro/AvroLilyImpl.java (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/cr/repository/impl/pom.xml
r5247 r5276 126 126 <goal>protocol</goal> 127 127 </goals> 128 <configuration> 129 <stringType>String</stringType> 130 </configuration> 128 131 </execution> 129 132 </executions> 130 133 </plugin> 131 132 <plugin>133 <groupId>com.thoughtworks.paranamer</groupId>134 <artifactId>paranamer-maven-plugin</artifactId>135 <version>2.3</version>136 <executions>137 <execution>138 <id>run</id> <!-- id is optional -->139 <configuration>140 <sourceDirectory>${project.build.directory}/generated-sources/avro</sourceDirectory>141 <outputDirectory>${project.build.directory}/classes</outputDirectory>142 </configuration>143 <goals>144 <goal>generate</goal>145 </goals>146 </execution>147 </executions>148 </plugin>149 150 134 </plugins> 151 135 </build> -
trunk/cr/repository/impl/src/main/java/org/lilyproject/repository/avro/AvroConverter.java
r5267 r5276 22 22 23 23 import org.apache.avro.AvroRemoteException; 24 import org.apache.avro.util.Utf8;25 24 import org.apache.commons.logging.Log; 26 25 import org.apache.commons.logging.LogFactory; … … 61 60 record.setRecordType(recordTypeName, avroRecord.getRecordTypeVersion()); 62 61 63 Map< CharSequence, AvroQName> scopeRecordTypeNames = avroRecord.getScopeRecordTypeNames();62 Map<String, AvroQName> scopeRecordTypeNames = avroRecord.getScopeRecordTypeNames(); 64 63 if (scopeRecordTypeNames != null) { 65 64 for (Scope scope : Scope.values()) { 66 Utf8 key = new Utf8(scope.name());65 String key = scope.name(); 67 66 AvroQName scopeRecordTypeName = scopeRecordTypeNames.get(key); 68 67 if (scopeRecordTypeName != null) { … … 76 75 for (AvroField field : avroRecord.getFields()) { 77 76 QName name = convert(field.getName()); 78 ValueType valueType = typeManager.getValueType( convert(field.getValueType()));77 ValueType valueType = typeManager.getValueType(field.getValueType()); 79 78 Object value = valueType.read(field.getValue().array()); 80 79 record.setField(name, value); … … 117 116 if (avroIdRecord.getScopeRecordTypeIds() == null) { 118 117 recordTypeIds = new EnumMap<Scope, SchemaId>(Scope.class); 119 Map< CharSequence, AvroSchemaId> avroRecordTypeIds = avroIdRecord.getScopeRecordTypeIds();118 Map<String, AvroSchemaId> avroRecordTypeIds = avroIdRecord.getScopeRecordTypeIds(); 120 119 for (Scope scope : Scope.values()) { 121 recordTypeIds.put(scope, convert(avroRecordTypeIds.get( new Utf8(scope.name()))));120 recordTypeIds.put(scope, convert(avroRecordTypeIds.get(scope.name()))); 122 121 } 123 122 } … … 140 139 Object value = null; 141 140 if (avroCond.getValue() != null) { 142 ValueType valueType = typeManager.getValueType( convert(avroCond.getValueType()));141 ValueType valueType = typeManager.getValueType(avroCond.getValueType()); 143 142 value = valueType.read(avroCond.getValue().array()); 144 143 } … … 178 177 avroRecord.setRecordTypeVersion(record.getRecordTypeVersion()); 179 178 } 180 avroRecord.setScopeRecordTypeNames(new HashMap< CharSequence, AvroQName>());181 avroRecord.setScopeRecordTypeVersions(new HashMap< CharSequence, Long>());179 avroRecord.setScopeRecordTypeNames(new HashMap<String, AvroQName>()); 180 avroRecord.setScopeRecordTypeVersions(new HashMap<String, Long>()); 182 181 for (Scope scope : Scope.values()) { 183 182 QName recordTypeName = record.getRecordTypeName(scope); 184 183 if (recordTypeName != null) { 185 avroRecord.getScopeRecordTypeNames().put( new Utf8(scope.name()), convert(recordTypeName));184 avroRecord.getScopeRecordTypeNames().put(scope.name(), convert(recordTypeName)); 186 185 Long version = record.getRecordTypeVersion(scope); 187 186 if (version != null) { 188 avroRecord.getScopeRecordTypeVersions().put( new Utf8(scope.name()), version);187 avroRecord.getScopeRecordTypeVersions().put(scope.name(), version); 189 188 } 190 189 } … … 248 247 249 248 // Record types 250 avroIdRecord.setScopeRecordTypeIds(new HashMap< CharSequence, AvroSchemaId>());249 avroIdRecord.setScopeRecordTypeIds(new HashMap<String, AvroSchemaId>()); 251 250 for (Scope scope : Scope.values()) { 252 251 SchemaId recordTypeId = idRecord.getRecordTypeId(scope); 253 252 if (recordTypeId != null) { 254 avroIdRecord.getScopeRecordTypeIds().put( new Utf8(scope.name()), convert(recordTypeId));253 avroIdRecord.getScopeRecordTypeIds().put(scope.name(), convert(recordTypeId)); 255 254 } 256 255 } … … 287 286 if (condition.getValue() != null) { 288 287 ValueType valueType = fieldType.getValueType(); 289 avroCond.setValueType( convert(valueType.getName()));288 avroCond.setValueType(valueType.getName()); 290 289 291 290 byte[] value = valueType.toBytes(condition.getValue(), parentRecords); … … 427 426 public TypeBucket convertAvroTypeBucket(AvroTypeBucket avroTypeBucket) throws RepositoryException, 428 427 InterruptedException { 429 TypeBucket typeBucket = new TypeBucket( convert(avroTypeBucket.getBucketId()));428 TypeBucket typeBucket = new TypeBucket(avroTypeBucket.getBucketId()); 430 429 for (AvroFieldType avroFieldType : avroTypeBucket.getFieldTypes()) { 431 430 typeBucket.add(convert(avroFieldType)); … … 438 437 439 438 public ValueType convert(AvroValueType valueType) throws RepositoryException, InterruptedException { 440 return valueType == null ? null : typeManager.getValueType( convert(valueType.getValueType()));439 return valueType == null ? null : typeManager.getValueType(valueType.getValueType()); 441 440 } 442 441 … … 446 445 447 446 AvroValueType avroValueType = new AvroValueType(); 448 avroValueType.setValueType( convert(valueType.getName()));447 avroValueType.setValueType(valueType.getName()); 449 448 return avroValueType; 450 449 } … … 453 452 if (name == null) 454 453 return null; 455 return new QName( convert(name.getNamespace()), convert(name.getName()));454 return new QName(name.getNamespace(), name.getName()); 456 455 } 457 456 … … 508 507 avroRepositoryException.setRemoteCauses(buildCauses(exception)); 509 508 avroRepositoryException.setExceptionClass(exception.getClass().getName()); 510 Map<String, String> params = exception.getState(); 511 if (params != null) { 512 avroRepositoryException.setParams(new HashMap<CharSequence, CharSequence>()); 513 avroRepositoryException.getParams().putAll(params); 514 } 509 avroRepositoryException.setParams(exception.getState()); 515 510 return avroRepositoryException; 516 511 } … … 518 513 public RepositoryException convert(AvroRepositoryException avroException) { 519 514 try { 520 Class exceptionClass = Class.forName( convert(avroException.getExceptionClass()));515 Class exceptionClass = Class.forName(avroException.getExceptionClass()); 521 516 Constructor constructor = exceptionClass.getConstructor(String.class, Map.class); 522 517 RepositoryException repositoryException = (RepositoryException)constructor.newInstance( 523 convert(avroException.getMessage$()), avroMapToStringMap(avroException.getParams()));518 avroException.getMessage$(), avroException.getParams()); 524 519 restoreCauses(avroException.getRemoteCauses(), repositoryException); 525 520 return repositoryException; … … 527 522 log.error("Failure while converting remote exception", e); 528 523 } 529 RepositoryException repositoryException = new RepositoryException( convert(avroException.getMessage$()));524 RepositoryException repositoryException = new RepositoryException(avroException.getMessage$()); 530 525 restoreCauses(avroException.getRemoteCauses(), repositoryException); 531 526 return repositoryException; 532 }533 534 private Map<String, String> avroMapToStringMap(Map<CharSequence, CharSequence> map) {535 if (map == null) {536 return null;537 }538 539 Map<String, String> result = new HashMap<String, String>();540 for (Map.Entry<CharSequence, CharSequence> entry : map.entrySet()) {541 result.put(convert(entry.getKey()), convert(entry.getValue()));542 }543 return result;544 527 } 545 528 … … 562 545 } 563 546 564 public String convert(CharSequence charSeq) {565 if (charSeq == null) return null;566 return charSeq.toString();567 }568 569 547 public Long convertAvroVersion(long avroVersion) { 570 548 if (avroVersion == -1) … … 594 572 private AvroExceptionCause convertCause(Throwable throwable) { 595 573 AvroExceptionCause cause = new AvroExceptionCause(); 596 cause.setClassName( convert(throwable.getClass().getName()));597 cause.setMessage( convert(throwable.getMessage()));574 cause.setClassName(throwable.getClass().getName()); 575 cause.setMessage(throwable.getMessage()); 598 576 599 577 StackTraceElement[] stackTrace = throwable.getStackTrace(); … … 610 588 private AvroStackTraceElement convert(StackTraceElement el) { 611 589 AvroStackTraceElement result = new AvroStackTraceElement(); 612 result.setClassName( convert(el.getClassName()));613 result.setMethodName( convert(el.getMethodName()));614 result.setFileName( convert(el.getFileName()));590 result.setClassName(el.getClassName()); 591 result.setMethodName(el.getMethodName()); 592 result.setFileName(el.getFileName()); 615 593 result.setLineNumber(el.getLineNumber()); 616 594 return result; … … 631 609 632 610 for (AvroStackTraceElement el : remoteCause.getStackTrace()) { 633 stackTrace.add(new StackTraceElement( convert(el.getClassName()), convert(el.getMethodName()),634 convert(el.getFileName()), el.getLineNumber()));635 } 636 637 RestoredException cause = new RestoredException( convert(remoteCause.getMessage()),638 convert(remoteCause.getClassName()), stackTrace);611 stackTrace.add(new StackTraceElement(el.getClassName(), el.getMethodName(), 612 el.getFileName(), el.getLineNumber())); 613 } 614 615 RestoredException cause = new RestoredException(remoteCause.getMessage(), 616 remoteCause.getClassName(), stackTrace); 639 617 640 618 if (result == null) { … … 697 675 } 698 676 699 public Set<RecordId> convertAvroRecordIds(List< CharSequence> avroRecordIds) {677 public Set<RecordId> convertAvroRecordIds(List<String> avroRecordIds) { 700 678 Set<RecordId> recordIds = new HashSet<RecordId>(); 701 679 IdGenerator idGenerator = repository.getIdGenerator(); 702 for ( CharSequenceavroRecordId : avroRecordIds) {703 recordIds.add(idGenerator.fromString( convert(avroRecordId)));680 for (String avroRecordId : avroRecordIds) { 681 recordIds.add(idGenerator.fromString(avroRecordId)); 704 682 } 705 683 return recordIds; 706 684 } 707 685 708 public List< CharSequence> convert(Set<RecordId> recordIds) {709 List< CharSequence> avroRecordIds = new ArrayList<CharSequence>(recordIds.size());686 public List<String> convert(Set<RecordId> recordIds) { 687 List<String> avroRecordIds = new ArrayList<String>(recordIds.size()); 710 688 for (RecordId recordId: recordIds) { 711 689 avroRecordIds.add(recordId.toString()); … … 743 721 return names; 744 722 } 745 746 public List<String> convert(List<CharSequence> charSequences) {747 if (charSequences == null)748 return null;749 List<String> result = new ArrayList<String>(charSequences.size());750 for (CharSequence charSequence : charSequences) {751 result.add(convert(charSequence));752 }753 return result;754 }755 756 public List<CharSequence> convertStrings(List<String> strings) {757 if (strings == null)758 return null;759 List<CharSequence> result = new ArrayList<CharSequence>(strings.size());760 for (String string : strings) {761 result.add(string);762 }763 return result;764 }765 723 } -
trunk/cr/repository/impl/src/main/java/org/lilyproject/repository/avro/AvroLilyImpl.java
r5179 r5276 35 35 } 36 36 37 @Override 37 38 public AvroRecord create(AvroRecord record) throws AvroRepositoryException, AvroInterruptedException { 38 39 try { … … 45 46 } 46 47 48 @Override 47 49 public AvroRecord createOrUpdate(AvroRecord record, boolean useLatestRecordType) 48 50 throws AvroRepositoryException, AvroInterruptedException { … … 69 71 } 70 72 73 @Override 71 74 public AvroRecord read(ByteBuffer avroRecordId, long avroVersion, List<AvroQName> avroFieldNames) 72 75 throws AvroRepositoryException, AvroInterruptedException { … … 86 89 } 87 90 } 88 91 92 @Override 89 93 public List<AvroRecord> readRecords(List<ByteBuffer> avroRecordIds, List<AvroQName> avroFieldNames) 90 94 throws AvroRepositoryException, AvroInterruptedException { … … 105 109 } 106 110 111 @Override 107 112 public List<AvroRecord> readVersions(ByteBuffer recordId, long avroFromVersion, long avroToVersion, 108 113 List<AvroQName> avroFieldNames) throws AvroRepositoryException, AvroInterruptedException { … … 116 121 } 117 122 } 118 123 124 @Override 119 125 public List<AvroRecord> readSpecificVersions(ByteBuffer recordId, List<Long> avroVersions, 120 126 List<AvroQName> avroFieldNames) throws AvroRepositoryException, AvroInterruptedException { … … 145 151 } 146 152 153 @Override 147 154 public AvroFieldType createFieldType(AvroFieldType avroFieldType) throws AvroRepositoryException, AvroInterruptedException { 148 155 … … 156 163 } 157 164 165 @Override 158 166 public AvroRecordType createRecordType(AvroRecordType avroRecordType) throws AvroRepositoryException, AvroInterruptedException { 159 167 … … 180 188 } 181 189 190 @Override 182 191 public AvroRecordType getRecordTypeById(AvroSchemaId id, long avroVersion) throws AvroRepositoryException, AvroInterruptedException { 183 192 try { … … 190 199 } 191 200 201 @Override 192 202 public AvroRecordType getRecordTypeByName(AvroQName name, long avroVersion) throws AvroRepositoryException, AvroInterruptedException { 193 203 try { … … 200 210 } 201 211 212 @Override 202 213 public AvroRecordType updateRecordType(AvroRecordType recordType) throws AvroRepositoryException, AvroInterruptedException { 203 214 … … 211 222 } 212 223 224 @Override 213 225 public AvroFieldType updateFieldType(AvroFieldType fieldType) throws AvroRepositoryException, AvroInterruptedException { 214 226 … … 235 247 } 236 248 249 @Override 237 250 public AvroFieldType getFieldTypeById(AvroSchemaId id) throws AvroRepositoryException, AvroInterruptedException { 238 251 try { … … 245 258 } 246 259 260 @Override 247 261 public AvroFieldType getFieldTypeByName(AvroQName name) throws AvroRepositoryException, AvroInterruptedException { 248 262 try { … … 255 269 } 256 270 271 @Override 257 272 public List<AvroFieldType> getFieldTypes() throws AvroRepositoryException, AvroInterruptedException { 258 273 try { … … 265 280 } 266 281 282 @Override 267 283 public List<AvroRecordType> getRecordTypes() throws AvroRepositoryException, AvroInterruptedException { 268 284 try { … … 274 290 } 275 291 } 276 292 293 @Override 277 294 public List<AvroFieldType> getFieldTypesWithoutCache() throws AvroRepositoryException, AvroInterruptedException { 278 295 try { … … 285 302 } 286 303 304 @Override 287 305 public List<AvroRecordType> getRecordTypesWithoutCache() throws AvroRepositoryException, AvroInterruptedException { 288 306 try { … … 295 313 } 296 314 315 @Override 297 316 public AvroFieldAndRecordTypes getTypesWithoutCache() 298 317 throws AvroRepositoryException, … … 307 326 } 308 327 309 public AvroTypeBucket getTypeBucketWithoutCache(CharSequence bucketId) 328 @Override 329 public AvroTypeBucket getTypeBucketWithoutCache(String bucketId) 310 330 throws AvroRepositoryException, AvroInterruptedException { 311 331 try { 312 TypeBucket typeBucket = typeManager.getTypeBucketWithoutCache( converter.convert(bucketId));332 TypeBucket typeBucket = typeManager.getTypeBucketWithoutCache(bucketId); 313 333 return converter.convertTypeBucket(typeBucket); 314 334 } catch (RepositoryException e) { … … 319 339 } 320 340 321 public List<CharSequence> getVariants(ByteBuffer recordId) throws AvroRepositoryException, AvroInterruptedException { 341 @Override 342 public List<String> getVariants(ByteBuffer recordId) throws AvroRepositoryException, AvroInterruptedException { 322 343 try { 323 344 return converter.convert(repository.getVariants(converter.convertAvroRecordId(recordId))); … … 329 350 } 330 351 352 @Override 331 353 public AvroIdRecord readWithIds(ByteBuffer recordId, long avroVersion, List<AvroSchemaId> avroFieldIds) 332 354 throws AvroRepositoryException, AvroInterruptedException {
Note: See TracChangeset
for help on using the changeset viewer.