Package net.sf.hibernate

Examples of net.sf.hibernate.Transaction


        ThreadSession.set(null);
        super.tearDown();
    }

    public void testAttributeManagement() throws Exception {
        Transaction txn;

        txn = session.beginTransaction();
        repository.setAttribute(0, "test.x", "xvalue0");
        repository.setAttribute(0, "test.y", "yvalue0");
        repository.setAttribute(10000, "test.y", "foo");
        txn.commit();

        txn = session.beginTransaction();
        assertEquals("wrong attribute value", "xvalue0", repository.getAttribute(0, "test.x"));
        assertEquals("wrong attribute value", "yvalue0", repository.getAttribute(0, "test.y"));
        assertEquals("wrong attribute value", "foo", repository.getAttribute(10000, "test.y"));

        repository.delete(10000, "test.y");
        txn.commit();

        txn = session.beginTransaction();
        assertNull("wrong attribute value", repository.getAttribute(10000, "test.y"));

        Map attributes = repository.getAttributes(0, "test.");
        assertEquals("wrong attribute map", 2, attributes.size());
        assertEquals("wrong attribute value", "xvalue0", attributes.get("x"));
        assertEquals("wrong attribute value", "yvalue0", attributes.get("y"));

        // modification
        repository.setAttribute(0, "test.x", "another value");
        txn.commit();

        txn = session.beginTransaction();
        assertEquals("wrong attribute value", "another value", repository.getAttribute(0, "test.x"));;

        repository.delete(0, "test.x");
        repository.delete(0, "test.y");
        txn.commit();

        txn = session.beginTransaction();
        assertNull("wrong attribute value", repository.getAttribute(0, "test.x"));
        assertNull("wrong attribute value", repository.getAttribute(0, "test.y"));
        txn.commit();
    }
View Full Code Here


     * This hack ensures that referential integrity is maintained.  It dropps
     * the table generated by hibernate and replaces it with a better one.
     * @param session
     */
    public static void addIntegrityEnforcements(Session session) throws HibernateException {
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            Statement st = session.connection().createStatement();
            st.executeUpdate(
                "DROP TABLE hresperformsrole;" +
                "CREATE TABLE hresperformsrole" +
                "(" +
                  "hresid varchar(255) NOT NULL," +
                  "rolename varchar(255) NOT NULL," +
                  "CONSTRAINT hresperformsrole_pkey PRIMARY KEY (hresid, rolename)," +
                  "CONSTRAINT ResourceFK FOREIGN KEY (hresid) REFERENCES resserposid (id) ON UPDATE CASCADE ON DELETE CASCADE," +
                  "CONSTRAINT RoleFK FOREIGN KEY (rolename) REFERENCES role (rolename) ON UPDATE CASCADE ON DELETE CASCADE" +
                ");"
            );
            tx.commit();
        } catch (Exception e) {
            tx.rollback();
        }
    }
View Full Code Here

    }

    private void doPersistAction(Object obj, int operation) throws YPersistenceException {
        try {
            Session session = _factory.openSession();
            Transaction tx = session.beginTransaction();
            if (UPDATE_OPERATION == operation) {
                session.update(obj);
            } else if (DELETE_OPERATION == operation) {
                session.delete(obj);
            } else if (SAVE_OPERATION == operation) {
                session.save(obj);
            }
            session.flush();
            session.evict(obj);
            tx.commit();
            session.close();
        } catch (HibernateException e) {
            throw new YPersistenceException("Hibernate problem: " + e.getMessage(), e);
        }
    }
View Full Code Here

    private MetaRepository metaRepository;

    public final ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        Session session = ThreadSession.get();
        Transaction transaction = session.beginTransaction();
        try {
            ActionForward forward = doExecute(mapping, form, request, response);
            Object object = request.getAttribute(TARGET_OBJECT);
            if (object != null) {
                beforeObjectCommit(object, session, mapping, form, request, response);
            }
            transaction.commit();
            afterObjectCommit(mapping, form, request, response);
            return forward;
        } catch (AuthorizationException e) {
            request.setAttribute("exception", e);
            return mapping.findForward("security/notAuthorized");
        } catch (ObjectNotFoundException e) {
            request.setAttribute("exception", e);
            return mapping.findForward("error/objectNotFound");
        } catch (Exception e) {
            transaction.rollback();
            throw e;
        }
    }
View Full Code Here

TOP

Related Classes of net.sf.hibernate.Transaction

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.