Search in sources :

Example 1 with Emp_

use of org.seasar.doma.jdbc.criteria.entity.Emp_ in project doma by domaframework.

the class NativeSqlSelectTest method union.

@Test
void union() {
    Emp_ e = new Emp_();
    Dept_ d = new Dept_();
    SetOperand<String> stmt1 = nativeSql.from(e).select(e.name);
    SetOperand<String> stmt2 = nativeSql.from(d).select(d.name);
    SetOperand<String> stmt3 = stmt1.union(stmt2);
    Sql<?> sql1 = stmt1.asSql();
    assertEquals("select t0_.NAME from EMP t0_", sql1.getFormattedSql());
    Sql<?> sql2 = stmt2.asSql();
    assertEquals("select t0_.NAME from CATA.DEPT t0_", sql2.getFormattedSql());
    Sql<?> sql3 = stmt3.asSql();
    assertEquals("select t0_.NAME from EMP t0_ union select t0_.NAME from CATA.DEPT t0_", sql3.getFormattedSql());
}
Also used : Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Dept_(org.seasar.doma.jdbc.criteria.entity.Dept_) Test(org.junit.jupiter.api.Test)

Example 2 with Emp_

use of org.seasar.doma.jdbc.criteria.entity.Emp_ 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 Emp_

use of org.seasar.doma.jdbc.criteria.entity.Emp_ in project doma by domaframework.

the class NativeSqlSelectTest method where_exist.

