use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method nameFromBuilder.
@Test
void nameFromBuilder() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(NameInAnnotation.class, t -> t.tableName("NAME_IN_BUILDER")).build();
Table<NameInAnnotation> result = database.table(NameInAnnotation.class);
assertThat(result.qualifiedName(), is("DEFAULT_SCHEMA.NAME_IN_BUILDER"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method givenAnnotationWithoutNameButNameOnParentThenParentIsUsed.
@Test
void givenAnnotationWithoutNameButNameOnParentThenParentIsUsed() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
Table<SchemaInAnnotationAndNameInParentAnnotation> result = database.table(SchemaInAnnotationAndNameInParentAnnotation.class);
assertThat(result.qualifiedName(), is("DERIVED_SCHEMA_IN_ANNOTATION.NAME_IN_ANNOTATION"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method nameFromParentAnnotation.
@Test
void nameFromParentAnnotation() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
Table<NameInParentAnnotation> result = database.table(NameInParentAnnotation.class);
assertThat(result.qualifiedName(), is("DEFAULT_SCHEMA.NAME_IN_ANNOTATION"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method notInsertableFromAnnotation.
@Test
void notInsertableFromAnnotation() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
String insertSql = database.table(IdAnnotation.class).columns().flatMap(Column::insertColumnSql).collect(joining(", "));
assertThat(database.table(IdAnnotation.class).column(IdAnnotation::id).insertable(), is(true));
assertThat(database.table(IdAnnotation.class).column(IdAnnotation::name).insertable(), is(true));
assertThat(database.table(IdAnnotation.class).column(IdAnnotation::updateTime).insertable(), is(false));
assertThat(database.table(IdAnnotation.class).column(IdAnnotation::insertTime).insertable(), is(true));
assertThat(insertSql, is("ID, NAME, INSERT_TIME"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class SiestaExample method insertOneRowAndReadItBack.
@Test
void insertOneRowAndReadItBack() {
Database database = Database.newBuilder().defaultSchema("SIESTA").defaultSqlExecutor(JdbcSqlExecutor.of(dataSource)).build();
Widget sprocket = new Widget(1001L, "Sprocket", 4L, Optional.empty());
database.insert(sprocket);
Optional<Widget> widgetNumberOne = database.from(Widget.class).where(Widget::widgetId).isEqualTo(1001L).optional();
List<Widget> sprockets = database.from(Widget.class).where(Widget::name).isEqualTo("Sprocket").list();
assertThat(widgetNumberOne.isPresent(), is(true));
assertThat(widgetNumberOne.map(Widget::name), is(Optional.of("Sprocket")));
assertThat(sprockets, hasSize(1));
assertThat(sprockets.get(0).widgetId(), is(1001L));
}
Aggregations