Example #1
0
  /**
   * Constructor, using the ObjectProvider of the "owner" and the field name.
   *
   * @param op The owner ObjectProvider
   * @param mmd Metadata for the member
   */
  public ArrayList(ObjectProvider op, AbstractMemberMetaData mmd) {
    super(op, mmd);

    // Set up our delegate
    this.delegate = new java.util.ArrayList();

    ExecutionContext ec = op.getExecutionContext();
    allowNulls = SCOUtils.allowNullsInContainer(allowNulls, mmd);
    queued = ec.isDelayDatastoreOperationsEnabled();
    useCache = SCOUtils.useContainerCache(op, mmd);

    if (!SCOUtils.collectionHasSerialisedElements(mmd)
        && mmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT) {
      ClassLoaderResolver clr = ec.getClassLoaderResolver();
      this.backingStore =
          (ListStore)
              ((BackedSCOStoreManager) op.getStoreManager())
                  .getBackingStoreForField(clr, mmd, java.util.ArrayList.class);
    }

    if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
      NucleusLogger.PERSISTENCE.debug(
          SCOUtils.getContainerInfoMessage(
              op,
              ownerMmd.getName(),
              this,
              useCache,
              queued,
              allowNulls,
              SCOUtils.useCachedLazyLoading(op, ownerMmd)));
    }
  }
Example #2
0
  /**
   * Constructor, using the ObjectProvider of the "owner" and the field name.
   *
   * @param op The owner ObjectProvider
   * @param mmd Metadata for the member
   */
  public Map(ObjectProvider op, AbstractMemberMetaData mmd) {
    super(op, mmd);

    // Set up our "delegate"
    this.delegate = new java.util.HashMap();

    ExecutionContext ec = ownerOP.getExecutionContext();
    allowNulls = SCOUtils.allowNullsInContainer(allowNulls, mmd);
    useCache = SCOUtils.useContainerCache(ownerOP, mmd);

    if (!SCOUtils.mapHasSerialisedKeysAndValues(mmd)
        && mmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT) {
      ClassLoaderResolver clr = ec.getClassLoaderResolver();
      this.backingStore =
          (MapStore)
              ((BackedSCOStoreManager) ownerOP.getStoreManager())
                  .getBackingStoreForField(clr, mmd, java.util.Map.class);
    }

    if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
      NucleusLogger.PERSISTENCE.debug(
          SCOUtils.getContainerInfoMessage(
              ownerOP,
              ownerMmd.getName(),
              this,
              useCache,
              allowNulls,
              SCOUtils.useCachedLazyLoading(ownerOP, ownerMmd)));
    }
  }
  /**
   * Method to remove an element from the List
   *
   * @param element The Element to remove
   * @return Whether it was removed successfully.
   */
  public boolean remove(Object element, boolean allowCascadeDelete) {
    boolean success = delegate.remove(element);
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
      ownerOP
          .getExecutionContext()
          .getRelationshipManager(ownerOP)
          .relationRemove(ownerMmd.getAbsoluteFieldNumber(), element);
    }

    if (ownerOP != null && allowCascadeDelete) {
      // Cascade delete
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        // Queue the cascade delete
        ownerOP
            .getExecutionContext()
            .addOperationToQueue(
                new CollectionRemoveOperation(
                    ownerOP, ownerMmd.getAbsoluteFieldNumber(), element, allowCascadeDelete));
      } else if (SCOUtils.hasDependentElement(ownerMmd)) {
        // Perform the cascade delete
        ownerOP.getExecutionContext().deleteObjectInternal(element);
      }
    }

    if (success) {
      makeDirty();
      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }
    }

    return success;
  }
