Search in sources :

Example 1 with MssqlDialect

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

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

the class NativeSqlSelectTest method forUpdate_mssql_nowait.

@Test
void forUpdate_mssql_nowait() {
    NativeSql nativeSql = new NativeSql(new MockConfig() {

        @Override
        public Dialect getDialect() {
            return new MssqlDialect();
        }
    });
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).where(c -> c.eq(e.id, 1)).forUpdate(ForUpdateOption.noWait()).select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_ with (updlock, rowlock, nowait) where t0_.ID = 1", sql.getFormattedSql());
}
Also used : MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 3 with MssqlDialect

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

the class NativeSqlUpdateTest method aliasInUpdateClause.

@Test
void aliasInUpdateClause() {
    MockConfig config = new MockConfig();
    config.dialect = new MssqlDialect();
    NativeSql nativeSql = new NativeSql(config);
    Emp_ e = new Emp_();
    Statement<Integer> stmt = nativeSql.update(e).set(c -> {
        c.value(e.name, "bbb");
        c.value(e.salary, new BigDecimal("1000"));
    }).where(c -> c.eq(e.id, 1));
    Sql<?> sql = stmt.asSql();
    assertEquals("update t0_ set NAME = 'bbb', SALARY = 1000 from EMP t0_ where t0_.ID = 1", sql.getFormattedSql());
}
Also used : Test(org.junit.jupiter.api.Test) BigDecimal(java.math.BigDecimal) Statement(org.seasar.doma.jdbc.criteria.statement.Statement) Sql(org.seasar.doma.jdbc.Sql) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 4 with MssqlDialect

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

the class NativeSqlSelectTest method forUpdate_mssql.

@Test
void forUpdate_mssql() {
    NativeSql nativeSql = new NativeSql(new MockConfig() {

        @Override
        public Dialect getDialect() {
            return new MssqlDialect();
        }
    });
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).where(c -> c.eq(e.id, 1)).forUpdate().select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_ with (updlock, rowlock) where t0_.ID = 1", sql.getFormattedSql());
}
Also used : MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Aggregations

MssqlDialect (org.seasar.doma.jdbc.dialect.MssqlDialect)4 Test (org.junit.jupiter.api.Test)3 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)3 Emp_ (org.seasar.doma.jdbc.criteria.entity.Emp_)3 Db2Dialect (org.seasar.doma.jdbc.dialect.Db2Dialect)3 OracleDialect (org.seasar.doma.jdbc.dialect.OracleDialect)3 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)3 NoIdEmp_ (org.seasar.doma.jdbc.criteria.entity.NoIdEmp_)2 Dialect (org.seasar.doma.jdbc.dialect.Dialect)2 Mssql2008Dialect (org.seasar.doma.jdbc.dialect.Mssql2008Dialect)2 BigDecimal (java.math.BigDecimal)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 DialectType (org.seasar.doma.boot.autoconfigure.DomaProperties.DialectType)1 Sql (org.seasar.doma.jdbc.Sql)1 Statement (org.seasar.doma.jdbc.criteria.statement.Statement)1 H2Dialect (org.seasar.doma.jdbc.dialect.H2Dialect)1 HsqldbDialect (org.seasar.doma.jdbc.dialect.HsqldbDialect)1 MysqlDialect (org.seasar.doma.jdbc.dialect.MysqlDialect)1 SqliteDialect (org.seasar.doma.jdbc.dialect.SqliteDialect)1 StandardDialect (org.seasar.doma.jdbc.dialect.StandardDialect)1