Java源码示例:com.querydsl.core.types.EntityPath

示例1
public <T extends CatalogItem> List<T> findVisibleCatalogItems(EntityPath<T> entityPath, List<T> items, String locale) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);
    Date now = new Date();
    List<T> results = new JPAQueryFactory(entityManager)
            .selectFrom(entityPath).where(
                    qCatalogItem.disabled.isFalse(),
                    qCatalogItem.endDate.after(now).or(qCatalogItem.endDate.isNull()),
                    qCatalogItem.startDate.before(now).or(qCatalogItem.startDate.isNull()),
                    qCatalogItem.in(items)
            )
            .fetch();

    results.forEach((catalogItem) -> catalogItem.setLocalizedPresentation(locale));

    return results;

}
 
示例2
/**
 * @param expressions        查询列表
 * @param entityPaths        查询表
 * @param predicates         条件
 * @param orderSpecifierList 排序
 * @param pageNo             页码
 * @param pageSize           页面大小
 */
@Transactional(readOnly = true)
public PageListMapResult queryDslForPageListResult(
        List<Expression> expressions,
        List<EntityPath> entityPaths,
        List<Predicate> predicates,
        List<OrderSpecifier> orderSpecifierList,
        Integer pageNo,
        Integer pageSize) {
    JPAQuery<Tuple> jpaQuery = queryFactory.select(expressions.toArray(new Expression[expressions.size()]))
            .from(entityPaths.toArray(new EntityPath[entityPaths.size()]))
            .where(predicates.toArray(new Predicate[predicates.size()]));
    List<Tuple> tuples = jpaQuery.orderBy(orderSpecifierList.toArray(new OrderSpecifier[orderSpecifierList.size()]))
            .offset((pageNo - 1) * pageSize).limit(pageSize)
            .fetch();
    List<Map<String, Object>> list = new LinkedList<>();//返回结果
    //封装结果
    for (int i = 0; i < tuples.size(); i++) {
        //遍历tuples
        Map<String, Object> map = new LinkedHashMap<>();//一条信息
        for (Expression expression : expressions) {
            map.put(expression.toString().split(" as ")[1],//别名作为Key
                    tuples.get(i).get(expression));//获取结果
        }
        list.add(map);
    }
    PageListMapResult pageListMapResult = new PageListMapResult(list, pageNo, pageSize, jpaQuery.fetchCount());//分页封装
    return pageListMapResult;
}
 
示例3
/**
 * @param expressions        查询列表
 * @param entityPaths        查询表
 * @param predicates         条件
 * @param orderSpecifierList 排序
 * @param pageNo             页码
 * @param pageSize           页面大小
 */
@Transactional(readOnly = true)
public PageListMapResult queryDslForPageListResult(
        List<Expression> expressions,
        List<EntityPath> entityPaths,
        List<Predicate> predicates,
        List<OrderSpecifier> orderSpecifierList,
        Integer pageNo,
        Integer pageSize) {
    JPAQuery<Tuple> jpaQuery = queryFactory.select(expressions.toArray(new Expression[expressions.size()]))
            .from(entityPaths.toArray(new EntityPath[entityPaths.size()]))
            .where(predicates.toArray(new Predicate[predicates.size()]));
    List<Tuple> tuples = jpaQuery.orderBy(orderSpecifierList.toArray(new OrderSpecifier[orderSpecifierList.size()]))
            .offset((pageNo - 1) * pageSize).limit(pageSize)
            .fetch();
    List<Map<String, Object>> list = new LinkedList<>();//返回结果
    //封装结果
    for (int i = 0; i < tuples.size(); i++) {
        //遍历tuples
        Map<String, Object> map = new LinkedHashMap<>();//一条信息
        for (Expression expression : expressions) {
            map.put(expression.toString().split(" as ")[1],//别名作为Key
                    tuples.get(i).get(expression));//获取结果
        }
        list.add(map);
    }
    PageListMapResult pageListMapResult = new PageListMapResult(list, pageNo, pageSize, jpaQuery.fetchCount());//分页封装
    return pageListMapResult;
}
 
示例4
@SuppressWarnings("unchecked")
public static <T> EntityPath<T> getEntityPath(Class<T> entityClass) {
	Class<?> queryClass = getQueryClass(entityClass);
	try {
		String fieldName = firstToLower(entityClass.getSimpleName());
		Field field = queryClass.getField(fieldName);
		return (EntityPath<T>) field.get(entityClass);
	} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
		throw new IllegalStateException("failed to access query class " + queryClass.getName(), e);
	}
}
 
