Search in sources :

Example 1 with ColumnMetadata

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();
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata)

Example 2 with ColumnMetadata

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();
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata)

Example 3 with ColumnMetadata

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);
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) ArrayList(java.util.ArrayList)

Example 4 with ColumnMetadata

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);
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) Test(org.testng.annotations.Test) CassandraVersion(com.datastax.driver.core.utils.CassandraVersion)

Example 5 with ColumnMetadata

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();
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Aggregations

ColumnMetadata (com.datastax.driver.core.ColumnMetadata)37 Test (org.testng.annotations.Test)11 TableMetadata (com.datastax.driver.core.TableMetadata)8 CassandraVersion (com.datastax.driver.core.utils.CassandraVersion)8 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 AbstractTableMetadata (com.datastax.driver.core.AbstractTableMetadata)2 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)2 ByteBuffer (java.nio.ByteBuffer)2 BoundStatementMapper (org.simpleflatmapper.datastax.BoundStatementMapper)2 Cluster (com.datastax.driver.core.Cluster)1 DataType (com.datastax.driver.core.DataType)1 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)1 RegularStatement (com.datastax.driver.core.RegularStatement)1 EntityWithCompositeKey (com.datastax.driver.mapping.entity.EntityWithCompositeKey)1 EntityWithIndexes (com.datastax.driver.mapping.entity.EntityWithIndexes)1 EntityWithTimeUUID (com.datastax.driver.mapping.entity.EntityWithTimeUUID)1 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)1