Search in sources :

Example 81 with NucleusDataStoreException

use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.

the class Stack method removeAll.

/**
 * Method to remove a Collection of objects from the Stack
 * @param elements The Collection
 * @return Whether the collection of elements were removed
 */
public synchronized boolean removeAll(Collection elements) {
    if (elements == null) {
        throw new NullPointerException();
    } else if (elements.isEmpty()) {
        return true;
    }
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    int size = useCache ? delegate.size() : -1;
    Collection contained = null;
    if (backingStore != null && SCOUtils.useQueuedUpdate(ownerOP)) {
        // Check which are contained before updating the delegate
        contained = new java.util.HashSet();
        for (Object elem : elements) {
            if (contains(elem)) {
                contained.add(elem);
            }
        }
    }
    boolean delegateSuccess = delegate.removeAll(elements);
    if (backingStore != null && ownerOP != null) {
        boolean backingSuccess = true;
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            if (contained != null && !contained.isEmpty()) {
                backingSuccess = false;
                for (Object element : contained) {
                    backingSuccess = true;
                    ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, backingStore, element, true));
                }
            }
        } else {
            try {
                backingSuccess = backingStore.removeAll(ownerOP, elements, size);
            } catch (NucleusDataStoreException dse) {
                NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "removeAll", ownerMmd.getName(), dse));
                backingSuccess = false;
            }
        }
        if (!ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
        return backingSuccess;
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return delegateSuccess;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) Collection(java.util.Collection) CollectionRemoveOperation(org.datanucleus.flush.CollectionRemoveOperation)

Example 82 with NucleusDataStoreException

use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.

the class Stack method remove.

/**
 * Method to remove an element from the collection, and observe the flag for whether to allow cascade delete.
 * @param element The element
 * @param allowCascadeDelete Whether to allow cascade delete
 */
public synchronized boolean remove(Object element, boolean allowCascadeDelete) {
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    int size = useCache ? delegate.size() : -1;
    boolean contained = delegate.contains(element);
    boolean delegateSuccess = delegate.remove(element);
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            backingSuccess = contained;
            if (backingSuccess) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, backingStore, element, allowCascadeDelete));
            }
        } else {
            try {
                backingSuccess = backingStore.remove(ownerOP, element, size, allowCascadeDelete);
            } catch (NucleusDataStoreException dse) {
                NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "remove", ownerMmd.getName(), dse));
                backingSuccess = false;
            }
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) CollectionRemoveOperation(org.datanucleus.flush.CollectionRemoveOperation)

Example 83 with NucleusDataStoreException

use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.

the class Stack method remove.

/**
 * Method to remove an element from the Stack
 * @param index The element position.
 * @return The object that was removed
 */
public synchronized E remove(int index) {
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    int size = useCache ? delegate.size() : -1;
    E delegateObject = (useCache ? delegate.remove(index) : null);
    E backingObject = null;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            backingObject = delegateObject;
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, backingStore, index));
        } else {
            try {
                backingObject = backingStore.remove(ownerOP, index, size);
            } catch (NucleusDataStoreException dse) {
                NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "remove", ownerMmd.getName(), dse));
                backingObject = null;
            }
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingObject : delegateObject;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Example 84 with NucleusDataStoreException

use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.

the class Vector method removeAll.

/**
 * Method to remove a Collection of elements from the Vector.
 * @param elements The collection
 * @return Whether it was removed ok.
 */
public synchronized boolean removeAll(Collection elements) {
    if (elements == null) {
        throw new NullPointerException();
    } else if (elements.isEmpty()) {
        return true;
    }
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    int size = useCache ? delegate.size() : -1;
    Collection contained = null;
    if (backingStore != null && SCOUtils.useQueuedUpdate(ownerOP)) {
        // Check which are contained before updating the delegate
        contained = new java.util.HashSet();
        for (Object elem : elements) {
            if (contains(elem)) {
                contained.add(elem);
            }
        }
    }
    boolean delegateSuccess = delegate.removeAll(elements);
    if (backingStore != null && ownerOP != null) {
        boolean backingSuccess = true;
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            if (contained != null && !contained.isEmpty()) {
                backingSuccess = false;
                for (Object element : contained) {
                    backingSuccess = true;
                    ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, backingStore, element, true));
                }
            }
        } else {
            try {
                backingSuccess = backingStore.removeAll(ownerOP, elements, size);
            } catch (NucleusDataStoreException dse) {
                NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "removeAll", ownerMmd.getName(), dse));
                backingSuccess = false;
            }
        }
        if (!ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
        return backingSuccess;
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return delegateSuccess;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) Collection(java.util.Collection) CollectionRemoveOperation(org.datanucleus.flush.CollectionRemoveOperation)

Example 85 with NucleusDataStoreException

use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.

the class Vector method remove.

/**
 * Method to remove an element from the Vector.
 * @param index The element position.
 * @return The object that was removed
 */
public synchronized E remove(int index) {
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    int size = useCache ? delegate.size() : -1;
    E delegateObject = useCache ? delegate.remove(index) : null;
    E backingObject = null;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            backingObject = delegateObject;
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, backingStore, index));
        } else {
            try {
                backingObject = backingStore.remove(ownerOP, index, size);
            } catch (NucleusDataStoreException dse) {
                NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "remove", ownerMmd.getName(), dse));
                backingObject = null;
            }
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingObject : delegateObject;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Aggregations

NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)200 SQLException (java.sql.SQLException)98 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)74 ExecutionContext (org.datanucleus.ExecutionContext)73 PreparedStatement (java.sql.PreparedStatement)63 SQLController (org.datanucleus.store.rdbms.SQLController)60 ResultSet (java.sql.ResultSet)45 Iterator (java.util.Iterator)34 CollectionAddOperation (org.datanucleus.flush.CollectionAddOperation)34 CollectionRemoveOperation (org.datanucleus.flush.CollectionRemoveOperation)26 ObjectProvider (org.datanucleus.state.ObjectProvider)22 ArrayList (java.util.ArrayList)21 MappedDatastoreException (org.datanucleus.store.rdbms.exceptions.MappedDatastoreException)21 Collection (java.util.Collection)20 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)20 StatementMappingIndex (org.datanucleus.store.rdbms.query.StatementMappingIndex)19 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)18 SCOCollectionIterator (org.datanucleus.store.types.SCOCollectionIterator)15 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)14 List (java.util.List)13