コード例 #1
0
ファイル: AdminDAO.java プロジェクト: jekay100/front-road
  public void deleteAdmin(Long id) throws DBException {
    Session session;
    Admin admin = null;
    Transaction tx = null;
    try {
      session = HibernateSessionFactory.currentSession();
      tx = session.beginTransaction();
      admin = (Admin) session.load(Admin.class, id);
      session.delete(admin);
      tx.commit();
    } catch (HibernateException e) {

      try {
        tx.rollback();

      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
      e.printStackTrace();
      throw new DBException("更新对象失败!");
    } finally {
      try {
        HibernateSessionFactory.closeSession();
      } catch (HibernateException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
 public void updatePerson(Person person) throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   session.update(person);
   transaction.commit();
   HibernateSessionFactory.closeSession();
 }
コード例 #3
0
ファイル: Example.java プロジェクト: selrahal/windup-rulesets
    public static void main(String[] args) throws HibernateException
    {

        Person person = new Person();
        person.setName("John Smith");
        person.setEmail("*****@*****.**");

        Session session = _sessions.openSession();

        Transaction tx = null;
        try
        {
            tx = session.beginTransaction();
            session.save(person);
            tx.commit();
        }
        catch (HibernateException he)
        {
            if (tx != null)
                tx.rollback();
            throw he;
        }
        finally
        {
            session.close();
        }

    }
コード例 #4
0
  public static void main(String[] args) throws HibernateException {
    Session s = HibernateUtil.currentSession();

    Transaction tx = s.beginTransaction();

    // Batiment Copernic = (Batiment) s.load(Batiment.class, new Long(1));
    Iterator itBat = s.iterate("from Batiment");
    while (itBat.hasNext()) {
      Batiment bat = (Batiment) itBat.next();
      System.out.println(bat.getNomBat());
      Iterator etageIt = bat.getEtages().iterator();
      while (etageIt.hasNext()) {
        Etage e = (Etage) etageIt.next();
        System.out.println("\t" + e.getNomEtage());

        Iterator salleIt = e.getSalles().iterator();
        while (salleIt.hasNext()) {
          Salle salle = (Salle) salleIt.next();
          System.out.println(
              "\t\t"
                  + salle.getNomSalle()
                  + "\t"
                  + salle.getTypeSalle()
                  + "\t"
                  + salle.getNbplaces());
        }
      }
    }
    tx.commit();

    HibernateUtil.closeSession();
  }
コード例 #5
0
ファイル: AdminDAO.java プロジェクト: jekay100/front-road
  public void updateAdmin(Admin admin) throws DBException {
    Session session;
    Transaction tx = null;
    try {
      session = HibernateSessionFactory.currentSession();
      tx = session.beginTransaction();
      session.update(admin);
      tx.commit();
    } catch (HibernateException e) {

      try {
        tx.rollback();

      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
      e.printStackTrace();
      throw new DBException("获取对象失败!");
    } finally {
      try {
        HibernateSessionFactory.closeSession();
      } catch (HibernateException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #6
0
 public Person loadPerson(String id) throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Person newPperson = (Person) session.load(Person.class, id);
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return newPperson;
 }
コード例 #7
0
 public void savePerson(Person person) throws HibernateException {
   person.setCreateDate(new Date());
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   session.save(person);
   transaction.commit();
   HibernateSessionFactory.closeSession();
 }
コード例 #8
0
 public TemplateData loadTemplate(String id) throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   TemplateData result = (TemplateData) session.load(TemplateData.class, id);
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return result;
 }
コード例 #9
0
 @SuppressWarnings("unchecked")
 public List<TemplateData> loadTemplateList() throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Criteria criteria = session.createCriteria(TemplateData.class);
   List<TemplateData> list = criteria.list();
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return list;
 }
コード例 #10
0
  public ActionForward query(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String room = request.getParameter("room");
    String strDate = request.getParameter("date");
    Date startDay = UtilDateTime.getThisWeekDay(strDate, 1);
    Date endDay = UtilDateTime.getDiffDay(startDay, 6);

    try {
      Session hs = Hibernate2Session.currentSession();
      Transaction tx = null;
      tx = hs.beginTransaction();
      List valueList = null;

      if (room == null || room.trim().equals("")) {
        Query query =
            hs.createQuery(
                "from BookingRoomVO as br where br.bookingDate>=? and br.bookingDate<=? order by br.bookingDate,br.room,br.startTime");
        query.setDate(0, startDay);
        query.setDate(1, endDay);
        valueList = query.list();
      } else {
        Query query =
            hs.createQuery(
                "from BookingRoomVO as br where br.room=? and br.bookingDate>=? and br.bookingDate<=? order by br.bookingDate,br.room,br.startTime");
        query.setString(0, room);
        query.setDate(1, startDay);
        query.setDate(2, endDay);
        valueList = query.list();
      }
      request.setAttribute("valueList", valueList);
      request.setAttribute("startDay", startDay);
      hs.flush();
      tx.commit();

    } catch (Exception e) {
      e.printStackTrace();
      //	log.error(e.getMessage());
    } finally {
      try {
        Hibernate2Session.closeSession();
      } catch (HibernateException e1) {
        //		log.error(e1.getMessage());
        e1.printStackTrace();
      } catch (SQLException e1) {
        //		log.error(e1.getMessage());
        e1.printStackTrace();
      }
    }
    return mapping.findForward("query-success");
  }
コード例 #11
0
 public TemplateData loadByResourceKey(String key) throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Criteria criteria = session.createCriteria(TemplateData.class);
   criteria.add(Expression.eq("resourceKey", key));
   criteria.setMaxResults(1);
   TemplateData result = (TemplateData) criteria.uniqueResult();
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return result;
 }
コード例 #12
0
 public TemplateData findTemplateByName(String name) throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Criteria criteria = session.createCriteria(TemplateData.class);
   criteria.add(Expression.eq("name", name));
   criteria.setMaxResults(1);
   TemplateData result = (TemplateData) criteria.uniqueResult();
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return result;
 }
コード例 #13
0
 public void rollback() throws RetsServerException {
   LOG.debug("rollback");
   if (mTx != null) {
     try {
       Transaction tx = mTx;
       mTx = null;
       tx.rollback();
     } catch (HibernateException e) {
       throw new RetsServerException(e);
     }
   }
 }
コード例 #14
0
 public Person findPersonByEmail(String emailAddress) throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Criteria criteria = session.createCriteria(Person.class);
   // criteria.createAlias("emailAddesses", "email");
   criteria.add(Expression.eq("emailAddress", emailAddress));
   // criteria.add(Expression.like("realname", personalName,
   // MatchMode.ANYWHERE));
   criteria.setMaxResults(1);
   Person person = (Person) criteria.uniqueResult();
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return person;
 }
コード例 #15
0
 @SuppressWarnings("unchecked")
 public List<Person> loadPersonList(boolean selectable) throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Criteria criteria = session.createCriteria(Person.class);
   criteria.add(Expression.eq("active", true));
   if (selectable) {
     criteria.add(Expression.eq("selectable", true));
   }
   List<Person> list = criteria.list();
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return list;
 }
