Search in sources :

Example 11 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.

the class TransactionImpl method commitBefore.

/**
 * Lower-level before-commit method - phase 0.
 *
 * This is called before commit processing actually begins.
 * State transition:
 *        STATUS_ACTIVE        starting state
 *        startedCommit        set to avoid concurrent commits
 *        beforeCompletion()    called while still active
 *        STATUS_PREPARING    no longer active, about to "really" commit
 *
 * The startedCommit status is an "internal state" which is still active
 * but prevents concurrent commits and some other operations.
 *
 * For exceptions see commit() method.
 */
private void commitBefore() {
    // marked for rollback
    boolean rollbackOnly = false;
    boolean notified = false;
    if (this.tracing)
        // NOI18N
        this.traceCall("commitBefore");
    if ((this.status == Status.STATUS_ROLLING_BACK) || (this.status == Status.STATUS_ROLLEDBACK)) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "transaction.transactionimpl.rolledback", // NOI18N
        "commit", this.statusString(this.status)));
    }
    if (this.status == Status.STATUS_MARKED_ROLLBACK) {
        rollbackOnly = true;
    } else if (this.status != Status.STATUS_ACTIVE) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "transaction.transactionimpl.commit_rollback.notactive", // NOI18N
        "commit", this.statusString(this.status)));
    }
    if (this.startedCommit) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "transaction.transactionimpl.commitbefore.incommit", // NOI18N
        "commit"));
    }
    this.startedCommit = true;
    // 
    if (!rollbackOnly) {
        this.notifyBeforeCompletion();
        notified = true;
        if (this.status == Status.STATUS_ACTIVE) {
            // All ok
            this.setStatus(Status.STATUS_PREPARING);
        } else if (this.status == Status.STATUS_MARKED_ROLLBACK) {
            rollbackOnly = true;
        } else {
            // Must have been concurrently rolled back
            throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
            "transaction.transactionimpl.commitbefore.rolledback"));
        }
    }
    if (rollbackOnly && txType == NON_MGD) {
        this.rollback();
        throw new JDOUserException(I18NHelper.getMessage(messages, notified ? // NOI18N
        "transaction.transactionimpl.commitbefore.rollbackonly_insync" : // NOI18N
        "transaction.transactionimpl.commitbefore.rollbackonly"));
    }
}
Also used : JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 12 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.

the class ArrayList method add.

/**
 * Appends the specified element to the end of this ArrayList.
 *
 * @param o element to be appended to this ArrayList.
 * @return true (as per the general contract of Collection.add).
 * @see java.util.ArrayList
 */
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())) {
        // 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 13 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.

the class HashSet method addAll.

/**
 * Adds all of the elements in the specified collection to this collection
 *
 * @param c collection whose elements are to be added to this collection.
 * @return <tt>true</tt> if this collection changed as a result of the
 * call.
 * @throws UnsupportedOperationException if the <tt>addAll</tt> method is
 *            not supported by this collection.
 *
 * @see java.util.AbstractCollection
 * @see java.util.HashSet
 */
public boolean addAll(Collection c) {
    if (allowNulls == false && c.contains(null)) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    ArrayList errc = new ArrayList();
    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());
    }
    boolean modified = false;
    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 = c.iterator(); iter.hasNext(); ) {
                        Object o = iter.next();
                        if (!super.contains(o)) {
                            if (removed.remove(o) == false) {
                                added.add(o);
                            }
                            super.add(o);
                            modified = true;
                        }
                    }
                    // Apply updates
                    if (modified) {
                        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++) {
                        super.remove(failedObjects[i]);
                    }
                }
                throw e;
            } finally {
                pm.releaseShareLock();
            }
        }
    }
    return super.addAll(c);
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) PersistenceManager(com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 14 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException 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 15 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException 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
 *            &lt; 0 || index &gt; 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)

Aggregations

JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)20 StateManager (com.sun.jdo.spi.persistence.support.sqlstore.StateManager)14 Iterator (java.util.Iterator)6 PersistenceManager (com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager)2 ArrayList (java.util.ArrayList)2 ConversionException (com.sun.jdo.api.persistence.mapping.ejb.ConversionException)1 ModelException (com.sun.jdo.api.persistence.model.ModelException)1 JDODataStoreException (com.sun.jdo.api.persistence.support.JDODataStoreException)1 JDOException (com.sun.jdo.api.persistence.support.JDOException)1 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)1 JDOUnsupportedOptionException (com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException)1 GeneratorException (com.sun.jdo.spi.persistence.support.ejb.codegen.GeneratorException)1 EJBQLException (com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException)1 com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)1 java.io (java.io)1 File (java.io.File)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 DBException (org.netbeans.modules.dbschema.DBException)1