Example #1
0
 public function __construct($object_model, $do, $old_values)
 {
     $this->object_model = $object_model;
     $this->do = $do;
     $type = SDO_DAS_Relational_DataObjectHelper::getApplicationType($do);
     $old_values_of_any_changed_properties = SDO_DAS_Relational_SettingListHelper::getSettingsAsArray($old_values);
     foreach ($this->do as $prop => $value) {
         if ($this->object_model->isContainmentReferenceProperty($type, $prop)) {
             // We ignore containment references - any changes to them appear elsewhere in the C/S
             continue;
         }
         if (array_key_exists($prop, $old_values_of_any_changed_properties)) {
             $this->settings_for_where_clause[$prop] = $old_values_of_any_changed_properties[$prop];
         } else {
             $this->settings_for_where_clause[$prop] = $value;
         }
     }
     if (count($this->settings_for_where_clause) > 0) {
         $this->convertNonContainmentReferencesFromObjectToPK();
         $this->stmt = $this->toSQL($this->settings_for_where_clause);
         $this->value_list = $this->buildValueList();
     }
     if (SDO_DAS_Relational::DEBUG_BUILD_PLAN) {
         echo "adding update to plan for type {$type}\n";
     }
 }
Example #2
0
 public function computeSettingsForSetAndWhereClauses($object_model, $do, $old_values)
 {
     $old_values_of_any_changed_properties = SDO_DAS_Relational_SettingListHelper::getSettingsAsArray($old_values);
     // iterate through data object and examine the primitive properties and non-containment references
     // 1a. if there is an old value, and it differs from new value, then save the current value for the SET clause and the old value for the WHERE clause
     // 1b. if there is an old value, but happens to be the same as the new value, ignore it - rare case
     // 2. if there is no old value it has not changed so save the current value for the WHERE clause
     // Properties that have been unset will not be seen when we iterate with foreach but that's OK, because:
     //   - we assign no meaning to unsetting a primitive or non-containment reference, so ignore it
     //   - unsetting a containment reference results in a delete appearing elsewhere in the change summary
     $type = SDO_DAS_Relational_DataObjectHelper::getApplicationType($do);
     foreach ($this->do as $prop => $value) {
         if ($this->object_model->isContainmentReferenceProperty($type, $prop)) {
             // We ignore containment references - updates to them will appear as creates or deletes elsewhere in the C/S
             continue;
         }
         if (array_key_exists($prop, $old_values_of_any_changed_properties)) {
             $old = $old_values_of_any_changed_properties[$prop];
             $new = $this->do[$prop];
             if ($new === $old) {
                 // it appeared to change but old === new so use whichever one you like for WHERE clause
                 $this->settings_for_where_clause[$prop] = $old;
             } else {
                 // this is more likely - it did change
                 $this->settings_for_set_clause[$prop] = $new;
                 $this->settings_for_where_clause[$prop] = $old;
             }
         } else {
             $this->settings_for_where_clause[$prop] = $do[$prop];
         }
     }
 }