Search in sources :

Example 1 with PersistenceManager

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

the class HashSet method clear.

/**
 * Removes all of the elements from this set.
 * @see java.util.HashSet
 */
public void clear() {
    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);
                    removed.clear();
                    added.clear();
                    for (Iterator iter = super.iterator(); iter.hasNext(); ) {
                        removed.add(iter.next());
                    }
                    super.clear();
                    // Apply updates
                    stateManager.applyUpdates(fieldName, this);
                    return;
                } finally {
                    pm.releaseFieldUpdateLock();
                }
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    super.clear();
}
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 2 with PersistenceManager

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

the class HashSet method add.

// -------------------------Public Methods------------------
/**
 * Adds the specified element to this set if it is not already
 * present.
 *
 * @param o element to be added to this set.
 * @return <tt>true</tt> if the set did not already contain the specified
 * element.
 * @see java.util.HashSet
 */
public boolean add(Object o) {
    if (allowNulls == false && o == null) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    if (elementType != null && !elementType.isAssignableFrom(o.getClass())) {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), new Object[] { o });
    }
    if (owner != null) {
        StateManager stateManager = owner.jdoGetStateManager();
        if (stateManager != null) {
            PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
            pm.acquireShareLock();
            boolean modified = false;
            try {
                pm.acquireFieldUpdateLock();
                try {
                    // Mark the field as dirty
                    stateManager.makeDirty(fieldName);
                    modified = super.add(o);
                    if (modified) {
                        if (removed.remove(o) == false) {
                            added.add(o);
                        }
                        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++) {
                        Object failedObject = failedObjects[i];
                        if (failedObject == o) {
                            super.remove(failedObject);
                            break;
                        }
                    }
                }
                throw e;
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    return super.add(o);
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) PersistenceManager(com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 3 with PersistenceManager

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

the class HashSet method remove.

/**
 * Removes the given element from this set if it is present.
 *
 * @param o object to be removed from this set, if present.
 * @return <tt>true</tt> if the set contained the specified element.
 * @see java.util.HashSet
 */
public boolean remove(Object o) {
    if (owner != null) {
        StateManager stateManager = owner.jdoGetStateManager();
        if (stateManager != null) {
            PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
            pm.acquireShareLock();
            try {
                pm.acquireFieldUpdateLock();
                try {
                    stateManager.makeDirty(fieldName);
                    boolean modified = super.remove(o);
                    if (modified) {
                        if (added.remove(o) == false) {
                            removed.add(o);
                        }
                        stateManager.applyUpdates(fieldName, this);
                    }
                    return modified;
                } finally {
                    pm.releaseFieldUpdateLock();
                }
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    return super.remove(o);
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) PersistenceManager(com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager)

Example 4 with PersistenceManager

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

the class HashSet method retainAll.

/**
 * Retains only the elements in this collection that are contained in the
 * specified collection (optional operation).
 *
 * @return <tt>true</tt> if this collection changed as a result of the
 *         call.
 *
 * @throws UnsupportedOperationException if the <tt>retainAll</tt> method
 *            is not supported by this collection.
 *
 * @see java.util.HashSet
 * @see java.util.AbstractCollection
 */
public boolean retainAll(Collection c) {
    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 = super.iterator(); iter.hasNext(); ) {
                        Object o = iter.next();
                        if (!c.contains(o)) {
                            if (added.remove(o) == false) {
                                removed.add(o);
                            }
                        }
                    }
                    boolean modified = super.retainAll(c);
                    if (modified) {
                        stateManager.applyUpdates(fieldName, this);
                    }
                    return modified;
                } finally {
                    pm.releaseFieldUpdateLock();
                }
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    return super.retainAll(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 5 with PersistenceManager

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

the class SqlDate 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

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