public DiffEqualityCollectionMapper(DiffEqualityMapping mapping, HollowCollectionTypeReadState fromState, HollowCollectionTypeReadState toState, boolean oneToOne, boolean orderingIsImportant) { super(fromState, toState, oneToOne); HollowCollectionSchema schema = fromState.getSchema(); this.referencedTypeEqualOrdinalMap = mapping.getEqualOrdinalMap(schema.getElementType()); this.requiresTraversalForMissingFields = mapping.requiresMissingFieldTraversal(schema.getElementType()); this.orderingIsImportant = orderingIsImportant; }
public HollowDiffCollectionCountingNode(HollowDiff diff, HollowTypeDiff topLevelTypeDiff, HollowDiffNodeIdentifier nodeId, HollowCollectionTypeReadState fromState, HollowCollectionTypeReadState toState) { super(diff, topLevelTypeDiff, nodeId); this.fromState = fromState; this.toState = toState; HollowTypeReadState refFromState = fromState == null ? null : fromState.getSchema().getElementTypeState(); HollowTypeReadState refToState = toState == null ? null : toState.getSchema().getElementTypeState(); String referencedType = fromState == null ? toState.getSchema().getElementType() : fromState.getSchema().getElementType(); this.elementNode = getHollowDiffCountingNode(refFromState, refToState, "element"); this.referenceFilter = new DiffEqualOrdinalFilter(equalityMapping.getEqualOrdinalMap(referencedType)); this.requiresTraversalForMissingFields = equalityMapping.requiresMissingFieldTraversal(referencedType); }
private static void addTransitiveMatches(HollowReadStateEngine stateEngine, HollowCollectionTypeReadState typeState, Map<String, BitSet> matches) { HollowCollectionSchema schema = typeState.getSchema(); BitSet matchingOrdinals = getOrCreateBitSet(matches, schema.getName(), typeState.maxOrdinal()); HollowTypeReadState childTypeState = stateEngine.getTypeState(schema.getElementType()); BitSet childOrdinals = getOrCreateBitSet(matches, schema.getElementType(), childTypeState.maxOrdinal()); int ordinal = matchingOrdinals.nextSetBit(0); while(ordinal != -1) { try { HollowOrdinalIterator iter = typeState.ordinalIterator(ordinal); int elementOrdinal = iter.next(); while(elementOrdinal != HollowOrdinalIterator.NO_MORE_ORDINALS) { childOrdinals.set(elementOrdinal); elementOrdinal = iter.next(); } } catch(Exception e) { log.log(Level.SEVERE, "Add transitive matches failed", e); } ordinal = matchingOrdinals.nextSetBit(ordinal + 1); } if(!childOrdinals.isEmpty()) { matches.put(schema.getElementType(), childOrdinals); } }
public SchemaDisplayField(String fieldPath, HollowCollectionSchema parentSchema) { this.fieldPath = fieldPath; this.fieldName = "element"; this.fieldType = FieldType.REFERENCE; this.isSearchable = false; this.referencedType = new SchemaDisplay(parentSchema.getElementTypeState().getSchema(), fieldPath); }
baseTypeState = collectionSchema.getElementTypeState();
private List<Field> createCollectionFields(HollowEffigy effigy) { List<Field> fields = new ArrayList<Field>(); HollowCollectionTypeDataAccess typeDataAccess = (HollowCollectionTypeDataAccess) effigy.dataAccess; HollowCollectionSchema schema = typeDataAccess.getSchema(); HollowOrdinalIterator iter = typeDataAccess.ordinalIterator(effigy.ordinal); int elementOrdinal = iter.next(); while(elementOrdinal != NO_MORE_ORDINALS) { HollowEffigy elementEffigy = effigy(typeDataAccess.getDataAccess(), schema.getElementType(), elementOrdinal); fields.add(new Field("element", elementEffigy)); elementOrdinal = iter.next(); } return fields; }
private static void traverseReferencesOutsideClosure(HollowReadStateEngine stateEngine, HollowCollectionTypeReadState referencerTypeState, String referencedType, Map<String, BitSet> closureMatches, TransitiveSetTraverserAction action) { HollowCollectionSchema schema = referencerTypeState.getSchema(); if(!referencedType.equals(schema.getElementType())) return; BitSet referencedClosureMatches = getOrCreateBitSet(closureMatches, referencedType, stateEngine.getTypeState(referencedType).maxOrdinal()); BitSet referencerClosureMatches = getOrCreateBitSet(closureMatches, schema.getName(), referencerTypeState.maxOrdinal()); BitSet allReferencerOrdinals = getPopulatedOrdinals(referencerTypeState); int ordinal = allReferencerOrdinals.nextSetBit(0); while(ordinal != -1) { if(!referencerClosureMatches.get(ordinal)) { HollowOrdinalIterator iter = referencerTypeState.ordinalIterator(ordinal); int refOrdinal = iter.next(); while(refOrdinal != HollowOrdinalIterator.NO_MORE_ORDINALS) { if(referencedClosureMatches.get(refOrdinal)) { action.foundReference(referencerClosureMatches, ordinal, referencedClosureMatches, refOrdinal); } refOrdinal = iter.next(); } } ordinal = allReferencerOrdinals.nextSetBit(ordinal + 1); } }
private int addSubArray(JsonParser parser, String arrayType, HollowWriteRecord arrayRec) throws IOException { JsonToken token = parser.nextToken(); arrayRec.reset(); HollowCollectionSchema schema = (HollowCollectionSchema) hollowSchemas.get(arrayType); ObjectFieldMapping valueRec = null; ObjectMappedFieldPath fieldMapping = null; while(token != JsonToken.END_ARRAY) { int elementOrdinal; if(token == JsonToken.START_OBJECT || token == JsonToken.START_ARRAY) { elementOrdinal = parseSubType(parser, token, schema.getElementType()); } else { if(valueRec == null) { valueRec = getObjectFieldMapping(schema.getElementType()); fieldMapping = valueRec.getSingleFieldMapping(); } addObjectField(parser, token, fieldMapping); elementOrdinal = valueRec.build(-1); } if(arrayRec instanceof HollowListWriteRecord) { ((HollowListWriteRecord) arrayRec).addElement(elementOrdinal); } else { ((HollowSetWriteRecord)arrayRec).addElement(elementOrdinal); } token = parser.nextToken(); } return stateEngine.add(arrayType, arrayRec); }
private HollowTypeDataAccess getChildDataAccess(HollowTypeDataAccess typeDataAccess, String childName) { if(typeDataAccess instanceof HollowObjectTypeDataAccess) { HollowObjectSchema schema = (HollowObjectSchema) typeDataAccess.getSchema(); int fieldIdx = schema.getPosition(childName); String childType = schema.getReferencedType(fieldIdx); return dataAccess.getTypeDataAccess(childType); } else if(typeDataAccess instanceof HollowCollectionTypeDataAccess) { HollowCollectionSchema schema = (HollowCollectionSchema) typeDataAccess.getSchema(); return dataAccess.getTypeDataAccess(schema.getElementType()); } else if(typeDataAccess instanceof HollowMapTypeDataAccess) { HollowMapSchema schema = (HollowMapSchema) typeDataAccess.getSchema(); String childType = "key".equals(childName) ? schema.getKeyType() : schema.getValueType(); return dataAccess.getTypeDataAccess(childType); } throw new IllegalArgumentException("I can't create a child node for a " + typeDataAccess.getClass()); }
String elementType = collectionSchema.getElementType();
private HollowIndexerTraversalNode createChildNode(HollowTypeDataAccess typeDataAccess, String childName) { if(typeDataAccess instanceof HollowObjectTypeDataAccess) { HollowObjectTypeDataAccess objectAccess = (HollowObjectTypeDataAccess) typeDataAccess; HollowObjectSchema schema = objectAccess.getSchema(); int fieldIdx = schema.getPosition(childName); if(schema.getFieldType(fieldIdx) == FieldType.REFERENCE) { String childType = schema.getReferencedType(fieldIdx); HollowTypeDataAccess childTypeAccess = dataAccess.getTypeDataAccess(childType); return createTypeNode(childTypeAccess); } else { return new HollowIndexerObjectFieldTraversalNode(objectAccess, fieldMatchLists); } } else if(typeDataAccess instanceof HollowCollectionTypeDataAccess) { HollowCollectionSchema schema = (HollowCollectionSchema) typeDataAccess.getSchema(); HollowTypeDataAccess childTypeAccess = dataAccess.getTypeDataAccess(schema.getElementType()); return createTypeNode(childTypeAccess); } else if(typeDataAccess instanceof HollowMapTypeDataAccess) { HollowMapSchema schema = (HollowMapSchema) typeDataAccess.getSchema(); String childType = "key".equals(childName) ? schema.getKeyType() : schema.getValueType(); HollowTypeDataAccess childTypeAccess = dataAccess.getTypeDataAccess(childType); return createTypeNode(childTypeAccess); } throw new IllegalArgumentException("I can't create a child node for a " + typeDataAccess.getClass()); }
public static List<EffigyFieldPair> pair(HollowEffigy from, HollowEffigy to, Map<String, PrimaryKey> matchHints) { if(from == null || to == null) return new HollowEffigyNullPartnerPairer(from, to).pair(); if(from.getDataAccess() == null) return new HollowEffigyObjectPairer(from, to).pair(); HollowSchema schema = from.getDataAccess().getSchema(); switch(schema.getSchemaType()) { case OBJECT: return new HollowEffigyObjectPairer(from, to).pair(); case MAP: String keyType = ((HollowMapSchema)schema).getKeyType(); return new HollowEffigyMapPairer(from, to, matchHints.get(keyType)).pair(); case LIST: case SET: String elementType = ((HollowCollectionSchema)schema).getElementType(); return new HollowEffigyCollectionPairer(from, to, matchHints.get(elementType)).pair(); } throw new IllegalArgumentException("I don't know how to pair fields for type " + schema.getName() + "(" + schema.getSchemaType() + ")"); } }
segmentType = collectionSchema.getElementType(); fieldSegments.add(new FieldSegment(collectionSchema, segment, segmentType)); } else if (traverseSequences && schemaType == HollowSchema.SchemaType.MAP) {
case LIST: case SET: addTypeRecursive(((HollowCollectionSchema)schema).getElementType(), schemas); break;
case LIST: case SET: return typeIsTransitivelyDependent(stateEngine, ((HollowCollectionSchema)dependentTypeSchema).getElementType(), dependencyType); case MAP: return typeIsTransitivelyDependent(stateEngine, ((HollowMapSchema)dependentTypeSchema).getKeyType(), dependencyType)
} else if(typeDataAccess instanceof HollowCollectionTypeDataAccess) { HollowCollectionTypeDataAccess collectionAccess = (HollowCollectionTypeDataAccess)typeDataAccess; childDataAccess = typeDataAccess.getDataAccess().getTypeDataAccess(collectionAccess.getSchema().getElementType()); for(int i=0;i<ordinals.size();i++) { HollowOrdinalIterator iter = collectionAccess.ordinalIterator(ordinals.get(i));
private void indexSchema(HollowSchema schema, Collection<HollowSchema> allSchemas) { if(schema instanceof HollowCollectionSchema) { String elementType = ((HollowCollectionSchema) schema).getElementType(); addDependency(schema.getName(), elementType, allSchemas); } else if(schema instanceof HollowMapSchema) { String keyType = ((HollowMapSchema)schema).getKeyType(); String valueType = ((HollowMapSchema)schema).getValueType(); addDependency(schema.getName(), keyType, allSchemas); addDependency(schema.getName(), valueType, allSchemas); } else if(schema instanceof HollowObjectSchema) { HollowObjectSchema objectSchema = (HollowObjectSchema) schema; for(int i=0;i<objectSchema.numFields();i++) { if(objectSchema.getFieldType(i) == FieldType.REFERENCE) { String refType = objectSchema.getReferencedType(i); addDependency(schema.getName(), refType, allSchemas); } } } getList(schema.getName(), dependencyIndex); getList(schema.getName(), reverseDependencyIndex); }
String elementType = collectionSchema.getElementType();