Search in sources :

Example 6 with Dialect

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

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

the class NativeSqlSelectTest method expression_concat_mssql2008.

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

        @Override
        public Dialect getDialect() {
            return new Mssql2008Dialect();
        }
    });
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).select(concat(e.name, "a"));
    Sql<?> sql = stmt.asSql();
    assertEquals("select (t0_.NAME + 'a') from EMP t0_", sql.getFormattedSql());
}
Also used : Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) 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 8 with Dialect

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

the class NativeSqlSelectTest method forUpdate_oracle_nowait.

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

        @Override
        public Dialect getDialect() {
            return new OracleDialect();
        }
    });
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).forUpdate(ForUpdateOption.noWait()).select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_ for update nowait", sql.getFormattedSql());
}
Also used : OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) 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 9 with Dialect

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

the class NativeSqlSelectTest method forUpdate_oracle_wait_withColumn.

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

        @Override
        public Dialect getDialect() {
            return new OracleDialect();
        }
    });
    Emp_ e = new Emp_();
    Dept_ d = new Dept_();
    Buildable<?> stmt = nativeSql.from(e).innerJoin(d, on -> on.eq(e.id, d.id)).forUpdate(ForUpdateOption.wait(5, e.id, d.id)).select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_ inner join CATA.DEPT t1_ on (t0_.ID = t1_.ID) for update of t0_.ID, t1_.ID wait 5", sql.getFormattedSql());
}
Also used : OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Dept_(org.seasar.doma.jdbc.criteria.entity.Dept_) 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 10 with Dialect

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

the class AutoDeleteQuery method prepareSql.

protected void prepareSql() {
    Naming naming = config.getNaming();
    Dialect dialect = config.getDialect();
    PreparedSqlBuilder builder = new PreparedSqlBuilder(config, SqlKind.DELETE, sqlLogType);
    builder.appendSql("delete from ");
    builder.appendSql(entityType.getQualifiedTableName(naming::apply, dialect::applyQuote));
    boolean whereClauseAppended = false;
    if (idPropertyTypes.size() > 0) {
        builder.appendSql(" where ");
        whereClauseAppended = true;
        for (EntityPropertyType<ENTITY, ?> propertyType : idPropertyTypes) {
            Property<ENTITY, ?> property = propertyType.createProperty();
            property.load(entity);
            builder.appendSql(propertyType.getColumnName(naming::apply, dialect::applyQuote));
            builder.appendSql(" = ");
            builder.appendParameter(property.asInParameter());
            builder.appendSql(" and ");
        }
        builder.cutBackSql(5);
    }
    if (versionPropertyType != null && !versionIgnored) {
        if (whereClauseAppended) {
            builder.appendSql(" and ");
        } else {
            builder.appendSql(" where ");
            whereClauseAppended = true;
        }
        Property<ENTITY, ?> property = versionPropertyType.createProperty();
        property.load(entity);
        builder.appendSql(versionPropertyType.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(" = ");
        builder.appendParameter(property.asInParameter());
    }
    if (tenantIdPropertyType != null) {
        if (whereClauseAppended) {
            builder.appendSql(" and ");
        } else {
            builder.appendSql(" where ");
            // noinspection UnusedAssignment
            whereClauseAppended = true;
        }
        Property<ENTITY, ?> property = tenantIdPropertyType.createProperty();
        property.load(entity);
        builder.appendSql(tenantIdPropertyType.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(" = ");
        builder.appendParameter(property.asInParameter());
    }
    sql = builder.build(this::comment);
}
Also used : Dialect(org.seasar.doma.jdbc.dialect.Dialect) Naming(org.seasar.doma.jdbc.Naming) PreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder)

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