Search in sources :

Example 1 with Dialect

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

the class AutoDetectDialect method from.

public static Dialect from(DataSource dataSource) {
    try (Connection connection = DataSourceUtil.connection(dataSource)) {
        DatabaseMetaData metaData = ConnectionUtil.getMetaData(connection);
        String productName = metaData.getDatabaseProductName();
        return DIALECTS.stream().filter(x -> x.item1().test(productName)).map(x -> x.item2().get()).findFirst().orElseGet(AnsiDialect::new);
    } catch (SQLException e) {
        throw new RuntimeSqlException(e);
    }
}
Also used : Tuple2(com.cadenzauk.core.tuple.Tuple2) Connection(java.sql.Connection) Predicate(java.util.function.Predicate) Tuple(com.cadenzauk.core.tuple.Tuple) DatabaseMetaData(java.sql.DatabaseMetaData) Dialect(com.cadenzauk.siesta.Dialect) Supplier(java.util.function.Supplier) DataSourceUtil(com.cadenzauk.core.sql.DataSourceUtil) SQLException(java.sql.SQLException) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RuntimeSqlException(com.cadenzauk.core.sql.RuntimeSqlException) DataSource(javax.sql.DataSource) Pattern(java.util.regex.Pattern) ConnectionUtil(com.cadenzauk.core.sql.ConnectionUtil) RuntimeSqlException(com.cadenzauk.core.sql.RuntimeSqlException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 2 with Dialect

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

the class AutoDetectDialectIntegrationTest method detectedCorrectly.

@Test
void detectedCorrectly() {
    Dialect result = AutoDetectDialect.from(dataSource);
    assertThat(result, Matchers.instanceOf(dialect.getClass()));
}
Also used : Dialect(com.cadenzauk.siesta.Dialect) Test(org.junit.jupiter.api.Test) IntegrationTest(com.cadenzauk.siesta.IntegrationTest)

Aggregations

Dialect (com.cadenzauk.siesta.Dialect)2 ConnectionUtil (com.cadenzauk.core.sql.ConnectionUtil)1 DataSourceUtil (com.cadenzauk.core.sql.DataSourceUtil)1 RuntimeSqlException (com.cadenzauk.core.sql.RuntimeSqlException)1 Tuple (com.cadenzauk.core.tuple.Tuple)1 Tuple2 (com.cadenzauk.core.tuple.Tuple2)1 IntegrationTest (com.cadenzauk.siesta.IntegrationTest)1 ImmutableList (com.google.common.collect.ImmutableList)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Pattern (java.util.regex.Pattern)1 DataSource (javax.sql.DataSource)1 Test (org.junit.jupiter.api.Test)1