Methods Summary |
---|
public boolean | add(java.lang.Object o)Adds the specified element to this set if it is not already
present.
if (allowNulls == false && o == null)
{
throw new JDOUserException(I18NHelper.getMessage(messages,
"sco.nulls_not_allowed")); // NOI18N
}
if (elementType != null && !elementType.isAssignableFrom(o.getClass()))
{
throw new JDOUserException(I18NHelper.getMessage(messages,
"sco.classcastexception", elementType.getName()), // NOI18N
new ClassCastException(), new Object[] {o});
}
if (owner != null)
{
StateManager stateManager = owner.jdoGetStateManager();
if (stateManager != null)
{
PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
pm.acquireShareLock();
boolean modified = false;
try
{
pm.acquireFieldUpdateLock();
try
{
// Mark the field as dirty
stateManager.makeDirty(fieldName);
modified = super.add(o);
if (modified)
{
if (removed.remove(o) == false)
{
added.add(o);
}
stateManager.applyUpdates(fieldName, this);
}
return modified;
}
finally
{
pm.releaseFieldUpdateLock();
}
}
catch (JDOUserException e)
{
Object[] failedObjects = e.getFailedObjectArray();
if (modified && (failedObjects != null))
{
//
// The failedObjects array may contain objects other
// than the one added. We iterate through it to find
// the one added and remove it from the collection.
//
for (int i = 0; i < failedObjects.length; i++)
{
Object failedObject = failedObjects[i];
if (failedObject == o)
{
super.remove(failedObject);
break;
}
}
}
throw e;
}
finally
{
pm.releaseShareLock();
}
}
}
return super.add(o);
|
public boolean | addAll(java.util.Collection c)Adds all of the elements in the specified collection to this collection
if (allowNulls == false && c.contains(null))
{
throw new JDOUserException(I18NHelper.getMessage(messages,
"sco.nulls_not_allowed")); // NOI18N
}
ArrayList errc = new ArrayList();
if (elementType != null)
{
// iterate the collection and make a list of wrong elements.
Iterator i = c.iterator();
while (i.hasNext())
{
Object o = i.next();
if (!elementType.isAssignableFrom(o.getClass()))
errc.add(o);
}
}
if (errc != null && errc.size() > 0)
{
throw new JDOUserException(I18NHelper.getMessage(messages,
"sco.classcastexception", elementType.getName()), // NOI18N
new ClassCastException(), errc.toArray());
}
boolean modified = false;
if (owner != null)
{
StateManager stateManager = owner.jdoGetStateManager();
if (stateManager != null)
{
PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
pm.acquireShareLock();
try
{
pm.acquireFieldUpdateLock();
try
{
// Mark the field as dirty
stateManager.makeDirty(fieldName);
for (Iterator iter = c.iterator(); iter.hasNext();)
{
Object o = iter.next();
if (!super.contains(o))
{
if (removed.remove(o) == false)
{
added.add(o);
}
super.add(o);
modified = true;
}
}
// Apply updates
if (modified)
{
stateManager.applyUpdates(fieldName, this);
}
return modified;
}
finally
{
pm.releaseFieldUpdateLock();
}
}
catch (JDOUserException e)
{
Object[] failedObjects = e.getFailedObjectArray();
if (modified && (failedObjects != null))
{
for (int i = 0; i < failedObjects.length; i++)
{
super.remove(failedObjects[i]);
}
}
throw e;
}
finally
{
pm.releaseShareLock();
}
}
}
return super.addAll(c);
|
public void | addAllInternal(java.util.Collection c)Adds a Collection to the list without recording changes if the HashSet is
not deferred. Otherwise, add o to the removed list.
if (c == null)
{
return;
}
Iterator iter = c.iterator();
while (iter.hasNext())
{
addInternal(iter.next());
}
|
public void | addInternal(java.lang.Object o)Adds an object to the list without recording changes if the HashSet is
not deferred. Otherwise, add o to the added list.
if (isDeferred)
{
if (removed.remove(o) == false)
{
added.add(o);
}
}
else
{
super.add(o);
}
|
public void | addToBaseCollection(java.lang.Object o)
super.add(o);
|
public void | applyDeferredUpdates(java.util.Collection c)If the HashSet is deferred, we first initialize the internal collection
with c and they apply any deferred updates specified by the added and
removed lists.
if (!isDeferred)
{
// should throw an exception??
return;
}
isDeferred = false;
addAllInternal(c);
addAllInternal(added);
removeAllInternal(removed);
added.clear();
removed.clear();
|
public void | applyUpdates(com.sun.jdo.spi.persistence.support.sqlstore.StateManager sm, boolean modified)Apply changes (can be a no-op)
if (modified && sm != null)
{
sm.applyUpdates(fieldName, this);
}
|
public void | clear()Removes all of the elements from this set.
if (owner != null)
{
StateManager stateManager = owner.jdoGetStateManager();
if (stateManager != null)
{
PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
pm.acquireShareLock();
try
{
pm.acquireFieldUpdateLock();
try
{
// Mark the field as dirty
stateManager.makeDirty(fieldName);
removed.clear();
added.clear();
for (Iterator iter = super.iterator(); iter.hasNext();)
{
removed.add(iter.next());
}
super.clear();
// Apply updates
stateManager.applyUpdates(fieldName, this);
return;
}
finally
{
pm.releaseFieldUpdateLock();
}
}
finally
{
pm.releaseShareLock();
}
}
}
super.clear();
|
public void | clearInternal()Clears Collection without notifing the owner
super.clear();
this.reset();
|
public java.lang.Object | clone()Creates and returns a copy of this object.
Mutable Second Class Objects are required to provide a public
clone method in order to allow for copying PersistenceCapable
objects. In contrast to Object.clone(), this method must not throw a
CloneNotSupportedException.
HashSet obj = (HashSet) super.clone();
// RESOLVE: check if added/removed should not be cleared
// for a deferred collection, but applyDeferredUpdates logic
// be used?
obj.unsetOwner();
return obj;
|
public java.lang.Object | cloneInternal()Creates and returns a copy of this object without resetting the owner and field value.
return super.clone();
|
public java.util.Collection | getAdded()Returns added collection
return (Collection)added;
|
public java.lang.String | getFieldName()Returns the field name
return this.fieldName;
|
public java.lang.Object | getOwner()Returns the owner object of the SCO instance
return this.owner;
|
public java.util.Collection | getRemoved()Returns removed collection
return (Collection)removed;
|
public boolean | isDeferred()Return true is this HashSet is deferred, false otherwise.
return isDeferred;
|
public java.util.Iterator | iterator()Returns an iterator over the elements in this set. The elements
are returned in no particular order.
return new SCOHashIterator(super.iterator(), this);
|
public com.sun.jdo.spi.persistence.support.sqlstore.StateManager | makeDirty()Marks object dirty
StateManager stateManager = owner.jdoGetStateManager();
if (stateManager != null)
{
stateManager.makeDirty(fieldName);
}
return stateManager;
|
public void | markDeferred()Mark this HashSet as deferred.
isDeferred = true;
|
public boolean | remove(java.lang.Object o)Removes the given element from this set if it is present.
// Mark the field as dirty
if (owner != null)
{
StateManager stateManager = owner.jdoGetStateManager();
if (stateManager != null)
{
PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
pm.acquireShareLock();
try
{
pm.acquireFieldUpdateLock();
try
{
stateManager.makeDirty(fieldName);
boolean modified = super.remove(o);
if (modified)
{
if (added.remove(o) == false)
{
removed.add(o);
}
stateManager.applyUpdates(fieldName, this);
}
return modified;
}
finally
{
pm.releaseFieldUpdateLock();
}
}
finally
{
pm.releaseShareLock();
}
}
}
return super.remove(o);
|
public boolean | removeAll(java.util.Collection c)Removes from this collection all of its elements that are contained in
the specified collection (optional operation).
// Mark the field as dirty
if (owner != null)
{
StateManager stateManager = owner.jdoGetStateManager();
if (stateManager != null)
{
PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
pm.acquireShareLock();
try
{
pm.acquireFieldUpdateLock();
try
{
stateManager.makeDirty(fieldName);
for (Iterator iter = c.iterator(); iter.hasNext();)
{
Object o = iter.next();
if (super.contains(o))
{
if (added.remove(o) == false)
{
removed.add(o);
}
}
}
boolean modified = super.removeAll(c);
// Apply updates
if (modified)
{
stateManager.applyUpdates(fieldName, this);
}
return modified;
}
finally
{
pm.releaseFieldUpdateLock();
}
}
finally
{
pm.releaseShareLock();
}
}
}
return super.removeAll(c);
|
public void | removeAllInternal(java.util.Collection c)
if (c == null)
{
return;
}
Iterator iter = c.iterator();
while (iter.hasNext())
{
removeInternal(iter.next());
}
|
public void | removeInternal(java.lang.Object o)Removes an element without notifing the owner
if (isDeferred)
{
if (added.remove(o) == false)
{
removed.add(o);
}
}
else
{
super.remove(o);
}
|
public void | reset()Cleans removed and added lists
// RESOLVE: do we need to synchronize this??
if (added != null)
added.clear();
if (removed != null)
removed.clear();
|
public boolean | retainAll(java.util.Collection c)Retains only the elements in this collection that are contained in the
specified collection (optional operation).
if (owner != null)
{
StateManager stateManager = owner.jdoGetStateManager();
if (stateManager != null)
{
PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
pm.acquireShareLock();
try
{
pm.acquireFieldUpdateLock();
try
{
// Mark the field as dirty
stateManager.makeDirty(fieldName);
for (Iterator iter = super.iterator(); iter.hasNext();)
{
Object o = iter.next();
if (!c.contains(o))
{
if (added.remove(o) == false)
{
removed.add(o);
}
}
}
boolean modified = super.retainAll(c);
// Apply updates
if (modified)
{
stateManager.applyUpdates(fieldName, this);
}
return modified;
}
finally
{
pm.releaseFieldUpdateLock();
}
}
finally
{
pm.releaseShareLock();
}
}
}
return super.retainAll(c);
|
public void | setOwner(java.lang.Object owner, java.lang.String fieldName, java.lang.Class elementType)Set the owner if this instance is not owned.
if (this.owner != null) {
throw new JDOUserException(I18NHelper.getMessage(
messages1, "core.statemanager.anotherowner"), // NOI18N
new Object[]{this.owner, this.fieldName});
}
if (owner instanceof PersistenceCapable) {
this.owner = (PersistenceCapable)owner;
this.fieldName = fieldName;
this.elementType = elementType;
}
|
public void | unsetOwner()Nullifies references to the owner Object and Field
this.owner = null;
this.fieldName = null;
this.elementType = null;
added.clear();
removed.clear();
|