org.jpox.sco
Class SCOUtils

java.lang.Object
  extended byorg.jpox.sco.SCOUtils

public class SCOUtils
extends java.lang.Object

Collection of utilities for second class objects.

Version:
$Revision: 1.33 $

Constructor Summary
SCOUtils()
           
 
Method Summary
static boolean arrayIsStoredInSingleColumn(AbstractPropertyMetaData fmd)
          Convenience method to return if an array field has the elements stored into the table of the field as a single (BLOB) column.
static boolean collectionHasElementsWithoutIdentity(AbstractPropertyMetaData fmd)
          Convenience method to return if a collection field has elements without their own identity.
static boolean collectionHasSerialisedElements(AbstractPropertyMetaData fmd)
          Convenience method to return if a collection field has the elements serialised into the table of the field as a single BLOB.
static boolean mapHasKeysWithoutIdentity(AbstractPropertyMetaData fmd)
          Convenience method to return if a map field has keys without their own identity.
static boolean mapHasSerialisedKeysAndValues(AbstractPropertyMetaData fmd)
          Convenience method to return if a map field has the keys/values serialised into the table of the field as a single BLOB.
static boolean mapHasValuesWithoutIdentity(AbstractPropertyMetaData fmd)
          Convenience method to return if a map field has values without their own identity.
static SCO newSCOInstance(java.lang.Class declaredType, java.lang.Object ownerSM, AbstractPropertyMetaData fmd, java.lang.Object value, boolean forUpdate)
          Method to create a new SCO wrapper for a SCO type.
static void populateMapDelegateWithStoreData(java.util.Map delegate, MapStore store, StateManager ownerSM)
          Convenience method to populate the passed delegate Map with the keys/values from the associated Store.
static java.lang.Object[] toArray(CollectionStore backingStore, StateManager sm)
          Returns true if this collection contains the specified element.
static java.lang.Object[] toArray(CollectionStore backingStore, StateManager sm, java.lang.Object[] a)
          Returns an array containing all of the elements in this collection;
static void updateCollectionWithCollection(java.util.Collection coll, java.util.Collection newColl)
          Convenience method to update a collection to contain the elements in another collection.
static void updateStoreWithCollection(CollectionStore store, StateManager ownerSM, java.util.Collection newColl)
          Convenience method to update a Store collection to contain the elements in another collection.
static boolean useCachedLazyLoading(StateManager ownerSM, java.lang.String fieldName, AbstractClassMetaData cmd)
          Accessor for whether the use lazy loading when caching the collection.
static boolean useContainerCache(StateManager ownerSM, java.lang.String fieldName, AbstractClassMetaData cmd)
          Utility to return whether or not to use the container cache for the collection/map for the passed StateManager SCO.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SCOUtils

public SCOUtils()
Method Detail

newSCOInstance

public static SCO newSCOInstance(java.lang.Class declaredType,
                                 java.lang.Object ownerSM,
                                 AbstractPropertyMetaData fmd,
                                 java.lang.Object value,
                                 boolean forUpdate)
Method to create a new SCO wrapper for a SCO type. The SCO wrapper will be appropriate for the passed value (which represents the instantiated type of the field) unless it is null when the wrapper will be appropriate for the declared type of the field.

Parameters:
declaredType - The class of the object
ownerSM - State Manager for the owning object
fmd - The Field MetaData for the related field.
value - The value we are wrapping
forUpdate - Whether the SCO needs updating in the datastore with this value
Returns:
The Second-Class Object

useContainerCache

public static boolean useContainerCache(StateManager ownerSM,
                                        java.lang.String fieldName,
                                        AbstractClassMetaData cmd)
Utility to return whether or not to use the container cache for the collection/map for the passed StateManager SCO.

Parameters:
ownerSM - The StateManager for the SCO field
fieldName - Name of the field.
cmd - MetaData for class
Returns:
Whether to use the cache.

useCachedLazyLoading

public static boolean useCachedLazyLoading(StateManager ownerSM,
                                           java.lang.String fieldName,
                                           AbstractClassMetaData cmd)
Accessor for whether the use lazy loading when caching the collection.

Parameters:
ownerSM - StateManager of the owning object
fieldName - Name of the collection/map field
cmd - MetaData for the class
Returns:
Whether to use lazy loading when caching the collection

