Пример #1
0
  /**
   * Method to add an element to the TreeSet.
   *
   * @param element The new element
   * @return Whether it was added ok.
   */
  public boolean add(Object element) {
    // Reject inappropriate elements
    if (!allowNulls && element == null) {
      throw new NullPointerException(
          "Nulls not allowed for collection at field "
              + ownerMmd.getName()
              + " but element is null");
    }

    if (useCache) {
      loadFromStore();
    }
    if (contains(element)) {
      return false;
    }

    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
      // Relationship management
      ownerOP
          .getExecutionContext()
          .getRelationshipManager(ownerOP)
          .relationAdd(ownerMmd.getAbsoluteFieldNumber(), element);
    }

    boolean backingSuccess = true;
    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(queued, ownerOP)) {
        ownerOP
            .getExecutionContext()
            .addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
      } else {
        try {
          backingStore.add(ownerOP, element, (useCache ? delegate.size() : -1));
        } catch (NucleusDataStoreException dse) {
          NucleusLogger.PERSISTENCE.warn(LOCALISER.msg("023013", "add", ownerMmd.getName(), dse));
          backingSuccess = false;
        }
      }
    }

    // Only make it dirty after adding the field to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before
    // completing the addition
    makeDirty();

    boolean delegateSuccess = delegate.add(element);

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return (backingStore != null ? backingSuccess : delegateSuccess);
  }