@Override
  public Withdrawal get(Trading trading, Currency currency) {
    TypedQuery<Withdrawal> query =
        (TypedQuery<Withdrawal>)
            em.createQuery(
                "SELECT w FROM Withdrawal w WHERE w.pk.trading=:trading AND w.pk.currency=:currency");
    query.setParameter("trading", trading);
    query.setParameter("currency", currency);

    try {
      return query.getSingleResult();
    } catch (NoResultException e) {
      return null;
    }
  }
 public User findUser(String username, String passwd) {
   try {
     TypedQuery<User> query =
         entityManager.createQuery(
             "SELECT u FROM User u WHERE u.username = :username and u.passwd=:passwd", User.class);
     query.setParameter("username", username);
     query.setParameter("passwd", passwd);
     User u = query.getSingleResult();
     u.setPermissions("root"); // TODO: dit moet natuurlijk anders! (moet uit de DB komen)
     return u;
   } catch (NoResultException e) {
     e.printStackTrace();
   }
   return null;
 }
  @Override
  public List<Withdrawal> getWithdrawalsOfTrading(Trading trading) {
    TypedQuery<Withdrawal> query =
        (TypedQuery<Withdrawal>)
            em.createQuery("SELECT w FROM Withdrawal w WHERE w.pk.trading=:trading");
    query.setParameter("trading", trading);

    return query.getResultList();
  }
 public static TypedQuery<Offering> findOfferingsByCourseId(Long courseId) {
   if (courseId == null) throw new IllegalArgumentException("The courseID argument is required");
   EntityManager em = entityManager();
   TypedQuery<Offering> q =
       em.createQuery(
           "SELECT Offering FROM Offering AS offering WHERE offering.course.id = :courseId",
           Offering.class);
   q.setParameter("courseId", courseId);
   return q;
 }
 @Override
 public List<Payment> findByMerchantId(int merchantId) {
   TypedQuery<Payment> query =
       em.createQuery("SELECT p FROM Payment p" + "WHERE p.merchantId = :id", Payment.class);
   query.setParameter("id", merchantId);
   log.debug(
       "The query selecting all payments of a merchant with id="
           + merchantId
           + " has been created.");
   return query.getResultList();
 }
示例#6
0
 public static List<TuserInfo> getList(String where, String orderby, List<Object> params) {
   TypedQuery<TuserInfo> q =
       entityManager().createQuery("from TuserInfo o " + where + orderby, TuserInfo.class);
   if (null != params && !params.isEmpty()) {
     int index = 1;
     for (Object param : params) {
       q.setParameter(index, param);
       index = index + 1;
     }
   }
   return q.getResultList();
 }
示例#7
0
  public static List<Node> findNodesByParent(Node parent, long regionId) {
    if (parent == null) {
      throw new IllegalArgumentException("The parent argument is required");
    }
    List<Node> resultList = new ArrayList<Node>();
    Set<Node> availableList = new HashSet<Node>();
    Set<Node> currentList;

    EntityManager em = Node.entityManager();

    TypedQuery<Node> q;
    if (NO_REGION == regionId) {
      q = em.createQuery("SELECT o FROM Node AS o WHERE o.active = :active", Node.class);
    } else {
      q =
          em.createQuery(
              "SELECT o FROM Node AS o WHERE o.region = :region AND o.active = :active",
              Node.class);
      q.setParameter("region", Region.findRegion(regionId));
    }
    q.setParameter("active", true);

    availableList.addAll(q.getResultList());
    currentList = collectParents(new ArrayList<Node>(availableList), parent);
    availableList.addAll(currentList);

    q =
        em.createQuery(
            "SELECT o FROM Node AS o WHERE o IN :childs AND o.active = :active", Node.class);
    while (currentList.size() > 0) {

      q.setParameter("childs", currentList);
      q.setParameter("active", true);
      currentList = collectParents(q.getResultList(), parent);
      availableList.addAll(currentList);
    }

    q =
        em.createQuery(
            "SELECT o FROM Node AS o WHERE o IN :avaliable AND o.parent = :parent ORDER BY o.rate DESC, o.name ASC",
            Node.class);
    q.setParameter("parent", parent);
    q.setParameter("avaliable", availableList);

    for (Node node : q.getResultList()) {
      if (node instanceof Entity) {
        Entity entity = (Entity) node;
        Set<Resource> resList = new HashSet<Resource>();

        for (Resource res : entity.getResources()) {
          resList.add(Resource.findResource(res.getId()));
        }
        entity.setResources(resList);
      }

      resultList.add(node);
    }

    return resultList;
  }
示例#8
0
 public static List<Node> findAllNodes(String like) {
   if (like.length() == 0) {
     return findAllNodes();
   } else {
     TypedQuery<Node> q =
         entityManager()
             .createQuery(
                 "SELECT o FROM Node o WHERE lower(o.name) LIKE :like AND dtype = 'Node'",
                 Node.class);
     q.setParameter("like", "%" + like.toLowerCase() + "%");
     return q.getResultList();
   }
 }