Exemplo n.º 1
0
 public void _delete() {
   try {
     avoidCascadeSaveLoops.set(new HashSet<JPABase>());
     try {
       saveAndCascade(true);
     } finally {
       avoidCascadeSaveLoops.get().clear();
     }
     em().remove(this);
     try {
       em().flush();
     } catch (PersistenceException e) {
       if (e.getCause() instanceof GenericJDBCException) {
         throw new PersistenceException(((GenericJDBCException) e.getCause()).getSQL(), e);
       } else {
         throw e;
       }
     }
     avoidCascadeSaveLoops.set(new HashSet<JPABase>());
     try {
       saveAndCascade(false);
     } finally {
       avoidCascadeSaveLoops.get().clear();
     }
     PlayPlugin.postEvent("JPASupport.objectDeleted", this);
   } catch (PersistenceException e) {
     throw e;
   } catch (Throwable e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 2
0
 public void _save() {
   if (!em().contains(this)) {
     em().persist(this);
     PlayPlugin.postEvent("JPASupport.objectPersisted", this);
   }
   avoidCascadeSaveLoops.set(new HashSet<JPABase>());
   try {
     saveAndCascade(true);
   } finally {
     avoidCascadeSaveLoops.get().clear();
   }
   try {
     em().flush();
   } catch (PersistenceException e) {
     if (e.getCause() instanceof GenericJDBCException) {
       throw new PersistenceException(((GenericJDBCException) e.getCause()).getSQL(), e);
     } else {
       throw e;
     }
   }
   avoidCascadeSaveLoops.set(new HashSet<JPABase>());
   try {
     saveAndCascade(false);
   } finally {
     avoidCascadeSaveLoops.get().clear();
   }
 }
  /**
   * Tests accuracy of <code>PersistenceException(String, Throwable)</code> constructor.<br>
   * The detail error message and the original cause of error should be properly set.
   */
  @Test
  public void testCtor2() {
    PersistenceException exception = new PersistenceException(DETAIL_MESSAGE, CAUSE);

    // Verify that there is a detail message
    assertNotNull("Should have message.", exception.getMessage());
    assertEquals(
        "Detailed error message with cause should be properly set.",
        DETAIL_MESSAGE,
        exception.getMessage());

    // Verify that there is a cause
    assertNotNull("Should have cause.", exception.getCause());
    assertSame("Cause should be identical.", CAUSE, exception.getCause());
  }
  /**
   * Tests accuracy of <code>PersistenceException(String, Throwable, ExceptionData)</code>
   * constructor.<br>
   * The detail error message, the cause exception and the exception data should be properly set.
   */
  @Test
  public void testCtor4() {
    PersistenceException exception =
        new PersistenceException(DETAIL_MESSAGE, CAUSE, EXCEPTION_DATA);

    // Verify that there is a detail message
    assertNotNull("Should have message.", exception.getMessage());
    assertEquals(
        "Detailed error message with cause should be properly set.",
        DETAIL_MESSAGE,
        exception.getMessage());

    // Verify that the exception data is correctly set.
    assertNotNull("Application code should not null.", exception.getApplicationCode());
    assertEquals("Exception data is not set.", APPLICATION_CODE, exception.getApplicationCode());

    // Verify that there is a cause
    assertNotNull("Should have cause.", exception.getCause());
    assertSame("Cause should be identical.", CAUSE, exception.getCause());
  }