Search in sources :

Example 31 with StateManager

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

the class Vector method removeElementAt.

/**
 * Deletes the component at the specified index.
 *
 * @param      index   the index of the object to remove.
 * @exception  ArrayIndexOutOfBoundsException  if the index was invalid.
 * @see java.util.Vector
 */
public synchronized void removeElementAt(int index) {
    throwUnsupportedOption();
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    Object obj = super.elementAt(index);
    super.removeElementAt(index);
    if (added.remove(obj) == false)
        removed.add(obj);
    // Apply updates
    this.applyUpdates(stateManager, true);
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager)

Example 32 with StateManager

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

the class Vector method removeElement.

/**
 * Removes the first (lowest-indexed) occurrence of the argument
 * from this vector.
 *
 * @param   obj   the component to be removed.
 * @return  <code>true</code> if the argument was a component of this
 *          vector; <code>false</code> otherwise.
 * @see java.util.Vector
 */
public synchronized boolean removeElement(Object obj) {
    // Because java.util.Vector.removeElement(Object) calls internally removeElementAt(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(obj);
    if (i > -1) {
        super.removeElementAt(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 33 with StateManager

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

the class Vector method add.

/**
 * Appends the specified element to the end of this Vector.
 *
 * @param o element to be appended to this Vector.
 * @return true (as per the general contract of Collection.add).
 * @see java.util.Vector
 */
public synchronized 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())) {
        // Mark the field as dirty
        StateManager stateManager = this.makeDirty();
        if (removed.remove(o) == false)
            added.add(o);
        boolean modified = super.add(o);
        // Apply updates
        this.applyUpdates(stateManager, modified);
        return modified;
    } else {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), new Object[] { o });
    }
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 34 with StateManager

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

the class Vector method addAll.

/**
 * Appends all of the elements in the specified Collection to the end of
 * this Vector, in the order that they are returned by the specified
 * Collection's Iterator.
 *
 * @param c elements to be inserted into this Vector.
 * @see java.util.Vector
 */
public synchronized 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 35 with StateManager

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

the class Vector method insertElementAt.

/**
 * Inserts the specified object as a component in this vector at the
 * specified <code>index</code>.
 *
 * @param      obj     the component to insert.
 * @param      index   where to insert the new component.
 * @exception  ArrayIndexOutOfBoundsException  if the index was invalid.
 * @see java.util.Vector
 */
public synchronized void insertElementAt(Object obj, int index) {
    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.insertElementAt(obj, index);
        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)

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