use of com.datastax.driver.core.ColumnMetadata in project SimpleFlatMapper by arnaudroger.
the class DatastaxCrudFactory method selectMapper.
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();
}
use of com.datastax.driver.core.ColumnMetadata in project SimpleFlatMapper by arnaudroger.
the class DatastaxCrudFactory method insertQuery.
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();
}
use of com.datastax.driver.core.ColumnMetadata in project teiid by teiid.
the class CassandraMetadataProcessor method addPrimaryKey.
/**
* 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 = columnFamily.getPrimaryKey();
List<String> names = new ArrayList<String>();
for (ColumnMetadata columnName : primaryKeys) {
names.add(columnName.getName());
table.getColumnByName(columnName.getName()).setSearchType(SearchType.Searchable);
}
// $NON-NLS-1$
factory.addPrimaryKey("PK_" + columnFamily.getName(), names, table);
}
use of com.datastax.driver.core.ColumnMetadata in project java-driver by datastax.
the class IndexMetadataTest method should_create_metadata_for_values_index_on_mixed_case_column.
@Test(groups = "short")
@CassandraVersion(value = "2.1", description = "index names with quoted identifiers and collection indexes not supported until 2.1")
public void should_create_metadata_for_values_index_on_mixed_case_column() {
// 3.0 assumes the 'values' keyword if index on a collection
String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (values(\"MixedCaseColumn\"));", keyspace) : String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (\"MixedCaseColumn\");", keyspace);
session().execute(createValuesIndex);
ColumnMetadata column = getColumn("\"MixedCaseColumn\"");
IndexMetadata index = getIndex("\"MixedCaseIndex\"");
assertThat(index).hasName("MixedCaseIndex").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"").hasKind(COMPOSITES).asCqlQuery(createValuesIndex);
assertThat((TableMetadata) column.getParent()).hasIndex(index);
}
use of com.datastax.driver.core.ColumnMetadata in project java-driver by datastax.
the class IndexMetadataTest method should_parse_with_null_string_index_options.
/**
* Validates a special case where a 'KEYS' index was created using thrift. In this particular case the index lacks
* index_options, however the index_options value is a 'null' string rather then a null value.
*
* @test_category metadata
* @expected_result Index properly parsed and is present.
* @jira_ticket JAVA-834
* @since 2.0.11, 2.1.7
*/
@Test(groups = "short")
public void should_parse_with_null_string_index_options() {
TableMetadata table = getTable("indexing");
List<ByteBuffer> data = ImmutableList.of(// column name 'parent_path'
wrap("b@706172656e745f70617468"), // component index (null)
ByteBuffer.allocate(0), // kind
wrap("regular"), // index name
wrap("cfs_archive_parent_path"), // index type
wrap("KEYS"), // validator
wrap("org.apache.cassandra.db.marshal.BytesType"), // index options
wrap("null"));
Row row = ArrayBackedRow.fromData(legacyColumnDefs, M3PToken.FACTORY, cluster().getConfiguration().getProtocolOptions().getProtocolVersion(), data);
Raw raw = Raw.fromRow(row, VersionNumber.parse("2.1"));
ColumnMetadata column = ColumnMetadata.fromRaw(table, raw, DataType.blob());
IndexMetadata index = IndexMetadata.fromLegacy(column, raw);
assertThat(index).isNotNull().hasName("cfs_archive_parent_path").isNotCustomIndex().hasTarget("\"b@706172656e745f70617468\"").hasKind(KEYS).asCqlQuery(String.format("CREATE INDEX cfs_archive_parent_path ON %s.indexing (\"b@706172656e745f70617468\");", keyspace));
// While the index type is KEYS, since it lacks index_options it does not get considered.
assertThat(index.getOption(IndexMetadata.INDEX_KEYS_OPTION_NAME)).isNull();
}
Aggregations