本文整理匯總了Java中com.datastax.driver.core.KeyspaceMetadata.getTable方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyspaceMetadata.getTable方法的具體用法?Java KeyspaceMetadata.getTable怎麽用?Java KeyspaceMetadata.getTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.KeyspaceMetadata
的用法示例。
在下文中一共展示了KeyspaceMetadata.getTable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: 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;
}
}
示例3: 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;
}
示例4: 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);
}
示例5: 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);
}
示例6: 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;
}
示例7: 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;
}
示例8: getKeyColumn
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
private String getKeyColumn(String columnFamily) {
KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace);
TableMetadata tableMetadata = keyspaceMetadata.getTable(columnFamily);
if (tableMetadata == null) {
return null;
}
for (String key : new String[] { "\"KEY\"", "key" }) {
if (tableMetadata.getColumn(key) != null) {
return key;
}
}
return null;
}
示例9: ensureTableExists
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
private void ensureTableExists() {
KeyspaceMetadata keyspaceMetadata =
session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace());
TableMetadata tableMetadata = keyspaceMetadata.getTable(TABLE_NAME);
if (tableMetadata != null) {
LOG.debug("Versioning column family already exists, skipping creation.");
ensureTableSchema(tableMetadata);
return;
}
LOG.info("Creating versioning column family.");
session.execute(
"CREATE TABLE " + TABLE_NAME + " ("
+ "key text PRIMARY KEY,"
+ "executed timestamp"
+ ");");
LOG.debug("Versioning column family created.");
}
示例10: ensureExists
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
static KeyspaceMetadata ensureExists(String keyspace, Session session) {
KeyspaceMetadata result = session.getCluster().getMetadata().getKeyspace(keyspace);
if (result == null || result.getTable("traces") == null) {
LOG.info("Installing schema {}", SCHEMA_RESOURCE);
applyCqlFile(keyspace, session, SCHEMA_RESOURCE);
// refresh metadata since we've installed the schema
result = session.getCluster().getMetadata().getKeyspace(keyspace);
}
return result;
}
示例11: ensureExists
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
static void ensureExists(String keyspace, Session session) {
KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null || keyspaceMetadata.getTable("traces") == null) {
LOG.info("Installing schema {}", SCHEMA);
applyCqlFile(keyspace, session, SCHEMA);
// refresh metadata since we've installed the schema
keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace);
}
if (!hasUpgrade1_defaultTtl(keyspaceMetadata)) {
LOG.info("Upgrading schema {}", UPGRADE_1);
applyCqlFile(keyspace, session, UPGRADE_1);
}
}
示例12: validateTableName
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
static void validateTableName(String tableName, KeyspaceMetadata keyspace) {
if (!Strings.isNullOrEmpty(tableName)) {
TableMetadata table = keyspace.getTable(tableName);
if (table == null) {
throw new IllegalArgumentException("table \"" + tableName + "\" does not existed!");
}
}
}
示例13: isEngineTablePresent
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
@Override
public boolean isEngineTablePresent() {
KeyspaceMetadata keyspaceMetaData = cassandraSession.getCluster()
.getMetadata()
.getKeyspace(cassandraSession.getLoggedKeyspace());
return keyspaceMetaData.getTable(ProcessDefinitionTableHandler.TABLE_NAME) != null;
}
示例14: getColumnNames
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
public List<String> getColumnNames(String keySpace, String tableName)
{
checkState(tableExists(keySpace, tableName), "table %s.%s does not exist", keySpace, tableName);
KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keySpace);
TableMetadata tableMetadata = keyspaceMetadata.getTable(tableName);
return tableMetadata.getColumns().stream().map(ColumnMetadata::getName).collect(toList());
}
示例15: tableExists
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
public boolean tableExists(String keySpace, String tableName)
{
KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keySpace);
if (keyspaceMetadata == null) {
return false;
}
return keyspaceMetadata.getTable(tableName) != null;
}