Search in sources :

Example 6 with Database

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"));
}
Also used : Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 7 with Database

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 = ?"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Embedded(javax.persistence.Embedded) ZonedDateTime(java.time.ZonedDateTime) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) AttributeOverride(javax.persistence.AttributeOverride) BigDecimal(java.math.BigDecimal) Alias(com.cadenzauk.siesta.Alias) EmbeddedId(javax.persistence.EmbeddedId) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Database(com.cadenzauk.siesta.Database) Id(javax.persistence.Id) Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 8 with Database

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 = ?"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Embedded(javax.persistence.Embedded) ZonedDateTime(java.time.ZonedDateTime) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) AttributeOverride(javax.persistence.AttributeOverride) BigDecimal(java.math.BigDecimal) Alias(com.cadenzauk.siesta.Alias) EmbeddedId(javax.persistence.EmbeddedId) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Database(com.cadenzauk.siesta.Database) Id(javax.persistence.Id) Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 9 with Database

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 = ?"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Embedded(javax.persistence.Embedded) ZonedDateTime(java.time.ZonedDateTime) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) AttributeOverride(javax.persistence.AttributeOverride) BigDecimal(java.math.BigDecimal) Alias(com.cadenzauk.siesta.Alias) EmbeddedId(javax.persistence.EmbeddedId) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Database(com.cadenzauk.siesta.Database) Id(javax.persistence.Id) Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 10 with Database

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"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Embedded(javax.persistence.Embedded) ZonedDateTime(java.time.ZonedDateTime) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) AttributeOverride(javax.persistence.AttributeOverride) BigDecimal(java.math.BigDecimal) Alias(com.cadenzauk.siesta.Alias) EmbeddedId(javax.persistence.EmbeddedId) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Database(com.cadenzauk.siesta.Database) Id(javax.persistence.Id) Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Aggregations

Database (com.cadenzauk.siesta.Database)57 Test (org.junit.jupiter.api.Test)41 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 ZonedDateTime (java.time.ZonedDateTime)17 Optional (java.util.Optional)17 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)16 Alias (com.cadenzauk.siesta.Alias)15 BigDecimal (java.math.BigDecimal)14 Collectors.joining (java.util.stream.Collectors.joining)14 AttributeOverride (javax.persistence.AttributeOverride)14 Embedded (javax.persistence.Embedded)14 EmbeddedId (javax.persistence.EmbeddedId)14 Id (javax.persistence.Id)14 CoreMatchers.is (org.hamcrest.CoreMatchers.is)14 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)13 WidgetRow (com.cadenzauk.siesta.model.WidgetRow)7 MockitoTest (com.cadenzauk.core.MockitoTest)5