org.datanucleus.store.rdbms.scostore
Class RDBMSFKSetStore

java.lang.Object
  extended by org.datanucleus.store.rdbms.scostore.BaseContainerStore
      extended by org.datanucleus.store.rdbms.scostore.ElementContainerStore
          extended by org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
              extended by org.datanucleus.store.rdbms.scostore.AbstractSetStore
                  extended by org.datanucleus.store.rdbms.scostore.RDBMSFKSetStore
All Implemented Interfaces:
org.datanucleus.store.scostore.CollectionStore, org.datanucleus.store.scostore.SetStore, org.datanucleus.store.scostore.Store

public class RDBMSFKSetStore
extends AbstractSetStore

RDBMS-specific implementation of an SetStore using foreign keys.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
 
Fields inherited from class org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
containsStmt
 
Fields inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
addStmt, clearStmt, clr, containerTable, elementInfo, elementIsPersistentInterface, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, emd, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, removeStmt, sizeStmt, usingDiscriminatorInSizeStmt
 
Fields inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowNulls, dba, LOCALISER, ownerMapping, ownerMemberMetaData, relationType, storeMgr
 
Constructor Summary
RDBMSFKSetStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
          Constructor for the backing store of a FK set for RDBMS.
 
Method Summary
 boolean add(org.datanucleus.store.ObjectProvider op, Object element, int size)
          Method to add an object to the relationship at the collection end.
 boolean addAll(org.datanucleus.store.ObjectProvider op, Collection elements, int size)
          Method to add a collection of object to the relationship at the collection end.
protected  boolean checkRemovalOfElementShouldDelete(org.datanucleus.store.ObjectProvider op)
          Convenience method to return if the removal of an element should delete the element.
 void clear(org.datanucleus.store.ObjectProvider op)
          Method to allow the Set relationship to be cleared out.
protected  String getClearNullifyStmt()
          Generates the statement for clearing items by nulling the owner link out.
protected  int getFieldNumberInElementForBidirectional(org.datanucleus.store.ObjectProvider op)
          This seems to return the field number in the element of the relation when it is a bidirectional relation.
protected  SQLStatement getSQLStatementForIterator(org.datanucleus.store.ObjectProvider op)
          Method to generate an SQLStatement for iterating through elements of the set.
 Iterator iterator(org.datanucleus.store.ObjectProvider op)
          Accessor for an iterator for the set.
