JDBCEntityBridge.FieldIterator lockedIterator = null;
if (hasLockedFields) {
lockedIterator = entity.getLockedIterator(ctx);
while (lockedIterator.hasNext()) {
sql.append(SQLUtil.AND);
JDBCCMPFieldBridge field = lockedIterator.next();
if (field.getLockedValue(ctx) == null) {
SQLUtil.getIsNullClause(false, field, "", sql);
lockedIterator.remove();
} else {
SQLUtil.getWhereClause(field, sql);
}
}
}
Connection con = null;
PreparedStatement ps = null;
int rowsAffected = 0;
try {
// create the statement
if (log.isDebugEnabled()) {
log.debug("Executing SQL: " + sql);
}
// get the connection
con = entity.getDataSource().getConnection();
ps = con.prepareStatement(sql.toString());
// SET: set the dirty fields parameters
int index = 1;
dirtyIterator.reset();
while (dirtyIterator.hasNext()) {
index = dirtyIterator.next().setInstanceParameters(ps, index, ctx);
}
// WHERE: set primary key fields
index = entity.setPrimaryKeyParameters(ps, index, ctx.getPrimaryKey());
// WHERE: set optimistically locked field values
if (hasLockedFields) {
lockedIterator.reset();
while (lockedIterator.hasNext()) {
JDBCCMPFieldBridge field = lockedIterator.next();
Object value = field.getLockedValue(ctx);
index = field.setArgumentParameters(ps, index, value);
}
}
// execute statement
rowsAffected = ps.executeUpdate();