Changeset 5276


Ignore:
Timestamp:
2011-12-16 15:20:48 (17 months ago)
Author:
bruno
Message:

Let Avro generate Java classes that use String instead of CharSequence?.

This is a new option to the Avro schema compiler (and maven plugin) in Avro 1.6. This makes things easier and more efficient for us, as we needed strings anyway (and maps were difficult with charsequence keys).
Meanwhile removed the paranamer maven plugin, iirc that was once needed by avro but not anymore.

Location:
trunk/cr/repository/impl
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/cr/repository/impl/pom.xml

    r5247 r5276  
    126126              <goal>protocol</goal> 
    127127            </goals> 
     128            <configuration> 
     129              <stringType>String</stringType> 
     130            </configuration> 
    128131          </execution> 
    129132        </executions> 
    130133      </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  
    150134    </plugins> 
    151135  </build> 
  • trunk/cr/repository/impl/src/main/java/org/lilyproject/repository/avro/AvroConverter.java

    r5267 r5276  
    2222 
    2323import org.apache.avro.AvroRemoteException; 
    24 import org.apache.avro.util.Utf8; 
    2524import org.apache.commons.logging.Log; 
    2625import org.apache.commons.logging.LogFactory; 
     
    6160        record.setRecordType(recordTypeName, avroRecord.getRecordTypeVersion()); 
    6261          
    63         Map<CharSequence, AvroQName> scopeRecordTypeNames = avroRecord.getScopeRecordTypeNames(); 
     62        Map<String, AvroQName> scopeRecordTypeNames = avroRecord.getScopeRecordTypeNames(); 
    6463        if (scopeRecordTypeNames != null) { 
    6564            for (Scope scope : Scope.values()) { 
    66                 Utf8 key = new Utf8(scope.name()); 
     65                String key = scope.name(); 
    6766                AvroQName scopeRecordTypeName = scopeRecordTypeNames.get(key); 
    6867                if (scopeRecordTypeName != null) { 
     
    7675            for (AvroField field : avroRecord.getFields()) { 
    7776                QName name = convert(field.getName()); 
    78                 ValueType valueType = typeManager.getValueType(convert(field.getValueType())); 
     77                ValueType valueType = typeManager.getValueType(field.getValueType()); 
    7978                Object value = valueType.read(field.getValue().array()); 
    8079                record.setField(name, value); 
     
    117116        if (avroIdRecord.getScopeRecordTypeIds() == null) { 
    118117            recordTypeIds = new EnumMap<Scope, SchemaId>(Scope.class); 
    119             Map<CharSequence, AvroSchemaId> avroRecordTypeIds = avroIdRecord.getScopeRecordTypeIds(); 
     118            Map<String, AvroSchemaId> avroRecordTypeIds = avroIdRecord.getScopeRecordTypeIds(); 
    120119            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()))); 
    122121            } 
    123122        } 
     
    140139            Object value = null; 
    141140            if (avroCond.getValue() != null) { 
    142                 ValueType valueType = typeManager.getValueType(convert(avroCond.getValueType())); 
     141                ValueType valueType = typeManager.getValueType(avroCond.getValueType()); 
    143142                value = valueType.read(avroCond.getValue().array()); 
    144143            } 
     
    178177            avroRecord.setRecordTypeVersion(record.getRecordTypeVersion()); 
    179178        } 
    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>()); 
    182181        for (Scope scope : Scope.values()) { 
    183182            QName recordTypeName = record.getRecordTypeName(scope); 
    184183            if (recordTypeName != null) { 
    185                 avroRecord.getScopeRecordTypeNames().put(new Utf8(scope.name()), convert(recordTypeName)); 
     184                avroRecord.getScopeRecordTypeNames().put(scope.name(), convert(recordTypeName)); 
    186185                Long version = record.getRecordTypeVersion(scope); 
    187186                if (version != null) { 
    188                     avroRecord.getScopeRecordTypeVersions().put(new Utf8(scope.name()), version); 
     187                    avroRecord.getScopeRecordTypeVersions().put(scope.name(), version); 
    189188                } 
    190189            } 
     
    248247 
    249248        // Record types 
    250         avroIdRecord.setScopeRecordTypeIds(new HashMap<CharSequence, AvroSchemaId>()); 
     249        avroIdRecord.setScopeRecordTypeIds(new HashMap<String, AvroSchemaId>()); 
    251250        for (Scope scope : Scope.values()) { 
    252251            SchemaId recordTypeId = idRecord.getRecordTypeId(scope); 
    253252            if (recordTypeId != null) { 
    254                 avroIdRecord.getScopeRecordTypeIds().put(new Utf8(scope.name()), convert(recordTypeId)); 
     253                avroIdRecord.getScopeRecordTypeIds().put(scope.name(), convert(recordTypeId)); 
    255254            } 
    256255        } 
     
    287286                if (condition.getValue() != null) { 
    288287                    ValueType valueType = fieldType.getValueType(); 
    289                     avroCond.setValueType(convert(valueType.getName())); 
     288                    avroCond.setValueType(valueType.getName()); 
    290289 
    291290                    byte[] value = valueType.toBytes(condition.getValue(), parentRecords); 
     
    427426    public TypeBucket convertAvroTypeBucket(AvroTypeBucket avroTypeBucket) throws RepositoryException, 
    428427            InterruptedException { 
    429         TypeBucket typeBucket = new TypeBucket(convert(avroTypeBucket.getBucketId())); 
     428        TypeBucket typeBucket = new TypeBucket(avroTypeBucket.getBucketId()); 
    430429        for (AvroFieldType avroFieldType : avroTypeBucket.getFieldTypes()) { 
    431430            typeBucket.add(convert(avroFieldType)); 
     
    438437 
    439438    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()); 
    441440    } 
    442441 
     
    446445 
    447446        AvroValueType avroValueType = new AvroValueType(); 
    448         avroValueType.setValueType(convert(valueType.getName())); 
     447        avroValueType.setValueType(valueType.getName()); 
    449448        return avroValueType; 
    450449    } 
     
    453452        if (name == null) 
    454453            return null; 
    455         return new QName(convert(name.getNamespace()), convert(name.getName())); 
     454        return new QName(name.getNamespace(), name.getName()); 
    456455    } 
    457456 
     
    508507        avroRepositoryException.setRemoteCauses(buildCauses(exception)); 
    509508        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()); 
    515510        return avroRepositoryException; 
    516511    } 
     
    518513    public RepositoryException convert(AvroRepositoryException avroException) { 
    519514        try { 
    520             Class exceptionClass = Class.forName(convert(avroException.getExceptionClass())); 
     515            Class exceptionClass = Class.forName(avroException.getExceptionClass()); 
    521516            Constructor constructor = exceptionClass.getConstructor(String.class, Map.class); 
    522517            RepositoryException repositoryException = (RepositoryException)constructor.newInstance( 
    523                     convert(avroException.getMessage$()), avroMapToStringMap(avroException.getParams())); 
     518                    avroException.getMessage$(), avroException.getParams()); 
    524519            restoreCauses(avroException.getRemoteCauses(), repositoryException); 
    525520            return repositoryException; 
     
    527522            log.error("Failure while converting remote exception", e); 
    528523        } 
    529         RepositoryException repositoryException = new RepositoryException(convert(avroException.getMessage$())); 
     524        RepositoryException repositoryException = new RepositoryException(avroException.getMessage$()); 
    530525        restoreCauses(avroException.getRemoteCauses(), repositoryException); 
    531526        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; 
    544527    } 
    545528 
     
    562545    } 
    563546 
    564     public String convert(CharSequence charSeq) { 
    565         if (charSeq == null) return null; 
    566         return charSeq.toString(); 
    567     } 
    568  
    569547    public Long convertAvroVersion(long avroVersion) { 
    570548        if (avroVersion == -1) 
     
    594572    private AvroExceptionCause convertCause(Throwable throwable) { 
    595573        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()); 
    598576 
    599577        StackTraceElement[] stackTrace = throwable.getStackTrace(); 
     
    610588    private AvroStackTraceElement convert(StackTraceElement el) { 
    611589        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()); 
    615593        result.setLineNumber(el.getLineNumber()); 
    616594        return result; 
     
    631609 
    632610            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); 
    639617 
    640618            if (result == null) { 
     
    697675    } 
    698676     
    699     public Set<RecordId> convertAvroRecordIds(List<CharSequence> avroRecordIds) { 
     677    public Set<RecordId> convertAvroRecordIds(List<String> avroRecordIds) { 
    700678        Set<RecordId> recordIds = new HashSet<RecordId>(); 
    701679        IdGenerator idGenerator = repository.getIdGenerator(); 
    702         for (CharSequence avroRecordId : avroRecordIds) { 
    703             recordIds.add(idGenerator.fromString(convert(avroRecordId))); 
     680        for (String avroRecordId : avroRecordIds) { 
     681            recordIds.add(idGenerator.fromString(avroRecordId)); 
    704682        } 
    705683        return recordIds; 
    706684    } 
    707685     
    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()); 
    710688        for (RecordId recordId: recordIds) { 
    711689            avroRecordIds.add(recordId.toString()); 
     
    743721        return names; 
    744722    } 
    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     } 
    765723} 
  • trunk/cr/repository/impl/src/main/java/org/lilyproject/repository/avro/AvroLilyImpl.java

    r5179 r5276  
    3535    } 
    3636 
     37    @Override 
    3738    public AvroRecord create(AvroRecord record) throws AvroRepositoryException, AvroInterruptedException { 
    3839        try { 
     
    4546    } 
    4647 
     48    @Override 
    4749    public AvroRecord createOrUpdate(AvroRecord record, boolean useLatestRecordType) 
    4850            throws AvroRepositoryException, AvroInterruptedException { 
     
    6971    } 
    7072 
     73    @Override 
    7174    public AvroRecord read(ByteBuffer avroRecordId, long avroVersion, List<AvroQName> avroFieldNames) 
    7275            throws AvroRepositoryException, AvroInterruptedException { 
     
    8689        } 
    8790    } 
    88      
     91 
     92    @Override 
    8993    public List<AvroRecord> readRecords(List<ByteBuffer> avroRecordIds, List<AvroQName> avroFieldNames) 
    9094            throws AvroRepositoryException, AvroInterruptedException { 
     
    105109    } 
    106110 
     111    @Override 
    107112    public List<AvroRecord> readVersions(ByteBuffer recordId, long avroFromVersion, long avroToVersion, 
    108113            List<AvroQName> avroFieldNames) throws AvroRepositoryException, AvroInterruptedException { 
     
    116121        } 
    117122    } 
    118      
     123 
     124    @Override 
    119125    public List<AvroRecord> readSpecificVersions(ByteBuffer recordId, List<Long> avroVersions, 
    120126            List<AvroQName> avroFieldNames) throws AvroRepositoryException, AvroInterruptedException { 
     
    145151    } 
    146152 
     153    @Override 
    147154    public AvroFieldType createFieldType(AvroFieldType avroFieldType) throws AvroRepositoryException, AvroInterruptedException { 
    148155 
     
    156163    } 
    157164 
     165    @Override 
    158166    public AvroRecordType createRecordType(AvroRecordType avroRecordType) throws AvroRepositoryException, AvroInterruptedException { 
    159167 
     
    180188    } 
    181189 
     190    @Override 
    182191    public AvroRecordType getRecordTypeById(AvroSchemaId id, long avroVersion) throws AvroRepositoryException, AvroInterruptedException { 
    183192        try { 
     
    190199    } 
    191200 
     201    @Override 
    192202    public AvroRecordType getRecordTypeByName(AvroQName name, long avroVersion) throws AvroRepositoryException, AvroInterruptedException { 
    193203        try { 
     
    200210    } 
    201211 
     212    @Override 
    202213    public AvroRecordType updateRecordType(AvroRecordType recordType) throws AvroRepositoryException, AvroInterruptedException { 
    203214 
     
    211222    } 
    212223 
     224    @Override 
    213225    public AvroFieldType updateFieldType(AvroFieldType fieldType) throws AvroRepositoryException, AvroInterruptedException { 
    214226 
     
    235247    } 
    236248 
     249    @Override 
    237250    public AvroFieldType getFieldTypeById(AvroSchemaId id) throws AvroRepositoryException, AvroInterruptedException { 
    238251        try { 
     
    245258    } 
    246259 
     260    @Override 
    247261    public AvroFieldType getFieldTypeByName(AvroQName name) throws AvroRepositoryException, AvroInterruptedException { 
    248262        try { 
     
    255269    } 
    256270 
     271    @Override 
    257272    public List<AvroFieldType> getFieldTypes() throws AvroRepositoryException, AvroInterruptedException { 
    258273        try { 
     
    265280    } 
    266281 
     282    @Override 
    267283    public List<AvroRecordType> getRecordTypes() throws AvroRepositoryException, AvroInterruptedException { 
    268284        try { 
     
    274290        } 
    275291    } 
    276      
     292 
     293    @Override 
    277294    public List<AvroFieldType> getFieldTypesWithoutCache() throws AvroRepositoryException, AvroInterruptedException { 
    278295        try { 
     
    285302    } 
    286303 
     304    @Override 
    287305    public List<AvroRecordType> getRecordTypesWithoutCache() throws AvroRepositoryException, AvroInterruptedException { 
    288306        try { 
     
    295313    } 
    296314 
     315    @Override 
    297316    public AvroFieldAndRecordTypes getTypesWithoutCache() 
    298317            throws AvroRepositoryException, 
     
    307326    } 
    308327 
    309     public AvroTypeBucket getTypeBucketWithoutCache(CharSequence bucketId) 
     328    @Override 
     329    public AvroTypeBucket getTypeBucketWithoutCache(String bucketId) 
    310330            throws AvroRepositoryException, AvroInterruptedException { 
    311331        try { 
    312             TypeBucket typeBucket = typeManager.getTypeBucketWithoutCache(converter.convert(bucketId)); 
     332            TypeBucket typeBucket = typeManager.getTypeBucketWithoutCache(bucketId); 
    313333            return converter.convertTypeBucket(typeBucket); 
    314334        } catch (RepositoryException e) { 
     
    319339    } 
    320340 
    321     public List<CharSequence> getVariants(ByteBuffer recordId) throws AvroRepositoryException, AvroInterruptedException { 
     341    @Override 
     342    public List<String> getVariants(ByteBuffer recordId) throws AvroRepositoryException, AvroInterruptedException { 
    322343        try { 
    323344            return converter.convert(repository.getVariants(converter.convertAvroRecordId(recordId))); 
     
    329350    } 
    330351 
     352    @Override 
    331353    public AvroIdRecord readWithIds(ByteBuffer recordId, long avroVersion, List<AvroSchemaId> avroFieldIds) 
    332354            throws AvroRepositoryException, AvroInterruptedException { 
Note: See TracChangeset for help on using the changeset viewer.