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