Package net.sf.hibernate

Examples of net.sf.hibernate.Session


        scheduledDeletes.add(object);
    }

    protected void tearDown() throws Exception {
        super.tearDown();
        Session session = tester.getSession();
        for (Iterator iterator = scheduledDeletes.iterator(); iterator.hasNext();) {
            Object object = iterator.next();
// Don't use session.delete(o); since the object might have been deleted in the first place.
            session.delete("from object in class " + object.getClass().getName() + " where object.id = ?",
                    new Integer(((DomainObject) object).getId()), Hibernate.INTEGER);
        }
        tester.releaseSession();
    }
View Full Code Here


    protected String generateUniqueName(String baseName) {
        return "@test." + baseName + "." + System.currentTimeMillis() + "@";
    }

    protected void setUpRole(Person person, Project project, String roleName) throws HibernateException {
        Session session = tester.getSession();
        List roles = session.find("from role in class " + Role.class.getName() +
                " where role.name = ?", roleName, Hibernate.STRING);
        Role role = null;
        if (roles.size() > 0) {
            role = (Role) roles.get(0);
        } else {
View Full Code Here

    public void deleteObjects(Class clazz, String attribute, String value) {
        deleteObjects(clazz, attribute, value, Hibernate.STRING);
    }

    private void deleteObjects(Class clazz, String attribute, String value, Type type) {
        Session session = null;
        try {
            session = getSession();
            session.connection().commit(); // start new txn for following query
            session.delete("from object in "+clazz+" where object."+attribute+" = ?", value, type);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

            ActionForm actionForm,
            HttpServletRequest request,
            HttpServletResponse reply) throws Exception {
        AggregateTimesheetForm form = (AggregateTimesheetForm)actionForm;
        try {
            Session session = getSession(request);
            try {

                form.setAllPeople(session.find("from people in class org.nxplanner.domain.Person " +
                        "where people.hidden = false order by name"));
                AggregateTimesheetQuery query = new AggregateTimesheetQuery(getSession(request));
                query.setPersonIds(form.getSelectedPeople());
                query.setStartDate(form.getStartDate());
                query.setEndDate(form.getEndDate());
                form.setTimesheet(query.getTimesheet());
                if (form.getDateFormat() == null) {
                    String format = getResources(request).getMessage("format.date");
                    form.setDateFormat(new SimpleDateFormat(format));
                }
                return actionMapping.findForward("view/aggregateTimesheet");
            } catch (Exception ex) {
                session.connection().rollback();
                log.error("error", ex);
                throw new ServletException(ex);
            }
        } catch (ServletException ex) {
            throw ex;
View Full Code Here

        super.tearDown();
    }

    public void testSimplePermissionQuery() throws Exception {
        HibernateHelper.initializeHibernate();
        Session session = GlobalSessionFactory.get().openSession();
        Person person = (Person)getObject(session, Person.class, "permissionTester");
        if (person != null) {
            session.delete(person);
            session.delete("from object in " + RoleAssociation.class +
                    " where object.personId = ?",
                    new Integer(person.getId()), Hibernate.INTEGER);
        }
        session.delete("from object in class " + Permission.class.getName() + " where object.name like 'test%'");
        session.flush();
        session.clear();

        int projectId = 11;
        person = new Person("permissionTester");
        person.setName("permissionTester");
        person.setInitials("pt");
        int personId = ((Integer)session.save(person)).intValue();
        session.save(new RoleAssociation(projectId, personId, getRoleId(session, "admin")));
        addPermission(session, personId, "system.project", 1, "testpermission");

        session.flush();
        session.connection().commit();

        SystemAuthorizer.set(new AuthorizerImpl());

        ThreadSession.set(session);
View Full Code Here

         {
            LOGGER.debug("The paging number per page '" + numberPerPage + "' was  set.");
         }
      }

      Session session = SessionFactoryUtils.getSession(getSessionFactory(), allowCreate);
      try
      {
         Query query;

         boolean doFocus = ((getAdapterType() & DO_FOCUS) == 0) && info.isFocusEnabled() && info.isDoFocus() && (namedQuery == null);
View Full Code Here

     * must return session using {@link #closeSession() closeSession()} method.
     * @return Hibernate Session for current thread.
     * @throws HibernateException if there is an error opening a new session.
     */
    public static Session currentSession() throws HibernateException {
        Session s = (Session)MAP.get();
        // Open a new Session, if this Thread has none yet
        if (s == null) {
            s = SESSION_FACTORY.openSession();
            MAP.set(s);
        }
View Full Code Here

     * Closes the Hibernate Session.  Users must call this method after calling
     * {@link #currentSession() currentSession()}.
     * @throws HibernateException if session has problem closing.
     */
    public static void closeSession() throws HibernateException {
        Session s = (Session)MAP.get();
        MAP.set(null);
        if (s != null) {
            s.close();
        }
    }
View Full Code Here

        // cast to the types I want to use
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        HttpSession session = request.getSession(true);

        Session ses = null;
        boolean sessionCreated = false;

        try
        {
            chain.doFilter(request, response);
View Full Code Here

    //~ Methods ================================================================

    public static Session currentSession() throws PersistenceException
    {
        Session s = (Session) session.get();

        if (s == null)
        {
            s = PersistenceManager.openSession();
            if (log.isDebugEnabled())
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.