this.parameters = parameters;
}
public Object evaluate(QueryExpression queryStmt)
{
QueryResult qr = null;
try
{
RDBMSManager storeMgr = (RDBMSManager)om.getStoreManager();
DatastoreAdapter dba = storeMgr.getDatastoreAdapter();
ManagedConnection mconn = storeMgr.getConnection(om);
Connection conn = (Connection) mconn.getConnection();
SQLController sqlControl = storeMgr.getSQLController();
try
{
PreparedStatement ps = conn.prepareStatement(compiledSQL);
try
{
Iterator iter = parameterOccurrences.iterator();
int stmtParamNum = 1;
while (iter.hasNext())
{
String paramName = (String) iter.next();
Class paramType = (Class) parameterTypesByName.get(paramName);
if (!parameters.containsKey(paramName))
{
throw new JPOXUserException(LOCALISER_RDBMS.msg("060006",
paramName));
}
if (paramType == null)
{
throw new JPOXUserException(LOCALISER_RDBMS.msg("060007",
paramName));
}
JavaTypeMapping mapping = dba.getMapping(paramType, storeMgr,
om.getClassLoaderResolver());
Object paramValue = parameters.get(paramName);
mapping.setObject(om, ps, Mappings.getParametersIndex(stmtParamNum,mapping), paramValue);
if (mapping.getNumberOfDatastoreFields() == 0)
{
stmtParamNum++;
}
else
{
stmtParamNum += mapping.getNumberOfDatastoreFields();
}
}
// Apply any user-specified constraints over timeouts and ResultSet
prepareStatementForExecution(ps);
// Execute the query
ResultSet rs = sqlControl.executeStatementQuery(mconn, compiledSQL, ps);
try
{
ResultObjectFactory rof = null;
if (candidateClass != null)
{
ResultSetMetaData rsmd = rs.getMetaData();
HashSet remainingColumnNames = new HashSet(fieldColumnNames);
int colCount = rsmd.getColumnCount();
for (int colNum = 1; colNum <= colCount; ++colNum)
{
String colName = rsmd.getColumnName(colNum);
int fieldNumber = fieldColumnNames.indexOf(colName);
if (fieldNumber >= 0)
{
statementExpressionIndex[fieldNumber].setExpressionIndex(new int[]{colNum});
remainingColumnNames.remove(colName);
}
}
if (!remainingColumnNames.isEmpty())
{
throw new JPOXUserException(LOCALISER_RDBMS.msg("060005",
remainingColumnNames));
}
if (resultClass != null)
{
rof = new ResultClassROF(resultClass, statementExpressionIndex);
}
else
{
rof = new TransientIDROF(candidateClass, fieldNumbers, statementExpressionIndex);
}
}
else
{
rof = getResultObjectFactoryForNoCandidateClass(rs, resultClass);
}
// Return the associated type of results depending on whether insensitive or not
if (getResultSetType().equals("scroll-insensitive") ||
getResultSetType().equals("scroll-sensitive"))
{
qr = new ScrollableQueryResult(null, query, rof, rs, null);
}
else
{
qr = new ForwardQueryResult(null, query, rof, rs, null);
}
final QueryResult qr1 = qr;
final ManagedConnection mconn1 = mconn;
mconn.addListener(new ManagedConnectionResourceListener()
{
public void managedConnectionFlushed()
{
qr1.disconnect();
}
public void managedConnectionPreClose() {}
public void managedConnectionPostClose() {}
public void resourcePostClose()
{