コード例 #16
0
 public Person authenticatePerson(String username, char[] password) throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Criteria criteria = session.createCriteria(Person.class);
   criteria.add(Expression.eq("username", username));
   criteria.setMaxResults(1);
   Person person = (Person) criteria.uniqueResult();
   transaction.commit();
   HibernateSessionFactory.closeSession();
   logger.debug("Found person: " + person.getUsername());
   if (person.checkPlainPassword(new String(password))) {
     return person;
   }
   return null;
 }
コード例 #17
0
 /**
  * Updates a class in database
  *
  * @param c IClass to update
  * @throws HibernateException
  */
 public static void update(IClass c) throws HibernateException {
   Session s = null;
   Transaction tx = null;
   try {
     s = HibernateUtil.currentSession();
     tx = s.beginTransaction();
     s.update(c);
     tx.commit();
   } catch (HibernateException e) {
     e.printStackTrace();
     if (tx != null) tx.rollback();
     throw e;
   } finally {
     HibernateUtil.closeSession();
   }
 }
コード例 #18
0
 private List getLogEntries(String nhsno, Calendar startdate, Calendar enddate)
     throws HibernateException {
   List logEntries = new ArrayList();
   if (nhsno != null && !nhsno.equals("")) {
     Session session = HibernateUtil.currentSession();
     Transaction tx = session.beginTransaction();
     Criteria criteria = session.createCriteria(LogEntry.class);
     criteria.add(Expression.between("date", startdate, enddate));
     criteria.add(Expression.like("nhsno", "%" + nhsno + "%"));
     criteria.addOrder(Order.asc("id"));
     logEntries = criteria.list();
     tx.commit();
     HibernateUtil.closeSession();
   }
   return logEntries;
 }
