+/*
+ public ResultSet executeSql(String sql) throws StorageObjectFailure, SQLException {
+ long startTime = System.currentTimeMillis();
+ Connection connection = null;
+ Statement statement = null;
+
+ try {
+ connection = getPooledCon();
+ statement = connection.createStatement();
+ ResultSet result;
+
+ result = statement.executeQuery(sql);
+
+ logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
+ return result;
+ }
+ catch (Throwable e) {
+ logger.error(e.getMessage() +"\n" + (System.currentTimeMillis() - startTime) + "ms. for: " + sql);
+ throw new StorageObjectFailure(e);
+ }
+ finally {
+ if (connection!=null) {
+ freeConnection(connection, statement);
+ }
+ }
+ }
+*/
+ private Map processRow(ResultSet aResultSet) throws StorageObjectFailure, StorageObjectExc {
+ try {
+ Map result = new HashMap();
+ ResultSetMetaData metaData = aResultSet.getMetaData();
+ int nrColumns = metaData.getColumnCount();
+ for (int i=0; i<nrColumns; i++) {
+ result.put(metaData.getColumnName(i+1), getValueAsString(aResultSet, i+1, metaData.getColumnType(i+1)));
+ }
+
+ return result;
+ }
+ catch (Throwable e) {
+ throw new StorageObjectFailure(e);
+ }
+ }
+
+ public List executeFreeSql(String sql, int aLimit) throws StorageObjectFailure, StorageObjectExc {
+ Connection connection = null;
+ Statement statement = null;
+ try {
+ List result = new Vector();
+ connection = getPooledCon();
+ statement = connection.createStatement();
+ ResultSet resultset = executeSql(statement, sql);
+ try {
+ while (resultset.next() && result.size() < aLimit) {
+ result.add(processRow(resultset));
+ }
+ }
+ finally {
+ resultset.close();
+ }
+
+ return result;
+ }
+ catch (Throwable e) {
+ throw new StorageObjectFailure(e);
+ }
+ finally {
+ if (connection!=null) {
+ freeConnection(connection, statement);
+ }
+ }
+ };
+
+ public Map executeFreeSingleRowSql(String anSqlStatement) throws StorageObjectFailure, StorageObjectExc {
+ try {
+ List resultList = executeFreeSql(anSqlStatement, 1);
+ try {
+ if (resultList.size()>0)
+ return (Map) resultList.get(0);
+ else
+ return null;
+ }
+ finally {
+ }
+ }
+ catch (Throwable t) {
+ throw new StorageObjectFailure(t);
+ }
+ };
+
+ public String executeFreeSingleValueSql(String sql) throws StorageObjectFailure, StorageObjectExc {
+ Map row = executeFreeSingleRowSql(sql);
+
+ if (row==null)
+ return null;
+
+ Iterator i = row.values().iterator();
+ if (i.hasNext())
+ return (String) i.next();
+ else
+ return null;
+ };