本文整理汇总了Java中com.datastax.driver.mapping.MappingManager类的典型用法代码示例。如果您正苦于以下问题:Java MappingManager类的具体用法?Java MappingManager怎么用?Java MappingManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MappingManager类属于com.datastax.driver.mapping包,在下文中一共展示了MappingManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startComponent
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
@Override
public void startComponent() {
if (cluster == null) {
// Configure and build up the Cassandra cluster.
cluster = Cluster.builder()
.withClusterName(clusterName)
.withPort(port)
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)
// TokenAware requires query has routing info (e.g. BoundStatement with all PK value bound).
.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()))
.addContactPoints(contactPoints.toArray(new String[contactPoints.size()]))
.build();
// Register any codecs.
cluster.getConfiguration().getCodecRegistry()
.register(new CassandraEnumCodec<>(AccessMode.class, AccessMode.getValueMap()))
.register(new CassandraEnumCodec<>(Direction.class, Direction.getValueMap()))
.register(new CassandraEnumCodec<>(SourceEntity.Type.class, SourceEntity.Type.getValueMap()));
// Create a session.
manager = new MappingManager(cluster.connect());
}
}
示例2: initSession
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
private void initSession() {
long endTime = System.currentTimeMillis() + initTimeout;
while (System.currentTimeMillis() < endTime) {
try {
if (this.keyspaceName != null) {
session = cluster.connect(keyspaceName);
} else {
session = cluster.connect();
}
mappingManager = new MappingManager(session);
break;
} catch (Exception e) {
log.warn("Failed to initialize cassandra cluster due to {}. Will retry in {} ms", e.getMessage(), initRetryInterval);
try {
Thread.sleep(initRetryInterval);
} catch (InterruptedException ie) {
log.warn("Failed to wait until retry", ie);
}
}
}
}
示例3: MyInterceptor
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
MyInterceptor(Class<?> entityCls, boolean singleton) {
super();
this.entityCls = entityCls;
this.targetInitializer = () -> {
if (singleton)
log.info("Creating actual mapper for entity: " + entityCls.getName());
Session session;
if (MapperScannerConfigurer.this.session == null)
session = mainContext.getBean(Session.class);
else
session = MapperScannerConfigurer.this.session;
MappingManager mappingManager = new MappingManager(session);
return mappingManager.mapper(entityCls);
};
this.singleton = singleton;
if (singleton)
this.singletonTarget = new Lazy<>(targetInitializer);
else
this.singletonTarget = null;
}
示例4: init
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
public void init(Class<T> tClass) {
try {
Cluster.Builder builder = Cluster.builder();
final String[] nodesList = nodes.split(",");
for (String node : nodesList) {
builder.addContactPoint(node).withPort(Integer.parseInt(port));
LOGGER.info(String.format("Added cassandra node : %s", node + ":" + port));
}
cluster = builder.build();
session = null;
if (keyspace != null) {
session = cluster.connect(keyspace);
} else {
session = cluster.connect();
}
MappingManager mappingManager = new MappingManager(session);
mapper = mappingManager.mapper(tClass);
} catch (Exception e) {
LOGGER.error("Error initializing CassandraDao");
throw e;
}
}
示例5: initializeUDTs
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
private static void initializeUDTs(Session session) {
Schema.ensureExists(DEFAULT_KEYSPACE + "_udts", session);
MappingManager mapping = new MappingManager(session);
// The UDTs are hardcoded against the zipkin keyspace.
// If a different keyspace is being used the codecs must be re-applied to this different keyspace
TypeCodec<TraceIdUDT> traceIdCodec = mapping.udtCodec(TraceIdUDT.class);
TypeCodec<EndpointUDT> endpointCodec = mapping.udtCodec(EndpointUDT.class);
TypeCodec<AnnotationUDT> annoCodec = mapping.udtCodec(AnnotationUDT.class);
TypeCodec<BinaryAnnotationUDT> bAnnoCodec = mapping.udtCodec(BinaryAnnotationUDT.class);
KeyspaceMetadata keyspace =
session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace());
session.getCluster().getConfiguration().getCodecRegistry()
.register(
new TypeCodecImpl(keyspace.getUserType("trace_id"), TraceIdUDT.class, traceIdCodec))
.register(
new TypeCodecImpl(keyspace.getUserType("endpoint"), EndpointUDT.class, endpointCodec))
.register(
new TypeCodecImpl(keyspace.getUserType("annotation"), AnnotationUDT.class, annoCodec))
.register(
new TypeCodecImpl(keyspace.getUserType("binary_annotation"), BinaryAnnotationUDT.class,
bAnnoCodec));
}
示例6: init
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
@PostConstruct
public void init() {
mapper = new MappingManager(session).mapper(PersistentToken.class);
findPersistentTokenSeriesByUserIdStmt = session.prepare(
"SELECT persistent_token_series " +
"FROM persistent_token_by_user " +
"WHERE user_id = :user_id");
insertPersistentTokenSeriesByUserIdStmt = session.prepare(
"INSERT INTO persistent_token_by_user (user_id, persistent_token_series) " +
"VALUES (:user_id, :persistent_token_series) " +
"USING TTL 2592000"); // 30 days
insertPersistentTokenStmt = session.prepare(
"INSERT INTO persistent_token (series, token_date, user_agent, token_value, login, user_id, ip_address) " +
"VALUES (:series, :token_date, :user_agent, :token_value, :login, :user_id, :ip_address) " +
"USING TTL 2592000"); // 30 days
}
示例7: CassandraExecutor
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
public CassandraExecutor(final Session session, final StatementSettings settings, final CQLMapper cqlMapper, final NamingPolicy namingPolicy,
final AsyncExecutor asyncExecutor) {
this.cluster = session.getCluster();
this.session = session;
this.codecRegistry = cluster.getConfiguration().getCodecRegistry();
this.mappingManager = new MappingManager(session);
if (settings == null) {
this.settings = null;
} else {
this.settings = settings.copy();
}
this.cqlMapper = cqlMapper;
this.namingPolicy = namingPolicy == null ? NamingPolicy.LOWER_CASE_WITH_UNDERSCORE : namingPolicy;
this.asyncExecutor = asyncExecutor == null ? new AsyncExecutor(64, 300, TimeUnit.SECONDS) : asyncExecutor;
}
示例8: initSession
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
private void initSession() {
long endTime = System.currentTimeMillis() + initTimeout;
while (System.currentTimeMillis() < endTime) {
try {
cluster = clusterBuilder.build();
cluster.init();
if (this.keyspaceName != null) {
session = cluster.connect(keyspaceName);
} else {
session = cluster.connect();
}
mappingManager = new MappingManager(session);
break;
} catch (Exception e) {
log.warn("Failed to initialize cassandra cluster due to {}. Will retry in {} ms", e.getMessage(), initRetryInterval);
try {
Thread.sleep(initRetryInterval);
} catch (InterruptedException ie) {
log.warn("Failed to wait until retry", ie);
Thread.currentThread().interrupt();
}
}
}
}
示例9: connect
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
@PostConstruct
public void connect() {
cluster = Cluster.builder()
.addContactPoint(getContactPoints())
.withPort(getPort())
.withPoolingOptions(new PoolingOptions())
.build();
Metadata metadata = cluster.getMetadata();
log.info("Connected to cluster: "+ metadata.getClusterName());
for (Host host : metadata.getAllHosts()) {
log.info("Datacenter: "+host.getDatacenter()+" Host: "+host.getAddress()+ " Rack: " + host.getRack());
}
session = cluster.connect(getKeyspace());
manager = new MappingManager(session);
}
示例10: open
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
@Override
public void open(Configuration configuration) {
super.open(configuration);
try {
this.mappingManager = new MappingManager(session);
this.mapper = mappingManager.mapper(clazz);
if (options != null) {
Mapper.Option[] optionsArray = options.getMapperOptions();
if (optionsArray != null) {
this.mapper.setDefaultSaveOptions(optionsArray);
}
}
} catch (Exception e) {
throw new RuntimeException("Cannot create CassandraPojoSink with input: " + clazz.getSimpleName(), e);
}
}
示例11: connect
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
@Override
public Connection connect() throws CEUException {
DSConnection dsConnection = null;
if (keyspaceDefault != null) {
dsConnection = new DSConnection(this,
coreCluster.connect(keyspaceDefault));
// não precisa guardar pra manipular posteriormente ?
new MappingManager(dsConnection.getCoreSession());
} else {
dsConnection = new DSConnection(this, coreCluster.connect());
}
return dsConnection;
}
示例12: NativeSerializer
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
NativeSerializer(CassandraClient cassandraClient, Class<K> keyClass, Class<T> persistentClass, CassandraMapping mapping) {
super(cassandraClient, keyClass, persistentClass, mapping);
try {
analyzePersistent();
} catch (Exception e) {
throw new RuntimeException("Error occurred while analyzing the persistent class, :" + e.getMessage());
}
this.createSchema();
MappingManager mappingManager = new MappingManager(cassandraClient.getSession());
mapper = mappingManager.mapper(persistentClass);
if (cassandraClient.getWriteConsistencyLevel() != null) {
mapper.setDefaultDeleteOptions(Mapper.Option.consistencyLevel(ConsistencyLevel.valueOf(cassandraClient.getWriteConsistencyLevel())));
mapper.setDefaultSaveOptions(Mapper.Option.consistencyLevel(ConsistencyLevel.valueOf(cassandraClient.getWriteConsistencyLevel())));
}
if (cassandraClient.getReadConsistencyLevel() != null) {
mapper.setDefaultGetOptions(Mapper.Option.consistencyLevel(ConsistencyLevel.valueOf(cassandraClient.getReadConsistencyLevel())));
}
}
示例13: connectViaConnectionString
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
@Test
public void connectViaConnectionString() throws Exception {
new MockUnit(Env.class, Config.class, Binder.class, Cluster.class, Cluster.Builder.class,
Configuration.class, Session.class)
.expect(clusterBuilder)
.expect(serviceKey(new Env.ServiceKey()))
.expect(contactPoints("localhost"))
.expect(port(9042))
.expect(codecRegistry)
.expect(bind("beers", Cluster.class))
.expect(bind(null, Cluster.class))
.expect(bind("beers", Session.class))
.expect(bind(null, Session.class))
.expect(connect("beers"))
.expect(mapper)
.expect(bind("beers", MappingManager.class))
.expect(bind(null, MappingManager.class))
.expect(datastore)
.expect(bind("beers", Datastore.class))
.expect(bind(null, Datastore.class))
.expect(routeMapper).expect(onStop)
.run(unit -> {
new Cassandra("cassandra://localhost/beers")
.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
});
}
示例14: connectViaConnectionStringSupplier
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
@Test
public void connectViaConnectionStringSupplier() throws Exception {
new MockUnit(Env.class, Config.class, Binder.class, Cluster.class, Cluster.Builder.class,
Configuration.class, Session.class)
.expect(clusterBuilderProvider)
.expect(serviceKey(new Env.ServiceKey()))
.expect(contactPoints("localhost"))
.expect(port(9042))
.expect(codecRegistry)
.expect(bind("beers", Cluster.class))
.expect(bind(null, Cluster.class))
.expect(bind("beers", Session.class))
.expect(bind(null, Session.class))
.expect(connect("beers"))
.expect(mapper)
.expect(bind("beers", MappingManager.class))
.expect(bind(null, MappingManager.class))
.expect(datastore)
.expect(bind("beers", Datastore.class))
.expect(bind(null, Datastore.class))
.expect(routeMapper).expect(onStop)
.run(unit -> {
new Cassandra("cassandra://localhost/beers", () -> unit.get(Cluster.Builder.class))
.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
});
}
示例15: PersistentTokenRepository
import com.datastax.driver.mapping.MappingManager; //导入依赖的package包/类
public PersistentTokenRepository(Session session, Validator validator) {
this.session = session;
this.validator = validator;
mapper = new MappingManager(session).mapper(PersistentToken.class);
findPersistentTokenSeriesByUserIdStmt = session.prepare(
"SELECT persistent_token_series " +
"FROM persistent_token_by_user " +
"WHERE user_id = :user_id");
insertPersistentTokenSeriesByUserIdStmt = session.prepare(
"INSERT INTO persistent_token_by_user (user_id, persistent_token_series) " +
"VALUES (:user_id, :persistent_token_series) " +
"USING TTL 2592000"); // 30 days
insertPersistentTokenStmt = session.prepare(
"INSERT INTO persistent_token (series, token_date, user_agent, token_value, login, user_id, ip_address) " +
"VALUES (:series, :token_date, :user_agent, :token_value, :login, :user_id, :ip_address) " +
"USING TTL 2592000"); // 30 days
deletePersistentTokenSeriesByUserIdStmt = session.prepare(
"DELETE FROM persistent_token_by_user WHERE user_id = :user_id AND persistent_token_series = :persistent_token_series"
);
}