Search in sources :

Example 6 with JdbcException

use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.

the class JdbcUtil method executePropertiesQuery.

public static Properties executePropertiesQuery(Connection connection, String query) throws JdbcException {
    PreparedStatement stmt = null;
    Properties props = new Properties();
    try {
        if (log.isDebugEnabled())
            log.debug("prepare and execute query [" + query + "]");
        stmt = connection.prepareStatement(query);
        ResultSet rs = stmt.executeQuery();
        try {
            while (rs.next()) {
                props.put(rs.getString(1), rs.getString(2));
            }
            return props;
        } finally {
            rs.close();
        }
    } catch (Exception e) {
        throw new JdbcException("could not obtain value using query [" + query + "]", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception e) {
                throw new JdbcException("could not close statement of query [" + query + "]", e);
            }
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) SQLException(java.sql.SQLException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) JMSException(javax.jms.JMSException)

Example 7 with JdbcException

use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.

the class ConfigurationUtils method getConfigFromDatabase.

public static Map<String, Object> getConfigFromDatabase(IbisContext ibisContext, String name, String jmsRealm, String version) throws ConfigurationException {
    if (StringUtils.isEmpty(jmsRealm)) {
        jmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
        if (StringUtils.isEmpty(jmsRealm)) {
            return null;
        }
    }
    if (StringUtils.isEmpty(version)) {
        // Make sure this is null when empty!
        version = null;
    }
    Connection conn = null;
    ResultSet rs = null;
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    qs.setJmsRealm(jmsRealm);
    qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
    qs.configure();
    try {
        qs.open();
        conn = qs.getConnection();
        String query;
        if (version == null) {
            // Return active config
            query = "SELECT CONFIG, VERSION, FILENAME, CRE_TYDST, RUSER FROM IBISCONFIG WHERE NAME=? AND ACTIVECONFIG='" + (qs.getDbmsSupport().getBooleanValue(true)) + "'";
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setString(1, name);
            rs = stmt.executeQuery();
        } else {
            query = "SELECT CONFIG, VERSION, FILENAME, CRE_TYDST, RUSER FROM IBISCONFIG WHERE NAME=? AND VERSION=?";
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setString(1, name);
            stmt.setString(2, version);
            rs = stmt.executeQuery();
        }
        if (rs.next()) {
            Map<String, Object> configuration = new HashMap<String, Object>(5);
            byte[] jarBytes = rs.getBytes(1);
            if (jarBytes == null)
                return null;
            configuration.put("CONFIG", jarBytes);
            configuration.put("VERSION", rs.getString(2));
            configuration.put("FILENAME", rs.getString(3));
            configuration.put("CREATED", rs.getString(4));
            configuration.put("USER", rs.getString(5));
            return configuration;
        }
    } catch (SenderException e) {
        throw new ConfigurationException(e);
    } catch (JdbcException e) {
        throw new ConfigurationException(e);
    } catch (SQLException e) {
        throw new ConfigurationException(e);
    } finally {
        qs.close();
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                log.warn("Could not close resultset", e);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                log.warn("Could not close connection", e);
            }
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ResultSet(java.sql.ResultSet) SenderException(nl.nn.adapterframework.core.SenderException) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 8 with JdbcException

use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.

the class StatisticsKeeperStore method openGroup.

public Object openGroup(Object parentData, String name, String type) throws SenderException {
    SessionInfo sessionInfo = (SessionInfo) parentData;
    int parentKey = sessionInfo.groupKey;
    int groupKey;
    try {
        groupKey = groups.findOrInsert(sessionInfo.connection, parentKey, instanceKey, name, type);
        SessionInfo groupData = new SessionInfo();
        groupData.connection = sessionInfo.connection;
        groupData.eventKey = sessionInfo.eventKey;
        groupData.groupKey = groupKey;
        return groupData;
    } catch (JdbcException e) {
        throw new SenderException(e);
    }
}
Also used : SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException)

Example 9 with JdbcException

use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.

the class StatisticsKeeperStore method start.

public Object start(Date now, Date mainMark, Date detailMark) throws SenderException {
    List nameList = new LinkedList();
    List valueList = new LinkedList();
    now = new Date();
    SessionInfo sessionInfo = new SessionInfo();
    PreparedStatement stmt = null;
    long freeMem = Runtime.getRuntime().freeMemory();
    long totalMem = Runtime.getRuntime().totalMemory();
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_HOUR, PERIOD_FORMAT_DATEHOUR }, PERIOD_ALLOWED_LENGTH_HOUR, "s", mainMark);
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_DAY, PERIOD_FORMAT_DATE, PERIOD_FORMAT_WEEKDAY }, PERIOD_ALLOWED_LENGTH_DAY, "s", mainMark);
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_WEEK, PERIOD_FORMAT_YEARWEEK }, PERIOD_ALLOWED_LENGTH_WEEK, "s", mainMark);
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_MONTH, PERIOD_FORMAT_YEARMONTH }, PERIOD_ALLOWED_LENGTH_MONTH, "s", mainMark);
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_YEAR }, PERIOD_ALLOWED_LENGTH_YEAR, "s", mainMark);
    try {
        Connection connection = getConnection();
        sessionInfo.connection = connection;
        String hostname = Misc.getHostname();
        int hostKey = hosts.findOrInsert(connection, hostname);
        sessionInfo.eventKey = JdbcUtil.executeIntQuery(connection, selectNextValueQuery);
        String insertEventQuery = null;
        try {
            String insertClause = insertEventQueryInsertClause;
            String valuesClause = insertEventQueryValuesClause;
            for (Iterator it = nameList.iterator(); it.hasNext(); ) {
                String name = (String) it.next();
                insertClause += "," + name;
                valuesClause += ",?";
            }
            insertEventQuery = insertClause + valuesClause + ")";
            if (trace && log.isDebugEnabled())
                log.debug("prepare and execute query [" + insertEventQuery + "]");
            stmt = connection.prepareStatement(insertEventQuery);
            int pos = 1;
            stmt.setInt(pos++, sessionInfo.eventKey);
            stmt.setInt(pos++, instanceKey);
            stmt.setInt(pos++, hostKey);
            stmt.setLong(pos++, totalMem - freeMem);
            stmt.setLong(pos++, totalMem);
            stmt.setTimestamp(pos++, new Timestamp(now.getTime()));
            stmt.setTimestamp(pos++, new Timestamp(mainMark.getTime()));
            for (Iterator it = valueList.iterator(); it.hasNext(); ) {
                String value = (String) it.next();
                stmt.setString(pos++, value);
            }
            stmt.execute();
        } catch (Exception e) {
            throw new JdbcException("could not execute query [" + insertEventQuery + "]", e);
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                    throw new JdbcException("could not close statement for query [" + insertEventQuery + "]", e);
                }
            }
        }
        return sessionInfo;
    } catch (Exception e) {
        throw new SenderException(e);
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) LinkedList(java.util.LinkedList) Date(java.util.Date) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SQLException(java.sql.SQLException) SenderException(nl.nn.adapterframework.core.SenderException) Iterator(java.util.Iterator) List(java.util.List) LinkedList(java.util.LinkedList) SenderException(nl.nn.adapterframework.core.SenderException)

