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 });
}
}
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);
}
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 < 0 || index >= size()).
* @exception IllegalArgumentException fromIndex > 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 });
}
}
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;
}
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();
}
}
Aggregations