本文整理匯總了Java中com.datastax.driver.core.TableMetadata.getColumns方法的典型用法代碼示例。如果您正苦於以下問題:Java TableMetadata.getColumns方法的具體用法?Java TableMetadata.getColumns怎麽用?Java TableMetadata.getColumns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.TableMetadata
的用法示例。
在下文中一共展示了TableMetadata.getColumns方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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);
}
}
}
示例3: 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;
}
示例4: 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();
}
示例5: 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;
}
示例6: registerNonPKColumnDefinitions
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private void registerNonPKColumnDefinitions(final TableMetadata tableMetadata)
{
List<ColumnMetadata> colInfoForTable = tableMetadata.getColumns();
for (ColumnMetadata aColumnDefinition : colInfoForTable) {
if (aColumnDefinition.getType().isCollection()) {
collectionColumns.add(aColumnDefinition.getName());
}
if (!pkColumnNames.contains(aColumnDefinition.getName())) {
columnDefinitions.put(aColumnDefinition.getName(), aColumnDefinition.getType());
regularColumns.add(aColumnDefinition.getName());
}
parseForSpecialDataType(aColumnDefinition);
}
}
示例7: addFields
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
/**
* Add fields to the class spec.
*/
private static void addFields(TypeSpec.Builder builder, TableMetadata tableMetadata, String className) {
Map<String, Integer> partitionKeys = getMapOfKeys(tableMetadata.getPartitionKey());
Map<String, Integer> clusteringKeys = getMapOfKeys(tableMetadata.getClusteringColumns());
List<String> fields = new ArrayList<>();
for (ColumnMetadata column : tableMetadata.getColumns()) {
DataType type = column.getType();
String name = column.getName();
List<AnnotationSpec> extraAnnotations = new ArrayList<>();
if(partitionKeys.containsKey(name)) {
extraAnnotations.add(EntityGeneratorHelper.getPartitionKeyAnnotation(partitionKeys.get(name)));
}
if(clusteringKeys.containsKey(name)) {
extraAnnotations.add(EntityGeneratorHelper.getClusteringAnnotation(clusteringKeys.get(name)));
}
builder.addField(EntityGeneratorHelper.getFieldSpec(name, type, false, extraAnnotations));
builder.addMethod(EntityGeneratorHelper.getSetter(name, type));
builder.addMethod(EntityGeneratorHelper.getGetter(name, type));
fields.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name));
}
builder.addMethod(EntityGeneratorHelper.getToString(fields, className));
}
示例8: selectMapper
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private static <T> DatastaxMapper<T> selectMapper(Type target, TableMetadata tableMetadata, DatastaxMapperFactory mapperFactory) {
DatastaxMapperBuilder<T> mapperBuilder = mapperFactory.newBuilder(target);
int i = 0;
for(ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
mapperBuilder.addMapping(DatastaxColumnKey.of(columnMetadata, i++));
}
return mapperBuilder.mapper();
}
示例9: insertSetter
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private static <T> BoundStatementMapper<T> insertSetter(Type target, TableMetadata tableMetadata, DatastaxMapperFactory mapperFactory, int offset) {
SettableDataMapperBuilder<T> mapperBuilder = mapperFactory.newBuilderFrom(target);
int i = offset;
for(ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
mapperBuilder.addColumn(DatastaxColumnKey.of(columnMetadata, i++));
}
return new BoundStatementMapper<T>(mapperBuilder.mapper());
}
示例10: loadColumnNames
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private static ImmutableSet<String> loadColumnNames(TableMetadata tableMetadata) {
final Set<String> columnNames = Sets.newHashSet();
for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
columnNames.add(columnMetadata.getName());
}
return ImmutableSet.copyOf(columnNames);
}
示例11: getLuceneIndex
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
/**
* Retrieve the column name for the lucene indexes. Null if there is no lucene index.
*
* @return Lucene index; null, if doesn't exist.
*/
private String getLuceneIndex() {
String indexName = "";
TableMetadata tableMetadata = config.fetchTableMetadata();
List<ColumnMetadata> columns = tableMetadata.getColumns();
for (ColumnMetadata column : columns) {
if (column.getIndex() != null) {
if (column.getIndex().isCustomIndex()) {
indexName = column.getName();
}
}
}
return indexName;
}
示例12: refreshTablenames
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
public void refreshTablenames() {
Collection<TableMetadata> tableMetadatas = session.getCluster().getMetadata()
.getKeyspace(STREAMING.STREAMING_KEYSPACE_NAME).getTables();
tablenames = new HashMap<>();
for (TableMetadata tableMetadata : tableMetadatas) {
Set<String> columns = new HashSet<>();
for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
columns.add(columnMetadata.getName());
}
tablenames.put(tableMetadata.getName(), columns.hashCode());
}
}
示例13: detectTable
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
/**
* Performs an analysis of an available table in Cassandra.
*
* @param tableMetaData
* the table meta data
* @return a table definition for cassandra.
*/
public static SimpleTableDef detectTable(TableMetadata tableMetaData) {
final List<ColumnMetadata> columns = tableMetaData.getColumns();
final String[] columnNames = new String[columns.size()];
final ColumnType[] columnTypes = new ColumnType[columns.size()];
int i = 0;
for (final ColumnMetadata column : columns) {
columnNames[i] = column.getName();
columnTypes[i] = getColumnTypeFromMetaDataField(column.getType().getName());
i++;
}
return new SimpleTableDef(tableMetaData.getName(), columnNames, columnTypes);
}
示例14: setTableFieldCombo
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
private void setTableFieldCombo() {
Runnable fieldLoader = new Runnable() {
@Override
public void run() {
if (!shell.isDisposed()) {
String nodes = transMeta.environmentSubstitute(hostText.getText());
String port_s = transMeta.environmentSubstitute(portText.getText());
String username = transMeta.environmentSubstitute(userText.getText());
String password = transMeta.environmentSubstitute(passText.getText());
String keyspace = transMeta.environmentSubstitute(keyspaceText.getText());
Boolean withSSL = sslenabledBut.getSelection();
String truststorefile = transMeta.environmentSubstitute(truststorefileText.getText());
String truststorepass = transMeta.environmentSubstitute(truststorepassText.getText());
ConnectionCompression compression = ConnectionCompression.fromString(wCompression.getText());
String columnFamily = columnFamilyCombo.getText();
ciFields[0].setComboValues(new String[0]);
if (!Const.isEmpty(columnFamily)) {
String[] fieldNames = null;
try {
connection = Utils.connect(nodes, port_s, username, password, keyspace, withSSL,
truststorefile, truststorepass, compression);
Cluster cluster = connection.getSession().getCluster();
Metadata clusterMeta = cluster != null ? cluster.getMetadata() : null;
KeyspaceMetadata keyspaceMeta = clusterMeta != null ? clusterMeta.getKeyspace(keyspace) : null;
TableMetadata tableMeta = keyspaceMeta != null ? keyspaceMeta.getTable(columnFamily) : null;
if (tableMeta != null) {
List<ColumnMetadata> column = tableMeta.getColumns();
Iterator<ColumnMetadata> iter = column.iterator();
fieldNames = new String[column.size()];
int i = 0;
while (iter.hasNext()) {
fieldNames[(i++)] = iter.next().getName();
}
}
} catch (Exception localException) {
localException.printStackTrace();
}
if (!fieldsList.isDisposed()) {
ciFields[0].setComboValues(fieldNames);
}
}
if (connection != null)
connection.release();
}
}
};
this.shell.getDisplay().asyncExec(fieldLoader);
}
示例15: init
import com.datastax.driver.core.TableMetadata; //導入方法依賴的package包/類
public void init(final String keyspace, final String columnFamily) {
this.keyspace = keyspace;
this.columnFamily = columnFamily;
// connect to the cluster
Cluster.Builder clusterBuilder = Cluster.builder();
clusterBuilder.addContactPoints(host);
if (port != -1) {
clusterBuilder.withPort(port);
}
// ask for some metadata
logger.info("getting cluster metadata for {}.{}", keyspace, columnFamily);
final TableMetadata tableMetadata;
try (final Cluster cluster = clusterBuilder.build()) {
Metadata clusterMetadata = cluster.getMetadata();
KeyspaceMetadata keyspaceMetadata = clusterMetadata.getKeyspace('"' + keyspace + '"');
tableMetadata = keyspaceMetadata.getTable('"' + columnFamily + '"');
cqlSchema = tableMetadata.asCQLQuery();
partitionerClass = clusterMetadata.getPartitioner();
Class.forName(partitionerClass);
numClusterNodes = clusterMetadata.getAllHosts().size();
columns = tableMetadata.getColumns();
} catch (ClassNotFoundException cnfe) {
throw new CrunchRuntimeException("No such partitioner: " + partitionerClass, cnfe);
} catch (NullPointerException npe) {
String msg = String.format("No such keyspace/table: %s/%s", keyspace, columnFamily);
throw new CrunchRuntimeException(msg, npe);
}
// map the partition key columns
final List<ColumnMetadata> partitionKeyColumns = tableMetadata.getPartitionKey();
partitionKeyIndexes = new int[partitionKeyColumns.size()];
for (int i = 0; i < partitionKeyColumns.size(); i++) {
final String keyColName = partitionKeyColumns.get(i).getName();
int j;
for (j = 0; j < columns.size(); j++) {
if (columns.get(j).getName().equals(keyColName)) {
partitionKeyIndexes[i] = j;
logger.info("partition key column {} index {}", keyColName, j);
break;
}
}
if (j == columns.size()) {
throw new CrunchRuntimeException("no matching column for key " + keyColName);
}
}
}