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.grails.datastore.mapping.redis.util.JedisTemplate.java

protected Jedis getNewConnection() {
    Jedis jedis;/*from w w w  .  j  a va 2s  .c o  m*/
    if (pool == null) {
        jedis = new Jedis(host, port, timeout);
    } else {
        try {
            jedis = pool.getResource();
        } catch (JedisConnectionException e) {
            throw new DataAccessResourceFailureException(
                    "Connection timeout getting Jedis connection from pool: " + e.getMessage(), e);
        }
    }
    return jedis;
}

From source file:org.opennms.ng.dao.support.ResourceTypeUtils.java

/**
 * <p>getStringProperty</p>//from w  w w .  j a v  a  2s  .c  om
 *
 * @param directory a {@link java.io.File} object.
 * @param key a {@link String} object.
 * @return a {@link String} object.
 */
public static String getStringProperty(File directory, String key) {
    File file = new File(directory, DefaultResourceDao.STRINGS_PROPERTIES_FILE_NAME);
    try {
        return s_cache.getProperty(file, key);
    } catch (IOException e) {
        String message = "loadProperties: Error opening properties file " + file.getAbsolutePath() + ": " + e;
        LOG.warn(message, e);
        throw new DataAccessResourceFailureException(message, e);
    }
}

From source file:org.grails.orm.hibernate.GrailsSessionContext.java

protected void registerJtaSynchronization(Session session, SessionHolder sessionHolder) {

    // JTA synchronization is only possible with a javax.transaction.TransactionManager.
    // We'll check the Hibernate SessionFactory: If a TransactionManagerLookup is specified
    // in Hibernate configuration, it will contain a TransactionManager reference.
    TransactionManager jtaTm = getJtaTransactionManager(session);
    if (jtaTm == null) {
        return;//  www .  j  a  v  a  2 s  .  c  o m
    }

    try {
        Transaction jtaTx = jtaTm.getTransaction();
        if (jtaTx == null) {
            return;
        }

        int jtaStatus = jtaTx.getStatus();
        if (jtaStatus != Status.STATUS_ACTIVE && jtaStatus != Status.STATUS_MARKED_ROLLBACK) {
            return;
        }

        LOG.debug("Registering JTA transaction synchronization for new Hibernate Session");
        SessionHolder holderToUse = sessionHolder;
        // Register JTA Transaction with existing SessionHolder.
        // Create a new SessionHolder if none existed before.
        if (holderToUse == null) {
            holderToUse = new SessionHolder(session);
        } else {
            // it's up to the caller to manage concurrent sessions
            // holderToUse.addSession(session);
        }
        jtaTx.registerSynchronization(
                new SpringJtaSynchronizationAdapter(createSpringSessionSynchronization(holderToUse), jtaTm));
        holderToUse.setSynchronizedWithTransaction(true);
        if (holderToUse != sessionHolder) {
            TransactionSynchronizationManager.bindResource(sessionFactory, holderToUse);
        }
    } catch (Throwable ex) {
        throw new DataAccessResourceFailureException(
                "Could not register synchronization with JTA TransactionManager", ex);
    }
}

From source file:org.dkpro.lab.engine.impl.DefaultTaskContext.java

