當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyspaceMetadata類代碼示例

本文整理匯總了Java中com.datastax.driver.core.KeyspaceMetadata的典型用法代碼示例。如果您正苦於以下問題:Java KeyspaceMetadata類的具體用法?Java KeyspaceMetadata怎麽用?Java KeyspaceMetadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


KeyspaceMetadata類屬於com.datastax.driver.core包,在下文中一共展示了KeyspaceMetadata類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的com.datastax.driver.core.KeyspaceMetadata類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。