本文整理匯總了Java中com.datastax.driver.core.TableMetadata類的典型用法代碼示例。如果您正苦於以下問題:Java TableMetadata類的具體用法?Java TableMetadata怎麽用?Java TableMetadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TableMetadata類屬於com.datastax.driver.core包,在下文中一共展示了TableMetadata類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: get
import com.datastax.driver.core.TableMetadata; //導入依賴的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: getTableInfo
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
private TableInfo getTableInfo(
@Nonnull @NonNull final QualifiedName name,
@Nonnull @NonNull final TableMetadata tableMetadata
) {
final ImmutableList.Builder<FieldInfo> fieldInfoBuilder = ImmutableList.builder();
// TODO: Ignores clustering, primary key, index, etc columns. We need to rework TableInfo to support
for (final ColumnMetadata column : tableMetadata.getColumns()) {
final String dataType = column.getType().toString();
fieldInfoBuilder.add(
FieldInfo.builder()
.name(column.getName())
.sourceType(dataType)
.type(this.typeConverter.toMetacatType(dataType))
.build()
);
}
return TableInfo.builder()
.name(QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), tableMetadata.getName()))
.fields(fieldInfoBuilder.build())
.build();
}
示例3: existsTable
import com.datastax.driver.core.TableMetadata; //導入依賴的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;
}
}
示例4: insertRow
import com.datastax.driver.core.TableMetadata; //導入依賴的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;
}
示例5: getRowIdentifier
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
private RowIdentifier getRowIdentifier(String keyspace,String tablename, MultivaluedMap<String, String> rowParams){
String rowIdString="";
int counter =0;
TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
String primaryKeyValue="";
for (MultivaluedMap.Entry<String, List<String>> entry : rowParams.entrySet()){
String keyName = entry.getKey();
List<String> valueList = entry.getValue();
String indValue = valueList.get(0);
DataType colType = tableInfo.getColumn(entry.getKey()).getType();
String formattedValue = MusicCore.convertToCQLDataType(colType,indValue);
if(counter ==0)
primaryKeyValue = primaryKeyValue+indValue;
rowIdString = rowIdString + keyName +"="+ formattedValue;
if(counter!=rowParams.size()-1)
rowIdString = rowIdString+" AND ";
counter = counter +1;
}
return new RowIdentifier(primaryKeyValue, rowIdString);
}
示例6: createColumnFamily
import com.datastax.driver.core.TableMetadata; //導入依賴的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);
}
示例7: loadTablesFromRemote
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
public static Cluster loadTablesFromRemote(String host, int port, String cfidOverrides) throws IOException {
Map<String, UUID> cfs = parseOverrides(cfidOverrides);
Cluster.Builder builder = Cluster.builder().addContactPoints(host).withPort(port);
Cluster cluster = builder.build();
Metadata metadata = cluster.getMetadata();
IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner());
if (DatabaseDescriptor.getPartitioner() == null)
DatabaseDescriptor.setPartitionerUnsafe(partitioner);
for (com.datastax.driver.core.KeyspaceMetadata ksm : metadata.getKeyspaces()) {
if (!ksm.getName().equals("system")) {
for (TableMetadata tm : ksm.getTables()) {
String name = ksm.getName()+"."+tm.getName();
try {
CassandraUtils.tableFromCQL(
new ByteArrayInputStream(tm.asCQLQuery().getBytes()),
cfs.get(name) != null ? cfs.get(name) : tm.getId());
} catch(SyntaxException e) {
// ignore tables that we cant parse (probably dse)
logger.debug("Ignoring table " + name + " due to syntax exception " + e.getMessage());
}
}
}
}
return cluster;
}
示例8: getTableMetadata
import com.datastax.driver.core.TableMetadata; //導入依賴的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);
}
示例9: generate
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
/**
* Kicks off table generation.
*
* @param tables the cassandra table meta data
* @throws IOException if write to file fails
*/
public static void generate(Collection<TableMetadata> tables) throws IOException {
String namespaceToUse = MetaData.instance.getTableNamespace();
for (TableMetadata table : tables) {
String rawName = table.getName();
String name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, rawName);
TypeSpec.Builder tableClassBuilder = TypeSpec.classBuilder(name)
.addModifiers(Modifier.PUBLIC)
.addAnnotation(getTableAnnotation(table.getKeyspace().getName(), rawName));
addFields(tableClassBuilder, table, name);
tableClassBuilder.addJavadoc(GeneratorHelper.getJavaDocHeader("Table class for Cassandra - " + rawName, MetaData.instance.getUpdateTime()));
JavaFile javaFile = JavaFile.builder(namespaceToUse, tableClassBuilder.build()).build();
Disk.outputFile(javaFile);
}
}
示例10: generateSpecificGet
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
private static MethodSpec generateSpecificGet(TableMetadata table, ClassName entityTable, int desiredColumns) {
String query = getBaseQuery(table) + " WHERE ";
MethodSpec.Builder builder = MethodSpec.methodBuilder("getAll");
List<ColumnMetadata> columns = table.getPrimaryKey();
for(int i = 0; i < desiredColumns; i++) {
ColumnMetadata column = columns.get(i);
String name = column.getName();
String newClause = name + "=:" + name;
if(i != 0) {
newClause = " AND " + newClause;
}
query += newClause;
builder.addParameter(getSpec(column, true));
}
return builder.addModifiers(Modifier.ABSTRACT).addModifiers(Modifier.PUBLIC)
.returns(ParameterizedTypeName.get(ClassName.get(ListenableFuture.class),
ParameterizedTypeName.get(ClassName.get(Result.class), entityTable)))
.addAnnotation(AnnotationSpec.builder(Query.class).addMember("value", "$S", query).build())
.build();
}
示例11: addColumnsToTable
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
/**
* Adds all columns of column family.
* @param table Teiid table
* @param columnFamily Column family
*/
private void addColumnsToTable(MetadataFactory factory, Table table, TableMetadata columnFamily) {
for (ColumnMetadata column : columnFamily.getColumns()){
Class<?> cqlTypeToJavaClass = column.getType().asJavaClass();
Class<?> teiidRuntimeTypeFromJavaClass = TypeFacility.getRuntimeType(cqlTypeToJavaClass);
String type = TypeFacility.getDataTypeName(teiidRuntimeTypeFromJavaClass);
if (column.getType().getName().equals(com.datastax.driver.core.DataType.Name.TIMESTAMP)) {
type = TypeFacility.RUNTIME_NAMES.TIMESTAMP;
} else if (column.getType().getName().equals(com.datastax.driver.core.DataType.Name.CUSTOM)
|| column.getType().getName().equals(com.datastax.driver.core.DataType.Name.BLOB)) {
type = TypeFacility.RUNTIME_NAMES.VARBINARY;
}
Column c = factory.addColumn(column.getName(), type, table);
c.setUpdatable(true);
if (column.getIndex() != null) {
c.setSearchType(SearchType.Searchable);
}
else {
c.setSearchType(SearchType.Unsearchable);
}
}
}
示例12: getSchema
import com.datastax.driver.core.TableMetadata; //導入依賴的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;
}
示例13: fetchKeys
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
private void fetchKeys()
{
// get CF meta data
TableMetadata tableMetadata = session.getCluster()
.getMetadata()
.getKeyspace(Metadata.quote(keyspace))
.getTable(Metadata.quote(cfName));
if (tableMetadata == null)
{
throw new RuntimeException("No table metadata found for " + keyspace + "." + cfName);
}
//Here we assume that tableMetadata.getPartitionKey() always
//returns the list of columns in order of component_index
for (ColumnMetadata partitionKey : tableMetadata.getPartitionKey())
{
partitionKeys.add(partitionKey.getName());
}
}
示例14: createCrud
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
private static <T, K> DatastaxCrud<T, K> createCrud(Type target, Type keyTarget,
TableMetadata tableMetadata,
Session session,
DatastaxMapperFactory mapperFactory) {
DatastaxMapper<T> selectMapper = selectMapper(target, tableMetadata, mapperFactory);
return new DatastaxCrud<T, K>(
session.prepare(insertQuery(tableMetadata)),
session.prepare(insertQuery(tableMetadata, "TTL", "TIMESTAMP")),
session.prepare(insertQuery(tableMetadata, "TTL" )),
session.prepare(insertQuery(tableMetadata, "TIMESTAMP")),
session.prepare(readQuery(tableMetadata)),
session.prepare(deleteQuery(tableMetadata)),
session.prepare(deleteQueryWithTimestamp(tableMetadata)),
DatastaxCrudFactory.<T>insertSetter(target, tableMetadata, mapperFactory, 0),
DatastaxCrudFactory.<K>keySetter(keyTarget, tableMetadata, mapperFactory, 0),
DatastaxCrudFactory.<K>keySetter(keyTarget, tableMetadata, mapperFactory, 1),
selectMapper,
tableMetadata.getColumns().size(), session);
}
示例15: insertQuery
import com.datastax.driver.core.TableMetadata; //導入依賴的package包/類
private static String insertQuery(TableMetadata tableMetadata, String... options) {
Insert insert = QueryBuilder.insertInto(tableMetadata);
if (options != null) {
Insert.Options using = insert.using();
for (String option : options) {
if ("TTL".equals(option)) {
using.and(QueryBuilder.ttl(QueryBuilder.bindMarker()));
} else {
using.and(QueryBuilder.timestamp(QueryBuilder.bindMarker()));
}
}
}
List<ColumnMetadata> columns = tableMetadata.getColumns();
for(ColumnMetadata column : columns) {
insert.value(column.getName(), QueryBuilder.bindMarker());
}
return insert.toString();
}