Example #4
0
  /**
   * Method to remove a collection of elements from the List.
   *
   * @param elements Collection of elements to remove
   * @return Whether it was successful.
   */
  public boolean removeAll(Collection elements) {
    makeDirty();

    if (useCache) {
      loadFromStore();
    }

    int size = (useCache ? delegate.size() : -1);
    Collection contained = null;
    if (backingStore != null && SCOUtils.useQueuedUpdate(queued, ownerOP)) {
      // Check which are contained before updating the delegate
      contained = new java.util.HashSet();
      for (Object elem : elements) {
        if (contains(elem)) {
          contained.add(elem);
        }
      }
    }
    boolean delegateSuccess = delegate.removeAll(elements);

    if (backingStore != null) {
      boolean backingSuccess = true;
      if (SCOUtils.useQueuedUpdate(queued, ownerOP)) {
        backingSuccess = false;
        for (Object element : contained) {
          backingSuccess = true;
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new CollectionRemoveOperation(ownerOP, backingStore, element, true));
        }
      } else {
        try {
          backingSuccess = backingStore.removeAll(ownerOP, elements, size);
        } catch (NucleusDataStoreException dse) {
          NucleusLogger.PERSISTENCE.warn(
              Localiser.msg("023013", "removeAll", ownerMmd.getName(), dse));
          backingSuccess = false;
        }
      }

      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }

      return backingSuccess;
    }

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return delegateSuccess;
  }
  /**
   * Method to return an attached copy of the passed (detached) value. The returned attached copy is
   * a SCO wrapper. Goes through the existing elements in the store for this owner field and removes
   * ones no longer present, and adds new elements. All elements in the (detached) value are
   * attached.
   *
   * @param value The new (collection) value
   */
  public void attachCopy(java.util.LinkedHashSet value) {
    boolean elementsWithoutIdentity = SCOUtils.collectionHasElementsWithoutIdentity(ownerMmd);
    SCOUtils.attachCopyElements(ownerOP, this, value, elementsWithoutIdentity);

    /*        // Remove any no-longer-needed elements from this collection
    SCOUtils.attachRemoveDeletedElements(ownerOP.getExecutionContext().getApiAdapter(), this, c, elementsWithoutIdentity);

    // Persist any new elements and form the attached elements collection
    java.util.Collection attachedElements = new java.util.LinkedHashSet(c.size());
    SCOUtils.attachCopyForCollection(ownerOP, c.toArray(), attachedElements, elementsWithoutIdentity);

    // Add any new elements to this collection
    SCOUtils.attachAddNewElements(ownerOP.getExecutionContext().getApiAdapter(), this, attachedElements,
        elementsWithoutIdentity);*/
  }
Example #6
0
  /**
   * Method to return an attached copy of the passed (detached) value. The returned attached copy is
   * a SCO wrapper. Goes through the existing keys/values in the store for this owner field and
   * removes ones no longer present, and adds new keys/values. All keys/values in the (detached)
   * value are attached.
   *
   * @param value The new (map) value
   */
  public void attachCopy(Object value) {
    java.util.Map m = (java.util.Map) value;

    // Attach all of the keys/values in the new map
    boolean keysWithoutIdentity = SCOUtils.mapHasKeysWithoutIdentity(ownerMmd);
    boolean valuesWithoutIdentity = SCOUtils.mapHasValuesWithoutIdentity(ownerMmd);

    java.util.Map attachedKeysValues = new java.util.TreeMap();
    SCOUtils.attachCopyForMap(
        ownerOP, m.entrySet(), attachedKeysValues, keysWithoutIdentity, valuesWithoutIdentity);

    // Update the attached map with the detached elements
    SCOUtils.updateMapWithMapKeysValues(
        ownerOP.getExecutionContext().getApiAdapter(), this, attachedKeysValues);
  }
Example #7
0
  /**
   * Method to add a Map of values to this map.
   *
   * @param m The Map to add
   */
  public synchronized void putAll(java.util.Map m) {
    makeDirty();

    if (useCache) {
      // Make sure we have all values loaded (e.g if in optimistic tx and we put new entry)
      loadFromStore();
    }

    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        Iterator iter = m.entrySet().iterator();
        while (iter.hasNext()) {
          java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new MapPutOperation(ownerOP, backingStore, entry.getKey(), entry.getValue()));
        }
      } else {
        backingStore.putAll(ownerOP, m);
      }
    }
    delegate.putAll(m);

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
  }
Example #8
0
  /**
   * Method to remove a value from the Map.
   *
   * @param key The key for the value.
   * @return The value removed.
   */
  public synchronized Object remove(Object key) {
    makeDirty();

    if (useCache) {
      // Make sure we have all values loaded (e.g if in optimistic tx and we put new entry)
      loadFromStore();
    }

    Object removed = null;
    Object delegateRemoved = delegate.remove(key);
    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        ownerOP
            .getExecutionContext()
            .addOperationToQueue(
                new MapRemoveOperation(ownerOP, backingStore, key, delegateRemoved));
        removed = delegateRemoved;
      } else {
        removed = backingStore.remove(ownerOP, key);
      }
    } else {
      removed = delegateRemoved;
    }

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return removed;
  }
