本文整理汇总了Java中com.datastax.driver.core.ColumnMetadata.getType方法的典型用法代码示例。如果您正苦于以下问题:Java ColumnMetadata.getType方法的具体用法?Java ColumnMetadata.getType怎么用?Java ColumnMetadata.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.ColumnMetadata
的用法示例。
在下文中一共展示了ColumnMetadata.getType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureTableSchema
import com.datastax.driver.core.ColumnMetadata; //导入方法依赖的package包/类
private static void ensureTableSchema(TableMetadata tableMetadata) throws IllegalStateException {
ColumnMetadata primaryKey = tableMetadata.getPrimaryKey().get(0);
if (!primaryKey.getName().equals("key")) {
throw new IllegalStateException(String.format("The name of primary key in table [%s] should be 'key'", TABLE_NAME));
}
if (primaryKey.getType() != DataType.text()) {
throw new IllegalStateException(String.format("Primary key in table [%s] should have type 'text'", TABLE_NAME));
}
ColumnMetadata executedColumn = tableMetadata.getColumn("executed");
if (executedColumn == null) {
throw new IllegalStateException(String.format("Cannot find column 'executed' in table [%s]", TABLE_NAME));
}
if (executedColumn.getType() != DataType.timestamp()) {
throw new IllegalStateException(String.format("Column 'executed' in table [%s] should have type 'timestamp'", TABLE_NAME));
}
}
示例2: addFields
import com.datastax.driver.core.ColumnMetadata; //导入方法依赖的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));
}
示例3: of
import com.datastax.driver.core.ColumnMetadata; //导入方法依赖的package包/类
public static DatastaxColumnKey of(ColumnMetadata metaData, int column) {
return new DatastaxColumnKey(metaData.getName(), column , metaData.getType());
}
示例4: getRelDataType
import com.datastax.driver.core.ColumnMetadata; //导入方法依赖的package包/类
RelProtoDataType getRelDataType(String columnFamily, boolean view) {
List<ColumnMetadata> columns;
if (view) {
columns = getKeyspace().getMaterializedView(columnFamily).getColumns();
} else {
columns = getKeyspace().getTable(columnFamily).getColumns();
}
// Temporary type factory, just for the duration of this method. Allowable
// because we're creating a proto-type, not a type; before being used, the
// proto-type will be copied into a real type factory.
final RelDataTypeFactory typeFactory =
new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
for (ColumnMetadata column : columns) {
final String columnName = column.getName();
final DataType type = column.getType();
// TODO: This mapping of types can be done much better
SqlTypeName typeName = SqlTypeName.ANY;
if (type == DataType.uuid() || type == DataType.timeuuid()) {
// We currently rely on this in CassandraFilter to detect UUID columns.
// That is, these fixed length literals should be unquoted in CQL.
typeName = SqlTypeName.CHAR;
} else if (type == DataType.ascii() || type == DataType.text()
|| type == DataType.varchar()) {
typeName = SqlTypeName.VARCHAR;
} else if (type == DataType.cint() || type == DataType.varint()) {
typeName = SqlTypeName.INTEGER;
} else if (type == DataType.bigint()) {
typeName = SqlTypeName.BIGINT;
} else if (type == DataType.cdouble() || type == DataType.cfloat()
|| type == DataType.decimal()) {
typeName = SqlTypeName.DOUBLE;
}
fieldInfo.add(columnName, typeFactory.createSqlType(typeName)).nullable(true);
}
return RelDataTypeImpl.proto(fieldInfo.build());
}