Search in sources :

Example 76 with ExecutionContext

use of org.datanucleus.ExecutionContext in project datanucleus-core by datanucleus.

the class SortedSet method initialise.

public void initialise(java.util.SortedSet<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 77 with ExecutionContext

use of org.datanucleus.ExecutionContext in project datanucleus-core by datanucleus.

the class Vector method initialise.

public void initialise(java.util.Vector 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()));
        }
        // TODO This does clear+addAll : Improve this and work out which elements are added and which deleted
        if (backingStore != null) {
            if (SCOUtils.useQueuedUpdate(ownerOP)) {
                if (ownerOP.isFlushedToDatastore() || !ownerOP.getLifecycleState().isNew()) {
                    ownerOP.getExecutionContext().addOperationToQueue(new CollectionClearOperation(ownerOP, backingStore));
                    for (Object element : newValue) {
                        ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
                    }
                }
            } else {
                backingStore.clear(ownerOP);
                try {
                    backingStore.addAll(ownerOP, newValue, useCache ? 0 : -1);
                } catch (NucleusDataStoreException dse) {
                    NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "addAll", ownerMmd.getName(), dse));
                }
            }
        }
        delegate.addAll(newValue);
        isCacheLoaded = true;
        makeDirty();
    }
}
Also used : CollectionClearOperation(org.datanucleus.flush.CollectionClearOperation) CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ExecutionContext(org.datanucleus.ExecutionContext) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 78 with ExecutionContext

use of org.datanucleus.ExecutionContext in project datanucleus-core by datanucleus.

the class Hashtable method initialise.

/**
 * Method to initialise the SCO from an existing value.
 * @param m Object to set value using.
 */
public void initialise(java.util.Hashtable m) {
    if (m != null) {
        // Check for the case of serialised maps, and assign ObjectProviders to any PC keys/values without
        if (SCOUtils.mapHasSerialisedKeysAndValues(ownerMmd) && (ownerMmd.getMap().keyIsPersistent() || ownerMmd.getMap().valueIsPersistent())) {
            ExecutionContext ec = ownerOP.getExecutionContext();
            Iterator iter = m.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                Object key = entry.getKey();
                Object value = entry.getValue();
                if (ownerMmd.getMap().keyIsPersistent()) {
                    ObjectProvider keyOP = ec.findObjectProvider(key);
                    if (keyOP == null) {
                        keyOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, key, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                    }
                }
                if (ownerMmd.getMap().valueIsPersistent()) {
                    ObjectProvider valOP = ec.findObjectProvider(value);
                    if (valOP == null) {
                        valOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, value, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                    }
                }
            }
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("023007", ownerOP.getObjectAsPrintable(), ownerMmd.getName(), "" + m.size()));
        }
        delegate.putAll(m);
        isCacheLoaded = true;
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) Iterator(java.util.Iterator) ObjectProvider(org.datanucleus.state.ObjectProvider) Map(java.util.Map)

Example 79 with ExecutionContext

use of org.datanucleus.ExecutionContext in project datanucleus-core by datanucleus.

the class LinkedHashMap method initialise.

/**
 * Method to initialise the SCO from an existing value.
 * @param m Object to set value using.
 */
public void initialise(java.util.LinkedHashMap m) {
    if (m != null) {
        // Check for the case of serialised maps, and assign ObjectProviders to any PC keys/values without
        if (SCOUtils.mapHasSerialisedKeysAndValues(ownerMmd) && (ownerMmd.getMap().keyIsPersistent() || ownerMmd.getMap().valueIsPersistent())) {
            ExecutionContext ec = ownerOP.getExecutionContext();
            Iterator iter = m.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                Object key = entry.getKey();
                Object value = entry.getValue();
                if (ownerMmd.getMap().keyIsPersistent()) {
                    ObjectProvider keyOP = ec.findObjectProvider(key);
                    if (keyOP == null) {
                        keyOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, key, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                    }
                }
                if (ownerMmd.getMap().valueIsPersistent()) {
                    ObjectProvider valOP = ec.findObjectProvider(value);
                    if (valOP == null) {
                        valOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, value, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                    }
                }
            }
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("023007", ownerOP.getObjectAsPrintable(), ownerMmd.getName(), "" + m.size()));
        }
        delegate.putAll(m);
        isCacheLoaded = true;
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) Iterator(java.util.Iterator) ObjectProvider(org.datanucleus.state.ObjectProvider) Map(java.util.Map)

Example 80 with ExecutionContext

use of org.datanucleus.ExecutionContext in project datanucleus-core by datanucleus.

the class LinkedHashSet method initialise.

/**
 * Method to initialise the SCO from an existing value.
 * @param c The object to set from
 */
public void initialise(java.util.LinkedHashSet c) {
    if (c != 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 = c.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 (backingStore != null && useCache && !isCacheLoaded) {
            // Mark as loaded
            isCacheLoaded = true;
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("023007", ownerOP.getObjectAsPrintable(), ownerMmd.getName(), "" + c.size()));
        }
        delegate.clear();
        delegate.addAll(c);
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator) ObjectProvider(org.datanucleus.state.ObjectProvider)

Aggregations

ExecutionContext (org.datanucleus.ExecutionContext)178 ObjectProvider (org.datanucleus.state.ObjectProvider)85 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)73 SQLException (java.sql.SQLException)66 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)64 SQLController (org.datanucleus.store.rdbms.SQLController)63 PreparedStatement (java.sql.PreparedStatement)62 Iterator (java.util.Iterator)56 MappedDatastoreException (org.datanucleus.store.rdbms.exceptions.MappedDatastoreException)27 ResultSet (java.sql.ResultSet)26 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)26 StatementMappingIndex (org.datanucleus.store.rdbms.query.StatementMappingIndex)25 Map (java.util.Map)23 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)20 Collection (java.util.Collection)18 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)18 StatementClassMapping (org.datanucleus.store.rdbms.query.StatementClassMapping)17 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)16 SCOCollectionIterator (org.datanucleus.store.types.SCOCollectionIterator)16 ArrayList (java.util.ArrayList)15