@Override
public File getFolder(String aKey, AccessMode aMode) {
    StorageKey key;// w w  w  . j  av  a 2  s  .  c  o m

    StorageService storage = getStorageService();
    Map<String, String> imports = getMetadata().getImports();

    if (storage.containsKey(getId(), aKey)) {
        // If the context contains the key, we do nothing. Locally available data always
        // supersedes imported data.
        key = new StorageKey(getId(), aKey);
    } else if (imports.containsKey(aKey)) {
        URI uri;
        try {
            uri = new URI(imports.get(aKey));
        } catch (URISyntaxException e) {
            throw new DataAccessResourceFailureException(
                    "Imported key [" + aKey + "] resolves to illegal URL [" + imports.get(aKey) + "]", e);
        }

        if ("file".equals(uri.getScheme()) && new File(uri).isDirectory()) {
            if (aMode == AccessMode.READONLY) {
                return new File(uri);
            } else {
                // Here we should probably just copy the imported folder into the context
                throw new DataAccessResourceFailureException(
                        "READWRITE access of imported " + "folders is not implemented yet.");
            }
        } else {
            key = resolve(aKey, aMode, true);
        }
    } else {
        key = resolve(aKey, aMode, true);
    }

    File folder = getStorageService().locateKey(key.contextId, key.key);

    if (!folder.exists()) {
        folder.mkdirs();
    }

    if (!folder.isDirectory()) {
        throw new DataAccessResourceFailureException(
                "Key [" + aKey + "] resolves to [" + folder + "] which is not a folder.");
    }

    return folder;
}

From source file:org.yestech.lib.hibernate.search.YesHibernateSearchTemplate.java

/**
 * Return a Session for use by this template.
 * <p>Returns a new Session in case of "alwaysUseNewSession" (using the same
 * JDBC Connection as a transactional Session, if applicable), a pre-bound
 * Session in case of "allowCreate" turned off, and a pre-bound or new Session
 * otherwise (new only if no transactional or otherwise pre-bound Session exists).
 *
 * @return the Session to use (never <code>null</code>)
 * @see SessionFactoryUtils#getSession//from  ww  w  .  j a  v  a  2 s .  co  m
 * @see SessionFactoryUtils#getNewSession
 * @see #setAlwaysUseNewSession
 */
protected Session getSession() {
    if (isAlwaysUseNewSession()) {
        return SessionFactoryUtils.getNewSession(getSessionFactory(), getEntityInterceptor());
    } else if (SessionFactoryUtils.hasTransactionalSession(getSessionFactory())) {
        return SessionFactoryUtils.getSession(getSessionFactory(), false);
    } else {
        try {
            return getSessionFactory().getCurrentSession();
        } catch (HibernateException ex) {
            throw new DataAccessResourceFailureException("Could not obtain current Hibernate Session", ex);
        }
    }
}

From source file:org.opennms.ng.dao.support.DefaultRrdDao.java

/** {@inheritDoc} */
@Override/*from   w w w  .  j  ava 2  s .  c  o  m*/
public Double getLastFetchValue(OnmsAttribute attribute, int interval)
        throws DataAccessResourceFailureException {
    Assert.notNull(attribute, "attribute argument must not be null");
    Assert.isTrue(interval > 0, "interval argument must be greater than zero");
    Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class,
            "attribute argument must be assignable to RrdGraphAttribute");

    RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute;

    File rrdFile = new File(m_rrdBaseDirectory, rrdAttribute.getRrdRelativePath());
    try {
        return m_rrdStrategy.fetchLastValue(rrdFile.getAbsolutePath(), attribute.getName(), interval);
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException(
                "Failure to fetch last value from file '" + rrdFile + "' with interval " + interval, e);
    }
}

From source file:org.opennms.ng.dao.support.DefaultRrdDao.java

/** {@inheritDoc} */
@Override/*from www . j  a  va 2  s .  c om*/
public Double getLastFetchValue(OnmsAttribute attribute, int interval, int range)
        throws DataAccessResourceFailureException {
    Assert.notNull(attribute, "attribute argument must not be null");
    Assert.isTrue(interval > 0, "interval argument must be greater than zero");
    Assert.isTrue(range > 0, "range argument must be greater than zero");
    Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class,
            "attribute argument must be assignable to RrdGraphAttribute");

    RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute;

    File rrdFile = new File(m_rrdBaseDirectory, rrdAttribute.getRrdRelativePath());
    try {
        return m_rrdStrategy.fetchLastValueInRange(rrdFile.getAbsolutePath(), attribute.getName(), interval,
                range);
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Failure to fetch last value from file '" + rrdFile
                + "' with interval " + interval + " and range " + range, e);
    }
}

