Search in sources :

Example 36 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) StringPath(com.querydsl.core.types.dsl.StringPath) Test(org.junit.Test)

Example 37 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) Test(org.junit.Test)

Example 38 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) StringPath(com.querydsl.core.types.dsl.StringPath) Test(org.junit.Test)

Example 39 with QueryMetadata

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

the class JPAQueryMixin method convertPathForOrder.

private <T> Path<T> convertPathForOrder(Path<T> path) {
    PathMetadata metadata = path.getMetadata();
    // at least three levels
    if (metadata.getParent() != null && !metadata.getParent().getMetadata().isRoot()) {
        Set<Expression<?>> exprs = Sets.newHashSet();
        QueryMetadata md = getMetadata();
        exprs.addAll(md.getGroupBy());
        if (md.getProjection() != null) {
            exprs.add(md.getProjection());
        }
        if (md.getWhere() != null) {
            exprs.add(md.getWhere());
        }
        if (md.getHaving() != null) {
            exprs.add(md.getHaving());
        }
        List<Path<?>> paths = Lists.newArrayList();
        // extract paths
        PathsExtractor.DEFAULT.visit(exprs, paths);
        if (!paths.contains(path) && !paths.contains(metadata.getParent())) {
            Path<?> shortened = shorten(metadata.getParent(), paths);
            return ExpressionUtils.path(path.getType(), new PathMetadata(shortened, metadata.getElement(), metadata.getPathType()));
        } else {
            return path;
        }
    } else {
        return path;
    }
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata)

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