Search in sources :

Example 6 with StateManager

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

the class ArrayList method add.

/**
 * Inserts the specified element at the specified position in this ArrayList.
 *
 * @param index index at which the specified element is to be inserted.
 * @param element element to be inserted.
 * @exception IndexOutOfBoundsException index is out of range
 *            (index < 0 || index > size()).
 * @see java.util.ArrayList
 */
public void add(int index, Object element) {
    if (allowNulls == false && element == null) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    if (elementType == null || elementType.isAssignableFrom(element.getClass())) {
        // Mark the field as dirty
        StateManager stateManager = this.makeDirty();
        super.add(index, element);
        if (removed.remove(element) == false)
            added.add(element);
        // Apply updates
        this.applyUpdates(stateManager, true);
    } else {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), new Object[] { element });
    }
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 7 with StateManager

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

the class ArrayList method set.

/**
 * ------------------Public Methods----------------
 */
/**
 * Replaces the element at the specified position in this ArrayList with the
 * specified element.
 *
 * @param index index of element to replace.
 * @param element element to be stored at the specified position.
 * @return the element previously at the specified position.
 * @exception IndexOutOfBoundsException index out of range
 *            (index < 0 || index >= size()).
 * @exception IllegalArgumentException fromIndex > toIndex.
 * @see java.util.ArrayList
 */
public Object set(int index, Object element) {
    throwUnsupportedOption();
    if (element == null) {
        if (allowNulls == false) {
            throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
            "sco.nulls_not_allowed"));
        }
        // It is actualy remove
        return this.remove(index);
    }
    if (elementType == null || elementType.isAssignableFrom(element.getClass())) {
        // Mark the field as dirty
        StateManager stateManager = this.makeDirty();
        Object o = super.set(index, element);
        if (added.remove(o) == false)
            removed.add(o);
        if (removed.remove(element) == false)
            added.add(element);
        // Apply updates
        this.applyUpdates(stateManager, true);
        return o;
    } else {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), new Object[] { element });
    }
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 8 with StateManager

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

the class ArrayList method remove.

/**
 * Removes the element at the specified position in this ArrayList.
 * shifts any subsequent elements to the left (subtracts one from their
 * indices).  Returns the element that was removed from the ArrayList.
 *
 * @param index the index of the element to removed.
 * @exception IndexOutOfBoundsException index out of range (index
 *            < 0 || index >= size()).
 * @see java.util.ArrayList
 */
public Object remove(int index) {
    throwUnsupportedOption();
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    Object obj = super.remove(index);
    if (added.remove(obj) == false)
        removed.add(obj);
    // Apply updates
    this.applyUpdates(stateManager, true);
    return obj;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager)

Example 9 with StateManager

use of com.sun.jdo.spi.persistence.support.sqlstore.StateManager 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 10 with StateManager

use of com.sun.jdo.spi.persistence.support.sqlstore.StateManager 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)

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