Search in sources :

Example 1 with Dialect

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

the class DomaAutoConfigurationTest method testDialectByDataSourceUrl.

@Test
public void testDialectByDataSourceUrl() {
    MutablePropertySources sources = context.getEnvironment().getPropertySources();
    sources.addFirst(new MapPropertySource("test", Collections.singletonMap("spring.datasource.url", "jdbc:h2:mem:example")));
    this.context.register(DomaAutoConfiguration.class, DataSourceAutoConfiguration.class);
    this.context.refresh();
    Dialect dialect = this.context.getBean(Dialect.class);
    assertThat(dialect, is(instanceOf(H2Dialect.class)));
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Dialect(org.seasar.doma.jdbc.dialect.Dialect) MysqlDialect(org.seasar.doma.jdbc.dialect.MysqlDialect) StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) H2Dialect(org.seasar.doma.jdbc.dialect.H2Dialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Example 2 with Dialect

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

the class DomaAutoConfigurationTest method testDialectByDomaPropertiesIgnoreDataSourceUrl.

@Test
public void testDialectByDomaPropertiesIgnoreDataSourceUrl() {
    MutablePropertySources sources = context.getEnvironment().getPropertySources();
    Map<String, Object> source = new HashMap<>();
    source.put("spring.datasource.url", "jdbc:h2:mem:example");
    source.put("doma.dialect", "POSTGRES");
    sources.addFirst(new MapPropertySource("test", source));
    this.context.register(DomaAutoConfiguration.class, DataSourceAutoConfiguration.class);
    this.context.refresh();
    Dialect dialect = this.context.getBean(Dialect.class);
    assertThat(dialect, is(instanceOf(PostgresDialect.class)));
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Dialect(org.seasar.doma.jdbc.dialect.Dialect) MysqlDialect(org.seasar.doma.jdbc.dialect.MysqlDialect) StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) H2Dialect(org.seasar.doma.jdbc.dialect.H2Dialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Example 3 with Dialect

use of org.seasar.doma.jdbc.dialect.Dialect 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 4 with Dialect

use of org.seasar.doma.jdbc.dialect.Dialect 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 5 with Dialect

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

the class ModifyCommand method prepareStatement.

protected PreparedStatement prepareStatement(Connection connection) {
    if (query.isAutoGeneratedKeysSupported()) {
        Config config = query.getConfig();
        Dialect dialect = config.getDialect();
        switch(dialect.getAutoGeneratedKeysType()) {
            case FIRST_COLUMN:
                return JdbcUtil.prepareStatementForAutoGeneratedKeysOfFirstColumn(connection, sql);
            case DEFAULT:
                return JdbcUtil.prepareStatementForAutoGeneratedKeys(connection, sql);
        }
    }
    return JdbcUtil.prepareStatement(connection, sql);
}
Also used : Config(org.seasar.doma.jdbc.Config) Dialect(org.seasar.doma.jdbc.dialect.Dialect)

Aggregations

Dialect (org.seasar.doma.jdbc.dialect.Dialect)32 Test (org.junit.jupiter.api.Test)11 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)11 Naming (org.seasar.doma.jdbc.Naming)10 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)8 Emp_ (org.seasar.doma.jdbc.criteria.entity.Emp_)8 NoIdEmp_ (org.seasar.doma.jdbc.criteria.entity.NoIdEmp_)8 Db2Dialect (org.seasar.doma.jdbc.dialect.Db2Dialect)8 Mssql2008Dialect (org.seasar.doma.jdbc.dialect.Mssql2008Dialect)8 MssqlDialect (org.seasar.doma.jdbc.dialect.MssqlDialect)8 OracleDialect (org.seasar.doma.jdbc.dialect.OracleDialect)8 PreparedSqlBuilder (org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder)6 StandardDialect (org.seasar.doma.jdbc.dialect.StandardDialect)6 SQLException (java.sql.SQLException)5 PreparedSql (org.seasar.doma.jdbc.PreparedSql)5 Connection (java.sql.Connection)4 Method (java.lang.reflect.Method)3 PreparedStatement (java.sql.PreparedStatement)3 Test (org.junit.Test)3 SqlExecutionException (org.seasar.doma.jdbc.SqlExecutionException)3