コード例 #1
0
  public static OptimisticLockException noVersionNumberWhenDeleting(
      Object object, ObjectLevelModifyQuery query) {
    Vector key = new Vector();
    if (query.getSession() != null) {
      key = query.getSession().keyFromObject(object);
    }
    Object[] args = {object, object.getClass().getName(), key, CR};

    OptimisticLockException optimisticLockException =
        new OptimisticLockException(
            ExceptionMessageGenerator.buildMessage(
                OptimisticLockException.class, NO_VERSION_NUMBER_WHEN_DELETING, args),
            query);
    optimisticLockException.setErrorCode(NO_VERSION_NUMBER_WHEN_DELETING);
    return optimisticLockException;
  }
コード例 #2
0
  public static OptimisticLockException objectChangedSinceLastReadWhenUpdating(
      Object object, ObjectLevelModifyQuery query) {
    Vector key = new Vector();
    if (query.getSession() != null) {
      key = query.getSession().keyFromObject(object);
    }
    Object[] args = {object, object.getClass().getName(), key, CR};

    OptimisticLockException optimisticLockException =
        new OptimisticLockException(
            ExceptionMessageGenerator.buildMessage(
                OptimisticLockException.class, OBJECT_CHANGED_SINCE_LAST_READ_WHEN_UPDATING, args),
            query);
    optimisticLockException.setErrorCode(OBJECT_CHANGED_SINCE_LAST_READ_WHEN_UPDATING);
    return optimisticLockException;
  }
コード例 #3
0
 /** INTERNAL: Prepare the receiver for execution in a session. */
 protected void prepare() {
   super.prepare();
   this.usesOptimisticLocking = shouldUseOptimisticLocking(this.object);
   if (this.name == null) {
     this.name = "delete" + this.descriptor.getJavaClass().getSimpleName();
   }
   getQueryMechanism().prepareDeleteObject();
 }
コード例 #4
0
 /** PUBLIC: (REQUIRED) Set the object required for modification. */
 @Override
 public void setObject(Object object) {
   if (isPrepared()) {
     if (this.usesOptimisticLocking != shouldUseOptimisticLocking(object)) {
       setIsPrepared(false);
     }
   }
   super.setObject(object);
 }
コード例 #5
0
  /**
   * Return whether any process leading to object modification should also affect its parts. Used by
   * write, insert, update, and delete.
   */
  protected boolean shouldObjectModifyCascadeToParts(ObjectLevelModifyQuery query) {
    if (isForeignKeyRelationship()) {
      return super.shouldObjectModifyCascadeToParts(query);
    } else {
      if (this.isReadOnly()) {
        return false;
      }

      if (this.isPrivateOwned()) {
        return true;
      }

      return query.shouldCascadeAllParts();
    }
  }
コード例 #6
0
  /**
   * INTERNAL: Prepare the receiver for execution in a session. In particular, verify that the
   * object is not null and contains a valid primary key.
   */
  public void prepareForExecution() throws QueryException {
    super.prepareForExecution();

    // Set the translation row
    if ((this.translationRow == null) || this.translationRow.isEmpty()) {
      if (this.isFullRowRequired) {
        this.translationRow =
            this.descriptor
                .getObjectBuilder()
                .buildRow(this.object, this.session, WriteType.UNDEFINED);
      } else {
        this.translationRow =
            this.descriptor.getObjectBuilder().buildRowForTranslation(this.object, this.session);
      }
    }

    // Add the write lock field if required
    if (this.descriptor.usesOptimisticLocking()) {
      this.descriptor.getOptimisticLockingPolicy().addLockValuesToTranslationRow(this);
    }
  }
コード例 #7
0
  /** INTERNAL: Get a value from the object and set that in the respective field of the row. */
  @Override
  public void writeFromObjectIntoRowForWhereClause(
      ObjectLevelModifyQuery query, AbstractRecord record) {
    if (isReadOnly()) {
      return;
    }
    Object object;
    if (query.isDeleteObjectQuery()) {
      object = query.getObject();
    } else {
      object = query.getBackupClone();
    }
    Object referenceObject = getRealAttributeValueFromObject(object, query.getSession());

    if (referenceObject == null) {
      writeFromNullObjectIntoRow(record);
    } else {
      if (isForeignKeyRelationship()) {
        Enumeration sourceFields = getForeignKeyFields().elements();
        ClassDescriptor descriptor = query.getSession().getDescriptor(referenceObject.getClass());
        while (sourceFields.hasMoreElements()) {
          DatabaseField sourceKey = (DatabaseField) sourceFields.nextElement();
          String targetQueryKey = (String) getSourceToTargetQueryKeyNames().get(sourceKey);
          DatabaseField targetKeyField =
              descriptor.getObjectBuilder().getFieldForQueryKeyName(targetQueryKey);
          if (targetKeyField == null) {
            throw DescriptorException.variableOneToOneMappingIsNotDefinedProperly(
                this, descriptor, targetQueryKey);
          }
          Object referenceValue =
              descriptor
                  .getObjectBuilder()
                  .extractValueFromObjectForField(
                      referenceObject, targetKeyField, query.getSession());
          record.put(sourceKey, referenceValue);
        }
      }
      if (getTypeField() != null) {
        record.put(getTypeField(), getTypeForImplementor(referenceObject.getClass()));
      }
    }
  }
コード例 #8
0
 /** INTERNAL: TopLink exceptions should only be thrown by TopLink. */
 protected OptimisticLockException(String theMessage, ObjectLevelModifyQuery query) {
   super(theMessage);
   this.query = query;
   query.getSession().incrementProfile(SessionProfiler.OptimisticLockException);
 }
コード例 #9
0
  /** INTERNAL: Prepare the receiver for execution in a session. */
  protected void prepare() {
    super.prepare();

    getQueryMechanism().prepareDeleteObject();
  }