Search in sources :

Example 1 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method schemaFromDefault.

@Test
void schemaFromDefault() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
    Table<NameInAnnotation> result = database.table(NameInAnnotation.class);
    assertThat(result.qualifiedName(), is("DEFAULT_SCHEMA.NAME_IN_ANNOTATION"));
}
Also used : Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 2 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method notUpdatableFromAnnotation.

@Test
void notUpdatableFromAnnotation() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
    String updateSql = database.table(IdAnnotation.class).columns().flatMap(Column::updateSql).collect(joining(", "));
    assertThat(database.table(IdAnnotation.class).column(IdAnnotation::id).updatable(), is(false));
    assertThat(database.table(IdAnnotation.class).column(IdAnnotation::name).updatable(), is(true));
    assertThat(database.table(IdAnnotation.class).column(IdAnnotation::insertTime).updatable(), is(false));
    assertThat(database.table(IdAnnotation.class).column(IdAnnotation::updateTime).updatable(), is(true));
    assertThat(updateSql, is("NAME = ?, UPDATE_TIME = ?"));
}
Also used : Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 3 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method nameFromAnnotation.

@Test
void nameFromAnnotation() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
    Table<NameInAnnotation> result = database.table(NameInAnnotation.class);
    assertThat(result.qualifiedName(), is("DEFAULT_SCHEMA.NAME_IN_ANNOTATION"));
}
Also used : Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 4 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method nameFromClassName.

@Test
void nameFromClassName() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(NameInAnnotation.class, t -> t.tableName("NAME_IN_BUILDER")).build();
    Table<NoAnnotations> result = database.table(NoAnnotations.class);
    assertThat(result.qualifiedName(), is("DEFAULT_SCHEMA.NO_ANNOTATIONS"));
}
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 5 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method embeddedIdFromAnnotation.

@Test
void embeddedIdFromAnnotation() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
    Alias<EmbeddedIdAnnotation> alias = database.table(EmbeddedIdAnnotation.class).as("t");
    String idSql = database.table(EmbeddedIdAnnotation.class).columns().flatMap(c -> c.idSql(alias)).collect(joining(" and "));
    assertThat(idSql, is("t.KEY_IDENTIFIER = ? and t.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)

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