for (int i = 0; i < getCacheSize(); i++) {
stmt.executeUpdate(getIncrementStatement());
ResultSet rs = stmt.executeQuery("select @@identity");
try {
if (!rs.next()) {
throw new DataAccessResourceFailureException("@@identity failed after executing an update");
}
this.valueCache[i] = rs.getLong(1);
}
finally {
JdbcUtils.closeResultSet(rs);
}
}
long maxValue = this.valueCache[(this.valueCache.length - 1)];
stmt.executeUpdate("delete from " + getIncrementerName() + " where " + getColumnName() + " < " + maxValue);
}
catch (SQLException ex) {
throw new DataAccessResourceFailureException("Could not increment identity", ex);
}
finally {
JdbcUtils.closeStatement(stmt);
DataSourceUtils.releaseConnection(con, getDataSource());
}