public class SCOUtils extends Object
Constructor and Description |
---|
SCOUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
allowNullsInContainer(boolean defaultValue,
AbstractMemberMetaData mmd)
Utility to return whether or not to allow nulls in the container for the specified field.
|
static boolean |
arrayIsStoredInSingleColumn(AbstractMemberMetaData fmd,
MetaDataManager mmgr)
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 |
attachCopyElements(ObjectProvider ownerOP,
Collection scoColl,
Collection detachedElements,
boolean elementsWithoutId)
Convenience method for use by Collection/Set/HashSet attachCopy methods to add any new elements (added
whilst detached) to the collection.
|
static void |
attachCopyForCollection(ObjectProvider ownerOP,
Object[] detachedElements,
Collection attached,
boolean elementsWithoutIdentity)
Method to return an attached copy of the passed (detached) value.
|
static void |
attachCopyForMap(ObjectProvider ownerOP,
Set detachedEntries,
Map attached,
boolean keysWithoutIdentity,
boolean valuesWithoutIdentity)
Method to return an attached copy of the passed (detached) value.
|
static void |
attachForCollection(ObjectProvider ownerOP,
Object[] elements,
boolean elementsWithoutIdentity)
Convenience method to attach (recursively) all elements for a collection field.
|
static void |
attachForMap(ObjectProvider ownerOP,
Set entries,
boolean keysWithoutIdentity,
boolean valuesWithoutIdentity)
Convenience method to attach (recursively) all keys/values for a map field.
|
static boolean |
collectionHasElementsWithoutIdentity(AbstractMemberMetaData mmd)
Convenience method to return if a collection field has elements without their own identity.
|
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.
|
static boolean |
collectionsAreEqual(ApiAdapter api,
Collection oldColl,
Collection newColl)
Convenience method to return if two collections of persistent elements are equal.
|
static boolean |
detachAsWrapped(ObjectProvider ownerOP)
Convenience accessor for whether to detach SCO objects as wrapped.
|
static void |
detachCopyForCollection(ObjectProvider ownerOP,
Object[] elements,
FetchPlanState state,
Collection detached)
Convenience method to detach copies (recursively) of all elements for a collection field.
|
static void |
detachCopyForMap(ObjectProvider ownerOP,
Set entries,
FetchPlanState state,
Map detached)
Convenience method to detach copies (recursively) of all elements for a map field.
|
static void |
detachForCollection(ObjectProvider ownerOP,
Object[] elements,
FetchPlanState state)
Convenience method to detach (recursively) all elements for a collection field.
|
static void |
detachForMap(ObjectProvider ownerOP,
Set entries,
FetchPlanState state)
Convenience method to detach (recursively) all elements for a map field.
|
static Comparator |
getComparator(AbstractMemberMetaData fmd,
ClassLoaderResolver clr)
Convenience method for creating a Comparator using extension metadata tags for the specified field.
|
static String |
getContainerInfoMessage(ObjectProvider ownerOP,
String fieldName,
SCOContainer cont,
boolean useCache,
boolean allowNulls,
boolean lazyLoading)
Utility to generate a message representing the SCO container wrapper and its capabilities.
|
static Class |
getContainerInstanceType(Class declaredType,
Boolean ordered)
Method to return the type to instantiate a container as.
|
static String |
getSCOWrapperOptionsMessage(boolean useCache,
boolean queued,
boolean allowNulls,
boolean lazyLoading)
Convenience method to generate a message containing the options of this SCO wrapper.
|
static boolean |
hasDependentElement(AbstractMemberMetaData mmd)
Method to return if the member is a collection/array with dependent element.
|
static boolean |
hasDependentKey(AbstractMemberMetaData mmd)
Method to return if the member is a map with dependent key.
|
static boolean |
hasDependentValue(AbstractMemberMetaData mmd)
Method to return if the member is a map with dependent value.
|
static boolean |
isListBased(Class type)
Return whether the supplied type (collection) is list based.
|
static boolean |
mapHasKeysWithoutIdentity(AbstractMemberMetaData fmd)
Convenience method to return if a map field has keys without their own identity.
|
static boolean |
mapHasSerialisedKeysAndValues(AbstractMemberMetaData fmd)
Convenience method to return if a map field has the keys/values serialised.
|
static boolean |
mapHasValuesWithoutIdentity(AbstractMemberMetaData fmd)
Convenience method to return if a map field has values without their own identity.
|
static SCO |
newSCOInstance(ObjectProvider ownerOP,
AbstractMemberMetaData mmd,
Class instantiatedType,
Object value,
boolean forInsert,
boolean forUpdate,
boolean replaceField)
Method to create a new SCO wrapper for a SCO type.
|
static void |
populateMapDelegateWithStoreData(Map delegate,
MapStore store,
ObjectProvider ownerOP)
Convenience method to populate the passed delegate Map with the keys/values from the associated Store.
|
static void |
refreshFetchPlanFieldsForCollection(ObjectProvider ownerOP,
Object[] elements)
Convenience method to refresh fetch plan fields for all elements for a collection field.
|
static void |
refreshFetchPlanFieldsForMap(ObjectProvider ownerOP,
Set entries)
Convenience method to refresh fetch plan fields for all elements for a map field.
|
static Object[] |
toArray(CollectionStore backingStore,
ObjectProvider op)
Returns true if this collection contains the specified element.
|
static Object[] |
toArray(CollectionStore backingStore,
ObjectProvider op,
Object[] a)
Returns an array containing all of the elements in this collection;
|
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.
|
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.
|
static boolean |
useCachedLazyLoading(ObjectProvider ownerOP,
AbstractMemberMetaData mmd)
Accessor for whether the use lazy loading when caching the collection.
|
static boolean |
useContainerCache(ObjectProvider ownerOP,
AbstractMemberMetaData mmd)
Utility to return whether or not to use the container cache for the collection/map for the passed
ObjectProvider SCO.
|
static boolean |
useQueuedUpdate(ObjectProvider op)
Convenience method to return if we should use a queued update for the current operation.
|
static boolean |
validateObjectForWriting(ExecutionContext ec,
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 ExecutionContext.
|
static void |
validateObjectsForWriting(ExecutionContext ec,
Object objects)
Method to check if objects to be stored in a SCO container are already persistent, or are managed by a
different ExecutionContext.
|
public static SCO newSCOInstance(ObjectProvider ownerOP, AbstractMemberMetaData mmd, Class instantiatedType, Object value, boolean forInsert, boolean forUpdate, boolean replaceField)
ownerOP
- ObjectProvider for the owning objectmmd
- The Field MetaData for the related field.instantiatedType
- Instantiated type for the field if knownvalue
- The value we are wrapping if knownforInsert
- Whether the SCO needs inserting in the datastore with this valueforUpdate
- Whether the SCO needs updating in the datastore with this valuereplaceField
- Whether to replace the field with this valueNucleusUserException
- if an error occurred when creating the SCO instancepublic static String getContainerInfoMessage(ObjectProvider ownerOP, String fieldName, SCOContainer cont, boolean useCache, boolean allowNulls, boolean lazyLoading)
ownerOP
- ObjectProvider for the ownerfieldName
- Field with the containercont
- The SCOContaineruseCache
- Whether to use caching of values in the containerallowNulls
- Whether to allow nullslazyLoading
- Whether to use lazy loading in the wrapperpublic static String getSCOWrapperOptionsMessage(boolean useCache, boolean queued, boolean allowNulls, boolean lazyLoading)
useCache
- Whether to cache the value in the wrapper (and not go to the datastore)queued
- Whether it supports queueing of updatesallowNulls
- Whether it allows null entrieslazyLoading
- Whether it is lazy loadedpublic static boolean allowNullsInContainer(boolean defaultValue, AbstractMemberMetaData mmd)
defaultValue
- Default value for the containermmd
- MetaData for the field/propertypublic static boolean useContainerCache(ObjectProvider ownerOP, AbstractMemberMetaData mmd)
ownerOP
- The ObjectProvider for the SCO fieldmmd
- Metadata for the member that we are consideringpublic static boolean useCachedLazyLoading(ObjectProvider ownerOP, AbstractMemberMetaData mmd)
ownerOP
- ObjectProvider of the owning objectmmd
- Meta-data of the collection/map fieldpublic static boolean collectionHasElementsWithoutIdentity(AbstractMemberMetaData mmd)
mmd
- MetaData for the fieldpublic static boolean mapHasKeysWithoutIdentity(AbstractMemberMetaData fmd)
fmd
- MetaData for the fieldpublic static boolean mapHasValuesWithoutIdentity(AbstractMemberMetaData fmd)
fmd
- MetaData for the fieldpublic static boolean collectionHasSerialisedElements(AbstractMemberMetaData fmd)
fmd
- MetaData for the fieldpublic static boolean arrayIsStoredInSingleColumn(AbstractMemberMetaData fmd, MetaDataManager mmgr)
fmd
- MetaData for the fieldmmgr
- MetaData managerpublic static boolean mapHasSerialisedKeysAndValues(AbstractMemberMetaData fmd)
fmd
- MetaData for the fieldpublic static boolean attachCopyElements(ObjectProvider ownerOP, Collection scoColl, Collection detachedElements, boolean elementsWithoutId)
ownerOP
- Owner ObjectProviderscoColl
- The current (attached) SCO collectiondetachedElements
- The collection of (detached) elements that we're mergingelementsWithoutId
- Whether the elements have no identitypublic static void attachCopyForCollection(ObjectProvider ownerOP, Object[] detachedElements, Collection attached, boolean elementsWithoutIdentity)
ownerOP
- ObjectProvider for the owning object with the collectiondetachedElements
- The detached elements in the collectionattached
- Collection to add the attached copies toelementsWithoutIdentity
- Whether the elements have their own identitypublic static boolean updateListWithListElements(List list, List elements)
list
- The current (attached) listelements
- The list of (attached) elements needed.public static void attachCopyForMap(ObjectProvider ownerOP, Set detachedEntries, Map attached, boolean keysWithoutIdentity, boolean valuesWithoutIdentity)
ownerOP
- ObjectProvider for the owning object with the mapdetachedEntries
- The detached entries in the mapattached
- Map to add the attached copies tokeysWithoutIdentity
- Whether the keys have their own identityvaluesWithoutIdentity
- Whether the values have their own identitypublic static boolean updateMapWithMapKeysValues(ApiAdapter api, Map map, Map keysValues)
api
- Api adaptermap
- The current (attached) mapkeysValues
- The keys/values requiredpublic static void populateMapDelegateWithStoreData(Map delegate, MapStore store, ObjectProvider ownerOP)
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 persistable), then the values (if persistable), and then the "entries" (ids of keys and values) so we can associate the keys to the values.
delegate
- The delegatestore
- The StoreownerOP
- ObjectProvider of the owner of the map.public static Object[] toArray(CollectionStore backingStore, ObjectProvider op)
This implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.
backingStore
- the Storeop
- the ObjectProviderpublic static Object[] toArray(CollectionStore backingStore, ObjectProvider op, Object[] a)
backingStore
- the Storeop
- the ObjectProvidera
- 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.NullPointerException
- if the specified array is null.ArrayStoreException
- if the runtime type of the specified array is not a supertype of the
runtime type of every element in this collection.public static Comparator getComparator(AbstractMemberMetaData fmd, ClassLoaderResolver clr)
fmd
- The field that needs the comparatorclr
- ClassLoader resolverpublic static void refreshFetchPlanFieldsForCollection(ObjectProvider ownerOP, Object[] elements)
ownerOP
- ObjectProvider for the owning object with the collectionelements
- The elements in the collectionpublic static void refreshFetchPlanFieldsForMap(ObjectProvider ownerOP, Set entries)
ownerOP
- ObjectProvider for the owning object with the mapentries
- The entries in the mappublic static void detachForCollection(ObjectProvider ownerOP, Object[] elements, FetchPlanState state)
ownerOP
- ObjectProvider for the owning object with the collectionelements
- The elements in the collectionstate
- FetchPlan statepublic static void detachCopyForCollection(ObjectProvider ownerOP, Object[] elements, FetchPlanState state, Collection detached)
ownerOP
- ObjectProvider for the owning object with the collectionelements
- The elements in the collectionstate
- FetchPlan statedetached
- Collection to add the detached copies topublic static void attachForCollection(ObjectProvider ownerOP, Object[] elements, boolean elementsWithoutIdentity)
ownerOP
- ObjectProvider for the owning object with the collectionelements
- The elements to processelementsWithoutIdentity
- Whether the elements have their own identitypublic static void detachForMap(ObjectProvider ownerOP, Set entries, FetchPlanState state)
ownerOP
- ObjectProvider for the owning object with the mapentries
- The entries in the mapstate
- FetchPlan statepublic static void detachCopyForMap(ObjectProvider ownerOP, Set entries, FetchPlanState state, Map detached)
ownerOP
- ObjectProvider for the owning object with the mapentries
- The entries in the mapstate
- FetchPlan statedetached
- Map to add the detached copies topublic static void attachForMap(ObjectProvider ownerOP, Set entries, boolean keysWithoutIdentity, boolean valuesWithoutIdentity)
ownerOP
- ObjectProvider for the owning object with the mapentries
- The entries in the map to processkeysWithoutIdentity
- Whether the keys have their own identityvaluesWithoutIdentity
- Whether the values have their own identitypublic static boolean validateObjectForWriting(ExecutionContext ec, Object object, FieldValues fieldValues)
ec
- ExecutionContextobject
- The objectfieldValues
- Values for any fields when persisting (if the object needs persisting)public static void validateObjectsForWriting(ExecutionContext ec, Object objects)
ec
- ExecutionContextobjects
- The objects (array, or Collection)public static boolean isListBased(Class type)
type
- Type to checkpublic static Class getContainerInstanceType(Class declaredType, Boolean ordered)
declaredType
- The declared typeordered
- Hint whether it needs ordering or not (null implies not)public static boolean detachAsWrapped(ObjectProvider ownerOP)
ownerOP
- ObjectProviderpublic static boolean useQueuedUpdate(ObjectProvider op)
op
- ObjectProviderpublic static boolean hasDependentElement(AbstractMemberMetaData mmd)
mmd
- member metadatapublic static boolean hasDependentKey(AbstractMemberMetaData mmd)
mmd
- member metadatapublic static boolean hasDependentValue(AbstractMemberMetaData mmd)
mmd
- member metadatapublic static boolean collectionsAreEqual(ApiAdapter api, Collection oldColl, Collection newColl)
api
- ApiAdapteroldColl
- Old collectionnewColl
- New collectionCopyright © 2015. All rights reserved.