use of com.datastax.driver.extras.codecs.date.SimpleDateCodec in project gora by apache.
the class CassandraClient method registerOptionalCodecs.
private void registerOptionalCodecs() {
// Optional Codecs for natives
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.ascii()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.bigint()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.blob()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cboolean()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cdouble()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cfloat()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cint()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.counter()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.date()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.decimal()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.inet()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.smallInt()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.time()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.timestamp()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.timeUUID()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.tinyInt()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.varint()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.varchar()));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.uuid()));
// Optional Array Codecs
this.cluster.getConfiguration().getCodecRegistry().register(new IntArrayCodec());
this.cluster.getConfiguration().getCodecRegistry().register(new DoubleArrayCodec());
this.cluster.getConfiguration().getCodecRegistry().register(new FloatArrayCodec());
this.cluster.getConfiguration().getCodecRegistry().register(new LongArrayCodec());
this.cluster.getConfiguration().getCodecRegistry().register(new ObjectArrayCodec<>(DataType.list(DataType.varchar()), String[].class, TypeCodec.varchar()));
// Optional Time Codecs
this.cluster.getConfiguration().getCodecRegistry().register(new SimpleDateCodec());
this.cluster.getConfiguration().getCodecRegistry().register(new SimpleTimestampCodec());
for (Field field : this.mapping.getFieldList()) {
String columnType = field.getType().toLowerCase(Locale.ENGLISH);
// http://docs.datastax.com/en/cql/3.3/cql/cql_reference/cql_data_types_c.html
if (columnType.contains("list")) {
columnType = columnType.substring(columnType.indexOf("<") + 1, columnType.indexOf(">"));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.list(getTypeCodec(columnType))));
} else if (columnType.contains("set")) {
columnType = columnType.substring(columnType.indexOf("<") + 1, columnType.indexOf(">"));
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.set(getTypeCodec(columnType))));
} else if (columnType.contains("map")) {
String[] columnTypes = columnType.substring(columnType.indexOf("<") + 1, columnType.indexOf(">")).split(",");
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.map(TypeCodec.set(getTypeCodec(columnTypes[0])), TypeCodec.set(getTypeCodec(columnTypes[1])))));
}
}
}
Aggregations