org.datanucleus.store.mapped.scostore
Class FKListStore

java.lang.Object
  extended by org.datanucleus.store.mapped.scostore.BaseContainerStore
      extended by org.datanucleus.store.mapped.scostore.ElementContainerStore
          extended by org.datanucleus.store.mapped.scostore.AbstractCollectionStore
              extended by org.datanucleus.store.mapped.scostore.AbstractListStore
                  extended by org.datanucleus.store.mapped.scostore.FKListStore
All Implemented Interfaces:
CollectionStore, ListStore, Store

public abstract class FKListStore
extends AbstractListStore

Representation of a List using a ForeignKey to form a relationship. This class is used where you have a 1-N and the tables are not joined via a join table. There is an owner table and an element table, and the element table has a column being the id of the owner table. This is in contrast to NormalListStore which represents 1-N relationships using a join table. There are 2 possible uses here


Nested Class Summary
 
Nested classes/interfaces inherited from class org.datanucleus.store.mapped.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
 
Fields inherited from class org.datanucleus.store.mapped.scostore.AbstractListStore
indexedList
 
Fields inherited from class org.datanucleus.store.mapped.scostore.ElementContainerStore
clr, containerTable, elementInfo, elementIsPersistentInterface, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, emd, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, specialization
 
Fields inherited from class org.datanucleus.store.mapped.scostore.BaseContainerStore
allowNulls, dba, LOCALISER, ownerMapping, ownerMemberMetaData, relationType, storeMgr
 
Constructor Summary
FKListStore(AbstractMemberMetaData fmd, MappedStoreManager storeMgr, ClassLoaderResolver clr, FKListStoreSpecialization specialization)
          Constructor.
 
Method Summary
 void clear(ObjectProvider ownerSM)
          Method to clear the List.
protected  boolean internalAdd(ObjectProvider sm, int startAt, boolean atEnd, java.util.Collection c, int size)
          Internal method for adding an item to the List.
protected  boolean internalRemove(ObjectProvider sm, java.lang.Object element, int size)
          Convenience method to remove the specified element from the List.
protected  void manageRemovalOfElement(ObjectProvider ownerSM, java.lang.Object element)
          Convenience method to manage the removal of an element from the collection, performing any necessary "managed relationship" updates when the field is bidirectional.
protected  void removeAt(ObjectProvider sm, int index, int size)
          Internal method to remove an object at a location in the List.
 java.lang.Object set(ObjectProvider sm, int index, java.lang.Object element, boolean allowDependentField)
          Method to set an object in the List at a position.
 void update(ObjectProvider sm, java.util.Collection coll)
          Method to update the collection to be the supplied collection of elements.
protected  boolean validateElementForWriting(ObjectProvider sm, java.lang.Object element, int index)
          Method to validate that an element is valid for writing to the datastore.
 
Methods inherited from class org.datanucleus.store.mapped.scostore.AbstractListStore
add, add, addAll, addAll, get, getIndicesOf, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, subList
 
Methods inherited from class org.datanucleus.store.mapped.scostore.AbstractCollectionStore
contains, updateEmbeddedElement
 
Methods inherited from class org.datanucleus.store.mapped.scostore.ElementContainerStore
getContainerTable, getElementInfo, getElementInformationForClass, getElementMapping, getElementType, getEmd, getOrderMapping, getRelationDiscriminatorMapping, getRelationDiscriminatorValue, hasOrderMapping, isElementsAreEmbedded, isElementsAreSerialised, size, validateElementForReading, validateElementForWriting, validateElementType
 
Methods inherited from class org.datanucleus.store.mapped.scostore.BaseContainerStore
allowsBatching, getDatastoreAdapter, getOwnerMapping, getOwnerMemberMetaData, getRelationType, getStateManagerForEmbeddedPCObject, getStoreManager, isEmbeddedMapping, setOwner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.datanucleus.store.scostore.CollectionStore
contains, getElementType, hasOrderMapping, size, updateEmbeddedElement
 
Methods inherited from interface org.datanucleus.store.scostore.Store
getStoreManager
 

Constructor Detail

FKListStore

public FKListStore(AbstractMemberMetaData fmd,
                   MappedStoreManager storeMgr,
                   ClassLoaderResolver clr,
                   FKListStoreSpecialization specialization)
Constructor.

Parameters:
fmd - Field MetaData for the field that this represents
storeMgr - The Store Manager in use
clr - The ClassLoaderResolver
specialization - The datastore-specific specialization
Method Detail

set

public java.lang.Object set(ObjectProvider sm,
                            int index,
                            java.lang.Object element,
                            boolean allowDependentField)
Method to set an object in the List at a position.

Parameters:
sm - The state manager
index - The item index
element - What to set it to.
allowDependentField - Whether to enable dependent-field deletes during the set
Returns:
The value before setting.

update

public void update(ObjectProvider sm,
                   java.util.Collection coll)
Method to update the collection to be the supplied collection of elements.

Specified by:
update in interface CollectionStore
Overrides:
update in class AbstractCollectionStore
Parameters:
sm - StateManager of the object
coll - The collection to use

internalAdd

protected boolean internalAdd(ObjectProvider sm,
                              int startAt,
                              boolean atEnd,
                              java.util.Collection c,
                              int size)
Internal method for adding an item to the List.

Specified by:
internalAdd in class AbstractListStore
Parameters:
sm - The state manager
startAt - The start position
atEnd - Whether to add at the end
c - The Collection of elements to add.
size - Current size of list (if known). -1 if not known
Returns:
Whether it was successful

internalRemove

protected boolean internalRemove(ObjectProvider sm,
                                 java.lang.Object element,
                                 int size)
Convenience method to remove the specified element from the List.

Specified by:
internalRemove in class AbstractListStore
Parameters:
sm - StateManager of the owner
element - The element
size - Current size of list if known. -1 if not known
Returns:
Whether the List was modified

manageRemovalOfElement

protected void manageRemovalOfElement(ObjectProvider ownerSM,
                                      java.lang.Object element)
Convenience method to manage the removal of an element from the collection, performing any necessary "managed relationship" updates when the field is bidirectional.

Parameters:
ownerSM - StateManager for the collection owner
element - The element

removeAt

protected void removeAt(ObjectProvider sm,
                        int index,
                        int size)
Internal method to remove an object at a location in the List. Differs from the JoinTable List in that it nulls out the owner FK.

Specified by:
removeAt in class AbstractListStore
Parameters:
sm - The state manager.
index - The location
size - Current size of list (if known). -1 if not known

clear

public void clear(ObjectProvider ownerSM)
Method to clear the List. This is called by the List.clear() method, or when the container object is being deleted and the elements are to be removed (maybe for dependent field), or also when updating a Collection and removing all existing prior to adding all new.

Specified by:
clear in interface CollectionStore
Overrides:
clear in class ElementContainerStore
Parameters:
ownerSM - The state manager

validateElementForWriting

protected boolean validateElementForWriting(ObjectProvider sm,
                                            java.lang.Object element,
                                            int index)
Method to validate that an element is valid for writing to the datastore. TODO Minimise differences to super.validateElementForWriting()

Parameters:
sm - StateManager for the List
element - The element to validate
index - The position that the element is being stored at in the list
Returns:
Whether the element was inserted


Copyright © 2011. All Rights Reserved.