Search in sources :

Example 1 with CreateTableSpecification

use of org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification in project spring-data-cassandra by spring-projects.

the class IndexCreationIntegrationTests method shouldCreateSecondaryIndex.

@Test
void shouldCreateSecondaryIndex() throws InterruptedException {
    BasicCassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(WithSecondaryIndex.class);
    CreateTableSpecification createTable = schemaFactory.getCreateTableSpecificationFor(entity);
    List<CreateIndexSpecification> createIndexes = schemaFactory.getCreateIndexSpecificationsFor(entity);
    session.execute(CreateTableCqlGenerator.toCql(createTable));
    createIndexes.forEach(it -> session.execute(CreateIndexCqlGenerator.toCql(it)));
    // index creation is async so we do poor man's sync to await completion
    Thread.sleep(500);
    TableMetadata metadata = getMetadata(createTable.getName());
    assertThat(metadata.getIndexes().get(CqlIdentifier.fromCql("firstname_index"))).isNotNull();
    assertThat(metadata.getIndexes().get(CqlIdentifier.fromCql("withsecondaryindex_map_idx"))).isNotNull();
}
Also used : CreateTableSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) CreateIndexSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification) Test(org.junit.jupiter.api.Test)

Example 2 with CreateTableSpecification

use of org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification in project spring-data-cassandra by spring-projects.

the class IndexCreationIntegrationTests method shouldCreateSasiIndex.

@Test
void shouldCreateSasiIndex() throws InterruptedException {
    BasicCassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(WithSasiIndex.class);
    CreateTableSpecification createTable = schemaFactory.getCreateTableSpecificationFor(entity);
    List<CreateIndexSpecification> createIndexes = schemaFactory.getCreateIndexSpecificationsFor(entity);
    session.execute(CreateTableCqlGenerator.toCql(createTable));
    createIndexes.forEach(it -> session.execute(CreateIndexCqlGenerator.toCql(it)));
    // index creation is async so we do poor man's sync to await completion
    Thread.sleep(500);
    TableMetadata metadata = getMetadata(createTable.getName());
    assertThat(metadata.getIndexes().get(CqlIdentifier.fromCql("withsasiindex_firstname_idx"))).isNotNull();
}
Also used : CreateTableSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) CreateIndexSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification) Test(org.junit.jupiter.api.Test)

Example 3 with CreateTableSpecification

use of org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification in project spring-data-cassandra by spring-projects.

the class CassandraCompositePrimaryKeyUnitTests method validateMappingInfo.

// DATACASS-507
@Test
void validateMappingInfo() {
    Field field = ReflectionUtils.findField(TypeWithCompositeKey.class, "id");
    CassandraPersistentProperty property = new BasicCassandraPersistentProperty(Property.of(ClassTypeInformation.from(TypeWithCompositeKey.class), field), entity, CassandraSimpleTypeHolder.HOLDER);
    assertThat(property.isIdProperty()).isTrue();
    assertThat(property.isCompositePrimaryKey()).isTrue();
    CreateTableSpecification spec = schemaFactory.getCreateTableSpecificationFor(entity);
    List<ColumnSpecification> partitionKeyColumns = spec.getPartitionKeyColumns();
    assertThat(partitionKeyColumns).hasSize(1);
    ColumnSpecification partitionKeyColumn = partitionKeyColumns.get(0);
    assertThat(partitionKeyColumn.getName()).hasToString("z");
    assertThat(partitionKeyColumn.getKeyType()).isEqualTo(PrimaryKeyType.PARTITIONED);
    assertThat(partitionKeyColumn.getType()).isEqualTo(DataTypes.TEXT);
    List<ColumnSpecification> clusteredKeyColumns = spec.getClusteredKeyColumns();
    assertThat(clusteredKeyColumns).hasSize(1);
    ColumnSpecification clusteredKeyColumn = clusteredKeyColumns.get(0);
    assertThat(clusteredKeyColumn.getName()).hasToString("a");
    assertThat(clusteredKeyColumn.getKeyType()).isEqualTo(PrimaryKeyType.CLUSTERED);
    assertThat(partitionKeyColumn.getType()).isEqualTo(DataTypes.TEXT);
}
Also used : CreateTableSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification) Field(java.lang.reflect.Field) ColumnSpecification(org.springframework.data.cassandra.core.cql.keyspace.ColumnSpecification) Test(org.junit.jupiter.api.Test)

Example 4 with CreateTableSpecification

use of org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification in project spring-data-cassandra by spring-projects.

the class SchemaFactoryUnitTests method createTableSpecificationShouldConsiderCustomTableName.

// DATACASS-678
@Test
void createTableSpecificationShouldConsiderCustomTableName() {
    CqlIdentifier customTableName = CqlIdentifier.fromCql("my_custom_came");
    CassandraPersistentEntity<?> persistentEntity = ctx.getRequiredPersistentEntity(Employee.class);
    CreateTableSpecification specification = schemaFactory.getCreateTableSpecificationFor(persistentEntity, customTableName);
    assertThat(specification).isNotNull();
    assertThat(specification.getName()).isEqualTo(customTableName);
}
Also used : CreateTableSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Test(org.junit.jupiter.api.Test)

Example 5 with CreateTableSpecification

use of org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification in project spring-data-cassandra by spring-projects.

the class SchemaFactoryUnitTests method columnsShouldMapToDecimal.

// DATACASS-296
@Test
void columnsShouldMapToDecimal() {
    CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
    assertThat(getColumnType("bigDecimal", specification)).isEqualTo(DataTypes.DECIMAL);
}
Also used : CreateTableSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification) Test(org.junit.jupiter.api.Test)

Aggregations

CreateTableSpecification (org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification)43 Test (org.junit.jupiter.api.Test)41 ColumnSpecification (org.springframework.data.cassandra.core.cql.keyspace.ColumnSpecification)10 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)5 DataType (com.datastax.oss.driver.api.core.type.DataType)5 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)4 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)3 TableOption (org.springframework.data.cassandra.core.cql.keyspace.TableOption)3 DataTypes (com.datastax.oss.driver.api.core.type.DataTypes)2 SetType (com.datastax.oss.driver.api.core.type.SetType)2 Assertions (org.assertj.core.api.Assertions)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Ordering (org.springframework.data.cassandra.core.cql.Ordering)2 CreateIndexSpecification (org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification)2 AbstractKeyspaceCreatingIntegrationTests (org.springframework.data.cassandra.test.util.AbstractKeyspaceCreatingIntegrationTests)2 ListType (com.datastax.oss.driver.api.core.type.ListType)1 Field (java.lang.reflect.Field)1 LinkedHashMap (java.util.LinkedHashMap)1 Option (org.springframework.data.cassandra.core.cql.keyspace.Option)1 CachingOption (org.springframework.data.cassandra.core.cql.keyspace.TableOption.CachingOption)1