private byte[] createBytesFromPropertyValue(Object obj, PropertyMappingDefinition md) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Object retVal = reflectionHelper.invokeGetter(obj, md); // if no value, then signal with null bytes if (null == retVal) { return null; } @SuppressWarnings("unchecked") byte[] bytes = md.getConverter().convertObjTypeToCassType(retVal); return bytes; }
@SuppressWarnings("unchecked") public boolean addColumnToCollection(CFMappingDef<?> cfMapDef, Object obj, String colName, byte[] colValue) { // if can parse, then at least adheres to formatting CollectionItemColName collColumnName; try { collColumnName = parseCollectionItemColName(colName); } catch (HectorObjectMapperException e) { return false; } // get property from mapping def - if not there, then isn't a collection // (but probably a problem elsewhere) PropertyMappingDefinition md = cfMapDef.getPropMapByColumnName(collColumnName.getPropertyName()); if (null == md) { return false; } Collection<Object> coll; try { coll = (Collection<Object>) reflectionHelper.invokeGetter(obj, md); } catch (HectorObjectMapperException e) { return false; } Object value = deserializeCollectionValue(colValue); coll.add(value); return true; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private <T> Collection<HColumn<String, byte[]>> createColumnsFromCollectionProperty(T obj, PropertyMappingDefinition md) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { // get collection Object tmpColl = reflectionHelper.invokeGetter(obj, md); if (!(tmpColl instanceof Collection)) { throw new HectorObjectMapperException("property, " + md.getColName() + ", is marked as a collection type, but not actually a Collection. Property is type, " + md.getPropDesc().getPropertyType()); } LinkedList<HColumn<String, byte[]>> colList = new LinkedList<HColumn<String, byte[]>>(); // save collection info Collection coll = (Collection) tmpColl; colList.add(createHColumn(md.getColName(), collMapperHelper.createCollectionInfoColValue(coll))); // iterate over collection applying converter to its elements int count = 0; for (Object elem : coll) { byte[] bytes = collMapperHelper.serializeCollectionValue(elem); if (null == bytes) { return null; } colList.add(createHColumn( collMapperHelper.createCollectionItemColName(md.getColName(), count), bytes)); count++; } return colList; }