Search in sources :

Example 36 with Database

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 = ?"));
}
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 37 with Database

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 = ?"));
}
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 38 with Database

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 = ?"));
}
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 39 with Database

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

Example 40 with Database

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 = ?"));
}
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