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.opennms.netmgt.config.DefaultEventConfDao.java

private Resource getProgrammaticStoreConfigResource() {
    if (m_programmaticStoreConfigResource == null) {
        try {/*  w  w  w  .  j a va2 s.c o m*/
            m_programmaticStoreConfigResource = getConfigResource()
                    .createRelative(getProgrammaticStoreRelativeUrl());
        } catch (IOException e) {
            log().warn(
                    "Could not get a relative resource for the programmatic store configuration file using relative URL '"
                            + getProgrammaticStoreRelativeUrl() + "': " + e,
                    e);
            throw new DataAccessResourceFailureException(
                    "Could not get a relative resource for the programmatic store configuration file using relative URL '"
                            + getProgrammaticStoreRelativeUrl() + "': " + e,
                    e);
        }
    }

    return m_programmaticStoreConfigResource;
}

From source file:org.opennms.netmgt.provision.adapters.link.config.dao.DefaultLinkAdapterConfigurationDao.java

/**
 * <p>saveCurrent</p>/*from  w w  w . j a va  2  s.  c  o m*/
 */
@Override
public synchronized void saveCurrent() {
    File file;
    try {
        file = getConfigResource().getFile();
    } catch (IOException e) {
        throw new DataAccessResourceFailureException(
                "Unable to determine file for " + getConfigResource() + ": " + e, e);
    }
    if (file == null) {
        throw new DataAccessResourceFailureException("Unable to determine file for " + getConfigResource());
    }

    final StringWriter stringWriter = new StringWriter();
    JaxbUtils.marshal(getContainer().getObject(), stringWriter);

    if (stringWriter.toString() != null) {
        OutputStream os = null;
        Writer fileWriter = null;
        try {
            os = new FileOutputStream(file);
            fileWriter = new OutputStreamWriter(os, "UTF-8");
            fileWriter.write(stringWriter.toString());
        } catch (final IOException e) {
            throw new DataAccessResourceFailureException(
                    "Could not write resource " + getConfigResource() + " to file " + file.getPath() + ": " + e,
                    e);
        } finally {
            IOUtils.closeQuietly(fileWriter);
            IOUtils.closeQuietly(os);
        }
    }
}

From source file:org.opennms.web.svclayer.support.DefaultManualProvisioningService.java

/** {@inheritDoc} */
@Override// w ww .  ja  v  a2 s  . co m
public void importProvisioningGroup(final String requisitionName) {
    m_writeLock.lock();

    try {
        final Requisition requisition = getProvisioningGroup(requisitionName);
        saveProvisioningGroup(requisitionName, requisition);

        // then we send an event to the importer
        final EventProxy proxy = Util.createEventProxy();

        m_pendingForeignSourceRepository.flush();
        final String url = m_pendingForeignSourceRepository.getRequisitionURL(requisitionName).toString();
        Assert.notNull(url, "Could not find url for group " + requisitionName + ".  Does it exists?");

        final EventBuilder bldr = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
        bldr.addParam(EventConstants.PARM_URL, url);

        try {
            proxy.send(bldr.getEvent());
        } catch (final EventProxyException e) {
            throw new DataAccessResourceFailureException(
                    "Unable to send event to import group " + requisitionName, e);
        }
    } finally {
        m_writeLock.unlock();
    }
}

From source file:org.openspaces.core.map.LockManager.java

/**
 * Locks the given key for any updates. Retruns a {@link org.openspaces.core.map.LockHandle}
 * that can be used to perform specific updates under the same lock (by using the transaction
 * object stored within it).// w  w w  .j  ava 2 s . c om
 *
 * <p>Might create an empty value if there is no value in order to lock on. The empty value can
 * be checked using {@link #isEmptyLockValue(Object)}.
 *
 * @param key                   The key to lock
 * @param lockTimeToLive        The lock time to live (in milliseconds)
 * @param timeoutWaitingForLock The time to wait for an already locked lock
 * @return LockHandle that can be used to perfrom operations under the given lock
 */
public LockHandle lock(Object key, long lockTimeToLive, long timeoutWaitingForLock) {

    String uid = String.valueOf(key);
    Transaction tr = null;
    try {
        tr = getTransaction(lockTimeToLive);
    } finally {
        if (tr == null) {
            lockedUIDHashMap.remove(uid);
            return null;
        }
    }

    SpaceMapEntry ee = getTemplate(key);
    try {
        Object retTake = masterSpace.readIfExists(ee, tr, timeoutWaitingForLock,
                ReadModifiers.EXCLUSIVE_READ_LOCK);
        if (retTake == null) {
            // TODO GS-9310: design and implement a solution for locking non-existent keys.
            map.put(key, EMPTY_LOCK_VALUE, tr, Integer.MAX_VALUE);
        }
    } catch (SpaceTimeoutException e) {
        try {
            tr.abort();
        } catch (Exception re) {
            logger.warn("Failed to abort transaction", e);
        }
        // rethrow
        throw e;
    } catch (Throwable t) {
        try {
            tr.abort();
        } catch (Exception re) {
            logger.warn("Failed to abort transaction", t);
        }
        lockedUIDHashMap.remove(uid);
        throw new DataAccessResourceFailureException("Failed to obtain lock for key [" + key + "]", t);
    } finally {
        releaseTemplate(ee);
    }

    //otherwise, map uid->txn
    lockedUIDHashMap.put(uid, tr);
    return new LockHandle(this, tr, key);
}