Example #9
0
  /**
   * Wrapper addition that allows turning off of the dependent-field checks when doing the position
   * setting. This means that we can prevent the deletion of the object that was previously in that
   * position. This particular feature is used when attaching a list field and where some elements
   * have changed positions.
   *
   * @param index The position
   * @param element The new element
   * @return The element previously at that position
   */
  public Object set(int index, Object element, boolean allowDependentField) {
    // Reject inappropriate elements
    if (!allowNulls && element == null) {
      throw new NullPointerException(
          "Nulls not allowed for collection at field "
              + ownerMmd.getName()
              + " but element is null");
    }

    makeDirty();

    if (useCache) {
      loadFromStore();
    }

    Object delegateReturn = delegate.set(index, element);
    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(queued, ownerOP)) {
        ownerOP
            .getExecutionContext()
            .addOperationToQueue(
                new ListSetOperation(ownerOP, backingStore, index, element, allowDependentField));
      } else {
        backingStore.set(ownerOP, index, element, allowDependentField);
      }
    }

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return delegateReturn;
  }
Example #10
0
  /**
   * Method to remove an element from the ArrayList.
   *
   * @param index The element position.
   * @return The object that was removed
   */
  public synchronized Object remove(int index) {
    makeDirty();

    if (useCache) {
      loadFromStore();
    }

    int size = (useCache ? delegate.size() : -1);
    Object delegateObject = (useCache ? delegate.remove(index) : null);

    Object backingObject = null;
    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(queued, ownerOP)) {
        backingObject = delegateObject;
        ownerOP
            .getExecutionContext()
            .addOperationToQueue(new ListRemoveAtOperation(ownerOP, backingStore, index));
      } else {
        try {
          backingObject = backingStore.remove(ownerOP, index, size);
        } catch (NucleusDataStoreException dse) {
          NucleusLogger.PERSISTENCE.warn(
              Localiser.msg("023013", "remove", ownerMmd.getName(), dse));
          backingObject = null;
        }
      }
    }

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }

    return (backingStore != null ? backingObject : delegateObject);
  }
  /**
   * Method to check if an element is already persistent, or is managed by a different
   * ExecutionContext. If not persistent, this will persist it.
   *
   * @param ec execution context
   * @param element The element
   * @param fieldValues any initial field values to use if persisting the element
   * @return Whether the element was persisted during this call
   */
  protected boolean validateElementForWriting(
      ExecutionContext ec, Object element, FieldValues fieldValues) {
    // TODO Pass in cascade flag and if element not present then throw exception
    // Check the element type for this collection
    if (!elementIsPersistentInterface
        && !validateElementType(ec.getClassLoaderResolver(), element)) {
      throw new ClassCastException(
          Localiser.msg(
              "056033",
              element.getClass().getName(),
              ownerMemberMetaData.getFullFieldName(),
              elementType));
    }

    boolean persisted = false;
    if (elementsAreEmbedded || elementsAreSerialised) {
      // Element is embedded/serialised so has no id
    } else {
      ObjectProvider elementSM = ec.findObjectProvider(element);
      if (elementSM != null && elementSM.isEmbedded()) {
        // Element is already with ObjectProvider and is embedded in another field!
        throw new NucleusUserException(
            Localiser.msg("056028", ownerMemberMetaData.getFullFieldName(), element));
      }

      persisted = SCOUtils.validateObjectForWriting(ec, element, fieldValues);
    }
    return persisted;
  }
Example #12
0
 /**
  * Method to add a collection to the LinkedHashSet.
  *
  * @param elements The collection
  * @return Whether it was added ok.
  */
 public boolean addAll(Collection elements) {
   boolean success = delegate.addAll(elements);
   if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
     // Relationship management
     Iterator iter = elements.iterator();
     while (iter.hasNext()) {
       ownerOP
           .getExecutionContext()
           .getRelationshipManager(ownerOP)
           .relationAdd(ownerMmd.getAbsoluteFieldNumber(), iter.next());
     }
   }
   if (success) {
     if (SCOUtils.useQueuedUpdate(ownerOP)) {
       for (Object element : elements) {
         ownerOP
             .getExecutionContext()
             .addOperationToQueue(
                 new CollectionAddOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), element));
       }
     }
     makeDirty();
     if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
       ownerOP.getExecutionContext().processNontransactionalUpdate();
     }
   }
   return success;
 }
