org.datanucleus.store.mapped.scostore
Class FKSetStore

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.AbstractSetStore
                  extended by org.datanucleus.store.mapped.scostore.FKSetStore
All Implemented Interfaces:
CollectionStoreQueryable, CollectionStore, SetStore, Store

public abstract class FKSetStore
extends AbstractSetStore

Representation of an Inverse Set as part of a relationship. This class is used where you have a 1-N and the tables are not joined via a link table. That is there is an owner table, and a collection table, and the collection table has a column being the id of the owner table. This is in contrast to NormalSetStore which represents 1-N relationships using a link 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.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
allowsNull, dba, LOCALISER, ownerMapping, ownerMemberMetaData, relationType, storeMgr
 
Constructor Summary
FKSetStore(AbstractMemberMetaData fmd, MappedStoreManager storeMgr, ClassLoaderResolver clr, AbstractSetStoreSpecialization specialization)
          Constructor for the relationship representation.
 
Method Summary
 boolean add(StateManager sm, java.lang.Object element, int size)
          Method to add an object to the relationship at the collection end.
 boolean addAll(StateManager sm, java.util.Collection elements, int size)
          Method to add a collection of object to the relationship at the collection end.
protected  boolean checkRemovalOfElementShouldDelete(StateManager ownerSM)
          Convenience method to return if the removal of an element should delete the element.
 void clear(StateManager ownerSM)
          Method to allow the Set relationship to be cleared out.
protected abstract  void clearInternal(StateManager ownerSM, ObjectManager om)
           
protected  int getFieldNumberInElementForBidirectional(StateManager sm)
          This seems to return the field number in the element of the relation when it is a bidirectional relation.
 ScalarExpression joinElementsTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier setTableAlias, java.lang.Class filteredElementType, ScalarExpression elementExpr, DatastoreIdentifier elementTableAlias, boolean existsQuery)
          Utility for use in building a query, joining the element table and the owner table.
protected  void manageRemovalOfElement(StateManager 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.
 boolean remove(StateManager ownerSM, java.lang.Object element, int size, boolean allowDependentField)
          Method to remove the link to the collection object specified.
 boolean removeAll(StateManager sm, java.util.Collection elements, int size)
          Method to remove the links to a collection of elements specified.
 void update(StateManager sm, java.util.Collection coll)
          Method to update the collection to be the supplied collection of elements.
protected abstract  boolean updateElementFkInternal(StateManager sm, java.lang.Object element, java.lang.Object owner)
           
 
Methods inherited from class org.datanucleus.store.mapped.scostore.AbstractSetStore
iterator
 
Methods inherited from class org.datanucleus.store.mapped.scostore.AbstractCollectionStore
contains, getExistsSubquery, getSizeSubquery, 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

FKSetStore

public FKSetStore(AbstractMemberMetaData fmd,
                  MappedStoreManager storeMgr,
                  ClassLoaderResolver clr,
                  AbstractSetStoreSpecialization specialization)
Constructor for the relationship representation.

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

getFieldNumberInElementForBidirectional

protected int getFieldNumberInElementForBidirectional(StateManager sm)
This seems to return the field number in the element of the relation when it is a bidirectional relation.

Parameters:
sm - StateManager of the owner
Returns:
The field number in the element for this relation

update

public void update(StateManager 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

add

public boolean add(StateManager sm,
                   java.lang.Object element,
                   int size)
Method to add an object to the relationship at the collection end.

Specified by:
add in interface CollectionStore
Overrides:
add in class AbstractSetStore
Parameters:
sm - StateManager of the owner of the Set
element - Element to be added
size - Current size of the collection if known. -1 if not known
Returns:
Success indicator

addAll

public boolean addAll(StateManager sm,
                      java.util.Collection elements,
                      int size)
Method to add a collection of object to the relationship at the collection end.

Specified by:
addAll in interface CollectionStore
Overrides:
addAll in class AbstractSetStore
Parameters:
sm - StateManager of the Set
elements - Elements to be added
size - Current size of set (if known). Not used by sets
Returns:
Success indicator

remove

public boolean remove(StateManager ownerSM,
                      java.lang.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 CollectionStore
Overrides:
remove in class AbstractSetStore
Parameters:
ownerSM - The StateManager of the Set
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(StateManager sm,
                         java.util.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 CollectionStore
Overrides:
removeAll in class AbstractSetStore
Parameters:
sm - The StateManager of the Set
elements - The elements of the collection to be deleted.
size - Current size of collection if known. -1 if not known
Returns:
A success indicator.

checkRemovalOfElementShouldDelete

protected boolean checkRemovalOfElementShouldDelete(StateManager ownerSM)
Convenience method to return if the removal of an element should delete the element.

Parameters:
ownerSM - StateManager for the owner
Returns:
Whether we should delete the element on removing from the collection

manageRemovalOfElement

protected void manageRemovalOfElement(StateManager 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

clear

public void clear(StateManager ownerSM)
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 CollectionStore
Overrides:
clear in class ElementContainerStore
Parameters:
ownerSM - StateManager of the Set

joinElementsTo

public ScalarExpression joinElementsTo(QueryExpression stmt,
                                       QueryExpression parentStmt,
                                       JavaTypeMapping ownerMapping,
                                       LogicSetExpression ownerTe,
                                       DatastoreIdentifier setTableAlias,
                                       java.lang.Class filteredElementType,
                                       ScalarExpression elementExpr,
                                       DatastoreIdentifier elementTableAlias,
                                       boolean existsQuery)
Utility for use in building a query, joining the element table and the owner table.

Parameters:
stmt - The Query Statement
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - the mapping for the owner.
ownerTe - Table Expression for the owner
filteredElementType - The Class Type for the filtered element
elementExpr - The Expression for the element
elementTableAlias - The SQL alias to assign to the expression or to the element table.
setTableAlias - The alias for the "Set" table
existsQuery - Whether this is joining for an EXISTS query
Returns:
Expression for the id of the elements table

clearInternal

protected abstract void clearInternal(StateManager ownerSM,
                                      ObjectManager om)

updateElementFkInternal

protected abstract boolean updateElementFkInternal(StateManager sm,
                                                   java.lang.Object element,
                                                   java.lang.Object owner)


Copyright © 2010. All Rights Reserved.