Search in sources :

Example 6 with DirectQuerySender

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

the class JobDef method cleanupDatabase.

private void cleanupDatabase(IbisManager ibisManager) {
    Date date = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = formatter.format(date);
    List<String> jmsRealmNames = new ArrayList<String>();
    for (Configuration configuration : ibisManager.getConfigurations()) {
        List<JobDef> scheduledJobs = configuration.getScheduledJobs();
        for (JobDef jobdef : configuration.getScheduledJobs()) {
            if (jobdef.getLocker() != null) {
                String jmsRealmName = jobdef.getLocker().getJmsRealName();
                if (!jmsRealmNames.contains(jmsRealmName)) {
                    jmsRealmNames.add(jmsRealmName);
                }
            }
        }
    }
    for (IAdapter adapter : ibisManager.getRegisteredAdapters()) {
        if (adapter instanceof Adapter) {
            PipeLine pipeLine = ((Adapter) adapter).getPipeLine();
            if (pipeLine != null) {
                for (IPipe pipe : pipeLine.getPipes()) {
                    if (pipe instanceof IExtendedPipe) {
                        IExtendedPipe extendedPipe = (IExtendedPipe) pipe;
                        if (extendedPipe.getLocker() != null) {
                            String jmsRealmName = extendedPipe.getLocker().getJmsRealName();
                            if (!jmsRealmNames.contains(jmsRealmName)) {
                                jmsRealmNames.add(jmsRealmName);
                            }
                        }
                    }
                }
            }
        }
    }
    for (Iterator iter = jmsRealmNames.iterator(); iter.hasNext(); ) {
        String jmsRealmName = (String) iter.next();
        setJmsRealm(jmsRealmName);
        DirectQuerySender qs;
        qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(jmsRealmName);
        String deleteQuery;
        if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
            deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < CONVERT(datetime, '" + formattedDate + "', 120)";
        } else {
            deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        setQuery(deleteQuery);
        qs = null;
        executeQueryJob(ibisManager);
    }
    List messageLogs = new ArrayList();
    for (IAdapter iadapter : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) iadapter;
        PipeLine pipeline = adapter.getPipeLine();
        for (int i = 0; i < pipeline.getPipes().size(); i++) {
            IPipe pipe = pipeline.getPipe(i);
            if (pipe instanceof MessageSendingPipe) {
                MessageSendingPipe msp = (MessageSendingPipe) pipe;
                if (msp.getMessageLog() != null) {
                    ITransactionalStorage transactionStorage = msp.getMessageLog();
                    if (transactionStorage instanceof JdbcTransactionalStorage) {
                        JdbcTransactionalStorage messageLog = (JdbcTransactionalStorage) transactionStorage;
                        String jmsRealmName = messageLog.getJmsRealName();
                        String expiryDateField = messageLog.getExpiryDateField();
                        String tableName = messageLog.getTableName();
                        String keyField = messageLog.getKeyField();
                        String typeField = messageLog.getTypeField();
                        MessageLogObject mlo = new MessageLogObject(jmsRealmName, tableName, expiryDateField, keyField, typeField);
                        if (!messageLogs.contains(mlo)) {
                            messageLogs.add(mlo);
                        }
                    }
                }
            }
        }
    }
    for (Iterator iter = messageLogs.iterator(); iter.hasNext(); ) {
        MessageLogObject mlo = (MessageLogObject) iter.next();
        setJmsRealm(mlo.getJmsRealmName());
        DirectQuerySender qs;
        qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(mlo.getJmsRealmName());
        String deleteQuery;
        if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
            deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getKeyField() + " IN (SELECT " + mlo.getKeyField() + " FROM " + mlo.getTableName() + " WITH (rowlock,updlock,readpast) WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < CONVERT(datetime, '" + formattedDate + "', 120))";
        } else {
            deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        qs = null;
        setQuery(deleteQuery);
        setQueryTimeout(900);
        executeQueryJob(ibisManager);
    }
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) ArrayList(java.util.ArrayList) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Date(java.util.Date) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) JdbcTransactionalStorage(nl.nn.adapterframework.jdbc.JdbcTransactionalStorage) Iterator(java.util.Iterator) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) ArrayList(java.util.ArrayList) List(java.util.List) PipeLine(nl.nn.adapterframework.core.PipeLine) SimpleDateFormat(java.text.SimpleDateFormat) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Example 7 with DirectQuerySender

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

