use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class ExpressionBuilderTest method testExpression.
@ParameterizedTest
@MethodSource("argsForTestExpression")
void testExpression(BiFunction<ExpressionBuilder<String, InWhereExpectingAnd<String>>, Alias<SalespersonRow>, InWhereExpectingAnd<String>> method, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
ExpressionBuilder<String, InWhereExpectingAnd<String>> select = database.from(alias).select(SalespersonRow::firstName, "name").where(SalespersonRow::firstName);
method.apply(select, alias).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select s.FIRST_NAME as name from SIESTA.SALESPERSON s where s.FIRST_NAME " + expectedSql));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class TransactionIntegrationTest method whenCommittedThenInserted.
@Test
void whenCommittedThenInserted() {
Database database = testDatabase(dataSource, dialect);
SalespersonRow salesperson = aRandomSalesperson();
try (Transaction transaction = database.beginTransaction()) {
database.insert(transaction, salesperson);
transaction.commit();
}
Integer count = database.from(SalespersonRow.class).select(count()).where(SalespersonRow::salespersonId).isEqualTo(salesperson.salespersonId()).single();
assertThat(count, is(1));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class TransactionIntegrationTest method whenUncommittedThenVisibleWithUr.
@Test
void whenUncommittedThenVisibleWithUr() {
assumeTrue(dialect.supportsIsolationLevelInQuery(), "Database doesn't support isolation levels in query.");
Database database = testDatabase(dataSource, dialect);
SalespersonRow salesperson = aRandomSalesperson();
try (Transaction transaction = database.beginTransaction()) {
database.insert(transaction, salesperson);
Integer count = database.from(SalespersonRow.class).select(count()).where(SalespersonRow::salespersonId).isEqualTo(salesperson.salespersonId()).fetchFirst(1).withIsolation(IsolationLevel.UNCOMMITTED_READ).single();
assertThat(count, is(1));
}
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class TransactionIntegrationTest method whenUncommittedThenNotVisible.
@Test
void whenUncommittedThenNotVisible() {
Database database = testDatabase(dataSource, dialect);
SalespersonRow salesperson = aRandomSalesperson();
try (Transaction transaction = database.beginTransaction()) {
database.insert(transaction, salesperson);
Optional<Long> result = database.from(SalespersonRow.class).select(SalespersonRow::salespersonId).where(SalespersonRow::salespersonId).isEqualTo(salesperson.salespersonId()).withIsolation(IsolationLevel.REPEATABLE_READ).keepLocks(LockLevel.UPDATE).optional();
assertThat(result.isPresent(), is(false));
}
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class TransactionIntegrationTest method whenRollingBackNothingInserted.
@Test
void whenRollingBackNothingInserted() {
Database database = testDatabase(dataSource, dialect);
SalespersonRow salesperson = aRandomSalesperson();
try (Transaction transaction = database.beginTransaction()) {
database.insert(transaction, salesperson);
transaction.rollback();
}
Integer count = database.from(SalespersonRow.class).select(count()).where(SalespersonRow::salespersonId).isEqualTo(salesperson.salespersonId()).single();
assertThat(count, is(0));
}
Aggregations