Search in sources :

Example 81 with ExecutionContext

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

the class LinkedList method initialise.

public void initialise(java.util.LinkedList newValue, Object oldValue) {
    if (newValue != null) {
        // Check for the case of serialised PC elements, and assign ObjectProviders to the elements without
        ExecutionContext ec = ownerOP.getExecutionContext();
        if (SCOUtils.collectionHasSerialisedElements(ownerMmd) && ownerMmd.getCollection().elementIsPersistent()) {
            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 82 with ExecutionContext

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

the class LinkedList method initialise.

/**
 * Method to initialise the SCO from an existing value.
 * @param c The object to set from
 */
public void initialise(java.util.LinkedList c) {
    if (c != null) {
        // Check for the case of serialised PC elements, and assign ObjectProviders to the elements without
        ExecutionContext ec = ownerOP.getExecutionContext();
        if (SCOUtils.collectionHasSerialisedElements(ownerMmd) && ownerMmd.getCollection().elementIsPersistent()) {
            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) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 83 with ExecutionContext

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

the class PriorityQueue method initialise.

public void initialise(java.util.PriorityQueue 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) || !ownerOP.getLifecycleState().isNew()) {
                if (ownerOP.isFlushedToDatastore()) {
                    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) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 84 with ExecutionContext

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

the class PriorityQueue method initialise.

/**
 * Method to initialise the SCO from an existing value.
 * @param c The object to set from
 */
public void initialise(java.util.PriorityQueue 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)

Example 85 with ExecutionContext

use of org.datanucleus.ExecutionContext in project datanucleus-api-jdo by datanucleus.

the class JDOPersistenceManagerFactory method close.

/**
 * Close this PersistenceManagerFactory. Check for JDOPermission("closePersistenceManagerFactory") and if not authorized, throw SecurityException.
 * <P>If the authorization check succeeds, check to see that all PersistenceManager instances obtained
 * from this PersistenceManagerFactory have no active transactions. If any PersistenceManager instances
 * have an active transaction, throw a JDOUserException, with one nested JDOUserException for each
 * PersistenceManager with an active Transaction.
 * <P>If there are no active transactions, then close all PersistenceManager instances obtained from
 * this PersistenceManagerFactory, mark this PersistenceManagerFactory as closed, disallow
 * getPersistenceManager methods, and allow all other get methods. If a set method or getPersistenceManager
 * method is called after close, then JDOUserException is thrown.
 * @see javax.jdo.PersistenceManagerFactory#close()
 */
public synchronized void close() {
    checkJDOPermission(JDOPermission.CLOSE_PERSISTENCE_MANAGER_FACTORY);
    if (isClosed()) {
        return;
    }
    setIsNotConfigurable();
    // Check there are no active transactions before closing any PM
    Set<JDOUserException> exceptions = new HashSet<JDOUserException>();
    for (JDOPersistenceManager pm : pmCache) {
        ExecutionContext ec = pm.getExecutionContext();
        if (ec.getTransaction().isActive()) {
            // Note: we replicate the exception that would have come from pm.close() when tx active
            TransactionActiveOnCloseException tae = new TransactionActiveOnCloseException(ec);
            exceptions.add(new JDOUserException(tae.getMessage(), pm));
        }
    }
    if (!exceptions.isEmpty()) {
        throw new JDOUserException(Localiser.msg("012002"), exceptions.toArray(new Throwable[exceptions.size()]));
    }
    // Close all PMs
    for (JDOPersistenceManager pm : pmCache) {
        pm.internalClose();
    }
    pmCache.clear();
    if (pmfByName != null) {
        // Closing so clean out from singleton pattern handler
        Iterator<Map.Entry<String, JDOPersistenceManagerFactory>> pmfIter = pmfByName.entrySet().iterator();
        while (pmfIter.hasNext()) {
            Map.Entry<String, JDOPersistenceManagerFactory> entry = pmfIter.next();
            if (entry.getValue() == this) {
                pmfIter.remove();
                break;
            }
        }
    }
    if (sequenceByFactoryClass != null) {
        sequenceByFactoryClass.clear();
        sequenceByFactoryClass = null;
    }
    if (lifecycleListeners != null) {
        lifecycleListeners.clear();
        lifecycleListeners = null;
    }
    if (datastoreCache != null) {
        datastoreCache.evictAll();
        datastoreCache = null;
    }
    if (queryCache != null) {
        queryCache.evictAll();
        queryCache = null;
    }
    if (jdoFetchGroups != null) {
        jdoFetchGroups.clear();
        jdoFetchGroups = null;
    }
    nucleusContext.close();
    active = false;
    closed = true;
}
Also used : JDOUserException(javax.jdo.JDOUserException) TransactionActiveOnCloseException(org.datanucleus.exceptions.TransactionActiveOnCloseException) ExecutionContext(org.datanucleus.ExecutionContext) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

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