387 # revert changes on in memory schema |
387 # revert changes on in memory schema |
388 self.rschema.__dict__.update(self.oldvalues) |
388 self.rschema.__dict__.update(self.oldvalues) |
389 # XXX revert changes on database |
389 # XXX revert changes on database |
390 |
390 |
391 |
391 |
|
392 class CWComputedRTypeUpdateOp(MemSchemaOperation): |
|
393 """actually update some properties of a computed relation definition""" |
|
394 rschema = entity = rule = None # make pylint happy |
|
395 old_rule = None |
|
396 |
|
397 def precommit_event(self): |
|
398 # update the in-memory schema first |
|
399 self.old_rule = self.rschema.rule |
|
400 self.rschema.rule = self.rule |
|
401 |
|
402 def revertprecommit_event(self): |
|
403 # revert changes on in memory schema |
|
404 self.rschema.rule = self.old_rule |
|
405 |
|
406 |
392 class CWAttributeAddOp(MemSchemaOperation): |
407 class CWAttributeAddOp(MemSchemaOperation): |
393 """an attribute relation (CWAttribute) has been added: |
408 """an attribute relation (CWAttribute) has been added: |
394 * add the necessary column |
409 * add the necessary column |
395 * set default on this column if any and possible |
410 * set default on this column if any and possible |
396 * register an operation to add the relation definition to the |
411 * register an operation to add the relation definition to the |
1044 rschema = self._cw.vreg.schema.rschema(entity.name) |
1059 rschema = self._cw.vreg.schema.rschema(entity.name) |
1045 CWRTypeUpdateOp(self._cw, rschema=rschema, entity=entity, |
1060 CWRTypeUpdateOp(self._cw, rschema=rschema, entity=entity, |
1046 values=newvalues) |
1061 values=newvalues) |
1047 |
1062 |
1048 |
1063 |
|
1064 class BeforeUpdateCWComputedRTypeHook(SyncSchemaHook): |
|
1065 """check name change, handle final""" |
|
1066 __regid__ = 'syncupdatecwcomputedrtype' |
|
1067 __select__ = SyncSchemaHook.__select__ & is_instance('CWComputedRType') |
|
1068 events = ('before_update_entity',) |
|
1069 |
|
1070 def __call__(self): |
|
1071 entity = self.entity |
|
1072 check_valid_changes(self._cw, entity) |
|
1073 if 'rule' in entity.cw_edited: |
|
1074 old, new = entity.cw_edited.oldnewvalue('rule') |
|
1075 if old != new: |
|
1076 rschema = self._cw.vreg.schema.rschema(entity.name) |
|
1077 CWComputedRTypeUpdateOp(self._cw, rschema=rschema, |
|
1078 entity=entity, rule=new) |
|
1079 |
|
1080 |
1049 class AfterDelRelationTypeHook(SyncSchemaHook): |
1081 class AfterDelRelationTypeHook(SyncSchemaHook): |
1050 """before deleting a CWAttribute or CWRelation entity: |
1082 """before deleting a CWAttribute or CWRelation entity: |
1051 * if this is a final or inlined relation definition, instantiate an |
1083 * if this is a final or inlined relation definition, instantiate an |
1052 operation to drop necessary column, else if this is the last instance |
1084 operation to drop necessary column, else if this is the last instance |
1053 of a non final relation, instantiate an operation to drop necessary |
1085 of a non final relation, instantiate an operation to drop necessary |