Search in sources :

Example 31 with QueryMetadata

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());
            }
        }
    });
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Benchmark(com.querydsl.core.testutil.Benchmark) Test(org.junit.Test)

Example 32 with QueryMetadata

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());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) QEmployee(com.querydsl.sql.domain.QEmployee) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Example 33 with QueryMetadata

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);
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 34 with QueryMetadata

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());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) StringPath(com.querydsl.core.types.dsl.StringPath) PhraseElement(com.querydsl.lucene5.PhraseElement) LuceneSerializer(com.querydsl.lucene5.LuceneSerializer) Test(org.junit.Test)

Example 35 with QueryMetadata

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());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) TermElement(com.querydsl.lucene5.TermElement) StringPath(com.querydsl.core.types.dsl.StringPath) LuceneSerializer(com.querydsl.lucene5.LuceneSerializer) Test(org.junit.Test)

Aggregations

QueryMetadata (com.querydsl.core.QueryMetadata)39 Test (org.junit.Test)35 DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)20 JoinExpression (com.querydsl.core.JoinExpression)15 QCat (com.querydsl.jpa.domain.QCat)8 QCat (com.querydsl.core.domain.QCat)7 StringPath (com.querydsl.core.types.dsl.StringPath)6 Tuple (com.querydsl.core.Tuple)2 QEmployee (com.querydsl.jpa.domain.QEmployee)2 QBookVersion (com.querydsl.jpa.domain4.QBookVersion)2 LuceneSerializer (com.querydsl.lucene5.LuceneSerializer)2 QEmployee (com.querydsl.sql.domain.QEmployee)2 Benchmark (com.querydsl.core.testutil.Benchmark)1 EntityPath (com.querydsl.core.types.EntityPath)1 Path (com.querydsl.core.types.Path)1 EntityPathBase (com.querydsl.core.types.dsl.EntityPathBase)1 NumberPath (com.querydsl.core.types.dsl.NumberPath)1 Location (com.querydsl.jpa.domain.Location)1 QCompany (com.querydsl.jpa.domain.QCompany)1 QDepartment (com.querydsl.jpa.domain.QDepartment)1