use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class JdbcUtil method executePropertiesQuery.
public static Properties executePropertiesQuery(Connection connection, String query) throws JdbcException {
PreparedStatement stmt = null;
Properties props = new Properties();
try {
if (log.isDebugEnabled())
log.debug("prepare and execute query [" + query + "]");
stmt = connection.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
try {
while (rs.next()) {
props.put(rs.getString(1), rs.getString(2));
}
return props;
} finally {
rs.close();
}
} catch (Exception e) {
throw new JdbcException("could not obtain value using query [" + query + "]", e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
throw new JdbcException("could not close statement of query [" + query + "]", e);
}
}
}
}
use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class ConfigurationUtils method getConfigFromDatabase.
public static Map<String, Object> getConfigFromDatabase(IbisContext ibisContext, String name, String jmsRealm, String version) throws ConfigurationException {
if (StringUtils.isEmpty(jmsRealm)) {
jmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
if (StringUtils.isEmpty(jmsRealm)) {
return null;
}
}
if (StringUtils.isEmpty(version)) {
// Make sure this is null when empty!
version = null;
}
Connection conn = null;
ResultSet rs = null;
FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
qs.setJmsRealm(jmsRealm);
qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
qs.configure();
try {
qs.open();
conn = qs.getConnection();
String query;
if (version == null) {
// Return active config
query = "SELECT CONFIG, VERSION, FILENAME, CRE_TYDST, RUSER FROM IBISCONFIG WHERE NAME=? AND ACTIVECONFIG='" + (qs.getDbmsSupport().getBooleanValue(true)) + "'";
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1, name);
rs = stmt.executeQuery();
} else {
query = "SELECT CONFIG, VERSION, FILENAME, CRE_TYDST, RUSER FROM IBISCONFIG WHERE NAME=? AND VERSION=?";
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1, name);
stmt.setString(2, version);
rs = stmt.executeQuery();
}
if (rs.next()) {
Map<String, Object> configuration = new HashMap<String, Object>(5);
byte[] jarBytes = rs.getBytes(1);
if (jarBytes == null)
return null;
configuration.put("CONFIG", jarBytes);
configuration.put("VERSION", rs.getString(2));
configuration.put("FILENAME", rs.getString(3));
configuration.put("CREATED", rs.getString(4));
configuration.put("USER", rs.getString(5));
return configuration;
}
} catch (SenderException e) {
throw new ConfigurationException(e);
} catch (JdbcException e) {
throw new ConfigurationException(e);
} catch (SQLException e) {
throw new ConfigurationException(e);
} finally {
qs.close();
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
log.warn("Could not close resultset", e);
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
log.warn("Could not close connection", e);
}
}
}
return null;
}
use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class StatisticsKeeperStore method openGroup.
public Object openGroup(Object parentData, String name, String type) throws SenderException {
SessionInfo sessionInfo = (SessionInfo) parentData;
int parentKey = sessionInfo.groupKey;
int groupKey;
try {
groupKey = groups.findOrInsert(sessionInfo.connection, parentKey, instanceKey, name, type);
SessionInfo groupData = new SessionInfo();
groupData.connection = sessionInfo.connection;
groupData.eventKey = sessionInfo.eventKey;
groupData.groupKey = groupKey;
return groupData;
} catch (JdbcException e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class StatisticsKeeperStore method start.
public Object start(Date now, Date mainMark, Date detailMark) throws SenderException {
List nameList = new LinkedList();
List valueList = new LinkedList();
now = new Date();
SessionInfo sessionInfo = new SessionInfo();
PreparedStatement stmt = null;
long freeMem = Runtime.getRuntime().freeMemory();
long totalMem = Runtime.getRuntime().totalMemory();
addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_HOUR, PERIOD_FORMAT_DATEHOUR }, PERIOD_ALLOWED_LENGTH_HOUR, "s", mainMark);
addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_DAY, PERIOD_FORMAT_DATE, PERIOD_FORMAT_WEEKDAY }, PERIOD_ALLOWED_LENGTH_DAY, "s", mainMark);
addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_WEEK, PERIOD_FORMAT_YEARWEEK }, PERIOD_ALLOWED_LENGTH_WEEK, "s", mainMark);
addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_MONTH, PERIOD_FORMAT_YEARMONTH }, PERIOD_ALLOWED_LENGTH_MONTH, "s", mainMark);
addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_YEAR }, PERIOD_ALLOWED_LENGTH_YEAR, "s", mainMark);
try {
Connection connection = getConnection();
sessionInfo.connection = connection;
String hostname = Misc.getHostname();
int hostKey = hosts.findOrInsert(connection, hostname);
sessionInfo.eventKey = JdbcUtil.executeIntQuery(connection, selectNextValueQuery);
String insertEventQuery = null;
try {
String insertClause = insertEventQueryInsertClause;
String valuesClause = insertEventQueryValuesClause;
for (Iterator it = nameList.iterator(); it.hasNext(); ) {
String name = (String) it.next();
insertClause += "," + name;
valuesClause += ",?";
}
insertEventQuery = insertClause + valuesClause + ")";
if (trace && log.isDebugEnabled())
log.debug("prepare and execute query [" + insertEventQuery + "]");
stmt = connection.prepareStatement(insertEventQuery);
int pos = 1;
stmt.setInt(pos++, sessionInfo.eventKey);
stmt.setInt(pos++, instanceKey);
stmt.setInt(pos++, hostKey);
stmt.setLong(pos++, totalMem - freeMem);
stmt.setLong(pos++, totalMem);
stmt.setTimestamp(pos++, new Timestamp(now.getTime()));
stmt.setTimestamp(pos++, new Timestamp(mainMark.getTime()));
for (Iterator it = valueList.iterator(); it.hasNext(); ) {
String value = (String) it.next();
stmt.setString(pos++, value);
}
stmt.execute();
} catch (Exception e) {
throw new JdbcException("could not execute query [" + insertEventQuery + "]", e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
throw new JdbcException("could not close statement for query [" + insertEventQuery + "]", e);
}
}
}
return sessionInfo;
} catch (Exception e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.jdbc.JdbcException in project iaf by ibissource.
the class StatisticsKeeperStore method configure.
public void configure() throws ConfigurationException {
if (StringUtils.isEmpty(getDatasourceName())) {
throw new ConfigurationException("datasource must be specified");
}
createQueries();
String instance = AppConstants.getInstance().getString("instance.name", "");
Connection connection = null;
try {
connection = getConnection();
instanceKey = instances.findOrInsert(connection, instance);
} catch (JdbcException e) {
throw new ConfigurationException("could not find instancekey for instance [" + instance + "]", e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e1) {
throw new ConfigurationException("could not close connection to find instancekey for instance [" + instance + "]", e1);
}
}
}
}
Aggregations