org.jpox.store.rdbms.scostore
Class AbstractCollectionStore

java.lang.Object
  extended by org.jpox.store.rdbms.scostore.ElementContainerStore
      extended by org.jpox.store.rdbms.scostore.AbstractCollectionStore
All Implemented Interfaces:
org.jpox.store.mapped.scostore.CollectionStoreQueryable, org.jpox.store.scostore.CollectionStore, org.jpox.store.scostore.Store
Direct Known Subclasses:
FKListStore, FKSetStore, JoinListStore, JoinSetStore, MapKeySetStore, MapValueSetStore

public abstract class AbstractCollectionStore
extends ElementContainerStore
implements org.jpox.store.scostore.CollectionStore, org.jpox.store.mapped.scostore.CollectionStoreQueryable

Abstract representation of a store of a Collection. Contains all common parts of storing Sets and Lists.

Version:
$Revision: 1.62 $

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
protected  boolean allowsNull
          Whether the container allows null elements/values.
protected  java.lang.String containsStmt
          Statement for getting whether an element is contained in the collection.
protected  org.jpox.store.mapped.DatastoreAdapter dba
          Datastore adapter in use by this store.
protected static org.jpox.util.Localiser LOCALISER
          Localiser for messages.
protected  org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping
          Mapping to the owner of the container.
protected  org.jpox.metadata.AbstractMemberMetaData ownerMemberMetaData
          MetaData for the field/property in the owner with this container.
protected  RDBMSManager storeMgr
          Manager for the store.
 
Fields inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
addStmt, clearStmt, clr, containerTable, elementInfo, elementIsPersistentInterface, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, elmIdentifier, emd, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, removeStmt, usingDiscriminatorInSizeStmt
 
Constructor Summary
protected AbstractCollectionStore(org.jpox.store.StoreManager storeMgr, org.jpox.ClassLoaderResolver clr)
          Constructor.
 
Method Summary
protected  boolean allowsBatching()
          Convenience method to return if the RDBMS supports batching and the user wants batching.
 boolean contains(org.jpox.StateManager sm, java.lang.Object element)
          Method to verify if the association owner vs elements contains a specific element in the association
protected  java.lang.String getContainsStmt()
          Generate statement for retrieving the contents of the Collection.
 org.jpox.store.mapped.expression.QueryExpression getExistsSubquery(org.jpox.store.mapped.expression.QueryExpression qs, org.jpox.store.mapped.mapping.JavaTypeMapping mapping, org.jpox.store.mapped.expression.LogicSetExpression ownerTe, org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias)
          Query utility to generate an exists() statement for an element.
 org.jpox.store.mapped.mapping.JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
protected  java.lang.String getRemoveStmt()
          Generate statement for removing an element from the Collection.
 org.jpox.store.mapped.expression.QueryExpression getSizeSubquery(org.jpox.store.mapped.expression.QueryExpression qs, org.jpox.store.mapped.mapping.JavaTypeMapping mapping, org.jpox.store.mapped.expression.LogicSetExpression ownerTe, org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias)
          Query utility to generate a subquery for the size() of the collection.
protected  org.jpox.StateManager getStateManagerForEmbeddedPCObject(org.jpox.StateManager sm, java.lang.Object obj, JoinTable table)
          Method to return the StateManager for an embedded PC object (element, key, value).
 org.jpox.store.StoreManager getStoreManager()
          Accessor for the RDBMSManager.
protected  java.lang.String getUpdateEmbeddedElementStmt(org.jpox.store.mapped.mapping.JavaTypeMapping fieldMapping)
          Generate statement for update the field of an embedded element.
protected  int[] internalRemove(org.jpox.StateManager ownerSM, org.jpox.ManagedConnection conn, boolean batched, java.lang.Object element, boolean executeNow)
          Method to process a "remove" statement
protected  boolean isEmbeddedMapping(org.jpox.store.mapped.mapping.JavaTypeMapping mapping)
          Check if the mapping correspond to a non pc object or embedded field
protected  int populateOwnerInStatement(org.jpox.StateManager sm, org.jpox.ObjectManager om, java.sql.PreparedStatement ps, int jdbcPosition)
          Convenience method to populate the passed PreparedStatement with the value from the owner.
