use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method givenSchemasInClassAndParentThenDerivedOneUsed.
@Test
void givenSchemasInClassAndParentThenDerivedOneUsed() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
Table<SchemaInAnnotationAndParentAnnotation> result = database.table(SchemaInAnnotationAndParentAnnotation.class);
assertThat(result.qualifiedName(), is("DERIVED_SCHEMA.SCHEMA_IN_ANNOTATION_AND_PARENT_ANNOTATION"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method embeddedNotUpdatableFromBuilderOverride.
@Test
void embeddedNotUpdatableFromBuilderOverride() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(EmbeddedColumnsNoAnnotations.class, t -> t.embedded(EmbeddableNoAnnotations.class, EmbeddedColumnsNoAnnotations::gross, c -> c.column(EmbeddableNoAnnotations::amount, o -> o.updatable(false))).embedded(EmbeddableNoAnnotations.class, EmbeddedColumnsNoAnnotations::net)).build();
Table<EmbeddedColumnsNoAnnotations> table = database.table(EmbeddedColumnsNoAnnotations.class);
String updateSql = table.columns().flatMap(Column::updateSql).collect(joining(", "));
assertThat(table.column(EmbeddedColumnsNoAnnotations::gross).updatable(), is(true));
assertThat(table.column(EmbeddedColumnsNoAnnotations::net).updatable(), is(true));
assertThat(table.embedded(EmbeddedColumnsNoAnnotations::gross).column(EmbeddableNoAnnotations::amount).updatable(), is(false));
assertThat(table.embedded(EmbeddedColumnsNoAnnotations::gross).column(EmbeddableNoAnnotations::unit).updatable(), is(true));
assertThat(table.embedded(EmbeddedColumnsNoAnnotations::net).column(EmbeddableNoAnnotations::amount).updatable(), is(true));
assertThat(table.embedded(EmbeddedColumnsNoAnnotations::net).column(EmbeddableNoAnnotations::unit).updatable(), is(true));
assertThat(updateSql, is("GROSS_UNIT = ?, NET_AMOUNT = ?, NET_UNIT = ?"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method embeddedNotUpdatableFromBuilder.
@Test
void embeddedNotUpdatableFromBuilder() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(EmbeddedColumnsNoAnnotations.class, t -> t.embedded(EmbeddableNoAnnotations.class, EmbeddedColumnsNoAnnotations::gross, c -> c.updatable(false)).embedded(EmbeddableNoAnnotations.class, EmbeddedColumnsNoAnnotations::net)).build();
String updateSql = database.table(EmbeddedColumnsNoAnnotations.class).columns().flatMap(Column::updateSql).collect(joining(", "));
assertThat(database.table(EmbeddedColumnsNoAnnotations.class).column(EmbeddedColumnsNoAnnotations::gross).updatable(), is(false));
assertThat(database.table(EmbeddedColumnsNoAnnotations.class).column(EmbeddedColumnsNoAnnotations::net).updatable(), is(true));
assertThat(updateSql, is("NET_AMOUNT = ?, NET_UNIT = ?"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method idFromBuilderMandatory.
@Test
void idFromBuilderMandatory() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(NoAnnotations.class, t -> t.column(NoAnnotations::id, c -> c.identifier(true))).build();
Alias<NoAnnotations> alias = Alias.of(database.table(NoAnnotations.class));
String idSql = database.table(NoAnnotations.class).columns().flatMap(c -> c.idSql(alias)).collect(joining(" and "));
assertThat(idSql, is("DEFAULT_SCHEMA.NO_ANNOTATIONS.ID = ?"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method embeddedNotInsertableFromBuilderOverride.
@Test
void embeddedNotInsertableFromBuilderOverride() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(EmbeddedColumnsNoAnnotations.class, t -> t.embedded(EmbeddableNoAnnotations.class, EmbeddedColumnsNoAnnotations::gross, c -> c.column(EmbeddableNoAnnotations::amount, o -> o.insertable(false))).embedded(EmbeddableNoAnnotations.class, EmbeddedColumnsNoAnnotations::net, c -> c.column(EmbeddableNoAnnotations::unit, o -> o.insertable(false)))).build();
String insertSql = database.table(EmbeddedColumnsNoAnnotations.class).columns().flatMap(Column::insertColumnSql).collect(joining(", "));
assertThat(database.table(EmbeddedColumnsNoAnnotations.class).column(EmbeddedColumnsNoAnnotations::gross).insertable(), is(true));
assertThat(database.table(EmbeddedColumnsNoAnnotations.class).column(EmbeddedColumnsNoAnnotations::net).insertable(), is(true));
assertThat(insertSql, is("GROSS_UNIT, NET_AMOUNT"));
}
Aggregations