PreparedStatementManager psMgr, Collection updates) throws SQLException { if (!row.isValid()) return updates; if (row.getAction() == Row.ACTION_DELETE) { psMgr.flush(row); return updates; ForeignKey[] fks = row.getTable().getForeignKeys(); OpenJPAStateManager sm; PrimaryRow rel; PrimaryRow update; for (int i = 0; i < fks.length; i++) { sm = row.getForeignKeySet(fks[i]); if (sm == null) continue; if (rel == null || !rel.isValid() || rel.getIndex() < row.getIndex() || (rel == row && !fks[i].isDeferred() && !fks[i].isLogical())) continue; update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null); if (row.getAction() == Row.ACTION_INSERT) update.wherePrimaryKey(row.getPrimaryKey()); else row.copyInto(update, true); update.setForeignKey(fks[i], row.getForeignKeyIO(fks[i]), sm);
public void setForeignKey(ForeignKey fk, ColumnIO io, OpenJPAStateManager sm) throws SQLException { if (!delayForeignKey(fk, sm, true)) super.setForeignKey(fk, io, sm); else recordForeignKey(fk, io, sm, true); }
PrimaryRow row, Collection updates) throws SQLException { if (!row.isValid()) return updates; ForeignKey[] fks = row.getTable().getForeignKeys(); OpenJPAStateManager sm; PrimaryRow rel; for (int i = 0; i < fks.length; i++) { sm = row.getForeignKeySet(fks[i]); if (sm == null) sm = row.getForeignKeyWhere(fks[i]); if (sm == null) continue; if (rel == null || !rel.isValid() || rel.getIndex() >= row.getIndex()) continue; update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null); row.copyInto(update, true); update.setForeignKey(fks[i], row.getForeignKeyIO(fks[i]), null); if (updates == null) updates = new ArrayList();
public String toString() { StringBuilder buf = new StringBuilder(); buf.append("PrimaryRow["); switch (getAction()) { case ACTION_UPDATE: buf.append("UPDATE"); break; case ACTION_INSERT: buf.append("INSERT"); break; case ACTION_DELETE: buf.append("DELETE"); break; default: buf.append("UNKNOWN"); } buf.append(" ").append(getTable().getName()).append("]: "); buf.append(_pk); return buf.toString(); } }
update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null); if (row.getAction() == Row.ACTION_INSERT) { if (row.getPrimaryKey() == null) throw new InternalException(_loc.get("ref-cycle")); update.wherePrimaryKey(row.getPrimaryKey()); } else { row.copyInto(update, true); update.setForeignKey(fk, row.getForeignKeyIO(fk), row.getForeignKeySet(fk)); row.clearForeignKey(fk); } else { col = (Column) edge.getUserObject(); update.setRelationId(col, row.getRelationIdSet(col), row.getRelationIdCallback(col)); row.clearRelationId(col);
/** * Break a circular dependency caused by delete operations. * If deleted row A has a ciricular fk to deleted row B, then use an update * statement to null A's fk to B before deleting B, then delete A. * @param edge Edge in the dependency graph corresponding to a foreign key * constraint. This dependency is broken by nullifying the foreign key. * @param deleteUpdates Collection of update statements that are executed * before the delete operations are flushed */ private void addDeleteUpdate(Edge edge, Collection deleteUpdates) throws SQLException { PrimaryRow row; RowImpl update; ForeignKey fk; // copy where conditions into new update that nulls the fk row = (PrimaryRow) edge.getTo(); update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null); row.copyInto(update, true); if (edge.getUserObject() instanceof ForeignKey) { fk = (ForeignKey) edge.getUserObject(); update.setForeignKey(fk, row.getForeignKeyIO(fk), null); } else update.setNull((Column) edge.getUserObject()); deleteUpdates.add(update); }
if (set) { if (canSetAny(io, fk.getColumns().length + fk.getConstantColumns().length, false)) setValid(true); _fkSet = new OpenJPAStateManager[getTable(). getForeignKeys().length]; _fkSet[fk.getIndex()] = sm; else if (io != null && ((getAction() == ACTION_INSERT && !io.isAllInsertable(fk, false)) || (getAction() != ACTION_INSERT && !io.isAllUpdatable(fk, false)))) { _fkIO = new ColumnIO[_fkSet.length]; if (getAction() == ACTION_DELETE) setValid(true); _fkWhere = new OpenJPAStateManager[getTable(). getForeignKeys().length]; _fkWhere[fk.getIndex()] = sm;
&& _row != null && _row.getAction() == action) return _row; _row = new PrimaryRow(table, action, sm); map.put(_key, _row); if (_primaryOrder != null) { _row.setIndex(_primaryOrder.size()); _primaryOrder.add(_row); _row.setFailedObject(sm.getManagedInstance()); return _row;
for (Iterator itr = rows.iterator(); itr.hasNext();) { row = (PrimaryRow) itr.next(); if (!row.isValid()) continue; fks = row.getTable().getForeignKeys(); for (int j = 0; j < fks.length; j++) { if (row.getForeignKeySet(fks[j]) == null) continue; Row.ACTION_INSERT, row.getForeignKeySet(fks[j]), false); if (row2 != null && row2.isValid() && (row2 != row || fks[j].isDeferred() || fks[j].isLogical())) cols = row.getTable().getRelationIdColumns(); for (int j = 0; j < cols.length; j++) { OpenJPAStateManager sm = row.getRelationIdSet(cols[j]); if (sm == null) continue;
for (Iterator itr = deletes.iterator(); itr.hasNext();) { row = (PrimaryRow) itr.next(); if (!row.isValid()) continue; fks = row.getTable().getForeignKeys(); for (int j = 0; j < fks.length; j++) { fkVal = row.getForeignKeySet(fks[j]); if (fkVal == null) fkVal = row.getForeignKeyWhere(fks[j]); if (fkVal == null) continue;
if (row.getAction() == Row.ACTION_DELETE) { addDeleteUpdate(breakableLink, deleteUpdates); } else {
protected RowImpl newInstance(Column[] cols, int action) { return new PrimaryRow(cols, action, _pk); }
update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null); if (row.getAction() == Row.ACTION_INSERT) { if (row.getPrimaryKey() == null) throw new InternalException(_loc.get("ref-cycle")); update.wherePrimaryKey(row.getPrimaryKey()); } else { row.copyInto(update, true); update.setForeignKey(fk, row.getForeignKeyIO(fk), row.getForeignKeySet(fk)); row.clearForeignKey(fk); } else { col = (Column) edge.getUserObject(); update.setRelationId(col, row.getRelationIdSet(col), row.getRelationIdCallback(col)); row.clearRelationId(col);
/** * Break a circular dependency caused by delete operations. * If deleted row A has a ciricular fk to deleted row B, then use an update * statement to null A's fk to B before deleting B, then delete A. * @param edge Edge in the dependency graph corresponding to a foreign key * constraint. This dependency is broken by nullifying the foreign key. * @param deleteUpdates Collection of update statements that are executed * before the delete operations are flushed */ private void addDeleteUpdate(Edge edge, Collection deleteUpdates) throws SQLException { PrimaryRow row; RowImpl update; ForeignKey fk; // copy where conditions into new update that nulls the fk row = (PrimaryRow) edge.getTo(); update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null); row.copyInto(update, true); if (edge.getUserObject() instanceof ForeignKey) { fk = (ForeignKey) edge.getUserObject(); update.setForeignKey(fk, row.getForeignKeyIO(fk), null); } else update.setNull((Column) edge.getUserObject()); deleteUpdates.add(update); }
if (set) { if (canSetAny(io, fk.getColumns().length + fk.getConstantColumns().length, false)) setValid(true); _fkSet = new OpenJPAStateManager[getTable(). getForeignKeys().length]; _fkSet[fk.getIndex()] = sm; else if (io != null && ((getAction() == ACTION_INSERT && !io.isAllInsertable(fk, false)) || (getAction() != ACTION_INSERT && !io.isAllUpdatable(fk, false)))) { _fkIO = new ColumnIO[_fkSet.length]; if (getAction() == ACTION_DELETE) setValid(true); _fkWhere = new OpenJPAStateManager[getTable(). getForeignKeys().length]; _fkWhere[fk.getIndex()] = sm;
&& _row != null && _row.getAction() == action) return _row; _row = new PrimaryRow(table, action, sm); map.put(_key, _row); if (_primaryOrder != null) { _row.setIndex(_primaryOrder.size()); _primaryOrder.add(_row); _row.setFailedObject(sm.getManagedInstance()); return _row;
for (Iterator itr = rows.iterator(); itr.hasNext();) { row = (PrimaryRow) itr.next(); if (!row.isValid()) continue; fks = row.getTable().getForeignKeys(); for (int j = 0; j < fks.length; j++) { if (row.getForeignKeySet(fks[j]) == null) continue; Row.ACTION_INSERT, row.getForeignKeySet(fks[j]), false); if (row2 != null && row2.isValid() && (row2 != row || fks[j].isDeferred() || fks[j].isLogical())) cols = row.getTable().getRelationIdColumns(); for (int j = 0; j < cols.length; j++) { OpenJPAStateManager sm = row.getRelationIdSet(cols[j]); if (sm == null) continue;
for (Iterator itr = deletes.iterator(); itr.hasNext();) { row = (PrimaryRow) itr.next(); if (!row.isValid()) continue; fks = row.getTable().getForeignKeys(); for (int j = 0; j < fks.length; j++) { fkVal = row.getForeignKeySet(fks[j]); if (fkVal == null) fkVal = row.getForeignKeyWhere(fks[j]); if (fkVal == null) continue;