use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method olapWithOrderBy.
@Test
void olapWithOrderBy() {
assumeTrue(dialect.supportsOrderByInOlap(), dialect.getClass().getSimpleName() + " does not support row_number() with ORDER BY.");
Database database = testDatabase(dataSource, dialect);
Tuple2<Long, Long> inserted = insertSalespeople(database, 5);
List<Tuple3<Long, Integer, Long>> result = database.from(SalespersonRow.class).select(SalespersonRow::salespersonId).comma(Olap.rowNumber().orderBy(SalespersonRow::salespersonId, DESC)).comma(Olap.sum(SalespersonRow::salespersonId).orderBy(SalespersonRow::salespersonId, ASC)).where(SalespersonRow::salespersonId).isBetween(inserted.item1()).and(inserted.item2()).orderBy(SalespersonRow::salespersonId).list();
assertThat(result, hasSize(5));
assertThat(result.get(0), is(Tuple.of(inserted.item1(), 5, inserted.item1())));
assertThat(result.get(4), is(Tuple.of(inserted.item2(), 1, LongStream.range(inserted.item1(), inserted.item2() + 1).reduce((x, y) -> x + y).orElse(0))));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method sequence.
@Test
void sequence() {
Database database = testDatabase(dataSource, dialect);
Sequence<Integer> widgetSeq = database.sequence("widget_seq");
long salespersonId = newId();
int seq1 = widgetSeq.single();
SalespersonRow salesPerson = SalespersonRow.newBuilder().salespersonId(salespersonId).firstName("Terry").surname("McCann").numberOfSales(seq1).build();
database.insert(salesPerson);
database.update(SalespersonRow.class).set(SalespersonRow::numberOfSales).to(widgetSeq.nextVal()).where(SalespersonRow::salespersonId).isEqualTo(literal(salespersonId)).execute();
int seq2 = database.from(SalespersonRow.class).select(SalespersonRow::numberOfSales).where(SalespersonRow::salespersonId).isEqualTo(literal(salespersonId)).single();
assertThat(seq2, greaterThan(seq1));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method fetchFirst.
@Test
void fetchFirst() {
Database database = testDatabase(dataSource);
Tuple2<Long, Long> inserted = insertSalespeople(database, 10);
List<SalespersonRow> fullList = database.from(SalespersonRow.class).where(SalespersonRow::salespersonId).isBetween(inserted.item1()).and(inserted.item2()).list();
List<SalespersonRow> reducedList = database.from(SalespersonRow.class).where(SalespersonRow::salespersonId).isBetween(inserted.item1()).and(inserted.item2()).fetchFirst(5).list();
assertThat(fullList, hasSize(10));
assertThat(reducedList, hasSize(5));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method concatTest.
@Test
void concatTest() {
Database database = testDatabase(dataSource, dialect);
SalespersonRow george = SalespersonRow.newBuilder().salespersonId(newId()).firstName("George").surname("Jetson").build();
database.insert(george);
Alias<SalespersonRow> s = database.table(SalespersonRow.class).as("s");
String name = database.from(s).select(upper(s.column(SalespersonRow::firstName).concat(cast(" ").asVarchar(1)).concat(SalespersonRow::surname).concat(cast(1).asInteger()))).where(SalespersonRow::salespersonId).isEqualTo(george.salespersonId()).single();
assertThat(name, is("GEORGE JETSON1"));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method uniqueConstraintViolationOnInsertInTransaction.
@Test
void uniqueConstraintViolationOnInsertInTransaction() {
Database database = TestDatabase.testDatabase(dataSource);
SalespersonRow salespersonRow = aRandomSalesperson();
try (Transaction transaction = database.beginTransaction()) {
calling(() -> database.insert(transaction, salespersonRow, salespersonRow)).shouldThrow(RuntimeSqlException.class).with(subclass(DuplicateKeyException.class)).withMessage(startsWith("Unique constraint violated while executing 'insert into "));
}
}
Aggregations