Example 10 with JdbcException

use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.

the class StatisticsKeeperStore method configure.

public void configure() throws ConfigurationException {
    if (StringUtils.isEmpty(getDatasourceName())) {
        throw new ConfigurationException("datasource must be specified");
    }
    createQueries();
    String instance = AppConstants.getInstance().getString("instance.name", "");
    Connection connection = null;
    try {
        connection = getConnection();
        instanceKey = instances.findOrInsert(connection, instance);
    } catch (JdbcException e) {
        throw new ConfigurationException("could not find instancekey for instance [" + instance + "]", e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e1) {
                throw new ConfigurationException("could not close connection to find instancekey for instance [" + instance + "]", e1);
            }
        }
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcException(nl.nn.adapterframework.jdbc.JdbcException)

Aggregations

JdbcException (nl.nn.adapterframework.jdbc.JdbcException)26 SQLException (java.sql.SQLException)19 IOException (java.io.IOException)15 PreparedStatement (java.sql.PreparedStatement)13 ResultSet (java.sql.ResultSet)9 JMSException (javax.jms.JMSException)9 DataFormatException (java.util.zip.DataFormatException)8 Connection (java.sql.Connection)7 InputStream (java.io.InputStream)6 SenderException (nl.nn.adapterframework.core.SenderException)6 FileNotFoundException (java.io.FileNotFoundException)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4 InputStreamReader (java.io.InputStreamReader)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)3 JmsException (nl.nn.adapterframework.jms.JmsException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2