org.datanucleus.store.mapped.scostore
Class JoinSetStore

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.JoinSetStore
All Implemented Interfaces:
CollectionStoreQueryable, CollectionStore, SetStore, Store

public abstract class JoinSetStore
extends AbstractSetStore

Representation of a JoinTable Set as part of a relationship. This class is used where you have a 1-N and the tables are joined via a link table. That is one table is the owner, and it has a link table to another table, with the link table having 2 columns - the ids of the 2 tables. This is in contrast to FKSetStore which represents 1-N relationships without using a link table (using an id in the other table).

For sets of primitive types (e.g Date,String etc), the JoinSetStore is used, but the 'link' table contains the id of the owner and the field(s) representing the primitive type.


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
JoinSetStore(AbstractMemberMetaData mmd, DatastoreContainerObject joinTable, ClassLoaderResolver clr, JavaTypeMapping ownerMapping, JavaTypeMapping elementMapping, JavaTypeMapping orderMapping, JavaTypeMapping relationDiscriminatorMapping, java.lang.String relationDiscriminatorValue, boolean isEmbeddedElement, boolean isSerialisedElement, AbstractSetStoreSpecialization specialization)
          Constructor for the relationship representation.
 
Method Summary
 boolean add(StateManager sm, java.lang.Object element, int size)
          Adds one element to the association owner vs elements.
 boolean addAll(StateManager sm, java.util.Collection elements, int size)
          Adds all elements from a collection to the association container.
protected abstract  int[] doInternalAdd(StateManager sm, java.lang.Object element, ManagedConnection conn, boolean batched, int orderId, boolean executeNow)
           
protected abstract  int getNextIDForOrderColumn(StateManager sm)
          Accessor for the next id when elements primary key can't be part of the primary key by datastore limitations like BLOB types can't be primary keys.
 ScalarExpression joinElementsTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTblExpr, 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.
abstract  boolean locate(StateManager sm, java.lang.Object element)
          Method to check for the existence in the datastore of an owner-element relation.
protected abstract  void preGetNextIDForOrderColumn(ManagedConnection mconn)
           
 boolean removeAll(StateManager sm, java.util.Collection elements, int size)
          Remove all elements from a collection from the association owner vs elements.
protected abstract  boolean removeAllInternal(StateManager sm, java.util.Collection elements, int size)
           
 void update(StateManager sm, java.util.Collection coll)
          Method to update the collection to be the supplied collection of elements.
 
Methods inherited from class org.datanucleus.store.mapped.scostore.AbstractSetStore
iterator, remove
 
Methods inherited from class org.datanucleus.store.mapped.scostore.AbstractCollectionStore
contains, getExistsSubquery, getSizeSubquery, updateEmbeddedElement
 
Methods inherited from class org.datanucleus.store.mapped.scostore.ElementContainerStore
clear, 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
clear, contains, getElementType, hasOrderMapping, size, updateEmbeddedElement
 
Methods inherited from interface org.datanucleus.store.scostore.Store
getStoreManager
 

Constructor Detail

JoinSetStore

public JoinSetStore(AbstractMemberMetaData mmd,
                    DatastoreContainerObject joinTable,
                    ClassLoaderResolver clr,
                    JavaTypeMapping ownerMapping,
                    JavaTypeMapping elementMapping,
                    JavaTypeMapping orderMapping,
                    JavaTypeMapping relationDiscriminatorMapping,
                    java.lang.String relationDiscriminatorValue,
                    boolean isEmbeddedElement,
                    boolean isSerialisedElement,
                    AbstractSetStoreSpecialization specialization)
Constructor for the relationship representation.

Parameters:
mmd - Metadata for the owner member
joinTable - The table for the link
clr - The ClassLoaderResolver
Method Detail

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

removeAll

public boolean removeAll(StateManager sm,
                         java.util.Collection elements,
                         int size)
Remove all elements from a collection from the association owner vs elements.

Specified by:
removeAll in interface CollectionStore
Overrides:
removeAll in class AbstractSetStore
Parameters:
sm - State Manager for the container
elements - Collection of elements to remove
size - Current size of collection if known. -1 if not known
Returns:
Whether the database was updated

removeAllInternal

protected abstract boolean removeAllInternal(StateManager sm,
                                             java.util.Collection elements,
                                             int size)

locate

public abstract boolean locate(StateManager sm,
                               java.lang.Object element)
Method to check for the existence in the datastore of an owner-element relation.

Parameters:
sm - State Manager for the owner
element - The element
Returns:
Whether the relation exists in the datastore

add

public boolean add(StateManager sm,
                   java.lang.Object element,
                   int size)
Adds one element to the association owner vs elements.

Specified by:
add in interface CollectionStore
Overrides:
add in class AbstractSetStore
Parameters:
sm - State Manager for the container.
element - Element to add
size - Current size of the collection if known. -1 if not known
Returns:
Whether it was successful

addAll

public boolean addAll(StateManager sm,
                      java.util.Collection elements,
                      int size)
Adds all elements from a collection to the association container.

Specified by:
addAll in interface CollectionStore
Overrides:
addAll in class AbstractSetStore
Parameters:
sm - State Manager for the container.
elements - Collection of elements to add
size - Current size of set (if known). Not used by sets
Returns:
Whether it was successful

preGetNextIDForOrderColumn

protected abstract void preGetNextIDForOrderColumn(ManagedConnection mconn)
                                            throws MappedDatastoreException
Throws:
MappedDatastoreException

doInternalAdd

protected abstract int[] doInternalAdd(StateManager sm,
                                       java.lang.Object element,
                                       ManagedConnection conn,
                                       boolean batched,
                                       int orderId,
                                       boolean executeNow)
                                throws MappedDatastoreException
Throws:
MappedDatastoreException

getNextIDForOrderColumn

protected abstract int getNextIDForOrderColumn(StateManager sm)
                                        throws MappedDatastoreException
Accessor for the next id when elements primary key can't be part of the primary key by datastore limitations like BLOB types can't be primary keys. Also for where the user wants to allow duplicates.

Parameters:
sm - The State Manager
Returns:
the next id value
Throws:
MappedDatastoreException

joinElementsTo

public ScalarExpression joinElementsTo(QueryExpression stmt,
                                       QueryExpression parentStmt,
                                       JavaTypeMapping ownerMapping,
                                       LogicSetExpression ownerTblExpr,
                                       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 no parent, "parentStmt" must be equal to "stmt"
ownerMapping - the mapping for the owner
ownerTblExpr - 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 element table expression
setTableAlias - The alias for the "Set" table
existsQuery - Whether this is joining for an EXISTS query
Returns:
Expression for the join


Copyright © 2010. All Rights Reserved.