Example #1
8
 @Override
 public List<Group> findAll() {
   TypedQuery<Group> allGroupsQuery =
       em.createNamedQuery("info.galleria.domain.Group.findAllGroups", Group.class);
   List<Group> result = allGroupsQuery.getResultList();
   return result;
 }
 @Override
 public List<SpaceObject> getSpaceObjects() {
   TypedQuery<SpaceObject> typedQuery =
       em.createQuery("SELECT m FROM SpaceObject m", SpaceObject.class);
   List<SpaceObject> result = typedQuery.getResultList();
   return result;
 }
  @Override
  public List<Withdrawal> getAll() {
    TypedQuery<Withdrawal> query =
        (TypedQuery<Withdrawal>) em.createQuery("SELECT w FROM Withdrawal w");

    return query.getResultList();
  }
 @Override
 public List<Payment> findAll() {
   TypedQuery<Payment> query = em.createQuery("SELECT p FROM Payment p", Payment.class);
   log.debug("The query selecting all payments has been created.");
   List<Payment> listP = query.getResultList();
   return listP;
 }
Example #5
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;
  }
Example #6
0
  public static List<Node> findRootNodes(long regionId) {
    EntityManager em = Node.entityManager();
    TypedQuery<Node> q =
        em.createQuery(
            "SELECT o FROM Node AS o WHERE o.parent IS NULL AND dtype = 'Node'", Node.class);
    Node root = q.getSingleResult();

    return findNodesByParent(root, regionId);
  }
  @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();
  }
Example #8
0
 public List<UserEntity> getUserByLogin(String login) {
   TypedQuery<UserEntity> query =
       em.createNamedQuery("UserEntity.findByLogin", UserEntity.class)
           .setParameter("login", login);
   if (query.getResultList().size() != 1) {
     System.out.print(login + " not found");
     return null;
   }
   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;
 }
Example #10
0
  public UserEntity getUserByLoginAndPassword(String login, String password) {
    TypedQuery<UserEntity> query =
        em.createNamedQuery("UserEntity.findByLoginAndPassword", UserEntity.class)
            .setParameter("login", login)
            .setParameter("password", password);

    List<UserEntity> result = query.getResultList();

    if (result.size() != 1) return null;
    return result.get(0);
  }
 public User findUser(long id) {
   TypedQuery<User> query =
       entityManager.createQuery("SELECT u FROM User u WHERE u.id = " + id + "", User.class);
   try {
     User u = query.getSingleResult();
     u.setPermissions("root"); // TODO: dit moet natuurlijk anders! (moet uit de DB komen)
     return u;
   } catch (NoResultException e) {
   }
   return null;
 }
 @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();
 }
Example #13
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();
 }
Example #14
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();
   }
 }
  /**
   * Método que sirve para encontrarTodos registros a la base de datos
   *
   * @return Tipo de retorno List<EspacioFísico>
   */
  public List<EspacioFísico> encontrarTodos() {
    List<EspacioFísico> lista = null;
    try {
      TypedQuery<EspacioFísico> typedQuery =
          entityManager.createQuery("SELECT t FROM espaciofísico t ", EspacioFísico.class);
      lista = typedQuery.getResultList();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {

    }
    return lista;
  }
Example #16
0
 public synchronized <T> List<T> loadAll(Class<T> entityClass, String orderBy) {
   final EntityManager em = getEntityManager();
   try {
     final TypedQuery<T> query =
         em.createQuery(
             "SELECT c FROM "
                 + entityClass.getName()
                 + "  c "
                 + ((orderBy == null) ? "" : " ORDER BY " + orderBy),
             entityClass);
     return query.getResultList();
   } finally {
     em.close();
   }
 }
 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 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;
    }
  }
Example #19
0
 public static void initialiseSubscriptions(
     EntityManagerFactory entityManagerFactory, Long immediateFrequency) {
   EntityManager badSubsEm = entityManagerFactory.createEntityManager();
   TypedQuery<Subscription> badSubsQuery =
       badSubsEm.createNamedQuery("subscription.unInitialised", Subscription.class);
   List<Subscription> uninitialisedSubscriptions = badSubsQuery.getResultList();
   badSubsEm.close();
   if (uninitialisedSubscriptions.size() > 0) {
     logger.debug("Initialising {} subscriptions", uninitialisedSubscriptions.size());
     for (Subscription s : uninitialisedSubscriptions) {
       logger.debug(
           "Scheduling new run for {} subscription {}", s.getSubscriber().emailAddress, s.getId());
       EntityManager schedEm = entityManagerFactory.createEntityManager();
       schedEm.getTransaction().begin();
       s.calculateNextScheduledRun(immediateFrequency);
       schedEm.merge(s);
       schedEm.getTransaction().commit();
       schedEm.close();
     }
   }
 }
 @Transactional(readOnly = true)
 public List<Course> findAll() {
   TypedQuery<Course> query =
       entityManager.createQuery("select course from Course course", Course.class);
   return query.getResultList();
 }
Example #21
0
 public List<UserEntity> getAll() {
   TypedQuery<UserEntity> namedQuery =
       (TypedQuery<UserEntity>) em.createNamedQuery("UserEntity.getAll");
   return namedQuery.getResultList();
 }