Search in sources :

Example 6 with JDOUserException

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

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

Example 8 with JDOUserException

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

the class Vector method set.

/**
 * Replaces the element at the specified position in this Vector 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 ArrayIndexOutOfBoundsException index out of range
 *            (index &lt; 0 || index &gt;= size()).
 * @exception IllegalArgumentException fromIndex &gt; toIndex.
 * @see java.util.Vector
 */
public synchronized 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 9 with JDOUserException

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

the class SelectQueryPlan method processOrderConstraints.

/**
 * Converts ConstraintFieldName used in Order by constraints into
 * ConstraintFieldDesc using ConstraintFieldName#originalPlan.<br />
 *
 * <em>Currently unused functionality:</em><br />
 * Gets all the "order by" constraints from the the current stack.
 * The constraints are ordered such that any "order by" constraint
 * with position N is placed before any "order by" constraint with
 * position N+m, where m > 0.  Also any "order by" constraint with
 * no position (i.e. position < 0) are placed immediately
 * following the previous "order by" constraint with a position.
 * The order of the "order by" constraints on the constraint stack
 * is changed to effect this ordering.
 * <em>NOTE:</em> The value constraints giving the position for
 * the order by constraints is currently not generated by the
 * query compiler.
 */
public void processOrderConstraints() {
    if ((status & ST_BUILT) > 0 || (status & ST_OC_BUILT) > 0) {
        return;
    }
    ArrayList orderByArray = new ArrayList();
    int i, pos;
    int insertAt = 0;
    // by SelectStatement.
    if (constraint != null) {
        i = 0;
        while (i < constraint.stack.size()) {
            ConstraintNode opNode = (ConstraintNode) constraint.stack.get(i);
            if ((opNode instanceof ConstraintOperation) && ((((ConstraintOperation) opNode).operation == ActionDesc.OP_ORDERBY) || (((ConstraintOperation) opNode).operation == ActionDesc.OP_ORDERBY_DESC))) {
                pos = -1;
                if ((i > 1) && (constraint.stack.get(i - 2) instanceof ConstraintValue)) {
                    pos = ((Integer) ((ConstraintValue) constraint.stack.get(i - 2)).getValue()).intValue();
                    constraint.stack.remove(i - 2);
                    i = i - 1;
                }
                if (pos > 0) {
                    insertAt = pos;
                }
                for (int k = orderByArray.size(); k <= insertAt; k++) {
                    orderByArray.add(null);
                }
                if (orderByArray.get(insertAt) == null) {
                    orderByArray.set(insertAt, new ArrayList());
                }
                ConstraintNode fieldNode = (ConstraintNode) constraint.stack.get(i - 1);
                ConstraintFieldDesc consFieldDesc = null;
                if (fieldNode instanceof ConstraintFieldName) {
                    QueryPlan originalPlan = this;
                    if (((ConstraintField) fieldNode).originalPlan != null) {
                        originalPlan = ((ConstraintField) fieldNode).originalPlan;
                    }
                    FieldDesc fieldDesc = originalPlan.config.getField(((ConstraintFieldName) fieldNode).name);
                    if (!(fieldDesc instanceof LocalFieldDesc)) {
                        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
                        "core.generic.notinstanceof", fieldDesc.getClass().getName(), // NOI18N
                        "LocalFieldDesc"));
                    }
                    consFieldDesc = new ConstraintFieldDesc((LocalFieldDesc) fieldDesc, originalPlan, 1);
                } else if (fieldNode instanceof ConstraintFieldDesc) {
                    consFieldDesc = (ConstraintFieldDesc) fieldNode;
                } else {
                    throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
                    "core.generic.notinstanceof", fieldNode.getClass().getName(), // NOI18N
                    "ConstraintFieldName/ConstraintFieldDesc"));
                }
                if (((ConstraintOperation) opNode).operation == ActionDesc.OP_ORDERBY_DESC) {
                    consFieldDesc.ordering = -1;
                }
                // Remember constraint in orderByArray.
                ArrayList temp = (ArrayList) (orderByArray.get(insertAt));
                temp.add(consFieldDesc);
                constraint.stack.remove(i);
                constraint.stack.remove(i - 1);
                i = i - 2 + 1;
            }
            i = i + 1;
        }
    }
    for (int j = 0, size = orderByArray.size(); j < size; j++) {
        ArrayList oa = (ArrayList) orderByArray.get(j);
        if (constraint == null) {
            constraint = new Constraint();
        }
        for (int k = 0, sizeK = oa.size(); k < sizeK; k++) {
            ConstraintFieldDesc ob = (ConstraintFieldDesc) oa.get(k);
            if (ob.ordering < 0) {
                constraint.addField(ob);
                constraint.addOperation(ActionDesc.OP_ORDERBY_DESC);
            } else {
                constraint.addField(ob);
                constraint.addOperation(ActionDesc.OP_ORDERBY);
            }
        }
    }
    status |= ST_OC_BUILT;
}
Also used : JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint(com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)

Example 10 with JDOUserException

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

the class TransactionImpl method rollback.

/**
 * Rollback the transaction represented by this transaction object.
 */
public void rollback() {
    persistenceManager.acquireExclusiveLock();
    try {
        if (txType == CMT || txType == BMT_UT) {
            // Error - should not be called
            throw new JDOUserException(I18NHelper.getMessage(messages, "transaction.transactionimpl.mgd", // NOI18N
            "rollback"));
        }
        this.setTrace();
        if (this.tracing)
            // NOI18N
            this.traceCall("rollback");
        if ((this.status != Status.STATUS_ACTIVE) && (this.status != Status.STATUS_MARKED_ROLLBACK)) {
            throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
            "transaction.transactionimpl.commit_rollback.notactive", // NOI18N
            "rollback", this.statusString(this.status)));
        }
        this.setStatus(Status.STATUS_ROLLING_BACK);
        this.internalRollback();
        this.closeConnection();
        if (txType == BMT_JDO) {
            // Send request to the container:
            try {
                EJBHelper.getLocalTransactionManager().rollback();
            } catch (Exception e) {
                // NOI18N
                throw new JDOException("", e);
            }
        } else {
            // NON_MGD
            // This has effect of rolling back changes also
            // which would not happen in case of BMT_JDO
            // Is this the desired behavior ?
            // TransactionImpl.notifyAfterCompletion()
            // PersistenceManagerImp.afterCompletion()
            // SQLStateManager.rollback()
            this.notifyAfterCompletion();
        }
    } finally {
        persistenceManager.releaseExclusiveLock();
    }
}
Also used : JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) JDOException(com.sun.jdo.api.persistence.support.JDOException) JDOUnsupportedOptionException(com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException) JDODataStoreException(com.sun.jdo.api.persistence.support.JDODataStoreException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) JDOException(com.sun.jdo.api.persistence.support.JDOException)

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