Search in sources :

Example 21 with QEmployee

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

the class SubqueriesBase method subQuery_innerJoin.

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

Example 22 with QEmployee

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

the class SubqueriesBase method subQuery_leftJoin.

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

Example 23 with QEmployee

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

the class UnionBase method union5.

// FIXME for CUBRID
// Teradata: The ORDER BY clause must contain only integer constants.
@SuppressWarnings("unchecked")
@Test
@ExcludeIn({ DERBY, CUBRID, FIREBIRD, TERADATA })
// FIXME
@Ignore
public void union5() {
    /* (select e.ID, e.FIRSTNAME, superior.ID as sup_id, superior.FIRSTNAME as sup_name
         * from EMPLOYEE e join EMPLOYEE superior on e.SUPERIOR_ID = superior.ID)
         * union
         * (select e.ID, e.FIRSTNAME, null, null from EMPLOYEE e)
         * order by ID asc
         */
    QEmployee superior = new QEmployee("superior");
    SubQueryExpression<Tuple> sq1 = query().from(employee).join(employee.superiorIdKey, superior).select(employee.id, employee.firstname, superior.id.as("sup_id"), superior.firstname.as("sup_name"));
    SubQueryExpression<Tuple> sq2 = query().from(employee).select(employee.id, employee.firstname, null, null);
    List<Tuple> results = query().union(sq1, sq2).orderBy(employee.id.asc()).fetch();
    for (Tuple result : results) {
        System.err.println(Arrays.asList(result));
    }
}
Also used : QEmployee(com.querydsl.sql.domain.QEmployee) Tuple(com.querydsl.core.Tuple) Ignore(org.junit.Ignore) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 24 with QEmployee

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

the class SQLSerializerTest method withRecursive2.

@SuppressWarnings("unchecked")
@Test
public void withRecursive2() {
    /*with sub (id, firstname, superior_id) as (
            select id, firstname, superior_id from employee where firstname like 'Mike'
            union all
            select employee.id, employee.firstname, employee.superior_id from sub, employee
            where employee.superior_id = sub.id)
        select * from sub;*/
    QEmployee e = QEmployee.employee;
    PathBuilder<Tuple> sub = new PathBuilder<Tuple>(Tuple.class, "sub");
    SQLQuery<?> query = new SQLQuery<Void>(SQLTemplates.DEFAULT);
    query.withRecursive(sub, sub.get(e.id), sub.get(e.firstname), sub.get(e.superiorId)).as(unionAll(select(e.id, e.firstname, e.superiorId).from(e).where(e.firstname.eq("Mike")), select(e.id, e.firstname, e.superiorId).from(e, sub).where(e.superiorId.eq(sub.get(e.id))))).from(sub);
    QueryMetadata md = query.getMetadata();
    md.setProjection(Wildcard.all);
    SQLSerializer serializer = new SQLSerializer(Configuration.DEFAULT);
    serializer.serialize(md, false);
    assertEquals("with recursive sub (ID, FIRSTNAME, SUPERIOR_ID) as ((select EMPLOYEE.ID, EMPLOYEE.FIRSTNAME, EMPLOYEE.SUPERIOR_ID\n" + "from EMPLOYEE EMPLOYEE\n" + "where EMPLOYEE.FIRSTNAME = ?)\n" + "union all\n" + "(select EMPLOYEE.ID, EMPLOYEE.FIRSTNAME, EMPLOYEE.SUPERIOR_ID\n" + "from EMPLOYEE EMPLOYEE, sub\n" + "where EMPLOYEE.SUPERIOR_ID = sub.ID))\n" + "select *\n" + "from sub", serializer.toString());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) QEmployee(com.querydsl.sql.domain.QEmployee) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Example 25 with QEmployee

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

the class ForeignKeyTest method on.

@Test
public void on() {
    QEmployee employee = new QEmployee("employee");
    QEmployee employee2 = new QEmployee("employee2");
    ForeignKey<Employee> foreignKey = new ForeignKey<Employee>(employee, employee.superiorId, "ID");
    assertEquals("employee.superiorId = employee2.ID", foreignKey.on(employee2).toString());
    foreignKey = new ForeignKey<Employee>(employee, ImmutableList.of(employee.superiorId, employee.firstname), ImmutableList.of("ID", "FN"));
    assertEquals("employee.superiorId = employee2.ID && employee.firstname = employee2.FN", foreignKey.on(employee2).toString());
}
Also used : Employee(com.querydsl.sql.domain.Employee) QEmployee(com.querydsl.sql.domain.QEmployee) 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