Example #13
0
 /**
  * Method to return the list as an array.
  *
  * @param a The runtime types of the array being defined by this param
  * @return The array
  */
 public Object[] toArray(Object a[]) {
   if (useCache) {
     loadFromStore();
   } else if (backingStore != null) {
     return SCOUtils.toArray(backingStore, ownerOP, a);
   }
   return delegate.toArray(a);
 }
Example #14
0
 /**
  * Method to return the list as an array.
  *
  * @return The array
  */
 public synchronized Object[] toArray() {
   if (useCache) {
     loadFromStore();
   } else if (backingStore != null) {
     return SCOUtils.toArray(backingStore, ownerOP);
   }
   return delegate.toArray();
 }
Example #15
0
 /** Convenience method to set up the delegate respecting any comparator specified in MetaData. */
 protected void initialiseDelegate() {
   Comparator comparator =
       SCOUtils.getComparator(ownerMmd, ownerOP.getExecutionContext().getClassLoaderResolver());
   if (comparator != null) {
     this.delegate = new java.util.TreeMap(comparator);
   } else {
     this.delegate = new java.util.TreeMap();
   }
 }
Example #16
0
  /**
   * Method to add a value to the Map.
   *
   * @param key The key for the value.
   * @param value The value
   * @return The previous value against this key (if any).
   */
  public synchronized Object put(Object key, Object value) {
    // Reject inappropriate values
    if (!allowNulls) {
      if (value == null) {
        throw new NullPointerException(
            "Nulls not allowed for map at field " + ownerMmd.getName() + " but value is null");
      }
      if (key == null) {
        throw new NullPointerException(
            "Nulls not allowed for map at field " + ownerMmd.getName() + " but key is null");
      }
    }

    if (useCache) {
      // Make sure we have all values loaded (e.g if in optimistic tx and we put new entry)
      loadFromStore();
    }

    makeDirty();

    Object oldValue = null;
    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        ownerOP
            .getExecutionContext()
            .addOperationToQueue(new MapPutOperation(ownerOP, backingStore, key, value));
      } else {
        oldValue = backingStore.put(ownerOP, key, value);
      }
    }
    Object delegateOldValue = delegate.put(key, value);
    if (backingStore == null) {
      oldValue = delegateOldValue;
    } else if (SCOUtils.useQueuedUpdate(ownerOP)) {
      oldValue = delegateOldValue;
    }

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return oldValue;
  }
Example #17
0
  /**
   * Method to remove all elements from the collection from the LinkedHashSet.
   *
   * @param elements The collection of elements to remove
   * @return Whether it was removed ok.
   */
  public boolean removeAll(java.util.Collection elements) {
    boolean success = delegate.removeAll(elements);
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
      // Relationship management
      Iterator iter = elements.iterator();
      RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
      while (iter.hasNext()) {
        relMgr.relationRemove(ownerMmd.getAbsoluteFieldNumber(), iter.next());
      }
    }

    if (ownerOP != null && elements != null && !elements.isEmpty()) {
      // Cascade delete
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        // Queue the cascade delete
        Iterator iter = elements.iterator();
        while (iter.hasNext()) {
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new CollectionRemoveOperation(
                      ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
        }
      } else if (SCOUtils.hasDependentElement(ownerMmd)) {
        // Perform the cascade delete
        Iterator iter = elements.iterator();
        while (iter.hasNext()) {
          ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
        }
      }
    }

    if (success) {
      makeDirty();
      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }
    }

    return success;
  }
Example #18
0
 /** Method to initialise the SCO for use. */
 public void initialise() {
   initialiseDelegate();
   if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
     NucleusLogger.PERSISTENCE.debug(
         LOCALISER.msg(
             "023003",
             ownerOP.getObjectAsPrintable(),
             ownerMmd.getName(),
             "" + size(),
             SCOUtils.getSCOWrapperOptionsMessage(true, false, false, false)));
   }
 }
