HectorObjectMapper { <T> Map<String, HColumn<String, byte[]>> createColumnMap(T obj) { if (null == obj) { throw new IllegalArgumentException("Class type cannot be null"); } @SuppressWarnings("unchecked") CFMappingDef<T> cfMapDef = (CFMappingDef<T>) cacheMgr.getCfMapDef((Class<T>) obj.getClass(), true); try { Map<String, HColumn<String, byte[]>> colSet = new HashMap<String, HColumn<String, byte[]>>(); Collection<PropertyMappingDefinition> coll = cfMapDef.getAllProperties(); for (PropertyMappingDefinition md : coll) { Collection<HColumn<String, byte[]>> colColl = createColumnsFromProperty(obj, md); if (null != colColl) { for (HColumn<String, byte[]> col : colColl) { colSet.put(col.getName(), col); } } } if (null != cfMapDef.getCfBaseMapDef()) { CFMappingDef<?> cfSuperMapDef = cfMapDef.getCfBaseMapDef(); String discColName = cfSuperMapDef.getDiscColumn(); DiscriminatorType discType = cfSuperMapDef.getDiscType(); colSet.put( discColName, createHColumn(discColName, convertDiscTypeToColValue(discType, cfMapDef.getDiscValue()))); } addAnonymousProperties(obj, cfMapDef, colSet); return colSet; } catch (SecurityException e) { throw new RuntimeException(e); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } HectorObjectMapper(ClassCacheMgr cacheMgr); T getObject(Keyspace keyspace, String colFamName, I pkObj); T saveObj(Keyspace keyspace, T obj); Collection<?> saveObjCollection(Keyspace keyspace, Collection<?> objColl); Collection<?> saveObjCollection(Keyspace keyspace, Collection<?> objColl, Mutator<byte[]> m); static Serializer<?> determineSerializer(Class<?> theType); static boolean isSerializable(Class<?> clazz); static boolean isImplementedBy(Class<?> clazz, Class<?> target); void setKeyConcatStrategy(KeyConcatenationStrategy keyConcatStrategy);  }
@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 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()); }