use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class JdbcUtil method executeIntQuery.
/**
* exectues query that returns an integer. Returns -1 if no results are found.
*/
public static int executeIntQuery(Connection connection, String query, String param1, String param2) throws JdbcException {
PreparedStatement stmt = null;
try {
if (log.isDebugEnabled())
log.debug("prepare and execute query [" + query + "]" + displayParameters(param1, param2));
stmt = connection.prepareStatement(query);
applyParameters(stmt, param1, param2);
ResultSet rs = stmt.executeQuery();
try {
if (!rs.next()) {
return -1;
}
return rs.getInt(1);
} finally {
rs.close();
}
} catch (Exception e) {
throw new JdbcException("could not obtain value using query [" + query + "]" + displayParameters(param1, param2), e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
throw new JdbcException("could not close statement of query [" + query + "]" + displayParameters(param1, param2), e);
}
}
}
}
use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class Locker method lock.
public String lock() throws JdbcException, SQLException, InterruptedException {
Connection conn = getConnection();
try {
if (!JdbcUtil.tableExists(conn, "ibisLock")) {
if (isIgnoreTableNotExist()) {
log.info("table [ibisLock] does not exist, ignoring lock");
return LOCK_IGNORED;
} else {
throw new JdbcException("table [ibisLock] does not exist");
}
}
} finally {
try {
conn.close();
} catch (SQLException e) {
log.error("error closing JdbcConnection", e);
}
}
String objectIdWithSuffix = null;
int r = -1;
while (objectIdWithSuffix == null && (numRetries == -1 || r < numRetries)) {
r++;
if (r == 0 && firstDelay > 0) {
Thread.sleep(firstDelay);
}
if (r > 0) {
Thread.sleep(retryDelay);
}
Date date = new Date();
objectIdWithSuffix = getObjectId();
if (StringUtils.isNotEmpty(getDateFormatSuffix())) {
String formattedDate = formatter.format(date);
objectIdWithSuffix = objectIdWithSuffix.concat(formattedDate);
}
log.debug("preparing to set lock [" + objectIdWithSuffix + "]");
conn = getConnection();
try {
PreparedStatement stmt = conn.prepareStatement(insertQuery);
stmt.clearParameters();
stmt.setString(1, objectIdWithSuffix);
stmt.setString(2, getType());
stmt.setString(3, Misc.getHostname());
stmt.setTimestamp(4, new Timestamp(date.getTime()));
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if (getType().equalsIgnoreCase("T")) {
cal.add(Calendar.HOUR_OF_DAY, getRetention());
} else {
cal.add(Calendar.DAY_OF_MONTH, getRetention());
}
stmt.setTimestamp(5, new Timestamp(cal.getTime().getTime()));
stmt.executeUpdate();
log.debug("lock [" + objectIdWithSuffix + "] set");
} catch (SQLException e) {
log.debug(getLogPrefix() + "error executing insert query (as part of locker): " + e.getMessage());
if (numRetries == -1 || r < numRetries) {
log.debug(getLogPrefix() + "will try again");
objectIdWithSuffix = null;
} else {
log.debug(getLogPrefix() + "will not try again");
throw e;
}
} finally {
try {
conn.close();
} catch (SQLException e) {
log.error("error closing JdbcConnection", e);
}
}
}
return objectIdWithSuffix;
}
use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class JdbcUtil method executeStatement.
public static void executeStatement(Connection connection, String query, int param1, int param2, String param3, String param4) throws JdbcException {
PreparedStatement stmt = null;
try {
if (log.isDebugEnabled())
log.debug("prepare and execute query [" + query + "]" + displayParameters(param1, param2, param3, param4));
stmt = connection.prepareStatement(query);
applyParameters(stmt, param1, param2, param3, param4);
stmt.execute();
} catch (Exception e) {
throw new JdbcException("could not execute query [" + query + "]" + displayParameters(param1, param2, param3, param4), e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
throw new JdbcException("could not close statement for query [" + query + "]" + displayParameters(param1, param2, param3, param4), e);
}
}
}
}
use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class JdbcUtil method executeIntQuery.
public static int executeIntQuery(Connection connection, String query, int param1, String param2, String param3) throws JdbcException {
PreparedStatement stmt = null;
try {
if (log.isDebugEnabled())
log.debug("prepare and execute query [" + query + "]" + displayParameters(param1, param2, param3));
stmt = connection.prepareStatement(query);
applyParameters(stmt, param1, param2, param3);
ResultSet rs = stmt.executeQuery();
try {
if (!rs.next()) {
return -1;
}
return rs.getInt(1);
} finally {
rs.close();
}
} catch (Exception e) {
throw new JdbcException("could not obtain value using query [" + query + "]" + displayParameters(param1, param2, param3), e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
throw new JdbcException("could not close statement of query [" + query + "]" + displayParameters(param1, param2, param3), e);
}
}
}
}
use of nl.nn.adapterframework.jdbc.JdbcException 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<Object>();
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 (int j = 0; j < jmsRealms.size(); j++) {
Map<String, Object> realm = new HashMap<String, Object>();
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)) {
realm.put("name", jmsRealm);
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);
}
}
}
JmsSender js = new JmsSender();
js.setJmsRealm(jmsRealm);
try {
qcfName = js.getConnectionFactoryName();
qcfInfo = js.getConnectionFactoryInfo();
} catch (JmsException jmse) {
// no connectionFactory
}
if (StringUtils.isNotEmpty(qcfName)) {
realm.put("name", jmsRealm);
realm.put("queueConnectionFactoryName", qcfName);
realm.put("info", qcfInfo);
if (confResString != null) {
String connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JMS", qcfName);
if (StringUtils.isNotEmpty(connectionPoolProperties)) {
realm.put("connectionPoolProperties", connectionPoolProperties);
}
}
}
tcfName = js.getTopicConnectionFactoryName();
if (StringUtils.isNotEmpty(tcfName)) {
realm.put("name", jmsRealm);
realm.put("topicConnectionFactoryName", tcfName);
}
jmsRealmList.add(realm);
}
return jmsRealmList;
}
Aggregations