Search in sources :

Example 6 with FixedQuerySender

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

the class JobDef method checkReload.

private void checkReload(IbisManager ibisManager) {
    String configJmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
    List<String> configsToReload = new ArrayList<String>();
    if (StringUtils.isNotEmpty(configJmsRealm)) {
        Connection conn = null;
        ResultSet rs = null;
        FixedQuerySender qs = (FixedQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(FixedQuerySender.class);
        qs.setJmsRealm(configJmsRealm);
        qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
        String selectQuery = "SELECT VERSION FROM IBISCONFIG WHERE NAME=? AND ACTIVECONFIG = 'TRUE' and AUTORELOAD = 'TRUE'";
        try {
            qs.configure();
            qs.open();
            conn = qs.getConnection();
            PreparedStatement stmt = conn.prepareStatement(selectQuery);
            for (Configuration configuration : ibisManager.getConfigurations()) {
                if ("DatabaseClassLoader".equals(configuration.getClassLoaderType())) {
                    String configName = configuration.getName();
                    stmt.setString(1, configName);
                    rs = stmt.executeQuery();
                    if (rs.next()) {
                        String ibisConfigVersion = rs.getString(1);
                        String configVersion = configuration.getVersion();
                        if (!StringUtils.equalsIgnoreCase(ibisConfigVersion, configVersion)) {
                            configsToReload.add(configName);
                        }
                    }
                }
            }
        } catch (Exception e) {
            String msg = "error while executing query [" + selectQuery + "] (as part of scheduled job execution): " + e.getMessage();
            getMessageKeeper().add(msg, MessageKeeperMessage.ERROR_LEVEL);
            log.error(getLogPrefix() + msg);
        } 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);
                }
            }
        }
    }
    if (!configsToReload.isEmpty()) {
        for (String configToReload : configsToReload) {
            ibisManager.getIbisContext().reload(configToReload);
        }
    }
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) SQLException(java.sql.SQLException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 7 with FixedQuerySender

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

the class TestTool method executeFixedQuerySenderRead.

private static int executeFixedQuerySenderRead(String step, String stepDisplayName, Properties properties, Map queues, Map writers, String queueName, String fileName, String fileContent) {
    int result = RESULT_ERROR;
    Map querySendersInfo = (Map) queues.get(queueName);
    Integer waitBeforeRead = (Integer) querySendersInfo.get("readQueryWaitBeforeRead");
    if (waitBeforeRead != null) {
        try {
            Thread.sleep(waitBeforeRead.intValue());
        } catch (InterruptedException e) {
        }
    }
    boolean newRecordFound = true;
    FixedQuerySender prePostFixedQuerySender = (FixedQuerySender) querySendersInfo.get("prePostQueryFixedQuerySender");
    if (prePostFixedQuerySender != null) {
        try {
            String preResult = (String) querySendersInfo.get("prePostQueryResult");
            debugPipelineMessage(stepDisplayName, "Pre result '" + queueName + "':", preResult, writers);
            String postResult = prePostFixedQuerySender.sendMessage(TESTTOOL_CORRELATIONID, TESTTOOL_DUMMY_MESSAGE);
            debugPipelineMessage(stepDisplayName, "Post result '" + queueName + "':", postResult, writers);
            if (preResult.equals(postResult)) {
                newRecordFound = false;
            }
            /* Fill the preResult with postResult, so closeQueues is able to determine if there
				 * are remaining messages left.
				 */
            querySendersInfo.put("prePostQueryResult", postResult);
        } catch (TimeOutException e) {
            errorMessage("Time out on execute query for '" + queueName + "': " + e.getMessage(), e, writers);
        } catch (SenderException e) {
            errorMessage("Could not execute query for '" + queueName + "': " + e.getMessage(), e, writers);
        }
    }
    String message = null;
    if (newRecordFound) {
        FixedQuerySender readQueryFixedQuerySender = (FixedQuerySender) querySendersInfo.get("readQueryQueryFixedQuerySender");
        try {
            message = readQueryFixedQuerySender.sendMessage(TESTTOOL_CORRELATIONID, TESTTOOL_DUMMY_MESSAGE);
        } catch (TimeOutException e) {
            errorMessage("Time out on execute query for '" + queueName + "': " + e.getMessage(), e, writers);
        } catch (SenderException e) {
            errorMessage("Could not execute query for '" + queueName + "': " + e.getMessage(), e, writers);
        }
    }
    if (message == null) {
        if ("".equals(fileName)) {
            result = RESULT_OK;
        } else {
            errorMessage("Could not read jdbc message (null returned) or no new message found (pre result equals post result)", writers);
        }
    } else {
        if ("".equals(fileName)) {
            debugPipelineMessage(stepDisplayName, "Unexpected message read from '" + queueName + "':", message, writers);
        } else {
            result = compareResult(step, stepDisplayName, fileName, fileContent, message, properties, writers, queueName);
        }
    }
    return result;
}
Also used : TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 8 with FixedQuerySender

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

the class ConfigurationUtils method retrieveConfigNamesFromDatabase.

public static List<String> retrieveConfigNamesFromDatabase(IbisContext ibisContext) throws ConfigurationException {
    Connection conn = null;
    ResultSet rs = null;
    FixedQuerySender qs = ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    qs.setDatasourceName(JndiDataSourceFactory.GLOBAL_DEFAULT_DATASOURCE_NAME);
    qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
    qs.configure();
    try {
        qs.open();
        conn = qs.getConnection();
        String query = "SELECT DISTINCT(NAME) FROM IBISCONFIG WHERE ACTIVECONFIG='" + (qs.getDbmsSupport().getBooleanValue(true)) + "'";
        PreparedStatement stmt = conn.prepareStatement(query);
        rs = stmt.executeQuery();
        List<String> stringList = new ArrayList<String>();
        while (rs.next()) {
            stringList.add(rs.getString(1));
        }
        return stringList;
    } catch (SenderException | JdbcException | SQLException e) {
        throw new ConfigurationException(e);
    } finally {
        JdbcUtil.fullClose(conn, rs);
        qs.close();
    }
}
Also used : SQLException(java.sql.SQLException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 9 with FixedQuerySender

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

the class ConfigurationUtils method getConfigFromDatabase.

public static Map<String, Object> getConfigFromDatabase(IbisContext ibisContext, String name, String dataSourceName, String version) throws ConfigurationException {
    String workdataSourceName = dataSourceName;
    if (StringUtils.isEmpty(workdataSourceName)) {
        workdataSourceName = JndiDataSourceFactory.GLOBAL_DEFAULT_DATASOURCE_NAME;
    }
    if (StringUtils.isEmpty(version)) {
        // Make sure this is null when empty!
        version = null;
    }
    if (log.isInfoEnabled())
        log.info("trying to fetch configuration [{}] version [{}] from database with dataSourceName [{}]", name, version, workdataSourceName);
    Connection conn = null;
    ResultSet rs = null;
    FixedQuerySender qs = ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    qs.setDatasourceName(workdataSourceName);
    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()) {
            log.error("no configuration found in database with name [" + name + "] " + (version != null ? "version [" + version + "]" : "activeconfig [TRUE]"));
            return null;
        }
        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 | JdbcException | SQLException e) {
        throw new ConfigurationException(e);
    } finally {
        JdbcUtil.fullClose(conn, rs);
        qs.close();
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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 10 with FixedQuerySender

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

the class ConfigurationUtils method activateConfig.

/**
 * Set the all ACTIVECONFIG to false and specified version to true
 * @param value
 */
public static boolean activateConfig(IbisContext ibisContext, String name, String version, boolean value, String dataSourceName) throws SenderException, ConfigurationException, JdbcException, SQLException {
    String workdataSourceName = dataSourceName;
    if (StringUtils.isEmpty(workdataSourceName)) {
        workdataSourceName = JndiDataSourceFactory.GLOBAL_DEFAULT_DATASOURCE_NAME;
    }
    Connection conn = null;
    ResultSet rs = null;
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    qs.setDatasourceName(workdataSourceName);
    qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
    qs.configure();
    String booleanValueFalse = qs.getDbmsSupport().getBooleanValue(false);
    String booleanValueTrue = qs.getDbmsSupport().getBooleanValue(true);
    try {
        qs.open();
        conn = qs.getConnection();
        int updated = 0;
        String selectQuery = "SELECT NAME FROM IBISCONFIG WHERE NAME=? AND VERSION=?";
        PreparedStatement selectStmt = conn.prepareStatement(selectQuery);
        selectStmt.setString(1, name);
        selectStmt.setString(2, version);
        rs = selectStmt.executeQuery();
        if (rs.next()) {
            String query = "UPDATE IBISCONFIG SET ACTIVECONFIG='" + booleanValueFalse + "' WHERE NAME=?";
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setString(1, name);
            updated = stmt.executeUpdate();
            if (updated > 0) {
                String query2 = "UPDATE IBISCONFIG SET ACTIVECONFIG='" + booleanValueTrue + "' WHERE NAME=? AND VERSION=?";
                PreparedStatement stmt2 = conn.prepareStatement(query2);
                stmt2.setString(1, name);
                stmt2.setString(2, version);
                return (stmt2.executeUpdate() > 0) ? true : false;
            }
        }
    } finally {
        JdbcUtil.fullClose(conn, rs);
        qs.close();
    }
    return false;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Aggregations

FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)32 Connection (java.sql.Connection)17 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)14 SenderException (nl.nn.adapterframework.core.SenderException)13 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)11 Parameter (nl.nn.adapterframework.parameters.Parameter)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 SQLException (java.sql.SQLException)8 LinkedHashMap (java.util.LinkedHashMap)8 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)8 Map (java.util.Map)7 PipeRunException (nl.nn.adapterframework.core.PipeRunException)7 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)7 ArrayList (java.util.ArrayList)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 ListenerException (nl.nn.adapterframework.core.ListenerException)4 IbisWebServiceSender (nl.nn.adapterframework.http.IbisWebServiceSender)4 WebServiceListener (nl.nn.adapterframework.http.WebServiceListener)4