use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class QueryPerformanceTest method serialization.
@Test
public void serialization() throws Exception {
QCompanies companies = QCompanies.companies;
final QueryMetadata md = new DefaultQueryMetadata();
md.addJoin(JoinType.DEFAULT, companies);
md.addWhere(companies.id.eq(1L));
md.setProjection(companies.name);
Runner.run("ser1", new Benchmark() {
@Override
public void run(int times) throws Exception {
for (int i = 0; i < times; i++) {
SQLSerializer serializer = new SQLSerializer(conf);
serializer.serialize(md, false);
serializer.getConstants();
serializer.getConstantPaths();
assertNotNull(serializer.toString());
}
}
});
}
use of com.querydsl.core.QueryMetadata 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.core.QueryMetadata in project querydsl by querydsl.
the class SQLListenersTest method notifyQuery_parent.
@Test
public void notifyQuery_parent() {
SQLListener listener = createMock(SQLListener.class);
SQLListeners listeners = new SQLListeners(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 PhraseElementTest method test.
@Test
public void test() {
StringPath title = Expressions.stringPath("title");
LuceneSerializer serializer = new LuceneSerializer(false, false);
QueryMetadata metadata = new DefaultQueryMetadata();
assertEquals("title:Hello World", serializer.toQuery(title.eq("Hello World"), metadata).toString());
assertEquals("title:\"Hello World\"", serializer.toQuery(title.eq(new PhraseElement("Hello World")), metadata).toString());
}
use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class TermElementTest method test.
@Test
public void test() {
StringPath title = Expressions.stringPath("title");
LuceneSerializer serializer = new LuceneSerializer(false, true);
QueryMetadata metadata = new DefaultQueryMetadata();
assertEquals("title:\"Hello World\"", serializer.toQuery(title.eq("Hello World"), metadata).toString());
assertEquals("title:Hello World", serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString());
}
Aggregations