コード例 #1
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public EventNumberOfPassesRequest getEventPassesRequest(User user, Event event) {
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      List result =
          session
              .createQuery(
                  "from EventNumberOfPassesRequest as eventNumberOfPassesRequest "
                      + "where eventNumberOfPassesRequest.idevent="
                      + event.getIdevent()
                      + " and eventNumberOfPassesRequest.iduser="
                      + user.getIduser())
              .list();
      transaction.commit();

      if (result != null && result.size() > 0) {
        return (EventNumberOfPassesRequest) result.get(0);
      }
    } finally {
      if (session.isOpen()) {
        session.disconnect();
        session.close();
      }
    }
    return null;
  }
コード例 #2
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public List<Team> getTeams() {
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    List result = null;
    try {
      Transaction transaction = session.beginTransaction();
      result = session.createQuery("from Team").list();
      session.flush();
      transaction.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
    } finally {
      if (session.isOpen()) {
        session.close();
      }
    }

    List<Team> teams = new ArrayList<Team>();
    for (Object o : result) {
      if (o instanceof Team) {
        teams.add((Team) o);
      }
    }

    return teams;
  }
コード例 #3
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public List<Activity> getActivities(Event parent) {
   List<Activity> result = new ArrayList<Activity>();
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     Object event =
         session
             .createQuery("from Event as event where event.idevent= " + parent.getIdevent())
             .uniqueResult();
     transaction.commit();
     if (event != null) {
       Event eventEntity = (Event) event;
       Collection<Activity> activityList = eventEntity.getActivities();
       for (Activity activity : activityList) {
         result.add(activity);
       }
     }
   } finally {
     if (session.isOpen()) {
       session.flush();
       session.disconnect();
       session.close();
     }
   }
   return result;
 }
コード例 #4
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public void savePartnerRequest(ActivityPartnerRequest activityPartnerRequest) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     List result =
         session
             .createQuery(
                 "from ActivityPartnerRequest as partnerrequest "
                     + "where partnerrequest.idactivity="
                     + activityPartnerRequest.getIdactivity()
                     + " and partnerrequest.iduser="
                     + activityPartnerRequest.getIduser())
             .list();
     transaction.commit();
     if (result != null && result.size() > 0) {
       Session session1 = SessionFactoryUtil.getInstance().getCurrentSession();
       Transaction transaction1 = session1.beginTransaction();
       for (Object o : result) {
         session1.delete(o);
       }
       transaction1.commit();
     }
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
   saveObject(activityPartnerRequest);
 }
