All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eurodyn.qlack.fuse.cm.util.JPAQueryUtil Maven / Gradle / Ivy

There is a newer version: 3.6.8
Show newest version
package com.eurodyn.qlack.fuse.cm.util;

import com.eurodyn.qlack.fuse.cm.model.Node;
import com.eurodyn.qlack.fuse.cm.model.QNode;
import com.eurodyn.qlack.fuse.cm.model.QNodeAttribute;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import javax.persistence.EntityManager;

/**
 * A Util class for the DocumentService class operations.
 *
 * @author European Dynamics SA
 */
public class JPAQueryUtil {

  private static final QNode Q_NODE = QNode.node;

  private static final QNodeAttribute Q_NODE_ATTRIBUTE = new QNodeAttribute("nodeAttribute");

  /**
   * Default Constructor
   */
  private JPAQueryUtil() {
  }

  /**
   * Creates a new JPAQuery to retrieve the nodes (folder/file) which have a required node attribute
   * name.
   *
   * @param em the Entity Manager instance
   * @param name the name to search for
   * @param parentNodeID the id of the parent folder
   * @return the created query
   */
  public static JPAQuery createJpaQueryForName(EntityManager em, String name,
      String parentNodeID) {
    return new JPAQueryFactory(em)
        .selectFrom(Q_NODE).innerJoin(Q_NODE.attributes, Q_NODE_ATTRIBUTE)
        .where(Q_NODE.parent.id.eq(parentNodeID)
            .and(Q_NODE_ATTRIBUTE.name.eq(CMConstants.ATTR_NAME))
            .and(Q_NODE_ATTRIBUTE.value.eq(name)));
  }

  /**
   * Creates a new JPAQuery to search all the nodes that their name is contained in a list of
   * strings.
   *
   * @param em the Entity Manager instance
   * @param fileNames the names to search for
   * @param parentNodeID the id of the parent folder
   * @return the created query
   */
  public static JPAQuery createJpaQueryForMultipleNames(EntityManager em,
      List fileNames,
      String parentNodeID) {
    return new JPAQueryFactory(em)
        .selectFrom(Q_NODE).innerJoin(Q_NODE.attributes, Q_NODE_ATTRIBUTE)
        .where(Q_NODE.parent.id.eq(parentNodeID)
            .and(Q_NODE_ATTRIBUTE.name.eq(CMConstants.ATTR_NAME))
            .and(Q_NODE_ATTRIBUTE.value.in(fileNames)));
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy