While working on this patch, I used the Select class hierarchy to generate select query. Previously the QueryExpression class was generating sql select query. But the query is being generated by SQLSelectInsertCheck by itself. The difference is as follows
old query SELECT 1 FROM test87_extended WHERE test87_extended.id=? FOR UPDATE
new query SELECT test87_extended.id FROM test87_extended WHERE test87_extended.id=?
The method for creating the old query is
/**
* Build SQL statement to check for duplicate keys.
*
* @throws MappingException If unable to get query from QueryExpression.
*/
private void buildStatement() throws MappingException {
try {
QueryExpression query = _factory.getQueryExpression();
for (int i = 0; i < _ids.length; i++) {
query.addParameter(_mapTo, _ids[i].getName(), QueryExpression.OP_EQUALS);
}
_statement = query.getStatement(true);
} catch (QueryException except) {
LOG.warn("Problem building SQL", except);
throw new MappingException(except);
}
}
The method for creating new query is
/**
* Build SQL statement to check for duplicate keys.
*
* @param mapTo Table name from which records need to be fetched.
*/
private void buildStatement(final String mapTo) {
Select select = new Select(mapTo);
select.addSelect(mapTo, _ids[0].getName());
for (int i = 0; i < _ids.length; i++) {
select.addCondition(mapTo, _ids[i].getName());
}
select.toString(_ctx);
}
In our usecase, I think we do not 'FOR UPDATE' clause in the end of select. What do you think...
Is this the correct way?
Regards.
CASTOR-2774should be resolved first