/** * Load an entity instance given the raw column slice. This is a stop gap * solution for instanting objects using entity manager while iterating over * rows. * * @param <T> The type of entity to load for compile time type checking * @param clazz The type of entity to load for runtime instance creation * @param id ID of the instance to load * @param colSlice Raw row slice as returned from Hector API, of the type * <code>ColumnSlice<String, byte[]></code> * @return Completely instantiated persisted object */ public <T> T find(Class<T> clazz, Object id, ColumnSlice<String, byte[]> colSlice) { if (null == clazz) { throw new IllegalArgumentException("clazz cannot be null"); } if (null == id) { throw new IllegalArgumentException("id cannot be null"); } CFMappingDef<T> cfMapDef = cacheMgr.getCfMapDef(clazz, false); if (null == cfMapDef) { throw new HectorObjectMapperException("No class annotated with @" + Entity.class.getSimpleName() + " for type, " + clazz.getName()); } T obj = objMapper.createObject(cfMapDef, id, colSlice); return obj; }
T obj = createObject(cfMapDef, pkObj, result.get()); return obj;
@Test public void testCreateInstanceCustomIdType() { Colors id = Colors.GREEN; long longProp1 = 1L; ColumnSliceMockImpl slice = new ColumnSliceMockImpl(); slice.add("lp1", LongSerializer.get().toBytes(longProp1)); CFMappingDef<MyCustomIdBean> cfMapDef = cacheMgr.getCfMapDef(MyCustomIdBean.class, true); MyCustomIdBean obj = new HectorObjectMapper(cacheMgr).createObject(cfMapDef, id, slice); assertEquals(id, obj.getId()); assertEquals(longProp1, obj.getLongProp1()); }
MyTestBean obj = new HectorObjectMapper(cacheMgr).createObject(cfMapDef, id, slice);