Package org.springframework.dao

Examples of org.springframework.dao.InvalidDataAccessApiUsageException


      catch (InvocationTargetException ex) {
        if (ex.getTargetException() instanceof SQLException) {
          throw (SQLException) ex.getTargetException();
        }
        else if (con != null && ex.getTargetException() instanceof ClassCastException) {
          throw new InvalidDataAccessApiUsageException(
              "OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [" +
              con.getClass().getName() + "]: specify a corresponding NativeJdbcExtractor",
              ex.getTargetException());
        }
        else {
View Full Code Here


   * @param generatedKeyHolder KeyHolder that will hold the generated keys
   * @return the number of rows affected by the update
   */
  public int update(Object[] params, KeyHolder generatedKeyHolder) throws DataAccessException {
    if (!isReturnGeneratedKeys() && getGeneratedKeysColumnNames() == null) {
      throw new InvalidDataAccessApiUsageException(
          "The update method taking a KeyHolder should only be used when generated keys have " +
          "been configured by calling either 'setReturnGeneratedKeys' or " +
          "'setGeneratedKeysColumnNames'.");
    }
    validateParameters(params);
View Full Code Here

   */
  public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
    // Following the JPA specification, a persistence provider can also
    // throw these two exceptions, besides PersistenceException.
    if (ex instanceof IllegalStateException) {
      return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof IllegalArgumentException) {
      return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }

    // Check for well-known PersistenceException subclasses.
    if (ex instanceof EntityNotFoundException) {
      return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
    }
    if (ex instanceof NoResultException) {
      return new EmptyResultDataAccessException(ex.getMessage(), 1);
    }
    if (ex instanceof NonUniqueResultException) {
      return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1);
    }
    if (ex instanceof OptimisticLockException) {
      return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);
    }
    if (ex instanceof EntityExistsException) {
      return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof TransactionRequiredException) {
      return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }

    // If we have another kind of PersistenceException, throw it.
    if (ex instanceof PersistenceException) {
      return new JpaSystemException((PersistenceException) ex);
View Full Code Here

   * been correctly initialized, for example if no DataSource has been provided
   */
  public final void compile() throws InvalidDataAccessApiUsageException {
    if (!isCompiled()) {
      if (getTableName() == null) {
        throw new InvalidDataAccessApiUsageException("Table name is required");
      }

      try {
        this.jdbcTemplate.afterPropertiesSet();
      }
      catch (IllegalArgumentException ex) {
        throw new InvalidDataAccessApiUsageException(ex.getMessage());
      }

      compileInternal();
      this.compiled = true;

View Full Code Here

   * Method to check whether we are allowd to make any configuration changes at this time.  If the class has been
   * compiled, then no further changes to the configuration are allowed.
   */
  protected void checkIfConfigurationModificationIsAllowed() {
    if (isCompiled()) {
      throw new InvalidDataAccessApiUsageException("Configuration can't be altered once the class has been compiled or used.");
    }
  }
View Full Code Here

      if (!this.tableMetaDataContext.isGetGeneratedKeysSimulated()) {
        throw new InvalidDataAccessResourceUsageException(
            "The getGeneratedKeys feature is not supported by this database");
      }
      if (getGeneratedKeyNames().length < 1) {
        throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specificed. " +
            "Using the generated keys features requires specifying the name(s) of the generated column(s)");
      }
      if (getGeneratedKeyNames().length > 1) {
        throw new InvalidDataAccessApiUsageException(
            "Current database only supports retreiving the key for a single column. There are " +
            getGeneratedKeyNames().length  + " columns specified: " + Arrays.asList(getGeneratedKeyNames()));
      }
      // This is a hack to be able to get the generated key from a database that doesn't support
      // get generated keys feature.  HSQL is one, PostgreSQL is another.  Has to be done with the same
View Full Code Here

   * @return PreparedStatement to use
   * @throws SQLException
   */
  private PreparedStatement prepareStatementForGeneratedKeys(Connection con) throws SQLException {
    if (getGeneratedKeyNames().length < 1) {
      throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specificed. " +
          "Using the generated keys features requires specifying the name(s) of the generated column(s)");
    }
    PreparedStatement ps;
    if (this.tableMetaDataContext.isGeneratedKeysColumnNameArraySupported()) {
      if (logger.isDebugEnabled()) {
View Full Code Here

  }

  public List executeFind(HibernateCallback action) throws DataAccessException {
    Object result = execute(action, isExposeNativeSession());
    if (result != null && !(result instanceof List)) {
      throw new InvalidDataAccessApiUsageException(
          "Result object returned from HibernateCallback isn't a List: [" + result + "]");
    }
    return (List) result;
  }
View Full Code Here

   * @see org.hibernate.FlushMode#MANUAL
   */
  protected void checkWriteOperationAllowed(Session session) throws InvalidDataAccessApiUsageException {
    if (isCheckWriteOperations() && getFlushMode() != FLUSH_EAGER &&
        session.getFlushMode().lessThan(FlushMode.COMMIT)) {
      throw new InvalidDataAccessApiUsageException(
          "Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): "+
          "Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.");
    }
  }
View Full Code Here

    }
    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 QueryException) {
      return new HibernateQueryException((QueryException) ex);
    }
    if (ex instanceof UnresolvableObjectException) {
View Full Code Here

TOP

Related Classes of org.springframework.dao.InvalidDataAccessApiUsageException

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.