Package org.datanucleus.api

Examples of org.datanucleus.api.ApiAdapter


     * @param elementsWithoutIdentity Whether the elements have their own identity
     */
    public static void attachForCollection(ObjectProvider ownerOP, Object[] elements, boolean elementsWithoutIdentity)
    {
        ExecutionContext ec = ownerOP.getExecutionContext();
        ApiAdapter api = ec.getApiAdapter();
        for (int i = 0; i < elements.length; i++)
        {
            if (api.isPersistable(elements[i]))
            {
                Object attached = ec.getAttachedObjectForId(api.getIdForObject(elements[i]));
                if (attached == null)
                {
                    // Not yet attached so attach
                    ec.attachObject(ownerOP, elements[i], elementsWithoutIdentity);
                }
View Full Code Here


     * @param elementsWithoutIdentity Whether the elements have their own identity
     */
    public static void attachCopyForCollection(ObjectProvider ownerOP, Object[] detachedElements,
            Collection attached, boolean elementsWithoutIdentity)
    {
        ApiAdapter api = ownerOP.getExecutionContext().getApiAdapter();
        for (int i = 0; i < detachedElements.length; i++)
        {
            if (api.isPersistable(detachedElements[i]) && api.isDetachable(detachedElements[i]))
            {
                attached.add(ownerOP.getExecutionContext().attachObjectCopy(ownerOP, detachedElements[i], elementsWithoutIdentity));
            }
            else
            {
View Full Code Here

     * @param entries The entries in the map
     * @param state FetchPlan state
     */
    public static void detachForMap(ObjectProvider ownerOP, Set entries, FetchPlanState state)
    {
        ApiAdapter api = ownerOP.getExecutionContext().getApiAdapter();
        for (Iterator it = entries.iterator(); it.hasNext();)
        {
            Map.Entry entry = (Map.Entry) it.next();
            Object val = entry.getValue();
            Object key = entry.getKey();
            if (api.isPersistable(key))
            {
               ownerOP.getExecutionContext().detachObject(key, state);
            }
            if (api.isPersistable(val))
            {
               ownerOP.getExecutionContext().detachObject(val, state);
            }
        }
    }
View Full Code Here

     * @param state FetchPlan state
     * @param detached Map to add the detached copies to
     */
    public static void detachCopyForMap(ObjectProvider ownerOP, Set entries, FetchPlanState state, Map detached)
    {
        ApiAdapter api = ownerOP.getExecutionContext().getApiAdapter();
        for (Iterator it = entries.iterator(); it.hasNext();)
        {
            Map.Entry entry = (Map.Entry) it.next();
            Object val = entry.getValue();
            Object key = entry.getKey();
            if (api.isPersistable(val))
            {
                val = ownerOP.getExecutionContext().detachObjectCopy(val, state);
            }
            if (api.isPersistable(key))
            {
                key = ownerOP.getExecutionContext().detachObjectCopy(key, state);
            }
            detached.put(key, val);
        }
View Full Code Here

     * @param valuesWithoutIdentity Whether the values have their own identity
     */
    public static void attachForMap(ObjectProvider ownerOP, Set entries, boolean keysWithoutIdentity, boolean valuesWithoutIdentity)
    {
        ExecutionContext ec = ownerOP.getExecutionContext();
        ApiAdapter api = ec.getApiAdapter();
        for (Iterator it = entries.iterator(); it.hasNext();)
        {
            Map.Entry entry = (Map.Entry) it.next();
            Object val = entry.getValue();
            Object key = entry.getKey();
            if (api.isPersistable(key))
            {
                Object attached = ec.getAttachedObjectForId(api.getIdForObject(key));
                if (attached == null)
                {
                    // Not yet attached so attach
                    ownerOP.getExecutionContext().attachObject(ownerOP, key, keysWithoutIdentity);
                }
            }
            if (api.isPersistable(val))
            {
                Object attached = ec.getAttachedObjectForId(api.getIdForObject(val));
                if (attached == null)
                {
                    // Not yet attached so attach
                    ownerOP.getExecutionContext().attachObject(ownerOP, val, valuesWithoutIdentity);
                }
View Full Code Here

     */
    public static void attachCopyForMap(ObjectProvider ownerOP, Set detachedEntries,
            Map attached, boolean keysWithoutIdentity, boolean valuesWithoutIdentity)
    {
        Iterator iter = detachedEntries.iterator();
        ApiAdapter api = ownerOP.getExecutionContext().getApiAdapter();
        while (iter.hasNext())
        {
            Map.Entry entry = (Map.Entry) iter.next();
            Object val = entry.getValue();
            Object key = entry.getKey();
            if (api.isPersistable(val) && api.isDetachable(val))
            {
                val = ownerOP.getExecutionContext().attachObjectCopy(ownerOP, val, valuesWithoutIdentity);
            }
            if (api.isPersistable(key) && api.isDetachable(key))
            {
                key = ownerOP.getExecutionContext().attachObjectCopy(ownerOP, key, keysWithoutIdentity);
            }
            attached.put(key, val);
        }
View Full Code Here

     */
    public static boolean validateObjectForWriting(ObjectProvider ownerOP, Object object, FieldValues fieldValues)
    {
        boolean persisted = false;
        ExecutionContext ec = ownerOP.getExecutionContext();
        ApiAdapter api = ec.getApiAdapter();
        if (api.isPersistable(object))
        {
            ExecutionContext objectEC = api.getExecutionContext(object);
            if (objectEC != null && ec != objectEC)
            {
                throw new NucleusUserException(LOCALISER.msg("023009", StringUtils.toJVMIDString(object)),
                    api.getIdForObject(object));
            }
            else if (!api.isPersistent(object))
            {
                // Not persistent, so either is detached, or needs persisting for first time
                boolean exists = false;
                if (api.isDetached(object))
                {
                    if (ec.getNucleusContext().getPersistenceConfiguration().getBooleanProperty("datanucleus.attachSameDatastore"))
                    {
                        // Assume that it is detached from this datastore
                        exists = true;
                    }
                    else
                    {
                        // Check if the (attached) object exists in this datastore
                        try
                        {
                            Object obj = ec.findObject(api.getIdForObject(object), true, false, object.getClass().getName());
                            if (obj != null)
                            {
                                // PM.getObjectById creates a dummy object to represent this object and automatically
                                // enlists it in the txn. Evict it to avoid issues with reachability
                                ObjectProvider objSM = ec.findObjectProvider(obj);
View Full Code Here

     * @return The detached container
     */
    public Object detachCopy(FetchPlanState state)
    {
        com.google.common.collect.Multimap<K, V> detached = HashMultimap.create();
        ApiAdapter api = ownerSM.getExecutionContext().getApiAdapter();
        Collection<Map.Entry<K, V>> entries = entries();
        for (Iterator<Map.Entry<K, V>> it = entries.iterator(); it.hasNext();)
        {
            Map.Entry<K, V> entry = it.next();
            K key = entry.getKey();
            V val = entry.getValue();
            if (api.isPersistable(key))
            {
                key = (K) ownerSM.getExecutionContext().detachObjectCopy(key, state);
            }
            if (api.isPersistable(val))
            {
                val = (V) ownerSM.getExecutionContext().detachObjectCopy(val, state);
            }
            detached.put(key, val);
        }
View Full Code Here

        boolean valuesWithoutIdentity = SCOUtils.mapHasValuesWithoutIdentity(fmd);

        com.google.common.collect.Multimap<K, V> attachedKeysValues = HashMultimap.create();
        Collection<Map.Entry<K, V>> detachedEntries = m.entries();
        Iterator<Map.Entry<K, V>> iter = detachedEntries.iterator();
        ApiAdapter api = ownerSM.getExecutionContext().getApiAdapter();
        while (iter.hasNext())
        {
            Map.Entry<K, V> entry = iter.next();
            K key = entry.getKey();
            V val = entry.getValue();
            if (api.isPersistable(key) && api.isDetachable(key))
            {
                key = (K) ownerSM.getExecutionContext().attachObjectCopy(ownerSM, key, keysWithoutIdentity);
            }
            if (api.isPersistable(val) && api.isDetachable(val))
            {
                val = (V) ownerSM.getExecutionContext().attachObjectCopy(ownerSM, val, valuesWithoutIdentity);
            }
            attachedKeysValues.put(key, val);
        }

        // Update the attached map with the detached entries
        com.google.common.collect.Multimap<K, V> copy = HashMultimap.create();
        copy.putAll(this);

        // Delete any keys that are no longer in the Map
        Iterator<Map.Entry<K, V>> attachedIter = copy.entries().iterator();
        while (attachedIter.hasNext())
        {
            Map.Entry<K, V> entry = attachedIter.next();
            K key = entry.getKey();
            if (!attachedKeysValues.containsKey(key))
            {
                this.removeAll(key);
            }
        }

        // Add any new keys/values and update any changed values
        Iterator<Map.Entry<K, V>> keysIter = attachedKeysValues.entries().iterator();
        while (keysIter.hasNext())
        {
            Map.Entry<K, V> entry = keysIter.next();
            K theKey = entry.getKey();
            V theValue = entry.getValue();
            if (!this.containsKey(theKey))
            {
                // Not present so add it
                this.put(theKey, theValue);
            }
            else
            {
                // Update any values
                Object oldValue = this.get(theKey);
                if (api.isPersistable(theValue) && api.getIdForObject(theValue) != api.getIdForObject(oldValue))
                {
                    // In case they have changed the PC for this key (different id)
                    this.put(theKey, theValue);
                }
                else
View Full Code Here

            {
                NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("007006", mmd.getFullFieldName()));
            }

            // Check for any persistable keys/values that arent persistent
            ApiAdapter api = ec.getApiAdapter();
            Set entries = value.entrySet();
            Iterator iter = entries.iterator();
            while (iter.hasNext())
            {
                Map.Entry entry = (Map.Entry)iter.next();
                if (api.isPersistable(entry.getKey()))
                {
                    if (!api.isPersistent(entry.getKey()) && !api.isDetached(entry.getKey()))
                    {
                        // Key is not persistent so throw exception
                        throw new ReachableObjectNotCascadedException(mmd.getFullFieldName(), entry.getKey());
                    }
                }
                if (api.isPersistable(entry.getValue()))
                {
                    if (!api.isPersistent(entry.getValue()) && !api.isDetached(entry.getValue()))
                    {
                        // Value is not persistent so throw exception
                        throw new ReachableObjectNotCascadedException(mmd.getFullFieldName(), entry.getValue());
                    }
                }
View Full Code Here

TOP

Related Classes of org.datanucleus.api.ApiAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.