javax.persistence.EntityManager#getFlushMode ( )源码实例Demo

下面列出了javax.persistence.EntityManager#getFlushMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mycore   文件: MCRCategoryDAOImpl.java
private static <T> T withoutFlush(EntityManager entityManager, boolean flushAtEnd,
    Function<EntityManager, T> task) {
    FlushModeType fm = entityManager.getFlushMode();
    entityManager.setFlushMode(FlushModeType.COMMIT);
    try {
        T result = task.apply(entityManager);
        if (flushAtEnd) {
            entityManager.flush();
        }
        return result;
    } catch (RuntimeException e) {
        throw e;
    } finally {
        entityManager.setFlushMode(fm);
    }
}
 
源代码2 项目: tomee   文件: EncBmpBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码3 项目: tomee   文件: EncCmpBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码4 项目: tomee   文件: EncCmp2Bean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码5 项目: tomee   文件: PersistenceContextStatefulBean.java
public void testPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码6 项目: tomee   文件: PersistenceContextStatefulBean.java
public void testPropgation() throws TestFailureException {
    if (inheritedDelegate == null) return;
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/ExtendedTestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();

            final EntityManager delegate = (EntityManager) em.getDelegate();
            Assert.assertSame("Extended entity manager delegate should be the same instance that was found last time",
                inheritedDelegate,
                delegate);
        } catch (final Exception e) {
            e.printStackTrace();
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码7 项目: tomee   文件: EncStatefulBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码8 项目: tomee   文件: ContextLookupMdbPojoBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码9 项目: tomee   文件: ContextLookupStatelessPojoBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码10 项目: tomee   文件: EncStatelessBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码11 项目: tomee   文件: EncSingletonBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码12 项目: tomee   文件: ContextLookupSingletonPojoBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码13 项目: tomee   文件: ContextLookupBmpBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final EntityManager em = (EntityManager) ejbContext.lookup("persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码14 项目: tomee   文件: ContextLookupCmpBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final EntityManager em = (EntityManager) ejbContext.lookup("persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码15 项目: tomee   文件: ContextLookupStatefulPojoBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final EntityManager em = (EntityManager) ejbContext.lookup("persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码16 项目: tomee   文件: ContextLookupStatefulBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final EntityManager em = (EntityManager) ejbContext.lookup("persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码17 项目: tomee   文件: PersistenceContextStatefulBean.java
public void testExtendedPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/ExtendedTestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();

            if (extendedEntityManager != null) {
                Assert.assertSame("Extended entity manager should be the same instance that was found last time",
                    extendedEntityManager,
                    em);
                Assert.assertSame("Extended entity manager delegate should be the same instance that was found last time",
                    extendedEntityManager.getDelegate(),
                    em.getDelegate());
            }
            extendedEntityManager = em;

            final UserTransaction userTransaction = ejbContext.getUserTransaction();
            userTransaction.begin();
            try {
                em.getFlushMode();
            } finally {
                userTransaction.commit();
            }
        } catch (final Exception e) {
            e.printStackTrace();
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码18 项目: tomee   文件: ContextLookupSingletonBean.java
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final EntityManager em = (EntityManager) ejbContext.lookup("persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
源代码19 项目: tomee   文件: JtaEntityManager.java
public FlushModeType getFlushMode() {
    final EntityManager entityManager = getEntityManager();
    try {
        final Timer timer = Op.getFlushMode.start(this.timer, this);
        try {
            return entityManager.getFlushMode();
        } finally {
            timer.stop();
        }
    } finally {
        closeIfNoTx(entityManager);
    }
}
 
源代码20 项目: tomee   文件: PersistenceContextStatefulBean.java
public void testPropagatedPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/ExtendedTestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();

            // get the raw entity manager so we can test it below
            inheritedDelegate = (EntityManager) em.getDelegate();

            // The extended entity manager is not propigated to a non-extended entity manager unless there is a transaction
            final EntityManager nonExtendedEm = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            nonExtendedEm.getFlushMode();
            final EntityManager nonExtendedDelegate = ((EntityManager) nonExtendedEm.getDelegate());
            Assert.assertTrue("non-extended entity manager should be open", nonExtendedDelegate.isOpen());
            Assert.assertNotSame("Extended non-extended entity manager shound not be the same instance as extendend entity manager when accessed out side of a transactions",
                inheritedDelegate,
                nonExtendedDelegate);

            // When the non-extended entity manager is accessed within a transaction is should see the stateful extended context.
            //
            // Note: this code also tests EBJ 3.0 Persistence spec 5.9.1 "UserTransaction is begun within the method, the
            // container associates the persistence context with the JTA transaction and calls EntityManager.joinTransaction."
            // If our the extended entity manager were not associted with the transaction, the non-extended entity manager would
            // not see it.
            final UserTransaction userTransaction = ejbContext.getUserTransaction();
            userTransaction.begin();
            try {
                Assert.assertSame("Extended non-extended entity manager to be same instance as extendend entity manager",
                    inheritedDelegate,
                    nonExtendedEm.getDelegate());
            } finally {
                userTransaction.commit();
            }

            // When a stateful bean with an extended entity manager creates another stateful bean, the new bean will
            // inherit the extended entity manager (assuming it contains an extended entity manager for the same persistence
            // unit).
            final PersistenceContextStatefulHome home = (PersistenceContextStatefulHome) ejbContext.getEJBHome();
            final PersistenceContextStatefulObject object = home.create();

            // test the new stateful bean recieved the context
            object.testPropgation();

            // remove the bean
            object.remove();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}