@Override public HollowTypeReadState getTypeState() { return currentDataAccess.getTypeState(); }
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(); } }
@Override public GenericHollowObject getRecord(int ordinal) { HollowObjectTypeReadState typeState = (HollowObjectTypeReadState) rStateEngine.getTypeDataAccess(type).getTypeState(); GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(typeState), ordinal); return obj; } }
protected void computeDataChange(String type, HollowReadStateEngine stateEngine, PrimaryKey primaryKey) { HollowTypeReadState typeState = stateEngine.getTypeDataAccess(type).getTypeState();
@Override public Collection<HInteger> getAllHInteger() { return new AllHollowRecordCollection<HInteger>(getDataAccess().getTypeDataAccess("Integer").getTypeState()) { @Override protected HInteger getForOrdinal(int ordinal) { return getHInteger(ordinal); } }; } @Override
@Override public Collection<HBoolean> getAllHBoolean() { return new AllHollowRecordCollection<HBoolean>(getDataAccess().getTypeDataAccess("Boolean").getTypeState()) { @Override protected HBoolean getForOrdinal(int ordinal) { return getHBoolean(ordinal); } }; } @Override
@Override public Collection<HDouble> getAllHDouble() { return new AllHollowRecordCollection<HDouble>(getDataAccess().getTypeDataAccess("Double").getTypeState()) { @Override protected HDouble getForOrdinal(int ordinal) { return getHDouble(ordinal); } }; } @Override
private Collection<HollowObject> getAllHollowObjects(HollowConsumer hollowConsumer, final String type) { final HollowReadStateEngine readStateEngine = hollowConsumer.getStateEngine(); final HollowTypeDataAccess typeDataAccess = readStateEngine.getTypeDataAccess(type); final HollowTypeReadState typeState = typeDataAccess.getTypeState(); return new AllHollowRecordCollection<HollowObject>(typeState) { @Override protected HollowObject getForOrdinal(int ordinal) { return new GenericHollowObject(readStateEngine, type, ordinal); } }; }
@Override public Collection<HFloat> getAllHFloat() { return new AllHollowRecordCollection<HFloat>(getDataAccess().getTypeDataAccess("Float").getTypeState()) { @Override protected HFloat getForOrdinal(int ordinal) { return getHFloat(ordinal); } }; } @Override
@Override public Collection<HLong> getAllHLong() { return new AllHollowRecordCollection<HLong>(getDataAccess().getTypeDataAccess("Long").getTypeState()) { @Override protected HLong getForOrdinal(int ordinal) { return getHLong(ordinal); } }; } @Override
@Override public Collection<HString> getAllHString() { return new AllHollowRecordCollection<HString>(getDataAccess().getTypeDataAccess("String").getTypeState()) { @Override protected HString getForOrdinal(int ordinal) { return getHString(ordinal); } }; } @Override
@Test public void testBuild_withTypeInitialization() { HollowReadStateEngine readEngine = new HollowReadStateEngineBuilder(Arrays.<Class<?>>asList(String.class, Long.class)) .add("foo").add(3L).build(); assertEquals("Should have both types", new HashSet<String>(Arrays.asList( String.class.getSimpleName(), Long.class.getSimpleName())), new HashSet<String>(readEngine.getAllTypes())); assertEquals("Should have one String", 1, readEngine.getTypeDataAccess( String.class.getSimpleName()).getTypeState().getPopulatedOrdinals().cardinality()); assertEquals("The one String should be foo", "foo", new GenericHollowObject(readEngine, String.class.getSimpleName(), 0).getString("value")); assertEquals("Should have one Long", 1, readEngine.getTypeDataAccess( Long.class.getSimpleName()).getTypeState().getPopulatedOrdinals().cardinality()); assertEquals("The one Long should be 3L", 3L, new GenericHollowObject(readEngine, Long.class.getSimpleName(), 0).getLong("value")); }