Search in sources :

Example 41 with DataAccessResourceFailureException

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

the class DefaultRrdDao method getPrintValues.

/**
 * <p>getPrintValues</p>
 *
 * @param attribute a {@link org.opennms.netmgt.model.OnmsAttribute} object.
 * @param rraConsolidationFunction a {@link java.lang.String} object.
 * @param startTimeInMillis a long.
 * @param endTimeInMillis a long.
 * @param printFunctions a {@link java.lang.String} object.
 * @return an array of double.
 */
@Override
public double[] getPrintValues(OnmsAttribute attribute, String rraConsolidationFunction, long startTimeInMillis, long endTimeInMillis, String... printFunctions) {
    Assert.notNull(attribute, "attribute argument must not be null");
    Assert.notNull(rraConsolidationFunction, "rraConsolicationFunction argument must not be null");
    Assert.isTrue(endTimeInMillis > startTimeInMillis, "end argument must be after start argument");
    Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class, "attribute argument must be assignable to RrdGraphAttribute");
    // if no printFunctions are given just use the rraConsolidationFunction
    if (printFunctions.length < 1) {
        printFunctions = new String[] { rraConsolidationFunction };
    }
    RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute;
    String[] command = new String[] { m_rrdBinaryPath, "graph", "-", "--start=" + (startTimeInMillis / 1000), "--end=" + (endTimeInMillis / 1000), "DEF:ds1=" + RrdFileConstants.escapeForGraphing(rrdAttribute.getRrdRelativePath()) + ":" + attribute.getName() + ":" + rraConsolidationFunction };
    String[] printDefs = new String[printFunctions.length];
    for (int i = 0; i < printFunctions.length; i++) {
        printDefs[i] = "PRINT:ds1:" + printFunctions[i] + ":\"%le\"";
    }
    String commandString = StringUtils.arrayToDelimitedString(command, " ") + ' ' + StringUtils.arrayToDelimitedString(printDefs, " ");
    LOG.debug("commandString: {}", commandString);
    RrdGraphDetails graphDetails;
    try {
        graphDetails = m_rrdStrategy.createGraphReturnDetails(commandString, m_rrdBaseDirectory);
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Failure when generating graph to get data with command '" + commandString + "'", e);
    }
    String[] printLines;
    try {
        printLines = graphDetails.getPrintLines();
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Failure to get print lines from graph after graphing with command '" + commandString + "'", e);
    }
    if (printLines.length != printFunctions.length) {
        throw new DataAccessResourceFailureException("Returned number of print lines should be " + printFunctions.length + ", but was " + printLines.length + " from command: " + commandString);
    }
    double[] values = new double[printLines.length];
    for (int i = 0; i < printLines.length; i++) {
        if (printLines[i].toLowerCase().endsWith("nan")) {
            values[i] = Double.NaN;
        } else {
            try {
                // To avoid NMS-5592 ~ 2,670374e+03 floating point issue.
                values[i] = Double.parseDouble(printLines[i].replace(",", "."));
            } catch (NumberFormatException e) {
                throw new DataAccessResourceFailureException("Value of line " + (i + 1) + " of output from RRD is not a valid floating point number: '" + printLines[i] + "'");
            }
        }
    }
    return values;
}
Also used : DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) RrdGraphDetails(org.opennms.netmgt.rrd.RrdGraphDetails)

Example 42 with DataAccessResourceFailureException

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

the class ReportDefinition method createReport.

/**
 * <p>createReport</p>
 *
 * @param resourceDao a {@link org.opennms.netmgt.dao.api.ResourceDao} object.
 * @param fetchStrategy an object.
 * @param filterDao a {@link org.opennms.netmgt.filter.api.FilterDao} object.
 * @return a {@link org.opennms.netmgt.statsd.ReportInstance} object.
 * @throws java.lang.Exception if any.
 */
public ReportInstance createReport(NodeDao nodeDao, ResourceDao resourceDao, MeasurementFetchStrategy fetchStrategy, FilterDao filterDao) throws Exception {
    Assert.notNull(resourceDao, "resourceDao argument must not be null");
    Assert.notNull(fetchStrategy, "fetchStrategy argument must not be null");
    Assert.notNull(filterDao, "filterDao argument must not be null");
    AttributeStatisticVisitorWithResults visitor;
    try {
        visitor = getReportClass().newInstance();
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Could not instantiate visitor object; nested exception: " + e, e);
    }
    ReportInstance report;
    if (getReport().getPackage().getFilter() != null) {
        FilteredReportInstance thisReport = new FilteredReportInstance(visitor);
        thisReport.setNodeDao(nodeDao);
        thisReport.setResourceDao(resourceDao);
        thisReport.setFetchStrategy(fetchStrategy);
        thisReport.setFilterDao(filterDao);
        thisReport.setFilter(getReport().getPackage().getFilter());
        report = thisReport;
    } else {
        UnfilteredReportInstance thisReport = new UnfilteredReportInstance(visitor);
        thisReport.setResourceDao(resourceDao);
        thisReport.setFetchStrategy(fetchStrategy);
        report = thisReport;
    }
    report.setReportDefinition(this);
    report.setStartTime(getRelativeTime().getStart().getTime());
    report.setEndTime(getRelativeTime().getEnd().getTime());
    report.setCount(getCount());
    report.setConsolidationFunction(getConsolidationFunction());
    report.setResourceTypeMatch(getResourceTypeMatch());
    report.setAttributeMatch(getAttributeMatch());
    report.setResourceAttributeKey(m_resourceAttributeKey);
    report.setResourceAttributeValueMatch(m_resourceAttributeValueMatch);
    if (report instanceof InitializingBean) {
        ((InitializingBean) report).afterPropertiesSet();
    }
    return report;
}
Also used : DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) AttributeStatisticVisitorWithResults(org.opennms.netmgt.model.AttributeStatisticVisitorWithResults) InitializingBean(org.springframework.beans.factory.InitializingBean)

