Search in sources :

Example 1 with EntityPathBase

use of com.querydsl.core.types.dsl.EntityPathBase in project querydsl by querydsl.

the class JPQLSerializerTest method fromWithCustomEntityName.

@Test
public void fromWithCustomEntityName() {
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
    EntityPath<Location> entityPath = new EntityPathBase<Location>(Location.class, "entity");
    QueryMetadata md = new DefaultQueryMetadata();
    md.addJoin(JoinType.DEFAULT, entityPath);
    serializer.serialize(md, false, null);
    assertEquals("select entity\nfrom Location2 entity", serializer.toString());
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) EntityPathBase(com.querydsl.core.types.dsl.EntityPathBase) Location(com.querydsl.jpa.domain.Location) Test(org.junit.Test)

Example 2 with EntityPathBase

use of com.querydsl.core.types.dsl.EntityPathBase in project querydsl by querydsl.

the class CustomFinder method findCustom.

@SuppressWarnings("unchecked")
public static <T> List<T> findCustom(EntityManager em, Class<T> entityClass, Map<String, ?> filters, String sort) {
    EntityPath<T> entityPath = new EntityPathBase<T>(entityClass, "entity");
    BooleanBuilder builder = new BooleanBuilder();
    for (Map.Entry<String, ?> entry : filters.entrySet()) {
        SimplePath<Object> property = Expressions.path((Class) entry.getValue().getClass(), entityPath, entry.getKey());
        builder.and(property.eq(entry.getValue()));
    }
    ComparablePath<?> sortProperty = Expressions.comparablePath(Comparable.class, entityPath, sort);
    return new JPAQuery<Void>(em).from(entityPath).where(builder.getValue()).orderBy(sortProperty.asc()).select(entityPath).fetch();
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) EntityPathBase(com.querydsl.core.types.dsl.EntityPathBase) Map(java.util.Map)

Aggregations

EntityPathBase (com.querydsl.core.types.dsl.EntityPathBase)2 BooleanBuilder (com.querydsl.core.BooleanBuilder)1 DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)1 QueryMetadata (com.querydsl.core.QueryMetadata)1 Location (com.querydsl.jpa.domain.Location)1 Map (java.util.Map)1 Test (org.junit.Test)1