{
ExecutionContext ec = ownerSM.getExecutionContext();
Transaction tx = ec.getTransaction();
boolean useUpdateLock = tx.lockReadObjects();
StatementClassMapping resultDefinition = null;
StatementParameterMapping paramDefinition = null;
String stmt = null;
if (startIdx < 0 && endIdx < 0)
{
// Iteration of all elements - cached
if (iteratorStmtLocked == null)
{
synchronized (this)
{
// Generate the statement, and statement mapping/parameter information
iteratorMappingDef = new StatementClassMapping();
iteratorMappingParams = new StatementParameterMapping();
SQLStatement sqlStmt = getSQLStatementForIterator(ownerSM, startIdx, endIdx,
iteratorMappingDef, iteratorMappingParams);
iteratorStmtUnlocked = sqlStmt.getSelectStatement().toSQL();
sqlStmt.addExtension("lock-for-update", true);
iteratorStmtLocked = sqlStmt.getSelectStatement().toSQL();
}
}
resultDefinition = iteratorMappingDef;
paramDefinition = iteratorMappingParams;
stmt = (useUpdateLock ? iteratorStmtLocked : iteratorStmtUnlocked);
}
else
{
// Iteration over a range so generate statement on the fly (uncached)
resultDefinition = new StatementClassMapping();
paramDefinition = new StatementParameterMapping();
SQLStatement sqlStmt = getSQLStatementForIterator(ownerSM, startIdx, endIdx, resultDefinition,
paramDefinition);
sqlStmt.addExtension("lock-for-update", useUpdateLock);
stmt = sqlStmt.getSelectStatement().toSQL();