Java Code Examples for com.datastax.driver.core.CodecRegistry#register()

The following examples show how to use com.datastax.driver.core.CodecRegistry#register() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractUpsertOutputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
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<>();
  }
}
 
Example 2
Source File: CassandraAbstractDao.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
private void registerCodecIfNotFound(CodecRegistry registry, TypeCodec<?> codec) {
    try {
        registry.codecFor(codec.getCqlType(), codec.getJavaType());
    } catch (CodecNotFoundException e) {
        registry.register(codec);
    }
}
 
Example 3
Source File: CassandraStorage.java    From cassandra-reaper with Apache License 2.0 5 votes vote down vote up
public CassandraStorage(
    UUID reaperInstanceId,
    ReaperApplicationConfiguration config,
    Environment environment) throws ReaperException {

  this.reaperInstanceId = reaperInstanceId;
  CassandraFactory cassandraFactory = config.getCassandraFactory();
  overrideQueryOptions(cassandraFactory);
  overrideRetryPolicy(cassandraFactory);
  overridePoolingOptions(cassandraFactory);

  // https://docs.datastax.com/en/developer/java-driver/3.5/manual/metrics/#metrics-4-compatibility
  cassandraFactory.setJmxEnabled(false);
  if (!CassandraStorage.UNINITIALISED.compareAndSet(true, false)) {
    // If there's been a past connection attempt, metrics are already registered
    cassandraFactory.setMetricsEnabled(false);
  }

  cassandra = cassandraFactory.build(environment);
  if (config.getActivateQueryLogger()) {
    cassandra.register(QueryLogger.builder().build());
  }
  CodecRegistry codecRegistry = cassandra.getConfiguration().getCodecRegistry();
  codecRegistry.register(new DateTimeCodec());
  session = cassandra.connect(config.getCassandraFactory().getKeyspace());

  version = cassandra.getMetadata().getAllHosts()
      .stream()
      .map(h -> h.getCassandraVersion())
      .min(VersionNumber::compareTo)
      .get();

  initializeAndUpgradeSchema(cassandra, session, config, version);
  prepareStatements();
}