Search in sources :

Example 96 with NucleusDataStoreException

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

the class LinkedList method addAll.

/**
 * Method to add a Collection to a position in the LinkedList.
 * @param index Position to insert the collection.
 * @param elements The collection
 * @return Whether it was added ok.
 */
public boolean addAll(int index, Collection elements) {
    if (useCache) {
        loadFromStore();
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            int pos = index;
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new ListAddAtOperation(ownerOP, backingStore, pos++, element));
            }
        } else {
            try {
                backingSuccess = backingStore.addAll(ownerOP, elements, index, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "addAll", ownerMmd.getName(), dse), dse);
            }
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    boolean delegateSuccess = delegate.addAll(index, elements);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListAddAtOperation(org.datanucleus.flush.ListAddAtOperation)

Example 97 with NucleusDataStoreException

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

the class List method addAll.

/**
 * Method to add a collection of elements.
 * @param elements The collection of elements to add.
 * @param index The position to add them
 * @return Whether they were added successfully.
 */
public boolean addAll(int index, Collection elements) {
    if (useCache) {
        loadFromStore();
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            int pos = index;
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new ListAddAtOperation(ownerOP, backingStore, pos++, element));
            }
        } else {
            try {
                backingSuccess = backingStore.addAll(ownerOP, elements, index, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "addAll", ownerMmd.getName(), dse), dse);
            }
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    boolean delegateSuccess = delegate.addAll(index, elements);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListAddAtOperation(org.datanucleus.flush.ListAddAtOperation)

Example 98 with NucleusDataStoreException

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

the class List method addAll.

/**
 * Method to add a Collection to the ArrayList.
 * @param elements The collection
 * @return Whether it was added ok.
 */
public boolean addAll(Collection elements) {
    if (useCache) {
        loadFromStore();
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
            }
        } else {
            try {
                backingSuccess = backingStore.addAll(ownerOP, elements, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "addAll", ownerMmd.getName(), dse), dse);
            }
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    boolean delegateSuccess = delegate.addAll(elements);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException)

Example 99 with NucleusDataStoreException

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

the class List method add.

// ----------------------------- Mutators methods --------------------------
/**
 * Method to add an element to the List
 * @param element The element to add
 * @return Whether it was added successfully.
 */
public boolean add(E element) {
    // Reject inappropriate elements
    if (!allowNulls && element == null) {
        throw new NullPointerException("Nulls not allowed for collection at field " + ownerMmd.getName() + " but element is null");
    }
    if (useCache) {
        loadFromStore();
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
        } else {
            try {
                backingSuccess = backingStore.add(ownerOP, element, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "add", ownerMmd.getName(), dse), dse);
            }
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    boolean delegateSuccess = delegate.add(element);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException)

Example 100 with NucleusDataStoreException

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

the class List 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 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)

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