Class Collection<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- org.datanucleus.store.types.wrappers.Collection<E>
-
- org.datanucleus.store.types.wrappers.backed.Collection<E>
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<E>
,Collection<E>
,SCO<Collection<E>>
,SCOCollection<Collection<E>,E>
,SCOContainer<Collection<E>>
,BackedSCO
public class Collection<E> extends Collection<E> implements BackedSCO
A mutable second-class Collection object. This class extends Collection, using that class to contain the current objects, and the backing CollectionStore to be the interface to the datastore. A "backing store" is not present for datastores that dont use DatastoreClass, or if the container is serialised or non-persistent.Modes of Operation
The user can operate the list in 2 modes. The cached mode will use an internal cache of the elements (in the "delegate") reading them at the first opportunity and then using the cache thereafter. The non-cached mode will just go direct to the "backing store" each call.Mutators
When the "backing store" is present any updates are passed direct to the datastore as well as to the "delegate". If the "backing store" isn't present the changes are made to the "delegate" only.Accessors
When any accessor method is invoked, it typically checks whether the container has been loaded from its "backing store" (where present) and does this as necessary. Some methods (size()) just check if everything is loaded and use the delegate if possible, otherwise going direct to the datastore.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowNulls
protected CollectionStore<E>
backingStore
protected boolean
initialising
protected boolean
isCacheLoaded
protected boolean
useCache
-
Fields inherited from class org.datanucleus.store.types.wrappers.Collection
delegate, ownerMmd, ownerOP
-
-
Constructor Summary
Constructors Constructor Description Collection(ObjectProvider op, AbstractMemberMetaData mmd)
Constructor.Collection(ObjectProvider ownerOP, AbstractMemberMetaData mmd, boolean allowNulls, CollectionStore backingStore)
Constructor used when creating a Collection for "Map.values" with specified backing store.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E element)
Method to add an element to the Collection.boolean
addAll(Collection c)
Method to add a collection of elements.void
clear()
Method to clear the Collection.Object
clone()
Creates and returns a copy of this object.boolean
contains(Object element)
Accessor for whether an element is contained in the Collection.boolean
containsAll(Collection c)
Accessor for whether a collection of elements are contained here.boolean
equals(Object o)
Equality operator.void
forEach(java.util.function.Consumer action)
Store
getBackingStore()
Collection
getValue()
Accessor for the unwrapped value that we are wrapping.int
hashCode()
Hashcode operator.void
initialise()
Method to initialise the SCO for use.void
initialise(Collection c)
Method to initialise the SCO from an existing value.void
initialise(Collection<E> newValue, Object oldValue)
Method to initialise the SCO for use, where replacing an old value with a new value such as when calling a setter field passing in a new value.boolean
isEmpty()
Accessor for whether the Collection is empty.boolean
isLoaded()
Method to return if the SCO has its contents loaded.Iterator<E>
iterator()
Accessor for an iterator for the Collection.void
load()
Method to effect the load of the data in the SCO.protected void
loadFromStore()
Method to load all elements from the "backing store" where appropriate.java.util.stream.Stream
parallelStream()
boolean
remove(Object element)
Method to remove an element from the Collection.boolean
remove(Object element, boolean allowCascadeDelete)
Method to remove an element from the collection, and observe the flag for whether to allow cascade delete.boolean
removeAll(Collection elements)
Method to remove a Collection of elements.boolean
retainAll(Collection c)
Method to retain a Collection of elements (and remove all others).int
size()
Accessor for the size of the Collection.Spliterator
spliterator()
java.util.stream.Stream
stream()
Object[]
toArray()
Method to return the Collection as an array.Object[]
toArray(Object[] a)
Method to return the Collection as an array.String
toString()
Method to return the Collection as a String.void
unsetOwner()
Method to unset the owner state manager and backing store information.void
updateEmbeddedElement(E element, int fieldNumber, Object value, boolean makeDirty)
Method to update an embedded element in this collection.protected Object
writeReplace()
The writeReplace method is called when ObjectOutputStream is preparing to write the object to the stream.-
Methods inherited from class org.datanucleus.store.types.wrappers.Collection
attachCopy, detachCopy, getFieldName, getOwner, makeDirty, setValue
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
removeIf, toArray
-
-
-
-
Field Detail
-
backingStore
protected transient CollectionStore<E> backingStore
-
allowNulls
protected transient boolean allowNulls
-
useCache
protected transient boolean useCache
-
isCacheLoaded
protected transient boolean isCacheLoaded
-
initialising
protected transient boolean initialising
-
-
Constructor Detail
-
Collection
public Collection(ObjectProvider op, AbstractMemberMetaData mmd)
Constructor.- Parameters:
op
- The ObjectProvider for this collection.mmd
- Metadata for the member
-
Collection
public Collection(ObjectProvider ownerOP, AbstractMemberMetaData mmd, boolean allowNulls, CollectionStore backingStore)
Constructor used when creating a Collection for "Map.values" with specified backing store.- Parameters:
ownerOP
- ObjectProvider for the owning objectmmd
- Metadata for the memberallowNulls
- Whether nulls are allowedbackingStore
- The backing store
-
-
Method Detail
-
initialise
public void initialise(Collection<E> newValue, Object oldValue)
Description copied from interface:SCO
Method to initialise the SCO for use, where replacing an old value with a new value such as when calling a setter field passing in a new value. Note that oldValue is marked as Object since for cases where the member type is Collection the newValue could be, for example, ArrayList, and the oldValue of type Collection (representing null).- Specified by:
initialise
in interfaceSCO<E>
- Overrides:
initialise
in classCollection<E>
- Parameters:
newValue
- New value (to wrap)oldValue
- Old value (to use in deciding what needs deleting etc)
-
initialise
public void initialise(Collection c)
Method to initialise the SCO from an existing value.- Specified by:
initialise
in interfaceSCO<E>
- Overrides:
initialise
in classCollection<E>
- Parameters:
c
- The object to set from
-
initialise
public void initialise()
Method to initialise the SCO for use.- Specified by:
initialise
in interfaceSCO<E>
- Overrides:
initialise
in classCollection<E>
-
getValue
public Collection getValue()
Accessor for the unwrapped value that we are wrapping.
-
load
public void load()
Method to effect the load of the data in the SCO. Used when the SCO supports lazy-loading to tell it to load all now.- Specified by:
load
in interfaceSCOContainer<E>
- Overrides:
load
in classCollection<E>
-
isLoaded
public boolean isLoaded()
Method to return if the SCO has its contents loaded. If the SCO doesn't support lazy loading will just return true.- Specified by:
isLoaded
in interfaceBackedSCO
- Specified by:
isLoaded
in interfaceSCOContainer<E>
- Overrides:
isLoaded
in classCollection<E>
- Returns:
- Whether it is loaded
-
loadFromStore
protected void loadFromStore()
Method to load all elements from the "backing store" where appropriate.
-
getBackingStore
public Store getBackingStore()
- Specified by:
getBackingStore
in interfaceBackedSCO
-
updateEmbeddedElement
public void updateEmbeddedElement(E element, int fieldNumber, Object value, boolean makeDirty)
Method to update an embedded element in this collection.- Specified by:
updateEmbeddedElement
in interfaceSCOCollection<Collection<E>,E>
- Overrides:
updateEmbeddedElement
in classCollection<E>
- Parameters:
element
- The elementfieldNumber
- Number of field in the elementvalue
- New value for this fieldmakeDirty
- Whether to make the SCO field dirty.
-
unsetOwner
public void unsetOwner()
Method to unset the owner state manager and backing store information.- Specified by:
unsetOwner
in interfaceSCO<E>
- Overrides:
unsetOwner
in classCollection<E>
-
clone
public 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 persistable objects. In contrast to Object.clone(), this method must not throw a CloneNotSupportedException.
-
contains
public boolean contains(Object element)
Accessor for whether an element is contained in the Collection.- Specified by:
contains
in interfaceCollection<E>
- Overrides:
contains
in classCollection<E>
- Parameters:
element
- The element- Returns:
- Whether the element is contained here
-
containsAll
public boolean containsAll(Collection c)
Accessor for whether a collection of elements are contained here.- Specified by:
containsAll
in interfaceCollection<E>
- Overrides:
containsAll
in classCollection<E>
- Parameters:
c
- The collection of elements.- Returns:
- Whether they are contained.
-
equals
public boolean equals(Object o)
Equality operator.- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classCollection<E>
- Parameters:
o
- The object to compare against.- Returns:
- Whether this object is the same.
-
forEach
public void forEach(java.util.function.Consumer action)
-
hashCode
public int hashCode()
Hashcode operator.- Specified by:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classCollection<E>
- Returns:
- The Hash code.
-
isEmpty
public boolean isEmpty()
Accessor for whether the Collection is empty.- Specified by:
isEmpty
in interfaceCollection<E>
- Overrides:
isEmpty
in classCollection<E>
- Returns:
- Whether it is empty.
-
iterator
public Iterator<E> iterator()
Accessor for an iterator for the Collection.- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Overrides:
iterator
in classCollection<E>
- Returns:
- The iterator
-
size
public int size()
Accessor for the size of the Collection.- Specified by:
size
in interfaceCollection<E>
- Overrides:
size
in classCollection<E>
- Returns:
- The size
-
toArray
public Object[] toArray()
Method to return the Collection as an array.- Specified by:
toArray
in interfaceCollection<E>
- Overrides:
toArray
in classCollection<E>
- Returns:
- The array
-
toArray
public Object[] toArray(Object[] a)
Method to return the Collection as an array.- Specified by:
toArray
in interfaceCollection<E>
- Overrides:
toArray
in classCollection<E>
- Parameters:
a
- The array to write the results to- Returns:
- The array
-
toString
public String toString()
Method to return the Collection as a String.- Overrides:
toString
in classAbstractCollection<E>
- Returns:
- The string form
-
add
public boolean add(E element)
Method to add an element to the Collection.- Specified by:
add
in interfaceCollection<E>
- Overrides:
add
in classCollection<E>
- Parameters:
element
- The element to add- Returns:
- Whether it was added successfully.
-
addAll
public boolean addAll(Collection c)
Method to add a collection of elements.- Specified by:
addAll
in interfaceCollection<E>
- Overrides:
addAll
in classCollection<E>
- Parameters:
c
- The collection of elements to add.- Returns:
- Whether they were added successfully.
-
clear
public void clear()
Method to clear the Collection.- Specified by:
clear
in interfaceCollection<E>
- Overrides:
clear
in classCollection<E>
-
remove
public boolean remove(Object element)
Method to remove an element from the Collection.- Specified by:
remove
in interfaceCollection<E>
- Overrides:
remove
in classCollection<E>
- Parameters:
element
- The Element to remove- Returns:
- Whether it was removed successfully.
-
remove
public boolean remove(Object element, boolean allowCascadeDelete)
Method to remove an element from the collection, and observe the flag for whether to allow cascade delete.- Specified by:
remove
in interfaceSCOCollection<Collection<E>,E>
- Overrides:
remove
in classCollection<E>
- Parameters:
element
- The elementallowCascadeDelete
- Whether to allow cascade delete- Returns:
- Whether it was removed successfully.
-
removeAll
public boolean removeAll(Collection elements)
Method to remove a Collection of elements.- Specified by:
removeAll
in interfaceCollection<E>
- Overrides:
removeAll
in classCollection<E>
- Parameters:
elements
- The collection to remove- Returns:
- Whether they were removed successfully.
-
retainAll
public boolean retainAll(Collection c)
Method to retain a Collection of elements (and remove all others).- Specified by:
retainAll
in interfaceCollection<E>
- Overrides:
retainAll
in classCollection<E>
- Parameters:
c
- The collection to retain- Returns:
- Whether they were retained successfully.
-
writeReplace
protected Object writeReplace() throws ObjectStreamException
The writeReplace method is called when ObjectOutputStream is preparing to write the object to the stream. The ObjectOutputStream checks whether the class defines the writeReplace method. If the method is defined, the writeReplace method is called to allow the object to designate its replacement in the stream. The object returned should be either of the same type as the object passed in or an object that when read and resolved will result in an object of a type that is compatible with all references to the object.- Overrides:
writeReplace
in classCollection<E>
- Returns:
- the replaced object
- Throws:
ObjectStreamException
- if an error occurs
-
spliterator
public Spliterator spliterator()
- Specified by:
spliterator
in interfaceCollection<E>
- Specified by:
spliterator
in interfaceIterable<E>
- Overrides:
spliterator
in classCollection<E>
-
stream
public java.util.stream.Stream stream()
- Specified by:
stream
in interfaceCollection<E>
- Overrides:
stream
in classCollection<E>
-
parallelStream
public java.util.stream.Stream parallelStream()
- Specified by:
parallelStream
in interfaceCollection<E>
- Overrides:
parallelStream
in classCollection<E>
-
-