List of usage examples for org.apache.cassandra.db.marshal UserType allTypes
public List<AbstractType<?>> allTypes()
From source file:com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.java
License:Apache License
/** * Sets the udt value.// ww w. j ava2 s . c om * * @param entity * the entity * @param thriftColumnValue * the thrift column value * @param metaModel * the meta model * @param attribute * the attribute * @return the object */ private Object setUdtValue(Object entity, Object thriftColumnValue, MetamodelImpl metaModel, Attribute attribute) { List<ByteBuffer> fieldNames = new ArrayList<ByteBuffer>(); List<AbstractType<?>> fieldTypes = new ArrayList<AbstractType<?>>(); String val = null; // get from cqlMetadata, details of types and names (for maintaining // order) Map<ByteBuffer, String> schemaTypes = this.clientBase.getCqlMetadata().getValue_types(); for (Map.Entry<ByteBuffer, String> schemaType : schemaTypes.entrySet()) { UTF8Serializer utf8Serializer = UTF8Serializer.instance; String key = utf8Serializer.deserialize((schemaType.getKey())); if (key.equals(((AbstractAttribute) attribute).getJavaMember().getName())) { val = schemaType.getValue(); break; } } UserType userType = null; try { userType = UserType.getInstance(new TypeParser(val.substring(val.indexOf("("), val.length()))); } catch (ConfigurationException | SyntaxException e) { log.error(e.getMessage()); throw new KunderaException("Error while getting instance of UserType " + e); } fieldNames = userType.fieldNames(); fieldTypes = userType.allTypes(); Field field = (Field) ((AbstractAttribute) attribute).getJavaMember(); Class embeddedClass = ((AbstractAttribute) attribute).getBindableJavaType(); Object embeddedObject = KunderaCoreUtils.createNewInstance(embeddedClass); Object finalValue = populateEmbeddedRecursive((ByteBuffer.wrap((byte[]) thriftColumnValue)), fieldTypes, fieldNames, embeddedObject, metaModel); PropertyAccessorHelper.set(entity, field, finalValue); return entity; }
From source file:com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.java
License:Apache License
/** * Sets the element collection map./* w ww . j a va 2 s .co m*/ * * @param mapType * the cql column metadata * @param thriftColumnValue * the thrift column value * @param entity * the entity * @param field * the field * @param metaModel * the meta model * @param embeddedObject * the embedded object * @return the object */ private Object setElementCollectionMap(MapType mapType, ByteBuffer thriftColumnValue, Object entity, Field field, MetamodelImpl metaModel, Class embeddedClass, boolean useNativeProtocol2) { Map result = new HashMap(); MapSerializer mapSerializer = mapType.getSerializer(); Map outputCollection = new HashMap(); if (useNativeProtocol2) { outputCollection.putAll(mapSerializer.deserializeForNativeProtocol(thriftColumnValue, 2)); } else { outputCollection.putAll((Map) mapSerializer.deserialize(thriftColumnValue)); } UserType usertype = (UserType) mapType.getValuesType(); for (Object key : outputCollection.keySet()) { Object embeddedObject = KunderaCoreUtils.createNewInstance(embeddedClass); Object value = populateEmbeddedRecursive((ByteBuffer) outputCollection.get(key), usertype.allTypes(), usertype.fieldNames(), embeddedObject, metaModel); result.put(key, value); } PropertyAccessorHelper.set(entity, field, result); return entity; }
From source file:com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.java
License:Apache License
/** * Sets the element collection set.//from ww w . ja va 2s. co m * * @param setType * the cql column metadata * @param thriftColumnValue * the thrift column value * @param entity * the entity * @param field * the field * @param metaModel * the meta model * @param embeddedObject * the embedded object * @return the object */ private Object setElementCollectionSet(SetType setType, ByteBuffer thriftColumnValue, Object entity, Field field, MetamodelImpl metaModel, Class embeddedClass, boolean useNativeProtocol2) { SetSerializer setSerializer = setType.getSerializer(); Collection outputCollection = new ArrayList(); if (useNativeProtocol2) { outputCollection.addAll((Collection) setSerializer.deserializeForNativeProtocol(thriftColumnValue, 2)); } else { outputCollection.addAll((Collection) setSerializer.deserialize(thriftColumnValue)); } UserType usertype = (UserType) setType.getElementsType(); Collection result = new HashSet(); Iterator collectionItems = outputCollection.iterator(); while (collectionItems.hasNext()) { Object embeddedObject = KunderaCoreUtils.createNewInstance(embeddedClass); Object value = populateEmbeddedRecursive((ByteBuffer) collectionItems.next(), usertype.allTypes(), usertype.fieldNames(), embeddedObject, metaModel); result.add(value); } PropertyAccessorHelper.set(entity, field, result); return entity; }
From source file:com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.java
License:Apache License
/** * Sets the element collection list.// w ww . j a va2 s.c om * * @param listType * the cql column metadata * @param thriftColumnValue * the thrift column value * @param entity * the entity * @param field * the field * @param metaModel * the meta model * @param embeddedObject * the embedded object * @return the object */ private Object setElementCollectionList(ListType listType, ByteBuffer thriftColumnValue, Object entity, Field field, MetamodelImpl metaModel, Class embeddedClass, boolean useNativeProtocol2) { ListSerializer listSerializer = listType.getSerializer(); Collection outputCollection = new ArrayList(); if (useNativeProtocol2) { outputCollection.addAll((Collection) listSerializer.deserializeForNativeProtocol(thriftColumnValue, 2)); } else { outputCollection.addAll((Collection) listSerializer.deserialize(thriftColumnValue)); } UserType usertype = (UserType) listType.getElementsType(); Collection result = new ArrayList(); Iterator collectionItems = outputCollection.iterator(); while (collectionItems.hasNext()) { Object embeddedObject = KunderaCoreUtils.createNewInstance(embeddedClass); Object value = populateEmbeddedRecursive((ByteBuffer) collectionItems.next(), usertype.allTypes(), usertype.fieldNames(), embeddedObject, metaModel); result.add(value); } PropertyAccessorHelper.set(entity, field, result); return entity; }