HollowObjectSchema schema1 = typeAccess1.getSchema(); Boolean bool1 = typeAccess1.readBoolean(ordinal1, fieldPosition1); Boolean bool2 = typeAccess2.readBoolean(ordinal2, fieldPosition2); return bool1 == bool2; case BYTES: byte[] data1 = typeAccess1.readBytes(ordinal1, fieldPosition1); byte[] data2 = typeAccess2.readBytes(ordinal2, fieldPosition2); return Arrays.equals(data1, data2); case DOUBLE: double d1 = typeAccess1.readDouble(ordinal1, fieldPosition1); double d2 = typeAccess2.readDouble(ordinal2, fieldPosition2); return Double.compare(d1, d2) == 0; case FLOAT: float f1 = typeAccess1.readFloat(ordinal1, fieldPosition1); float f2 = typeAccess2.readFloat(ordinal2, fieldPosition2); return Float.compare(f1, f2) == 0; case INT: int i1 = typeAccess1.readInt(ordinal1, fieldPosition1); int i2 = typeAccess2.readInt(ordinal2, fieldPosition2); return i1 == i2; case LONG: long l1 = typeAccess1.readLong(ordinal1, fieldPosition1); long l2 = typeAccess2.readLong(ordinal2, fieldPosition2); return l1 == l2; case STRING: String s1 = typeAccess1.readString(ordinal1, fieldPosition1); return typeAccess2.isStringFieldEqual(ordinal2, fieldPosition2, s1); case REFERENCE:
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 Object readFromObject(HollowObjectTypeDataAccess objectTypeDataAccess, int ordinal, FieldType fieldType, int fieldPosition) { Object value; switch (fieldType) { case INT: value = objectTypeDataAccess.readInt(ordinal, fieldPosition); break; case LONG: value = objectTypeDataAccess.readLong(ordinal, fieldPosition); break; case DOUBLE: value = objectTypeDataAccess.readDouble(ordinal, fieldPosition); break; case FLOAT: value = objectTypeDataAccess.readFloat(ordinal, fieldPosition); break; case BOOLEAN: value = objectTypeDataAccess.readBoolean(ordinal, fieldPosition); break; case STRING: value = objectTypeDataAccess.readString(ordinal, fieldPosition); break; default: throw new IllegalStateException("Invalid field type :" + fieldType + " cannot read values for this type"); } return value; } }
HollowObjectSchema schema = typeAccess.getSchema(); Boolean bool = typeAccess.readBoolean(ordinal, fieldPosition); return booleanHashCode(bool); case BYTES: case STRING: return typeAccess.findVarLengthFieldHashCode(ordinal, fieldPosition); case DOUBLE: double d = typeAccess.readDouble(ordinal, fieldPosition); return doubleHashCode(d); case FLOAT: float f = typeAccess.readFloat(ordinal, fieldPosition); return floatHashCode(f); case INT: return intHashCode(typeAccess.readInt(ordinal, fieldPosition)); case LONG: long l = typeAccess.readLong(ordinal, fieldPosition); return longHashCode(l); case REFERENCE: return typeAccess.readOrdinal(ordinal, fieldPosition);
@Override public HollowObjectSchema getSchema() { return dataAccess.getSchema(); }
private String roundTripReferenceStringValue(String value) throws IOException { HollowObjectMapper mapper = new HollowObjectMapper(writeStateEngine); mapper.add(new TypeA(value, 1, null, null)); roundTripSnapshot(); HollowObjectTypeDataAccess typeDataAccess = (HollowObjectTypeDataAccess) readStateEngine.getTypeDataAccess("TypeA"); int stringFieldIndex = typeDataAccess.getSchema().getPosition("a1"); int stringValueOrdinal = typeDataAccess.readOrdinal(0, stringFieldIndex); HollowObjectTypeDataAccess stringDataAccess = (HollowObjectTypeDataAccess) readStateEngine.getTypeDataAccess("String"); int stringValueField = stringDataAccess.getSchema().getPosition("value"); return stringDataAccess.readString(stringValueOrdinal, stringValueField); }
@Override public boolean shouldIndex(int ordinal) { HollowObjectTypeDataAccess objectTypeDataAccess = (HollowObjectTypeDataAccess) readStateEngine.getTypeDataAccess("Movie"); int yearReleasedFieldPosition = objectTypeDataAccess.getSchema().getPosition("releaseYear"); int yearReleased = objectTypeDataAccess.readInt(ordinal, yearReleasedFieldPosition); if (yearReleased == 2009) return true; return false; } };
@Override public int readOrdinal(int ordinal, int fieldIndex) { return ((HollowObjectTypeDataAccess) currentDataAccess).readOrdinal(ordinal, fieldIndex); }
private String roundTripInlinedStringValue(String value) throws IOException { HollowObjectMapper mapper = new HollowObjectMapper(writeStateEngine); mapper.add(new TypeD(value)); roundTripSnapshot(); HollowObjectTypeDataAccess typeDataAccess = (HollowObjectTypeDataAccess) readStateEngine.getTypeDataAccess("TypeD"); int stringFieldIndex = typeDataAccess.getSchema().getPosition("inlinedString"); return typeDataAccess.readString(0, stringFieldIndex); }
@Test public void testClientAPIHoldsLongLivedReferences() throws IOException { client.triggerRefreshTo(1); HollowAPI api = client.getAPI(); HollowObjectTypeDataAccess dataAccess = (HollowObjectTypeDataAccess) api.getDataAccess().getTypeDataAccess("TestObject"); client.triggerRefreshTo(2); client.triggerRefreshTo(3); client.triggerRefreshTo(4); Assert.assertEquals(1, dataAccess.readInt(1, 0)); Assert.assertEquals("one", dataAccess.readString(1, 1)); Assert.assertEquals(3, dataAccess.readInt(3, 0)); Assert.assertEquals("three", dataAccess.readString(3, 1)); }
@Override public int readInt(int ordinal, int fieldIndex) { return ((HollowObjectTypeDataAccess) currentDataAccess).readInt(ordinal, fieldIndex); }
int fieldIdx = objectAccess.getSchema().getPosition(fieldIdentifier.getParents().get(level+1).getViaFieldName()); childDataAccess = typeDataAccess.getDataAccess().getTypeDataAccess(objectAccess.getSchema().getReferencedType(fieldIdx)); for(int i=0;i<ordinals.size();i++) childOrdinals.add(objectAccess.readOrdinal(ordinals.get(i), fieldIdx)); } else if(typeDataAccess instanceof HollowCollectionTypeDataAccess) { HollowCollectionTypeDataAccess collectionAccess = (HollowCollectionTypeDataAccess)typeDataAccess;
@Override public String readString(int ordinal, int fieldIndex) { return ((HollowObjectTypeDataAccess) currentDataAccess).readString(ordinal, fieldIndex); }
private void appendObjectStringify(Writer writer, HollowDataAccess dataAccess, HollowObjectTypeDataAccess typeDataAccess, int ordinal, int indentation) throws IOException { HollowObjectSchema schema = typeDataAccess.getSchema(); if(schema.numFields() == 1 && (collapseAllSingleFieldObjects || collapseObjectTypes.contains(schema.getName()))) { appendFieldStringify(writer, dataAccess, indentation, schema, typeDataAccess, ordinal, 0); } else { writer.append("{"); boolean firstField = true; indentation++; for(int i=0;i<schema.numFields();i++) { String fieldName = schema.getFieldName(i); if(!typeDataAccess.isNull(ordinal, i)) { if(firstField) firstField = false; else writer.append(","); if(prettyPrint) { writer.append(NEWLINE); appendIndentation(writer, indentation); } writer.append("\"").append(fieldName).append("\": "); appendFieldStringify(writer, dataAccess, indentation, schema, typeDataAccess, ordinal, i); } } if(prettyPrint && !firstField) { writer.append(NEWLINE); appendIndentation(writer, indentation - 1); } writer.append("}"); } }
@Override public long readLong(int ordinal, int fieldIndex) { return ((HollowObjectTypeDataAccess) currentDataAccess).readLong(ordinal, fieldIndex); }
@Override public Boolean readBoolean(int ordinal, int fieldIndex) { return ((HollowObjectTypeDataAccess) currentDataAccess).readBoolean(ordinal, fieldIndex); }
@Override public double readDouble(int ordinal, int fieldIndex) { return ((HollowObjectTypeDataAccess) currentDataAccess).readDouble(ordinal, fieldIndex); }
@Override public float readFloat(int ordinal, int fieldIndex) { return ((HollowObjectTypeDataAccess) currentDataAccess).readFloat(ordinal, fieldIndex); }
@Override public byte[] readBytes(int ordinal, int fieldIndex) { return ((HollowObjectTypeDataAccess) currentDataAccess).readBytes(ordinal, fieldIndex); }
private MissingDataHandler missingDataHandler() { return getTypeDataAccess().getDataAccess().getMissingDataHandler(); } }