use of com.cadenzauk.siesta.model.SalesAreaRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method lockTimeoutOnDelete.
@Test
void lockTimeoutOnDelete() {
assumeTrue(dialect.supportsLockTimeout(), "Database does not support lock timeouts.");
Database database = TestDatabase.testDatabase(dataSource);
SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").build();
database.insert(salesArea);
try (CompositeAutoCloseable closer = new CompositeAutoCloseable()) {
Transaction transaction1 = closer.add(database.beginTransaction());
database.update(SalesAreaRow.class).set(SalesAreaRow::salesCount).to(10L).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute(transaction1);
Transaction transaction2 = closer.add(database.beginTransaction());
closer.add(database.withLockTimeout(transaction2, 0, TimeUnit.MILLISECONDS));
calling(() -> database.delete(SalesAreaRow.class).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute(transaction2)).shouldThrow(RuntimeSqlException.class).with(subclass(LockingException.class)).withMessage(startsWith("Locking failure while executing 'delete "));
transaction2.rollback();
}
}
use of com.cadenzauk.siesta.model.SalesAreaRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method stringValueTooLongOnUpdate.
@Test
void stringValueTooLongOnUpdate() {
Database database = TestDatabase.testDatabase(dataSource);
SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").build();
database.insert(salesArea);
calling(() -> database.update(SalesAreaRow.class).set(SalesAreaRow::salesAreaName).to("Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu").where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute()).shouldThrow(RuntimeSqlException.class).with(subclass(InvalidValueException.class)).withMessage(startsWith("Incorrect data value for data type while executing 'update "));
}
use of com.cadenzauk.siesta.model.SalesAreaRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method lockTimeoutOnUpdate.
@Test
void lockTimeoutOnUpdate() {
assumeTrue(dialect.supportsLockTimeout(), "Database does not support lock timeouts.");
Database database = TestDatabase.testDatabase(dataSource);
SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").build();
database.insert(salesArea);
try (CompositeAutoCloseable closer = new CompositeAutoCloseable()) {
Transaction transaction1 = closer.add(database.beginTransaction());
database.update(SalesAreaRow.class).set(SalesAreaRow::salesCount).to(10L).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute(transaction1);
Transaction transaction2 = closer.add(database.beginTransaction());
closer.add(database.withLockTimeout(transaction2, 0, TimeUnit.MILLISECONDS));
calling(() -> database.update(SalesAreaRow.class).set(SalesAreaRow::salesCount).to(1L).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute(transaction2)).shouldThrow(RuntimeSqlException.class).with(subclass(LockingException.class)).withMessage(startsWith("Locking failure while executing 'update "));
transaction2.rollback();
}
}
use of com.cadenzauk.siesta.model.SalesAreaRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method nullNotAllowedOnInsert.
@Test
void nullNotAllowedOnInsert() {
Database database = TestDatabase.testDatabase(dataSource);
SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).build();
calling(() -> database.insert(salesArea)).shouldThrow(RuntimeSqlException.class).with(subclass(IllegalNullException.class)).withMessage(startsWith("Null value is not allowed while executing 'insert into "));
}
use of com.cadenzauk.siesta.model.SalesAreaRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method stringValueTooLongOnInsert.
@Test
void stringValueTooLongOnInsert() {
Database database = TestDatabase.testDatabase(dataSource);
SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu").build();
calling(() -> database.insert(salesArea)).shouldThrow(RuntimeSqlException.class).with(subclass(InvalidValueException.class)).withMessage(startsWith("Incorrect data value for data type while executing 'insert into "));
}
Aggregations