From source file:org.codehaus.grepo.query.hibernate.repository.DefaultHibernateRepository.java

/**
 * @return Returns the current sesssion holder.
 *//*from   w  w w. jav  a  2 s.  c o  m*/
protected CurrentSessionHolder getCurrentSession() {
    Session session = null;
    if (isAlwaysUseNewSession()) {
        session = SessionFactoryUtils.getNewSession(getSessionFactory(), getEntityInterceptor());
    } else if (isAllowCreate()) {
        session = SessionFactoryUtils.getSession(getSessionFactory(), getEntityInterceptor(),
                getJdbcExceptionTranslator());
    } else if (SessionFactoryUtils.hasTransactionalSession(getSessionFactory())) {
        session = SessionFactoryUtils.getSession(getSessionFactory(), false);
    } else {
        try {
            session = getSessionFactory().getCurrentSession();
        } catch (HibernateException ex) {
            throw new DataAccessResourceFailureException("Could not obtain current Hibernate Session", ex);
        }
    }

    boolean existingTransaction = (!isAlwaysUseNewSession()
            && (!isAllowCreate() || SessionFactoryUtils.isSessionTransactional(session, getSessionFactory())));

    if (!existingTransaction) {
        logger.debug("No existing transactional Hibernate Session for generic repository execution found");
    }

    return new CurrentSessionHolder(session, existingTransaction);
}

From source file:org.dkpro.lab.storage.filesystem.FileSystemStorageService.java

@Override
public void copy(String aContextId, String aKey, StorageKey aResolvedKey, AccessMode aMode) {
    StorageKey key = aResolvedKey;/*from w  w  w .  j  av  a  2  s .  c o  m*/
    // If the resource is imported from another context and will be modified and it is a
    // folder, we have to copy it to the current context now, since we cannot do a
    // copy-on-write strategy as for streams.
    if (isStorageFolder(key.contextId, key.key)
            && (aMode == AccessMode.READWRITE || aMode == AccessMode.ADD_ONLY)) {
        try {
            File source = new File(getContextFolder(key.contextId, false), key.key);
            File target = new File(getContextFolder(aContextId, false), aKey);

            if (Util.isSymlinkSupported() && aMode == AccessMode.ADD_ONLY) {
                log.info("Write access to imported storage folder [" + aKey
                        + "]was requested. Linking to current context");
                Util.copy(source, target, true);
            } else {
                log.info("Write access to imported storage folder [" + aKey
                        + "]was requested. Copying to current context");
                Util.copy(source, target, false);
            }
        } catch (IOException e) {
            throw new DataAccessResourceFailureException(e.getMessage(), e);
        }

        // Key should point to the local context now
        key = new StorageKey(aContextId, aKey);
    }
}

From source file:org.guzz.web.context.spring.TransactionManagerUtils.java

/**
 * Apply the current transaction timeout, if any, to the given
 * Guzz Query object.//  w  w w .j  a v a  2  s .c o  m
 * @param query the Guzz Query object
 * @param transactionManager Guzz TransactionManager that the Query was created for
 * (may be <code>null</code>)
 * @see org.hibernate.Query#setTimeout
 */
public static void applyTransactionTimeout(PreparedStatement pstm, TransactionManager transactionManager) {
    Assert.notNull(pstm, "No PreparedStatement object specified");
    if (transactionManager != null) {
        WriteTranSessionHolder writeTranSessionHolder = (WriteTranSessionHolder) TransactionSynchronizationManager
                .getResource(transactionManager);

        if (writeTranSessionHolder != null && writeTranSessionHolder.hasTimeout()) {
            try {
                pstm.setQueryTimeout(writeTranSessionHolder.getTimeToLiveInSeconds());
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException(e.getMessage(), e);
            }
        }
    }
}