javax.naming.Context ctx = new InitialContext();
if ( ctx == null ) throw new ProcessException(new ErrorMessage("noInitialContextAvailable"));
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
Result result = new Result(StateDescriptor.OK);
if (ds != null) {
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
Connection conn = null;
try {
conn = ds.getConnection();
if(conn != null) {
preparedStatement = conn.prepareStatement(statemenet);
for ( int i = 0; i < values.length; i++ ) {
// FIXME: We need a mapping for every sql type that should be supported
if ( values[i] instanceof StringValue ) {
preparedStatement.setString(i+1, values[i].toString());
} else if ( values[i] instanceof NumberValue ) {
preparedStatement.setInt(i+1, ((NumberValue)values[i]).getNumber().intValue());
} else if ( values[i] instanceof StreamableValue ) {
preparedStatement.setBinaryStream(i+1, ((StreamableValue)values[i]).getInputStream(), ((StreamableValue)values[i]).getContentLength());
}
}
if ( preparedStatement.execute() ) {
resultSet = preparedStatement.getResultSet();
List resultSetResources = new ArrayList();
ResultSetMetaData metaData = resultSet.getMetaData();
while ( resultSet.next() ) {
Map rowMap = new HashMap();
int columnCount = metaData.getColumnCount();
for ( int i = 0; i < columnCount; i++ ) {
String key = metaData.getColumnLabel(i+1);
Object object = resultSet.getObject(i+1);
if ( object instanceof String ) {
rowMap.put(key, new StringValue((String)object));
} else if ( object instanceof Integer ) {
rowMap.put(key, new NumberValue((Integer)object));
}
}
resultSetResources.add(new MapValue(rowMap));
}
Value[] resultEntries = new Value[resultSetResources.size()];
result.addResultEntry(RESULT, new ArrayValue((Value[] )resultSetResources.toArray(resultEntries)));
} else {
result.addResultEntry(ROW_COUNT, new NumberValue(new BigDecimal(preparedStatement.getUpdateCount())));
}
conn.close();
}
} catch (SQLException e) {
throw new ProcessException(new ErrorMessage("sqlException"), e);