Search in sources :

Example 1 with StandardDialect

use of org.seasar.doma.jdbc.dialect.StandardDialect in project doma-spring-boot by domaframework.

the class DomaAutoConfiguration method dialect.

@Bean
@ConditionalOnMissingBean
public Dialect dialect(Environment environment) {
    DialectType dialectType = domaProperties.getDialect();
    if (dialectType != null) {
        return dialectType.create();
    }
    String url = environment.getProperty("spring.datasource.url");
    if (url != null) {
        DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(url);
        switch(databaseDriver) {
            case DB2:
                return new Db2Dialect();
            case H2:
                return new H2Dialect();
            case HSQLDB:
                return new HsqldbDialect();
            case SQLSERVER:
            case JTDS:
                return new MssqlDialect();
            case MYSQL:
                return new MysqlDialect();
            case ORACLE:
                return new OracleDialect();
            case POSTGRESQL:
                return new PostgresDialect();
            case SQLITE:
                return new SqliteDialect();
            default:
                break;
        }
    }
    if (logger.isWarnEnabled()) {
        logger.warn("StandardDialect was selected because no explicit configuration and it is not possible to guess from 'spring.datasource.url property'");
    }
    return new StandardDialect();
}
Also used : HsqldbDialect(org.seasar.doma.jdbc.dialect.HsqldbDialect) MysqlDialect(org.seasar.doma.jdbc.dialect.MysqlDialect) H2Dialect(org.seasar.doma.jdbc.dialect.H2Dialect) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) DialectType(org.seasar.doma.boot.autoconfigure.DomaProperties.DialectType) DatabaseDriver(org.springframework.boot.jdbc.DatabaseDriver) SqliteDialect(org.seasar.doma.jdbc.dialect.SqliteDialect) StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with StandardDialect

use of org.seasar.doma.jdbc.dialect.StandardDialect in project doma by domaframework.

the class AbstractSqlFileRepositoryTest method testGetSqlFile_illegalPath.

@Test
public void testGetSqlFile_illegalPath(TestInfo testInfo) {
    SqlFileRepository repository = new MySqlFileRepository();
    Method method = testInfo.getTestMethod().get();
    String path = method.getName();
    Dialect dialect = new StandardDialect();
    try {
        repository.getSqlFile(method, path, dialect);
        fail();
    } catch (DomaIllegalArgumentException ignored) {
    }
}
Also used : StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Method(java.lang.reflect.Method) StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) DomaIllegalArgumentException(org.seasar.doma.DomaIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 3 with StandardDialect

use of org.seasar.doma.jdbc.dialect.StandardDialect in project doma by domaframework.

the class AbstractSqlFileRepositoryTest method testGetSqlFile.

@Test
public void testGetSqlFile(TestInfo testInfo) {
    SqlFileRepository repository = new MySqlFileRepository();
    Method method = testInfo.getTestMethod().get();
    String path = String.format("META-INF/%s.sql", getClass().getName().replace(".", "/"));
    Dialect dialect = new StandardDialect();
    SqlFile sqlFile = repository.getSqlFile(method, path, dialect);
    assertEquals("select * from employee", sqlFile.getSql());
}
Also used : StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Method(java.lang.reflect.Method) StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) Test(org.junit.jupiter.api.Test)

Example 4 with StandardDialect

use of org.seasar.doma.jdbc.dialect.StandardDialect in project doma by domaframework.

the class JdbcExceptionTest method testSqlFileNotFound.

@Test
public void testSqlFileNotFound() {
    GreedyCacheSqlFileRepository repository = new GreedyCacheSqlFileRepository();
    try {
        repository.getSqlFile(method, "META-INF/aaa/bbb.sql", new StandardDialect());
        fail();
    } catch (SqlFileNotFoundException e) {
        System.out.println(e.getMessage());
        assertEquals(Message.DOMA2011, e.getMessageResource());
    }
}
Also used : StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) Test(org.junit.jupiter.api.Test)

Example 5 with StandardDialect

use of org.seasar.doma.jdbc.dialect.StandardDialect in project doma by domaframework.

the class GreedyCacheSqlFileRepositoryTest method testGetSqlFile.

@Test
public void testGetSqlFile() {
    StandardDialect dialect = new StandardDialect();
    String path = "META-INF/" + getClass().getName().replace(".", "/") + ".sql";
    GreedyCacheSqlFileRepository repository = new GreedyCacheSqlFileRepository();
    SqlFile sqlFile = repository.getSqlFile(method, path, dialect);
    assertNotNull(sqlFile);
    SqlFile sqlFile2 = repository.getSqlFile(method, path, dialect);
    assertSame(sqlFile, sqlFile2);
    assertEquals(path, sqlFile.getPath());
}
Also used : StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) Test(org.junit.jupiter.api.Test)

Aggregations

StandardDialect (org.seasar.doma.jdbc.dialect.StandardDialect)7 Test (org.junit.jupiter.api.Test)6 Method (java.lang.reflect.Method)3 Dialect (org.seasar.doma.jdbc.dialect.Dialect)3 DomaIllegalArgumentException (org.seasar.doma.DomaIllegalArgumentException)1 Sql (org.seasar.doma.Sql)1 DialectType (org.seasar.doma.boot.autoconfigure.DomaProperties.DialectType)1 Db2Dialect (org.seasar.doma.jdbc.dialect.Db2Dialect)1 H2Dialect (org.seasar.doma.jdbc.dialect.H2Dialect)1 HsqldbDialect (org.seasar.doma.jdbc.dialect.HsqldbDialect)1 MssqlDialect (org.seasar.doma.jdbc.dialect.MssqlDialect)1 MysqlDialect (org.seasar.doma.jdbc.dialect.MysqlDialect)1 OracleDialect (org.seasar.doma.jdbc.dialect.OracleDialect)1 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)1 SqliteDialect (org.seasar.doma.jdbc.dialect.SqliteDialect)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 DatabaseDriver (org.springframework.boot.jdbc.DatabaseDriver)1 Bean (org.springframework.context.annotation.Bean)1