// Update/Delete statement (INSERT/UPDATE/DELETE/MERGE)
try
{
RDBMSStoreManager storeMgr = (RDBMSStoreManager)ec.getStoreManager();
ManagedConnection mconn = storeMgr.getConnection(ec);
SQLController sqlControl = storeMgr.getSQLController();
try
{
PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, compiledSQL, false);
try
{
// Set the values of any parameters
for (int i=0;i<parameters.size();i++)
{
Object obj = parameters.get(Integer.valueOf(i+1));
ps.setObject((i+1), obj);
}
// Execute the update statement
int[] rcs = sqlControl.executeStatementUpdate(mconn, compiledSQL, ps, true);
return Long.valueOf(rcs[0]); // Return a single Long with the number of records updated
}
finally
{
sqlControl.closeStatement(mconn, ps);
}
}
finally
{
mconn.release();
}
}
catch (SQLException e)
{
throw new NucleusDataStoreException(LOCALISER.msg("059025", compiledSQL), e);
}
}
else
{
// Query statement (SELECT, stored-procedure)
QueryResult qr = null;
try
{
RDBMSStoreManager storeMgr = (RDBMSStoreManager)ec.getStoreManager();
ManagedConnection mconn = storeMgr.getConnection(ec);
SQLController sqlControl = storeMgr.getSQLController();
try
{
PreparedStatement ps = RDBMSQueryUtils.getPreparedStatementForQuery(mconn, compiledSQL, this);
try
{
// Set the values of any parameters
for (int i=0;i<parameters.size();i++)
{
Object obj = parameters.get(Integer.valueOf(i+1));
ps.setObject((i+1), obj);
}
// Apply any user-specified constraints over timeouts and ResultSet
RDBMSQueryUtils.prepareStatementForExecution(ps, this, false);
ResultSet rs = sqlControl.executeStatementQuery(mconn, compiledSQL, ps);
try
{
// Generate a ResultObjectFactory
ResultObjectFactory rof = null;
if (resultMetaData != null)
{
// Each row of the ResultSet is defined by MetaData
rof = new ResultMetaDataROF(resultMetaData);
}
else if (resultClass != null || candidateClass == null)
{
// Each row of the ResultSet is either an instance of resultClass, or Object[]
rof = getResultObjectFactoryForNoCandidateClass(rs, resultClass);
}
else
{
// Each row of the ResultSet is an instance of the candidate class
rof = getResultObjectFactoryForCandidateClass(rs);
}
// Return the associated type of results depending on whether scrollable or not
String resultSetType = RDBMSQueryUtils.getResultSetTypeForQuery(this);
if (resultSetType.equals("scroll-insensitive") ||
resultSetType.equals("scroll-sensitive"))
{
qr = new ScrollableQueryResult(this, rof, rs, null);
}
else
{
qr = new ForwardQueryResult(this, rof, rs, null);
}
final QueryResult qr1 = qr;
final ManagedConnection mconn1 = mconn;
mconn.addListener(new ManagedConnectionResourceListener()
{
public void transactionFlushed(){}
public void transactionPreClose(){}
{
qr1.disconnect();
}
public void managedConnectionPreClose(){}
public void managedConnectionPostClose(){}
public void resourcePostClose()
{
mconn1.removeListener(this);
}
});
}
finally
{
if (qr == null)
{
rs.close();
}
}
}
catch (QueryInterruptedException qie)
{
// Execution was cancelled so cancel the PreparedStatement
ps.cancel();
throw qie;
}
finally
{
if (qr == null)
{
sqlControl.closeStatement(mconn, ps);
}
}
}
finally
{