protected  void setOwnerMemberMetaData(org.jpox.metadata.AbstractMemberMetaData mmd)
          Method to set the owner field/property MetaData and sets whether null elements/values are allowed.
 boolean updateEmbeddedElement(org.jpox.StateManager sm, java.lang.Object element, int fieldNumber, java.lang.Object value)
          Method to update a field of an embedded element.
 
Methods inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
clear, getAddStmt, getClearStmt, getElementInformationForClass, getElementType, getSizeStmt, hasOrderMapping, iterator, newResultObjectFactory, populateElementDiscriminatorInStatement, populateElementInStatement, populateEmbeddedElementFieldsInStatement, populateOrderInStatement, populateRelationDiscriminatorInStatement, size, validateElementForReading, validateElementForWriting, validateElementType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jpox.store.scostore.CollectionStore
add, addAll, clear, getElementType, hasOrderMapping, iterator, remove, removeAll, size
 
Methods inherited from interface org.jpox.store.scostore.Store
getStoreManager
 
Methods inherited from interface org.jpox.store.mapped.scostore.CollectionStoreQueryable
joinElementsTo, newQueryStatement, newResultObjectFactory
 

Field Detail

containsStmt

protected java.lang.String containsStmt
Statement for getting whether an element is contained in the collection.


LOCALISER

protected static final org.jpox.util.Localiser LOCALISER
Localiser for messages.


storeMgr

protected RDBMSManager storeMgr
Manager for the store.


dba

protected org.jpox.store.mapped.DatastoreAdapter dba
Datastore adapter in use by this store.


ownerMapping

protected org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping
Mapping to the owner of the container.


ownerMemberMetaData

protected org.jpox.metadata.AbstractMemberMetaData ownerMemberMetaData
MetaData for the field/property in the owner with this container.


allowsNull

protected boolean allowsNull
Whether the container allows null elements/values.

Constructor Detail

AbstractCollectionStore

protected AbstractCollectionStore(org.jpox.store.StoreManager storeMgr,
                                  org.jpox.ClassLoaderResolver clr)
Constructor.

Parameters:
storeMgr - Manager for the store
clr - ClassLoader resolver
Method Detail

getUpdateEmbeddedElementStmt

protected java.lang.String getUpdateEmbeddedElementStmt(org.jpox.store.mapped.mapping.JavaTypeMapping fieldMapping)
Generate statement for update the field of an embedded element.
 UPDATE SETTABLE
 SET EMBEDDEDFIELD1 = ?
 WHERE OWNERCOL=?
 AND ELEMENTCOL = ?
 

Parameters:
fieldMapping - The mapping for the field within the embedded object to be updated
Returns:
Statement for updating an embedded element in the Set

updateEmbeddedElement

public boolean updateEmbeddedElement(org.jpox.StateManager sm,
                                     java.lang.Object element,
                                     int fieldNumber,
                                     java.lang.Object value)
Method to update a field of an embedded element.

Specified by:
updateEmbeddedElement in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - State Manager of the owner
element - The element to update
fieldNumber - The number of the field to update
value - The value
Returns:
true if the datastore was updated

getContainsStmt

protected java.lang.String getContainsStmt()
Generate statement for retrieving the contents of the Collection. The discriminator part is only present when the element type has inheritance strategy of "superclass-table" and is Inverse.
 SELECT OWNERCOL FROM COLLECTIONTABLE 
 WHERE OWNERCOL=?
 AND ELEMENTCOL=?
 [AND DISCRIMINATOR=?]
 [AND RELATION_DISCRIM=?]
 

Returns:
Statement for retrieving the contents of the Collection.

contains

public boolean contains(org.jpox.StateManager sm,
                        java.lang.Object element)
Method to verify if the association owner vs elements contains a specific element in the association

Specified by:
contains in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - The StateManager
element - The element
Returns:
Whether it contains the element

internalRemove

protected int[] internalRemove(org.jpox.StateManager ownerSM,
                               org.jpox.ManagedConnection conn,
                               boolean batched,
                               java.lang.Object element,
                               boolean executeNow)
                        throws java.sql.SQLException
Method to process a "remove" statement

Parameters:
ownerSM - StateManager for the owner
conn - The connection
batched - Whether we are batching it
element - The element
executeNow - Whether to execute the statement rather than allow batching til later
Returns:
Number of records changed (0 if batch since nothing yet changed)
Throws:
java.sql.SQLException - Thrown if an error occurs

