public EntityManagerImpl(Keyspace keyspace, String[] classpathPrefix, ClassCacheMgr cacheMgr, HectorObjectMapper objMapper, AnnotationScanner scanner) { this.keyspace = keyspace; if (null != cacheMgr) { this.cacheMgr = cacheMgr; } else { this.cacheMgr = new ClassCacheMgr(); } if (null != objMapper) { this.objMapper = objMapper; } else { this.objMapper = new HectorObjectMapper(this.cacheMgr); } initialize(scanner, classpathPrefix); }
@Test public void testNonStringAnonymousValues() { AnonymousWithLongSerializer b1 = new AnonymousWithLongSerializer(); b1.addAnonymousProp("one", 1L); b1.addAnonymousProp("two", 2L); b1.addAnonymousProp("three", 3L); Map<String, HColumn<String, byte[]>> colMap = new HectorObjectMapper(cacheMgr).createColumnMap(b1); assertEquals("should have added all props as anonymous", colMap.size(), b1.getAnonymousProps() .size()); }
@Test public void testCustomConvertedCollectionIsOneColumn() { MyConvertedCollectionBean b1 = new MyConvertedCollectionBean(); int first = 111; int second = 0; int third = -1; b1.addToList(first).addToList(second).addToList(third); Map<String, HColumn<String, byte[]>> colMap = new HectorObjectMapper(cacheMgr).createColumnMap(b1); CFMappingDef<MyConvertedCollectionBean> cfMapping = cacheMgr.getCfMapDef( MyConvertedCollectionBean.class, false); assertEquals( "collections with custom converters should be skipped by default collection mapping", colMap.size(), cfMapping.getAllProperties().size()); }
@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()); }
obj.addAnonymousProp("rice", "beans"); Map<String, HColumn<String, byte[]>> colMap = new HectorObjectMapper(cacheMgr).createColumnMap(obj);
MyTestBean obj = new HectorObjectMapper(cacheMgr).createObject(cfMapDef, id, slice);