/** Returns the flush mode. */
  @Override
  public FlushModeType getFlushMode() {
    EntityManager em = getCurrent();

    if (em != null) return em.getFlushMode();

    em = createEntityManager();

    try {
      return em.getFlushMode();
    } finally {
      freeEntityManager(em);
    }
  }
  @Test
  public void testSMPCCreationObserved()
      throws NotSupportedException, SystemException, SecurityException, IllegalStateException,
          RollbackException, HeuristicMixedException, HeuristicRollbackException {
    em.isOpen(); // need to make a call on the EM to force creation

    Assert.assertTrue(observer.isObserverRun());
    Assert.assertEquals(FlushModeType.COMMIT, em.getFlushMode());
  }
  /**
   * Sets the flush mode to COMMIT and verifies if the container does not make a flush when a query
   * method is called.The flush must be called only in the commit.
   */
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void setFlushModeCommit() {
    entityManager.setFlushMode(FlushModeType.COMMIT);
    assertEquals(entityManager.getFlushMode(), FlushModeType.COMMIT, "The flush mode was not set.");

    EBStore ebstoreBeforeChange = entityManager.find(EBStore.class, ENTITY_ID);
    ebstoreBeforeChange.setName(ENTITY_NAME_2);
    // forces a flush
    entityManager.createQuery("SELECT e FROM EBStore e");
    // verifies if the flush was not made
    EBStore ebstoreAfterChange = entityManager.find(EBStore.class, ENTITY_ID);
    assertEquals(
        ebstoreAfterChange.getName(), ENTITY_NAME, "The container made a flush after the query");
  }
  public void lookupPersistenceContext() throws TestFailureException {
    try {
      try {
        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 (Exception e) {
        Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
      }
    } catch (AssertionFailedError afe) {
      throw new TestFailureException(afe);
    }
  }
Example #5
0
  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);
    }
  }
 /** Verifies if the flush mode value is auto. */
 public void verifyDefaultFlushMode() {
   assertEquals(
       entityManager.getFlushMode(),
       FlushModeType.AUTO,
       "The flush mode is not beginning with the default value");
 }
 @Override
 public FlushModeType getFlushMode() {
   // TODO Auto-generated method stub
   return myEntityManager.getFlushMode();
 }
Example #8
0
 public FlushModeType getFlushMode() {
   return delegate.getFlushMode();
 }