コード例 #1
0
  /**
   * Clear the association from owner to all elements. Provides cascade-delete when the elements
   * being deleted are PC types.
   *
   * @param ownerOP ObjectProvider for the container.
   */
  public void clear(ObjectProvider ownerOP) {
    Collection dependentElements = null;
    CollectionMetaData collmd = ownerMemberMetaData.getCollection();
    boolean dependent = collmd.isDependentElement();
    if (ownerMemberMetaData.isCascadeRemoveOrphans()) {
      dependent = true;
    }
    if (dependent && !collmd.isEmbeddedElement() && !collmd.isSerializedElement()) {
      // Retain the dependent elements that need deleting after clearing
      dependentElements = new HashSet();
      Iterator iter = iterator(ownerOP);
      while (iter.hasNext()) {
        dependentElements.add(iter.next());
      }
    }
    executeClear(ownerOP);

    // Cascade-delete
    if (dependentElements != null && dependentElements.size() > 0) {
      Iterator iter = dependentElements.iterator();
      while (iter.hasNext()) {
        Object obj = iter.next();
        if (ownerOP.getExecutionContext().getApiAdapter().isDeleted(obj)) {
          // Element is tagged for deletion so will be deleted at flush(), and we dont need it
          // immediately
        } else {
          ownerOP.getExecutionContext().deleteObjectInternal(obj);
        }
      }
    }
  }
コード例 #2
0
  /**
   * Clear the association from owner to all elements. Provides cascade-delete when the elements
   * being deleted are PC types.
   *
   * @param ownerOP ObjectProvider for the container.
   */
  public void clear(ObjectProvider ownerOP) {
    Collection dependentElements = null;
    CollectionMetaData collmd = ownerMemberMetaData.getCollection();
    boolean dependent = collmd.isDependentElement();
    if (ownerMemberMetaData.isCascadeRemoveOrphans()) {
      dependent = true;
    }
    if (dependent && !collmd.isEmbeddedElement() && !collmd.isSerializedElement()) {
      // Retain the dependent elements that need deleting after clearing
      dependentElements = new HashSet();
      Iterator iter = iterator(ownerOP);
      while (iter.hasNext()) {
        dependentElements.add(iter.next());
      }
    }

    String clearStmt = getClearStmt();
    try {
      ExecutionContext ec = ownerOP.getExecutionContext();
      ManagedConnection mconn = storeMgr.getConnection(ec);
      SQLController sqlControl = storeMgr.getSQLController();
      try {
        PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, clearStmt, false);
        try {
          int jdbcPosition = 1;
          jdbcPosition =
              BackingStoreHelper.populateOwnerInStatement(ownerOP, ec, ps, jdbcPosition, this);
          if (relationDiscriminatorMapping != null) {
            BackingStoreHelper.populateRelationDiscriminatorInStatement(ec, ps, jdbcPosition, this);
          }

          sqlControl.executeStatementUpdate(ec, mconn, clearStmt, ps, true);
        } finally {
          sqlControl.closeStatement(mconn, ps);
        }
      } finally {
        mconn.release();
      }
    } catch (SQLException e) {
      throw new NucleusDataStoreException(Localiser.msg("056013", clearStmt), e);
    }

    // Cascade-delete
    if (dependentElements != null && dependentElements.size() > 0) {
      Iterator iter = dependentElements.iterator();
      while (iter.hasNext()) {
        Object obj = iter.next();
        if (ownerOP.getExecutionContext().getApiAdapter().isDeleted(obj)) {
          // Element is tagged for deletion so will be deleted at flush(), and we dont need it
          // immediately
        } else {
          ownerOP.getExecutionContext().deleteObjectInternal(obj);
        }
      }
    }
  }