getRemoveStmt

protected java.lang.String getRemoveStmt()
Generate statement for removing an element from the Collection.
 DELETE FROM COLLTABLE WHERE OWNERCOL=? AND ELEMENTCOL = ? [AND DISCRIM = ?]
 

Returns:
Statement for deleting an item from the Collection.

getExistsSubquery

public org.jpox.store.mapped.expression.QueryExpression getExistsSubquery(org.jpox.store.mapped.expression.QueryExpression qs,
                                                                          org.jpox.store.mapped.mapping.JavaTypeMapping mapping,
                                                                          org.jpox.store.mapped.expression.LogicSetExpression ownerTe,
                                                                          org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias)
Query utility to generate an exists() statement for an element. The generated query will be of the form
 SELECT 1 FROM JOINTABLE THIS_JOIN WHERE THIS_JOIN.OWNER_ID_OID = THIS.OWNER_ID
 

Specified by:
getExistsSubquery in interface org.jpox.store.mapped.scostore.CollectionStoreQueryable
Parameters:
qs - The parent query statement that will use this as a subquery
mapping - mapping for the owner
ownerTe - Expression for the table that the subquery should join to
collectionTableAlias - alias for the main table of the subquery
Returns:
The query statement

getSizeSubquery

public org.jpox.store.mapped.expression.QueryExpression getSizeSubquery(org.jpox.store.mapped.expression.QueryExpression qs,
                                                                        org.jpox.store.mapped.mapping.JavaTypeMapping mapping,
                                                                        org.jpox.store.mapped.expression.LogicSetExpression ownerTe,
                                                                        org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias)
Query utility to generate a subquery for the size() of the collection. The generated query will be of the form
 SELECT COUNT(*) FROM JOINTABLE THIS_JOIN WHERE THIS_JOIN.OWNER_ID_OID = THIS.OWNER_ID
 

Specified by:
getSizeSubquery in interface org.jpox.store.mapped.scostore.CollectionStoreQueryable
Parameters:
qs - The parent query statement that will use this as a subquery
mapping - mapping of the field
ownerTe - Expression for the owner table that the subquery should join to
collectionTableAlias - alias for the main table of the subquery
Returns:
The query statement

setOwnerMemberMetaData

protected void setOwnerMemberMetaData(org.jpox.metadata.AbstractMemberMetaData mmd)
Method to set the owner field/property MetaData and sets whether null elements/values are allowed.

Parameters:
mmd - MetaData for the field/property owning this backing store.

getStoreManager

public org.jpox.store.StoreManager getStoreManager()
Accessor for the RDBMSManager.

Returns:
The RDBMSManager.

getOwnerMapping

public org.jpox.store.mapped.mapping.JavaTypeMapping getOwnerMapping()
Accessor for the owner mapping.

Returns:
Owner mapping.

isEmbeddedMapping

protected boolean isEmbeddedMapping(org.jpox.store.mapped.mapping.JavaTypeMapping mapping)
Check if the mapping correspond to a non pc object or embedded field

Parameters:
mapping - the mapping
Returns:
true if the field is embedded into one column

populateOwnerInStatement

protected int populateOwnerInStatement(org.jpox.StateManager sm,
                                       org.jpox.ObjectManager om,
                                       java.sql.PreparedStatement ps,
                                       int jdbcPosition)
Convenience method to populate the passed PreparedStatement with the value from the owner.

Parameters:
sm - State Manager
om - Object Manager
ps - The PreparedStatement
jdbcPosition - Position in JDBC statement to populate
Returns:
The next position in the JDBC statement

getStateManagerForEmbeddedPCObject

protected org.jpox.StateManager getStateManagerForEmbeddedPCObject(org.jpox.StateManager sm,
                                                                   java.lang.Object obj,
                                                                   JoinTable table)
Method to return the StateManager for an embedded PC object (element, key, value). It creates one if the element is not currently managed.

Parameters:
sm - State Manager of the owner
obj - The embedded PC object
table - Join table where the objects are stored
Returns:
The state manager

allowsBatching

protected boolean allowsBatching()
Convenience method to return if the RDBMS supports batching and the user wants batching.

Returns:
If batching of statements is permissible


Copyright © -2008 . All Rights Reserved.