Package org.springframework.dao

Examples of org.springframework.dao.DataAccessException


        bookService.deleteBook(null);
    }
   
    @Test(expected=DataAccessException.class)
    public void testDeleteBookWithNullID() {
       doThrow(new DataAccessException("null book id") {}).when(bookDao).deleteBook(book);
       bookService.deleteBook(bookTO);
    }
View Full Code Here


        verify(bookDao).deleteBook(book);
    }
   
    @Test(expected=DataAccessException.class)
    public void testUpdateNullBook() {
        doThrow(new DataAccessException("null book") {}).when(bookDao).updateBook(null);
        bookService.updateBook(null);
    }
View Full Code Here

        bookService.updateBook(null);
    }
   
    @Test(expected=DataAccessException.class)
    public void testUpdateBookWithNullID() {
       doThrow(new DataAccessException("null book id") {}).when(bookDao).updateBook(book);
       bookService.updateBook(bookTO);
    }
View Full Code Here

     * @param re the RuntimeException to translate to a Rave application exception
     * @return a Rave application exception representing the database error
     */
    @Override
    public DataAccessException translateExceptionIfPossible(RuntimeException re) {       
        DataAccessException e = null;
        // first make sure the root exception is actually an org.h2.jdbc.JdbcSQLException
        if (ExceptionUtils.getRootCause(re) instanceof JdbcSQLException) {
            JdbcSQLException rootException = (JdbcSQLException)ExceptionUtils.getRootCause(re);
                       
            // now translate the H2 specific error codes into Rave's common application Exceptions
View Full Code Here

        }
      }
    }

    private RuntimeException convertCompletionException(RuntimeException ex) {
      DataAccessException daex = (this.exceptionTranslator != null) ?
          this.exceptionTranslator.translateExceptionIfPossible(ex) :
          EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
      return (daex != null ? daex : ex);
    }
View Full Code Here

      EntityTransaction tx = txObject.getEntityManagerHolder().getEntityManager().getTransaction();
      tx.commit();
    }
    catch (RollbackException ex) {
      if (ex.getCause() instanceof RuntimeException) {
        DataAccessException dex = getJpaDialect().translateExceptionIfPossible((RuntimeException) ex.getCause());
        if (dex != null) {
          throw dex;
        }
      }
      throw new TransactionSystemException("Could not commit JPA transaction", ex);
View Full Code Here

    assertNull("No dialect set", cefb.getJpaDialect());

    RuntimeException in1 = new RuntimeException("in1");
    PersistenceException in2 = new PersistenceException();
    assertNull("No translation here", cefb.translateExceptionIfPossible(in1));
    DataAccessException dex = cefb.translateExceptionIfPossible(in2);
    assertNotNull(dex);
    assertSame(in2, dex.getCause());
  }
View Full Code Here

   
  protected void doTestExceptionTranslationWithDialectFound(PersistenceExceptionTranslator pet) throws Exception {
    RuntimeException in1 = new RuntimeException("in1");
    PersistenceException in2 = new PersistenceException();
    assertNull("No translation here", pet.translateExceptionIfPossible(in1));
    DataAccessException dex = pet.translateExceptionIfPossible(in2);
    assertNotNull(dex);
    assertSame(in2, dex.getCause());
  }
View Full Code Here

    assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
  }
 
  public void testTranslatesIllegalStateException() {
    IllegalStateException ise = new IllegalStateException();
    DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ise);
    assertSame(ise, dex.getCause());
    assertTrue(dex instanceof InvalidDataAccessApiUsageException);
  }
View Full Code Here

    assertTrue(dex instanceof InvalidDataAccessApiUsageException);
  }
 
  public void testTranslatesIllegalArgumentException() {
    IllegalArgumentException iae = new IllegalArgumentException();
    DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(iae);
    assertSame(iae, dex.getCause());
    assertTrue(dex instanceof InvalidDataAccessApiUsageException);
  }
View Full Code Here

TOP

Related Classes of org.springframework.dao.DataAccessException

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.