Search in sources :

Example 6 with SCOCollection

use of org.datanucleus.store.types.SCOCollection in project datanucleus-core by datanucleus.

the class HashSet method initialise.

public void initialise(java.util.HashSet<E> newValue, Object oldValue) {
    if (newValue != null) {
        // Check for the case of serialised PC elements, and assign ObjectProviders to the elements without
        if (SCOUtils.collectionHasSerialisedElements(ownerMmd) && ownerMmd.getCollection().elementIsPersistent()) {
            ExecutionContext ec = ownerOP.getExecutionContext();
            Iterator iter = newValue.iterator();
            while (iter.hasNext()) {
                Object pc = iter.next();
                ObjectProvider objSM = ec.findObjectProvider(pc);
                if (objSM == null) {
                    objSM = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, pc, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                }
            }
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("023008", ownerOP.getObjectAsPrintable(), ownerMmd.getName(), "" + newValue.size()));
        }
        // Detect which objects are added and which are deleted
        initialising = true;
        if (useCache) {
            Collection oldColl = (Collection) oldValue;
            if (oldColl != null) {
                delegate.addAll(oldColl);
            }
            isCacheLoaded = true;
            SCOUtils.updateCollectionWithCollection(ownerOP.getExecutionContext().getApiAdapter(), this, newValue);
        } else {
            java.util.Collection oldColl = (java.util.Collection) oldValue;
            if (oldColl instanceof SCOCollection) {
                oldColl = (java.util.Collection) ((SCOCollection) oldColl).getValue();
            }
            for (E elem : newValue) {
                if (oldColl == null || !oldColl.contains(elem)) {
                    add(elem);
                }
            }
            if (oldColl != null) {
                for (Object elem : oldColl) {
                    if (!newValue.contains(elem)) {
                        remove(elem);
                    }
                }
            }
        }
        initialising = false;
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) Collection(java.util.Collection) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator) Collection(java.util.Collection) SCOCollection(org.datanucleus.store.types.SCOCollection) SCOCollection(org.datanucleus.store.types.SCOCollection) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 7 with SCOCollection

use of org.datanucleus.store.types.SCOCollection in project datanucleus-core by datanucleus.

the class LinkedHashSet method initialise.

public void initialise(java.util.LinkedHashSet<E> newValue, Object oldValue) {
    if (newValue != null) {
        // Check for the case of serialised PC elements, and assign ObjectProviders to the elements without
        if (SCOUtils.collectionHasSerialisedElements(ownerMmd) && ownerMmd.getCollection().elementIsPersistent()) {
            ExecutionContext ec = ownerOP.getExecutionContext();
            Iterator iter = newValue.iterator();
            while (iter.hasNext()) {
                Object pc = iter.next();
                ObjectProvider objSM = ec.findObjectProvider(pc);
                if (objSM == null) {
                    objSM = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, pc, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                }
            }
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("023008", ownerOP.getObjectAsPrintable(), ownerMmd.getName(), "" + newValue.size()));
        }
        // Detect which objects are added and which are deleted
        initialising = true;
        if (useCache) {
            Collection oldColl = (Collection) oldValue;
            if (oldColl != null) {
                delegate.addAll(oldColl);
            }
            isCacheLoaded = true;
            SCOUtils.updateCollectionWithCollection(ownerOP.getExecutionContext().getApiAdapter(), this, newValue);
        } else {
            java.util.Collection oldColl = (java.util.Collection) oldValue;
            if (oldColl instanceof SCOCollection) {
                oldColl = (java.util.Collection) ((SCOCollection) oldColl).getValue();
            }
            for (E elem : newValue) {
                if (oldColl == null || !oldColl.contains(elem)) {
                    add(elem);
                }
            }
            if (oldColl != null) {
                Iterator iter = oldColl.iterator();
                while (iter.hasNext()) {
                    Object elem = iter.next();
                    if (!newValue.contains(elem)) {
                        remove(elem);
                    }
                }
            }
        }
        initialising = false;
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) Collection(java.util.Collection) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator) Collection(java.util.Collection) SCOCollection(org.datanucleus.store.types.SCOCollection) SCOCollection(org.datanucleus.store.types.SCOCollection) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 8 with SCOCollection

use of org.datanucleus.store.types.SCOCollection in project datanucleus-core by datanucleus.

the class Set method initialise.