コード例 #19
0
  /**
   * @param principal the user principal representing the desired user
   * @param name the name of the workflow to create.
   * @param actionId the ID of the initial action
   * @param inputs the inputs to the workflow
   * @return a WorkflowVO representing the newly created workflow instance
   * @throws SystemException if an error occurs while initiaizing the workflow
   */
  public WorkflowVO initializeWorkflow(
      InfoGluePrincipal principal, String name, int actionId, Map inputs) throws SystemException {
    WorkflowVO workflowVO = null;

    try {
      Session session = null;
      net.sf.hibernate.Transaction tx = null;

      try {
        session = hibernateSessionFactory.openSession();
        tx = session.beginTransaction();

        if (getIsAccessApproved(name, principal)) {
          WorkflowFacade wf =
              new WorkflowFacade(
                  principal, name, actionId, inputs, hibernateSessionFactory, session);
          workflowVO = wf.createWorkflowVO();

          session.flush();

          tx.commit();
        } else {
          throw new Bug("You are not allowed to create " + name + " workflows.");
        }
      } catch (Exception e) {
        logger.error(
            "An error occurred when we tries to run initializeWorkflow():" + e.getMessage(), e);
        try {
          tx.rollback();
        } catch (HibernateException he) {
          logger.error(
              "An error occurred when we tries to rollback transaction:" + he.getMessage(), he);
        }
        restoreSessionFactory(e);
      } finally {
        try {
          session.close();
        } catch (HibernateException e) {
          logger.error("An error occurred when we tries to close:" + e.getMessage(), e);
        }
      }
    } catch (Exception e) {
      throw new SystemException(e);
    }

    return workflowVO;
  }
コード例 #20
0
  /**
   * Returns a list of all available workflows, i.e., workflows defined in workflows.xml
   *
   * @param userPrincipal a user principal
   * @return a list WorkflowVOs representing available workflows
   */
  public List<WorkflowVO> getAvailableWorkflowVOList(InfoGluePrincipal userPrincipal)
      throws SystemException {
    final List<WorkflowVO> accessibleWorkflows = new ArrayList<WorkflowVO>();

    Session session = null;
    net.sf.hibernate.Transaction tx = null;

    try {
      session = hibernateSessionFactory.openSession();

      tx = session.beginTransaction();

      WorkflowFacade wf = new WorkflowFacade(userPrincipal, hibernateSessionFactory, session);
      final List<WorkflowVO> allWorkflows = wf.getDeclaredWorkflows();

      for (final Iterator<WorkflowVO> i = allWorkflows.iterator(); i.hasNext(); ) {
        final WorkflowVO workflowVO = i.next();
        if (getIsAccessApproved(workflowVO.getName(), userPrincipal)) {
          accessibleWorkflows.add(workflowVO);
        }
      }

      session.flush();

      tx.commit();
    } catch (Exception e) {
      logger.error(
          "An error occurred when we tries to execute getAvailableWorkflowVOList():"
              + e.getMessage(),
          e);
      try {
        tx.rollback();
      } catch (HibernateException he) {
        logger.error(
            "An error occurred when we tries to rollback transaction():" + he.getMessage(), he);
      }
      restoreSessionFactory(e);
    } finally {
      try {
        session.close();
      } catch (HibernateException e) {
        logger.error("An error occurred when we tries to close session:" + e.getMessage(), e);
      }
    }

    return accessibleWorkflows;
  }
コード例 #21
0
 @SuppressWarnings("unchecked")
 public Person loadPersonForPrincipal(Principal principal) throws HibernateException {
   // Principal principal = request.getUserPrincipal();
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Criteria criteria = session.createCriteria(Person.class);
   criteria.add(Expression.eq("username", principal.getName()));
   criteria.setMaxResults(1);
   List<Person> personList = criteria.list();
   Person person = null;
   if (personList.size() == 1) {
     person = personList.get(0);
   }
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return person;
 }
