Search in sources :

Example 21 with StateManager

use of com.sun.jdo.spi.persistence.support.sqlstore.StateManager in project Payara by payara.

the class ArrayList method remove.

/**
 * Removes the first occurrence of the specified element in this ArrayList
 * If the ArrayList does not contain the element, it is unchanged.
 *
 * @param o element to be removed from this ArrayList, if present.
 * @return true if the ArrayList contained the specified element.
 * @see java.util.ArrayList
 */
public boolean remove(Object o) {
    // Because java.util.AbstractCollection.remove(Object) delegates remove() to remove(int)
    // which is not supported, we cannot rely on jdk. We need to process remove here.
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    int i = super.indexOf(o);
    Object obj = null;
    if (i > -1) {
        obj = super.remove(i);
        if (added.remove(obj) == false)
            removed.add(obj);
        // Apply updates
        this.applyUpdates(stateManager, true);
        return true;
    }
    return false;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager)

Example 22 with StateManager

use of com.sun.jdo.spi.persistence.support.sqlstore.StateManager in project Payara by payara.

the class Date method makeDirty.

/**
 * Marks object dirty
 */
public StateManager makeDirty() {
    if (owner != null) {
        StateManager stateManager = owner.jdoGetStateManager();
        if (stateManager != null) {
            PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
            pm.acquireShareLock();
            try {
                synchronized (stateManager) {
                    // 
                    if (owner != null) {
                        stateManager.makeDirty(fieldName);
                        return stateManager;
                    }
                }
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    return null;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) PersistenceManager(com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager)

Example 23 with StateManager

use of com.sun.jdo.spi.persistence.support.sqlstore.StateManager in project Payara by payara.

the class HashSet method removeAll.

/**
 * Removes from this collection all of its elements that are contained in
 * the specified collection (optional operation). <p>
 *
 * @param c elements to be removed from this collection.
 * @return <tt>true</tt> if this collection changed as a result of the
 * call.
 *
 * @throws    UnsupportedOperationException removeAll is not supported
 *            by this collection.
 *
 * @see java.util.HashSet
 * @see java.util.AbstractCollection
 */
public boolean removeAll(Collection c) {
    if (owner != null) {
        StateManager stateManager = owner.jdoGetStateManager();
        if (stateManager != null) {
            PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
            pm.acquireShareLock();
            try {
                pm.acquireFieldUpdateLock();
                try {
                    stateManager.makeDirty(fieldName);
                    for (Iterator iter = c.iterator(); iter.hasNext(); ) {
                        Object o = iter.next();
                        if (super.contains(o)) {
                            if (added.remove(o) == false) {
                                removed.add(o);
                            }
                        }
                    }
                    boolean modified = super.removeAll(c);
                    // Apply updates
                    if (modified) {
                        stateManager.applyUpdates(fieldName, this);
                    }
                    return modified;
                } finally {
                    pm.releaseFieldUpdateLock();
                }
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    return super.removeAll(c);
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) PersistenceManager(com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager) Iterator(java.util.Iterator)

Example 24 with StateManager

use of com.sun.jdo.spi.persistence.support.sqlstore.StateManager in project Payara by payara.

the class HashSet method addAll.

/**
 * Adds all of the elements in the specified collection to this collection
 *
 * @param c collection whose elements are to be added to this collection.
 * @return <tt>true</tt> if this collection changed as a result of the
 * call.
 * @throws UnsupportedOperationException if the <tt>addAll</tt> method is
 *            not supported by this collection.
 *
 * @see java.util.AbstractCollection
 * @see java.util.HashSet
 */
public boolean addAll(Collection c) {
    if (allowNulls == false && c.contains(null)) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    ArrayList errc = new ArrayList();
    if (elementType != null) {
        // iterate the collection and make a list of wrong elements.
        Iterator i = c.iterator();
        while (i.hasNext()) {
            Object o = i.next();
            if (!elementType.isAssignableFrom(o.getClass()))
                errc.add(o);
        }
    }
    if (errc != null && errc.size() > 0) {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), errc.toArray());
    }
    boolean modified = false;
    if (owner != null) {
        StateManager stateManager = owner.jdoGetStateManager();
        if (stateManager != null) {
            PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
            pm.acquireShareLock();
            try {
                pm.acquireFieldUpdateLock();
                try {
                    // Mark the field as dirty
                    stateManager.makeDirty(fieldName);
                    for (Iterator iter = c.iterator(); iter.hasNext(); ) {
                        Object o = iter.next();
                        if (!super.contains(o)) {
                            if (removed.remove(o) == false) {
                                added.add(o);
                            }
                            super.add(o);
                            modified = true;
                        }
                    }
                    // Apply updates
                    if (modified) {
                        stateManager.applyUpdates(fieldName, this);
                    }
                    return modified;
                } finally {
                    pm.releaseFieldUpdateLock();
                }
            } catch (JDOUserException e) {
                Object[] failedObjects = e.getFailedObjectArray();
                if (modified && (failedObjects != null)) {
                    for (int i = 0; i < failedObjects.length; i++) {
                        super.remove(failedObjects[i]);
                    }
                }
                throw e;
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    return super.addAll(c);
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) PersistenceManager(com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 25 with StateManager

use of com.sun.jdo.spi.persistence.support.sqlstore.StateManager in project Payara by payara.

the class SqlTime method makeDirty.

/**
 * Marks object dirty
 */
public StateManager makeDirty() {
    if (owner != null) {
        StateManager stateManager = owner.jdoGetStateManager();
        if (stateManager != null) {
            PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
            pm.acquireShareLock();
            try {
                synchronized (stateManager) {
                    // 
                    if (owner != null) {
                        stateManager.makeDirty(fieldName);
                        return stateManager;
                    }
                }
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    return null;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) PersistenceManager(com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager)

Aggregations

StateManager (com.sun.jdo.spi.persistence.support.sqlstore.StateManager)36 JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)14 Iterator (java.util.Iterator)14 PersistenceManager (com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager)10 ArrayList (java.util.ArrayList)1