/** {@inheritDoc} */
  @Override
  public void txEnd(GridCacheTx tx, boolean commit) throws GridException {
    init();

    Session ses = tx.removeMeta(ATTR_SES);

    if (ses != null) {
      Transaction hTx = ses.getTransaction();

      if (hTx != null) {
        try {
          if (commit) {
            ses.flush();

            hTx.commit();
          } else hTx.rollback();

          if (log.isDebugEnabled())
            log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']');
        } catch (HibernateException e) {
          throw new GridException(
              "Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e);
        } finally {
          ses.close();
        }
      }
    }
  }
Beispiel #2
0
  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;
  }
Beispiel #3
0
  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;
  }
Beispiel #4
0
  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();
      }
    }
  }
Beispiel #5
0
  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;
  }
Beispiel #6
0
 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;
 }
Beispiel #7
0
  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;
  }
Beispiel #8
0
  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;
  }
 public void guardaActualiza(TbAplicativo tbAplicativo) {
   try {
     iniciaOperacion();
     sesion.saveOrUpdate(tbAplicativo);
     tx.commit();
     sesion.flush();
   } catch (HibernateException he) {
     manejaExcepcion(he);
     throw he;
   } finally {
     sesion.close();
   }
 }
Beispiel #10
0
 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();
     }
   }
 }
 public void eliminar(TbAplicativo tbAplicativo) {
   try {
     iniciaOperacion();
     sesion.delete(tbAplicativo);
     tx.commit();
     sesion.flush();
   } catch (HibernateException he) {
     manejaExcepcion(he);
     throw he;
   } finally {
     sesion.close();
   }
 }
Beispiel #12
0
 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();
     }
   }
 }
Beispiel #13
0
  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();
      }
    }
  }
Beispiel #14
0
 public List<Event> getEvents() {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   List<Event> result = new ArrayList<Event>();
   try {
     Transaction transaction = session.beginTransaction();
     List list = session.createQuery("from Event").list();
     transaction.commit();
     for (Object o : list) {
       result.add((Event) o);
     }
   } finally {
     if (session.isOpen()) {
       session.flush();
       session.disconnect();
       session.close();
     }
   }
   return result;
 }
Beispiel #15
0
  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;
  }
Beispiel #16
0
  public List<Location> getLocations() {
    List<Location> result = new ArrayList<Location>();
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      List list = session.createQuery("from Location").list();
      transaction.commit();

      if (list != null) {
        for (Object o : list) {
          Location location = (Location) o;
          result.add(location);
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
Beispiel #17
0
 public Location getLocation(Location location) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     Object o =
         session
             .createQuery(
                 "from Location as location where location.idlocation = "
                     + location.getIdlocation())
             .uniqueResult();
     transaction.commit();
     if (o != null) {
       return (Location) o;
     }
   } finally {
     if (session.isOpen()) {
       session.flush();
       session.disconnect();
       session.close();
     }
   }
   return null;
 }
Beispiel #18
0
  public List<ClassificationType> getClassificationTypes() {
    List<ClassificationType> result = new ArrayList<ClassificationType>();
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      List list = session.createQuery("from ClassificationType").list();
      transaction.commit();

      if (list != null) {
        for (Object o : list) {
          ClassificationType classificationType = (ClassificationType) o;
          result.add(classificationType);
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
Beispiel #19
0
 public Activity getActivity(Activity activity) {
   Activity result = null;
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     Object o =
         session
             .createQuery(
                 "from Activity as activity where activity.idactivity= "
                     + activity.getIdactivity())
             .uniqueResult();
     transaction.commit();
     if (o != null) {
       result = (Activity) o;
     }
   } finally {
     if (session.isOpen()) {
       session.flush();
       session.disconnect();
       session.close();
     }
   }
   return result;
 }
Beispiel #20
0
  public boolean saveUser(User user) {
    boolean result = false;

    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    try {
      session.update(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;
  }