コード例 #5
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public Location getLocation(int id) {
    Location result = null;
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      Object o =
          session
              .createQuery("from Location as location where location.idlocation = " + id)
              .uniqueResult();

      transaction.commit();
      if (o != null) {
        if (o instanceof Location) {
          Location location = (Location) o;
          result = new Location();
          result.setName(location.getName());
          result.setIdlocation(location.getIdlocation());
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
コード例 #6
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public User getUser(String username) {
    User result = null;
    Session session;
    Object user;
    session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = null;
      user = null;
      try {
        transaction = session.beginTransaction();
        Query query =
            session.createQuery("from User as user where user.userName='******'");
        user = query.uniqueResult();
        transaction.commit();
      } catch (HibernateException e) {
        transaction.rollback();
        e.printStackTrace();
      }

      if (user != null) {
        result = (User) user;
      }
    } finally {
      if (session.isOpen()) {
        if (session.isOpen()) {
          session.disconnect();
          session.close();
        }
      }
    }
    return result;
  }
コード例 #7
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public ClassificationValue getClassification(String value) {
    ClassificationValue result = null;
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();

      Object o =
          session
              .createQuery(
                  "from ClassificationValue as classificationValue where classificationValue.value like '"
                      + value
                      + "'")
              .uniqueResult();

      transaction.commit();
      if (o != null) {
        if (o instanceof ClassificationValue) {
          result = (ClassificationValue) o;
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
コード例 #8
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public boolean createUser(User user) {
    boolean result = false;
    if (user.getEmployeeId() != null) {
      User userById = getUserByEmployeeId(user.getEmployeeId());
      if (userById != null) {
        MessageUtils.createMessage("Brugeren eksisterer allerede.");
        return false;
      }
    }
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    try {
      session.saveOrUpdate(user);
      result = true;
      session.flush();
      transaction.commit();
    } catch (StaleObjectStateException sose) {
      System.out.println("StaleObjectException");
      transaction.rollback();
    } catch (HibernateException e) {
      e.printStackTrace();
      transaction.rollback();
      result = false;
    } finally {
      if (session.isOpen()) {
        session.close();
      }
    }

    return result;
  }
コード例 #9
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public ActivityPartnerRequest getPartnerRequest(User user, Activity activity) {
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      List result =
          session
              .createQuery(
                  "from ActivityPartnerRequest as partnerrequest "
                      + "where partnerrequest.idactivity="
                      + activity.getIdactivity()
                      + " and partnerrequest.iduser="
                      + user.getIduser())
              .list();
      transaction.commit();

      if (result != null && result.size() > 0) {
        return (ActivityPartnerRequest) result.get(0);
      }
    } finally {
      if (session.isOpen()) {
        session.disconnect();
        session.close();
      }
    }
    return null;
  }
コード例 #10
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public Location getLocation(String s) {
    Location result = null;
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      Object o =
          session
              .createQuery("from Location as location where location.name like '" + s + "'")
              .uniqueResult();

      transaction.commit();
      if (o != null) {
        if (o instanceof Location) {
          result = (Location) o;
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
コード例 #11
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public void saveEventPassesRequest(EventNumberOfPassesRequest eventNumberOfPassesRequest) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     List result =
         session
             .createQuery(
                 "from EventNumberOfPassesRequest as eventNumberOfPassesRequest "
                     + "where eventNumberOfPassesRequest.idevent="
                     + eventNumberOfPassesRequest.getIdevent()
                     + " and eventNumberOfPassesRequest.iduser="
                     + eventNumberOfPassesRequest.getIduser())
             .list();
     transaction.commit();
     if (result != null && result.size() > 0) {
       Session session1 = SessionFactoryUtil.getInstance().getCurrentSession();
       Transaction transaction1 = session1.beginTransaction();
       for (Object o : result) {
         session1.delete(o);
       }
       transaction1.commit();
     }
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
   saveObject(eventNumberOfPassesRequest);
 }
コード例 #12
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public User getUser(int iduser) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   Transaction transaction = session.beginTransaction();
   User user =
       (User)
           session.createQuery("from User as user where user.iduser = " + iduser).uniqueResult();
   transaction.commit();
   return user;
 }
コード例 #13
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public Team getTeam(String name) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   Transaction transaction = session.beginTransaction();
   Team team =
       (Team)
           session.createQuery("from Team as team where team.name= '" + name + "'").uniqueResult();
   transaction.commit();
   return team;
 }
コード例 #14
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public Team getTeam(Team teamSelection) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   Transaction transaction = session.beginTransaction();
   Team team =
       (Team)
           session
               .createQuery("from Team as team where team.id = " + teamSelection.getId())
               .uniqueResult();
   transaction.commit();
   return team;
 }
コード例 #15
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public User getUserByEmail(String email) {
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    List list = session.createQuery("from User as user where user.mail = '" + email + "'").list();

    transaction.commit();
    if (list != null && list.size() == 1) {
      return (User) list.get(0);
    }

    return null;
  }
コード例 #16
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public void deleteObject(Object o) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     session.delete(o);
     session.flush();
     transaction.commit();
   } finally {
     if (session.isOpen()) {
       session.close();
     }
   }
 }
コード例 #17
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  private User getUserByEmployeeId(String employeeId) {

    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    String queryString = "from User user where user.employeeId ='" + employeeId + "'";

    List list = session.createQuery(queryString).list();
    transaction.commit();
    if (list != null && list.size() == 1) {
      return (User) list.get(0);
    }
    return null;
  }
コード例 #18
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public TeamUserSelection getTeamUserSelection(User user) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   Transaction transaction = session.beginTransaction();
   TeamUserSelection teamUserSelection =
       (TeamUserSelection)
           session
               .createQuery(
                   "from TeamUserSelection as teamUserSelection where teamUserSelection.iduser="
                       + user.getIduser())
               .uniqueResult();
   transaction.commit();
   return teamUserSelection;
 }
コード例 #19
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public void updateObject(Object entity) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     session.update(entity);
     session.flush();
     transaction.commit();
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
 }
