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();
}
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();
}
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));
}
}
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());
}
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());
}
Aggregations