本文整理汇总了Java中com.datastax.driver.core.KeyspaceMetadata类的典型用法代码示例。如果您正苦于以下问题:Java KeyspaceMetadata类的具体用法?Java KeyspaceMetadata怎么用?Java KeyspaceMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyspaceMetadata类属于com.datastax.driver.core包,在下文中一共展示了KeyspaceMetadata类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: insertRawUdt
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
/**
* Insert a row with a raw User-defined type.
*/
@Test
public void insertRawUdt() {
KeyspaceMetadata keyspaceMetadata = adminOperations.getKeyspaceMetadata();
UserType address = keyspaceMetadata.getUserType("address");
UDTValue udtValue = address.newValue();
udtValue.setString("street", "308 Negra Arroyo Lane");
udtValue.setString("zip", "87104");
udtValue.setString("city", "Albuquerque");
Person person = new Person();
person.setId(42);
person.setFirstname("Walter");
person.setLastname("White");
person.setAlternative(udtValue);
operations.insert(person);
Person loaded = operations.selectOne("SELECT * FROM person WHERE id = 42", Person.class);
assertThat(loaded.getAlternative().getString("zip")).isEqualTo("87104");
}
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:28,代码来源:UserDefinedTypeIntegrationTest.java
示例2: get
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public TableInfo get(@Nonnull @NonNull final ConnectorRequestContext context,
@Nonnull @NonNull final QualifiedName name) {
final String keyspace = name.getDatabaseName();
final String table = name.getTableName();
log.debug("Attempting to get metadata for Cassandra table {}.{} for request {}", keyspace, table, context);
try {
final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new DatabaseNotFoundException(name);
}
final TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
if (tableMetadata == null) {
throw new TableNotFoundException(name);
}
final TableInfo tableInfo = this.getTableInfo(name, tableMetadata);
log.debug("Successfully got metadata for Cassandra table {}.{} for request {}", keyspace, table, context);
return tableInfo;
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, name);
}
}
开发者ID:Netflix,项目名称:metacat,代码行数:28,代码来源:CassandraConnectorTableService.java
示例3: get
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public DatabaseInfo get(
@Nonnull @NonNull final ConnectorRequestContext context,
@Nonnull @NonNull final QualifiedName name
) {
final String keyspace = name.getDatabaseName();
log.debug("Attempting to get keyspace metadata for keyspace {} for request {}", keyspace, context);
try {
final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new DatabaseNotFoundException(name);
}
log.debug("Successfully found the keyspace metadata for {} for request {}", name, context);
return DatabaseInfo.builder().name(name).build();
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, name);
}
}
开发者ID:Netflix,项目名称:metacat,代码行数:24,代码来源:CassandraConnectorDatabaseService.java
示例4: existsTable
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
/**
* Checks if the main table exists in the database.
* @param appid name of the {@link com.erudika.para.core.App}
* @return true if the table exists
*/
public static boolean existsTable(String appid) {
if (StringUtils.isBlank(appid)) {
return false;
}
if (cluster == null) {
throw new IllegalStateException("Cassandra client not initialized.");
}
try {
KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(DBNAME);
TableMetadata table = ks.getTable(getTableNameForAppid(appid));
return table != null && table.getName() != null;
} catch (Exception e) {
return false;
}
}
开发者ID:Erudika,项目名称:para-dao-cassandra,代码行数:21,代码来源:CassandraUtils.java
示例5: initializeUDTs
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的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));
}
开发者ID:liaominghua,项目名称:zipkin,代码行数:26,代码来源:DefaultSessionFactory.java
示例6: readMetadata
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
static Metadata readMetadata(Session session) {
KeyspaceMetadata keyspaceMetadata = getKeyspaceMetadata(session);
Map<String, String> replication = keyspaceMetadata.getReplication();
if ("SimpleStrategy".equals(replication.get("class")) && "1".equals(
replication.get("replication_factor"))) {
LOG.warn("running with RF=1, this is not suitable for production. Optimal is 3+");
}
String compactionClass =
keyspaceMetadata.getTable("traces").getOptions().getCompaction().get("class");
boolean hasDefaultTtl = hasUpgrade1_defaultTtl(keyspaceMetadata);
if (!hasDefaultTtl) {
LOG.warn("schema lacks default ttls: apply {}, or set CassandraStorage.ensureSchema=true",
UPGRADE_1);
}
return new Metadata(compactionClass, hasDefaultTtl);
}
开发者ID:liaominghua,项目名称:zipkin,代码行数:18,代码来源:Schema.java
示例7: insertRow
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
public boolean insertRow(String tablename, Map<String, Object> valuesMap, Map<String, String> consistencyInfo, JsonInsert insObj) throws Exception {
// Note: https://docs.datastax.com/en/cql/3.0/cql/cql_reference/insert_r.html
String[] parts = tablename.split("\\.");
KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(parts[0]);
TableMetadata tableInfo = ks.getTable(parts[1]);
StringBuilder fields = new StringBuilder();
StringBuilder values = new StringBuilder();
String prefix = "";
for (String key : valuesMap.keySet()) {
fields.append(prefix).append(key);
Object valueObj = valuesMap.get(key);
DataType colType = tableInfo.getColumn(key).getType();
values.append(prefix).append(convertToSqlDataType(colType, valueObj));
prefix = ", ";
}
String suffix = getTTLSuffix(insObj);
String query = String.format("INSERT INTO %s (%s) VALUES (%s)%s;", tablename, fields.toString(), values.toString(), suffix);
LOG.debug(query);
String consistency = extractConsistencyInfo(tablename, consistencyInfo);
executeCreateQuery(query, consistency);
return false;
}
开发者ID:att,项目名称:music,代码行数:26,代码来源:MusicClient.java
示例8: createColumnFamily
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
protected void createColumnFamily() {
final String ks = getKeySpace();
final String cf = getColumnFamily();
final KeyspaceMetadata keySpaceMeta = this.cluster.getMetadata().getKeyspace(ks);
final TableMetadata tableMetadata = keySpaceMeta.getTable(cf);
// check if the table exists
if (tableMetadata != null) {
return;
}
final String stmt = String.format("CREATE TABLE %s (\n" +
" " + KEY_COLUMN + " text,\n" +
" " + COLL_COLUMN + " blob,\n" +
" PRIMARY KEY (" + KEY_COLUMN + ")\n" +
");", cf);
getSession().execute(stmt);
}
开发者ID:Breinify,项目名称:brein-time-utilities,代码行数:21,代码来源:CassandraIntervalCollectionPersistor.java
示例9: initCassandraClient
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
protected void initCassandraClient() {
if(keyspace == null) {
keyspace = DEFAULT_KEYSPACE;
}
if(cluster == null) {
cluster = Cluster.builder()
.addContactPoint(cassandraContactPoint)
.withTimestampGenerator(new AtomicMonotonicTimestampGenerator())
.build();
hasOpenedCluster = true;
}
// make sure the keyspace exists (create it with default replication settings otherwise)
KeyspaceMetadata existingKeyspace = cluster.getMetadata().getKeyspace("camunda");
if(existingKeyspace == null) {
final Session session = cluster.connect();
session.execute(String.format("CREATE keyspace %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : " + replicationFactor + " };", keyspace));
session.close();
}
if(session == null) {
session = cluster.connect(keyspace);
}
}
开发者ID:camunda,项目名称:camunda-engine-cassandra,代码行数:26,代码来源:CassandraProcessEngineConfiguration.java
示例10: getTableMetadata
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
private TableMetadata getTableMetadata(SchemaTableName schemaTableName)
{
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
KeyspaceMetadata keyspaceMetadata = getCheckedKeyspaceMetadata(schemaName);
TableMetadata tableMetadata = keyspaceMetadata.getTable(tableName);
if (tableMetadata != null) {
return tableMetadata;
}
for (TableMetadata table : keyspaceMetadata.getTables()) {
if (table.getName().equalsIgnoreCase(tableName)) {
return table;
}
}
throw new TableNotFoundException(schemaTableName);
}
开发者ID:y-lan,项目名称:presto,代码行数:19,代码来源:CassandraSession.java
示例11: schemaUpdatesTableShouldNotBeCreatedIfExists
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
@Test
public void schemaUpdatesTableShouldNotBeCreatedIfExists() throws Exception {
//given
cluster.connect("system").execute("CREATE KEYSPACE " + TEST_KEYSPACE + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1 };");
Session session = cluster.connect(TEST_KEYSPACE);
SessionContext sessionContext = new SessionContext(session, ConsistencyLevel.ALL, ConsistencyLevel.ALL, clusterHealth);
SchemaUpdates schemaUpdates = new SchemaUpdates(sessionContext, TEST_KEYSPACE);
//when
schemaUpdates.initialise();
try {
schemaUpdates.initialise();
} catch (AlreadyExistsException exception) {
fail("Expected " + SCHEMA_UPDATES_TABLE + " table creation to be attempted only once.");
}
//then
KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(TEST_KEYSPACE);
assertThat(keyspaceMetadata.getTable(SCHEMA_UPDATES_TABLE)).as("table should have been created").isNotNull();
}
开发者ID:sky-uk,项目名称:cqlmigrate,代码行数:21,代码来源:SchemaUpdatesTest.java
示例12: makeSchemas
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
public CassandraMetadataResultSet makeSchemas(CassandraStatement statement, String schemaPattern) throws SQLException
{
// TABLE_SCHEM String => schema name
// TABLE_CATALOG String => catalog name (may be null)
final ArrayList<MetadataRow> schemas = Lists.newArrayList();
List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces();
for(KeyspaceMetadata keyspace:keyspaces){
if ("%".equals(schemaPattern)) schemaPattern = null;
if((schemaPattern==null?keyspace.getName():schemaPattern).equals(keyspace.getName())){
MetadataRow row = new MetadataRow().addEntry("TABLE_SCHEM", keyspace.getName()).addEntry("TABLE_CATALOG", statement.connection.getCatalog());
schemas.add(row);
}
}
CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas));
return result;
}
开发者ID:adejanovski,项目名称:cassandra-jdbc-wrapper,代码行数:23,代码来源:MetadataResultSets.java
示例13: getSchema
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
public List<Column> getSchema(String keySpace, String tableName) {
Metadata m = session.getCluster().getMetadata();
KeyspaceMetadata km = m.getKeyspace(keySpace);
if (km == null)
return null;
TableMetadata tm = km.getTable(tableName);
if (tm == null)
return null;
// build schema
List<Column> columns = new LinkedList<Column>();
for (ColumnMetadata cm : tm.getColumns()) {
if (!meta.contains(cm.getName()))
columns.add(Column.newBuilder().setName(cm.getName())
.setType(toSimbaType(cm.getType().toString())).build());
}
return columns;
}
开发者ID:SimbaService,项目名称:Simba,代码行数:20,代码来源:CassandraHandler.java
示例14: output
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
@Override
public void output( Collection<Metric> metrics ) {
if( metrics.size() == 0 ) {
return;
}
Map<RetentionTable, BatchStatement> stms = LazyMap.<RetentionTable, BatchStatement>lazyMap( new HashMap<>(), () -> new BatchStatement() );
for ( Metric metric : metrics ) {
insertMetricIntoBatch( metric, stms );
}
KeyspaceMetadata metadata = cluster.getMetadata().getKeyspace( keyspace );
for (RetentionTable table : stms.keySet()) {
createTableIfNecessary( table, metadata );
}
for ( BatchStatement batch : stms.values() ) {
try {
session.execute( batch );
} catch ( WriteTimeoutException e ) {
log.info( "WriteTimeoutException while sending Metrics to cassandra." );
log.info( e.getMessage() );
log.info( "According to http://www.datastax.com/dev/blog/how-cassandra-deals-with-replica-failure, this is harmless" );
}
}
EventBusManager.fire( new DrainMetricOutputEvent( ( new PersistentCassandraDrainFactory<>().handledType() ), metrics.size() ) );
}
开发者ID:Tetha,项目名称:bifroest,代码行数:26,代码来源:PersistentCassandraDrain.java
示例15: createTableIfNecessary
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
private void createTableIfNecessary( RetentionTable table, KeyspaceMetadata metadata ) {
for ( TableMetadata meta : metadata.getTables()) {
log.debug( "Comparing " + meta.getName() + " with " + table.tableName() );
if ( meta.getName().equalsIgnoreCase( table.tableName() )) {
return;
}
}
StringBuilder query = new StringBuilder();
query.append( "CREATE TABLE " ).append( table.tableName() ).append( " (" );
query.append( COL_NAME ).append( " text, " );
query.append( COL_TIME ).append( " bigint, " );
query.append( COL_VALUE ).append( " double, " );
query.append( "PRIMARY KEY (" ).append( COL_NAME ).append( ", " ).append( COL_TIME ).append( ")");
query.append( ");" );
log.debug( "Creating table with query: <" + query.toString() + ">");
try {
session.execute( query.toString() );
} catch( AlreadyExistsException e ) {
// Some other gatherer might have already created the same table.
}
}
开发者ID:Tetha,项目名称:bifroest,代码行数:23,代码来源:PersistentCassandraDrain.java
示例16: getSchemaVersion
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
private static @Nullable Integer getSchemaVersion(Session session, KeyspaceMetadata keyspace)
throws Exception {
ResultSet results =
session.execute("select schema_version from schema_version where one = 1");
Row row = results.one();
if (row != null) {
return row.getInt(0);
}
TableMetadata agentTable = keyspace.getTable("agent");
if (agentTable != null && agentTable.getColumn("system_info") != null) {
// special case, this is glowroot version 0.9.1, the only version supporting upgrades
// prior to schema_version table
return 1;
}
// new installation
return null;
}
开发者ID:glowroot,项目名称:glowroot,代码行数:18,代码来源:SchemaUpgrade.java
示例17: setUp
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
SharedSetupRunListener.startCassandra();
cluster = Clusters.newCluster();
session = new Session(cluster.newSession());
session.createKeyspaceIfNotExists("glowroot_unit_tests");
session.execute("use glowroot_unit_tests");
KeyspaceMetadata keyspaceMetadata =
cluster.getMetadata().getKeyspace("glowroot_unit_tests");
clusterManager = ClusterManager.create();
CentralConfigDao centralConfigDao = new CentralConfigDao(session, clusterManager);
AgentConfigDao agentConfigDao = new AgentConfigDao(session, clusterManager);
UserDao userDao = new UserDao(session, keyspaceMetadata, clusterManager);
RoleDao roleDao = new RoleDao(session, keyspaceMetadata, clusterManager);
ConfigRepositoryImpl configRepository =
new ConfigRepositoryImpl(centralConfigDao, agentConfigDao, userDao, roleDao, "");
syntheticResultDao =
new SyntheticResultDaoImpl(session, configRepository, Clock.systemClock());
}
开发者ID:glowroot,项目名称:glowroot,代码行数:21,代码来源:SyntheticResultDaoIT.java
示例18: setUp
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
SharedSetupRunListener.startCassandra();
cluster = Clusters.newCluster();
session = new Session(cluster.newSession());
session.createKeyspaceIfNotExists("glowroot_unit_tests");
session.execute("use glowroot_unit_tests");
KeyspaceMetadata keyspaceMetadata =
cluster.getMetadata().getKeyspace("glowroot_unit_tests");
clusterManager = ClusterManager.create();
CentralConfigDao centralConfigDao = new CentralConfigDao(session, clusterManager);
agentConfigDao = new AgentConfigDao(session, clusterManager);
UserDao userDao = new UserDao(session, keyspaceMetadata, clusterManager);
RoleDao roleDao = new RoleDao(session, keyspaceMetadata, clusterManager);
ConfigRepositoryImpl configRepository =
new ConfigRepositoryImpl(centralConfigDao, agentConfigDao, userDao, roleDao, "");
TransactionTypeDao transactionTypeDao =
new TransactionTypeDao(session, configRepository, clusterManager);
FullQueryTextDao fullQueryTextDao = new FullQueryTextDao(session, configRepository);
agentDao = new AgentDao(session, agentConfigDao, configRepository, Clock.systemClock());
aggregateDao = new AggregateDaoWithV09Support(ImmutableSet.of(), 0, 0, Clock.systemClock(),
new AggregateDaoImpl(session, agentDao, transactionTypeDao, fullQueryTextDao,
configRepository, Clock.systemClock()));
}
开发者ID:glowroot,项目名称:glowroot,代码行数:26,代码来源:AggregateDaoIT.java
示例19: setUp
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
SharedSetupRunListener.startCassandra();
cluster = Clusters.newCluster();
session = new Session(cluster.newSession());
session.createKeyspaceIfNotExists("glowroot_unit_tests");
session.execute("use glowroot_unit_tests");
KeyspaceMetadata keyspaceMetadata =
cluster.getMetadata().getKeyspace("glowroot_unit_tests");
clusterManager = ClusterManager.create();
CentralConfigDao centralConfigDao = new CentralConfigDao(session, clusterManager);
agentConfigDao = new AgentConfigDao(session, clusterManager);
UserDao userDao = new UserDao(session, keyspaceMetadata, clusterManager);
RoleDao roleDao = new RoleDao(session, keyspaceMetadata, clusterManager);
ConfigRepositoryImpl configRepository = new ConfigRepositoryImpl(centralConfigDao,
agentConfigDao, userDao, roleDao, "");
gaugeValueDao = new GaugeValueDaoWithV09Support(ImmutableSet.of(), 0, Clock.systemClock(),
new GaugeValueDaoImpl(session, configRepository, Clock.systemClock()));
}
开发者ID:glowroot,项目名称:glowroot,代码行数:21,代码来源:GaugeValueDaoIT.java
示例20: setUp
import com.datastax.driver.core.KeyspaceMetadata; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
SharedSetupRunListener.startCassandra();
cluster = Clusters.newCluster();
session = new Session(cluster.newSession());
session.createKeyspaceIfNotExists("glowroot_unit_tests");
session.execute("use glowroot_unit_tests");
session.execute("drop table if exists agent_config");
session.execute("drop table if exists user");
session.execute("drop table if exists role");
session.execute("drop table if exists central_config");
session.execute("drop table if exists agent");
KeyspaceMetadata keyspaceMetadata =
cluster.getMetadata().getKeyspace("glowroot_unit_tests");
clusterManager = ClusterManager.create();
CentralConfigDao centralConfigDao = new CentralConfigDao(session, clusterManager);
agentConfigDao = new AgentConfigDao(session, clusterManager);
UserDao userDao = new UserDao(session, keyspaceMetadata, clusterManager);
RoleDao roleDao = new RoleDao(session, keyspaceMetadata, clusterManager);
configRepository =
new ConfigRepositoryImpl(centralConfigDao, agentConfigDao, userDao, roleDao, "");
}
开发者ID:glowroot,项目名称:glowroot,代码行数:24,代码来源:ConfigRepositoryIT.java
注:本文中的com.datastax.driver.core.KeyspaceMetadata类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论