コード例 #20
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public void deletePartnerRequest(ActivityPartnerRequest activityPartnerRequest) {
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      session.delete(activityPartnerRequest);
      session.flush();
      transaction.commit();

    } finally {
      if (session.isOpen()) {
        session.disconnect();
        session.close();
      }
    }
  }
コード例 #21
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public List<ActivityPartnerRequest> getAllActivityPartnerRequestForUser(User user) {
   List<ActivityPartnerRequest> result = new ArrayList<ActivityPartnerRequest>();
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   Transaction transaction = session.beginTransaction();
   List list =
       session
           .createQuery("from ActivityPartnerRequest apr where apr.iduser=" + user.getIduser())
           .list();
   transaction.commit();
   if (list != null && list.size() > 0) {
     for (Object o : list) {
       result.add((ActivityPartnerRequest) o);
     }
   }
   return result;
 }
コード例 #22
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public User getUserByName(String firstName, String lastName) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   Transaction transaction = session.beginTransaction();
   String queryString =
       "from User user where user.firstname ='"
           + firstName
           + "' and user.lastname ='"
           + lastName
           + "'";
   //        System.out.println("queryString = " + queryString);
   List list = session.createQuery(queryString).list();
   transaction.commit();
   if (list != null && list.size() == 1) {
     return (User) list.get(0);
   }
   return null;
 }
コード例 #23
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public void saveObject(Object entity) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   Transaction transaction = null;
   try {
     transaction = session.beginTransaction();
     session.saveOrUpdate(entity);
     transaction.commit();
   } catch (HibernateException e) {
     transaction.rollback();
     e.printStackTrace();
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
 }
コード例 #24
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public List<Event> getEvent(String name) {
   List<Event> result = new ArrayList<Event>();
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     List list = session.createQuery("from Event as event where event.name='" + name + "'").list();
     transaction.commit();
     for (Object o : list) {
       result.add((Event) o);
     }
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
   return result;
 }
コード例 #25
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public List<User> getUsers() {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   List<User> result = new ArrayList<User>();
   try {
     Transaction transaction = session.beginTransaction();
     List list = session.createQuery("from User").list();
     transaction.commit();
     for (Object o : list) {
       User user = (User) o;
       result.add(user);
     }
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
   return result;
 }
コード例 #26
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public List<Logo> getLogos() {
    List<Logo> result = new ArrayList<Logo>();
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();

      List list = session.createQuery("from Logo").list();
      transaction.commit();
      for (Object o : list) {
        Logo logo = (Logo) o;
        result.add(logo);
      }
    } finally {
      if (session.isOpen()) {
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
コード例 #27
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public List<User> getUsersForTeam(Team team) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   Transaction transaction = session.beginTransaction();
   List list =
       session
           .createQuery(
               "from TeamUserSelection as teamUserSelection where teamUserSelection.idteam= "
                   + team.getId())
           .list();
   transaction.commit();
   if (list != null) {
     List<User> result = new ArrayList<User>();
     for (Object o : list) {
       User user = getUser(((TeamUserSelection) o).getIduser());
       result.add(user);
     }
     return result;
   }
   return null;
 }
コード例 #28
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public List<Activity> getActivities() {
    List<Activity> result = new ArrayList<Activity>();
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      List list = session.createQuery("from Activity").list();
      transaction.commit();

      for (Object o : list) {
        Activity activity = (Activity) o;
        result.add(activity);
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
コード例 #29
0
ファイル: DataManager.java プロジェクト: mhylle/schema
 public Event getEvent(Event event) {
   Event result = null;
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     Object o =
         session
             .createQuery("from Event as event where event.idevent= " + event.getIdevent())
             .uniqueResult();
     transaction.commit();
     if (o != null) {
       result = (Event) o;
     }
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
   return result;
 }
コード例 #30
0
ファイル: DataManager.java プロジェクト: mhylle/schema
  public void saveEvent(Event event) {
    Event event1 = getEvent(event);

    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      if (event1 == null) {
        Transaction transaction = session.beginTransaction();
        try {
          session.save(event);
          transaction.commit();
        } catch (HibernateException e) {
          transaction.rollback();
          e.printStackTrace();
        }
      } else {
        Transaction transaction = session.beginTransaction();
        try {
          session.update(event);
          transaction.commit();
        } catch (HibernateException e) {
          transaction.rollback();
          e.printStackTrace();
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
  }