MentaBean

Compare Revisions

Ignore whitespace Rev 201 → Rev 202

/trunk/src/main/java/org/mentabean/jdbc/PostgreSQLBeanSession.java
68,11 → 68,59
if (seqField == null) {
//find autoincrement field
super.insert(bean);
dispatchAfterInsert(bean);
final DBField autoIncrement = bc.getAutoIncrementField();
 
if (autoIncrement == null) {
 
dispatchAfterInsert(bean);
return;
}
return;
PreparedStatement stmt = null;
 
ResultSet rset = null;
StringBuilder sb = new StringBuilder("select lastval();");
try {
 
stmt = conn.prepareStatement(sb.toString());
 
rset = stmt.executeQuery();
 
if (rset.next()) {
 
final long id = rset.getLong(1);
try {
 
injectValue(bean, autoIncrement.getName(), id, Integer.class);
} catch(Exception e) {
// try long as well:
injectValue(bean, autoIncrement.getName(), id, Long.class);
}
dispatchAfterInsert(bean);
return;
}
 
} catch (Exception e) {
 
throw new BeanException(e);
 
} finally {
 
close(stmt, rset);
}
}
String seqName = bc.getSequenceName();