Search in sources :

Example 1 with DefaultQueryMetadata

use of com.querydsl.core.DefaultQueryMetadata in project querydsl by querydsl.

the class JPQLSerializerTest method join_with.

@Test
public void join_with() {
    QCat cat = QCat.cat;
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.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 with cat.mate.alive", serializer.toString());
}
Also used : QCat(com.querydsl.core.domain.QCat) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 2 with DefaultQueryMetadata

use of com.querydsl.core.DefaultQueryMetadata in project querydsl by querydsl.

the class JPQLSerializerTest method delete_clause_uses_dELETE_fROM.

@Test
public void delete_clause_uses_dELETE_fROM() {
    QEmployee employee = QEmployee.employee;
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
    QueryMetadata md = new DefaultQueryMetadata();
    md.addJoin(JoinType.DEFAULT, employee);
    md.addWhere(employee.lastName.isNull());
    serializer.serializeForDelete(md);
    assertEquals("delete from Employee employee\nwhere employee.lastName is null", serializer.toString());
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QEmployee(com.querydsl.jpa.domain.QEmployee) Test(org.junit.Test)

Example 3 with DefaultQueryMetadata

use of com.querydsl.core.DefaultQueryMetadata 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) Test(org.junit.Test)

Example 4 with DefaultQueryMetadata

use of com.querydsl.core.DefaultQueryMetadata in project querydsl by querydsl.

the class QueryPerformanceTest method querydsl14.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void querydsl14() throws Exception {
    try (Connection conn = Connections.getH2()) {
        QCompanies companies = QCompanies.companies;
        SQLQuery<?> query = new SQLQuery<Void>(conn, conf, new DefaultQueryMetadata());
        query.from(companies).where(companies.id.eq((long) ThreadLocalRandom.current().nextLong())).select(companies.name).fetch();
    }
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Connection(java.sql.Connection) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 5 with DefaultQueryMetadata

use of com.querydsl.core.DefaultQueryMetadata in project querydsl by querydsl.

the class SQLListenersTest method notifyQuery_detailedListener_contexSetting.

@Test
public void notifyQuery_detailedListener_contexSetting() {
    SQLListenerContext sqlListenerContext = new SQLListenerContextImpl(new DefaultQueryMetadata());
    SQLDetailedListener listenerParent = new AssertingDetailedListener("keyParent", "valueParent");
    SQLDetailedListener listener1 = new AssertingDetailedListener("key1", "value1");
    SQLDetailedListener listener2 = new AssertingDetailedListener("key1", "value1");
    SQLListeners listeners = new SQLListeners(listenerParent);
    listeners.add(listener1);
    listeners.add(listener2);
    listeners.start(sqlListenerContext);
    listeners.preRender(sqlListenerContext);
    listeners.rendered(sqlListenerContext);
    listeners.prePrepare(sqlListenerContext);
    listeners.prepared(sqlListenerContext);
    listeners.preExecute(sqlListenerContext);
    listeners.preExecute(sqlListenerContext);
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Aggregations

DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)28 Test (org.junit.Test)24 QueryMetadata (com.querydsl.core.QueryMetadata)20 QCat (com.querydsl.core.domain.QCat)8 StringPath (com.querydsl.core.types.dsl.StringPath)6 Connection (java.sql.Connection)3 Benchmark (org.openjdk.jmh.annotations.Benchmark)3 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)3 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)3 LuceneSerializer (com.querydsl.lucene5.LuceneSerializer)2 QAnimal (com.querydsl.core.domain.QAnimal)1 GroupExpression (com.querydsl.core.group.GroupExpression)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 QEmployee (com.querydsl.jpa.domain.QEmployee)1 SAnimal (com.querydsl.jpa.domain.sql.SAnimal)1 PhraseElement (com.querydsl.lucene5.PhraseElement)1