Package net.sf.hibernate

Examples of net.sf.hibernate.Session


        return s;
    }

    public static void closeSession() throws HibernateException, JDBCException
    {
        Session s = (Session) session.get();
        session.set(null);

        if (s != null)
        {
            if (s.isOpen())
            {
                s.flush();
                s.close();

                if (log.isDebugEnabled())
                {
                    log.debug("Closed hibernate session.");
                }
View Full Code Here


        info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, "true");
        ProxoolFacade.registerConnectionPool(url, info);

        Configuration configuration = null;
        SessionFactory sessionFactory = null;
        Session session = null;
        Properties hibernateProperties = new Properties();
        Connection connection = null;

        try {
            hibernateProperties.setProperty(Environment.DRIVER, ProxoolDriver.class.getName());
            hibernateProperties.setProperty(Environment.URL, url);

            configuration = new Configuration().addProperties(hibernateProperties);

            // create a session object to the database
            sessionFactory = configuration.buildSessionFactory();
            session = sessionFactory.openSession();
            assertNotNull("Expected a session", session);

            // Inspect the assigned connection to the session from
            // the pool.
            connection = session.connection();

            // assert that the connection is not null
            assertNotNull("Expected a connection", connection);

        } finally {
            try {
                connection.close();
            } catch (Exception e) {
                LOG.error("Problem closing Hibernate session", e);
            }
            // close the session which will also close it's assigned connection
            try {
                session.close();
            } catch (Exception e) {
                LOG.error("Problem closing Hibernate session", e);
            }
        }
View Full Code Here

        info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
        ProxoolFacade.registerConnectionPool(url, info);

        Configuration configuration = null;
        SessionFactory sessionFactory = null;
        Session session = null;
        Properties hibernateProperties = new Properties();
        Connection connection = null;

        try {
            hibernateProperties.setProperty(Environment.PROXOOL_EXISTING_POOL, "true");
            hibernateProperties.setProperty(Environment.PROXOOL_POOL_ALIAS, alias);

            configuration = new Configuration().addProperties(hibernateProperties);

            // create a session object to the database
            sessionFactory = configuration.buildSessionFactory();
            session = sessionFactory.openSession();
            assertNotNull("Expected a session", session);

            // Inspect the assigned connection to the session from
            // the pool.
            connection = session.connection();

            // assert that the connection is not null
            assertNotNull("Expected a connection", connection);

        } finally {
            try {
                connection.close();
            } catch (Exception e) {
                LOG.error("Problem closing Hibernate session", e);
            }
            // close the session which will also close it's assigned connection
            try {
                session.close();
            } catch (Exception e) {
                LOG.error("Problem closing Hibernate session", e);
            }
        }
View Full Code Here

        String testName = "hibernateConfiguredConnection";
        String alias = testName;

        Configuration configuration = null;
        SessionFactory sessionFactory = null;
        Session session = null;
        Properties hibernateProperties = new Properties();
        Connection connection = null;

        try {
            hibernateProperties.setProperty(Environment.PROXOOL_XML, "src/java-test/org/logicalcobwebs/proxool/hibernate.xml");
            hibernateProperties.setProperty(Environment.PROXOOL_POOL_ALIAS, alias);

            configuration = new Configuration().addProperties(hibernateProperties);

            // create a session object to the database
            sessionFactory = configuration.buildSessionFactory();
            session = sessionFactory.openSession();
            assertNotNull("Expected a session", session);

            // Inspect the assigned connection to the session from
            // the pool.
            connection = session.connection();
            assertNotNull("Expected a connection", connection);

        } finally {
            try {
                connection.close();
            } catch (Exception e) {
                LOG.error("Problem closing Hibernate session", e);
            }
            // close the session which will also close it's assigned connection
            try {
                session.close();
            } catch (Exception e) {
                LOG.error("Problem closing Hibernate session", e);
            }
        }
View Full Code Here

  {
    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);
        }
View Full Code Here

   */
  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);
      }
View Full Code Here

   */
  public List<WorkflowVO> getCurrentWorkflowVOList(InfoGluePrincipal userPrincipal, Integer maxNumberOfWorkflows) throws SystemException
  {
    List<WorkflowVO> list = 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);
      list = wf.getActiveWorkflows(maxNumberOfWorkflows);
     
      session.flush();

      tx.commit();
    }
    catch (Exception e)
    {
      logger.error("An error occurred when we tries to execute getCurrentWorkflowVOList():" + 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);
      }
View Full Code Here

   */
  public List getMyCurrentWorkflowVOList(InfoGluePrincipal userPrincipal, Integer maxNumberOfWorkflows) 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, maxNumberOfWorkflows);
     
      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);
      }
View Full Code Here

   */
  public WorkflowVO invokeAction(InfoGluePrincipal principal, long workflowId, int actionId, Map inputs) throws WorkflowException
  {
    WorkflowVO workflowVO = null;

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

    try
    {
      session = hibernateSessionFactory.openSession();

      tx = session.beginTransaction();

      WorkflowFacade wf = new WorkflowFacade(principal, workflowId, hibernateSessionFactory, session);
      wf.doAction(actionId, inputs);

      session.flush();

      tx.commit();
    }
    catch (Exception e)
    {
      logger.error("An error occurred when we tries to execute invokeAction():" + 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);
      }
    }
     
    try
    {
      session = hibernateSessionFactory.openSession();

      tx = session.beginTransaction();

      WorkflowFacade wf = new WorkflowFacade(principal, workflowId, hibernateSessionFactory, session);

      workflowVO = wf.createWorkflowVO();
     
      session.flush();

      tx.commit();
    }
    catch (Exception e)
    {
      logger.error("An error occurred when we tries to execute invokeAction():" + 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);
      }
View Full Code Here

 
  public PropertySet getPropertySet(InfoGluePrincipal userPrincipal, long workflowId)
  {
    PropertySet propertySet = null;
   
    Session session = null;
    net.sf.hibernate.Transaction tx = null;

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

      WorkflowFacade wf = new WorkflowFacade(userPrincipal, workflowId, hibernateSessionFactory, session);
      propertySet = wf.getPropertySet();
   
      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);
      }
View Full Code Here

TOP

Related Classes of net.sf.hibernate.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.