Example #19
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);
  }
Example #20
0
  /**
   * Method to remove the value for a key from the SortedMap.
   *
   * @param key The key to remove
   * @return The value that was removed from this key.
   */
  public Object remove(Object key) {
    Object value = delegate.remove(key);

    if (ownerOP != null) {
      // Cascade delete
      if (SCOUtils.hasDependentKey(ownerMmd) || SCOUtils.hasDependentValue(ownerMmd)) {
        if (SCOUtils.hasDependentKey(ownerMmd)) {
          ownerOP.getExecutionContext().deleteObjectInternal(key);
        }
        if (SCOUtils.hasDependentValue(ownerMmd)) {
          ownerOP.getExecutionContext().deleteObjectInternal(value);
        }
      }
    }

    makeDirty();
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }

    return value;
  }
Example #21
0
  /**
   * Method to retain a Collection of elements (and remove all others).
   *
   * @param c The collection to retain
   * @return Whether they were retained successfully.
   */
  public boolean retainAll(java.util.Collection c) {
    if (c == null) {
      throw new NullPointerException("Input collection was null");
    }
    Collection collToRemove = new java.util.LinkedHashSet();
    for (Object o : delegate) {
      if (!c.contains(o)) {
        collToRemove.add(o);
      }
    }

    boolean success = delegate.retainAll(c);
    if (success) {
      makeDirty();
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        // Queue any cascade delete
        Iterator iter = collToRemove.iterator();
        while (iter.hasNext()) {
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new CollectionRemoveOperation(
                      ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
        }
      } else if (SCOUtils.hasDependentElement(ownerMmd)) {
        // Perform the cascade delete
        Iterator iter = collToRemove.iterator();
        while (iter.hasNext()) {
          ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
        }
      }

      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }
    }
    return success;
  }
Example #22
0
  /** Method to clear the SortedMap. */
  public void clear() {
    if (ownerOP != null && !delegate.isEmpty()) {
      // Cascade delete
      if (SCOUtils.hasDependentKey(ownerMmd) || SCOUtils.hasDependentValue(ownerMmd)) {
        Iterator<Map.Entry> entryIter = delegate.entrySet().iterator();
        while (entryIter.hasNext()) {
          Map.Entry entry = entryIter.next();
          if (SCOUtils.hasDependentKey(ownerMmd)) {
            ownerOP.getExecutionContext().deleteObjectInternal(entry.getKey());
          }
          if (SCOUtils.hasDependentValue(ownerMmd)) {
            ownerOP.getExecutionContext().deleteObjectInternal(entry.getValue());
          }
        }
      }
    }

    delegate.clear();
    makeDirty();
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
  }
Example #23
0
  /** Method to load all elements from the "backing store" where appropriate. */
  protected void loadFromStore() {
    if (backingStore != null && !isCacheLoaded) {
      if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
        NucleusLogger.PERSISTENCE.debug(
            Localiser.msg("023006", ownerOP.getObjectAsPrintable(), ownerMmd.getName()));
      }
      delegate.clear();

      // Populate the delegate with the keys/values from the store
      SCOUtils.populateMapDelegateWithStoreData(delegate, backingStore, ownerOP);

      isCacheLoaded = true;
    }
  }
Example #24
0
 /**
  * Method to initialise the SCO from an existing value.
  *
  * @param o Object to set value using.
  * @param forInsert Whether the object needs inserting in the datastore with this value
  * @param forUpdate Whether to update the datastore with this value
  */
 public void initialise(Object o, boolean forInsert, boolean forUpdate) {
   java.util.Map m = (java.util.Map) o;
   if (m != null) {
     delegate = (java.util.HashMap) m;
   } else {
     delegate = new java.util.HashMap();
   }
   if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
     NucleusLogger.PERSISTENCE.debug(
         LOCALISER.msg(
             "023003",
             ownerOP.getObjectAsPrintable(),
             ownerMmd.getName(),
             "" + size(),
             SCOUtils.getSCOWrapperOptionsMessage(true, false, true, false)));
   }
 }
