use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method embeddedIdFromBuilder.
@Test
void embeddedIdFromBuilder() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(EmbeddedIdNoAnnotation.class, t -> t.embedded(Key.class, EmbeddedIdNoAnnotation::key, c -> c.identifier(true))).build();
Alias<EmbeddedIdNoAnnotation> alias = Alias.of(database.table(EmbeddedIdNoAnnotation.class));
String idSql = database.table(EmbeddedIdNoAnnotation.class).columns().flatMap(c -> c.idSql(alias)).collect(joining(" and "));
assertThat(idSql, is("DEFAULT_SCHEMA.EMBEDDED_ID_NO_ANNOTATION.KEY_IDENTIFIER = ? and DEFAULT_SCHEMA.EMBEDDED_ID_NO_ANNOTATION.KEY_VERSION = ?"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method idFromBuilderOptional.
@Test
void idFromBuilderOptional() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(NoAnnotations.class, t -> t.column(NoAnnotations::name, c -> c.identifier(true))).build();
Alias<NoAnnotations> alias = database.table(NoAnnotations.class).as("z");
String idSql = database.table(NoAnnotations.class).columns().flatMap(c -> c.idSql(alias)).collect(joining(" and "));
assertThat(idSql, is("z.NAME = ?"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method idFromAnnotation.
@Test
void idFromAnnotation() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
Alias<IdAnnotation> alias = Alias.of(database.table(IdAnnotation.class));
String idSql = database.table(IdAnnotation.class).columns().flatMap(c -> c.idSql(alias)).collect(joining(" and "));
assertThat(idSql, is("DEFAULT_SCHEMA.ID_ANNOTATION.ID = ?"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TableBuilderTest method embeddedNotUpdatableFromAnnotationOverride.
@Test
void embeddedNotUpdatableFromAnnotationOverride() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
Table<EmbeddedColumnsInsertOverride> table = database.table(EmbeddedColumnsInsertOverride.class);
String updateSql = table.columns().flatMap(Column::updateSql).collect(joining(", "));
assertThat(table.column(EmbeddedColumnsInsertOverride::gross).updatable(), is(true));
assertThat(table.column(EmbeddedColumnsInsertOverride::net).updatable(), is(true));
assertThat(table.embedded(EmbeddedColumnsInsertOverride::gross).column(EmbeddableNoAnnotations::amount).updatable(), is(false));
assertThat(table.embedded(EmbeddedColumnsInsertOverride::gross).column(EmbeddableNoAnnotations::unit).updatable(), is(true));
assertThat(table.embedded(EmbeddedColumnsInsertOverride::net).column(EmbeddableNoAnnotations::amount).updatable(), is(true));
assertThat(table.embedded(EmbeddedColumnsInsertOverride::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 notUpdatableFromBuilder.
@Test
void notUpdatableFromBuilder() {
Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(NoAnnotations.class, t -> t.column(NoAnnotations::updateTime, c -> c.updatable(false))).build();
String insertSql = database.table(NoAnnotations.class).columns().flatMap(Column::updateSql).collect(joining(", "));
assertThat(database.table(NoAnnotations.class).column(NoAnnotations::id).updatable(), is(true));
assertThat(database.table(NoAnnotations.class).column(NoAnnotations::name).updatable(), is(true));
assertThat(database.table(NoAnnotations.class).column(NoAnnotations::updateTime).updatable(), is(false));
assertThat(database.table(NoAnnotations.class).column(NoAnnotations::insertTime).updatable(), is(true));
assertThat(insertSql, is("ID = ?, NAME = ?, INSERT_TIME = ?"));
}
Aggregations