List of usage examples for org.apache.cassandra.db.marshal TypeParser TypeParser
public TypeParser(String str)
From source file:com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.java
License:Apache License
/** * Sets the udt value.//from www . j a va 2s . co 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.// w ww .j a va2 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 setElementCollection(Object entity, Object thriftColumnValue, MetamodelImpl metaModel, Attribute attribute) { String cqlColumnMetadata = null; Map<ByteBuffer, String> schemaTypes = this.clientBase.getCqlMetadata().getValue_types(); for (Map.Entry<ByteBuffer, String> schemaType : schemaTypes.entrySet()) { String key = UTF8Serializer.instance.deserialize((schemaType.getKey())); if (key.equals(((AbstractAttribute) attribute).getJavaMember().getName())) { cqlColumnMetadata = schemaType.getValue(); } } Field field = (Field) ((AbstractAttribute) attribute).getJavaMember(); Class embeddedClass = ((AbstractAttribute) attribute).getBindableJavaType(); if (List.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType())) { ListType listType = null; try { listType = ListType.getInstance(new TypeParser( cqlColumnMetadata.substring(cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length()))); } catch (ConfigurationException | SyntaxException e) { log.error(e.getMessage()); throw new KunderaException("Error while getting instance of ListType " + e); } return setElementCollectionList(listType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field, metaModel, embeddedClass, true); } else if (Set.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType())) { SetType setType = null; try { setType = SetType.getInstance(new TypeParser( cqlColumnMetadata.substring(cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length()))); } catch (ConfigurationException | SyntaxException e) { log.error(e.getMessage()); throw new KunderaException("Error while getting instance of SetType " + e); } return setElementCollectionSet(setType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field, metaModel, embeddedClass, true); } else if (Map.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType())) { MapType mapType = null; try { mapType = MapType.getInstance(new TypeParser( cqlColumnMetadata.substring(cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length()))); } catch (ConfigurationException | SyntaxException e) { log.error(e.getMessage()); throw new KunderaException("Error while getting instance of MapType " + e); } return setElementCollectionMap(mapType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field, metaModel, embeddedClass, true); } return entity; }
From source file:com.impetus.client.cassandra.schemamanager.CassandraValidationClassMapper.java
License:Apache License
/** * Gets the value type name.//from w w w .j a v a 2 s .c o m * * @param dataType * the data type * @param genericClasses * the generic classes * @param isCql3Enabled * the is cql3 enabled * @return the value type name * @throws SyntaxException * the syntax exception * @throws ConfigurationException * the configuration exception * @throws IllegalArgumentException * the illegal argument exception * @throws IllegalAccessException * the illegal access exception * @throws NoSuchFieldException * the no such field exception * @throws SecurityException * the security exception */ public static String getValueTypeName(Class<?> dataType, List<Class<?>> genericClasses, boolean isCql3Enabled) throws SyntaxException, ConfigurationException, IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { String valueType; Class<?> validation_class = getValidationClassInstance(dataType, isCql3Enabled); valueType = validation_class.toString(); if (validation_class.equals(ListType.class)) { TypeParser parser = new TypeParser(getValidationClass(genericClasses.get(0), isCql3Enabled)); valueType = ListType.getInstance(parser.parse(), true).toString(); } else if (validation_class.equals(SetType.class)) { TypeParser parser = new TypeParser(getValidationClass(genericClasses.get(0), isCql3Enabled)); valueType = SetType.getInstance(parser.parse(), true).toString(); } else if (validation_class.equals(MapType.class)) { Class keyClass = CassandraValidationClassMapper.getValidationClassInstance(genericClasses.get(0), true); Class valueClass = CassandraValidationClassMapper.getValidationClassInstance(genericClasses.get(1), true); Object keyClassInstance = keyClass.getDeclaredField("instance").get(null); Object valueClassInstance = valueClass.getDeclaredField("instance").get(null); valueType = MapType .getInstance((AbstractType) keyClassInstance, (AbstractType) valueClassInstance, true) .toString(); // TypeParser keyParser = new // TypeParser(getValidationClass(genericClasses.get(0), // isCql3Enabled)); // TypeParser valueParser = new // TypeParser(getValidationClass(genericClasses.get(1), // isCql3Enabled)); // valueType = MapType.getInstance(keyParser, // valueParser).toString(); } return valueType; }