本文整理汇总了Java中com.datastax.driver.core.ColumnMetadata类的典型用法代码示例。如果您正苦于以下问题:Java ColumnMetadata类的具体用法?Java ColumnMetadata怎么用?Java ColumnMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ColumnMetadata类属于com.datastax.driver.core包,在下文中一共展示了ColumnMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareStatement
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
private PreparedStatement prepareStatement() {
List<ColumnMetadata> partkeys = cluster.getMetadata().getKeyspace(keyspaceName).getTable(tableName).getPartitionKey();
StringBuilder sb = new StringBuilder();
sb.append("SELECT COUNT(*) FROM ");
sb.append(keyspaceName).append(".").append(tableName);
sb.append(" WHERE Token(");
sb.append(partkeys.get(0).getName());
for (int i = 1; i < partkeys.size(); i++)
sb.append(", ").append(partkeys.get(i).getName());
sb.append(") > ? AND Token(");
sb.append(partkeys.get(0).getName());
for (int i = 1; i < partkeys.size(); i++)
sb.append(",").append(partkeys.get(i).getName());
sb.append(") <= ?");
debugPrint("Query: " + sb.toString(), true, 2);
return session.prepare(sb.toString()).setConsistencyLevel(consistencyLevel);
}
示例2: getTableInfo
import com.datastax.driver.core.ColumnMetadata; //导入依赖的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: parseForSpecialDataType
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
private void parseForSpecialDataType(final ColumnMetadata aColumnDefinition)
{
switch (aColumnDefinition.getType().getName()) {
case COUNTER:
counterColumns.add(aColumnDefinition.getName());
break;
case MAP:
mapColumns.add(aColumnDefinition.getName());
break;
case SET:
setColumns.add(aColumnDefinition.getName());
break;
case LIST:
listColumns.add(aColumnDefinition.getName());
break;
case UDT:
userDefinedTypeColumns.add(aColumnDefinition.getName());
break;
default:
break;
}
}
示例4: buildColumnHandle
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
private CassandraColumnHandle buildColumnHandle(ColumnMetadata columnMeta, boolean partitionKey, boolean clusteringKey, int ordinalPosition, boolean hidden)
{
CassandraType cassandraType = CassandraType.getCassandraType(columnMeta.getType().getName());
List<CassandraType> typeArguments = null;
if (cassandraType != null && cassandraType.getTypeArgumentSize() > 0) {
List<DataType> typeArgs = columnMeta.getType().getTypeArguments();
switch (cassandraType.getTypeArgumentSize()) {
case 1:
typeArguments = ImmutableList.of(CassandraType.getCassandraType(typeArgs.get(0).getName()));
break;
case 2:
typeArguments = ImmutableList.of(CassandraType.getCassandraType(typeArgs.get(0).getName()), CassandraType.getCassandraType(typeArgs.get(1).getName()));
break;
default:
throw new IllegalArgumentException("Invalid type arguments: " + typeArgs);
}
}
boolean indexed = columnMeta.getIndex() != null;
return new CassandraColumnHandle(connectorId, columnMeta.getName(), ordinalPosition, cassandraType, typeArguments, partitionKey, clusteringKey, indexed, hidden);
}
示例5: generateSpecificGet
import com.datastax.driver.core.ColumnMetadata; //导入依赖的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();
}
示例6: getSpec
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
private static ParameterSpec getSpec(ColumnMetadata column, boolean addAnnotation) {
String name = column.getName();
String paramName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
ParameterSpec.Builder param;
if (Udt.instance.isUdt(column.getType())) {
throw new IllegalArgumentException("We don't currently support UDT primary keys in the query string, field: "
+ column.getName());
} else {
param = ParameterSpec.builder(EntityGeneratorHelper.getRawType(column.getType()), paramName);
}
if(addAnnotation) {
param.addAnnotation(AnnotationSpec.builder(Param.class).addMember("value", "$S", name).build());
}
return param.addModifiers(Modifier.FINAL).build();
}
示例7: getPartitionKey
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
private String getPartitionKey(CqlDelimParser cdp, Session session) {
String keyspace = cdp.getKeyspace();
String table = cdp.getTable();
if (keyspace.startsWith("\"") && keyspace.endsWith("\""))
keyspace = keyspace.replaceAll("\"", "");
else
keyspace = keyspace.toLowerCase();
if (table.startsWith("\"") && table.endsWith("\""))
table = table.replaceAll("\"", "");
else
table = table.toLowerCase();
List<ColumnMetadata> lcm = session.getCluster().getMetadata()
.getKeyspace(keyspace).getTable(table).getPartitionKey();
String partitionKey = lcm.get(0).getName();
for (int i = 1; i < lcm.size(); i++) {
partitionKey = partitionKey + "," + lcm.get(i).getName();
}
return partitionKey;
}
示例8: addColumnsToTable
import com.datastax.driver.core.ColumnMetadata; //导入依赖的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);
}
}
}
示例9: getSchema
import com.datastax.driver.core.ColumnMetadata; //导入依赖的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;
}
示例10: fetchKeys
import com.datastax.driver.core.ColumnMetadata; //导入依赖的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());
}
}
示例11: insertQuery
import com.datastax.driver.core.ColumnMetadata; //导入依赖的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();
}
示例12: validateAdditionalFilters
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
private void validateAdditionalFilters(TableMetadata tableMetadata) {
for (Map.Entry<String, Serializable> entry : additionalFilters.entrySet()) {
/* check if there's an index specified on the provided column */
ColumnMetadata columnMetadata = tableMetadata.getColumn(entry.getKey());
if (columnMetadata == null) {
throw new DeepNoSuchFieldException("No column with name " + entry.getKey() + " has been found on " +
"table " + this.catalog + "." + this.table);
}
if (columnMetadata.getIndex() == null) {
throw new DeepIndexNotFoundException("No index has been found on column " + columnMetadata.getName()
+ " on table " + this.catalog + "." + this.table);
}
}
}
示例13: deleteEntityTableNonTransactional
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
private boolean deleteEntityTableNonTransactional(String tableName, ODataEntry entity) throws ODataServiceFault {
List<ColumnMetadata> cassandraTableMetaData = this.session.getCluster().getMetadata().getKeyspace(this.keyspace)
.getTable(tableName).getColumns();
List<String> pKeys = this.primaryKeys.get(tableName);
String query = createDeleteCQL(tableName);
List<Object> values = new ArrayList<>();
for (String column : entity.getNames()) {
if (pKeys.contains(column)) {
bindParams(column, entity.getValue(column), values, cassandraTableMetaData);
}
}
PreparedStatement statement = this.preparedStatementMap.get(query);
if (statement == null) {
statement = this.session.prepare(query);
this.preparedStatementMap.put(query, statement);
}
ResultSet result = this.session.execute(statement.bind(values.toArray()));
return result.wasApplied();
}
示例14: generateMetaData
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
private Map<String, Map<String, DataColumn>> generateMetaData() {
Map<String, Map<String, DataColumn>> metadata = new HashMap<>();
for (String tableName : this.tableList) {
Map<String, DataColumn> dataColumnMap = new HashMap<>();
for (ColumnMetadata columnMetadata : this.session.getCluster().getMetadata().getKeyspace(this.keyspace)
.getTable(tableName).getColumns()) {
DataColumn dataColumn;
if (this.primaryKeys.get(tableName).contains(columnMetadata.getName())) {
dataColumn = new DataColumn(columnMetadata.getName(),
getDataType(columnMetadata.getType().getName()), false);
} else {
dataColumn = new DataColumn(columnMetadata.getName(),
getDataType(columnMetadata.getType().getName()), true);
}
dataColumnMap.put(dataColumn.getColumnName(), dataColumn);
}
metadata.put(tableName, dataColumnMap);
}
return metadata;
}
示例15: CassandraTable
import com.datastax.driver.core.ColumnMetadata; //导入依赖的package包/类
public CassandraTable(
final Session session,
final TableMetadata table,
final ConsistencyLevel consistencyLevel,
final String bodyColumn,
final boolean ignoreCase) {
this.session = session;
this.table = table;
this.consistencyLevel = consistencyLevel;
this.bodyColumn = bodyColumn;
this.columns = table.getColumns();
this.totalColumns = this.columns.size();
this.primaryKeys = new ArrayList<String>();
for (final ColumnMetadata column : table.getPrimaryKey()) {
primaryKeys.add(column.getName());
}
this.ignoreCase = ignoreCase;
}