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