public void initialise(java.util.Set<E> newValue, Object oldValue) {
    if (newValue != null) {
        // Check for the case of serialised PC elements, and assign ObjectProviders to the elements without
        if (SCOUtils.collectionHasSerialisedElements(ownerMmd) && ownerMmd.getCollection().elementIsPersistent()) {
            ExecutionContext ec = ownerOP.getExecutionContext();
            Iterator iter = newValue.iterator();
            while (iter.hasNext()) {
                Object pc = iter.next();
                ObjectProvider objSM = ec.findObjectProvider(pc);
                if (objSM == null) {
                    objSM = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, pc, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                }
            }
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("023008", ownerOP.getObjectAsPrintable(), ownerMmd.getName(), "" + newValue.size()));
        }
        // Detect which objects are added and which are deleted
        initialising = true;
        if (useCache) {
            Collection oldColl = (Collection) oldValue;
            if (oldColl != null) {
                delegate.addAll(oldColl);
            }
            isCacheLoaded = true;
            SCOUtils.updateCollectionWithCollection(ownerOP.getExecutionContext().getApiAdapter(), this, newValue);
        } else {
            java.util.Collection oldColl = (java.util.Collection) oldValue;
            if (oldColl instanceof SCOCollection) {
                oldColl = (java.util.Collection) ((SCOCollection) oldColl).getValue();
            }
            for (E elem : newValue) {
                if (oldColl == null || !oldColl.contains(elem)) {
                    add(elem);
                }
            }
            if (oldColl != null) {
                Iterator iter = oldColl.iterator();
                while (iter.hasNext()) {
                    Object elem = iter.next();
                    if (!newValue.contains(elem)) {
                        remove(elem);
                    }
                }
            }
        }
        initialising = false;
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) Collection(java.util.Collection) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator) Collection(java.util.Collection) SCOCollection(org.datanucleus.store.types.SCOCollection) SCOCollection(org.datanucleus.store.types.SCOCollection) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 9 with SCOCollection

use of org.datanucleus.store.types.SCOCollection in project datanucleus-core by datanucleus.

the class TreeSet method initialise.

public void initialise(java.util.TreeSet<E> newValue, Object oldValue) {
    if (newValue != null) {
        // Check for the case of serialised PC elements, and assign ObjectProviders to the elements without
        if (SCOUtils.collectionHasSerialisedElements(ownerMmd) && ownerMmd.getCollection().elementIsPersistent()) {
            ExecutionContext ec = ownerOP.getExecutionContext();
            Iterator iter = newValue.iterator();
            while (iter.hasNext()) {
                Object pc = iter.next();
                ObjectProvider objSM = ec.findObjectProvider(pc);
                if (objSM == null) {
                    objSM = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, pc, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                }
            }
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("023008", ownerOP.getObjectAsPrintable(), ownerMmd.getName(), "" + newValue.size()));
        }
        // Detect which objects are added and which are deleted
        initialising = true;
        if (useCache) {
            Collection oldColl = (Collection) oldValue;
            if (oldColl != null) {
                delegate.addAll(oldColl);
            }
            isCacheLoaded = true;
            SCOUtils.updateCollectionWithCollection(ownerOP.getExecutionContext().getApiAdapter(), this, newValue);
        } else {
            java.util.Collection oldColl = (java.util.Collection) oldValue;
            if (oldColl instanceof SCOCollection) {
                oldColl = (java.util.Collection) ((SCOCollection) oldColl).getValue();
            }
            for (E elem : newValue) {
                if (oldColl == null || !oldColl.contains(elem)) {
                    add(elem);
                }
            }
            if (oldColl != null) {
                Iterator iter = oldColl.iterator();
                while (iter.hasNext()) {
                    Object elem = iter.next();
                    if (!newValue.contains(elem)) {
                        remove(elem);
                    }
                }
            }
        }
        initialising = false;
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) Collection(java.util.Collection) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator) Collection(java.util.Collection) SCOCollection(org.datanucleus.store.types.SCOCollection) SCOCollection(org.datanucleus.store.types.SCOCollection) ObjectProvider(org.datanucleus.state.ObjectProvider)

Aggregations

SCOCollection (org.datanucleus.store.types.SCOCollection)9 Collection (java.util.Collection)7 ObjectProvider (org.datanucleus.state.ObjectProvider)7 Iterator (java.util.Iterator)6 ExecutionContext (org.datanucleus.ExecutionContext)6 SCOCollectionIterator (org.datanucleus.store.types.SCOCollectionIterator)6 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)3 Set (java.util.Set)1 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)1 EmbeddedOwnerRelation (org.datanucleus.ExecutionContext.EmbeddedOwnerRelation)1 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 CollectionAddOperation (org.datanucleus.flush.CollectionAddOperation)1 CollectionClearOperation (org.datanucleus.flush.CollectionClearOperation)1 RelationType (org.datanucleus.metadata.RelationType)1 ElementContainerHandler (org.datanucleus.store.types.ElementContainerHandler)1 SCOMap (org.datanucleus.store.types.SCOMap)1 TypeManager (org.datanucleus.store.types.TypeManager)1 PersistableRelationStore (org.datanucleus.store.types.scostore.PersistableRelationStore)1