本文整理匯總了Java中com.datastax.driver.core.TableMetadata.getPrimaryKey方法的典型用法代碼示例。如果您正苦於以下問題:Java TableMetadata.getPrimaryKey方法的具體用法?Java TableMetadata.getPrimaryKey怎麽用?Java TableMetadata.getPrimaryKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.TableMetadata
的用法示例。
在下文中一共展示了TableMetadata.getPrimaryKey方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: CassandraTable
import com.datastax.driver.core.TableMetadata; //導入方法依賴的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;
}
示例3: getMainSchema
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
@Override
protected Schema getMainSchema() throws MetaModelException {
final MutableSchema theSchema = new MutableSchema(getMainSchemaName());
for (final SimpleTableDef tableDef : tableDefs) {
final MutableTable table = tableDef.toTable().setSchema(theSchema);
final TableMetadata cassandraTable = cassandraCluster.getMetadata().getKeyspace(keySpaceName).getTable(table
.getName());
if (cassandraTable != null) {
final List<ColumnMetadata> primaryKeys = cassandraTable.getPrimaryKey();
for (ColumnMetadata primaryKey : primaryKeys) {
final MutableColumn column = (MutableColumn) table.getColumnByName(primaryKey.getName());
if (column != null) {
column.setPrimaryKey(true);
}
column.setNativeType(primaryKey.getType().getName().name());
}
}
theSchema.addTable(table);
}
return theSchema;
}
示例4: registerPrimaryKeyColumnDefinitions
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private void registerPrimaryKeyColumnDefinitions(final TableMetadata tableMetadata)
{
List<ColumnMetadata> primaryKeyColumns = tableMetadata.getPrimaryKey();
for (ColumnMetadata primaryColumn : primaryKeyColumns) {
columnDefinitions.put(primaryColumn.getName(), primaryColumn.getType());
pkColumnNames.add(primaryColumn.getName());
parseForSpecialDataType(primaryColumn);
}
}
示例5: getQueryConverter
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private static MethodSpec getQueryConverter(TableMetadata table) {
List<ColumnMetadata> keys = table.getPrimaryKey();
int numKeys = keys.size();
TypeMap typeToConverters = TypeMap.create();
MethodSpec.Builder builder = MethodSpec.methodBuilder("convertQueryString")
.addJavadoc("Convert query params to their Cassandra type.\n")
.addParameter(RoutingContext.class, "context", Modifier.FINAL)
.addModifiers(Modifier.PUBLIC)
.returns(Object[].class)
.addStatement("$T request = context.request()", HttpServerRequest.class)
.addCode("// if query params aren't valid a HttpResponseStatus.BAD_REQUEST will be sent with the missing field\n")
.addStatement("$T values = new Object[$L]", Object[].class, keys.size());
builder.beginControlFlow("try");
for(int i = 0; i < numKeys; i++) {
ColumnMetadata column = keys.get(i);
if(column.getType().equals(DataType.text())) {
builder.addStatement("values[$L] = request.getParam($S)", i, column.getName());
} else 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 {
String type = EntityGeneratorHelper.getRawType(column.getType()).simpleName();
builder.addCode("values[$L] = ", i)
.addCode(typeToConverters.getTypeConverter(type,
CodeBlock.builder().add("request.getParam($S)", column.getName()).build()))
.addStatement("");
}
}
return builder.nextControlFlow("catch (Exception ex)")
.addStatement("$T.processErrorResponse(ex.getMessage(), context.response(), $T.BAD_REQUEST.code())",
HttpHelper.class, HttpResponseStatus.class)
.addStatement("return null")
.endControlFlow()
.addStatement("return values").build();
}
示例6: generate
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
/**
* Kicks off DAL 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.getDalNamespace();
for (TableMetadata table : tables) {
String rawName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, table.getName());
String name = rawName + "Accessor";
ClassName entityTable = ClassName.get(MetaData.instance.getTableNamespace(), rawName);
TypeSpec.Builder accessorBuilder = TypeSpec.interfaceBuilder(name)
.addModifiers(Modifier.PUBLIC);
accessorBuilder.addAnnotation(Accessor.class);
List<ColumnMetadata> pKeyColumns = table.getPrimaryKey();
List<ColumnMetadata> partitionKeyColumns = table.getPartitionKey();
int partitionKeys = partitionKeyColumns.size();
// if there is only 1 key or there's just the partition key without clustering keys
if (isSingleValueKeyedTable(table)) {
accessorBuilder.addMethod(generateAll(table, entityTable));
} else {
// if there are clustering keys after the partition key we need to start at the partition key
int count = partitionKeys > 1 ? partitionKeys : 1;
while (count < pKeyColumns.size()) {
accessorBuilder.addMethod(generateSpecificGet(table, entityTable, count));
count++;
}
}
accessorBuilder.addJavadoc(GeneratorHelper.getJavaDocHeader("Accessor for Cassandra entity - {@link " +
ClassName.get(MetaData.instance.getTableNamespace(), rawName) + "}", MetaData.instance.getUpdateTime()));
JavaFile javaFile = JavaFile.builder(namespaceToUse, accessorBuilder.build()).build();
Disk.outputFile(javaFile);
}
}
示例7: getParametersForAccessors
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
public static List<List<ParameterSpec>> getParametersForAccessors(TableMetadata table) {
List<List<ParameterSpec>> methodParamPermutations = new ArrayList<>();
List<ColumnMetadata> pKeys = table.getPrimaryKey();
int partitionKeys = table.getPartitionKey().size();
int primaryKeys = pKeys.size();
// if there are clustering keys after the partition key we need to start at the partition key
int count = partitionKeys > 1 ? partitionKeys : 1;
while (count < primaryKeys) {
methodParamPermutations.add(getParameters(table, count));
count++;
}
return methodParamPermutations;
}
示例8: getParameters
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private static List<ParameterSpec> getParameters(TableMetadata table, int desiredColumns) {
List<ColumnMetadata> columns = table.getPrimaryKey();
List<ParameterSpec> fields = new ArrayList<>();
for(int i = 0; i < desiredColumns; i++) {
ColumnMetadata column = columns.get(i);
fields.add(getSpec(column));
}
return fields;
}
示例9: addPrimaryKey
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
/**
* Adds a primary key from columnFamily to given table.
* @param table Teiid table
* @param columnFamily
*/
private void addPrimaryKey(MetadataFactory factory, Table table, TableMetadata columnFamily) {
List<ColumnMetadata> primaryKeys = new ArrayList<ColumnMetadata>();
primaryKeys = columnFamily.getPrimaryKey();
List<String> PKNames = new ArrayList<String>();
for (ColumnMetadata columnName : primaryKeys){
PKNames.add(columnName.getName());
table.getColumnByName(columnName.getName()).setSearchType(SearchType.Searchable);
}
factory.addPrimaryKey("PK_" + columnFamily.getName(), PKNames, table); //$NON-NLS-1$
}
示例10: keySetter
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private static <K> BoundStatementMapper<K> keySetter(Type keyTarget, TableMetadata tableMetadata, DatastaxMapperFactory mapperFactory, int offset) {
SettableDataMapperBuilder<K> mapperBuilder = mapperFactory.newBuilderFrom(keyTarget);
int i = offset;
for(ColumnMetadata columnMetadata : tableMetadata.getPrimaryKey()) {
mapperBuilder.addColumn(DatastaxColumnKey.of(columnMetadata, i++));
}
return new BoundStatementMapper<K>(mapperBuilder.mapper());
}
示例11: makePrimaryKeys
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
public CassandraMetadataResultSet makePrimaryKeys(CassandraStatement statement, String schema, String tableName) throws SQLException
{
final ArrayList<MetadataRow> schemas = Lists.newArrayList();
List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces();
for(KeyspaceMetadata keyspace:keyspaces){
if(schema.equals(keyspace.getName())){
Collection<TableMetadata> tables = keyspace.getTables();
for(TableMetadata table:tables){
if(tableName.equals(table.getName())){
int seq=0;
for(ColumnMetadata col:table.getPrimaryKey()){
MetadataRow row = new MetadataRow().addEntry("TABLE_CAT", statement.connection.getCatalog())
.addEntry("TABLE_SCHEM", keyspace.getName())
.addEntry("TABLE_NAME", table.getName())
.addEntry("COLUMN_NAME", col.getName())
.addEntry("KEY_SEQ", seq+"")
.addEntry("PK_NAME", null);
schemas.add(row);
seq++;
}
}
}
}
}
CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas));
return result;
//1.TABLE_CAT String => table catalog (may be null)
//2.TABLE_SCHEM String => table schema (may be null)
//3.TABLE_NAME String => table name
//4.COLUMN_NAME String => column name
//5.KEY_SEQ short => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key).
//6.PK_NAME String => primary key name (may be null)
}
示例12: deleteQuery
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private static String deleteQuery(TableMetadata tableMetadata) {
Delete delete = QueryBuilder.delete().from(tableMetadata);
Delete.Where where = delete.where();
List<ColumnMetadata> columns = tableMetadata.getPrimaryKey();
for(ColumnMetadata column : columns) {
where.and(QueryBuilder.eq(column.getName(), QueryBuilder.bindMarker()));
}
return delete.toString();
}
示例13: deleteQueryWithTimestamp
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private static String deleteQueryWithTimestamp(TableMetadata tableMetadata) {
Delete delete = QueryBuilder.delete().from(tableMetadata);
delete.using(QueryBuilder.timestamp(QueryBuilder.bindMarker()));
Delete.Where where = delete.where();
List<ColumnMetadata> columns = tableMetadata.getPrimaryKey();
for(ColumnMetadata column : columns) {
where.and(QueryBuilder.eq(column.getName(), QueryBuilder.bindMarker()));
}
return delete.toString();
}