Search in sources :

Example 1 with StateManager

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

the class ArrayList method addAll.

/**
 * Inserts all of the elements in in the specified Collection into this
 * ArrayList at the specified position.  Shifts the element currently at
 * that position (if any) and any subsequent elements to the right
 * (increases their indices).  The new elements will appear in the ArrayList
 * in the order that they are returned by the specified Collection's
 * iterator.
 *
 * @param index index at which to insert first element
 *              from the specified collection.
 * @param c elements to be inserted into this ArrayList.
 * @exception IndexOutOfBoundsException index out of range (index
 *            < 0 || index > size()).
 * @see java.util.ArrayList
 */
public boolean addAll(int index, Collection c) {
    if (allowNulls == false && c.contains(null)) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    java.util.Vector errc = new java.util.Vector();
    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());
    }
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    removed.removeAll(c);
    added.addAll(c);
    boolean modified = super.addAll(index, c);
    // Apply updates
    this.applyUpdates(stateManager, modified);
    return modified;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) Iterator(java.util.Iterator) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 2 with StateManager

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

the class ArrayList method clear.

/**
 * Removes all of the elements from this ArrayList.  The ArrayList will
 * be empty after this call returns (unless it throws an exception).
 *
 * @see java.util.ArrayList
 */
public void clear() {
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    for (Iterator iter = super.iterator(); iter.hasNext(); ) {
        Object o = iter.next();
        if (added.remove(o) == false)
            removed.add(o);
    }
    added.clear();
    super.clear();
    // Apply updates
    this.applyUpdates(stateManager, true);
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) Iterator(java.util.Iterator)

Example 3 with StateManager

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

the class ArrayList method addAll.

/**
 * Appends all of the elements in the specified Collection to the end of
 * this ArrayList, in the order that they are returned by the specified
 * Collection's Iterator.
 *
 * @param c elements to be inserted into this ArrayList.
 * @exception IndexOutOfBoundsException index out of range (index
 *            < 0 || index > size()).
 * @see java.util.ArrayList
 */
public boolean addAll(Collection c) {
    if (allowNulls == false && c.contains(null)) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    java.util.Vector errc = new java.util.Vector();
    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());
    }
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    removed.removeAll(c);
    added.addAll(c);
    boolean modified = super.addAll(c);
    // Apply updates
    this.applyUpdates(stateManager, modified);
    return modified;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) Iterator(java.util.Iterator) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 4 with StateManager

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

the class ArrayList method retainAll.

/**
 * Retains only the elements in this ArrayList that are contained in the
 * specified Collection.
 *
 * @return true if this ArrayList changed as a result of the call.
 * @see java.util.ArrayList
 */
public boolean retainAll(Collection c) {
    boolean modified = false;
    java.util.Vector v = new java.util.Vector();
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    for (Iterator iter = super.iterator(); iter.hasNext(); ) {
        Object o = iter.next();
        if (!c.contains(o)) {
            v.add(o);
            if (added.remove(o) == false)
                removed.add(o);
            modified = true;
        }
    }
    // Now remove the rest (stored in "v")
    for (Iterator iter = v.iterator(); iter.hasNext(); ) {
        removeInternal(iter.next());
    }
    // Apply updates
    this.applyUpdates(stateManager, modified);
    return modified;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) Iterator(java.util.Iterator)

Example 5 with StateManager

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

the class ArrayList method removeAll.

/**
 * Removes from this ArrayList all of its elements that are contained in the
 * specified Collection.
 *
 * @return true if this ArrayList changed as a result of the call.
 * @see java.util.ArrayList
 */
public boolean removeAll(Collection c) {
    boolean modified = false;
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    Iterator e = c.iterator();
    while (e.hasNext()) {
        Object o = e.next();
        if (super.contains(o)) {
            removeInternal(o);
            if (added.remove(o) == false)
                removed.add(o);
            modified = true;
        }
    }
    // Apply updates
    this.applyUpdates(stateManager, modified);
    return modified;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) Iterator(java.util.Iterator)

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