@Override public String stringify(HollowRecord record) { return stringify(record.getTypeDataAccess().getDataAccess(), record.getSchema().getName(), record.getOrdinal()); }
public static boolean equalObject(String typeName, int ordinal, Object testObject) { if(testObject instanceof HollowRecord) { HollowRecord testRec = (HollowRecord)testObject; if(testRec.getOrdinal() == ordinal) { String otherType = testRec.getSchema().getName(); return otherType.equals(typeName); } } return false; } }
public int hashCode(String typeName, Object objectToHash) { if(objectToHash instanceof HollowRecord) return ((HollowRecord)objectToHash).getOrdinal(); return objectToHash.hashCode(); }
public HollowObjectCacheProvider(HollowTypeDataAccess typeDataAccess, HollowTypeAPI typeAPI, HollowFactory<T> factory, HollowObjectCacheProvider<T> previous) { if(typeDataAccess != null) { PopulatedOrdinalListener listener = typeDataAccess.getTypeState().getListener(PopulatedOrdinalListener.class); BitSet populatedOrdinals = listener.getPopulatedOrdinals(); BitSet previousOrdinals = listener.getPreviousOrdinals(); int length = Math.max(populatedOrdinals.length(), previousOrdinals.length()); List<T> arr = new ArrayList<T>(length); for(int ordinal = 0; ordinal < length; ordinal++) { while(ordinal >= arr.size()) arr.add(null); if(previous != null && previousOrdinals.get(ordinal) && populatedOrdinals.get(ordinal)) { T cached = previous.getHollowObject(ordinal); arr.set(ordinal, cached); if(cached instanceof HollowRecord) ((HollowCachedDelegate)((HollowRecord)cached).getDelegate()).updateTypeAPI(typeAPI); } else if(populatedOrdinals.get(ordinal)){ arr.set(ordinal, instantiateCachedObject(factory, typeDataAccess, typeAPI, ordinal)); } } if(typeDataAccess instanceof HollowTypeReadState) { this.factory = factory; this.typeAPI = typeAPI; this.typeReadState = (HollowTypeReadState)typeDataAccess; this.typeReadState.addListener(this); } this.cachedItems = arr; } else { this.cachedItems = Collections.emptyList(); } }
@Test public void testCompletelyMissingMap() throws IOException { roundTripSnapshot(); readStateEngine.setMissingDataHandler(new FakeMissingDataHandler()); GenericHollowMap map = (GenericHollowMap) GenericHollowRecordHelper.instantiate(readStateEngine, "MissingMap", 0); Assert.assertEquals(2, map.size()); Assert.assertTrue(map.containsKey(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 2))); Assert.assertEquals(300, map.get(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 3)).getOrdinal()); Assert.assertFalse(map.containsKey(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 0))); Assert.assertNull(map.get(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 4))); Iterator<Map.Entry<HollowRecord, HollowRecord>> rec = map.entrySet().iterator(); Assert.assertTrue(rec.hasNext()); Map.Entry<HollowRecord, HollowRecord> next = rec.next(); Assert.assertEquals(2, next.getKey().getOrdinal()); Assert.assertEquals("MissingObject", next.getKey().getSchema().getName()); Assert.assertEquals(200, next.getValue().getOrdinal()); Assert.assertEquals("MissingObject", next.getValue().getSchema().getName()); Assert.assertTrue(rec.hasNext()); next = rec.next(); Assert.assertEquals(3, next.getKey().getOrdinal()); Assert.assertEquals("MissingObject", next.getKey().getSchema().getName()); Assert.assertEquals(300, next.getValue().getOrdinal()); Assert.assertEquals("MissingObject", next.getValue().getSchema().getName()); Assert.assertEquals(300, map.get(next.getKey()).getOrdinal()); Assert.assertEquals("MissingObject", map.get(next.getKey()).getSchema().getName()); Assert.assertFalse(rec.hasNext()); }
@Test public void test() { HashIndexSelect<DataModel.Consumer.References, S, Integer> hi = HashIndex .from(consumer, DataModel.Consumer.References.class) .selectField(path, type) .usingPath("values._int", int.class); List<S> r = hi.findMatches(1) .collect(toList()); Assert.assertEquals(1, r.size()); Assert.assertTrue(type.isInstance(r.get(0))); Assert.assertEquals(0, r.get(0).getOrdinal()); } }
@Override public String stringify(HollowRecord record) { return stringify(record.getTypeDataAccess().getDataAccess(), record.getSchema().getName(), record.getOrdinal()); }
@Test public void testCompletelyMissingSet() throws IOException { roundTripSnapshot(); readStateEngine.setMissingDataHandler(new FakeMissingDataHandler()); GenericHollowSet set = (GenericHollowSet) GenericHollowRecordHelper.instantiate(readStateEngine, "MissingSet", 0); Assert.assertEquals(2, set.size()); Assert.assertTrue(set.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 2))); Assert.assertFalse(set.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 0))); Iterator<HollowRecord> rec = set.iterator(); Assert.assertTrue(rec.hasNext()); HollowRecord next = rec.next(); Assert.assertEquals(2, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertTrue(rec.hasNext()); next = rec.next(); Assert.assertEquals(3, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertFalse(rec.hasNext()); }
@Test public void testLookupOfLongKey() throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.initializeTypeState(TypeWithLongMap.class); TypeWithLongMap top = new TypeWithLongMap(); long longValue = (long)Integer.MAX_VALUE+1; top.longMap.put(longValue, 100L); mapper.add(top); HollowReadStateEngine readEngine = StateEngineRoundTripper.roundTripSnapshot(writeEngine); GenericHollowMap map = new GenericHollowMap(readEngine, "MapOfLongToLong", 0); GenericHollowObject value = new GenericHollowObject(readEngine, "Long", map.findValue(longValue).getOrdinal()); Assert.assertEquals(100L, value.getLong("value")); }
@Override public void stringify(Writer writer, HollowRecord record) throws IOException { stringify(writer, record.getTypeDataAccess().getDataAccess(), record.getSchema().getName(), record.getOrdinal()); }
@Test public void testCompletelyMissingList() throws IOException { roundTripSnapshot(); readStateEngine.setMissingDataHandler(new FakeMissingDataHandler()); GenericHollowList list = (GenericHollowList) GenericHollowRecordHelper.instantiate(readStateEngine, "MissingList", 0); Assert.assertEquals(2, list.size()); Assert.assertTrue(list.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 2))); Assert.assertFalse(list.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 0))); Iterator<HollowRecord> rec = list.iterator(); Assert.assertTrue(rec.hasNext()); HollowRecord next = rec.next(); Assert.assertEquals(2, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertTrue(rec.hasNext()); next = rec.next(); Assert.assertEquals(3, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertFalse(rec.hasNext()); }
Assert.assertEquals("four", typeC0.getObject("c2").getString("b1")); Assert.assertEquals(typeC0.getObject("c2").getOrdinal(), typeA0.getSet("a4").findElement("four").getOrdinal());
@Override public void stringify(Writer writer, HollowRecord record) throws IOException { stringify(writer, record.getTypeDataAccess().getDataAccess(), record.getSchema().getName(), record.getOrdinal()); }