use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class SQLListenersTest method notifyQuery.
@Test
public void notifyQuery() {
SQLListener listener = createMock(SQLListener.class);
SQLListeners listeners = new SQLListeners();
listeners.add(listener);
QueryMetadata md = new DefaultQueryMetadata();
listener.notifyQuery(md);
replay(listener);
listeners.notifyQuery(md);
verify(listener);
}
use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class SQLSerializerTest method withRecursive.
@SuppressWarnings("unchecked")
@Test
public void withRecursive() {
/*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, 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 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.core.QueryMetadata in project querydsl by querydsl.
the class QueryMetadataTest method reusage.
@Test
public void reusage() {
QueryMetadata metadata = new DefaultQueryMetadata();
metadata.addJoin(JoinType.DEFAULT, cat);
metadata.addWhere(cat.name.startsWith("A"));
CollQuery<?> query = new CollQuery<Void>(metadata);
query.bind(cat, cats);
assertEquals(Arrays.asList(c3), query.select(cat).fetch());
}
use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class JPQLSerializerTest method openJPA_variables.
@Test
public void openJPA_variables() {
QCat cat = QCat.cat;
JPQLSerializer serializer = new JPQLSerializer(OpenJPATemplates.DEFAULT);
QueryMetadata md = new DefaultQueryMetadata();
md.addJoin(JoinType.DEFAULT, cat);
md.addJoin(JoinType.INNERJOIN, cat.mate);
md.addJoinCondition(cat.mate.alive);
serializer.serialize(md, false, null);
assertEquals("select cat_\nfrom Cat cat_\n inner join cat_.mate on cat_.mate.alive", serializer.toString());
}
use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class JPQLSerializerTest method treat.
@SuppressWarnings("unchecked")
@Test
public void treat() {
QCat cat = QCat.cat;
JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
QueryMetadata md = new DefaultQueryMetadata();
md.addJoin(JoinType.DEFAULT, cat);
md.addJoin(JoinType.JOIN, cat.mate.as((Path) QDomesticCat.domesticCat));
md.setProjection(QDomesticCat.domesticCat);
serializer.serialize(md, false, null);
assertEquals("select domesticCat\n" + "from Cat cat\n" + " inner join treat(cat.mate as DomesticCat) as domesticCat", serializer.toString());
}
Aggregations