Search in sources :

Example 1 with MysqlDialect

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

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

the class AutoInsertQueryTest method testPrepare_MySql_autoIncrement.

@Test
public void testPrepare_MySql_autoIncrement() {
    runtimeConfig.setDialect(new MysqlDialect());
    AutoIncrement autoIncrement = new AutoIncrement();
    AutoInsertQuery<AutoIncrement> query = new AutoInsertQuery<>(_AutoIncrement.getSingletonInternal());
    query.setMethod(method);
    query.setConfig(runtimeConfig);
    query.setEntity(autoIncrement);
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    assertEquals("insert into AutoIncrement () values ()", query.getSql().getRawSql());
}
Also used : MysqlDialect(org.seasar.doma.jdbc.dialect.MysqlDialect) AutoIncrement(example.entity.AutoIncrement) example.entity._AutoIncrement(example.entity._AutoIncrement) Test(org.junit.jupiter.api.Test)

Example 3 with MysqlDialect

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

the class NativeSqlDeleteTest method aliasInDeleteClause.

@Test
void aliasInDeleteClause() {
    MockConfig config = new MockConfig();
    config.dialect = new MysqlDialect();
    NativeSql nativeSql = new NativeSql(config);
    Emp_ e = new Emp_();
    Statement<Integer> stmt = nativeSql.delete(e);
    Sql<?> sql = stmt.asSql();
    assertEquals("delete t0_ from EMP t0_", sql.getFormattedSql());
}
Also used : MysqlDialect(org.seasar.doma.jdbc.dialect.MysqlDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Aggregations

MysqlDialect (org.seasar.doma.jdbc.dialect.MysqlDialect)3 Test (org.junit.jupiter.api.Test)2 AutoIncrement (example.entity.AutoIncrement)1 example.entity._AutoIncrement (example.entity._AutoIncrement)1 DialectType (org.seasar.doma.boot.autoconfigure.DomaProperties.DialectType)1 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)1 Emp_ (org.seasar.doma.jdbc.criteria.entity.Emp_)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 OracleDialect (org.seasar.doma.jdbc.dialect.OracleDialect)1 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)1 SqliteDialect (org.seasar.doma.jdbc.dialect.SqliteDialect)1 StandardDialect (org.seasar.doma.jdbc.dialect.StandardDialect)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 DatabaseDriver (org.springframework.boot.jdbc.DatabaseDriver)1 Bean (org.springframework.context.annotation.Bean)1