the class JobDef method executeQueryJob.

private void executeQueryJob(IbisManager ibisManager) {
    DirectQuerySender qs;
    qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
    try {
        qs.setName("QuerySender");
        qs.setJmsRealm(getJmsRealm());
        qs.setQueryType("other");
        qs.setTimeout(getQueryTimeout());
        qs.configure(true);
        qs.open();
        String result = qs.sendMessage("dummy", getQuery());
        log.info("result [" + result + "]");
    } catch (Exception e) {
        String msg = "error while executing query [" + getQuery() + "] (as part of scheduled job execution): " + e.getMessage();
        getMessageKeeper().add(msg, MessageKeeperMessage.ERROR_LEVEL);
        log.error(getLogPrefix() + msg);
    } finally {
        qs.close();
    }
}
Also used : DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) SQLException(java.sql.SQLException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 8 with DirectQuerySender

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

the class ShowSecurityItems method addJmsRealms.

private void addJmsRealms(XmlBuilder securityItems, String confResString) {
    List jmsRealms = JmsRealmFactory.getInstance().getRegisteredRealmNamesAsList();
    XmlBuilder jrs = new XmlBuilder("jmsRealms");
    securityItems.addSubElement(jrs);
    for (int j = 0; j < jmsRealms.size(); j++) {
        String jmsRealm = (String) jmsRealms.get(j);
        String dsName = null;
        String qcfName = null;
        String tcfName = null;
        String dsInfo = null;
        String qcfInfo = null;
        DirectQuerySender qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(jmsRealm);
        try {
            dsName = qs.getDataSourceNameToUse();
            dsInfo = qs.getDatasourceInfo();
        } catch (JdbcException jdbce) {
        // no datasource
        }
        if (StringUtils.isNotEmpty(dsName)) {
            XmlBuilder jr = new XmlBuilder("jmsRealm");
            jrs.addSubElement(jr);
            jr.addAttribute("name", jmsRealm);
            jr.addAttribute("datasourceName", dsName);
            XmlBuilder infoElem = new XmlBuilder("info");
            infoElem.setValue(dsInfo);
            jr.addSubElement(infoElem);
            if (confResString != null) {
                String connectionPoolProperties;
                try {
                    connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JDBC", dsName);
                } catch (Exception e) {
                    connectionPoolProperties = "*** ERROR ***";
                }
                if (StringUtils.isNotEmpty(connectionPoolProperties)) {
                    infoElem = new XmlBuilder("info");
                    infoElem.setValue(connectionPoolProperties);
                    jr.addSubElement(infoElem);
                }
            }
        }
        JmsSender js = new JmsSender();
        js.setJmsRealm(jmsRealm);
        try {
            qcfName = js.getConnectionFactoryName();
            qcfInfo = js.getConnectionFactoryInfo();
        } catch (JmsException jmse) {
        // no connectionFactory
        }
        if (StringUtils.isNotEmpty(qcfName)) {
            XmlBuilder jr = new XmlBuilder("jmsRealm");
            jrs.addSubElement(jr);
            jr.addAttribute("name", jmsRealm);
            jr.addAttribute("queueConnectionFactoryName", qcfName);
            XmlBuilder infoElem = new XmlBuilder("info");
            infoElem.setValue(qcfInfo);
            jr.addSubElement(infoElem);
            if (confResString != null) {
                String connectionPoolProperties;
                try {
                    connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JMS", qcfName);
                } catch (Exception e) {
                    connectionPoolProperties = "*** ERROR ***";
                }
                if (StringUtils.isNotEmpty(connectionPoolProperties)) {
                    infoElem = new XmlBuilder("info");
                    infoElem.setValue(connectionPoolProperties);
                    jr.addSubElement(infoElem);
                }
            }
        }
        tcfName = js.getTopicConnectionFactoryName();
        if (StringUtils.isNotEmpty(tcfName)) {
            XmlBuilder jr = new XmlBuilder("jmsRealm");
            jrs.addSubElement(jr);
            jr.addAttribute("name", jmsRealm);
            jr.addAttribute("topicConnectionFactoryName", tcfName);
        }
    }
}
Also used : JmsException(nl.nn.adapterframework.jms.JmsException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) JmsSender(nl.nn.adapterframework.jms.JmsSender) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) ServletException(javax.servlet.ServletException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) TransformerException(javax.xml.transform.TransformerException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) JmsException(nl.nn.adapterframework.jms.JmsException) IOException(java.io.IOException)