protected  void manageRemovalOfElement(org.datanucleus.store.ObjectProvider op, 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.
 boolean remove(org.datanucleus.store.ObjectProvider op, Object element, int size, boolean allowDependentField)
          Method to remove the link to the collection object specified.
 boolean removeAll(org.datanucleus.store.ObjectProvider op, Collection elements, int size)
          Method to remove the links to a collection of elements specified.
 void update(org.datanucleus.store.ObjectProvider op, Collection coll)
          Method to update the collection to be the supplied collection of elements.
 
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractSetStore
internalAdd, internalRemove, remove
 
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
contains, containsInternal, getRemoveStmt, getUpdateEmbeddedElementStmt, updateEmbeddedElement, updateEmbeddedElement
 
Methods inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
executeClear, getAddStmt, getClearStmt, getContainerTable, getElementInfo, getElementInformationForClass, getElementMapping, getEmd, getOrderMapping, getRelationDiscriminatorMapping, getRelationDiscriminatorValue, getSize, getSizeStmt, hasOrderMapping, invalidateAddStmt, isElementsAreEmbedded, isElementsAreSerialised, size, validateElementForReading, validateElementForWriting, validateElementType
 
Methods inherited from class org.datanucleus.store.rdbms.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, hasOrderMapping, size, updateEmbeddedElement
 
Methods inherited from interface org.datanucleus.store.scostore.Store
getStoreManager
 

Constructor Detail

RDBMSFKSetStore

public RDBMSFKSetStore(org.datanucleus.metadata.AbstractMemberMetaData mmd,
                       RDBMSStoreManager storeMgr,
                       org.datanucleus.ClassLoaderResolver clr)
Constructor for the backing store of a FK set for RDBMS.

Parameters:
mmd - The MetaData for the field that this represents
storeMgr - The MappedStoreManager managing the associated datastore.
clr - The ClassLoaderResolver
Method Detail

getFieldNumberInElementForBidirectional

protected int getFieldNumberInElementForBidirectional(org.datanucleus.store.ObjectProvider op)
This seems to return the field number in the element of the relation when it is a bidirectional relation.

Parameters:
op - ObjectProvider for the owner.
Returns:
The field number in the element for this relation

update

public void update(org.datanucleus.store.ObjectProvider op,
                   Collection coll)
Method to update the collection to be the supplied collection of elements.

Specified by:
update in interface org.datanucleus.store.scostore.CollectionStore
Overrides:
update in class AbstractCollectionStore
Parameters:
op - ObjectProvider for the owner.
coll - The collection to use

add

public boolean add(org.datanucleus.store.ObjectProvider op,
                   Object element,
                   int size)
Method to add an object to the relationship at the collection end.

Specified by:
add in interface org.datanucleus.store.scostore.CollectionStore
Overrides:
add in class AbstractSetStore
Parameters:
op - ObjectProvider for the owner.
element - Element to be added
Returns:
Success indicator

addAll

public boolean addAll(org.datanucleus.store.ObjectProvider op,
                      Collection elements,
                      int size)
Method to add a collection of object to the relationship at the collection end.

Specified by:
addAll in interface org.datanucleus.store.scostore.CollectionStore
Overrides:
addAll in class AbstractSetStore
Parameters:
op - ObjectProvider for the owner.
elements - Elements to be added
size - Current size of set (if known). Not used by sets
Returns:
Success indicator

remove

public boolean remove(org.datanucleus.store.ObjectProvider op,
                      Object element,
                      int size,
                      boolean allowDependentField)
Method to remove the link to the collection object specified. Depending on the column characteristics in the collection table, the id of the owner field may be NULLed, or the record may be deleted completely (as per cascade-delete in EJB).

Specified by:
remove in interface org.datanucleus.store.scostore.CollectionStore
Overrides:
remove in class AbstractSetStore
Parameters:
op - ObjectProvider for the owner.
element - The element of the collection to be deleted.
allowDependentField - Whether to allow any cascade deletes caused by this removal
size - Current size
Returns:
A success indicator.

removeAll

public boolean removeAll(org.datanucleus.store.ObjectProvider op,
                         Collection elements,
                         int size)
Method to remove the links to a collection of elements specified. Depending on the column characteristics in the collection table, the id of the owner fields may be NULLed, or the records may be deleted completely.

Specified by:
removeAll in interface org.datanucleus.store.scostore.CollectionStore
Overrides:
removeAll in class AbstractSetStore
Parameters:
op - ObjectProvider for the owner.
elements - The elements of the collection to be deleted.
Returns:
A success indicator.

checkRemovalOfElementShouldDelete

protected boolean checkRemovalOfElementShouldDelete(org.datanucleus.store.ObjectProvider op)
Convenience method to return if the removal of an element should delete the element.

Parameters:
op - ObjectProvider for the owner.
Returns:
Whether we should delete the element on removing from the collection

manageRemovalOfElement

protected void manageRemovalOfElement(org.datanucleus.store.ObjectProvider op,
                                      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:
op - ObjectProvider for the owner.
element - The element

clear

public void clear(org.datanucleus.store.ObjectProvider op)
Method to allow the Set relationship to be cleared out. 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 org.datanucleus.store.scostore.CollectionStore
Overrides:
clear in class ElementContainerStore
Parameters:
op - ObjectProvider for the owner.

getClearNullifyStmt

protected String getClearNullifyStmt()
Generates the statement for clearing items by nulling the owner link out. The statement will be
 UPDATE LISTTABLE SET OWNERCOL=NULL [,DISTINGUISHER=NULL]
 WHERE OWNERCOL=?
 
when there is only one element table, and will be
 UPDATE  SET OWNERCOL=NULL [,DISTINGUISHER=NULL]
 WHERE OWNERCOL=?
 
 when there is more than 1 element table.

Returns:
The Statement for clearing items for the owner.

iterator

public Iterator iterator(org.datanucleus.store.ObjectProvider op)
Accessor for an iterator for the set.

Specified by:
iterator in interface org.datanucleus.store.scostore.CollectionStore
Specified by:
iterator in class AbstractSetStore
Parameters:
op - ObjectProvider for the owner.
Returns:
Iterator for the set.

getSQLStatementForIterator

protected SQLStatement getSQLStatementForIterator(org.datanucleus.store.ObjectProvider op)
Method to generate an SQLStatement for iterating through elements of the set. Selects the element table. Populates the iteratorMappingDef and iteratorMappingParams.

Parameters:
op - ObjectProvider for the owner.
Returns:
The SQLStatement


Copyright © 2012. All Rights Reserved.