本文整理了Java中com.datastax.driver.core.Configuration.getCodecRegistry()
方法的一些代码示例,展示了Configuration.getCodecRegistry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getCodecRegistry()
方法的具体详情如下:
包路径:com.datastax.driver.core.Configuration
类名称:Configuration
方法名:getCodecRegistry
[英]Returns the CodecRegistry instance for this configuration.
Note that this method could return CodecRegistry#DEFAULT_INSTANCEif no specific codec registry has been set on the Cluster. In this case, care should be taken when registering new codecs as they would be immediately available to other Cluster instances sharing the same default instance.
[中]返回此配置的CodecRegistry实例。
请注意,如果群集上未设置特定的编解码器注册表,此方法可能会返回CodecRegistry#DEFAULT_instancei。在这种情况下,注册新的编解码器时应小心,因为共享同一默认实例的其他集群实例可以立即使用这些编解码器。
代码示例来源:origin: apache/storm
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;
}
}
}
代码示例来源:origin: kaaproject/kaa
.getCluster()
.getConfiguration()
.getCodecRegistry()
.register(instance);
} catch (Exception exception) {
代码示例来源:origin: jooby-project/jooby
CodecRegistry codecRegistry = configuration.getCodecRegistry();
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public CodecRegistry getCodecRegistry() {
return cluster.getConfiguration().getCodecRegistry();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Creates a tuple type given a list of types.
*
* @param types the types for the tuple type.
* @return the newly created tuple type.
*/
public TupleType newTupleType(List<DataType> types) {
return new TupleType(
types, cluster.protocolVersion(), cluster.configuration.getCodecRegistry());
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
private static Map<String, DataType> buildArguments(
KeyspaceMetadata ksm,
List<String> names,
List<String> types,
VersionNumber version,
Cluster cluster) {
if (names.isEmpty()) return Collections.emptyMap();
ImmutableMap.Builder<String, DataType> builder = ImmutableMap.builder();
CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry();
ProtocolVersion protocolVersion =
cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
Iterator<String> iterTypes = types.iterator();
for (String name : names) {
DataType type;
if (version.getMajor() >= 3) {
type =
DataTypeCqlNameParser.parse(
iterTypes.next(), cluster, ksm.getName(), ksm.userTypes, null, false, false);
} else {
type = DataTypeClassNameParser.parseOne(iterTypes.next(), protocolVersion, codecRegistry);
}
builder.put(name, type);
}
return builder.build();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@BeforeMethod(groups = "unit")
public void setUpQueryBuilder() throws Exception {
CodecRegistry codecRegistry = new CodecRegistry();
cluster = mock(Cluster.class);
Configuration configuration = mock(Configuration.class);
ProtocolOptions protocolOptions = mock(ProtocolOptions.class);
when(cluster.getConfiguration()).thenReturn(configuration);
when(configuration.getCodecRegistry()).thenReturn(codecRegistry);
when(configuration.getProtocolOptions()).thenReturn(protocolOptions);
when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
private static List<DataType> parseTypes(
KeyspaceMetadata ksm, List<String> types, VersionNumber version, Cluster cluster) {
if (types.isEmpty()) return Collections.emptyList();
CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry();
ProtocolVersion protocolVersion =
cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
ImmutableList.Builder<DataType> builder = ImmutableList.builder();
for (String name : types) {
DataType type;
if (version.getMajor() >= 3) {
type =
DataTypeCqlNameParser.parse(
name, cluster, ksm.getName(), ksm.userTypes, null, false, false);
} else {
type = DataTypeClassNameParser.parseOne(name, protocolVersion, codecRegistry);
}
builder.add(type);
}
return builder.build();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
static UserType build(
KeyspaceMetadata ksm,
Row row,
VersionNumber version,
Cluster cluster,
Map<String, UserType> userTypes) {
ProtocolVersion protocolVersion =
cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry();
String keyspace = row.getString(KeyspaceMetadata.KS_NAME);
String name = row.getString(TYPE_NAME);
List<String> fieldNames = row.getList(COLS_NAMES, String.class);
List<String> fieldTypes = row.getList(COLS_TYPES, String.class);
List<Field> fields = new ArrayList<Field>(fieldNames.size());
for (int i = 0; i < fieldNames.size(); i++) {
DataType fieldType;
if (version.getMajor() >= 3.0) {
fieldType =
DataTypeCqlNameParser.parse(
fieldTypes.get(i), cluster, ksm.getName(), userTypes, ksm.userTypes, false, false);
} else {
fieldType =
DataTypeClassNameParser.parseOne(fieldTypes.get(i), protocolVersion, codecRegistry);
}
fields.add(new Field(fieldNames.get(i), fieldType));
}
return new UserType(keyspace, name, false, fields, protocolVersion, codecRegistry);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public void init(Cluster cluster, Collection<Host> hosts) {
clusterMetadata = cluster.getMetadata();
protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
codecRegistry = cluster.getConfiguration().getCodecRegistry();
childPolicy.init(cluster, hosts);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
public void checkGetValuesReturnsSerializedValue(
ProtocolVersion protocolVersion, SimpleStatement statement, TestTable table) {
CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry();
ByteBuffer[] values = statement.getValues(protocolVersion, codecRegistry);
assertThat(values.length).isEqualTo(1);
assertThat(values[0])
.as("Value not serialized as expected for " + table.sampleValue)
.isEqualTo(
codecRegistry
.codecFor(table.testColumnType)
.serialize(table.sampleValue, protocolVersion));
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@BeforeMethod(groups = "unit")
public void initMocks() {
CodecRegistry codecRegistry = new CodecRegistry();
cluster = mock(Cluster.class);
Configuration configuration = mock(Configuration.class);
ProtocolOptions protocolOptions = mock(ProtocolOptions.class);
Metadata metadata = mock(Metadata.class);
childPolicy = mock(LoadBalancingPolicy.class);
when(cluster.getConfiguration()).thenReturn(configuration);
when(configuration.getCodecRegistry()).thenReturn(codecRegistry);
when(configuration.getProtocolOptions()).thenReturn(protocolOptions);
when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED);
when(cluster.getMetadata()).thenReturn(metadata);
when(metadata.getReplicas(Metadata.quote("keyspace"), routingKey))
.thenReturn(Sets.newLinkedHashSet(host1, host2));
when(childPolicy.newQueryPlan("keyspace", statement))
.thenReturn(Sets.newLinkedHashSet(host4, host3, host2, host1).iterator());
when(childPolicy.distance(any(Host.class))).thenReturn(HostDistance.LOCAL);
when(host1.isUp()).thenReturn(true);
when(host2.isUp()).thenReturn(true);
when(host3.isUp()).thenReturn(true);
when(host4.isUp()).thenReturn(true);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/** {@inheritDoc} */
@Override
public ListenableFuture<PreparedStatement> prepareAsync(final RegularStatement statement) {
if (statement.hasValues())
throw new IllegalArgumentException("A statement to prepare should not have values");
final CodecRegistry codecRegistry = getCluster().getConfiguration().getCodecRegistry();
ListenableFuture<PreparedStatement> prepared =
prepareAsync(statement.getQueryString(codecRegistry), statement.getOutgoingPayload());
return GuavaCompatibility.INSTANCE.transform(
prepared,
new Function<PreparedStatement, PreparedStatement>() {
@Override
public PreparedStatement apply(PreparedStatement prepared) {
ProtocolVersion protocolVersion =
getCluster().getConfiguration().getProtocolOptions().getProtocolVersion();
ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry);
if (routingKey != null) prepared.setRoutingKey(routingKey);
if (statement.getConsistencyLevel() != null)
prepared.setConsistencyLevel(statement.getConsistencyLevel());
if (statement.getSerialConsistencyLevel() != null)
prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel());
if (statement.isTracing()) prepared.enableTracing();
prepared.setRetryPolicy(statement.getRetryPolicy());
prepared.setOutgoingPayload(statement.getOutgoingPayload());
prepared.setIdempotent(statement.isIdempotent());
return prepared;
}
});
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_set_registry_on_nested_udts() {
ResultSet rows = session().execute("SELECT c1 FROM t1 WHERE pk = 1");
Row row = rows.one();
// here the CodecRegistry will create a codec on-the-fly using the UserType received from the
// resultset metadata
UDTValue udt1 = row.getUDTValue("c1");
assertThat(udt1.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
UDTValue udt2 = udt1.getUDTValue("f1");
assertThat(udt2.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
UDTValue udt3 = udt2.getUDTValue("f2");
assertThat(udt3.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
String f3 = udt3.getString("f3");
assertThat(f3).isEqualTo("foo");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_set_registry_on_nested_tuples() {
ResultSet rows = session().execute("SELECT c2 FROM t1 WHERE pk = 2");
Row row = rows.one();
// here the CodecRegistry will create a codec on-the-fly using the TupleType received from the
// resultset metadata
TupleValue tuple1 = row.getTupleValue("c2");
assertThat(tuple1.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
TupleValue tuple2 = tuple1.getTupleValue(0);
assertThat(tuple2.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
TupleValue tuple3 = tuple2.getTupleValue(0);
assertThat(tuple3.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
String s = tuple3.getString(0);
assertThat(s).isEqualTo("foo");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Copy constructor.
*
* @param toCopy the object to copy from.
*/
protected Configuration(Configuration toCopy) {
this(
toCopy.getPolicies(),
toCopy.getProtocolOptions(),
toCopy.getPoolingOptions(),
toCopy.getSocketOptions(),
toCopy.getMetricsOptions(),
toCopy.getQueryOptions(),
toCopy.getThreadingOptions(),
toCopy.getNettyOptions(),
toCopy.getCodecRegistry());
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_log_all_parameter_types_bound_statements() throws Exception {
// given
normal.setLevel(TRACE);
queryLogger = QueryLogger.builder().withMaxParameterValueLength(Integer.MAX_VALUE).build();
cluster().register(queryLogger);
// when
String query = "UPDATE test SET " + assignments + " WHERE pk = 42";
PreparedStatement ps = session().prepare(query);
BoundStatement bs = ps.bind(values.toArray());
session().execute(bs);
// then
String line = normalAppender.waitAndGet(10000);
assertThat(line).contains("Query completed normally").contains(ipOfNode(1)).contains(query);
CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry();
for (DataType type : dataTypes) {
TypeCodec<Object> codec = codecRegistry.codecFor(type);
assertThat(line).contains(codec.format(getFixedValue(type)));
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_set_registry_on_nested_tuples_and_udts() {
ResultSet rows = session().execute("SELECT c3 FROM t1 WHERE pk = 3");
Row row = rows.one();
// here the CodecRegistry will create a codec on-the-fly using the TupleType received from the
// resultset metadata
TupleValue tuple1 = row.getTupleValue("c3");
assertThat(tuple1.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
TupleValue tuple2 = tuple1.getTupleValue(0);
assertThat(tuple2.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
TupleValue tuple3 = tuple2.getTupleValue(0);
assertThat(tuple3.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
UDTValue udt1 = tuple3.getUDTValue(0);
assertThat(udt1.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
UDTValue udt2 = udt1.getUDTValue("f1");
assertThat(udt2.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
UDTValue udt3 = udt2.getUDTValue("f2");
assertThat(udt3.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry());
String f3 = udt3.getString("f3");
assertThat(f3).isEqualTo("foo");
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
@CassandraVersion("2.0.0")
public void should_log_all_parameter_types_simple_statements() throws Exception {
// given
normal.setLevel(TRACE);
queryLogger = QueryLogger.builder().withMaxParameterValueLength(Integer.MAX_VALUE).build();
cluster().register(queryLogger);
// when
String query = "UPDATE test SET " + assignments + " WHERE pk = 42";
SimpleStatement ss = new SimpleStatement(query, values.toArray());
session().execute(ss);
// then
String line = normalAppender.waitAndGet(10000);
assertThat(line).contains("Query completed normally").contains(ipOfNode(1)).contains(query);
CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry();
for (DataType type : dataTypes) {
TypeCodec<Object> codec;
if (type.equals(DataType.time())) {
codec = codecRegistry.codecFor(DataType.bigint());
} else {
codec = codecRegistry.codecFor(type);
}
assertThat(line).contains(codec.format(getFixedValue(type)));
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void preparedNativeTest() {
// Test preparing/bounding for all native types
for (DataType type : primitiveTypes) {
// This must be handled separately
if (exclude(type)) continue;
String name = "c_" + type;
PreparedStatement ps =
session()
.prepare(
String.format(
"INSERT INTO %s(k, %s) VALUES ('prepared_native', ?)",
ALL_NATIVE_TABLE, name));
BoundStatement bs = ps.bind();
setValue(bs, name, type, getFixedValue(type));
session().execute(bs);
Row row =
session()
.execute(
String.format(
"SELECT %s FROM %s WHERE k='prepared_native'", name, ALL_NATIVE_TABLE))
.one();
assertEquals(
getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()),
getFixedValue(type),
"For type " + type);
}
}
内容来源于网络,如有侵权,请联系作者删除!