コード例 #22
0
 public List<Person> loadExcludedPersonList(List<String> excludeList, boolean selectable)
     throws HibernateException {
   Session session = HibernateSessionFactory.currentSession();
   Transaction transaction = session.beginTransaction();
   Criteria criteria = session.createCriteria(Person.class);
   criteria.add(Expression.eq("active", true));
   if (selectable) {
     criteria.add(Expression.eq("selectable", true));
   }
   if (excludeList != null && !excludeList.isEmpty()) {
     criteria.add(Expression.not(Expression.in("id", excludeList)));
   }
   List<Person> list = criteria.list();
   transaction.commit();
   HibernateSessionFactory.closeSession();
   return list;
 }
コード例 #23
0
  /**
   * Method to get all the classes
   *
   * @param parent
   * @return List of IClass
   * @throws HibernateException
   */
  public static List<IClass> get(ITrack parent) throws HibernateException {
    Session s = null;
    Transaction tx = null;
    List<IClass> l = null;
    try {
      s = HibernateUtil.currentSession();
      tx = s.beginTransaction();
      l = s.find("FROM ClassImpl as c WHERE c.parentTrack = ?", parent.getIdData(), Hibernate.LONG);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      if (tx != null) tx.rollback();
      throw e;
    } finally {
      HibernateUtil.closeSession();
    }

    return l;
  }
コード例 #24
0
  public Map getProperties(InfoGluePrincipal userPrincipal, long workflowId) {
    if (logger.isDebugEnabled()) {
      logger.info("userPrincipal:" + userPrincipal);
      logger.info("workflowId:" + workflowId);
    }

    Map parameters = new HashMap();

    Session session = null;
    net.sf.hibernate.Transaction tx = null;

    try {
      session = hibernateSessionFactory.openSession();
      tx = session.beginTransaction();

      PropertySet propertySet = getPropertySet(userPrincipal, workflowId, session);
      for (Iterator keys = propertySet.getKeys().iterator(); keys.hasNext(); ) {
        String key = (String) keys.next();
        parameters.put(key, propertySet.getString(key));
      }

      session.flush();

      tx.commit();
    } catch (Exception e) {
      logger.error("An error occurred when we tries to run getHistorySteps():" + e.getMessage(), e);
      try {
        tx.rollback();
      } catch (HibernateException he) {
        logger.error(
            "An error occurred when we tries to rollback transaction:" + he.getMessage(), he);
      }
      restoreSessionFactory(e);
    } finally {
      try {
        session.close();
      } catch (HibernateException e) {
        logger.error("An error occurred when we tries to close session:" + e.getMessage(), e);
      }
    }

    return parameters;
  }
コード例 #25
0
  /**
   * Commit the database level changes. Declared in AbstractDAO class.
   *
   * @throws DAOException
   */
  public void commit() throws DAOException {
    try {
      auditManager.insert(this);

      if (transaction != null) transaction.commit();
    } catch (HibernateException dbex) {
      Logger.out.error(dbex.getMessage(), dbex);
      throw handleError("Error in commit: ", dbex);
    }
  }
コード例 #26
0
  /**
   * Returns the workflows owned by the specified principal.
   *
   * @param userPrincipal a user principal.
   * @return a list of WorkflowVOs owned by the principal.
   * @throws SystemException if an error occurs while finding the workflows
   */
  public List getMyCurrentWorkflowVOList(InfoGluePrincipal userPrincipal) throws SystemException {
    List list = new ArrayList();

    Session session = null;
    net.sf.hibernate.Transaction tx = null;

    try {
      session = hibernateSessionFactory.openSession();

      tx = session.beginTransaction();

      WorkflowFacade wf = new WorkflowFacade(userPrincipal, hibernateSessionFactory, session);
      list = wf.getMyActiveWorkflows(userPrincipal);

      session.flush();

      tx.commit();
    } catch (Exception e) {
      logger.error(
          "An error occurred when we tries to execute getMyCurrentWorkflowVOList():"
              + e.getMessage(),
          e);
      try {
        tx.rollback();
      } catch (HibernateException he) {
        logger.error(
            "An error occurred when we tries to rollback transaction:" + he.getMessage(), he);
      }
      restoreSessionFactory(e);
    } finally {
      try {
        session.close();
      } catch (HibernateException e) {
        logger.error("An error occurred when we tries to close session:" + e.getMessage(), e);
      }
    }

    return list;

    // return new WorkflowFacade(userPrincipal, true).getMyActiveWorkflows(userPrincipal);
  }
