Package javax.persistence

Examples of javax.persistence.EntityManager


                logger.debug("Error in EntityManagerFactory use: {0}", e);
                e.printStackTrace();
            }

        } else if (isEqual(ENTITY_MANAGER, op)) {
            EntityManager em = (EntityManager) ctx.lookup("persistence/pctx01");
            try {
                EntityManagerTester.checkInstance(em, "tmpTable" + this.hashCode());
                log(MDBListenerMethodAccess.class, ON_MESSAGE, MDBListenerMethodAccess.class, ENTITY_MANAGER);
            } catch (Exception e) {
                logger.debug("Error in EntityManagerFactory use: {0}", e);
View Full Code Here


    /**
     * Cleans the db.
     */
    public void startup() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Book bookResult = entityManager.find(Book.class, new Integer(ID));
        if (bookResult != null) {
            entityManager.remove(bookResult);
        }
    }
View Full Code Here

    /**
     * Verifies if the rollback works.
     */
    public void resourceLevelRollback() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        // begins the transaction
        entityManager.getTransaction().begin();
        // creates a book
        Book book = new Book();
        book.setId(ID);
        book.setName(ENTITY_NAME);
        entityManager.persist(book);
        // makes a rollback
        entityManager.getTransaction().rollback();
        entityManager.close();
        // verifies if the container made the rollback
        Book bookResult = entityManager.find(Book.class, new Integer(ID));
        assertNull(bookResult, "The container did not make the rollback");
    }
View Full Code Here

    /**
     * Verifies if the serRollbackOnly works.
     */
    public void setRollbackOnly() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        // begins the transaction and sets the rollbackonly
        entityManager.getTransaction().begin();
        entityManager.getTransaction().setRollbackOnly();
        // creates a book
        Book book = new Book();
        book.setId(ID);
        book.setName(ENTITY_NAME);
        entityManager.persist(book);
        // verifies if the container registered the rollback.
        assertTrue(entityManager.getTransaction().getRollbackOnly(),
                "The transaction is marked as rollback, but the container returned false for the method getRollbackOnly()");

        // tries to make the commit, the container must throw an exception.
        try {
            entityManager.getTransaction().commit();
            fail("The method setRollbackOnly was called, so the transaction cannot make the commit.");
        } catch (RollbackException e) {
            logger.info("The bean threw an expected exception");
        }
        entityManager.close();

        // verifies if the transaction was rolled back
        Book bookResult = entityManager.find(Book.class, new Integer(ID));
        assertNull(bookResult, "The container did not make the rollback");
    }
View Full Code Here

    /**
     * Verifies if the commit works.
     */
    public void resourceLevelCommit() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        // begins the trasnaction
        entityManager.getTransaction().begin();
        // inserts a book
        Book book = new Book();
        book.setId(ID);
        book.setName(ENTITY_NAME);
        entityManager.persist(book);
        // verifies if the transaction is marked as ACTIVE
        assertTrue(entityManager.getTransaction().isActive(),
                "The transaction is active, but the container returned false when the method isActive was called.");
        // verify if the rollbackonly is not set.
        assertFalse(entityManager.getTransaction().getRollbackOnly(),
                "The transaction is not marked as rollback, but the container returned true for the method getRollbackOnly()");
        // makes a commit
        entityManager.getTransaction().commit();
        entityManager.close();
        // verifies if the bean is persistent.
        Book bookResult = entityManager.find(Book.class, new Integer(ID));
        assertNotNull(bookResult, "The container did not make the rollback");

    }
View Full Code Here

                logger.debug("Error in EntityManagerFactory use: {0}", e);
                e.printStackTrace();
            }

        } else if (isEqual(ENTITY_MANAGER, op)) {
            EntityManager em = (EntityManager) ctx.lookup("persistence/pctx01");
            try {
                EntityManagerTester.checkInstance(em, "tmpTable" + this.hashCode());
                log(getName(), TIMEOUT, getName(), ENTITY_MANAGER);
            } catch (Exception e) {
                logger.debug("Error in EntityManagerFactory use: {0}", e);
View Full Code Here


        } else if (ic.getMethod().toString().contains("accessEntityManagerFactory")) {

            //EntityManagerFactory Access
            EntityManager entityManager = entityFactory.createEntityManager();
            entityManager.getTransaction().begin();
            checkInstance(entityManager, EMFactoryTester.NAME);
            entityManager.getTransaction().commit();

        } else if (ic.getMethod().toString().contains("accessSessionContext")) {

            //SessionContext Access
            if (ctx == null){
View Full Code Here

     * Creates the EntityManagerFactory and cleans the db.
     */
    public ResourceLevelTransTester() {
        // gets the EntitymanagerFactory for the persistence unite book
        entityManagerFactory = Persistence.createEntityManagerFactory("book");
        EntityManager entityManager = entityManagerFactory.createEntityManager();

        Book bookResult = entityManager.find(Book.class, new Integer(ID));
        if (bookResult != null) {
            entityManager.remove(bookResult);
        }
    }
View Full Code Here

    /**
     * Verifies if the rollback works.
     */
    public void resourceLevelRollback() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        // begins the transaction
        entityManager.getTransaction().begin();
        // creates a book
        Book book = new Book();
        book.setId(ID);
        book.setName(ENTITY_NAME);
        entityManager.persist(book);
        // makes a rollback
        entityManager.getTransaction().rollback();
        entityManager.close();
        // verifies if the container made the rollback
        Book bookResult = entityManager.find(Book.class, new Integer(ID));
        assertNull(bookResult, "The container did not make the rollback");
    }
View Full Code Here

    /**
     * Verifies if the serRollbackOnly works.
     */
    public void setRollbackOnly() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        // begins the transaction and sets the rollbackonly
        entityManager.getTransaction().begin();
        entityManager.getTransaction().setRollbackOnly();
        // creates a book
        Book book = new Book();
        book.setId(ID);
        book.setName(ENTITY_NAME);
        entityManager.persist(book);
        // verifies if the container registered the rollback.
        assertTrue(entityManager.getTransaction().getRollbackOnly(),
                "The transaction is marked as rollback, but the container returned false for the method getRollbackOnly()");

        // tries to make the commit, the container must throw an exception.
        try {
            entityManager.getTransaction().commit();
            fail("The method setRollbackOnly was called, so the transaction cannot make the commit.");
        } catch (RollbackException e) {
            logger.info("The bean threw an expected exception");
        }
        entityManager.close();

        // verifies if the transaction was rolled back
        Book bookResult = entityManager.find(Book.class, new Integer(ID));
        assertNull(bookResult, "The container did not make the rollback");
    }
View Full Code Here

TOP

Related Classes of javax.persistence.EntityManager

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.