public static void saveMatchComplete(Match match) {
    Session session = HibernateUtils.getSessionFactory().openSession();
    session.beginTransaction();
    session.saveOrUpdate(match);
    for (Team team : match.getTeams()) {
      team.setMatch(match);
      session.saveOrUpdate(team);

      for (Matchbannedchampion banned : team.getBans()) {
        banned.setTeam(team);
        session.saveOrUpdate(banned);
      }
    }
    for (Matchparticipant participant : match.getParticipants()) {
      participant.setMatch(match);
      session.saveOrUpdate(participant);

      Participantstats stats = participant.getStats().iterator().next();
      stats.setMatchparticipant(participant);
      session.saveOrUpdate(stats);
    }

    for (Participantidentity identity : match.getParticipantIdentities()) {
      identity.setMatch(match);
      Player player = identity.getPlayer();
      player.setParticipantidentity(identity);
      session.saveOrUpdate(player);
    }
    session.getTransaction().commit();
    session.close();
  }
 @SuppressWarnings("unchecked")
 public static List<Match> getAllMatches() {
   Session session = HibernateUtils.getSessionFactory().openSession();
   List<Match> summList = session.createCriteria(Match.class).list();
   session.close();
   return summList;
 }
 public static List<Match> getAllMatchesForSummoner(long id) {
   Session session = HibernateUtils.getSessionFactory().openSession();
   SQLQuery query =
       session.createSQLQuery(
           " SELECT * FROM `match` m, participantstats ps,  participantidentity pi, player p, matchparticipant mp WHERE m.matchId = mp.matchId "
               + "  AND m.matchId = pi.matchId AND pi.dbId = p.dbId AND mp.dbId = ps.dbId AND p.summonerId = :id AND mp.participantId = pi.participantId");
   query.setParameter("id", id);
   query.addEntity(Match.class);
   session.close();
   return query.list();
 }
 @SuppressWarnings("unchecked")
 public static List<Match> getAllMatchesFiltered(long id, String season) {
   Session session = HibernateUtils.getSessionFactory().openSession();
   Query query =
       session.createQuery(
           " SELECT distinct m FROM Match as m left join m.participants mp left join m.participantIdentities pi left join pi.player p left join mp.stats ps  WHERE "
               + " m.season = :season and p.summonerId = :id AND m.matchId = mp.match.matchId and m.matchId = pi.match.matchId and pi.dbId = p.participantidentity.dbId and mp.dbId = ps.matchparticipant.dbId");
   query.setParameter("season", season);
   query.setParameter("id", id);
   List<Match> matchList = query.list();
   session.close();
   return matchList;
 }
 public static Match findById(long id) {
   Session session = HibernateUtils.getSessionFactory().openSession();
   log.debug("getting Match instance with id: " + id);
   try {
     Match instance = (Match) session.get("Match", id);
     session.close();
     return instance;
   } catch (RuntimeException re) {
     session.close();
     log.error("get failed", re);
     throw re;
   }
 }
 public static void delete(Match persistentInstance) {
   log.debug("deleting Match instance");
   Session session = HibernateUtils.getSessionFactory().openSession();
   try {
     session.delete(persistentInstance);
     log.debug("delete successful");
     session.close();
   } catch (RuntimeException re) {
     session.close();
     log.error("delete failed", re);
     throw re;
   }
 }
示例#7
-3
 public static String getLastSeasonRank(long id, String season) {
   Session session = HibernateUtils.getSessionFactory().openSession();
   SQLQuery query =
       session.createSQLQuery(
           " SELECT mp.highestAchievedSeasonTier as tier FROM `match` m,  participantidentity pi,  player p, "
               + " matchparticipant mp WHERE m.season = :season AND m.matchId = mp.matchId AND m.matchId = pi.matchId AND "
               + " pi.dbId = p.dbId AND mp.participantId = pi.participantId AND p.summonerId = :id LIMIT 1");
   query.setParameter("season", season);
   query.setParameter("id", id);
   query.addScalar("tier", StringType.INSTANCE);
   String rank = (String) query.uniqueResult();
   session.close();
   return rank;
 }