Search in sources :

Example 26 with StateManager

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

the class Vector method addElement.

/**
 * Adds the specified component to the end of this vector,
 * increasing its size by one.
 *
 * @param   obj   the component to be added.
 * @see java.util.Vector
 */
public synchronized void addElement(Object obj) {
    if (allowNulls == false && obj == null) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    if (elementType == null || elementType.isAssignableFrom(obj.getClass())) {
        // Mark the field as dirty
        StateManager stateManager = this.makeDirty();
        super.addElement(obj);
        if (removed.remove(obj) == false)
            added.add(obj);
        // Apply updates
        this.applyUpdates(stateManager, true);
    } else {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), new Object[] { obj });
    }
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 27 with StateManager

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

the class Vector method addAll.

/**
 * Inserts all of the elements in in the specified Collection into this
 * Vector 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 Vector
 * 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 Vector.
 * @exception ArrayIndexOutOfBoundsException index out of range (index
 *            < 0 || index > size()).
 * @see java.util.Vector
 */
public synchronized 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 28 with StateManager

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

the class Vector method setElementAt.

/**
 * ------------------Public Methods----------------
 */
/**
 * Sets the component at the specified <code>index</code> of this
 * vector to be the specified object. The previous component at that
 * position is discarded.<p>
 *
 * @param      obj     what the component is to be set to.
 * @param      index   the specified index.
 * @exception  ArrayIndexOutOfBoundsException  if the index was invalid.
 * @see java.util.Vector
 */
public synchronized void setElementAt(Object obj, int index) {
    throwUnsupportedOption();
    if (obj == null) {
        if (allowNulls == false) {
            throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
            "sco.nulls_not_allowed"));
        }
        // It is actualy remove
        this.removeElementAt(index);
    }
    if (elementType == null || elementType.isAssignableFrom(obj.getClass())) {
        // Mark the field as dirty
        StateManager stateManager = this.makeDirty();
        Object o = super.elementAt(index);
        super.setElementAt(obj, index);
        if (added.remove(o) == false)
            removed.add(o);
        if (removed.remove(obj) == false)
            added.add(obj);
        // Apply updates
        this.applyUpdates(stateManager, true);
    } else {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), new Object[] { obj });
    }
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 29 with StateManager

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

the class Vector method removeAll.

/**
 * Removes from this Vector all of its elements that are contained in the
 * specified Collection.
 *
 * @return true if this Vector changed as a result of the call.
 * @see java.util.Vector
 */
public synchronized 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)

Example 30 with StateManager

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

the class Vector method remove.

/**
 * Removes the element at the specified position in this Vector.
 * shifts any subsequent elements to the left (subtracts one from their
 * indices).  Returns the element that was removed from the Vector.
 *
 * @param index the index of the element to removed.
 * @exception ArrayIndexOutOfBoundsException index out of range (index
 *            &lt; 0 || index &gt;= size()).
 * @see java.util.Vector
 */
public synchronized 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)

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