public void executeClear(ObjectProvider ownerOP) {
    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 (getRelationDiscriminatorMapping() != 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);
    }
  }
  /**
   * 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);
        }
      }
    }
  }
  public int getSize(ObjectProvider ownerOP) {
    int numRows;

    String sizeStmt = getSizeStmt();
    try {
      ExecutionContext ec = ownerOP.getExecutionContext();
      ManagedConnection mconn = storeMgr.getConnection(ec);
      SQLController sqlControl = storeMgr.getSQLController();
      try {
        PreparedStatement ps = sqlControl.getStatementForQuery(mconn, sizeStmt);
        try {
          int jdbcPosition = 1;
          jdbcPosition =
              BackingStoreHelper.populateOwnerInStatement(ownerOP, ec, ps, jdbcPosition, this);
          if (getElementInfo() != null && getElementInfo().length == 1) {
            // TODO Allow for multiple element types (e.g interface implementations)
            for (int i = 0; i < getElementInfo().length; i++) {
              if (getElementInfo()[i].getDiscriminatorMapping() != null) {
                jdbcPosition =
                    BackingStoreHelper.populateElementDiscriminatorInStatement(
                        ec, ps, jdbcPosition, true, getElementInfo()[i], clr);
              }
            }
          }
          if (getRelationDiscriminatorMapping() != null) {
            jdbcPosition =
                BackingStoreHelper.populateRelationDiscriminatorInStatement(
                    ec, ps, jdbcPosition, this);
          }

          ResultSet rs = sqlControl.executeStatementQuery(ec, mconn, sizeStmt, ps);
          try {
            if (!rs.next()) {
              throw new NucleusDataStoreException(Localiser.msg("056007", sizeStmt));
            }

            numRows = rs.getInt(1);
            JDBCUtils.logWarnings(rs);
          } finally {
            rs.close();
          }
        } finally {
          sqlControl.closeStatement(mconn, ps);
        }
      } finally {
        mconn.release();
      }
    } catch (SQLException e) {
      throw new NucleusDataStoreException(Localiser.msg("056007", sizeStmt), e);
    }

    return numRows;
  }
  public int getSize(ObjectProvider ownerOP) {
    int numRows;

    String sizeStmt = getSizeStmt();
    try {
      ExecutionContext ec = ownerOP.getExecutionContext();
      ManagedConnection mconn = storeMgr.getConnection(ec);
      SQLController sqlControl = storeMgr.getSQLController();
      try {
        PreparedStatement ps = sqlControl.getStatementForQuery(mconn, sizeStmt);
        try {
          int jdbcPosition = 1;
          if (elementInfo == null) {
            jdbcPosition =
                BackingStoreHelper.populateOwnerInStatement(ownerOP, ec, ps, jdbcPosition, this);
          } else {
            if (usingJoinTable()) {
              jdbcPosition =
                  BackingStoreHelper.populateOwnerInStatement(ownerOP, ec, ps, jdbcPosition, this);
              if (elementInfo[0].getDiscriminatorMapping() != null) {
                jdbcPosition =
                    BackingStoreHelper.populateElementDiscriminatorInStatement(
                        ec, ps, jdbcPosition, true, elementInfo[0], clr);
              }
              if (relationDiscriminatorMapping != null) {
                jdbcPosition =
                    BackingStoreHelper.populateRelationDiscriminatorInStatement(
                        ec, ps, jdbcPosition, this);
              }
            } else {
              for (int i = 0; i < elementInfo.length; i++) {
                jdbcPosition =
                    BackingStoreHelper.populateOwnerInStatement(
                        ownerOP, ec, ps, jdbcPosition, this);
                if (elementInfo[i].getDiscriminatorMapping() != null) {
                  jdbcPosition =
                      BackingStoreHelper.populateElementDiscriminatorInStatement(
                          ec, ps, jdbcPosition, true, elementInfo[i], clr);
                }
                if (relationDiscriminatorMapping != null) {
                  jdbcPosition =
                      BackingStoreHelper.populateRelationDiscriminatorInStatement(
                          ec, ps, jdbcPosition, this);
                }
              }
            }
          }

          ResultSet rs = sqlControl.executeStatementQuery(ec, mconn, sizeStmt, ps);
          try {
            if (!rs.next()) {
              throw new NucleusDataStoreException(Localiser.msg("056007", sizeStmt));
            }

            numRows = rs.getInt(1);

            if (elementInfo != null && elementInfo.length > 1) {
              while (rs.next()) {
                numRows = numRows + rs.getInt(1);
              }
            }

            JDBCUtils.logWarnings(rs);
          } finally {
            rs.close();
          }
        } catch (SQLException sqle) {
          NucleusLogger.GENERAL.error("Exception in size", sqle);
          throw sqle;
        } finally {
          sqlControl.closeStatement(mconn, ps);
        }
      } finally {
        mconn.release();
      }
    } catch (SQLException e) {
      throw new NucleusDataStoreException(Localiser.msg("056007", sizeStmt), e);
    }

    return numRows;
  }