Search in sources :

Example 6 with DefaultQueryMetadata

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

the class AbstractBaseTest method testQuery.

protected TestQuery<?> testQuery() {
    TestQuery<Void> testQuery = new TestQuery<Void>(connection, configuration, new DefaultQueryMetadata());
    testQuery.addListener(new TestLoggingListener());
    return testQuery;
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata)

Example 7 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)

Example 8 with DefaultQueryMetadata

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

Example 9 with DefaultQueryMetadata

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

Example 10 with DefaultQueryMetadata

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

the class SerializationTest method expressions.

@Test
public void expressions() throws Exception {
    Map<Class<?>, Object> args = Maps.newHashMap();
    args.put(Object.class, "obj");
    args.put(BeanPath.class, new EntityPathBase<Object>(Object.class, "obj"));
    args.put(Class.class, Integer.class);
    args.put(Class[].class, new Class<?>[] { Object.class, Object.class });
    args.put(java.util.Date.class, new java.util.Date(0));
    args.put(java.sql.Date.class, new java.sql.Date(0));
    args.put(java.sql.Time.class, new java.sql.Time(0));
    args.put(java.sql.Timestamp.class, new java.sql.Timestamp(0));
    args.put(Expression.class, Expressions.enumPath(Gender.class, "e"));
    args.put(Expression[].class, new Expression<?>[] { Expressions.enumPath(Gender.class, "e"), Expressions.stringPath("s") });
    args.put(FactoryExpression.class, Projections.tuple(Expressions.stringPath("str")));
    args.put(GroupExpression.class, GroupBy.avg(Expressions.numberPath(Integer.class, "num")));
    args.put(Number.class, 1);
    args.put(Operator.class, Ops.AND);
    args.put(Path.class, Expressions.stringPath("str"));
    args.put(PathBuilderValidator.class, PathBuilderValidator.DEFAULT);
    args.put(PathMetadata.class, PathMetadataFactory.forVariable("obj"));
    args.put(PathInits.class, PathInits.DEFAULT);
    args.put(Predicate.class, Expressions.path(Object.class, "obj").isNull());
    args.put(QueryMetadata.class, new DefaultQueryMetadata());
    args.put(String.class, "obj");
    Reflections reflections = new Reflections();
    Set<Class<? extends Expression>> types = reflections.getSubTypesOf(Expression.class);
    for (Class<?> type : types) {
        if (!type.isInterface() && !type.isMemberClass() && !Modifier.isAbstract(type.getModifiers())) {
            for (Constructor<?> c : type.getConstructors()) {
                Object[] parameters = new Object[c.getParameterTypes().length];
                for (int i = 0; i < c.getParameterTypes().length; i++) {
                    parameters[i] = Objects.requireNonNull(args.get(c.getParameterTypes()[i]), c.getParameterTypes()[i].getName());
                }
                c.setAccessible(true);
                Object o = c.newInstance(parameters);
                assertEquals(o, Serialization.serialize(o));
            }
        }
    }
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) GroupExpression(com.querydsl.core.group.GroupExpression) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Aggregations

DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)25 Test (org.junit.Test)24 QueryMetadata (com.querydsl.core.QueryMetadata)19 QCat (com.querydsl.core.domain.QCat)7 StringPath (com.querydsl.core.types.dsl.StringPath)6 LuceneSerializer (com.querydsl.lucene5.LuceneSerializer)2 GroupExpression (com.querydsl.core.group.GroupExpression)1 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 QEmployee (com.querydsl.jpa.domain.QEmployee)1 SAnimal (com.querydsl.jpa.domain.sql.SAnimal)1 PhraseElement (com.querydsl.lucene5.PhraseElement)1 TermElement (com.querydsl.lucene5.TermElement)1 Configuration (com.querydsl.sql.Configuration)1 MySQLTemplates (com.querydsl.sql.MySQLTemplates)1 Reflections (org.reflections.Reflections)1