collectionHasElementsWithoutIdentity

public static boolean collectionHasElementsWithoutIdentity(AbstractPropertyMetaData fmd)
Convenience method to return if a collection field has elements without their own identity. Checks if the elements are embedded in a join table, or in the main table, or serialised.

Parameters:
fmd - MetaData for the field
Returns:
Whether the elements have their own identity or not

mapHasKeysWithoutIdentity

public static boolean mapHasKeysWithoutIdentity(AbstractPropertyMetaData fmd)
Convenience method to return if a map field has keys without their own identity. Checks if the keys are embedded in a join table, or in the main table, or serialised.

Parameters:
fmd - MetaData for the field
Returns:
Whether the keys have their own identity or not

mapHasValuesWithoutIdentity

public static boolean mapHasValuesWithoutIdentity(AbstractPropertyMetaData fmd)
Convenience method to return if a map field has values without their own identity. Checks if the values are embedded in a join table, or in the main table, or serialised.

Parameters:
fmd - MetaData for the field
Returns:
Whether the values have their own identity or not

collectionHasSerialisedElements

public static boolean collectionHasSerialisedElements(AbstractPropertyMetaData fmd)
Convenience method to return if a collection field has the elements serialised into the table of the field as a single BLOB.

Parameters:
fmd - MetaData for the field
Returns:
Whether the elements are serialised (either explicitly or implicitly)

arrayIsStoredInSingleColumn

public static boolean arrayIsStoredInSingleColumn(AbstractPropertyMetaData fmd)
Convenience method to return if an array field has the elements stored into the table of the field as a single (BLOB) column.

Parameters:
fmd - MetaData for the field
Returns:
Whether the elements are stored in a single column

mapHasSerialisedKeysAndValues

public static boolean mapHasSerialisedKeysAndValues(AbstractPropertyMetaData fmd)
Convenience method to return if a map field has the keys/values serialised into the table of the field as a single BLOB.

Parameters:
fmd - MetaData for the field
Returns:
Whether the keys and values are serialised (either explicitly or implicitly)

updateCollectionWithCollection

public static void updateCollectionWithCollection(java.util.Collection coll,
                                                  java.util.Collection newColl)
Convenience method to update a collection to contain the elements in another collection. Performs the updates by calling the necessary add(), remove() methods just for the elements that have changed. Allows for some elements in one collection being attached and some being detached (so having same id, but different state)

Parameters:
coll - The collection to update
newColl - The new collection whose elements we need in "coll"

updateStoreWithCollection

public static void updateStoreWithCollection(CollectionStore store,
                                             StateManager ownerSM,
                                             java.util.Collection newColl)
Convenience method to update a Store collection to contain the elements in another collection. Performs the updates by calling the necessary add(), remove() methods just for the elements that have changed. Allows for some elements in one collection being attached and some being detached (so having same id, but different state)

Parameters:
store - The store to apply changes to
ownerSM - StateManager of the owner
newColl - The new collection whose elements we need in "coll"

populateMapDelegateWithStoreData

public static void populateMapDelegateWithStoreData(java.util.Map delegate,
                                                    MapStore store,
                                                    StateManager ownerSM)
Convenience method to populate the passed delegate Map with the keys/values from the associated Store.

The issue here is that we need to load the keys and values in as few calls as possible. The method employed here reads in the keys (if PersistenceCapable), then the values (if PersistenceCapable), and then the "entries" (ids of keys and values) so we can associate the keys to the values.

Parameters:
delegate - The delegate
store - The Store
ownerSM - State Manager of the owner of the map.

toArray

public static java.lang.Object[] toArray(CollectionStore backingStore,
                                         StateManager sm)
Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element it such that (o==null ? it==null : o.equals(it)).

This implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.

Parameters:
backingStore - the Store
sm - the StateManager
Returns:
true if this collection contains the specified element.

toArray

public static java.lang.Object[] toArray(CollectionStore backingStore,
                                         StateManager sm,
                                         java.lang.Object[] a)
Returns an array containing all of the elements in this collection;

Parameters:
backingStore - the Store
sm - the StateManager
a - the array into which the elements of the collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the collection.
Throws:
java.lang.NullPointerException - if the specified array is null.
java.lang.ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this collection.


Copyright © -2007 . All Rights Reserved.