Example usage for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException

List of usage examples for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException.

Prototype

public DataAccessResourceFailureException(String msg, @Nullable Throwable cause) 

Source Link

Document

Constructor for DataAccessResourceFailureException.

Usage

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 .  java  2s.  c o 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:org.opennms.ng.services.databaseschemaconfig.FilterDaoFactory.java

/**
 * <p>init</p>//  w w w .j  a  va2s  .c  om
 */
protected static synchronized void init() {
    if (m_filterDao != null) {
        return;
    }

    JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();

    try {
        DataSourceFactory.init();
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Could not initialize DataSourceFactory: " + e, e);
    }
    jdbcFilterDao.setDataSource(DataSourceFactory.getInstance());

    try {
        DatabaseSchemaConfigFactory.init();
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Could not initialize DatabaseSchemaConfigFactory: " + e,
                e);
    }
    jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());

    jdbcFilterDao.afterPropertiesSet();

    setInstance(jdbcFilterDao);
}

From source file:org.grails.datastore.mapping.cassandra.util.HectorTemplate.java

public Object execute(String keyspace, HectorCallback callable) throws DataAccessException {
    final Keyspace ks;
    try {/*from   w ww .j av a2 s.  c o m*/
        ks = cassandraClient.getKeyspace(keyspace);
    } catch (HectorException e) {
        throw new DataAccessResourceFailureException("Exception occurred invoking Cassandra: " + e.getMessage(),
                e);
    }

    try {
        return callable.doInHector(ks);
    } catch (HectorException e) {
        throw new DataAccessResourceFailureException("Exception occurred invoking Cassandra: " + e.getMessage(),
                e);
    }
}

From source file:org.grails.datastore.mapping.cassandra.CassandraDatastore.java

@Override
protected Session createSession(@SuppressWarnings("hiding") Map<String, String> connectionDetails) {
    final CassandraClient client;
    try {/*from  w  w  w.j  a  va2 s.  c  om*/
        client = connectionPool.borrowClient("localhost", 9160);
        return new CassandraSession(this, getMappingContext(), connectionPool, client);
    } catch (Exception e) {
        throw new DataAccessResourceFailureException(
                "Failed to obtain Cassandra client session: " + e.getMessage(), e);
    }
}

From source file:org.grails.datastore.mapping.core.DatastoreUtils.java

/**
 * Get a Datastore Session for the given Datastore. Is aware of and will
 * return any existing corresponding Session bound to the current thread, for
 * example when using {@link org.grails.datastore.mapping.transactions.DatastoreTransactionManager}. Will create a new
 * Session otherwise, if "allowCreate" is <code>true</code>.
 * <p>This is the <code>getSession</code> method used by typical data access code,
 * in combination with <code>releaseSession</code> called when done with
 * the Session./*from w  w w . j a  v a2s .c om*/
 *
 * @param datastore Datastore to create the session with
 * @param allowCreate whether a non-transactional Session should be created
 * when no transactional Session can be found for the current thread
 * @return the Datastore Session
 * @throws org.springframework.dao.DataAccessResourceFailureException if the Session couldn't be created
 * @throws IllegalStateException if no thread-bound Session found and
 * "allowCreate" is <code>false</code>
 */
public static Session getSession(Datastore datastore, boolean allowCreate)
        throws DataAccessResourceFailureException, IllegalStateException {

    try {
        return doGetSession(datastore, allowCreate);
    } catch (Exception ex) {
        throw new DataAccessResourceFailureException("Could not open Datastore Session", ex);
    }
}

From source file:org.grails.datastore.mapping.cassandra.CassandraSession.java

@Override
public void disconnect() {
    try {//from   w  w w . j a  v a  2s .  co m
        connectionPool.releaseClient(cassandraClient);
    } catch (Exception e) {
        throw new DataAccessResourceFailureException(
                "Failed to release Cassandra client session: " + e.getMessage(), e);
    } finally {
        super.disconnect();
    }
}

From source file:com._4dconcept.springframework.data.marklogic.core.MarklogicExceptionTranslator.java

@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {

    // Check for well-known MarklogicException subclasses.

    String exception = ClassUtils.getShortName(ClassUtils.getUserClass(ex.getClass()));

    if (RESOURCE_FAILURE_EXCEPTIONS.contains(exception)) {
        return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }/*  ww w .ja v  a 2 s  .  c o m*/

    if (RESOURCE_USAGE_EXCEPTIONS.contains(exception)) {
        return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
    }

    if (DATA_INTEGRETY_EXCEPTIONS.contains(exception)) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }

    return null;
}

From source file:com.couchbase.spring.core.CouchbaseExceptionTranslator.java

/**
 * Translate Couchbase specific exceptions to spring exceptions if possible.
 *
 * @param ex the exception to translate.
 * @return the translated exception or null.
 *//*from www . ja v a2s . c om*/
@Override
public final DataAccessException translateExceptionIfPossible(RuntimeException ex) {
    if (ex instanceof ConnectionException) {
        return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }

    if (ex instanceof ObservedException || ex instanceof ObservedTimeoutException
            || ex instanceof ObservedModifiedException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }

    return null;
}

From source file:at.ac.univie.isc.asio.database.MysqlSchemaService.java

@Override
public SqlSchema explore(final Id target) throws Id.NotFound {
    final SqlSchemaBuilder builder = SqlSchemaBuilder.create().noCatalog();
    try (final Connection connection = pool.getConnection()) {
        final DSLContext jooq = DSL.using(connection, SQLDialect.MYSQL);
        final org.jooq.Schema schema = findActiveSchema(jooq, target);
        builder.switchSchema(schema);//  ww w .ja v  a2  s  .  c  o m
        for (final org.jooq.Table<?> sqlTable : schema.getTables()) {
            builder.add(sqlTable);
        }
    } catch (final SQLException e) {
        throw new DataAccessResourceFailureException(e.getMessage(), e);
    }
    return builder.build();
}

From source file:cz.jirutka.spring.data.jdbc.sql.SqlGeneratorFactory.java

/**
 * @param dataSource The DataSource for which to find compatible
 *        SQL Generator.//ww w. j av a  2 s  . co  m
 * @return An SQL Generator compatible with the given {@code dataSource}.
 * @throws DataAccessResourceFailureException if exception is thrown when
 *         trying to obtain Connection or MetaData from the
 *         {@code dataSource}.
 * @throws IllegalStateException if no compatible SQL Generator is found.
 */
public SqlGenerator getGenerator(DataSource dataSource) {

    if (cache.containsKey(dataSource)) {
        return cache.get(dataSource);
    }

    DatabaseMetaData metaData;
    try {
        metaData = dataSource.getConnection().getMetaData();
    } catch (SQLException ex) {
        throw new DataAccessResourceFailureException("Failed to retrieve database metadata", ex);
    }

    for (SqlGenerator generator : generators) {
        try {
            if (generator.isCompatible(metaData)) {
                LOG.info("Using SQL Generator {} for dataSource {}", generator.getClass().getName(),
                        dataSource.getClass());

                cache.put(dataSource, generator);
                return generator;
            }
        } catch (SQLException ex) {
            LOG.warn("Exception occurred when invoking isCompatible() on {}",
                    generator.getClass().getSimpleName(), ex);
        }
    }

    // This should not happen, because registry should always contain one
    // "default" generator that returns true for every DatabaseMetaData.
    throw new IllegalStateException("No compatible SQL Generator found.");
}