Search in sources :

Example 21 with DataAccessResourceFailureException

use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.

the class PropertiesGraphDao method loadPrefabGraphDefinitions.

/**
     * @param type
     *            - a PrefabGraphType in which graphs
     *            found in 'properties' will be stored
     * @param properties
     *            - a properties object, usually loaded from a File or
     *            InputStream, with graph definitions in it
     * @return A list of the graphs found.  THIS LIST MAY CONTAIN NULL ENTRIES, one for each
     * graph in a multi-graph file that failed to load (e.g. missing properties).  Other than
     * logging an error, this is the only way this method indicates a problem with just one graph
     * The only cause for a real exception is if there's neither a "reports" nor a "report.id" 
     * property, which cannot be recovered from   
     */
private List<PrefabGraph> loadPrefabGraphDefinitions(PrefabGraphTypeDao type, Properties properties) {
    Assert.notNull(properties, "properties argument cannot be null");
    List<PrefabGraph> result = new ArrayList<PrefabGraph>();
    // Optional
    String listString = properties.getProperty(DEFAULT_GRAPH_LIST_KEY);
    String[] list;
    if (listString != null) {
        list = BundleLists.parseBundleList(listString);
    } else {
        // A report-per-file properties file; just use the report.id
        // At this stage, if there was no "reports", then there *must* be
        // a report.id, otherwise we're pooched
        list = new String[1];
        try {
            list[0] = getProperty(properties, "report.id");
        } catch (DataAccessResourceFailureException e) {
            // graphs if just one file was broken
            throw new DataAccessResourceFailureException("Properties must " + "contain a 'report.id' property " + "or a 'reports' property");
        }
    }
    for (String name : list) {
        try {
            PrefabGraph graph = makePrefabGraph(name, properties, type.getNextOrdering());
            result.add(graph);
        } catch (DataAccessResourceFailureException e) {
            LOG.error("Failed to load report '{}'", name, e);
            //Add a null, indicating a broken graph
            result.add(null);
        }
    }
    return result;
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) ArrayList(java.util.ArrayList)

Example 22 with DataAccessResourceFailureException

use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.

the class PropertiesGraphDao method loadIncludedFile.

private void loadIncludedFile(PrefabGraphTypeDao type, File file) throws FileNotFoundException, IOException {
    Properties props = new Properties();
    InputStream fileIn = new FileInputStream(file);
    try {
        props.load(fileIn);
    } finally {
        IOUtils.closeQuietly(fileIn);
    }
    //Clear any malformed setting; if everything goes ok, it'll remain cleared
    // If there's problems, it'll be re-added.
    type.removeMalformedFile(file);
    try {
        List<PrefabGraph> subGraphs = loadPrefabGraphDefinitions(type, props);
        for (PrefabGraph graph : subGraphs) {
            if (graph == null) {
                //Indicates a multi-graph file that had a munted graph definition
                //Record that the file was partly broken
                type.addMalformedFile(file);
            } else {
                type.addPrefabGraph(new FileReloadContainer<PrefabGraph>(graph, new FileSystemResource(file), type.getCallback()));
            }
        }
    } catch (DataAccessResourceFailureException e) {
        LOG.error("Problem while attempting to load {}", file, e);
        //Record that the file was completely broken
        type.addMalformedFile(file);
    }
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileSystemResource(org.springframework.core.io.FileSystemResource) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 23 with DataAccessResourceFailureException

use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.

the class DefaultRrdDao method getLastFetchValue.

/** {@inheritDoc} */
@Override
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);
    }
}
Also used : DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) File(java.io.File) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute)

Example 24 with DataAccessResourceFailureException

use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.

the class DefaultRequisitionAccessService method importRequisition.

@Override
public void importRequisition(final String foreignSource, final String rescanExisting) {
    final URL activeUrl = createSnapshot(foreignSource);
    final String url = activeUrl.toString();
    LOG.debug("importRequisition: Sending import event with URL {}", url);
    final EventBuilder bldr = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
    bldr.addParam(EventConstants.PARM_URL, url);
    if (rescanExisting != null) {
        bldr.addParam(EventConstants.PARM_IMPORT_RESCAN_EXISTING, rescanExisting);
    }
    try {
        getEventProxy().send(bldr.getEvent());
    } catch (final EventProxyException e) {
        throw new DataAccessResourceFailureException("Unable to send event to import group " + foreignSource, e);
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) URL(java.net.URL)

Example 25 with DataAccessResourceFailureException

use of org.springframework.dao.DataAccessResourceFailureException in project uPortal by Jasig.

the class RDBMServices method getConnection.

/**
     * Returns a connection produced by a DataSource found in the JNDI context. The DataSource
     * should be configured and loaded into JNDI by the J2EE container or may be the portal default
     * database.
     *
     * @param dbName the database name which will be retrieved from the JNDI context relative to
     *     "jdbc/"
     * @return a database Connection object or <code>null</code> if no Connection
     * @deprecated Where possible code should be injected with a {@link DataSource} object via the
     *     Spring application context
     */
@Deprecated
public static Connection getConnection(String dbName) {
    final DataSource dataSource = getDataSource(dbName);
    try {
        final long start = System.currentTimeMillis();
        final Connection c = dataSource.getConnection();
        // metric
        lastDatabase = databaseTimes.add(System.currentTimeMillis() - start);
        final int current = activeConnections.incrementAndGet();
        if (current > maxConnections) {
            maxConnections = current;
        }
        return c;
    } catch (SQLException e) {
        throw new DataAccessResourceFailureException("RDBMServices sql error trying to get connection to " + dbName, e);
    }
}
Also used : SQLException(java.sql.SQLException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) Connection(java.sql.Connection) DataSource(javax.sql.DataSource)

Aggregations

DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)36 SQLException (java.sql.SQLException)10 Connection (java.sql.Connection)6 IOException (java.io.IOException)5 HibernateException (org.hibernate.HibernateException)4 Session (org.hibernate.Session)4 File (java.io.File)3 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 Test (org.junit.Test)3 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)3 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)3 FileOutputStream (java.io.FileOutputStream)2 Clob (java.sql.Clob)2 DatabaseMetaData (java.sql.DatabaseMetaData)2 Date (java.util.Date)2 EntityManager (javax.persistence.EntityManager)2 PersistenceException (javax.persistence.PersistenceException)2 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)2 DatabaseMetaDataCallback (org.springframework.jdbc.support.DatabaseMetaDataCallback)2