本文整理匯總了Java中com.datastax.driver.core.Metadata.getKeyspace方法的典型用法代碼示例。如果您正苦於以下問題:Java Metadata.getKeyspace方法的具體用法?Java Metadata.getKeyspace怎麽用?Java Metadata.getKeyspace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.Metadata
的用法示例。
在下文中一共展示了Metadata.getKeyspace方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSchema
import com.datastax.driver.core.Metadata; //導入方法依賴的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;
}
示例2: createKeySpace
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
private void createKeySpace() {
try (Session session = cluster.connect()) { // session without an associated keyspace
Metadata clusterMetadata = cluster.getMetadata();
boolean keyspaceExists = clusterMetadata.getKeyspace(configuration.keyspace()) != null;
if (!keyspaceExists) {
log.debug("Creating a keyspace " + configuration.keyspace());
session.execute("CREATE KEYSPACE IF NOT EXISTS " + configuration.keyspace() + " WITH replication = " +
configuration.replicationStrategy() + ";");
}
boolean entryTableExists = clusterMetadata.getKeyspace(configuration.keyspace())
.getTable(configuration.entryTable()) != null;
if (!entryTableExists) {
log.debug("Creating an entry table " + configuration.entryTable());
session.execute("CREATE TABLE " + configuration.keyspace() + "." + configuration.entryTable() + " (" +
"key blob PRIMARY KEY," +
"value blob," +
"metadata blob) WITH COMPRESSION = " + configuration.compression() + ";");
}
} catch (Exception e) {
throw log.errorCreatingKeyspace(e);
}
}
示例3: detectSchema
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
/**
* Performs an analysis of the given keyspace in a Cassandra cluster
* {@link Cluster} instance and detects the cassandra types structure based
* on the metadata provided by the datastax cassandra java client.
*
* @see #detectTable(TableMetadata)
*
* @param cluster
* the cluster to inspect
* @param keyspaceName
* @return a mutable schema instance, useful for further fine tuning by the
* user.
*/
public static SimpleTableDef[] detectSchema(Cluster cluster, String keyspaceName) {
final Metadata metadata = cluster.getMetadata();
final KeyspaceMetadata keyspace = metadata.getKeyspace(keyspaceName);
if (keyspace == null) {
throw new IllegalArgumentException("Keyspace '" + keyspaceName + "' does not exist in the database");
}
final Collection<TableMetadata> tables = keyspace.getTables();
final SimpleTableDef[] result = new SimpleTableDef[tables.size()];
int i = 0;
for (final TableMetadata tableMetaData : tables) {
final SimpleTableDef table = detectTable(tableMetaData);
result[i] = table;
i++;
}
return result;
}
示例4: getTableNames
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public List<String> getTableNames(String keySpace)
{
Metadata clusterMetadata = cluster.getMetadata();
KeyspaceMetadata keyspaceMetadata = clusterMetadata.getKeyspace(keySpace);
if (keyspaceMetadata == null) {
return ImmutableList.of();
}
return keyspaceMetadata.getTables().stream()
.map(TableMetadata::getName)
.collect(toList());
}
示例5: initialize
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
private void initialize() {
Session session = cluster.connect();
Metadata metadata = cluster.getMetadata();
KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(KEYSPACE);
if (keyspaceMetadata == null) {
session.execute("CREATE KEYSPACE "
+ KEYSPACE
+ " WITH REPLICATION = { 'class' : 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1' } AND DURABLE_WRITES = true;");
}
session = cluster.connect(KEYSPACE);
metadata = cluster.getMetadata();
keyspaceMetadata = metadata.getKeyspace(KEYSPACE);
TableMetadata dataTableMetadata = keyspaceMetadata.getTable(DATA_TABLE);
if (dataTableMetadata == null) {
session.execute("CREATE TABLE "
+ KEYSPACE
+ "."
+ DATA_TABLE
+ " ("
+ DATA_TABLE_ATTRIBUTE_1
+ " ascii,"
+ DATA_TABLE_ATTRIBUTE_2
+ " timeuuid,"
+ DATA_TABLE_ATTRIBUTE_3
+ " blob,PRIMARY KEY ("
+ DATA_TABLE_ATTRIBUTE_1
+ ", "
+ DATA_TABLE_ATTRIBUTE_2
+ ")) WITH COMPACT STORAGE AND read_repair_chance = 0.0 AND dclocal_read_repair_chance = 0.1 AND gc_grace_seconds = 864000 AND bloom_filter_fp_chance = 0.01 AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 'NONE' } AND comment = '' AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy' } AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.LZ4Compressor' } AND default_time_to_live = 0 AND speculative_retry = 'NONE' AND min_index_interval = 128 AND max_index_interval = 2048;");
}
}
示例6: fetchTableMetadata
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
/**
* Fetches table metadata from the underlying datastore, using DataStax java driver.
*
* @return the table metadata as returned by the driver.
*/
public TableMetadata fetchTableMetadata() {
Metadata metadata = getSession().getCluster().getMetadata();
KeyspaceMetadata ksMetadata = metadata.getKeyspace(quote(this.catalog));
if (ksMetadata != null) {
return ksMetadata.getTable(quote(this.table));
} else {
return null;
}
}
示例7: execute
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
/**
* Execute when shCQL is DESCRIBE KEYSPACE anyvalue
* @param metaData
* @return table
*/
@Override
public Table execute(Metadata metaData) {
KeyspaceMetadata keySpaceMetada = metaData.getKeyspace(param);
FunctionalList<TableMetadata,RowData> functionalList = new FunctionalList<>(new ArrayList<>(keySpaceMetada.getTables()));
List<RowData> rows = functionalList.map(new TableMetadataToRowDataFunction());
rows.add(0,buildFirst(keySpaceMetada.toString()));
return new Table(new ListUtils<String>().buildList(),rows);
}
示例8: setTableFieldCombo
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
private void setTableFieldCombo() {
Runnable fieldLoader = new Runnable() {
@Override
public void run() {
if (!shell.isDisposed()) {
String nodes = transMeta.environmentSubstitute(hostText.getText());
String port_s = transMeta.environmentSubstitute(portText.getText());
String username = transMeta.environmentSubstitute(userText.getText());
String password = transMeta.environmentSubstitute(passText.getText());
String keyspace = transMeta.environmentSubstitute(keyspaceText.getText());
Boolean withSSL = sslenabledBut.getSelection();
String truststorefile = transMeta.environmentSubstitute(truststorefileText.getText());
String truststorepass = transMeta.environmentSubstitute(truststorepassText.getText());
ConnectionCompression compression = ConnectionCompression.fromString(wCompression.getText());
String columnFamily = columnFamilyCombo.getText();
ciFields[0].setComboValues(new String[0]);
if (!Const.isEmpty(columnFamily)) {
String[] fieldNames = null;
try {
connection = Utils.connect(nodes, port_s, username, password, keyspace, withSSL,
truststorefile, truststorepass, compression);
Cluster cluster = connection.getSession().getCluster();
Metadata clusterMeta = cluster != null ? cluster.getMetadata() : null;
KeyspaceMetadata keyspaceMeta = clusterMeta != null ? clusterMeta.getKeyspace(keyspace) : null;
TableMetadata tableMeta = keyspaceMeta != null ? keyspaceMeta.getTable(columnFamily) : null;
if (tableMeta != null) {
List<ColumnMetadata> column = tableMeta.getColumns();
Iterator<ColumnMetadata> iter = column.iterator();
fieldNames = new String[column.size()];
int i = 0;
while (iter.hasNext()) {
fieldNames[(i++)] = iter.next().getName();
}
}
} catch (Exception localException) {
localException.printStackTrace();
}
if (!fieldsList.isDisposed()) {
ciFields[0].setComboValues(fieldNames);
}
}
if (connection != null)
connection.release();
}
}
};
this.shell.getDisplay().asyncExec(fieldLoader);
}
示例9: healthCheckKeyspaceExists
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public boolean healthCheckKeyspaceExists() {
Metadata metaData = cluster.getMetadata();
KeyspaceMetadata kmd = metaData.getKeyspace(HEALTHCHECK_KEYSPACE_NAME);
return kmd != null;
}
示例10: getHealthcheckKeyspaceReplicationFactor
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public int getHealthcheckKeyspaceReplicationFactor() {
Metadata metaData = cluster.getMetadata();
KeyspaceMetadata kmd = metaData.getKeyspace(HEALTHCHECK_KEYSPACE_NAME);
Map<String, String> replicationInfo = kmd.getReplication();
return Integer.parseInt(replicationInfo.get("replication_factor"));
}
示例11: accept
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
@Override
public void accept(final Configuration<Map<String, Object>> configuration) {
deletionBatchSize = configuration.getParameter("delete-batch-size", Integer.valueOf(1000));
final String hosts = configuration.getParameter("cassandra-contact-points", "localhost");
final Cluster.Builder builder = Cluster.builder()
.addContactPoints(hosts.split(","))
.withLoadBalancingPolicy(configureLoadBalancingPolicy(configuration))
.withQueryOptions(configureQueryOptions(configuration))
.withPoolingOptions(configurePoolingOptions(configuration))
.withReconnectionPolicy(configureReconnectionPolicy(configuration))
.withRetryPolicy(configureRetryPolicy(configuration))
.withSocketOptions(configureSocketOptions(configuration));
final Compression compression = configureCompression(configuration);
if (compression != null) {
builder.withCompression(compression);
}
final String keyspaceName = configuration.getParameter("keyspace-name", "C2XDB");
final Boolean createSchema = configuration.getParameter("create-schema", Boolean.TRUE);
cluster = builder.build();
final Metadata metadata = cluster.getMetadata();
final KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(keyspaceName);
session = cluster.connect();
if (keyspaceMetadata == null) {
createKeyspace(keyspaceName, configuration);
session.execute("USE " + keyspaceName);
if (createSchema) {
createSchema(configuration);
}
} else {
session.execute("USE " + keyspaceName);
}
dictionary = new TransientNodeDictionary("TEST_DICTIONARY", new TransientNodeDictionary("NEVER_USED"), 1000000);
// new CacheNodectionary(
// "TopLevelCacheDictionary",
// new KnownURIsDictionary(
// "KnownURIsDictionary",
// new ThreeTieredNodeDictionary(
// "ThreeTieredDictionary",
// new CacheStringDictionary(
// "NamespacesCacheDictionary",
// new PersistentStringDictionary("NamespacesDictionary", "DICT_NAMESPACES"),
// configuration.getParameter("namespaces-id-cache-size", Integer.valueOf(1000)),
// configuration.getParameter("namespaces-value-cache-size", Integer.valueOf(1000)),
// false),
// new TransientStringDictionary("LocalNamesDictionary"),
// new CacheNodectionary(
// "LiteralsAndBNodesCacheDictionary",
// new TransientNodeDictionary(
// "LiteralAndBNodesDictionary",
// new PersistentNodeDictionary("LongLiteralsDictionary"),
// configuration.getParameter("long-literals-threshold", Integer.valueOf(1000))),
// configuration.getParameter("literals-bnodes-id-cache-size", Integer.valueOf(50000)),
// configuration.getParameter("literals-bnodes-value-cache-size", Integer.valueOf(50000)),
// true))),
// configuration.getParameter("known-uris-id-cache-size", Integer.valueOf(2000)),
// configuration.getParameter("known-uris-value-cache-size", Integer.valueOf(2000)),
// true);
try {
dictionary.initialise(this);
} catch (InitialisationException e) {
throw new RuntimeException(e);
}
}
示例12: init
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public void init(final String keyspace, final String columnFamily) {
this.keyspace = keyspace;
this.columnFamily = columnFamily;
// connect to the cluster
Cluster.Builder clusterBuilder = Cluster.builder();
clusterBuilder.addContactPoints(host);
if (port != -1) {
clusterBuilder.withPort(port);
}
// ask for some metadata
logger.info("getting cluster metadata for {}.{}", keyspace, columnFamily);
final TableMetadata tableMetadata;
try (final Cluster cluster = clusterBuilder.build()) {
Metadata clusterMetadata = cluster.getMetadata();
KeyspaceMetadata keyspaceMetadata = clusterMetadata.getKeyspace('"' + keyspace + '"');
tableMetadata = keyspaceMetadata.getTable('"' + columnFamily + '"');
cqlSchema = tableMetadata.asCQLQuery();
partitionerClass = clusterMetadata.getPartitioner();
Class.forName(partitionerClass);
numClusterNodes = clusterMetadata.getAllHosts().size();
columns = tableMetadata.getColumns();
} catch (ClassNotFoundException cnfe) {
throw new CrunchRuntimeException("No such partitioner: " + partitionerClass, cnfe);
} catch (NullPointerException npe) {
String msg = String.format("No such keyspace/table: %s/%s", keyspace, columnFamily);
throw new CrunchRuntimeException(msg, npe);
}
// map the partition key columns
final List<ColumnMetadata> partitionKeyColumns = tableMetadata.getPartitionKey();
partitionKeyIndexes = new int[partitionKeyColumns.size()];
for (int i = 0; i < partitionKeyColumns.size(); i++) {
final String keyColName = partitionKeyColumns.get(i).getName();
int j;
for (j = 0; j < columns.size(); j++) {
if (columns.get(j).getName().equals(keyColName)) {
partitionKeyIndexes[i] = j;
logger.info("partition key column {} index {}", keyColName, j);
break;
}
}
if (j == columns.size()) {
throw new CrunchRuntimeException("no matching column for key " + keyColName);
}
}
}