Example 43 with DataAccessResourceFailureException

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

the class DatabaseMetaDataImpl method runDatabaseTests.

/**
 * Run a set of tests on the database to provide better meta data.
 */
private void runDatabaseTests() {
    Connection conn = null;
    try {
        conn = this.dataSource.getConnection();
        // The order of these tests is IMPORTANT, each may depend on the
        // results of the previous tests.
        this.getMetaData(conn);
        final JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
        this.testDatabaseInitialized(jdbcTemplate);
        if (this.portalTablesExist) {
            this.testOuterJoins(jdbcTemplate);
            this.testTimeStamp(jdbcTemplate);
        }
    } catch (SQLException e) {
        LOG.error("Error during database initialization. ", e);
        /*
             * We must throw a RuntimeException here to avoid starting the portal
             * with incorrect assumptions about what the database supports.
             */
        throw new DataAccessResourceFailureException("Error during database initialization. ", e);
    } finally {
        this.releaseConnection(conn);
    }
}
Also used : SQLException(java.sql.SQLException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) Connection(java.sql.Connection) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 44 with DataAccessResourceFailureException

use of org.springframework.dao.DataAccessResourceFailureException in project spring-framework by spring-projects.

the class HibernateTransactionManager method doGetTransaction.

@Override
protected Object doGetTransaction() {
    HibernateTransactionObject txObject = new HibernateTransactionObject();
    txObject.setSavepointAllowed(isNestedTransactionAllowed());
    SessionFactory sessionFactory = obtainSessionFactory();
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
    if (sessionHolder != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Found thread-bound Session [" + sessionHolder.getSession() + "] for Hibernate transaction");
        }
        txObject.setSessionHolder(sessionHolder);
    } else if (this.hibernateManagedSession) {
        try {
            Session session = sessionFactory.getCurrentSession();
            if (logger.isDebugEnabled()) {
                logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction");
            }
            txObject.setExistingSession(session);
        } catch (HibernateException ex) {
            throw new DataAccessResourceFailureException("Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
        }
    }
    if (getDataSource() != null) {
        ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(getDataSource());
        txObject.setConnectionHolder(conHolder);
    }
    return txObject;
}
Also used : SessionFactory(org.hibernate.SessionFactory) HibernateException(org.hibernate.HibernateException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) Session(org.hibernate.Session) ConnectionHolder(org.springframework.jdbc.datasource.ConnectionHolder)

Example 45 with DataAccessResourceFailureException

use of org.springframework.dao.DataAccessResourceFailureException in project spring-framework by spring-projects.

the class OpenSessionInterceptor method openSession.

/**
 * Open a Session for the given SessionFactory.
 * <p>The default implementation delegates to the {@link SessionFactory#openSession}
 * method and sets the {@link Session}'s flush mode to "MANUAL".
 * @param sessionFactory the SessionFactory to use
 * @return the Session to use
 * @throws DataAccessResourceFailureException if the Session could not be created
 * @since 5.0
 * @see FlushMode#MANUAL
 */
protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
    try {
        Session session = sessionFactory.openSession();
        session.setHibernateFlushMode(FlushMode.MANUAL);
        return session;
    } catch (HibernateException ex) {
        throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) Session(org.hibernate.Session)

Aggregations

DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)53 SQLException (java.sql.SQLException)13 IOException (java.io.IOException)10 File (java.io.File)9 Connection (java.sql.Connection)9 BadSqlGrammarException (org.springframework.jdbc.BadSqlGrammarException)6 HibernateException (org.hibernate.HibernateException)5 Session (org.hibernate.Session)5 InputStream (java.io.InputStream)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 StorageService (org.dkpro.lab.storage.StorageService)4 StorageKey (org.dkpro.lab.storage.StorageService.StorageKey)4 QueryRuntimeException (org.hisp.dhis.common.QueryRuntimeException)4 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 Statement (java.sql.Statement)3 InOrder (org.mockito.InOrder)3