Search in sources :

Example 1 with FixedQuerySender

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

the class ExecuteJdbcProperties method doPost.

private String doPost(IPipeLineSession session) throws PipeRunException {
    String action = (String) session.get("action");
    String name = (String) session.get("name");
    String value = (String) session.get("value");
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    String form_jmsRealm = (String) session.get("jmsRealm");
    if (StringUtils.isEmpty(name)) {
        throw new PipeRunException(this, getLogPrefix(session) + "Name should not be empty");
    }
    String result = null;
    String remoteUser = (String) session.get("principal");
    if ("insert".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("insert");
            if (StringUtils.isEmpty(remoteUser)) {
                qs.setQuery("INSERT INTO IBISPROP (NAME, VALUE, LASTMODDATE) VALUES (?, ?, CURRENT_TIMESTAMP)");
            } else {
                qs.setQuery("INSERT INTO IBISPROP (NAME, VALUE, LASTMODDATE, LASTMODBY) VALUES (?, ?, CURRENT_TIMESTAMP, ?)");
            }
            Parameter param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            param = new Parameter();
            param.setName("value");
            param.setValue(value);
            qs.addParameter(param);
            if (StringUtils.isNotEmpty(remoteUser)) {
                param = new Parameter();
                param.setName("lastmodby");
                param.setValue(remoteUser);
                qs.addParameter(param);
            }
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc insert query", t);
        } finally {
            qs.close();
        }
    } else if ("update".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("update");
            qs.setQuery("UPDATE IBISPROP SET VALUE=?, LASTMODDATE=CURRENT_TIMESTAMP, LASTMODBY=? WHERE NAME=?");
            Parameter param = new Parameter();
            param.setName("value");
            param.setValue(value);
            qs.addParameter(param);
            param = new Parameter();
            param.setName("lastmodby");
            if (StringUtils.isNotEmpty(remoteUser)) {
                param.setValue(remoteUser);
            }
            qs.addParameter(param);
            param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc update query", t);
        } finally {
            qs.close();
        }
    } else if ("delete".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("delete");
            qs.setQuery("DELETE IBISPROP WHERE NAME=?");
            Parameter param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc delete query", t);
        } finally {
            qs.close();
        }
    } else {
        throw new PipeRunException(this, getLogPrefix(session) + "Unknown action [" + action + "]");
    }
    session.put("result", result);
    return "<dummy/>";
}
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)

Example 2 with FixedQuerySender

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

the class ShowConfig method doGet.

private String doGet(IPipeLineSession session) throws PipeRunException {
    String parm_name = (String) session.get("name");
    if (StringUtils.isEmpty(parm_name)) {
        return retrieveAllConfigs(session);
    } else {
        session.put("contentType", "application/octet-stream");
        String parm_jmsRealm = (String) session.get("jmsRealm");
        if (StringUtils.isEmpty(parm_jmsRealm)) {
            parm_jmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
            if (parm_jmsRealm == null) {
                throw new PipeRunException(this, getLogPrefix(session) + "No datasource jmsRealm available");
            }
        }
        FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
        String queryResult;
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(parm_jmsRealm);
            qs.setQueryType("select");
            qs.setQuery("SELECT CONFIG FROM IBISCONFIG WHERE NAME = ? ORDER BY NAME");
            Parameter param = new Parameter();
            param.setName("name");
            param.setSessionKey("name");
            qs.addParameter(param);
            qs.setScalar(true);
            qs.setScalarExtended(true);
            qs.setBlobsCompressed(false);
            qs.setStreamResultToServlet(true);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("dummy", session);
            queryResult = qs.sendMessage("dummy", "dummy", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
        } finally {
            qs.close();
        }
        if (queryResult.length() == 0) {
        // means result is found and streamed
        } else {
            throw new PipeRunException(this, getLogPrefix(session) + "Could not retrieve configuration for name [" + parm_name + "]");
        }
        return queryResult;
    }
}
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)

Example 3 with FixedQuerySender

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

the class ConfigData method processJarFile.

private String processJarFile(IPipeLineSession session, String name, String version, String fileName, String fileNameSessionKey) throws PipeRunException {
    String formJmsRealm = (String) session.get("jmsRealm");
    String activeConfig = (String) session.get(ACTIVE_CONFIG);
    String autoReload = (String) session.get(AUTO_RELOAD);
    String result = selectConfigQuery(session, name);
    if ("on".equals(activeConfig)) {
        activeConfigQuery(session, name, formJmsRealm, result);
    }
    if (Integer.parseInt(result) > 0) {
        deleteConfigQuery(session, name, formJmsRealm, version);
    }
    String remoteUser = (String) session.get("principal");
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    try {
        qs.setName("QuerySender");
        qs.setJmsRealm(formJmsRealm);
        qs.setQueryType("insert");
        if (StringUtils.isEmpty(remoteUser)) {
            qs.setQuery("INSERT INTO IBISCONFIG (NAME, VERSION, FILENAME, CONFIG, CRE_TYDST, ACTIVECONFIG, AUTORELOAD) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?)");
        } else {
            qs.setQuery("INSERT INTO IBISCONFIG (NAME, VERSION, FILENAME, CONFIG, CRE_TYDST, RUSER, ACTIVECONFIG, AUTORELOAD) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?, ?)");
        }
        Parameter param = new Parameter();
        param.setName("name");
        param.setValue(name);
        qs.addParameter(param);
        param = new Parameter();
        param.setName("version");
        param.setValue(version);
        qs.addParameter(param);
        param = new Parameter();
        param.setName("fileName");
        param.setValue(fileName);
        qs.addParameter(param);
        param = new Parameter();
        param.setName("config");
        param.setSessionKey(fileNameSessionKey);
        param.setType(Parameter.TYPE_INPUTSTREAM);
        qs.addParameter(param);
        if (StringUtils.isNotEmpty(remoteUser)) {
            param = new Parameter();
            param.setName("ruser");
            param.setValue(remoteUser);
            qs.addParameter(param);
        }
        setActiveConfig(activeConfig, qs);
        setAutoReload(autoReload, qs);
        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 4 with FixedQuerySender

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

the class ConfigData method deleteConfigQuery.

private String deleteConfigQuery(IPipeLineSession session, String name, String formJmsRealm, String version) throws PipeRunException {
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    String result = "";
    try {
        qs.setName("QuerySender");
        qs.setJmsRealm(formJmsRealm);
        qs.setQuery("DELETE FROM IBISCONFIG WHERE NAME = ? AND VERSION = ?");
        Parameter param = new Parameter();
        param.setName("name");
        param.setValue(name);
        qs.addParameter(param);
        param = new Parameter();
        param.setName("version");
        param.setValue(version);
        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 5 with FixedQuerySender

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

the class ConfigData method selectConfigQuery.

private String selectConfigQuery(IPipeLineSession session, String name) throws PipeRunException {
    String formJmsRealm = (String) session.get("jmsRealm");
    String result = "";
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    try {
        qs.setName("QuerySender");
        qs.setJmsRealm(formJmsRealm);
        qs.setQueryType("select");
        qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG 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)

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