| java.lang.Object org.jpox.sco.SCOUtils
SCOUtils | public class SCOUtils (Code) | | Collection of utilities for second class wrappers and objects.
version: $Revision: 1.80 $ |
Method Summary | |
public static boolean | allowNullsInContainer(boolean defaultValue, AbstractMemberMetaData fmd) Utility to return whether or not to allow nulls in the container for the specified field. | public static boolean | arrayIsStoredInSingleColumn(AbstractMemberMetaData fmd) Convenience method to return if an array field has the elements stored into the
table of the field as a single (BLOB) column. | public static void | attachCopyForCollection(StateManager ownerSM, Object[] detachedElements, Collection attached, boolean elementsWithoutIdentity) Method to return an attached copy of the passed (detached) value. | public static void | attachCopyForMap(StateManager ownerSM, Set detachedEntries, Map attached, boolean keysWithoutIdentity, boolean valuesWithoutIdentity) Method to return an attached copy of the passed (detached) value. | public static void | attachForCollection(StateManager ownerSM, Object[] elements, boolean elementsWithoutIdentity) Convenience method to attach (recursively) all elements for a collection field. | public static void | attachForMap(StateManager ownerSM, Set entries, boolean keysWithoutIdentity, boolean valuesWithoutIdentity) Convenience method to attach (recursively) all elements for a map field. | public static boolean | collectionHasElementsWithoutIdentity(AbstractMemberMetaData fmd) Convenience method to return if a collection field has elements without their own identity. | public static boolean | collectionHasSerialisedElements(AbstractMemberMetaData fmd) Convenience method to return if a collection field has the elements serialised into the
table of the field as a single BLOB. | public static void | detachCopyForCollection(StateManager ownerSM, Object[] elements, FetchPlanState state, Collection detached) Convenience method to detach copies (recursively) of all elements for a collection field. | public static void | detachCopyForMap(StateManager ownerSM, Set entries, FetchPlanState state, Map detached) Convenience method to detach copies (recursively) of all elements for a map field. | public static void | detachForCollection(StateManager ownerSM, Object[] elements, FetchPlanState state) Convenience method to detach (recursively) all elements for a collection field. | public static void | detachForMap(StateManager ownerSM, Set entries, FetchPlanState state) Convenience method to detach (recursively) all elements for a map field. | public static Comparator | getComparator(AbstractMemberMetaData fmd, ClassLoaderResolver clr) Convenience method for creating a Comparator using extension metadata tags for the specified field. | public static String | getContainerInfoMessage(StateManager ownerSM, String fieldName, SCOContainer cont, boolean useCache, boolean queued, boolean allowNulls, boolean lazyLoading) Utility to generate a message representing the SCO container wrapper and its capabilities. | public static String | getSCOWrapperOptionsMessage(boolean useCache, boolean queued, boolean allowNulls, boolean lazyLoading) Convenience method to generate a message containing the options of this SCO wrapper. | public static boolean | mapHasKeysWithoutIdentity(AbstractMemberMetaData fmd) Convenience method to return if a map field has keys without their own identity. | public static boolean | mapHasSerialisedKeysAndValues(AbstractMemberMetaData fmd) Convenience method to return if a map field has the keys/values serialised into the
table of the field as a single BLOB. | public static boolean | mapHasValuesWithoutIdentity(AbstractMemberMetaData fmd) Convenience method to return if a map field has values without their own identity. | public static SCO | newSCOInstance(StateManager ownerSM, AbstractMemberMetaData fmd, Class declaredType, Class instantiatedType, Object value, boolean forInsert, boolean forUpdate, boolean replaceField) Method to create a new SCO wrapper for a SCO type. | public static void | populateMapDelegateWithStoreData(Map delegate, MapStore store, StateManager ownerSM) Convenience method to populate the passed delegate Map with the keys/values from
the associated Store. | public static void | refreshFetchPlanFieldsForCollection(StateManager ownerSM, Object[] elements) Convenience method to refresh fetch plan fields for all elements for a collection field. | public static void | refreshFetchPlanFieldsForMap(StateManager ownerSM, Set entries) Convenience method to refresh fetch plan fields for all elements for a map field. | public static Object[] | toArray(CollectionStore backingStore, StateManager sm) Returns true if this collection contains the specified
element. | public static Object[] | toArray(CollectionStore backingStore, StateManager sm, Object a) Returns an array containing all of the elements in this collection;
Parameters: backingStore - the Store Parameters: sm - the StateManager Parameters: a - the array into which the elements of the collection are tobe stored, if it is big enough; otherwise, a new array of thesame runtime type is allocated for this purpose. | public static void | updateCollectionWithCollection(ApiAdapter api, Collection coll, 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. | public static boolean | updateCollectionWithCollectionElements(Collection coll, Collection elements) Convenience method for use by Collection/Set/HashSet attachCopy methods to
update the passed (attached) collection using the (attached) elements passed.
Parameters: coll - The current (attached) collection Parameters: elements - The collection of (attached) elements needed. | public static boolean | updateListWithListElements(List list, List elements) Convenience method for use by List attachCopy methods to update the
passed (attached) list using the (attached) list elements passed.
Parameters: list - The current (attached) list Parameters: elements - The list of (attached) elements needed. | public static boolean | updateMapWithMapKeysValues(ApiAdapter api, Map map, Map keysValues) Convenience method for use by Map attachCopy methods to update the
passed (attached) map using the (attached) map keys/values passed. | public static void | updateStoreWithCollection(CollectionStore store, StateManager ownerSM, 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. | public static boolean | useCachedLazyLoading(StateManager ownerSM, String fieldName) Accessor for whether the use lazy loading when caching the collection. | public static boolean | useContainerCache(StateManager ownerSM, String fieldName) 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 Parameters: fieldName - Name of the field. | public static boolean | useContainerQueueing(StateManager ownerSM) Utility to return whether to use queueing of operations in the SCO container. | public static boolean | validateObjectForWriting(ObjectManager om, Object object, FieldValues fieldValues) Method to check if an object to be stored in a SCO container is already persistent, or is managed
by a different ObjectManager. | public static void | validateObjectsForWriting(ObjectManager om, Object objects) Method to check if objects to be stored in a SCO container are already persistent, or are managed by
a different ObjectManager. |
allowNullsInContainer | public static boolean allowNullsInContainer(boolean defaultValue, AbstractMemberMetaData fmd)(Code) | | Utility to return whether or not to allow nulls in the container for the specified field.
Uses the metadata extension "allow-nulls".
Parameters: defaultValue - Default value for the container Parameters: fmd - MetaData for the field/property Whether to allow nulls |
arrayIsStoredInSingleColumn | public static boolean arrayIsStoredInSingleColumn(AbstractMemberMetaData fmd)(Code) | | 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 Whether the elements are stored in a single column |
attachCopyForCollection | public static void attachCopyForCollection(StateManager ownerSM, Object[] detachedElements, Collection attached, boolean elementsWithoutIdentity)(Code) | | Method to return an attached copy of the passed (detached) value. The returned attached copy
is a SCO wrapper. Goes through the existing elements in the store for this owner field and
removes ones no longer present, and adds new elements. All elements in the (detached)
value are attached.
Parameters: ownerSM - StateManager for the owning object with the collection Parameters: detachedElements - The detached elements in the collection Parameters: attached - Collection to add the attached copies to Parameters: elementsWithoutIdentity - Whether the elements have their own identity |
attachCopyForMap | public static void attachCopyForMap(StateManager ownerSM, Set detachedEntries, Map attached, boolean keysWithoutIdentity, boolean valuesWithoutIdentity)(Code) | | Method to return an attached copy of the passed (detached) value. The returned attached copy
is a SCO wrapper. Goes through the existing elements in the store for this owner field and
removes ones no longer present, and adds new elements. All elements in the (detached)
value are attached.
Parameters: ownerSM - StateManager for the owning object with the map Parameters: detachedEntries - The detached entries in the map Parameters: attached - Map to add the attached copies to Parameters: keysWithoutIdentity - Whether the keys have their own identity Parameters: valuesWithoutIdentity - Whether the values have their own identity |
attachForCollection | public static void attachForCollection(StateManager ownerSM, Object[] elements, boolean elementsWithoutIdentity)(Code) | | Convenience method to attach (recursively) all elements for a collection field.
All elements that are PersistenceCapable will be attached.
Parameters: ownerSM - StateManager for the owning object with the collection Parameters: elements - The elements in the collection Parameters: elementsWithoutIdentity - Whether the elements have their own identity |
attachForMap | public static void attachForMap(StateManager ownerSM, Set entries, boolean keysWithoutIdentity, boolean valuesWithoutIdentity)(Code) | | Convenience method to attach (recursively) all elements for a map field.
All elements that are PersistenceCapable will be attached.
Parameters: ownerSM - StateManager for the owning object with the map Parameters: entries - The entries in the map Parameters: keysWithoutIdentity - Whether the keys have their own identity Parameters: valuesWithoutIdentity - Whether the values have their own identity |
collectionHasElementsWithoutIdentity | public static boolean collectionHasElementsWithoutIdentity(AbstractMemberMetaData fmd)(Code) | | 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 Whether the elements have their own identity or not |
collectionHasSerialisedElements | public static boolean collectionHasSerialisedElements(AbstractMemberMetaData fmd)(Code) | | 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 Whether the elements are serialised (either explicitly or implicitly) |
detachCopyForCollection | public static void detachCopyForCollection(StateManager ownerSM, Object[] elements, FetchPlanState state, Collection detached)(Code) | | Convenience method to detach copies (recursively) of all elements for a collection field.
All elements that are PersistenceCapable will be detached.
Parameters: ownerSM - StateManager for the owning object with the collection Parameters: elements - The elements in the collection Parameters: state - FetchPlan state Parameters: detached - Collection to add the detached copies to |
detachCopyForMap | public static void detachCopyForMap(StateManager ownerSM, Set entries, FetchPlanState state, Map detached)(Code) | | Convenience method to detach copies (recursively) of all elements for a map field.
All elements that are PersistenceCapable will be detached.
Parameters: ownerSM - StateManager for the owning object with the map Parameters: entries - The entries in the map Parameters: state - FetchPlan state Parameters: detached - Map to add the detached copies to |
detachForCollection | public static void detachForCollection(StateManager ownerSM, Object[] elements, FetchPlanState state)(Code) | | Convenience method to detach (recursively) all elements for a collection field.
All elements that are PersistenceCapable will be detached.
Parameters: ownerSM - StateManager for the owning object with the collection Parameters: elements - The elements in the collection Parameters: state - FetchPlan state |
detachForMap | public static void detachForMap(StateManager ownerSM, Set entries, FetchPlanState state)(Code) | | Convenience method to detach (recursively) all elements for a map field.
All elements that are PersistenceCapable will be detached.
Parameters: ownerSM - StateManager for the owning object with the map Parameters: entries - The entries in the map Parameters: state - FetchPlan state |
getComparator | public static Comparator getComparator(AbstractMemberMetaData fmd, ClassLoaderResolver clr)(Code) | | Convenience method for creating a Comparator using extension metadata tags for the specified field.
Uses the extension key "comparator-name" (and allows for "comparatorName" - deprecated).
Parameters: fmd - The field that needs the comparator Parameters: clr - ClassLoader resolver The Comparator |
getContainerInfoMessage | public static String getContainerInfoMessage(StateManager ownerSM, String fieldName, SCOContainer cont, boolean useCache, boolean queued, boolean allowNulls, boolean lazyLoading)(Code) | | Utility to generate a message representing the SCO container wrapper and its capabilities.
Parameters: ownerSM - StateManager for the owner Parameters: fieldName - Field with the container Parameters: cont - The SCOContainer Parameters: useCache - Whether to use caching of values in the container Parameters: queued - Whether operations are queued in the wrapper Parameters: allowNulls - Whether to allow nulls Parameters: lazyLoading - Whether to use lazy loading in the wrapper The String |
getSCOWrapperOptionsMessage | public static String getSCOWrapperOptionsMessage(boolean useCache, boolean queued, boolean allowNulls, boolean lazyLoading)(Code) | | Convenience method to generate a message containing the options of this SCO wrapper.
Parameters: useCache - Whether to cache the value in the wrapper (and not go to the datastore) Parameters: queued - Whether it supports queueing of updates Parameters: allowNulls - Whether it allows null entries Parameters: lazyLoading - Whether it is lazy loaded the message |
mapHasKeysWithoutIdentity | public static boolean mapHasKeysWithoutIdentity(AbstractMemberMetaData fmd)(Code) | | 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 Whether the keys have their own identity or not |
mapHasSerialisedKeysAndValues | public static boolean mapHasSerialisedKeysAndValues(AbstractMemberMetaData fmd)(Code) | | 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 Whether the keys and values are serialised (either explicitly or implicitly) |
mapHasValuesWithoutIdentity | public static boolean mapHasValuesWithoutIdentity(AbstractMemberMetaData fmd)(Code) | | 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 Whether the values have their own identity or not |
newSCOInstance | public static SCO newSCOInstance(StateManager ownerSM, AbstractMemberMetaData fmd, Class declaredType, Class instantiatedType, Object value, boolean forInsert, boolean forUpdate, boolean replaceField)(Code) | | 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.
While the "instantiated type" and the type of "value" should be the same when value is non-null, there are
situations where we need to create a List based collection yet have no value so pass in the declaredType
as Collection, instantiatedType as ArrayList, and value as null.
Parameters: ownerSM - State Manager for the owning object Parameters: fmd - The Field MetaData for the related field. Parameters: declaredType - The class of the object Parameters: instantiatedType - Instantiated type for the field if known Parameters: value - The value we are wrapping if known Parameters: forInsert - Whether the SCO needs inserting in the datastore with this value Parameters: forUpdate - Whether the SCO needs updating in the datastore with this value Parameters: replaceField - Whether to replace the field with this value The Second-Class Object throws: JPOXUserException - if an error occurred when creating the SCO instance |
populateMapDelegateWithStoreData | public static void populateMapDelegateWithStoreData(Map delegate, MapStore store, StateManager ownerSM)(Code) | | 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 Parameters: store - The Store Parameters: ownerSM - State Manager of the owner of the map. |
refreshFetchPlanFieldsForCollection | public static void refreshFetchPlanFieldsForCollection(StateManager ownerSM, Object[] elements)(Code) | | Convenience method to refresh fetch plan fields for all elements for a collection field.
All elements that are PersistenceCapable will be made transient.
Parameters: ownerSM - StateManager for the owning object with the collection Parameters: elements - The elements in the collection |
refreshFetchPlanFieldsForMap | public static void refreshFetchPlanFieldsForMap(StateManager ownerSM, Set entries)(Code) | | Convenience method to refresh fetch plan fields for all elements for a map field.
All elements that are PersistenceCapable will be made transient.
Parameters: ownerSM - StateManager for the owning object with the map Parameters: entries - The entries in the map |
toArray | public static Object[] toArray(CollectionStore backingStore, StateManager sm)(Code) | | 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 Parameters: sm - the StateManager true if this collection contains the specified element. |
toArray | public static Object[] toArray(CollectionStore backingStore, StateManager sm, Object a)(Code) | | Returns an array containing all of the elements in this collection;
Parameters: backingStore - the Store Parameters: sm - the StateManager Parameters: a - the array into which the elements of the collection are tobe stored, if it is big enough; otherwise, a new array of thesame runtime type is allocated for this purpose. an array containing the elements of the collection. throws: NullPointerException - if the specified array is null. throws: ArrayStoreException - if the runtime type of the specified arrayis not a supertype of the runtime type of every element in thiscollection. |
updateCollectionWithCollection | public static void updateCollectionWithCollection(ApiAdapter api, Collection coll, Collection newColl)(Code) | | 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: api - API Adapter Parameters: coll - The collection to update Parameters: newColl - The new collection whose elements we need in "coll" |
updateCollectionWithCollectionElements | public static boolean updateCollectionWithCollectionElements(Collection coll, Collection elements)(Code) | | Convenience method for use by Collection/Set/HashSet attachCopy methods to
update the passed (attached) collection using the (attached) elements passed.
Parameters: coll - The current (attached) collection Parameters: elements - The collection of (attached) elements needed. If the Collection was updated |
updateListWithListElements | public static boolean updateListWithListElements(List list, List elements)(Code) | | Convenience method for use by List attachCopy methods to update the
passed (attached) list using the (attached) list elements passed.
Parameters: list - The current (attached) list Parameters: elements - The list of (attached) elements needed. If the List was updated |
updateMapWithMapKeysValues | public static boolean updateMapWithMapKeysValues(ApiAdapter api, Map map, Map keysValues)(Code) | | Convenience method for use by Map attachCopy methods to update the
passed (attached) map using the (attached) map keys/values passed.
Parameters: api - TODO Parameters: map - The current (attached) map Parameters: keysValues - The keys/values required If the map was updated |
updateStoreWithCollection | public static void updateStoreWithCollection(CollectionStore store, StateManager ownerSM, Collection newColl)(Code) | | 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 Parameters: ownerSM - StateManager of the owner Parameters: newColl - The new collection whose elements we need in "coll" |
useCachedLazyLoading | public static boolean useCachedLazyLoading(StateManager ownerSM, String fieldName)(Code) | | Accessor for whether the use lazy loading when caching the collection.
Parameters: ownerSM - StateManager of the owning object Parameters: fieldName - Name of the collection/map field Whether to use lazy loading when caching the collection |
useContainerCache | public static boolean useContainerCache(StateManager ownerSM, String fieldName)(Code) | | 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 Parameters: fieldName - Name of the field. Whether to use the cache. |
useContainerQueueing | public static boolean useContainerQueueing(StateManager ownerSM)(Code) | | Utility to return whether to use queueing of operations in the SCO container.
Parameters: ownerSM - The StateManager for the SCO field Whether to use queueing |
validateObjectForWriting | public static boolean validateObjectForWriting(ObjectManager om, Object object, FieldValues fieldValues)(Code) | | Method to check if an object to be stored in a SCO container is already persistent, or is managed
by a different ObjectManager. If not persistent, this call will persist it. If not yet flushed to the
datastore this call will flush it.
Parameters: om - ObjectManager that we are using Parameters: object - The object Parameters: fieldValues - Values for any fields when persisting (if the object needs persisting) Whether the object was persisted during this call |
validateObjectsForWriting | public static void validateObjectsForWriting(ObjectManager om, Object objects)(Code) | | Method to check if objects to be stored in a SCO container are already persistent, or are managed by
a different ObjectManager. If not persistent, this call will persist them.
Parameters: om - ObjectManager being used Parameters: objects - The objects (array, or Collection) |
|
|