@Test
void where_exist() {
    Emp_ e = new Emp_();
    Dept_ d = new Dept_();
    Buildable<?> stmt = nativeSql.from(e).where(c -> c.exists(c.from(d).select(d.id))).select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_ where exists (select t1_.ID from CATA.DEPT t1_)", sql.getFormattedSql());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Emp(org.seasar.doma.jdbc.criteria.entity.Emp) DistinctOption(org.seasar.doma.jdbc.criteria.option.DistinctOption) Expressions.upper(org.seasar.doma.jdbc.criteria.expression.Expressions.upper) Arrays(java.util.Arrays) Statement(org.seasar.doma.jdbc.criteria.statement.Statement) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) Expressions.when(org.seasar.doma.jdbc.criteria.expression.Expressions.when) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Buildable(org.seasar.doma.jdbc.criteria.statement.Buildable) BigDecimal(java.math.BigDecimal) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) CommentContext(org.seasar.doma.jdbc.CommentContext) Expressions.literal(org.seasar.doma.jdbc.criteria.expression.Expressions.literal) Expressions.sum(org.seasar.doma.jdbc.criteria.expression.Expressions.sum) Config(org.seasar.doma.jdbc.Config) Expressions.concat(org.seasar.doma.jdbc.criteria.expression.Expressions.concat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Expressions.count(org.seasar.doma.jdbc.criteria.expression.Expressions.count) Expressions.ltrim(org.seasar.doma.jdbc.criteria.expression.Expressions.ltrim) SelectExpression(org.seasar.doma.jdbc.criteria.expression.SelectExpression) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) Dept_(org.seasar.doma.jdbc.criteria.entity.Dept_) Expressions.countDistinct(org.seasar.doma.jdbc.criteria.expression.Expressions.countDistinct) Expressions.trim(org.seasar.doma.jdbc.criteria.expression.Expressions.trim) Commenter(org.seasar.doma.jdbc.Commenter) Expressions.rtrim(org.seasar.doma.jdbc.criteria.expression.Expressions.rtrim) Expressions.lower(org.seasar.doma.jdbc.criteria.expression.Expressions.lower) DomaException(org.seasar.doma.DomaException) Expressions.avg(org.seasar.doma.jdbc.criteria.expression.Expressions.avg) Expressions.min(org.seasar.doma.jdbc.criteria.expression.Expressions.min) ForUpdateOption(org.seasar.doma.jdbc.criteria.option.ForUpdateOption) Test(org.junit.jupiter.api.Test) Message(org.seasar.doma.message.Message) List(java.util.List) Expressions.select(org.seasar.doma.jdbc.criteria.expression.Expressions.select) Sql(org.seasar.doma.jdbc.Sql) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Expressions.avgAsDouble(org.seasar.doma.jdbc.criteria.expression.Expressions.avgAsDouble) SetOperand(org.seasar.doma.jdbc.criteria.statement.SetOperand) Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) LikeOption(org.seasar.doma.jdbc.criteria.option.LikeOption) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Tuple2(org.seasar.doma.jdbc.criteria.tuple.Tuple2) Expressions.max(org.seasar.doma.jdbc.criteria.expression.Expressions.max) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Dept_(org.seasar.doma.jdbc.criteria.entity.Dept_) Test(org.junit.jupiter.api.Test)

Example 4 with Emp_

use of org.seasar.doma.jdbc.criteria.entity.Emp_ in project doma by domaframework.

the class NativeSqlSelectTest method orderBy_empty.

@Test
void orderBy_empty() {
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).orderBy(c -> {
    }).select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_", sql.getFormattedSql());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Emp(org.seasar.doma.jdbc.criteria.entity.Emp) DistinctOption(org.seasar.doma.jdbc.criteria.option.DistinctOption) Expressions.upper(org.seasar.doma.jdbc.criteria.expression.Expressions.upper) Arrays(java.util.Arrays) Statement(org.seasar.doma.jdbc.criteria.statement.Statement) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) Expressions.when(org.seasar.doma.jdbc.criteria.expression.Expressions.when) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Buildable(org.seasar.doma.jdbc.criteria.statement.Buildable) BigDecimal(java.math.BigDecimal) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) CommentContext(org.seasar.doma.jdbc.CommentContext) Expressions.literal(org.seasar.doma.jdbc.criteria.expression.Expressions.literal) Expressions.sum(org.seasar.doma.jdbc.criteria.expression.Expressions.sum) Config(org.seasar.doma.jdbc.Config) Expressions.concat(org.seasar.doma.jdbc.criteria.expression.Expressions.concat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Expressions.count(org.seasar.doma.jdbc.criteria.expression.Expressions.count) Expressions.ltrim(org.seasar.doma.jdbc.criteria.expression.Expressions.ltrim) SelectExpression(org.seasar.doma.jdbc.criteria.expression.SelectExpression) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) Dept_(org.seasar.doma.jdbc.criteria.entity.Dept_) Expressions.countDistinct(org.seasar.doma.jdbc.criteria.expression.Expressions.countDistinct) Expressions.trim(org.seasar.doma.jdbc.criteria.expression.Expressions.trim) Commenter(org.seasar.doma.jdbc.Commenter) Expressions.rtrim(org.seasar.doma.jdbc.criteria.expression.Expressions.rtrim) Expressions.lower(org.seasar.doma.jdbc.criteria.expression.Expressions.lower) DomaException(org.seasar.doma.DomaException) Expressions.avg(org.seasar.doma.jdbc.criteria.expression.Expressions.avg) Expressions.min(org.seasar.doma.jdbc.criteria.expression.Expressions.min) ForUpdateOption(org.seasar.doma.jdbc.criteria.option.ForUpdateOption) Test(org.junit.jupiter.api.Test) Message(org.seasar.doma.message.Message) List(java.util.List) Expressions.select(org.seasar.doma.jdbc.criteria.expression.Expressions.select) Sql(org.seasar.doma.jdbc.Sql) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Expressions.avgAsDouble(org.seasar.doma.jdbc.criteria.expression.Expressions.avgAsDouble) SetOperand(org.seasar.doma.jdbc.criteria.statement.SetOperand) Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) LikeOption(org.seasar.doma.jdbc.criteria.option.LikeOption) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Tuple2(org.seasar.doma.jdbc.criteria.tuple.Tuple2) Expressions.max(org.seasar.doma.jdbc.criteria.expression.Expressions.max) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Test(org.junit.jupiter.api.Test)

Example 5 with Emp_

use of org.seasar.doma.jdbc.criteria.entity.Emp_ in project doma by domaframework.

the class NativeSqlSelectTest method distinct.

@Test
void distinct() {
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).distinct().where(c -> c.eq(e.name, "a"));
    Sql<?> sql = stmt.asSql();
    assertEquals("select distinct t0_.ID, t0_.NAME, t0_.SALARY, t0_.VERSION from EMP t0_ where t0_.NAME = 'a'", sql.getFormattedSql());
}
Also used : Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)150 Emp_ (org.seasar.doma.jdbc.criteria.entity.Emp_)150 NoIdEmp_ (org.seasar.doma.jdbc.criteria.entity.NoIdEmp_)96 Dept_ (org.seasar.doma.jdbc.criteria.entity.Dept_)75 List (java.util.List)72 Emp (org.seasar.doma.jdbc.criteria.entity.Emp)71 BigDecimal (java.math.BigDecimal)68 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)67 DomaException (org.seasar.doma.DomaException)60 MssqlDialect (org.seasar.doma.jdbc.dialect.MssqlDialect)60 Db2Dialect (org.seasar.doma.jdbc.dialect.Db2Dialect)58 Dialect (org.seasar.doma.jdbc.dialect.Dialect)58 Mssql2008Dialect (org.seasar.doma.jdbc.dialect.Mssql2008Dialect)58 OracleDialect (org.seasar.doma.jdbc.dialect.OracleDialect)58 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)58 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)57 Sql (org.seasar.doma.jdbc.Sql)57 Statement (org.seasar.doma.jdbc.criteria.statement.Statement)57 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)55 DistinctOption (org.seasar.doma.jdbc.criteria.option.DistinctOption)55