List of usage examples for org.springframework.dao InvalidDataAccessApiUsageException InvalidDataAccessApiUsageException
public InvalidDataAccessApiUsageException(String msg, Throwable cause)
From source file:org.springextensions.db4o.ObjectServerUtils.java
/** * db4o exception translator - it converts specific db4o unchecked/checked * exceptions into unchecked Spring DA exception. * <p/>/*from www.ja v a 2s . co m*/ * As there is no db4o specific base exception, the Db4oSystemException is * used as a marker inside the package for a user specific runtime exception * inside the callbacks for example. * * @param ex * @return */ public static DataAccessException translateException(Exception ex) { if (ex instanceof DatabaseFileLockedException) { return new DataAccessResourceFailureException("database is already locked ", ex); } if (ex instanceof ObjectNotStorableException) return new InvalidDataAccessApiUsageException("object not storable ", ex); if (ex instanceof OldFormatException) return new DataAccessResourceFailureException("database is in old format", ex); if (ex instanceof IOException) return new DataAccessResourceFailureException("cannot do backup ", ex); // fallback return new Db4oSystemException(ex); }
From source file:com.frank.search.solr.core.SolrExceptionTranslator.java
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex.getCause() instanceof SolrServerException) { SolrServerException solrServerException = (SolrServerException) ex.getCause(); if (solrServerException.getCause() instanceof SolrException) { SolrException solrException = (SolrException) solrServerException.getCause(); // solr 4.x moved ParseExecption from org.apache.lucene.queryParser to org.apache.lucene.queryparser.classic // therefore compare ShortClassName instead of using instanceof expression if (solrException.getCause() != null && ClassUtils.getShortName(solrException.getCause().getClass()) .equalsIgnoreCase("ParseException")) { return new InvalidDataAccessApiUsageException((solrException.getCause()).getMessage(), solrException.getCause()); } else { ErrorCode errorCode = ErrorCode.getErrorCode(solrException.code()); switch (errorCode) { case NOT_FOUND: case SERVICE_UNAVAILABLE: case SERVER_ERROR: return new DataAccessResourceFailureException(solrException.getMessage(), solrException); case FORBIDDEN: case UNAUTHORIZED: return new PermissionDeniedDataAccessException(solrException.getMessage(), solrException); case BAD_REQUEST: return new InvalidDataAccessApiUsageException(solrException.getMessage(), solrException); case UNKNOWN: return new UncategorizedSolrException(solrException.getMessage(), solrException); default: break; }//w ww . j av a 2 s .c om } } else if (solrServerException.getCause() instanceof ConnectException) { return new DataAccessResourceFailureException(solrServerException.getCause().getMessage(), solrServerException.getCause()); } } return null; }
From source file:com.frank.search.solr.repository.support.SimpleSolrRepository.java
public Class<T> getEntityClass() { if (!isEntityClassSet()) { try {//w w w. j a v a 2 s . c o m this.entityClass = resolveReturnedClassFromGernericType(); } catch (Exception e) { throw new InvalidDataAccessApiUsageException( "Unable to resolve EntityClass. Please use according setter!", e); } } return entityClass; }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
/** * Inspects the given {@link CommandResult} for erros and potentially throws an * {@link InvalidDataAccessApiUsageException} for that error. * /*from w ww . ja va 2 s . c o m*/ * @param result must not be {@literal null}. * @param source must not be {@literal null}. */ private void handleCommandError(CommandResult result, DBObject source) { try { result.throwOnError(); } catch (MongoException ex) { String error = result.getErrorMessage(); error = error == null ? "NO MESSAGE" : error; throw new InvalidDataAccessApiUsageException( "Command execution failed: Error [" + error + "], Command = " + source, ex); } }
From source file:org.springframework.data.neo4j.transaction.SessionFactoryUtils.java
/** * Convert the given runtime exception to an appropriate exception from the * {@code org.springframework.dao} hierarchy. * Return null if no translation is appropriate: any other exception may * have resulted from user code, and should not be translated. * @param ex runtime exception that occurred * @return the corresponding DataAccessException instance, * or {@code null} if the exception should not be translated *//*from w w w .j a v a2 s . c om*/ public static DataAccessException convertOgmAccessException(RuntimeException ex) { if (ex instanceof IllegalStateException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof IllegalArgumentException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof NotFoundException) { return new DataRetrievalFailureException(ex.getMessage(), ex); } if (ex instanceof InvalidDepthException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof ResultProcessingException) { return new DataRetrievalFailureException(ex.getMessage(), ex); } // If we get here, we have an exception that resulted from user code, // rather than the persistence provider, so we return null to indicate // that translation should not occur. return null; }
From source file:org.springframework.jdbc.support.lob.OracleLobHandler.java
/** * Retrieve the {@code oracle.sql.BLOB} and {@code oracle.sql.CLOB} * classes via reflection, and initialize the values for the * DURATION_SESSION, MODE_READWRITE and MODE_READONLY constants defined there. * <p><strong>See Also:</strong> * <ul>/*from w w w . j a v a2 s. c o m*/ * <li><a href="http://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/sql/BLOB.html#DURATION_SESSION">oracle.sql.BLOB.DURATION_SESSION</a></li> * <li><a href="http://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/sql/BLOB.html#MODE_READWRITE">oracle.sql.BLOB.MODE_READWRITE</a></li> * <li><a href="http://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/sql/BLOB.html#MODE_READONLY">oracle.sql.BLOB.MODE_READONLY</a></li> * <li><a href="http://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/sql/CLOB.html#DURATION_SESSION">oracle.sql.CLOB.DURATION_SESSION</a></li> * <li><a href="http://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/sql/CLOB.html#MODE_READWRITE">oracle.sql.CLOB.MODE_READWRITE</a></li> * <li><a href="http://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/sql/CLOB.html#MODE_READONLY">oracle.sql.CLOB.MODE_READONLY</a></li> * </ul> * @param con the Oracle Connection, for using the exact same class loader * that the Oracle driver was loaded with */ protected synchronized void initOracleDriverClasses(Connection con) { if (this.blobClass == null) { try { // Initialize oracle.sql.BLOB class this.blobClass = con.getClass().getClassLoader().loadClass(BLOB_CLASS_NAME); this.durationSessionConstants.put(this.blobClass, this.blobClass.getField(DURATION_SESSION_FIELD_NAME).getInt(null)); this.modeReadWriteConstants.put(this.blobClass, this.blobClass.getField(MODE_READWRITE_FIELD_NAME).getInt(null)); this.modeReadOnlyConstants.put(this.blobClass, this.blobClass.getField(MODE_READONLY_FIELD_NAME).getInt(null)); // Initialize oracle.sql.CLOB class this.clobClass = con.getClass().getClassLoader().loadClass(CLOB_CLASS_NAME); this.durationSessionConstants.put(this.clobClass, this.clobClass.getField(DURATION_SESSION_FIELD_NAME).getInt(null)); this.modeReadWriteConstants.put(this.clobClass, this.clobClass.getField(MODE_READWRITE_FIELD_NAME).getInt(null)); this.modeReadOnlyConstants.put(this.clobClass, this.clobClass.getField(MODE_READONLY_FIELD_NAME).getInt(null)); } catch (Exception ex) { throw new InvalidDataAccessApiUsageException( "Couldn't initialize OracleLobHandler because Oracle driver classes are not available. " + "Note that OracleLobHandler requires Oracle JDBC driver 9i or higher!", ex); } } }
From source file:org.springframework.orm.hibernate.SessionFactoryUtils.java
/** * Convert the given HibernateException to an appropriate exception * from the <code>org.springframework.dao</code> hierarchy. * <p>Note that it is advisable to handle {@link net.sf.hibernate.JDBCException} * specifically by using a {@link org.springframework.jdbc.support.SQLExceptionTranslator} * for the underlying SQLException.// w w w .j a v a 2 s. c o m * @param ex HibernateException that occured * @return the corresponding DataAccessException instance * @see HibernateAccessor#convertHibernateAccessException * @see HibernateTransactionManager#convertHibernateAccessException */ public static DataAccessException convertHibernateAccessException(HibernateException ex) { if (ex instanceof JDBCException) { // SQLException during Hibernate access: only passed in here from custom code, // as HibernateTemplate etc will use SQLExceptionTranslator-based handling. return new HibernateJdbcException((JDBCException) ex); } if (ex instanceof UnresolvableObjectException) { return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex); } if (ex instanceof ObjectNotFoundException) { return new HibernateObjectRetrievalFailureException((ObjectNotFoundException) ex); } if (ex instanceof ObjectDeletedException) { return new HibernateObjectRetrievalFailureException((ObjectDeletedException) ex); } if (ex instanceof WrongClassException) { return new HibernateObjectRetrievalFailureException((WrongClassException) ex); } if (ex instanceof StaleObjectStateException) { return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex); } if (ex instanceof QueryException) { return new HibernateQueryException((QueryException) ex); } if (ex instanceof PersistentObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof TransientObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } // fallback return new HibernateSystemException(ex); }
From source file:org.springframework.orm.hibernate3.SessionFactoryUtils.java
/** * Convert the given HibernateException to an appropriate exception * from the {@code org.springframework.dao} hierarchy. * @param ex HibernateException that occurred * @return the corresponding DataAccessException instance * @see HibernateAccessor#convertHibernateAccessException * @see HibernateTransactionManager#convertHibernateAccessException *//*from ww w . j a v a2 s . co m*/ public static DataAccessException convertHibernateAccessException(HibernateException ex) { if (ex instanceof JDBCConnectionException) { return new DataAccessResourceFailureException(ex.getMessage(), ex); } if (ex instanceof SQLGrammarException) { SQLGrammarException jdbcEx = (SQLGrammarException) ex; return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof QueryTimeoutException) { QueryTimeoutException jdbcEx = (QueryTimeoutException) ex; return new org.springframework.dao.QueryTimeoutException( ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof LockAcquisitionException) { LockAcquisitionException jdbcEx = (LockAcquisitionException) ex; return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof PessimisticLockException) { PessimisticLockException jdbcEx = (PessimisticLockException) ex; return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof ConstraintViolationException) { ConstraintViolationException jdbcEx = (ConstraintViolationException) ex; return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex); } if (ex instanceof DataException) { DataException jdbcEx = (DataException) ex; return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof JDBCException) { return new HibernateJdbcException((JDBCException) ex); } // end of JDBCException (subclass) handling if (ex instanceof QueryException) { return new HibernateQueryException((QueryException) ex); } if (ex instanceof NonUniqueResultException) { return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex); } if (ex instanceof NonUniqueObjectException) { return new DuplicateKeyException(ex.getMessage(), ex); } if (ex instanceof PropertyValueException) { return new DataIntegrityViolationException(ex.getMessage(), ex); } if (ex instanceof PersistentObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof TransientObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof ObjectDeletedException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof UnresolvableObjectException) { return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex); } if (ex instanceof WrongClassException) { return new HibernateObjectRetrievalFailureException((WrongClassException) ex); } if (ex instanceof StaleObjectStateException) { return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex); } if (ex instanceof StaleStateException) { return new HibernateOptimisticLockingFailureException((StaleStateException) ex); } if (ex instanceof OptimisticLockException) { return new HibernateOptimisticLockingFailureException((OptimisticLockException) ex); } // fallback return new HibernateSystemException(ex); }
From source file:org.springframework.orm.hibernate4.fix.SessionFactoryUtils.java
/** * Convert the given HibernateException to an appropriate exception * from the {@code org.springframework.dao} hierarchy. * @param ex HibernateException that occured * @return the corresponding DataAccessException instance * @see HibernateExceptionTranslator#convertHibernateAccessException * @see HibernateTransactionManager#convertHibernateAccessException */// ww w. j a va 2s .co m public static DataAccessException convertHibernateAccessException(HibernateException ex) { if (ex instanceof JDBCConnectionException) { return new DataAccessResourceFailureException(ex.getMessage(), ex); } if (ex instanceof SQLGrammarException) { SQLGrammarException jdbcEx = (SQLGrammarException) ex; return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof LockAcquisitionException) { LockAcquisitionException jdbcEx = (LockAcquisitionException) ex; return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof ConstraintViolationException) { ConstraintViolationException jdbcEx = (ConstraintViolationException) ex; return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex); } if (ex instanceof DataException) { DataException jdbcEx = (DataException) ex; return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof JDBCException) { return new HibernateJdbcException((JDBCException) ex); } // end of JDBCException (subclass) handling if (ex instanceof QueryException) { return new HibernateQueryException((QueryException) ex); } if (ex instanceof NonUniqueResultException) { return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex); } if (ex instanceof NonUniqueObjectException) { return new DuplicateKeyException(ex.getMessage(), ex); } if (ex instanceof PropertyValueException) { return new DataIntegrityViolationException(ex.getMessage(), ex); } if (ex instanceof PersistentObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof TransientObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof ObjectDeletedException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof UnresolvableObjectException) { return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex); } if (ex instanceof WrongClassException) { return new HibernateObjectRetrievalFailureException((WrongClassException) ex); } if (ex instanceof StaleObjectStateException) { return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex); } if (ex instanceof StaleStateException) { return new HibernateOptimisticLockingFailureException((StaleStateException) ex); } // fallback return new HibernateSystemException(ex); }
From source file:org.springframework.orm.hibernate4.SessionFactoryUtils.java
/** * Convert the given HibernateException to an appropriate exception * from the {@code org.springframework.dao} hierarchy. * @param ex HibernateException that occurred * @return the corresponding DataAccessException instance * @see HibernateExceptionTranslator#convertHibernateAccessException * @see HibernateTransactionManager#convertHibernateAccessException *///from w w w . j a va2s . c o m public static DataAccessException convertHibernateAccessException(HibernateException ex) { if (ex instanceof JDBCConnectionException) { return new DataAccessResourceFailureException(ex.getMessage(), ex); } if (ex instanceof SQLGrammarException) { SQLGrammarException jdbcEx = (SQLGrammarException) ex; return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof QueryTimeoutException) { QueryTimeoutException jdbcEx = (QueryTimeoutException) ex; return new org.springframework.dao.QueryTimeoutException( ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof LockAcquisitionException) { LockAcquisitionException jdbcEx = (LockAcquisitionException) ex; return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof PessimisticLockException) { PessimisticLockException jdbcEx = (PessimisticLockException) ex; return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof ConstraintViolationException) { ConstraintViolationException jdbcEx = (ConstraintViolationException) ex; return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex); } if (ex instanceof DataException) { DataException jdbcEx = (DataException) ex; return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof JDBCException) { return new HibernateJdbcException((JDBCException) ex); } // end of JDBCException (subclass) handling if (ex instanceof QueryException) { return new HibernateQueryException((QueryException) ex); } if (ex instanceof NonUniqueResultException) { return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex); } if (ex instanceof NonUniqueObjectException) { return new DuplicateKeyException(ex.getMessage(), ex); } if (ex instanceof PropertyValueException) { return new DataIntegrityViolationException(ex.getMessage(), ex); } if (ex instanceof PersistentObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof TransientObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof ObjectDeletedException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof UnresolvableObjectException) { return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex); } if (ex instanceof WrongClassException) { return new HibernateObjectRetrievalFailureException((WrongClassException) ex); } if (ex instanceof StaleObjectStateException) { return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex); } if (ex instanceof StaleStateException) { return new HibernateOptimisticLockingFailureException((StaleStateException) ex); } if (ex instanceof OptimisticEntityLockException) { return new HibernateOptimisticLockingFailureException((OptimisticEntityLockException) ex); } if (ex instanceof PessimisticEntityLockException) { if (ex.getCause() instanceof LockAcquisitionException) { return new CannotAcquireLockException(ex.getMessage(), ex.getCause()); } return new PessimisticLockingFailureException(ex.getMessage(), ex); } // fallback return new HibernateSystemException(ex); }