Search in sources :

Example 21 with FixedQuerySender

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

the class ShowConfig method retrieveAllConfigs.

private String retrieveAllConfigs(IPipeLineSession session) throws PipeRunException {
    List<String> jmsRealms = JmsRealmFactory.getInstance().getRegisteredDatasourceRealmNamesAsList();
    XmlBuilder configsXML = new XmlBuilder("configs");
    for (int i = 0; i < jmsRealms.size(); i++) {
        XmlBuilder configXML = new XmlBuilder("config");
        String jr = jmsRealms.get(i);
        configXML.addAttribute("jmsRealm", jr);
        FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(jr);
            qs.setQueryType("select");
            qs.setQuery("SELECT NAME, VERSION, FILENAME, CRE_TYDST, RUSER, ACTIVECONFIG, AUTORELOAD FROM IBISCONFIG WHERE ACTIVECONFIG = '" + qs.getDbmsSupport().getBooleanValue(true) + "' ORDER BY NAME");
            qs.setBlobSmartGet(true);
            qs.setIncludeFieldDefinition(false);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("dummy", session);
            String queryResult = qs.sendMessage("dummy", "dummy", prc);
            configXML.setValue(queryResult, false);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
        } finally {
            qs.close();
        }
        configsXML.addSubElement(configXML);
    }
    return configsXML.toXML();
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 22 with FixedQuerySender

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

the class ConfigData method activeConfigQuery.

private String activeConfigQuery(IPipeLineSession session, String name, String formJmsRealm, String result) throws PipeRunException {
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    try {
        qs.setName("QuerySender");
        qs.setJmsRealm(formJmsRealm);
        qs.setQueryType("update");
        qs.setQuery("UPDATE IBISCONFIG SET ACTIVECONFIG = '" + qs.getDbmsSupport().getBooleanValue(false) + "' WHERE NAME=?");
        Parameter param = new Parameter();
        param.setName("name");
        param.setValue(name);
        qs.addParameter(param);
        qs.setScalar(true);
        qs.configure();
        qs.open();
        ParameterResolutionContext prc = new ParameterResolutionContext(DUMMY, session);
        result = qs.sendMessage(DUMMY, DUMMY, prc);
    } catch (Exception t) {
        throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
    } finally {
        qs.close();
    }
    return result;
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 23 with FixedQuerySender

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

the class ConfigurationUtils method addConfigToDatabase.

public static boolean addConfigToDatabase(IbisContext ibisContext, String dataSourceName, boolean activate_config, boolean automatic_reload, String name, String version, String fileName, InputStream file, String ruser) throws ConfigurationException {
    String workdataSourceName = dataSourceName;
    if (StringUtils.isEmpty(workdataSourceName)) {
        workdataSourceName = JndiDataSourceFactory.GLOBAL_DEFAULT_DATASOURCE_NAME;
    }
    Connection conn = null;
    ResultSet rs = null;
    FixedQuerySender qs = ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    qs.setDatasourceName(workdataSourceName);
    qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
    qs.configure();
    PlatformTransactionManager txManager = ibisContext.getBean("txManager", PlatformTransactionManager.class);
    TransactionDefinition txDef = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    IbisTransaction itx = new IbisTransaction(txManager, txDef, "add config [" + name + "] to database");
    try {
        qs.open();
        conn = qs.getConnection();
        int updated = 0;
        if (activate_config) {
            String query = ("UPDATE IBISCONFIG SET ACTIVECONFIG = '" + (qs.getDbmsSupport().getBooleanValue(false)) + "' WHERE NAME=?");
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setString(1, name);
            updated = stmt.executeUpdate();
        }
        if (updated > 0) {
            String query = ("DELETE FROM IBISCONFIG WHERE NAME=? AND VERSION = ?");
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setString(1, name);
            stmt.setString(2, version);
            stmt.execute();
        }
        String query = ("INSERT INTO IBISCONFIG (NAME, VERSION, FILENAME, CONFIG, CRE_TYDST, RUSER, ACTIVECONFIG, AUTORELOAD) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?, ?)");
        PreparedStatement stmt = conn.prepareStatement(query);
        stmt.setString(1, name);
        stmt.setString(2, version);
        stmt.setString(3, fileName);
        stmt.setBinaryStream(4, file);
        if (StringUtils.isEmpty(ruser)) {
            stmt.setNull(5, Types.VARCHAR);
        } else {
            stmt.setString(5, ruser);
        }
        stmt.setObject(6, qs.getDbmsSupport().getBooleanValue(activate_config));
        stmt.setObject(7, qs.getDbmsSupport().getBooleanValue(automatic_reload));
        return stmt.executeUpdate() > 0;
    } catch (SenderException | JdbcException | SQLException e) {
        itx.setRollbackOnly();
        throw new ConfigurationException(e);
    } finally {
        itx.commit();
        JdbcUtil.fullClose(conn, rs);
        qs.close();
    }
}
Also used : TransactionDefinition(org.springframework.transaction.TransactionDefinition) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IbisTransaction(nl.nn.adapterframework.core.IbisTransaction) ResultSet(java.sql.ResultSet) SenderException(nl.nn.adapterframework.core.SenderException) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 24 with FixedQuerySender

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

the class ConfigurationUtils method autoReloadConfig.

/**
 * Toggle AUTORELOAD
 */
public static boolean autoReloadConfig(IbisContext ibisContext, String name, String version, boolean booleanValue, 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();
    try {
        qs.open();
        conn = qs.getConnection();
        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 AUTORELOAD='" + qs.getDbmsSupport().getBooleanValue(booleanValue) + "' WHERE NAME=? AND VERSION=?";
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setString(1, name);
            stmt.setString(2, version);
            return stmt.executeUpdate() > 0;
        }
    } 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)

Example 25 with FixedQuerySender

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

the class ConfigurationUtils method removeConfigFromDatabase.

public static void removeConfigFromDatabase(IbisContext ibisContext, String name, String jmsRealm, String version) throws ConfigurationException {
    Connection conn = null;
    ResultSet rs = null;
    FixedQuerySender qs = (FixedQuerySender) 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 = ("DELETE FROM IBISCONFIG WHERE NAME=? AND VERSION=?");
        PreparedStatement stmt = conn.prepareStatement(query);
        stmt.setString(1, name);
        stmt.setString(2, version);
        stmt.execute();
    } catch (SenderException e) {
        throw new ConfigurationException(e);
    } catch (JdbcException e) {
        throw new ConfigurationException(e);
    } catch (SQLException e) {
        throw new ConfigurationException(e);
    } finally {
        JdbcUtil.fullClose(conn, rs);
        qs.close();
    }
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) 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