Search in sources :

Example 1 with UpdateJoinTableDesc

use of com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateJoinTableDesc in project Payara by payara.

the class UpdateQueryPlan method processJoinTables.

private void processJoinTables() {
    Collection fields = updateDesc.getUpdatedJoinTableFields();
    if (fields == null)
        return;
    Iterator fieldIter = fields.iterator();
    ArrayList deleteStatements = new ArrayList();
    ArrayList insertStatements = new ArrayList();
    while (fieldIter.hasNext()) {
        ForeignFieldDesc f = (ForeignFieldDesc) fieldIter.next();
        Collection descs = updateDesc.getUpdateJoinTableDescs(f);
        Iterator descIter = descs.iterator();
        ColumnElement c = (ColumnElement) f.assocLocalColumns.get(0);
        QueryTable t = addQueryTable(config.findTableDesc(c.getDeclaringTable()));
        while (descIter.hasNext()) {
            UpdateJoinTableDesc desc = (UpdateJoinTableDesc) descIter.next();
            int action = getAction(desc.getAction());
            UpdateStatement s = (UpdateStatement) createStatement(t);
            s.setAction(action);
            if (action == ACT_INSERT) {
                insertStatements.add(s);
            } else if (action == ACT_DELETE) {
                // RESOLVE: There are redundant deletes from join tables that causes
                // update to fail with no rows affected. To work around this problem
                // for now, we set the minAffectedRows to 0.
                // We need to figure out why there are redundant deletes.
                s.minAffectedRows = 0;
                deleteStatements.add(s);
            }
            s.addLocalConstraints(action, f, desc.getParentStateManager());
            s.addForeignConstraints(action, f, desc.getForeignStateManager());
        }
    }
    // All join table delete statements have to go first and all
    // join table insert statements have to go last.
    ArrayList oldStatements = statements;
    statements = deleteStatements;
    statements.addAll(oldStatements);
    statements.addAll(insertStatements);
}
Also used : UpdateJoinTableDesc(com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateJoinTableDesc) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ColumnElement(org.netbeans.modules.dbschema.ColumnElement)

Aggregations

UpdateJoinTableDesc (com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateJoinTableDesc)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 ColumnElement (org.netbeans.modules.dbschema.ColumnElement)1