Example #25
0
 public void initialise(java.util.LinkedHashSet c) {
   if (c != null) {
     delegate = c;
   } else {
     delegate = new java.util.LinkedHashSet();
   }
   if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
     NucleusLogger.PERSISTENCE.debug(
         Localiser.msg(
             "023003",
             this.getClass().getName(),
             ownerOP.getObjectAsPrintable(),
             ownerMmd.getName(),
             "" + size(),
             SCOUtils.getSCOWrapperOptionsMessage(true, false, true, false)));
   }
 }
 /**
  * Method to initialise the SCO from an existing value.
  *
  * @param c The object to set from
  * @param forInsert Whether the object needs inserting in the datastore with this value
  * @param forUpdate Whether to update the datastore with this value
  */
 public void initialise(java.util.PriorityQueue c, boolean forInsert, boolean forUpdate) {
   if (c != null) {
     initialiseDelegate();
     delegate.addAll(c);
   } else {
     initialiseDelegate();
   }
   if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
     NucleusLogger.PERSISTENCE.debug(
         Localiser.msg(
             "023003",
             ownerOP.getObjectAsPrintable(),
             ownerMmd.getName(),
             "" + size(),
             SCOUtils.getSCOWrapperOptionsMessage(true, false, false, false)));
   }
 }
Example #27
0
  /**
   * Method to add a collection to the TreeSet.
   *
   * @param elements The collection
   * @return Whether it was added ok.
   */
  public boolean addAll(Collection elements) {
    if (useCache) {
      loadFromStore();
    }
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
      // Relationship management
      Iterator iter = elements.iterator();
      RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
      while (iter.hasNext()) {
        relMgr.relationAdd(ownerMmd.getAbsoluteFieldNumber(), iter.next());
      }
    }

    boolean backingSuccess = true;
    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(queued, ownerOP)) {
        for (Object element : elements) {
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
        }
      } else {
        try {
          backingSuccess =
              backingStore.addAll(ownerOP, elements, (useCache ? delegate.size() : -1));
        } catch (NucleusDataStoreException dse) {
          NucleusLogger.PERSISTENCE.warn(
              LOCALISER.msg("023013", "addAll", 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.addAll(elements);

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return (backingStore != null ? backingSuccess : delegateSuccess);
  }
Example #28
0
  /**
   * Method to remove an element from the collection, and observe the flag for whether to allow
   * cascade delete.
   *
   * @param element The element
   * @param allowCascadeDelete Whether to allow cascade delete
   */
  public boolean remove(Object element, boolean allowCascadeDelete) {
    makeDirty();

    if (useCache) {
      loadFromStore();
    }

    int size = (useCache ? delegate.size() : -1);
    boolean contained = delegate.contains(element);
    boolean delegateSuccess = delegate.remove(element);
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
      ownerOP
          .getExecutionContext()
          .getRelationshipManager(ownerOP)
          .relationRemove(ownerMmd.getAbsoluteFieldNumber(), element);
    }

    boolean backingSuccess = true;
    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(queued, ownerOP)) {
        backingSuccess = contained;
        if (backingSuccess) {
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new CollectionRemoveOperation(
                      ownerOP, backingStore, element, allowCascadeDelete));
        }
      } else {
        try {
          backingSuccess = backingStore.remove(ownerOP, element, size, allowCascadeDelete);
        } catch (NucleusDataStoreException dse) {
          NucleusLogger.PERSISTENCE.warn(
              LOCALISER.msg("023013", "remove", ownerMmd.getName(), dse));
          backingSuccess = false;
        }
      }
    }

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }

    return (backingStore != null ? backingSuccess : delegateSuccess);
  }
  /** Method to clear the Collection. */
  public synchronized void clear() {
    if (ownerOP != null && !delegate.isEmpty()) {
      // Cascade delete
      if (SCOUtils.hasDependentElement(ownerMmd)) {
        Iterator iter = delegate.iterator();
        while (iter.hasNext()) {
          ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
        }
      }
    }

    delegate.clear();

    makeDirty();
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
  }
Example #30
0
  /** Method to clear the Map. */
  public synchronized void clear() {
    makeDirty();
    delegate.clear();

    if (backingStore != null) {
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        ownerOP
            .getExecutionContext()
            .addOperationToQueue(new MapClearOperation(ownerOP, backingStore));
      } else {
        backingStore.clear(ownerOP);
      }
    }

    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
      ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
  }