Search in sources :

Example 1 with StatementFactory

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

the class MappingCassandraConverterTupleIntegrationTests method shouldInsertRowWithComplexTuple.

// DATACASS-523
@Test
void shouldInsertRowWithComplexTuple() {
    Person person = new Person();
    person.setId("foo");
    AddressUserType userType = new AddressUserType();
    userType.setZip("myzip");
    MappedTuple tuple = new MappedTuple();
    tuple.setAddressUserType(userType);
    tuple.setCurrency(Arrays.asList(Currency.getInstance("EUR"), Currency.getInstance("USD")));
    tuple.setName("bar");
    person.setMappedTuple(tuple);
    person.setMappedTuples(Collections.singletonList(tuple));
    StatementFactory statementFactory = new StatementFactory(new UpdateMapper(converter));
    StatementBuilder<RegularInsert> insert = statementFactory.insert(person, WriteOptions.empty());
    this.session.execute(insert.build());
}
Also used : StatementFactory(org.springframework.data.cassandra.core.StatementFactory) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) AbstractSpringDataEmbeddedCassandraIntegrationTest(org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with StatementFactory

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

the class MappingCassandraConverterUDTUnitTests method shouldWriteMappedUdt.

// DATACASS-172
@Test
void shouldWriteMappedUdt() {
    AddressUserType addressUserType = prepareAddressUserType();
    AddressBook addressBook = new AddressBook();
    addressBook.setId("1");
    addressBook.setCurrentaddress(addressUserType);
    SimpleStatement statement = new StatementFactory(converter).insert(addressBook, WriteOptions.empty()).build(StatementBuilder.ParameterHandling.INLINE);
    assertThat(statement.getQuery()).isEqualTo("INSERT INTO addressbook (currentaddress,id) " + "VALUES ({zip:'69469',city:'Weinheim',streetlines:['Heckenpfad','14']},'1')");
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) StatementFactory(org.springframework.data.cassandra.core.StatementFactory) Test(org.junit.jupiter.api.Test)

Example 3 with StatementFactory

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

the class MappingCassandraConverterUDTUnitTests method shouldWriteCompositeUdtPkClass.

// #1137
@Test
void shouldWriteCompositeUdtPkClass() {
    WithCompositePrimaryKeyClassWithUdt object = prepareCompositePrimaryKeyClassWithUdt();
    SimpleStatement statement = new StatementFactory(converter).insert(object, WriteOptions.empty()).build(StatementBuilder.ParameterHandling.INLINE);
    assertThat(statement.getQuery()).isEqualTo("INSERT INTO withcompositeprimarykeyclasswithudt (id,addressusertype,currency) " + "VALUES ('foo',{zip:'69469',city:'Weinheim',streetlines:['Heckenpfad','14']},{currency:'EUR'})");
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) StatementFactory(org.springframework.data.cassandra.core.StatementFactory) Test(org.junit.jupiter.api.Test)

Example 4 with StatementFactory

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

the class MappingCassandraConverterUDTUnitTests method shouldWriteCompositeUdtPk.

// #1137
@Test
void shouldWriteCompositeUdtPk() {
    AddressUserType addressUserType = prepareAddressUserType();
    WithCompositePrimaryKey withUdt = new WithCompositePrimaryKey();
    withUdt.addressUserType = addressUserType;
    withUdt.id = "foo";
    SimpleStatement statement = new StatementFactory(converter).insert(withUdt, WriteOptions.empty()).build(StatementBuilder.ParameterHandling.INLINE);
    assertThat(statement.getQuery()).isEqualTo("INSERT INTO withcompositeprimarykey (id,addressusertype) " + "VALUES ('foo',{zip:'69469',city:'Weinheim',streetlines:['Heckenpfad','14']})");
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) StatementFactory(org.springframework.data.cassandra.core.StatementFactory) Test(org.junit.jupiter.api.Test)

Example 5 with StatementFactory

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

the class MappingCassandraConverterUDTUnitTests method shouldWriteUdtListWithCustomConversion.

// DATACASS-172, DATACASS-400
@Test
void shouldWriteUdtListWithCustomConversion() {
    Bank bank = new Bank(null, null, Collections.singletonList(new Currency("EUR")));
    SimpleStatement statement = new StatementFactory(converter).insert(bank, WriteOptions.empty()).build(StatementBuilder.ParameterHandling.INLINE);
    assertThat(statement.getQuery()).isEqualTo("INSERT INTO bank (othercurrencies) VALUES ([{currency:'EUR'}])");
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) StatementFactory(org.springframework.data.cassandra.core.StatementFactory) Test(org.junit.jupiter.api.Test)

Aggregations

StatementFactory (org.springframework.data.cassandra.core.StatementFactory)15 Test (org.junit.jupiter.api.Test)14 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)12 RegularInsert (com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)3 AbstractSpringDataEmbeddedCassandraIntegrationTest (org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest)3 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)2 Row (com.datastax.oss.driver.api.core.cql.Row)2 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)2 TupleType (com.datastax.oss.driver.api.core.type.TupleType)2 UpdateMapper (org.springframework.data.cassandra.core.convert.UpdateMapper)1 Query (org.springframework.data.cassandra.core.query.Query)1 PartTree (org.springframework.data.repository.query.parser.PartTree)1