Example 9 with DirectQuerySender

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

the class ShowSecurityItems method addJmsRealms.

private ArrayList<Object> addJmsRealms() {
    List<String> jmsRealms = JmsRealmFactory.getInstance().getRegisteredRealmNamesAsList();
    ArrayList<Object> jmsRealmList = new ArrayList<>();
    String confResString;
    try {
        confResString = Misc.getConfigurationResources();
        if (confResString != null) {
            confResString = XmlUtils.removeNamespaces(confResString);
        }
    } catch (IOException e) {
        log.warn("error getting configuration resources [" + e + "]");
        confResString = null;
    }
    for (String realmName : jmsRealms) {
        Map<String, Object> realm = new HashMap<>();
        JmsRealm jmsRealm = JmsRealmFactory.getInstance().getJmsRealm(realmName);
        String dsName = jmsRealm.getDatasourceName();
        String qcfName = jmsRealm.getQueueConnectionFactoryName();
        String tcfName = jmsRealm.getTopicConnectionFactoryName();
        String dsInfo = null;
        String cfInfo = null;
        if (StringUtils.isNotEmpty(dsName)) {
            DirectQuerySender qs = getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
            qs.setJmsRealm(realmName);
            try {
                qs.configure();
                dsInfo = qs.getDatasourceInfo();
            } catch (JdbcException | ConfigurationException e) {
                log.debug("no datasource (" + ClassUtils.nameOf(e) + "): " + e.getMessage());
            }
            realm.put("name", realmName);
            realm.put("datasourceName", dsName);
            realm.put("info", dsInfo);
            if (confResString != null) {
                String connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JDBC", dsName);
                if (StringUtils.isNotEmpty(connectionPoolProperties)) {
                    realm.put("connectionPoolProperties", connectionPoolProperties);
                }
            }
        } else {
            JmsSender js = new JmsSender();
            js.setJmsRealm(realmName);
            if (StringUtils.isNotEmpty(tcfName)) {
                js.setDestinationType(DestinationType.TOPIC);
            }
            try {
                cfInfo = js.getConnectionFactoryInfo();
            } catch (JmsException e) {
                log.debug("no connectionFactory (" + ClassUtils.nameOf(e) + "): " + e.getMessage());
            }
            if (StringUtils.isNotEmpty(qcfName)) {
                realm.put("name", realmName);
                realm.put("queueConnectionFactoryName", qcfName);
                realm.put("info", cfInfo);
                if (confResString != null) {
                    String connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JMS", qcfName);
                    if (StringUtils.isNotEmpty(connectionPoolProperties)) {
                        realm.put("connectionPoolProperties", connectionPoolProperties);
                    }
                }
            } else if (StringUtils.isNotEmpty(tcfName)) {
                realm.put("name", realmName);
                realm.put("topicConnectionFactoryName", tcfName);
                realm.put("info", cfInfo);
            }
        }
        jmsRealmList.add(realm);
    }
    return jmsRealmList;
}
Also used : HashMap(java.util.HashMap) JmsException(nl.nn.adapterframework.jms.JmsException) ArrayList(java.util.ArrayList) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) IOException(java.io.IOException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) JmsRealm(nl.nn.adapterframework.jms.JmsRealm) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JmsSender(nl.nn.adapterframework.jms.JmsSender)

Aggregations

DirectQuerySender (nl.nn.adapterframework.jdbc.DirectQuerySender)9 IOException (java.io.IOException)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)3 ServletException (javax.servlet.ServletException)3 Transformer (javax.xml.transform.Transformer)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 ResultSet (java.sql.ResultSet)2 HashMap (java.util.HashMap)2 List (java.util.List)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Cookie (javax.servlet.http.Cookie)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)2 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)2 JmsException (nl.nn.adapterframework.jms.JmsException)2 JmsSender (nl.nn.adapterframework.jms.JmsSender)2