if (pk == null)
throw new InvalidStateException(_loc.get("bad-seq-type",
getClass(), mapping));
DBDictionary dict = _conf.getDBDictionaryInstance();
SQLBuffer where = new SQLBuffer(dict).append(_pkColumn).append(" = ").
appendValue(pk, _pkColumn);
// loop until we have a successful atomic select/update sequence
long cur = 0;
PreparedStatement stmnt;
ResultSet rs;
SQLBuffer upd;
for (int updates = 0; updates == 0;) {
stmnt = null;
rs = null;
try {
cur = getSequence(mapping, conn);
if (cur == -1)
return false;
// update the value
upd = new SQLBuffer(dict);
String tableName = resolveTableName(mapping, _seqColumn.getTable());
upd.append("UPDATE ").append(tableName).
append(" SET ").append(_seqColumn).append(" = ").
appendValue(Numbers.valueOf(cur + inc), _seqColumn).
append(" WHERE ").append(where).append(" AND ").
append(_seqColumn).append(" = ").
appendValue(Numbers.valueOf(cur), _seqColumn);
stmnt = upd.prepareStatement(conn);
updates = stmnt.executeUpdate();
} finally {
if (rs != null)
try { rs.close(); } catch (SQLException se) {}
if (stmnt != null)