當前位置: 首頁>>代碼示例>>Java>>正文


Java TableMetadata.getPrimaryKey方法代碼示例

本文整理匯總了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();

}
 
開發者ID:jtruelove,項目名稱:exovert,代碼行數:24,代碼來源:AccessorGenerator.java

示例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;
}
 
開發者ID:Stratio,項目名稱:ingestion,代碼行數:21,代碼來源:CassandraTable.java

示例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;
}
 
開發者ID:apache,項目名稱:metamodel,代碼行數:24,代碼來源:CassandraDataContext.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:10,代碼來源:AbstractUpsertOutputOperator.java

示例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();
    }
 
開發者ID:jtruelove,項目名稱:exovert,代碼行數:40,代碼來源:RestGenerator.java

示例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);
    }
}
 
開發者ID:jtruelove,項目名稱:exovert,代碼行數:44,代碼來源:AccessorGenerator.java

示例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;
}
 
開發者ID:jtruelove,項目名稱:exovert,代碼行數:16,代碼來源:AccessorGenerator.java

示例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;
}
 
開發者ID:jtruelove,項目名稱:exovert,代碼行數:11,代碼來源:AccessorGenerator.java

示例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$
}
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:17,代碼來源:CassandraMetadataProcessor.java

示例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());
}
 
開發者ID:arnaudroger,項目名稱:SimpleFlatMapper,代碼行數:9,代碼來源:DatastaxCrudFactory.java

示例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) 

	
}
 
開發者ID:adejanovski,項目名稱:cassandra-jdbc-wrapper,代碼行數:46,代碼來源:MetadataResultSets.java

示例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();
}
 
開發者ID:arnaudroger,項目名稱:SimpleFlatMapper,代碼行數:14,代碼來源:DatastaxCrudFactory.java

示例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();
}
 
開發者ID:arnaudroger,項目名稱:SimpleFlatMapper,代碼行數:16,代碼來源:DatastaxCrudFactory.java


注:本文中的com.datastax.driver.core.TableMetadata.getPrimaryKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。