this.pkSql = "";
}
public Object execute(Method m, Object[] args, CmpEntityBeanContext ctx) throws CreateException {
Object pk;
PersistentContext pctx = (PersistentContext) ctx.getPersistenceContext();
if (ctx.getPrimaryKey() == null) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
if (log.isDebugEnabled()) {
log.debug("executing sql: " + pkSql);
}
con = entityBridge.getDataSource().getConnection();
ps = con.prepareStatement(pkSql);
rs = ps.executeQuery();
if (!rs.next()) {
throw CmpMessages.MESSAGES.pkSqlReturnedNoResults(pkSql);
}
pk = pkField.loadArgumentResults(rs, 1);
pctx.setFieldValue(pkField.getRowIndex(), pk);
pk = entityBridge.extractPrimaryKeyFromInstance(ctx);
} catch (SQLException e) {
throw CmpMessages.MESSAGES.failedToExecutePkSql(e);
} finally {
JDBCUtil.safeClose(rs);
JDBCUtil.safeClose(ps);
JDBCUtil.safeClose(con);
}
if (pk == null) {
throw CmpMessages.MESSAGES.pkIsNullForCreatedInstance();
}
pctx.setPk(pk);
} else {
// insert-after-ejb-post-create
try {
pctx.flush();
} catch (SQLException e) {
if ("23000".equals(e.getSQLState())) {
throw CmpMessages.MESSAGES.uniqueKeyViolation(ctx.getPrimaryKey());
} else {
throw CmpMessages.MESSAGES.failedToCreateInstance(ctx.getPrimaryKey(), e);