org.jpox.store.rdbms.scostore
Class AbstractArrayStore

java.lang.Object
  extended by org.jpox.store.rdbms.scostore.ElementContainerStore
      extended by org.jpox.store.rdbms.scostore.AbstractArrayStore
All Implemented Interfaces:
org.jpox.store.mapped.scostore.ArrayStoreQueryable, org.jpox.store.scostore.ArrayStore, org.jpox.store.scostore.Store
Direct Known Subclasses:
FKArrayStore, JoinArrayStore

public abstract class AbstractArrayStore
extends ElementContainerStore
implements org.jpox.store.scostore.ArrayStore, org.jpox.store.mapped.scostore.ArrayStoreQueryable

Abstract representation of the backing store for an array.

Version:
$Revision: 1.37 $

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  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 AbstractArrayStore(org.jpox.store.StoreManager storeMgr, org.jpox.ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 boolean add(org.jpox.StateManager sm, java.lang.Object element, int position)
          Adds one element to the association owner vs elements
protected  boolean allowsBatching()
          Convenience method to return if the RDBMS supports batching and the user wants batching.
 void clear(org.jpox.StateManager ownerSM)
          Clear the association from owner to all elements.
 java.util.List getArray(org.jpox.StateManager ownerSM)
          Accessor for the array from the datastore.
 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 arrayTableAlias)
          Query utility to generate an exists() statement for an element.
protected abstract  org.jpox.store.mapped.expression.QueryExpression getIteratorStatement(org.jpox.StateManager ownerSM)
          Accessor for the statement for the iterator.
 org.jpox.store.mapped.mapping.JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
 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 arrayTableAlias)
          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  int[] internalAdd(org.jpox.StateManager sm, java.lang.Object element, org.jpox.ManagedConnection conn, boolean batched, int orderId, boolean executeNow)
          Internal method to add a row to the join table.
protected  boolean isEmbeddedMapping(org.jpox.store.mapped.mapping.JavaTypeMapping mapping)
          Check if the mapping correspond to a non pc object or embedded field
 java.util.Iterator iterator(org.jpox.StateManager ownerSM)
          Accessor for an iterator through the array elements.
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.
 boolean set(org.jpox.StateManager ownerSM, java.lang.Object array)
          Method to set the array for the specified owner to the passed value.
protected  void setOwnerMemberMetaData(org.jpox.metadata.AbstractMemberMetaData mmd)
          Method to set the owner field/property MetaData and sets whether null elements/values are allowed.
 
Methods inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
getAddStmt, getClearStmt, getElementInformationForClass, getElementType, getSizeStmt, hasOrderMapping, 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.ArrayStore
getElementType, size
 
Methods inherited from interface org.jpox.store.scostore.Store
getStoreManager
 
Methods inherited from interface org.jpox.store.mapped.scostore.ArrayStoreQueryable
joinElementsTo
 

Field Detail

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

AbstractArrayStore

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

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

getArray

public java.util.List getArray(org.jpox.StateManager ownerSM)
Accessor for the array from the datastore.

Specified by:
getArray in interface org.jpox.store.scostore.ArrayStore
Parameters:
ownerSM - SM for the owner
Returns:
The array (as a List of objects)

clear

public void clear(org.jpox.StateManager ownerSM)
Clear the association from owner to all elements. Observes the necessary dependent field settings with respect to whether it should delete the element when doing so.

Specified by:
clear in interface org.jpox.store.scostore.ArrayStore
Overrides:
clear in class ElementContainerStore
Parameters:
ownerSM - State Manager for the container.

set

public boolean set(org.jpox.StateManager ownerSM,
                   java.lang.Object array)
Method to set the array for the specified owner to the passed value.

Specified by:
set in interface org.jpox.store.scostore.ArrayStore
Parameters:
ownerSM - State Manager for the owner
array - the array
Returns:
Whether the array was updated successfully

add

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

Parameters:
sm - State Manager for the container
element - The element to add
position - The position to add this element at
Returns:
Whether it was successful

internalAdd

protected int[] internalAdd(org.jpox.StateManager sm,
                            java.lang.Object element,
                            org.jpox.ManagedConnection conn,
                            boolean batched,
                            int orderId,
                            boolean executeNow)
                     throws java.sql.SQLException
Internal method to add a row to the join table. Used by add() and set() to add a row to the join table.

Parameters:
sm - StateManager for the owner of the collection
element - The element to add the relation to
conn - The connection
batched - Whether we are batching
orderId - The order id to use for this element relation
executeNow - Whether to execute the statement now (and not wait for any batch)
Returns:
Whether a row was inserted
Throws:
java.sql.SQLException - Thrown if an error occurs

getIteratorStatement

protected abstract org.jpox.store.mapped.expression.QueryExpression getIteratorStatement(org.jpox.StateManager ownerSM)
Accessor for the statement for the iterator.

Parameters:
ownerSM - the owner StateManager
Returns:
The iterator Query Statement.

iterator

public java.util.Iterator iterator(org.jpox.StateManager ownerSM)
Accessor for an iterator through the array elements.

Specified by:
iterator in interface org.jpox.store.scostore.ArrayStore
Specified by:
iterator in class ElementContainerStore
Parameters:
ownerSM - State Manager for the container.
Returns:
The Iterator

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 arrayTableAlias)
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.ArrayStoreQueryable
Parameters:
qs - The JDOQL query statement
mapping - mapping of the field
ownerTe - Expression for the table
arrayTableAlias - alias for the array
Returns:
The JDOQL 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 arrayTableAlias)
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.ArrayStoreQueryable
Parameters:
qs - The query statement
mapping - mapping of the field
ownerTe - Expression for the table
arrayTableAlias - alias for the array
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.