use of org.springframework.data.cassandra.core.CassandraAdminTemplate in project spring-data-cassandra by spring-projects.
the class SessionFactoryFactoryBean method performSchemaActions.
@SuppressWarnings("all")
private void performSchemaActions(boolean drop, boolean dropUnused, boolean ifNotExists) throws Exception {
CassandraAdminOperations adminOperations = new CassandraAdminTemplate(getObject(), this.converter);
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(this.converter.getMappingContext(), adminOperations);
if (drop) {
CassandraPersistentEntitySchemaDropper schemaDropper = new CassandraPersistentEntitySchemaDropper(this.converter.getMappingContext(), adminOperations);
schemaDropper.dropTables(dropUnused);
schemaDropper.dropUserTypes(dropUnused);
}
schemaCreator.createUserTypes(ifNotExists);
schemaCreator.createTables(ifNotExists);
schemaCreator.createIndexes(ifNotExists);
}
use of org.springframework.data.cassandra.core.CassandraAdminTemplate in project spring-data-cassandra by spring-projects.
the class CassandraTemplateProducer method createCassandraOperations.
@Produces
@ApplicationScoped
public CassandraOperations createCassandraOperations(CqlSession session) throws Exception {
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(session));
mappingContext.afterPropertiesSet();
MappingCassandraConverter cassandraConverter = new MappingCassandraConverter(mappingContext);
cassandraConverter.afterPropertiesSet();
return new CassandraAdminTemplate(session, cassandraConverter);
}
use of org.springframework.data.cassandra.core.CassandraAdminTemplate in project spring-data-cassandra by spring-projects.
the class CassandraOperationsProducer method createCassandraOperations.
@Produces
@ApplicationScoped
public CassandraOperations createCassandraOperations(CqlSession session) throws Exception {
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(session, CqlIdentifier.fromCql(KEYSPACE_NAME)));
mappingContext.setInitialEntitySet(Collections.singleton(User.class));
mappingContext.afterPropertiesSet();
MappingCassandraConverter cassandraConverter = new MappingCassandraConverter(mappingContext);
CassandraAdminTemplate cassandraTemplate = new CassandraAdminTemplate(session, cassandraConverter);
CreateKeyspaceSpecification createKeyspaceSpecification = CreateKeyspaceSpecification.createKeyspace(KEYSPACE_NAME).ifNotExists();
cassandraTemplate.getCqlOperations().execute(CreateKeyspaceCqlGenerator.toCql(createKeyspaceSpecification));
cassandraTemplate.getCqlOperations().execute("USE " + KEYSPACE_NAME);
CassandraPersistentEntitySchemaDropper schemaDropper = new CassandraPersistentEntitySchemaDropper(mappingContext, cassandraTemplate);
schemaDropper.dropTables(false);
schemaDropper.dropUserTypes(false);
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(mappingContext, cassandraTemplate);
schemaCreator.createUserTypes(false);
schemaCreator.createTables(false);
for (CassandraPersistentEntity<?> entity : cassandraTemplate.getConverter().getMappingContext().getTableEntities()) {
cassandraTemplate.truncate(entity.getType());
}
return cassandraTemplate;
}
use of org.springframework.data.cassandra.core.CassandraAdminTemplate in project spring-data-cassandra by spring-projects.
the class CqlSessionFactoryBean method createTables.
/**
* Perform schema actions.
*
* @param drop {@literal true} to drop types/tables.
* @param dropUnused {@literal true} to drop unused types/tables (i.e. types/tables not known to be used by the
* {@link CassandraMappingContext}).
* @param ifNotExists {@literal true} to perform fail-safe creations by adding {@code IF NOT EXISTS} to each creation
* statement.
*/
protected void createTables(boolean drop, boolean dropUnused, boolean ifNotExists) {
CassandraAdminTemplate adminTemplate = new CassandraAdminTemplate(this.session, this.converter);
performSchemaActions(drop, dropUnused, ifNotExists, adminTemplate);
}
Aggregations