コード例 #27
0
  public static IClass getClassFromId(Long idClass) throws HibernateException {
    IClass c = null;
    Session s = null;
    Transaction tx = null;
    try {
      s = HibernateUtil.currentSession();
      tx = s.beginTransaction();
      c = (IClass) s.load(ClassImpl.class, idClass);
      tx.commit();

      System.out.println(c);
    } catch (HibernateException e) {
      e.printStackTrace();
      if (tx != null) tx.rollback();
      throw e;
    } finally {
      HibernateUtil.closeSession();
    }

    return c;
  }
コード例 #28
0
  /**
   * Returns all current steps for a workflow, i.e., steps that could be performed in the workflow's
   * current state
   *
   * @param userPrincipal a user principal
   * @param workflowId the Id of the desired workflow
   * @return a list of WorkflowStepVOs representing the current steps of the workflow with
   *     workflowId
   */
  public List getCurrentSteps(InfoGluePrincipal userPrincipal, long workflowId) {
    List currentSteps = new ArrayList();

    Session session = null;
    net.sf.hibernate.Transaction tx = null;

    try {
      session = hibernateSessionFactory.openSession();
      tx = session.beginTransaction();

      WorkflowFacade wf =
          new WorkflowFacade(userPrincipal, workflowId, hibernateSessionFactory, session);
      currentSteps = wf.getCurrentSteps();

      session.flush();

      tx.commit();
    } catch (Exception e) {
      logger.error("An error occurred when we tries to run getCurrentSteps():" + e.getMessage(), e);
      try {
        tx.rollback();
      } catch (HibernateException he) {
        logger.error(
            "An error occurred when we tries to rollback transaction:" + he.getMessage(), he);
      }
      restoreSessionFactory(e);
    } finally {
      try {
        session.close();
      } catch (HibernateException e) {
        logger.error("An error occurred when we tries to close session:" + e.getMessage(), e);
      }
    }

    // WorkflowFacade wf = new WorkflowFacade(userPrincipal, workflowId, true);
    // List currentSteps = wf.getCurrentSteps();

    return currentSteps;
  }
コード例 #29
0
  private void parseMetadata() throws Exception {
    Session hSession = null;
    Transaction tx = null;

    try {
      hSession = mSessions.openSession();
      tx = hSession.beginTransaction();

      MSystem hSystem = doSystem(hSession);
      doResource(hSession, hSystem);
      doClasses(hSession);
      doObjects(hSession);
      doSearchHelp(hSession);
      doEditMask(hSession);
      doLookup(hSession);
      doLookupTypes(hSession);
      doUpdateHelp(hSession);
      doValidationExternal(hSession);
      doUpdate(hSession);
      doTable(hSession);
      doValidationLookup(hSession);
      doValidationLookupType(hSession);
      doValidationExternalType(hSession);
      doValidationExpression(hSession);
      doUpdateType(hSession);
      doForeignKey(hSession, hSystem);

      tx.commit();
      hSession.close();
    } catch (Exception e) {
      e.printStackTrace();
      try {
        tx.rollback();
        hSession.close();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    }
  }
コード例 #30
0
  /**
   * Returns true if the workflow has terminated; false otherwise.
   *
   * @param workflowVO the workflow.
   * @return true if the workflow has terminated; false otherwise.
   */
  public boolean hasTerminated(InfoGluePrincipal userPrincipal, long workflowId)
      throws WorkflowException {
    boolean isFinished = false;

    Session session = null;
    net.sf.hibernate.Transaction tx = null;

    try {
      session = hibernateSessionFactory.openSession();
      tx = session.beginTransaction();

      WorkflowFacade wf =
          new WorkflowFacade(userPrincipal, workflowId, hibernateSessionFactory, session);
      isFinished = wf.isFinished();

      session.flush();

      tx.commit();
    } catch (Exception e) {
      logger.error("An error occurred when we tries to run hasTerminated:" + e.getMessage(), e);
      try {
        tx.rollback();
      } catch (HibernateException he) {
        logger.error(
            "An error occurred when we tries to rollback transaction:" + he.getMessage(), he);
      }
      restoreSessionFactory(e);
    } finally {
      try {
        session.close();
      } catch (HibernateException e) {
        logger.error("An error occurred when we tries to close session:" + e.getMessage(), e);
      }
    }

    return isFinished;
    // return new WorkflowFacade(userPrincipal, workflowId, true).isFinished();
  }