Search in sources :

Example 41 with Database

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

the class TableBuilderTest method nameFromBuilder.

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

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

the class TableBuilderTest method givenAnnotationWithoutNameButNameOnParentThenParentIsUsed.

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

Example 43 with Database

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

the class TableBuilderTest method nameFromParentAnnotation.

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

Example 44 with Database

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

the class TableBuilderTest method notInsertableFromAnnotation.

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

Example 45 with Database

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

the class SiestaExample method insertOneRowAndReadItBack.

@Test
void insertOneRowAndReadItBack() {
    Database database = Database.newBuilder().defaultSchema("SIESTA").defaultSqlExecutor(JdbcSqlExecutor.of(dataSource)).build();
    Widget sprocket = new Widget(1001L, "Sprocket", 4L, Optional.empty());
    database.insert(sprocket);
    Optional<Widget> widgetNumberOne = database.from(Widget.class).where(Widget::widgetId).isEqualTo(1001L).optional();
    List<Widget> sprockets = database.from(Widget.class).where(Widget::name).isEqualTo("Sprocket").list();
    assertThat(widgetNumberOne.isPresent(), is(true));
    assertThat(widgetNumberOne.map(Widget::name), is(Optional.of("Sprocket")));
    assertThat(sprockets, hasSize(1));
    assertThat(sprockets.get(0).widgetId(), is(1001L));
}
Also used : Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test) IntegrationTest(com.cadenzauk.siesta.IntegrationTest)

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