示例5
public QuerydslQueryBackend(QuerydslQueryImpl<T> queryImpl, Class<T> clazz, MetaDataObject parentMeta,
		MetaAttribute parentAttr, boolean addParentSelection) {
	this.queryImpl = queryImpl;

	JPAQueryFactory queryFactory = queryImpl.getQueryFactory();

	if (parentMeta != null) {
		parentFrom = QuerydslUtils.getEntityPath(parentMeta.getImplementationClass());
		root = QuerydslUtils.getEntityPath(clazz);

		Path joinPath = (Path) QuerydslUtils.get(parentFrom, parentAttr.getName());
		joinHelper = new JoinRegistry<>(this, queryImpl);

		joinHelper.putJoin(new MetaAttributePath(), root);

		if (addParentSelection) {
			Expression<Object> parentIdExpr = getParentIdExpression(parentMeta, parentAttr);
			querydslQuery = queryFactory.select(parentIdExpr, root);
		}
		else {
			querydslQuery = queryFactory.select(root);
		}

		querydslQuery = querydslQuery.from(parentFrom);
		if (joinPath instanceof CollectionExpression) {
			querydslQuery = querydslQuery.join((CollectionExpression) joinPath, root);
		}
		else {
			querydslQuery = querydslQuery.join((EntityPath) joinPath, root);
		}
	}
	else {
		root = QuerydslUtils.getEntityPath(clazz);
		joinHelper = new JoinRegistry<>(this, queryImpl);
		joinHelper.putJoin(new MetaAttributePath(), root);
		querydslQuery = queryFactory.select(root);
		querydslQuery = querydslQuery.from((EntityPath) root);
	}
}
 
示例6
@SuppressWarnings("unchecked")
public static <T> EntityPath<T> getEntityPath(Class<T> entityClass) {
	Class<?> queryClass = getQueryClass(entityClass);
	try {
		String fieldName = firstToLower(entityClass.getSimpleName());
		Field field = queryClass.getField(fieldName);
		return (EntityPath<T>) field.get(entityClass);
	}
	catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
		throw new IllegalStateException("failed to access query class " + queryClass.getName(), e);
	}
}
 
示例7
public QuerydslQueryBackend(QuerydslQueryImpl<T> queryImpl, Class<T> clazz, MetaDataObject parentMeta,
		MetaAttribute parentAttr, boolean addParentSelection) {
	this.queryImpl = queryImpl;

	JPAQueryFactory queryFactory = queryImpl.getQueryFactory();

	if (parentMeta != null) {
		parentFrom = QuerydslUtils.getEntityPath(parentMeta.getImplementationClass());
		root = QuerydslUtils.getEntityPath(clazz);

		Path joinPath = (Path) QuerydslUtils.get(parentFrom, parentAttr.getName());
		joinHelper = new JoinRegistry<>(this, queryImpl);

		joinHelper.putJoin(new MetaAttributePath(), root);

		if (addParentSelection) {
			Expression<Object> parentIdExpr = getParentIdExpression(parentMeta, parentAttr);
			querydslQuery = queryFactory.select(parentIdExpr, root);
		}
		else {
			querydslQuery = queryFactory.select(root);
		}

		querydslQuery = querydslQuery.from(parentFrom);
		if (joinPath instanceof CollectionExpression) {
			querydslQuery = querydslQuery.join((CollectionExpression) joinPath, root);
		}
		else {
			querydslQuery = querydslQuery.join((EntityPath) joinPath, root);
		}
	}
	else {
		root = QuerydslUtils.getEntityPath(clazz);
		joinHelper = new JoinRegistry<>(this, queryImpl);
		joinHelper.putJoin(new MetaAttributePath(), root);
		querydslQuery = queryFactory.select(root);
		querydslQuery = querydslQuery.from((EntityPath) root);
	}
}
 
示例8
public <T extends CatalogItem, P extends CatalogItem> List<P> findForeignHolder(EntityPath<P> hp,
                                                                                ListPath<T, ? extends SimpleExpression<T>> h, T c) {

    return new JPAQueryFactory(entityManager)
            .selectFrom(hp)
            .where(h.contains(c))
            .fetch();
}
 
