use of com.datastax.driver.core.CodecRegistry in project storm by apache.
the class ObjectMapperCqlStatementMapper method getMappingManager.
private MappingManager getMappingManager(Session session) {
synchronized (mappingManagers) {
MappingManager mappingManager = mappingManagers.get(session);
if (mappingManager == null) {
mappingManager = new MappingManager(session);
mappingManagers.put(session, mappingManager);
CodecRegistry codecRegistry = session.getCluster().getConfiguration().getCodecRegistry();
for (TypeCodec<?> codec : codecs) {
codecRegistry.register(codec);
}
for (Class<?> udtClass : udtClasses) {
mappingManager.udtCodec(udtClass);
}
}
return mappingManager;
}
}
use of com.datastax.driver.core.CodecRegistry in project ats-framework by Axway.
the class CassandraDbProvider method extractObjectFromResultSet.
private static Object extractObjectFromResultSet(Row row, Definition columnDefinition) {
Object object;
String columnName = columnDefinition.getName();
DataType dataType = columnDefinition.getType();
Name columnTypeName = dataType.getName();
if (columnTypeName.equals(DataType.Name.UUID)) {
object = row.getUUID(columnName);
} else if (columnTypeName.equals(DataType.Name.TIMEUUID)) {
object = row.getUUID(columnName);
} else if (columnTypeName.equals(DataType.Name.BOOLEAN)) {
/* By default null values are deserialized to false (False)
* That's why this check is needed, in order to distinguish between null and false values
* */
if (row.isNull(columnName)) {
object = null;
} else {
object = row.getBool(columnName);
}
} else if (columnTypeName.equals(DataType.Name.INT)) {
/* By default null values are deserialized to 0
* That's why this check is needed, in order to distinguish between null and 0 values
* */
if (row.isNull(columnName)) {
object = null;
} else {
object = row.getInt(columnName);
}
} else if (columnTypeName.equals(DataType.Name.BIGINT)) {
/* By default null values are deserialized to 0
* That's why this check is needed, in order to distinguish between null and 0 values
* */
if (row.isNull(columnName)) {
object = null;
} else {
object = row.getLong(columnName);
}
} else if (columnTypeName.equals(DataType.Name.FLOAT)) {
/* By default null values are deserialized to 0
* That's why this check is needed, in order to distinguish between null and 0 values
* */
if (row.isNull(columnName)) {
object = null;
} else {
object = row.getFloat(columnName);
}
} else if (columnTypeName.equals(DataType.Name.DOUBLE)) {
/* By default null values are deserialized to 0
* That's why this check is needed, in order to distinguish between null and 0 values
* */
if (row.isNull(columnName)) {
object = null;
} else {
object = row.getDouble(columnName);
}
} else if (columnTypeName.equals(DataType.Name.COUNTER)) {
/* By default null values are deserialized to 0
* That's why this check is needed, in order to distinguish between null and 0 values
* */
if (row.isNull(columnName)) {
object = null;
} else {
object = row.getLong(columnName);
}
} else if (columnTypeName.equals(DataType.Name.DECIMAL)) {
object = row.getDecimal(columnName);
} else if (columnTypeName.equals(DataType.Name.TEXT) || columnTypeName.equals(DataType.Name.VARCHAR)) {
object = row.getString(columnName);
} else if (columnTypeName.equals(DataType.Name.TIMESTAMP)) {
object = row.getTimestamp(columnName);
} else if (columnTypeName.equals(DataType.Name.DATE)) {
object = row.getDate(columnName);
} else if (columnTypeName.equals(DataType.Name.BLOB)) {
object = row.getBytes(columnName);
} else if (columnTypeName.equals(DataType.Name.SET)) {
// this is the class of the set's elements (i.e. for a Set<String>, clazz variable will be equal to String.class)
Class<?> clazz = new CodecRegistry().codecFor(dataType.getTypeArguments().get(0)).getJavaType().getRawType();
object = row.getSet(columnName, clazz);
} else if (columnTypeName.equals(DataType.Name.LIST)) {
// this is the class of the list's elements (i.e. for a Set<String>, clazz variable will be equal to String.class)
Class<?> clazz = new CodecRegistry().codecFor(dataType.getTypeArguments().get(0)).getJavaType().getRawType();
object = row.getList(columnName, clazz);
} else if (columnTypeName.equals(DataType.Name.MAP)) {
/* this is the class of the map's key and value elements
* for a Map<Integer, String>,
* keyClazz variable will be equal to Integer.class
* and valueClazz variable will be equal to String.class
*/
Class<?> keyClazz = new CodecRegistry().codecFor(dataType.getTypeArguments().get(0)).getJavaType().getRawType();
Class<?> valueClazz = new CodecRegistry().codecFor(dataType.getTypeArguments().get(1)).getJavaType().getRawType();
object = row.getMap(columnName, keyClazz, valueClazz);
} else {
throw new DbException("Unsupported data type '" + columnDefinition.getType().toString() + "' for table '" + columnDefinition.getTable() + "' and column '" + columnName + "'");
}
return object;
}
use of com.datastax.driver.core.CodecRegistry in project apex-malhar by apache.
the class AbstractUpsertOutputOperator method registerCodecs.
private void registerCodecs() {
complexTypeCodecs = getCodecsForUserDefinedTypes();
if (complexTypeCodecs != null) {
CodecRegistry registry = cluster.getConfiguration().getCodecRegistry();
if (cluster.getConfiguration().getProtocolOptions().getProtocolVersion().toInt() < 4) {
LOG.error("Custom codecs are not supported for protocol version < 4");
throw new RuntimeException("Custom codecs are not supported for protocol version < 4");
}
for (String typeCodecStr : complexTypeCodecs.keySet()) {
TypeCodec codec = complexTypeCodecs.get(typeCodecStr);
registry.register(codec);
userDefinedTypesClass.put(typeCodecStr, codec.getJavaType().getRawType());
}
} else {
complexTypeCodecs = new HashMap<>();
}
}
use of com.datastax.driver.core.CodecRegistry in project apex-malhar by apache.
the class UserUpsertOperator method getCodecsForUserDefinedTypes.
@Override
public Map<String, TypeCodec> getCodecsForUserDefinedTypes() {
Map<String, TypeCodec> allCodecs = new HashMap<>();
CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry();
UserType addressType = cluster.getMetadata().getKeyspace(getConnectionStateManager().getKeyspaceName()).getUserType("address");
TypeCodec<UDTValue> addressTypeCodec = codecRegistry.codecFor(addressType);
AddressCodec addressCodec = new AddressCodec(addressTypeCodec, Address.class);
allCodecs.put("currentaddress", addressCodec);
UserType userFullNameType = cluster.getMetadata().getKeyspace(getConnectionStateManager().getKeyspaceName()).getUserType("fullname");
TypeCodec<UDTValue> userFullNameTypeCodec = codecRegistry.codecFor(userFullNameType);
FullNameCodec fullNameCodec = new FullNameCodec(userFullNameTypeCodec, FullName.class);
allCodecs.put("username", fullNameCodec);
return allCodecs;
}
Aggregations