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();
}
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();
}
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);
}
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);
}
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);
}
Aggregations