congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
IndirectSet
Code IndexAdd Tabnine to your IDE (free)

How to use
IndirectSet
in
org.eclipse.persistence.indirection

Best Java code snippets using org.eclipse.persistence.indirection.IndirectSet (Showing top 20 results out of 315)

origin: com.haulmont.thirdparty/eclipselink

/**
 * Raise the add change event and relationship maintainence.
 */
protected void raiseAddChangeEvent(Object element) {
  if (hasTrackedPropertyChangeListener()) {
    _persistence_getPropertyChangeListener().propertyChange(new CollectionChangeEvent(this, getTrackedAttributeName(), this, element, CollectionChangeEvent.ADD, true));
  }
  if (isRelationshipMaintenanceRequired()) {
    ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceSet(element, null);
  }
}
 
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * @see java.util.Set#addAll(java.util.Collection)
 */
public boolean addAll(Collection c) {
  // Must trigger add events if tracked or uow.
  if (hasBeenRegistered() || hasTrackedPropertyChangeListener()) {
    Iterator objects = c.iterator();
    while (objects.hasNext()) {
      this.add(objects.next());
    }
    return true;
  }
  return getDelegate().addAll(c);
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * INTERNAL:
 * Check whether the contents have been read from the database.
 * If they have not, read them and set the delegate.
 */
protected Set getDelegate() {
  if (delegate == null) {
    synchronized(this){
      if (delegate == null) {
        delegate = this.buildDelegate();
      }
    }
  }
  return delegate;
}
 
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * INTERNAL:
 * Return if any elements that have been added or removed before instantiation.
 */
public boolean hasDeferredChanges() {
  return hasRemovedElements() || hasAddedElements();
}
 
origin: org.eclipse.persistence/org.eclipse.persistence.core

  /**
   * INTERNAL:
   * Return if add/remove should trigger instantiation or avoid.
   * Current instantiation is avoided is using change tracking.
   */
  protected boolean shouldAvoidInstantiation() {
    return (!isInstantiated()) && (shouldUseLazyInstantiation()) && (_persistence_getPropertyChangeListener() instanceof AttributeChangeListener) && ((WeavedAttributeValueHolderInterface)getValueHolder()).shouldAllowInstantiationDeferral();
  }
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

  /**
   * INTERNAL:
   * Return if add/remove should trigger instantiation or avoid.
   * Current instantiation is avoided is using change tracking.
   */
  protected boolean shouldAvoidInstantiation() {
    return (!isInstantiated()) && (_persistence_getPropertyChangeListener() instanceof AttributeChangeListener) && ((WeavedAttributeValueHolderInterface)getValueHolder()).shouldAllowInstantiationDeferral();
  }
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * @see java.util.Set#contains(java.lang.Object)
 */
public boolean contains(Object element) {
  // PERF: Avoid instantiation if not required.
  if (hasAddedElements()) {
    if (getAddedElements().contains(element)) {
      return true;
    }
  }
  if (hasRemovedElements()) {
    if (getRemovedElements().contains(element)) {
      return false;
    }
  }
  return this.getDelegate().contains(element);
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * @see java.util.Set#clear()
 */
public void clear() {
  if (hasBeenRegistered() || hasTrackedPropertyChangeListener()) {
    Iterator objects = this.iterator();
    while (objects.hasNext()) {
      Object o = objects.next();
      objects.remove();
      this.raiseRemoveChangeEvent(o);
    }
  } else {
    this.getDelegate().clear();
  }
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * @see java.util.Set#add(java.lang.Object)
 */
@Override
public boolean add(E element) {
  boolean added = true;
  // PERF: If not instantiated just record the add to avoid the instantiation.
  if (shouldAvoidInstantiation()) {
    if (hasRemovedElements() && getRemovedElements().contains(element)) {
      getRemovedElements().remove(element);
    } else if (isRelationshipMaintenanceRequired() && getAddedElements().contains(element)) {
      // Must avoid recursion for relationship maintenance.
      return false;
    } else {
      getAddedElements().add(element);
    }
  } else {
    added = getDelegate().add(element);
  }
  if (added) {
    raiseAddChangeEvent(element);
  }
  return added;
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * @see java.util.Set#remove(java.lang.Object)
 */
public boolean remove(Object element) {
  // PERF: If not instantiated just record the removal to avoid the instantiation.
  if (shouldAvoidInstantiation()) {
    if (hasAddedElements() && getAddedElements().contains(element)) {
      getAddedElements().remove(element);
    } else if (getRemovedElements().contains(element)) {
      // Must avoid recursion for relationship maintenance.
      return false;
    } else {
      getRemovedElements().add(element);
    }
    this.raiseRemoveChangeEvent(element);
    return true;
  } else if (this.getDelegate().remove(element)) {
    this.raiseRemoveChangeEvent(element);
    return true;
  }
  return false;
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * Raise the remove change event.
 */
protected void raiseRemoveChangeEvent(Object element) {
  if (hasTrackedPropertyChangeListener()) {
    _persistence_getPropertyChangeListener().propertyChange(new CollectionChangeEvent(this, getTrackedAttributeName(), this, element, CollectionChangeEvent.REMOVE));
  }
  if (hasBeenRegistered()) {
    ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceRemove(element);
  }
}
 
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * @see java.util.Set#removeAll(java.util.Collection)
 */
public boolean removeAll(Collection c) {
  // Must trigger remove events if tracked or uow.
  if (hasBeenRegistered() || hasTrackedPropertyChangeListener()) {
    Iterator objects = c.iterator();
    while (objects.hasNext()) {
      this.remove(objects.next());
    }
    return true;
  }
  return this.getDelegate().removeAll(c);
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * INTERNAL:
 * Return the real collection object.
 * This will force instantiation.
 */
@Override
public Object getDelegateObject() {
  return getDelegate();
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * Use the delegate's #toString(); but wrap it with braces to indicate
 * there is a bit of indirection.
 * Don't allow this method to trigger a database read.
 * @see java.util.HashSet#toString()
 */
@Override
public String toString() {
  if (ValueHolderInterface.shouldToStringInstantiate) {
    return this.getDelegate().toString();
  }
  if (this.isInstantiated()) {
    return "{" + this.getDelegate().toString() + "}";
  } else {
    return "{" + org.eclipse.persistence.internal.helper.Helper.getShortClassName(this.getClass()) + ": " + ToStringLocalization.buildMessage("not_instantiated", (Object[])null) + "}";
  }
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * INTERNAL:
 * Return whether this IndirectSet has been registered in a UnitOfWork
 */
public boolean hasBeenRegistered() {
  return getValueHolder() instanceof org.eclipse.persistence.internal.indirection.UnitOfWorkQueryValueHolder;
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * @see java.lang.Object#clone()
 * This will result in a database query if necessary.
 */
/*
  There are 3 situations when #clone() is called:
  1.    The developer actually wants to clone the collection (typically to modify one
    of the 2 resulting collections). In which case the contents must be read from
    the database.
  2.    A UnitOfWork needs a clone (or backup clone) of the collection. But the
    UnitOfWork checks "instantiation" before cloning collections (i.e. "un-instantiated"
    collections are not cloned).
  3.    A MergeManager needs an extra copy of the collection (because the "backup"
    and "target" are the same object?). But the MergeManager also checks "instantiation"
    before merging collections (again, "un-instantiated" collections are not merged).
*/
public Object clone() {
  try {
    IndirectSet result = (IndirectSet)super.clone();
    result.delegate = this.cloneDelegate();
    result.attributeName = null;
    result.changeListener = null;
    return result;
  } catch (CloneNotSupportedException e) {
    throw new InternalError("clone not supported");
  }
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * @see java.util.Set#contains(java.lang.Object)
 */
@Override
public boolean contains(Object element) {
  // PERF: Avoid instantiation if not required.
  if (hasAddedElements()) {
    if (getAddedElements().contains(element)) {
      return true;
    }
  }
  if (hasRemovedElements()) {
    if (getRemovedElements().contains(element)) {
      return false;
    }
  }
  return this.getDelegate().contains(element);
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * @see java.util.Set#clear()
 */
@Override
public void clear() {
  if (hasBeenRegistered() || hasTrackedPropertyChangeListener()) {
    Iterator<E> objects = iterator();
    while (objects.hasNext()) {
      objects.next();
      objects.remove();
    }
    // clear delegate in case it's still not empty, see bug 338393
  }
  getDelegate().clear();
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * @see java.util.Set#add(java.lang.Object)
 */
public boolean add(Object element) {
  boolean added = true;
  // PERF: If not instantiated just record the add to avoid the instantiation.
  if (shouldAvoidInstantiation()) {
    if (hasRemovedElements() && getRemovedElements().contains(element)) {
      getRemovedElements().remove(element);
    } else if (getAddedElements().contains(element)) {
      // Must avoid recursion for relationship maintenance.                
      return false;
    } else {
      getAddedElements().add(element);
    }
  } else {
    added = getDelegate().add(element);
  }
  raiseAddChangeEvent(element);
  return added;
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * @see java.util.Set#remove(java.lang.Object)
 */
@Override
public boolean remove(Object element) {
  // PERF: If not instantiated just record the removal to avoid the instantiation.
  if (shouldAvoidInstantiation()) {
    if (hasAddedElements() && getAddedElements().contains(element)) {
      getAddedElements().remove(element);
    } else if (getRemovedElements().contains(element)) {
      // Must avoid recursion for relationship maintenance.
      return false;
    } else {
      getRemovedElements().add((E) element);
    }
    this.raiseRemoveChangeEvent(element);
    return true;
  } else if (this.getDelegate().remove(element)) {
    this.raiseRemoveChangeEvent(element);
    return true;
  }
  return false;
}
org.eclipse.persistence.indirectionIndirectSet

Javadoc

IndirectSet is an example implementation of the Set protocol that allows a domain class to take advantage of TopLink Indirection without having to declare its instance variable as a ValueHolderInterface.

To use an IndirectSet:

  • Declare the appropriate instance variable with type Set (or Collection).
  • Send the message #useTransparentCollection() to the appropriate CollectionMapping.
  • Send the message #useCollectionClass(IndirectSet.class) to the same CollectionMapping. (The order of these two message sends is significant.)
TopLink will place an IndirectSet in the instance variable when the containing domain object is read from the datatabase. With the first message sent to the IndirectSet, the contents are fetched from the database and normal Set behavior is resumed.

Implementation notes:

  • The Set interface is implemented by delegating nearly every message to the Set held on to by the 'delegate' instance variable. (The 'delegate' will be either a HashSet or yet another IndirectSet.)
  • The IndirectContainer interface is implemented in a straightforward fashion:
    • #get- and #setValueHolder() are implemented as simple accessors for the 'valueHolder' instance variable. (Note that #setValueHolder() clears out the 'delegate' instance variable, since its contents are invalidated by the arrival of a new value holder.)
    • #isInstantiated() is simply delegated to the value holder.
  • TopLink requires that the Cloneable interface be implemented. The #clone() method must clone the 'delegate'. (The implementation here uses reflection to invoke the #clone() method because it is not included in the common interface shared by IndirectSet and its base delegate class, HashSet; namely, Set.)
  • TopLink requires that the Serializable interface be implemented.
  • The database read is ultimately triggered when one of the "delegated" methods makes the first call to #getDelegate(), which in turn calls #buildDelegate(), which sends the message #getValue() to the value holder. The value holder performs the database read.
  • For debugging purposes, #toString() will not trigger a database read. This is not required behavior.

Most used methods

  • _persistence_getPropertyChangeListener
    INTERNAL: Return the property change listener for change tracking.
  • add
  • buildDelegate
    INTERNAL: Return the freshly-built delegate.
  • cloneDelegate
    INTERNAL: Clone the delegate.
  • getAddedElements
    INTERNAL: Return the elements that have been added before instantiation.
  • getDelegate
    INTERNAL: Check whether the contents have been read from the database. If they have not, read them a
  • getRemovedElements
    INTERNAL: Return the elements that have been removed before instantiation.
  • getTrackedAttributeName
    INTERNAL: Return the mapping attribute name, used to raise change events.
  • getValueHolder
    INTERNAL: Return the valueHolder.
  • hasAddedElements
    INTERNAL: Return if any elements that have been added before instantiation.
  • hasBeenRegistered
    INTERNAL: Return whether this IndirectSet has been registered in a UnitOfWork
  • hasRemovedElements
    INTERNAL: Return if any elements that have been removed before instantiation.
  • hasBeenRegistered,
  • hasRemovedElements,
  • hasTrackedPropertyChangeListener,
  • isInstantiated,
  • iterator,
  • raiseAddChangeEvent,
  • raiseRemoveChangeEvent,
  • remove,
  • shouldAvoidInstantiation,
  • <init>

Popular in Java

  • Finding current android device location
  • onRequestPermissionsResult (Fragment)
  • setContentView (Activity)
  • findViewById (Activity)
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • ImageIO (javax.imageio)
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now