Shortcut shortcut = ergonomicShortcuts.getShortcut(schema.getName() + "." + schema.getFieldName(i)); if(shortcut != null) builder.append(" private final ").append(HollowCodeGenerationUtils.getJavaBoxedType(shortcut.getType())).append(" ").append(substituteInvalidChars(schema.getFieldName(i))).append(";\n"); builder.append(" private final int ").append(substituteInvalidChars(schema.getFieldName(i))).append("Ordinal;\n"); break; for(int j=0;j<shortcut.getPath().length-1;j++) { String typeAPIName = HollowCodeGenerationUtils.typeAPIClassname(shortcut.getPathTypes()[j]); builder.append(" " + ordinalVariableName + " = " + ordinalVariableName + " == -1 ? -1 : typeAPI.getAPI().get").append(typeAPIName).append("().get").append(uppercase(shortcut.getPath()[j])).append("Ordinal(").append(ordinalVariableName).append(");\n"); String typeAPIName = HollowCodeGenerationUtils.typeAPIClassname(shortcut.getPathTypes()[shortcut.getPathTypes().length-1]); builder.append(" this.").append(fieldName).append(" = ").append(ordinalVariableName).append(" == -1 ? null : ").append("typeAPI.getAPI().get").append(typeAPIName).append("().get").append(uppercase(shortcut.getPath()[shortcut.getPath().length-1])).append("(").append(ordinalVariableName).append(");\n"); Shortcut shortcut = ergonomicShortcuts.getShortcut(schema.getName() + "." + schema.getFieldName(i)); if(shortcut != null) addAccessor(builder, shortcut.getType(), fieldName);
private void addShortcutAccessMethod(StringBuilder builder, String methodFieldName, Shortcut shortcut) { String finalFieldName = substituteInvalidChars(uppercase(shortcut.getPath()[shortcut.getPath().length-1])); String finalTypeAPI = typeAPIClassname(shortcut.getPathTypes()[shortcut.getPathTypes().length-1]); switch(shortcut.getType()) { case BOOLEAN: builder.append(" public boolean get").append(methodFieldName).append("(int ordinal) {\n");
Shortcut shortcut = ergonomicShortcuts.getShortcut(schema.getName() + "." + schema.getFieldName(i)); if(shortcut != null) { switch(shortcut.getType()) { case BOOLEAN: case DOUBLE: case INT: case LONG: classBuilder.append(" public " + HollowCodeGenerationUtils.getJavaScalarType(shortcut.getType()) + " get").append(methodFieldName).append("(int ordinal);\n\n"); classBuilder.append(" public " + HollowCodeGenerationUtils.getJavaBoxedType(shortcut.getType()) + " get").append(methodFieldName).append("Boxed(int ordinal);\n\n"); break; case BYTES:
switch(shortcut.getType()) { case BOOLEAN: case DOUBLE: case INT: case LONG: String methodName = (shortcut.getType()==FieldType.BOOLEAN) ? generateBooleanAccessorMethodName(fieldName, useBooleanFieldErgonomics) : "get" + uppercase(fieldName); builder.append(" public ").append(HollowCodeGenerationUtils.getJavaBoxedType(shortcut.getType())).append(" ").append(getterPrefix).append(methodName); if(!restrictApiToFieldType) { builder.append("Boxed"); builder.append(" }\n\n"); if(!restrictApiToFieldType) { builder.append(" public ").append(HollowCodeGenerationUtils.getJavaScalarType(shortcut.getType())).append(" ").append(getterPrefix).append(methodName + "() {\n"); builder.append(" return delegate().get" + uppercase(fieldName) + "(ordinal);\n"); builder.append(" }\n\n");
private Shortcut getShortcutFieldPath(HollowDataset dataset, HollowSchema schema) { if(schema.getSchemaType() == SchemaType.OBJECT) { HollowObjectSchema objSchema = (HollowObjectSchema)schema; if(objSchema.numFields() == 1) { if(objSchema.getFieldType(0) == FieldType.REFERENCE) { HollowSchema refSchema = dataset.getSchema(objSchema.getReferencedType(0)); if(refSchema != null) { Shortcut childShortcut = getShortcutFieldPath(dataset, refSchema); if(childShortcut != null) { String[] shortcutPathTypes = new String[childShortcut.getPathTypes().length+1]; String[] shortcutPath = new String[childShortcut.getPath().length+1]; shortcutPathTypes[0] = objSchema.getName(); shortcutPath[0] = objSchema.getFieldName(0); System.arraycopy(childShortcut.getPath(), 0, shortcutPath, 1, childShortcut.getPath().length); System.arraycopy(childShortcut.getPathTypes(), 0, shortcutPathTypes, 1, childShortcut.getPathTypes().length); return new Shortcut(shortcutPathTypes, shortcutPath, childShortcut.getType()); } } } else { return new Shortcut(new String[] { objSchema.getName() }, new String[] { objSchema.getFieldName(0) }, objSchema.getFieldType(0)); } } } return null; }
@Test public void test() throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.initializeTypeState(TypeA.class); HollowErgonomicAPIShortcuts shortcuts = new HollowErgonomicAPIShortcuts(writeEngine); Assert.assertEquals(5, shortcuts.numShortcuts()); Assert.assertArrayEquals(new String[] { "value" }, shortcuts.getShortcut("StringReferenceReference.ref").getPath()); Assert.assertArrayEquals(new String[] { "StringReference" }, shortcuts.getShortcut("StringReferenceReference.ref").getPathTypes()); Assert.assertArrayEquals(new String[] { "value" }, shortcuts.getShortcut("TypeA.a2").getPath()); Assert.assertArrayEquals(new String[] { "StringReference" }, shortcuts.getShortcut("TypeA.a2").getPathTypes()); Assert.assertArrayEquals(new String[] { "value" }, shortcuts.getShortcut("TypeB.b1").getPath()); Assert.assertArrayEquals(new String[] { "StringReference" }, shortcuts.getShortcut("TypeB.b1").getPathTypes()); Assert.assertArrayEquals(new String[] { "ref", "value" }, shortcuts.getShortcut("TypeA.a3").getPath()); Assert.assertArrayEquals(new String[] { "StringReferenceReference", "StringReference" }, shortcuts.getShortcut("TypeA.a3").getPathTypes()); Assert.assertArrayEquals(new String[] { "ref", "value" }, shortcuts.getShortcut("TypeB.b2").getPath()); Assert.assertArrayEquals(new String[] { "StringReferenceReference", "StringReference" }, shortcuts.getShortcut("TypeB.b2").getPathTypes()); Assert.assertEquals(FieldType.STRING, shortcuts.getShortcut("StringReferenceReference.ref").getType()); Assert.assertEquals(FieldType.STRING, shortcuts.getShortcut("TypeA.a2").getType()); Assert.assertEquals(FieldType.STRING, shortcuts.getShortcut("TypeB.b1").getType()); Assert.assertEquals(FieldType.STRING, shortcuts.getShortcut("TypeA.a3").getType()); Assert.assertEquals(FieldType.STRING, shortcuts.getShortcut("TypeB.b2").getType()); }
private void addShortcutTraversal(StringBuilder builder, Shortcut shortcut) { for(int i=0;i<shortcut.getPath().length-1;i++) { String typeAPIClassname = typeAPIClassname(shortcut.getPathTypes()[i]); builder.append(" if(ordinal != -1) ordinal = typeAPI.getAPI().get" + typeAPIClassname + "().get" + uppercase(shortcut.getPath()[i]) + "Ordinal(ordinal);\n"); } }