private static boolean referencesGenericStringSchema(HollowSchema schema) { if(schema instanceof HollowObjectSchema) { HollowObjectSchema objSchema = (HollowObjectSchema)schema; for(int i=0;i<objSchema.numFields();i++) { if("String".equals(objSchema.getReferencedType(i))) { return true; } } } return false; }
private void addSchemaField(HollowObjectSchema schema, HollowObjectSchema keySchema, String keyField, String[] keyFieldParts, int keyFieldPartPosition) { int schemaPosition = schema.getPosition(keyFieldParts[keyFieldPartPosition]); if(keyFieldPartPosition < keyFieldParts.length - 1) { HollowObjectSchema nextPartSchema = (HollowObjectSchema) schema.getReferencedTypeState(schemaPosition).getSchema(); addSchemaField(nextPartSchema, keySchema, keyField, keyFieldParts, keyFieldPartPosition + 1); } else { keySchema.addField(keyField, schema.getFieldType(schemaPosition), schema.getReferencedType(schemaPosition)); } }
public String getReferencedType(String fieldName) { int fieldPosition = getPosition(fieldName); if(fieldPosition == -1) return null; return getReferencedType(fieldPosition); }
private void generateInstanceVariables(StringBuilder classBodyBuilder) { for (int i = 0;i < schema.numFields();i++) { if (fieldNeedsTypeNameAnnotation(i)) { classBodyBuilder.append(" @HollowTypeName(name=\"").append(schema.getReferencedType(i)).append("\")\n"); } if (fieldNeedsInlineAnnotation(i)) { importClasses.add(HollowInline.class); classBodyBuilder.append(" @HollowInline\n"); } classBodyBuilder.append(" public "); classBodyBuilder.append(fieldType(i)); classBodyBuilder.append(" ").append(getFieldName(i)).append(" = ").append(defaultValue(i)).append(";\n"); } }
private String generateReferenceFieldAccessors(int fieldNum) { StringBuilder builder = new StringBuilder(); String fieldName = substituteInvalidChars(objectSchema.getFieldName(fieldNum)); String referencedType = substituteInvalidChars(objectSchema.getReferencedType(fieldNum)); builder.append(" public int get"+ uppercase(fieldName) + "Ordinal(int ordinal) {\n"); builder.append(" if(fieldIndex[" + fieldNum +"] == -1)\n"); builder.append(" return missingDataHandler().handleReferencedOrdinal(\"").append(objectSchema.getName()).append("\", ordinal, \"").append(fieldName).append("\");\n"); builder.append(" return getTypeDataAccess().readOrdinal(ordinal, fieldIndex[" + fieldNum + "]);\n"); builder.append(" }\n\n"); builder.append(" public " + typeAPIClassname(referencedType) + " get" + uppercase(fieldName) + "TypeAPI() {\n"); builder.append(" return getAPI().get").append(uppercase(referencedType)).append("TypeAPI();\n"); builder.append(" }"); return builder.toString(); }
/** * Add an individual field from an OBJECT schema, plus recursively add any directly or transitively referenced types. * This field will be either excluded or included, depending on whether this is an exclude or include filter, respectively. * * @param type The OBJECT type from the data model * @param objectField The field in the specified type to either include or exclude. * @param schemas A map of typeName to schema including all schemas for this data model. */ public void addFieldRecursive(String type, String objectField, Map<String, HollowSchema> schemas) { addField(type, objectField); HollowObjectSchema schema = (HollowObjectSchema)schemas.get(type); if(schema.getFieldType(objectField) == FieldType.REFERENCE) { addTypeRecursive(schema.getReferencedType(objectField), schemas); } }
private boolean fieldNeedsTypeNameAnnotation(int i) { if (schema.getFieldType(i) == FieldType.REFERENCE) { HollowSchema referencedSchema = dataset.getSchema(schema.getReferencedType(i)); return !referencedSchema.getName().equals(expectedCollectionClassName(referencedSchema)); } return false; }
/** * Returns the ultimate field Schema of the specified type/field path in the provided dataset. * * @param dataAccess the data set * @param type the type name * @param fieldPath the field path * @return the field schema */ public static HollowObjectSchema getFieldSchema(HollowDataset dataAccess, String type, String fieldPath) { HollowObjectSchema schema = (HollowObjectSchema)dataAccess.getSchema(type); int pathIndexes[] = getFieldPathIndex(dataAccess, type, fieldPath); for (int i = 0; i < pathIndexes.length; i++) schema = (HollowObjectSchema)dataAccess.getSchema(schema.getReferencedType(pathIndexes[i])); return schema; }
/** * Returns the ultimate field type of the specified type/field path in the provided dataset. * * @param dataAccess the data set * @param type the type name * @param fieldPath the field path * @return the field type */ public static FieldType getFieldType(HollowDataset dataAccess, String type, String fieldPath) { HollowObjectSchema schema = (HollowObjectSchema)dataAccess.getSchema(type); int pathIndexes[] = getFieldPathIndex(dataAccess, type, fieldPath); for(int i=0;i<pathIndexes.length - 1;i++) schema = (HollowObjectSchema)dataAccess.getSchema(schema.getReferencedType(pathIndexes[i])); return schema.getFieldType(pathIndexes[pathIndexes.length - 1]); }
private String getKeyFieldType(String fieldPath) { try { HollowObjectSchema keySchema = (HollowObjectSchema)dataset.getSchema(schema.getKeyType()); String fieldPathElements[] = fieldPath.split("\\."); int idx = 0; while(idx < fieldPathElements.length-1) { keySchema = (HollowObjectSchema)dataset.getSchema(keySchema.getReferencedType(fieldPathElements[idx])); idx++; } FieldType fieldType = keySchema.getFieldType(keySchema.getPosition(fieldPathElements[idx])); return HollowCodeGenerationUtils.getJavaBoxedType(fieldType); } catch(Throwable th) { } throw new IllegalArgumentException("Field path '" + fieldPath + "' specified incorrectly for type: " + schema.getName()); }
private String fieldType(int i) { switch (schema.getFieldType(i)) { case BOOLEAN: case BYTES: case DOUBLE: case FLOAT: case INT: case LONG: case STRING: return getJavaScalarType(schema.getFieldType(i)); case REFERENCE: return buildFieldType(dataset.getSchema(schema.getReferencedType(i))); default: throw new IllegalArgumentException("Field type is unrecognized: " + schema.getFieldType(i)); } }
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()); }
public final HollowRecord getReferencedGenericRecord(String fieldName) { String referencedType = getSchema().getReferencedType(fieldName); if(referencedType == null) { try { HollowObjectSchema hollowObjectSchema = (HollowObjectSchema)getTypeDataAccess().getDataAccess().getMissingDataHandler().handleSchema(getSchema().getName()); referencedType = hollowObjectSchema.getReferencedType(fieldName); if(referencedType == null) return null; } catch(Exception e) { return null; } } int ordinal = getOrdinal(fieldName); if(ordinal == -1) return null; return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), referencedType, ordinal); }
public HollowWriteStateEnginePrimaryKeyHasher(PrimaryKey primaryKey, HollowWriteStateEngine writeEngine) { HollowWriteStateEngine stateEngine = writeEngine; HollowObjectTypeWriteState rootTypeWriteState = (HollowObjectTypeWriteState)writeEngine.getTypeState(primaryKey.getType()); this.fieldPathIndexes = new int[primaryKey.numFields()][]; this.typeStates = new HollowObjectTypeWriteState[primaryKey.numFields()][]; for(int i=0;i<primaryKey.numFields();i++) { fieldPathIndexes[i] = primaryKey.getFieldPathIndex(stateEngine, i); typeStates[i] = new HollowObjectTypeWriteState[fieldPathIndexes[i].length]; typeStates[i][0] = rootTypeWriteState; for(int j=1;j<typeStates[i].length;j++) { String referencedType = typeStates[i][j-1].getSchema().getReferencedType(fieldPathIndexes[i][j-1]); typeStates[i][j] = (HollowObjectTypeWriteState) stateEngine.getTypeState(referencedType); } } }
private int fieldHashCode(HollowEffigy element, int[] fieldPath) { HollowObjectTypeDataAccess dataAccess = (HollowObjectTypeDataAccess) element.getDataAccess(); HollowObjectSchema schema = dataAccess.getSchema(); int ordinal = element.getOrdinal(); for (int i = 0; i < fieldPath.length - 1; i++) { int fieldPosition = fieldPath[i]; ordinal = dataAccess.readOrdinal(ordinal, fieldPosition); dataAccess = (HollowObjectTypeDataAccess) dataAccess.getDataAccess().getTypeDataAccess(schema.getReferencedType(fieldPosition)); schema = dataAccess.getSchema(); } int fieldHash = HollowReadFieldUtils.fieldHashCode(dataAccess, ordinal, fieldPath[fieldPath.length-1]); return HashCodes.hashInt(fieldHash); }
private ObjectMappedFieldPath addPathMapping(String fieldName, String[] fieldPaths, RemappingBuilderInstruction instruction, int idx) { if(idx < fieldPaths.length - 1) { RemappingBuilderInstruction childInstruction = instruction.childrenRecs.get(fieldPaths[idx]); HollowObjectSchema schema = instruction.typeState.getSchema(); String referencedType = schema.getReferencedType(fieldPaths[idx]); if(childInstruction == null) { HollowObjectTypeWriteState childTypeState = (HollowObjectTypeWriteState) stateEngine.getTypeState(referencedType); HollowObjectWriteRecord childWriteRec = getWriteRecord(childTypeState.getSchema()); childInstruction = new RemappingBuilderInstruction(childWriteRec, childTypeState); instruction.addChildInstruction(fieldPaths[idx], childInstruction); } return addPathMapping(fieldName, fieldPaths, childInstruction, idx+1); } HollowObjectSchema schema = instruction.rec.getSchema(); String remappedFieldName = fieldPaths[idx]; return new ObjectMappedFieldPath(instruction.rec, remappedFieldName, typeName, fieldName, schema.getPosition(remappedFieldName), findFieldProcessor(typeName, fieldName, schema.getName(), remappedFieldName)); }
public HollowObjectSchema findUnionSchema(HollowObjectSchema otherSchema) { if(!getName().equals(otherSchema.getName())) { throw new IllegalArgumentException("Cannot find common schema of two schemas with different names!"); } int totalFields = otherSchema.numFields(); for (String fieldName : fieldNames) { if(otherSchema.getPosition(fieldName) == -1) totalFields++; } PrimaryKey primaryKey = isNullableObjectEquals(this.primaryKey, otherSchema.getPrimaryKey()) ? this.primaryKey : null; HollowObjectSchema unionSchema = new HollowObjectSchema(getName(), totalFields, primaryKey); for(int i=0;i<fieldNames.length;i++) { unionSchema.addField(fieldNames[i], fieldTypes[i], referencedTypes[i]); } for(int i=0;i<otherSchema.numFields();i++) { if(getPosition(otherSchema.getFieldName(i)) == -1) { unionSchema.addField(otherSchema.getFieldName(i), otherSchema.getFieldType(i), otherSchema.getReferencedType(i)); } } return unionSchema; }
public HollowObjectSchema filterSchema(HollowFilterConfig config) { ObjectFilterConfig typeConfig = config.getObjectTypeConfig(getName()); int includedFields = 0; for(int i=0;i<numFields();i++) { if(typeConfig.includesField(getFieldName(i))) includedFields++; } HollowObjectSchema filteredSchema = new HollowObjectSchema(getName(), includedFields, primaryKey); for(int i=0;i<numFields();i++) { if(typeConfig.includesField(getFieldName(i))) filteredSchema.addField(getFieldName(i), getFieldType(i), getReferencedType(i)); } return filteredSchema; }
private HollowObjectSchema getFilteredObjectSchema(HollowObjectSchema schema, HollowFilterConfig filterConfig) { ObjectFilterConfig typeConfig = filterConfig.getObjectTypeConfig(schema.getName()); int numIncludedFields = 0; for(int i=0;i<schema.numFields();i++) { if(typeConfig.includesField(schema.getFieldName(i))) numIncludedFields++; } if(numIncludedFields == schema.numFields()) return schema; HollowObjectSchema filteredSchema = new HollowObjectSchema(schema.getName(), numIncludedFields, schema.getPrimaryKey()); for(int i=0;i<schema.numFields();i++) { if(typeConfig.includesField(schema.getFieldName(i))) filteredSchema.addField(schema.getFieldName(i), schema.getFieldType(i), schema.getReferencedType(i)); } return filteredSchema; }
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); }