Ejemplo n.º 1
0
 /* (non-Javadoc)
  * @see cz.plsi.webInfo.shared.dataStore.entities.EntityCommon#exists()
  */
 @Override
 public boolean exists() {
   EntityManager em = EMF.getInstance().createEntityManager();
   Query query =
       em.createQuery(
           "SELECT ts FROM "
               + TeamStage.class.getName()
               + " ts "
               + "where ts.teamName=:teamName "
               + "and ts.stageName=:stageName");
   query.setParameter("teamName", this.getTeamName());
   query.setParameter("stageName", this.getStageName());
   query.setMaxResults(1);
   return !query.getResultList().isEmpty();
 }
Ejemplo n.º 2
0
  public static TeamStage getTeamStage(Key id) {
    EntityManager em = EMF.getInstance().createEntityManager();
    TypedQuery<TeamStage> query =
        em.createQuery(
            "SELECT ts FROM " + TeamStage.class.getName() + " ts " + "where ts.id=:id",
            TeamStage.class);
    query.setParameter("id", id);
    query.setMaxResults(1);
    List<TeamStage> resultList = query.getResultList();
    if (resultList.isEmpty()) {
      return null;
    }

    return resultList.get(0);
  }
Ejemplo n.º 3
0
  @Override
  public List<TeamStage> getList() {
    EntityManager em = EMF.getInstance().createEntityManager();
    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    CriteriaQuery<TeamStage> cq = criteriaBuilder.createQuery(TeamStage.class);
    Root<TeamStage> teamStage = cq.from(TeamStage.class);

    Predicate criteria = null;
    if (this.teamName != null) {
      criteria = criteriaBuilder.equal(teamStage.get("teamName"), this.teamName);
    }

    if (this.stageName != null) {
      criteria =
          criteriaBuilder.and(
              criteria, criteriaBuilder.equal(teamStage.get("stageName"), this.stageName));
    }

    if (this.stageBranch != null) {
      criteria =
          criteriaBuilder.and(
              criteria, criteriaBuilder.equal(teamStage.get("stageBranch"), this.stageBranch));
    }

    if (this.stageOrder == TEAM_ENDED_GAME) {
      Predicate equalEnded = criteriaBuilder.equal(teamStage.get("stageOrder"), this.stageOrder);
      criteria = criteria != null ? criteriaBuilder.and(criteria, equalEnded) : equalEnded;
    } else {
      Predicate notEqualOrder =
          criteriaBuilder.notEqual(teamStage.get("stageOrder"), TEAM_ENDED_GAME);
      criteria = criteria != null ? criteriaBuilder.and(criteria, notEqualOrder) : notEqualOrder;
    }

    if (criteria != null) {
      cq.where(criteria);
    }

    cq.select(teamStage);
    cq.orderBy(
        criteriaBuilder.desc(teamStage.get("stageOrder")),
        criteriaBuilder.asc(teamStage.get("stageDate")));

    em.getTransaction().begin();
    List<TeamStage> resultList = em.createQuery(cq).getResultList();
    em.getTransaction().commit();
    return resultList;
  }
Ejemplo n.º 4
0
  /* (non-Javadoc)
   * @see cz.plsi.webInfo.shared.dataStore.entities.EntityCommon#count()
   */
  @Override
  public long count() {
    EntityManager em = EMF.getInstance().createEntityManager();
    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("SELECT COUNT(ts) FROM ");
    queryBuilder.append(TeamStage.class.getName());
    queryBuilder.append(" ts");
    if (this.teamName != null) {
      queryBuilder.append(" where ts.teamName=:teamName");
    }
    TypedQuery<Long> query = em.createQuery(queryBuilder.toString(), Long.class);
    if (this.teamName != null) {
      query.setParameter("teamName", this.teamName);
    }

    return query.getSingleResult();
  }
Ejemplo n.º 5
0
  // TODO refaktor z team name na team code
  public static TeamStage getLastTeamStage(String team) {
    EntityManager em = EMF.getInstance().createEntityManager();
    TypedQuery<TeamStage> query =
        em.createQuery(
            "SELECT ts FROM "
                + TeamStage.class.getName()
                + " ts "
                + "where ts.teamName=:teamName "
                + "ORDER BY ts.stageDate DESC",
            TeamStage.class);
    query.setParameter("teamName", team);
    query.setMaxResults(1);
    List<TeamStage> resultList = query.getResultList();
    if (resultList.isEmpty()) {
      return null;
    }

    return resultList.get(0);
  }