/** 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(); }
/** 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); }
/** * 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); } }
/** 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())); } } }
/** INTERNAL: Prepare the receiver for execution in a session. */ protected void prepare() { super.prepare(); getQueryMechanism().prepareDeleteObject(); }