protected int executeInsert(int paramIndex,
PreparedStatement ps,
EntityEnterpriseContext ctx) throws SQLException {
int rows = ps.executeUpdate();
// remove any JCA wrappers
Statement stmt = ps;
do
{
try
{
Object[] args = {};
stmt = (Statement) getUnderlyingStatement.invoke(stmt, args);
}
catch (IllegalAccessException e)
{
SQLException ex = new SQLException("Failed to invoke getUnderlyingStatement");
ex.initCause(e);
throw ex;
}
catch (InvocationTargetException e)
{
SQLException ex = new SQLException("Failed to invoke getUnderlyingStatement");
ex.initCause(e);
throw ex;
}
} while (stmt != null && method.getDeclaringClass().isInstance(stmt) == false);
ResultSet rs = null;
try
{
rs = (ResultSet) method.invoke(stmt, null);
if (!rs.next())
{
throw new EJBException("getGeneratedKeys returned an empty ResultSet");
}
pkField.loadInstanceResults(rs, 1, ctx);
}
catch (RuntimeException e)
{
throw e;
}
catch (Exception e)
{
// throw EJBException to force a rollback as the row has been inserted
throw new EJBException("Error extracting generated keys", e);
}
finally
{
JDBCUtil.safeClose(rs);
}
return rows;
}
|