Search in sources :

Example 1 with CassandraMappingContext

use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.

the class CassandraBatchTemplate method insert.

/* (non-Javadoc)
	 * @see org.springframework.data.cassandra.core.CassandraBatchOperations#insert(java.lang.Iterable, org.springframework.data.cassandra.core.cql.WriteOptions)
	 */
@Override
public CassandraBatchOperations insert(Iterable<?> entities, WriteOptions options) {
    assertNotExecuted();
    Assert.notNull(entities, "Entities must not be null");
    Assert.notNull(options, "WriteOptions must not be null");
    assertNotQueryOptions(entities);
    CassandraMappingContext mappingContext = getMappingContext();
    for (Object entity : entities) {
        Assert.notNull(entity, "Entity must not be null");
        BasicCassandraPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entity.getClass());
        SimpleStatement insertQuery = getStatementFactory().insert(entity, options, persistentEntity, persistentEntity.getTableName()).build();
        this.batch.addStatement(insertQuery);
    }
    return this;
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext)

Example 2 with CassandraMappingContext

use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.

the class ReactiveCassandraBatchTemplate method doInsert.

private Collection<SimpleStatement> doInsert(Iterable<?> entities, WriteOptions options) {
    CassandraMappingContext mappingContext = getMappingContext();
    List<SimpleStatement> insertQueries = new ArrayList<>();
    for (Object entity : entities) {
        Assert.notNull(entity, "Entity must not be null");
        BasicCassandraPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entity.getClass());
        SimpleStatement insertQuery = getStatementFactory().insert(entity, options, persistentEntity, persistentEntity.getTableName()).build();
        insertQueries.add(insertQuery);
    }
    return insertQueries;
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext)

Example 3 with CassandraMappingContext

use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.

the class MappingCassandraConverterTupleIntegrationTests method setUp.

@BeforeEach
void setUp() {
    if (initialized.compareAndSet(false, true)) {
        this.session.execute("DROP TYPE IF EXISTS address;");
        this.session.execute("DROP TABLE IF EXISTS person;");
        CassandraMappingContext mappingContext = converter.getMappingContext();
        SchemaFactory schemaFactory = new SchemaFactory(converter);
        CreateUserTypeSpecification createAddress = schemaFactory.getCreateUserTypeSpecificationFor(mappingContext.getRequiredPersistentEntity(AddressUserType.class));
        this.session.execute(CreateUserTypeCqlGenerator.toCql(createAddress));
        String ddl = // 
        "CREATE TABLE person (id text, " + "tuplevalue tuple<text,int>," + // 
        "mapoftuples map<text, frozen<tuple<address, list<text>, text>>>, " + // 
        "mapoftuplevalues map<text, frozen<tuple<text, int>>>, " + // 
        "mappedtuple frozen<tuple<address, list<text>, text>>, " + // 
        "mappedtuplewithvalue frozen<tuple<address, list<text>, text>>, " + // 
        "mappedtuples list<frozen<tuple<address, list<text>, text>>>, " + "PRIMARY KEY (id));";
        this.session.execute(ddl);
    } else {
        this.session.execute("TRUNCATE person;");
    }
}
Also used : CreateUserTypeSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CassandraMappingContext

use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.

the class CustomConversionIntegrationTests method createConverter.

private static MappingCassandraConverter createConverter(Consumer<List<Converter<?, ?>>> converterCustomizer) {
    List<Converter<?, ?>> converters = new ArrayList<>();
    converterCustomizer.accept(converters);
    CustomConversions customConversions = new CassandraCustomConversions(converters);
    CassandraMappingContext mappingContext = new CassandraMappingContext();
    mappingContext.setCustomConversions(customConversions);
    mappingContext.afterPropertiesSet();
    MappingCassandraConverter converter = new MappingCassandraConverter(mappingContext);
    converter.setCustomConversions(customConversions);
    converter.afterPropertiesSet();
    return converter;
}
Also used : CustomConversions(org.springframework.data.convert.CustomConversions) ArrayList(java.util.ArrayList) Converter(org.springframework.core.convert.converter.Converter) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext)

Example 5 with CassandraMappingContext

use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.

the class CassandraQueryCreatorUnitTests method setUp.

@BeforeEach
void setUp() {
    context = new CassandraMappingContext();
    context.setUserTypeResolver(mock(UserTypeResolver.class));
    converter = new MappingCassandraConverter(context);
}
Also used : UserTypeResolver(org.springframework.data.cassandra.core.mapping.UserTypeResolver) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CassandraMappingContext (org.springframework.data.cassandra.core.mapping.CassandraMappingContext)29 BeforeEach (org.junit.jupiter.api.BeforeEach)10 Test (org.junit.jupiter.api.Test)8 MappingCassandraConverter (org.springframework.data.cassandra.core.convert.MappingCassandraConverter)8 SimpleUserTypeResolver (org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver)5 ArrayList (java.util.ArrayList)4 Bean (org.springframework.context.annotation.Bean)4 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)3 ApplicationContext (org.springframework.context.ApplicationContext)3 ReactiveEntityCallbacks (org.springframework.data.mapping.callback.ReactiveEntityCallbacks)3 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 Collection (java.util.Collection)2 Set (java.util.Set)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Produces (javax.enterprise.inject.Produces)2 SessionFactoryFactoryBean (org.springframework.data.cassandra.config.SessionFactoryFactoryBean)2 CassandraAdminTemplate (org.springframework.data.cassandra.core.CassandraAdminTemplate)2 SchemaFactory (org.springframework.data.cassandra.core.convert.SchemaFactory)2 CreateUserTypeSpecification (org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification)2 UserTypeResolver (org.springframework.data.cassandra.core.mapping.UserTypeResolver)2