Search in sources :

Example 6 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SubqueriesBase method list_in_query.

@Test
@ExcludeIn({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, SQLITE, SQLSERVER })
public void list_in_query() {
    QEmployee employee2 = new QEmployee("employee2");
    query().from(employee).where(Expressions.list(employee.id, employee.lastname).in(query().from(employee2).select(employee2.id, employee2.lastname))).select(employee.id).fetch();
}
Also used : QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 7 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SubqueriesBase method subQuery_rightJoin.

@Test
@ExcludeIn(SQLITE)
public void subQuery_rightJoin() {
    SubQueryExpression<Integer> sq = query().from(employee2).select(employee2.id);
    QEmployee sqEmp = new QEmployee("sq");
    query().from(employee).rightJoin(sq, sqEmp).on(sqEmp.id.eq(employee.id)).select(employee.id).fetch();
}
Also used : QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 8 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SelectOracleBase method sumOver.

@Test
@IncludeIn(ORACLE)
@SkipForQuoted
public void sumOver() throws SQLException {
    //        SQL> select deptno,
    //        2  ename,
    //        3  sal,
    //        4  sum(sal) over (partition by deptno
    //        5  order by sal,ename) CumDeptTot,
    //        6  sum(sal) over (partition by deptno) SalByDept,
    //        7  sum(sal) over (order by deptno, sal) CumTot,
    //        8  sum(sal) over () TotSal
    //        9  from emp
    //       10  order by deptno, sal;
    expectedQuery = "select e.LASTNAME, e.SALARY, " + "sum(e.SALARY) over (partition by e.SUPERIOR_ID order by e.LASTNAME asc, e.SALARY asc), " + "sum(e.SALARY) over (order by e.SUPERIOR_ID asc, e.SALARY asc), " + "sum(e.SALARY) over () from EMPLOYEE e order by e.SALARY asc, e.SUPERIOR_ID asc";
    oracleQuery().from(employee).orderBy(employee.salary.asc(), employee.superiorId.asc()).select(employee.lastname, employee.salary, SQLExpressions.sum(employee.salary).over().partitionBy(employee.superiorId).orderBy(employee.lastname, employee.salary), SQLExpressions.sum(employee.salary).over().orderBy(employee.superiorId, employee.salary), SQLExpressions.sum(employee.salary).over()).fetch();
    // shorter version
    QEmployee e = employee;
    oracleQuery().from(e).orderBy(e.salary.asc(), e.superiorId.asc()).select(e.lastname, e.salary, SQLExpressions.sum(e.salary).over().partitionBy(e.superiorId).orderBy(e.lastname, e.salary), SQLExpressions.sum(e.salary).over().orderBy(e.superiorId, e.salary), SQLExpressions.sum(e.salary).over()).fetch();
}
Also used : QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test) IncludeIn(com.querydsl.core.testutil.IncludeIn)

Example 9 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SerializationTest method delete_with_subQuery_exists.

@Test
public void delete_with_subQuery_exists() {
    QSurvey survey1 = new QSurvey("s1");
    QEmployee employee = new QEmployee("e");
    SQLDeleteClause delete = new SQLDeleteClause(connection, SQLTemplates.DEFAULT, survey1);
    delete.where(survey1.name.eq("XXX"), selectOne().from(employee).where(survey1.id.eq(employee.id)).exists());
    assertEquals("delete from SURVEY\n" + "where SURVEY.NAME = ? and exists (select 1\n" + "from EMPLOYEE e\n" + "where SURVEY.ID = e.ID)", delete.toString());
}
Also used : SQLDeleteClause(com.querydsl.sql.dml.SQLDeleteClause) QSurvey(com.querydsl.sql.domain.QSurvey) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 10 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SQLSerializerTest method noSchemaInWhere.

@Test
public void noSchemaInWhere() {
    Configuration defaultWithPrintSchema = new Configuration(new SQLTemplates(Keywords.DEFAULT, "\"", '\\', false, false));
    defaultWithPrintSchema.getTemplates().setPrintSchema(true);
    QEmployee e = QEmployee.employee;
    SQLDeleteClause delete = new SQLDeleteClause(EasyMock.createNiceMock(Connection.class), defaultWithPrintSchema, e);
    delete.where(e.id.gt(100));
    assertEquals("delete from PUBLIC.EMPLOYEE\n" + "where EMPLOYEE.ID > ?", delete.toString());
}
Also used : SQLDeleteClause(com.querydsl.sql.dml.SQLDeleteClause) Connection(java.sql.Connection) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Aggregations

QEmployee (com.querydsl.sql.domain.QEmployee)27 Test (org.junit.Test)27 QSurvey (com.querydsl.sql.domain.QSurvey)10 SQLDeleteClause (com.querydsl.sql.dml.SQLDeleteClause)6 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)4 SQLUpdateClause (com.querydsl.sql.dml.SQLUpdateClause)4 Tuple (com.querydsl.core.Tuple)3 QueryMetadata (com.querydsl.core.QueryMetadata)2 Param (com.querydsl.core.types.dsl.Param)2 Employee (com.querydsl.sql.domain.Employee)2 Connection (java.sql.Connection)2 QueryModifiers (com.querydsl.core.QueryModifiers)1 QueryMixin (com.querydsl.core.support.QueryMixin)1 IncludeIn (com.querydsl.core.testutil.IncludeIn)1 SubQueryExpression (com.querydsl.core.types.SubQueryExpression)1 Ignore (org.junit.Ignore)1