示例9
public <T extends CatalogItem> List<T> findBySearchCriteria(EntityPath<T> entityPath, String searchCriteria,
                                                            Integer offset, Integer limit, String orderBy, Boolean isDesc) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);

    JPAQuery<T> query = new JPAQueryFactory(entityManager).selectFrom(entityPath)
            .where(buildSearchPredicate(searchCriteria, qCatalogItem));

    addOffsetAndLimitToQuery(offset, limit, query, orderBy, isDesc, qCatalogItem);

    return query.fetch();
}
 
示例10
public Long countBySearchCriteria(EntityPath<? extends CatalogItem> entityPath, String searchCriteria) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);
    JPAQuery query = new JPAQueryFactory(entityManager)
            .selectFrom(qCatalogItem)
            .where(buildSearchPredicate(searchCriteria, qCatalogItem));
    return query.fetchCount();
}
 
示例11
/**
 * Creates a new {@link QuerydslKeyValueRepository} for the given {@link EntityInformation},
 * {@link KeyValueOperations} and {@link EntityPathResolver}.
 *
 * @param entityInformation must not be {@literal null}.
 * @param operations must not be {@literal null}.
 * @param resolver must not be {@literal null}.
 */
public QuerydslKeyValueRepository(EntityInformation<T, ID> entityInformation, KeyValueOperations operations,
		EntityPathResolver resolver) {

	super(entityInformation, operations);

	Assert.notNull(resolver, "EntityPathResolver must not be null!");

	EntityPath<T> path = resolver.createPath(entityInformation.getJavaType());
	this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
}
 
示例12
public void add(EntityPath entityPath) {
    entityPaths.add(entityPath);
}
 
示例13
public EntityPath[] entityPathToArray() {
    return entityPaths.toArray(new EntityPath[entityPaths.size()]);
}
 
示例14
public void add(EntityPath entityPath) {
    entityPaths.add(entityPath);
}
 
示例15
public EntityPath[] entityPathToArray() {
    return entityPaths.toArray(new EntityPath[entityPaths.size()]);
}
 
示例16
@Override
public EntityPath getParentRoot() {
	return parentFrom;
}
 
示例17
@Override
public <E> EntityPath<E> getJoin(MetaAttributePath path, JoinType defaultJoinType) {
	return (EntityPath<E>) joinHelper.getOrCreateJoin(path, defaultJoinType);
}
 
示例18
@Override
public EntityPath getParentRoot() {
	return parentFrom;
}
 
示例19
@Override
public <E> EntityPath<E> getJoin(MetaAttributePath path) {
	return (EntityPath<E>) joinHelper.getOrCreateJoin(path);
}
 
示例20
public QDataTablesRepositoryImpl(JpaEntityInformation<T, ID> entityInformation,
    EntityManager entityManager, EntityPathResolver resolver) {
  super(entityInformation, entityManager);
  EntityPath<T> path = resolver.createPath(entityInformation.getJavaType());
  this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
}
 
示例21
public Long countAll(EntityPath<? extends CatalogItem> entityPath) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);
    JPAQuery query = new JPAQueryFactory(entityManager).selectFrom(qCatalogItem);
    return query.fetchCount();
}
 
示例22
public <T extends CatalogItem> List<T> findAll(EntityPath<T> entityPath, Integer offset, Integer limit, String orderBy, Boolean isDesc) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);

    JPAQuery<T> query = new JPAQueryFactory(entityManager).selectFrom(entityPath);

    addOffsetAndLimitToQuery(offset, limit, query, orderBy, isDesc, qCatalogItem);

    return query.fetch();
}
 
示例23
/**
 * Create a new root query using {@link #jpaQuery()}
 *
 * @param entityPath represents the entity type to be used on the FROM clause in the SQL query
 * @param <V> value type of this {@link EntityPath}
 * @return a new {@link JPAQuery} typed by the {@link EntityPath}
 */
default <V> JPAQuery<T> jpaQueryFor(EntityPath<V> entityPath) {
    return this.jpaQuery().from(entityPath);
}
 
示例24
<P> EntityPath<P> getParentRoot(); 
示例25
<E> EntityPath<E> getJoin(MetaAttributePath path, JoinType defaultJoinType); 
示例26
<P> EntityPath<P> getParentRoot(); 
示例27
public <E> EntityPath<E> getJoin(MetaAttributePath path);