From source file:org.openspaces.core.map.LockManager.java

private SpaceMapEntry getTemplate(Object key) {
    SpaceMapEntry ee;/*from www. j a  v  a2 s . co m*/
    try {
        ee = templatePool.poll(100, TimeUnit.MILLISECONDS);
        if (ee == null) {
            ee = MapEntryFactory.create();
        }
    } catch (InterruptedException e) {
        throw new DataAccessResourceFailureException("Failed to take resource from pool", e);
    }
    ee.setKey(key);
    // to support load balancing
    return ee;
}

From source file:org.springframework.batch.item.xml.StaxEventItemWriter.java

/**
 * Helper method for opening output source at given file position
 *///from   w w  w.  j  a  va 2s  . com
private void open(long position) {

    File file;
    FileOutputStream os = null;
    FileChannel fileChannel = null;

    try {
        file = resource.getFile();
        FileUtils.setUpOutputFile(file, restarted, false, overwriteOutput);
        Assert.state(resource.exists(), "Output resource must exist");
        os = new FileOutputStream(file, true);
        fileChannel = os.getChannel();
        channel = os.getChannel();
        setPosition(position);
    } catch (IOException ioe) {
        throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]",
                ioe);
    }

    XMLOutputFactory outputFactory = createXmlOutputFactory();

    if (outputFactory.isPropertySupported("com.ctc.wstx.automaticEndElements")) {
        // If the current XMLOutputFactory implementation is supplied by
        // Woodstox >= 3.2.9 we want to disable its
        // automatic end element feature (see:
        // http://jira.codehaus.org/browse/WSTX-165) per
        // http://jira.spring.io/browse/BATCH-761).
        outputFactory.setProperty("com.ctc.wstx.automaticEndElements", Boolean.FALSE);
    }
    if (outputFactory.isPropertySupported("com.ctc.wstx.outputValidateStructure")) {
        // On restart we don't write the root element so we have to disable
        // structural validation (see:
        // http://jira.spring.io/browse/BATCH-1681).
        outputFactory.setProperty("com.ctc.wstx.outputValidateStructure", Boolean.FALSE);
    }

    try {
        final FileChannel channel = fileChannel;
        if (transactional) {
            TransactionAwareBufferedWriter writer = new TransactionAwareBufferedWriter(channel, new Runnable() {
                @Override
                public void run() {
                    closeStream();
                }
            });

            writer.setEncoding(encoding);
            writer.setForceSync(forceSync);
            bufferedWriter = writer;
        } else {
            bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, encoding));
        }
        delegateEventWriter = createXmlEventWriter(outputFactory, bufferedWriter);
        eventWriter = new NoStartEndDocumentStreamWriter(delegateEventWriter);
        initNamespaceContext(delegateEventWriter);
        if (!restarted) {
            startDocument(delegateEventWriter);
            if (forceSync) {
                channel.force(false);
            }
        }
    } catch (XMLStreamException xse) {
        throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]",
                xse);
    } catch (UnsupportedEncodingException e) {
        throw new DataAccessResourceFailureException(
                "Unable to write to file resource: [" + resource + "] with encoding=[" + encoding + "]", e);
    } catch (IOException e) {
        throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e);
    }
}

From source file:org.springframework.batch.item.xml.StaxEventItemWriter.java

/**
 * Writes the EndDocument tag manually./*from   w  w w.  j  a  va2s  .  co m*/
 * 
 * @param writer XML event writer
 * @throws XMLStreamException
 */
protected void endDocument(XMLEventWriter writer) throws XMLStreamException {

    // writer.writeEndDocument(); <- this doesn't work after restart
    // we need to write end tag of the root element manually

    String nsPrefix = !StringUtils.hasText(getRootTagNamespacePrefix()) ? ""
            : getRootTagNamespacePrefix() + ":";
    try {
        bufferedWriter.write("</" + nsPrefix + getRootTagName() + ">");
    } catch (IOException ioe) {
        throw new DataAccessResourceFailureException("Unable to close file resource: [" + resource + "]", ioe);
    }
}

From source file:org.springframework.batch.item.xml.StaxEventItemWriter.java

private long getPosition() {

    long position;

    try {//from w w  w .j a  v  a  2s.  co  m
        eventWriter.flush();
        position = channel.position();
        if (bufferedWriter instanceof TransactionAwareBufferedWriter) {
            position += ((TransactionAwareBufferedWriter) bufferedWriter).getBufferSize();
        }
    } catch (Exception e) {
        throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e);
    }

    return position;
}

From source file:org.springframework.batch.item.xml.StaxEventItemWriter.java

/**
 * Set the file channel position./*www .  j  a  va  2  s .  c o m*/
 * 
 * @param newPosition new file channel position
 */
private void setPosition(long newPosition) {

    try {
        channel.truncate(newPosition);
        channel.position(newPosition);
    } catch (IOException e) {
        throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e);
    }

}

From source file:org.springframework.boot.autoconfigure.jdbc.BasicDataSourceConfiguration.java

@PreDestroy
public void close() {
    if (this.pool != null) {
        try {//from w  w  w .  j  a  v a2  s  .c  o  m
            this.pool.close();
        } catch (SQLException ex) {
            throw new DataAccessResourceFailureException("Could not close data source", ex);
        }
    }
}