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);
}
}
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();
}
}
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);
}
}
}
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;
}
Aggregations