* Throws an exception by default if {@link #lastGeneratedKeyQuery} is null.
*/
public Object getGeneratedKey(Column col, Connection conn)
throws SQLException {
if (lastGeneratedKeyQuery == null)
throw new StoreException(_loc.get("no-auto-assign"));
// replace things like "SELECT MAX({0}) FROM {1}"
String query = lastGeneratedKeyQuery;
if (query.indexOf('{') != -1) // only if the token is in the string
{
query = MessageFormat.format(query, new Object[]{
col.getName(), getFullName(col.getTable(), false),
getGeneratedKeySequenceName(col),
});
}
PreparedStatement stmnt = conn.prepareStatement(query);
ResultSet rs = null;
try {
rs = stmnt.executeQuery();
if (!rs.next())
throw new StoreException(_loc.get("no-genkey"));
Object key = rs.getObject(1);
if (key == null)
log.warn(_loc.get("invalid-genkey", col));
return key;
} finally {