List of usage examples for org.apache.cassandra.db.marshal UserType fieldNames
List fieldNames
To view the source code for org.apache.cassandra.db.marshal UserType fieldNames.
Click Source Link
From source file:com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.java
License:Apache License
/** * Sets the udt value./*from w w w . j a va2 s . c o m*/ * * @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 w w. j a v a 2s .c o 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./* w w w. j a v a2 s.c om*/ * * @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./*from www.j av a 2 s . co m*/ * * @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; }
From source file:com.stratio.cassandra.lucene.column.ColumnsMapper.java
License:Apache License
private void addColumns(Columns columns, ColumnBuilder builder, AbstractType type, ByteBuffer value) { if (type.isCollection()) { value = ByteBufferUtil.clone(value); CollectionType<?> collectionType = (CollectionType<?>) type; switch (collectionType.kind) { case SET: { AbstractType<?> nameType = collectionType.nameComparator(); int colSize = CollectionSerializer.readCollectionSize(value, Server.CURRENT_VERSION); for (int j = 0; j < colSize; j++) { ByteBuffer itemValue = CollectionSerializer.readValue(value, Server.CURRENT_VERSION); addColumns(columns, builder, nameType, itemValue); }/*from w w w .ja v a2 s.c om*/ break; } case LIST: { AbstractType<?> valueType = collectionType.valueComparator(); int colSize = CollectionSerializer.readCollectionSize(value, Server.CURRENT_VERSION); for (int j = 0; j < colSize; j++) { ByteBuffer itemValue = CollectionSerializer.readValue(value, Server.CURRENT_VERSION); addColumns(columns, builder, valueType, itemValue); } break; } case MAP: { AbstractType<?> keyType = collectionType.nameComparator(); AbstractType<?> valueType = collectionType.valueComparator(); int colSize = MapSerializer.readCollectionSize(value, Server.CURRENT_VERSION); for (int j = 0; j < colSize; j++) { ByteBuffer mapKey = MapSerializer.readValue(value, Server.CURRENT_VERSION); ByteBuffer mapValue = MapSerializer.readValue(value, Server.CURRENT_VERSION); String itemName = keyType.compose(mapKey).toString(); collectionType.nameComparator(); addColumns(columns, builder.withMapName(itemName), valueType, mapValue); } break; } default: { throw new IndexException("Unknown collection type %s", collectionType.kind); } } } else if (type instanceof UserType) { UserType userType = (UserType) type; ByteBuffer[] values = userType.split(value); for (int i = 0; i < userType.fieldNames().size(); i++) { String itemName = userType.fieldNameAsString(i); AbstractType<?> itemType = userType.fieldType(i); // This only occurs in UDT not fully composed if (values[i] != null) { addColumns(columns, builder.withUDTName(itemName), itemType, values[i]); } } } else if (type instanceof TupleType) { TupleType tupleType = (TupleType) type; ByteBuffer[] values = tupleType.split(value); for (Integer i = 0; i < tupleType.size(); i++) { String itemName = i.toString(); AbstractType<?> itemType = tupleType.type(i); addColumns(columns, builder.withUDTName(itemName), itemType, values[i]); } } else { if (value != null) { columns.add(builder.buildWithDecomposed(value, type)); } } }