コード例 #1
0
 private void processRecordField(
     CommonRecord record, GenericRecord deltaRecord, String fieldName) {
   CommonRecord nextRecord = null;
   CommonValue nextValue = record.getField(fieldName);
   if (nextValue != null
       && nextValue.isRecord()
       && nextValue
           .getRecord()
           .getSchema()
           .getFullName()
           .equals(deltaRecord.getSchema().getFullName())) {
     nextRecord = nextValue.getRecord();
     GenericFixed uuidFixed = (GenericFixed) deltaRecord.get(UUID);
     if (uuidFixed != null) {
       UUID uuid = AvroGenericUtils.createUuidFromFixed(uuidFixed);
       // Checking if the uuid was changed
       if (!uuid.equals(nextRecord.getUuid())) {
         records.remove(nextRecord.getUuid());
         records.put(uuid, nextRecord);
         nextRecord.setUuid(uuid);
       }
     }
   } else {
     nextRecord = createCommonRecord(deltaRecord);
     record.setField(fieldName, commonFactory.createCommonValue(nextRecord));
   }
   updateRecord(nextRecord, deltaRecord);
 }
コード例 #2
0
 private void processArrayField(CommonRecord record, GenericArray array, String fieldName) {
   List<CommonValue> currentArray;
   CommonValue arrayValue = record.getField(fieldName);
   if (arrayValue != null && arrayValue.isArray()) {
     currentArray = arrayValue.getArray().getList();
   } else {
     currentArray = new LinkedList<CommonValue>();
     record.setField(
         fieldName,
         commonFactory.createCommonValue(
             commonFactory.createCommonArray(array.getSchema(), currentArray)));
   }
   if (!array.isEmpty()) {
     Object rawItem = array.get(0);
     if (AvroGenericUtils.isRecord(rawItem)) {
       GenericArray<GenericRecord> recordItems = (GenericArray<GenericRecord>) array;
       // Adding new records
       for (GenericRecord item : recordItems) {
         CommonRecord newRecord = createCommonRecord(item);
         updateRecord(newRecord, item);
         currentArray.add(commonFactory.createCommonValue(newRecord));
       }
     } else if (AvroGenericUtils.isFixed(rawItem)) {
       GenericArray<GenericFixed> fixedItems = (GenericArray<GenericFixed>) array;
       if (AvroGenericUtils.isUuid(rawItem)) {
         // Removing items with given uuids
         for (GenericFixed item : fixedItems) {
           UUID currentUuid = AvroGenericUtils.createUuidFromFixed(item);
           Iterator<CommonValue> valueIt = currentArray.iterator();
           while (valueIt.hasNext()) {
             CommonRecord currentRecord = valueIt.next().getRecord();
             if (currentRecord.getUuid().equals(currentUuid)) {
               valueIt.remove();
               records.remove(currentUuid);
               break;
             }
           }
         }
       } else {
         for (GenericFixed item : fixedItems) {
           currentArray.add(
               commonFactory.createCommonValue(
                   commonFactory.createCommonFixed(item.getSchema(), item.bytes())));
         }
       }
     } else {
       // Adding new primitive items
       for (Object item : array) {
         currentArray.add(commonFactory.createCommonValue(item));
       }
     }
   }
 }