Package Gnumed :: Package pycommon :: Module gmBusinessDBObject
[frames] | no frames]

Source Code for Module Gnumed.pycommon.gmBusinessDBObject

  1  """GnuMed database object business class. 
  2   
  3  Overview 
  4  -------- 
  5  This class wraps a source relation (table, view) which 
  6  represents an entity that makes immediate business sense 
  7  such as a vaccination or a medical document. In many if 
  8  not most cases this source relation is a denormalizing 
  9  view. The data in that view will in most cases, however, 
 10  originate from several normalized tables. One instance 
 11  of this class represents one row of said source relation. 
 12   
 13  Note, however, that this class does not *always* simply 
 14  wrap a single table or view. It can also encompass several 
 15  relations (views, tables, sequences etc) that taken together 
 16  form an object meaningful to *business* logic. 
 17   
 18  Initialization 
 19  -------------- 
 20  There are two ways to initialize an instance with values. 
 21  One way is to pass a "primary key equivalent" object into 
 22  __init__(). Refetch_payload() will then pull the data from 
 23  the backend. Another way would be to fetch the data outside 
 24  the instance and pass it in via the <row> argument. In that 
 25  case the instance will not initially connect to the databse 
 26  which may offer a great boost to performance. 
 27   
 28  Values API 
 29  ---------- 
 30  Field values are cached for later access. They can be accessed 
 31  by a dictionary API, eg: 
 32   
 33          old_value = object['field'] 
 34          object['field'] = new_value 
 35   
 36  The field names correspond to the respective column names 
 37  in the "main" source relation. Accessing non-existant field 
 38  names will raise an error, so does trying to set fields not 
 39  listed in self.__class__._updatable_fields. To actually 
 40  store updated values in the database one must explicitly 
 41  call save_payload(). 
 42   
 43  The class will in many cases be enhanced by accessors to 
 44  related data that is not directly part of the business 
 45  object itself but are closely related, such as codes 
 46  linked to a clinical narrative entry (eg a diagnosis). Such 
 47  accessors in most cases start with get_*. Related setters 
 48  start with set_*. The values can be accessed via the 
 49  object['field'] syntax, too, but they will be cached 
 50  independantly. 
 51   
 52  Concurrency handling 
 53  -------------------- 
 54  GnuMed connections always run transactions in isolation level 
 55  "serializable". This prevents transactions happening at the 
 56  *very same time* to overwrite each other's data. All but one 
 57  of them will abort with a concurrency error (eg if a 
 58  transaction runs a select-for-update later than another one 
 59  it will hang until the first transaction ends. Then it will 
 60  succeed or fail depending on what the first transaction 
 61  did). This is standard transactional behaviour. 
 62   
 63  However, another transaction may have updated our row 
 64  between the time we first fetched the data and the time we 
 65  start the update transaction. This is noticed by getting the 
 66  XMIN system column for the row when initially fetching the 
 67  data and using that value as a where condition value when 
 68  updating the row later. If the row had been updated (xmin 
 69  changed) or deleted (primary key disappeared) in the 
 70  meantime the update will touch zero rows (as no row with 
 71  both PK and XMIN matching is found) even if the query itself 
 72  syntactically succeeds. 
 73   
 74  When detecting a change in a row due to XMIN being different 
 75  one needs to be careful how to represent that to the user. 
 76  The row may simply have changed but it also might have been 
 77  deleted and a completely new and unrelated row which happens 
 78  to have the same primary key might have been created ! This 
 79  row might relate to a totally different context (eg. patient, 
 80  episode, encounter). 
 81   
 82  One can offer all the data to the user: 
 83   
 84  self.original_payload 
 85  - contains the data at the last successful refetch 
 86   
 87  self.modified_payload 
 88  - contains the modified payload just before the last 
 89    failure of save_payload() - IOW what is currently 
 90    in the database 
 91   
 92  self._payload 
 93  - contains the currently active payload which may or 
 94    may not contain changes 
 95   
 96  For discussion on this see the thread starting at: 
 97   
 98          http://archives.postgresql.org/pgsql-general/2004-10/msg01352.php 
 99   
100  and here 
101   
102          http://groups.google.com/group/pgsql.general/browse_thread/thread/e3566ba76173d0bf/6cf3c243a86d9233 
103          (google for "XMIN semantic at peril") 
104   
105  Problem cases with XMIN: 
106   
107  1) not unlikely 
108  - a very old row is read with XMIN 
109  - vacuum comes along and sets XMIN to FrozenTransactionId 
110    - now XMIN changed but the row actually didn't ! 
111  - an update with "... where xmin = old_xmin ..." fails 
112    although there is no need to fail 
113   
114  2) quite unlikely 
115  - a row is read with XMIN 
116  - a long time passes 
117  - the original XMIN gets frozen to FrozenTransactionId 
118  - another writer comes along and changes the row 
119  - incidentally the exact same old row gets the old XMIN *again* 
120    - now XMIN is (again) the same but the data changed ! 
121  - a later update fails to detect the concurrent change !! 
122   
123  TODO: 
124  The solution is to use our own column for optimistic locking 
125  which gets updated by an AFTER UPDATE trigger. 
126  """ 
127  #============================================================ 
128  # $Source: /cvsroot/gnumed/gnumed/gnumed/client/pycommon/gmBusinessDBObject.py,v $ 
129  # $Id: gmBusinessDBObject.py,v 1.60 2009/12/21 15:02:17 ncq Exp $ 
130  __version__ = "$Revision: 1.60 $" 
131  __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>" 
132  __license__ = "GPL" 
133   
134  import sys, copy, types, inspect, logging 
135   
136   
137  if __name__ == '__main__': 
138          sys.path.insert(0, '../../') 
139  from Gnumed.pycommon import gmExceptions, gmPG2 
140   
141   
142  _log = logging.getLogger('gm.db') 
143  _log.info(__version__) 
144  #============================================================ 
145 -class cBusinessDBObject(object):
146 """Represents business objects in the database. 147 148 Rules: 149 - instances ARE ASSUMED TO EXIST in the database 150 - PK construction (aPK_obj): DOES verify its existence on instantiation 151 (fetching data fails) 152 - Row construction (row): allowed by using a dict of pairs 153 field name: field value (PERFORMANCE improvement) 154 - does NOT verify FK target existence 155 - does NOT create new entries in the database 156 - does NOT lazy-fetch fields on access 157 158 Class scope SQL commands and variables: 159 160 <_cmd_fetch_payload> 161 - must return exactly one row 162 - where clause argument values are expected 163 in self.pk_obj (taken from __init__(aPK_obj)) 164 - must return xmin of all rows that _cmds_store_payload 165 will be updating, so views must support the xmin columns 166 of their underlying tables 167 168 <_cmds_store_payload> 169 - one or multiple "update ... set ... where xmin_* = ..." statements 170 which actually update the database from the data in self._payload, 171 - the last query must refetch the XMIN values needed to detect 172 concurrent updates, their field names had better be the same as 173 in _cmd_fetch_payload 174 175 <_updatable_fields> 176 - a list of fields available for update via object['field'] 177 178 """ 179 #--------------------------------------------------------
180 - def __init__(self, aPK_obj=None, row=None):
181 """Init business object. 182 """ 183 # initialize those "too early" because checking descendants might 184 # fail which will then call __str__ in stack trace logging if --debug 185 # was given which in turn needs those instance variables 186 self.pk_obj = '<uninitialized>' 187 self._idx = {} 188 self._payload = [] # the cache for backend object values (mainly table fields) 189 self._ext_cache = {} # the cache for extended method's results 190 self._is_modified = False 191 192 # check descendants 193 self.__class__._cmd_fetch_payload 194 self.__class__._cmds_store_payload 195 self.__class__._updatable_fields 196 197 if aPK_obj is not None: 198 self.__init_from_pk(aPK_obj=aPK_obj) 199 else: 200 self._init_from_row_data(row=row) 201 202 self._is_modified = False
203 #--------------------------------------------------------
204 - def __init_from_pk(self, aPK_obj=None):
205 """Creates a new clinical item instance by its PK. 206 207 aPK_obj can be: 208 - a simple value 209 * the primary key WHERE condition must be 210 a simple column 211 - a dictionary of values 212 * the primary key where condition must be a 213 subselect consuming the dict and producing 214 the single-value primary key 215 """ 216 self.pk_obj = aPK_obj 217 result = self.refetch_payload() 218 if result is True: 219 self.original_payload = {} 220 for field in self._idx.keys(): 221 self.original_payload[field] = self._payload[self._idx[field]] 222 return True 223 224 if result is False: 225 raise gmExceptions.ConstructorError, "[%s:%s]: error loading instance" % (self.__class__.__name__, self.pk_obj)
226 #--------------------------------------------------------
227 - def _init_from_row_data(self, row=None):
228 """Creates a new clinical item instance given its fields. 229 230 row must be a dict with the fields: 231 - pk_field: the name of the primary key field 232 - idx: a dict mapping field names to position 233 - data: the field values in a list (as returned by 234 cursor.fetchone() in the DB-API) 235 """ 236 try: 237 self._idx = row['idx'] 238 self._payload = row['data'] 239 self.pk_obj = self._payload[self._idx[row['pk_field']]] 240 except: 241 _log.exception('faulty <row> argument structure: %s' % row) 242 raise gmExceptions.ConstructorError, "[%s:??]: error loading instance from row data" % self.__class__.__name__ 243 244 if len(self._idx.keys()) != len(self._payload): 245 _log.critical('field index vs. payload length mismatch: %s field names vs. %s fields' % (len(self._idx.keys()), len(self._payload))) 246 _log.critical('faulty <row> argument structure: %s' % row) 247 raise gmExceptions.ConstructorError, "[%s:??]: error loading instance from row data" % self.__class__.__name__ 248 249 self.original_payload = {} 250 for field in self._idx.keys(): 251 self.original_payload[field] = self._payload[self._idx[field]]
252 #--------------------------------------------------------
253 - def __del__(self):
254 if self.__dict__.has_key('_is_modified'): 255 if self._is_modified: 256 _log.critical('[%s:%s]: loosing payload changes' % (self.__class__.__name__, self.pk_obj)) 257 _log.debug('original: %s' % self.original_payload) 258 _log.debug('modified: %s' % self._payload)
259 #--------------------------------------------------------
260 - def __str__(self):
261 tmp = [] 262 try: 263 for attr in self._idx.keys(): 264 if self._payload[self._idx[attr]] is None: 265 tmp.append(u'%s: NULL' % attr) 266 else: 267 tmp.append('%s: >>%s<<' % (attr, self._payload[self._idx[attr]])) 268 return '[%s:%s]: %s' % (self.__class__.__name__, self.pk_obj, str(tmp)) 269 except: 270 return 'nascent [%s @ %s], cannot show payload and primary key' %(self.__class__.__name__, id(self))
271 #--------------------------------------------------------
272 - def __getitem__(self, attribute):
273 # use try: except: as it is faster and we want this as fast as possible 274 275 # 1) backend payload cache 276 try: 277 return self._payload[self._idx[attribute]] 278 except KeyError: 279 pass 280 281 # 2) extension method results ... 282 getter = getattr(self, 'get_%s' % attribute, None) 283 if not callable(getter): 284 _log.warning('[%s]: no attribute [%s]' % (self.__class__.__name__, attribute)) 285 _log.warning('[%s]: valid attributes: %s' % (self.__class__.__name__, str(self._idx.keys()))) 286 _log.warning('[%s]: no getter method [get_%s]' % (self.__class__.__name__, attribute)) 287 methods = filter(lambda x: x[0].startswith('get_'), inspect.getmembers(self, inspect.ismethod)) 288 _log.warning('[%s]: valid getter methods: %s' % (self.__class__.__name__, str(methods))) 289 raise gmExceptions.NoSuchBusinessObjectAttributeError, '[%s]: cannot access [%s]' % (self.__class__.__name__, attribute) 290 291 self._ext_cache[attribute] = getter() 292 return self._ext_cache[attribute]
293 #--------------------------------------------------------
294 - def __setitem__(self, attribute, value):
295 296 # 1) backend payload cache 297 if attribute in self.__class__._updatable_fields: 298 try: 299 if self._payload[self._idx[attribute]] != value: 300 self._payload[self._idx[attribute]] = value 301 self._is_modified = True 302 return 303 except KeyError: 304 _log.warning('[%s]: cannot set attribute <%s> despite marked settable' % (self.__class__.__name__, attribute)) 305 _log.warning('[%s]: supposedly settable attributes: %s' % (self.__class__.__name__, str(self.__class__._updatable_fields))) 306 raise gmExceptions.NoSuchBusinessObjectAttributeError, '[%s]: cannot access [%s]' % (self.__class__.__name__, attribute) 307 308 # 2) setters providing extensions 309 if hasattr(self, 'set_%s' % attribute): 310 setter = getattr(self, "set_%s" % attribute) 311 if not callable(setter): 312 raise gmExceptions.NoSuchBusinessObjectAttributeError, '[%s] setter [set_%s] not callable' % (self.__class__.__name__, attribute) 313 try: 314 del self._ext_cache[attribute] 315 except KeyError: 316 pass 317 if type(value) is types.TupleType: 318 if setter(*value): 319 self._is_modified = True 320 return 321 raise gmExceptions.BusinessObjectAttributeNotSettableError, '[%s]: setter [%s] failed for [%s]' % (self.__class__.__name__, setter, value) 322 if setter(value): 323 self._is_modified = True 324 return 325 326 # 3) don't know what to do with <attribute> 327 _log.error('[%s]: cannot find attribute <%s> or setter method [set_%s]' % (self.__class__.__name__, attribute, attribute)) 328 _log.warning('[%s]: settable attributes: %s' % (self.__class__.__name__, str(self.__class__._updatable_fields))) 329 methods = filter(lambda x: x[0].startswith('set_'), inspect.getmembers(self, inspect.ismethod)) 330 _log.warning('[%s]: valid setter methods: %s' % (self.__class__.__name__, str(methods))) 331 raise gmExceptions.BusinessObjectAttributeNotSettableError, '[%s]: cannot set [%s]' % (self.__class__.__name__, attribute)
332 #-------------------------------------------------------- 333 # external API 334 #--------------------------------------------------------
335 - def same_payload(self, another_object=None):
336 raise NotImplementedError('comparison between [%s] and [%s] not implemented' % (self, another_object))
337 #--------------------------------------------------------
338 - def is_modified(self):
339 return self._is_modified
340 #--------------------------------------------------------
341 - def get_fields(self):
342 return self._idx.keys()
343 #--------------------------------------------------------
344 - def get_updatable_fields(self):
345 return self.__class__._updatable_fields
346 #--------------------------------------------------------
347 - def get_patient(self):
348 _log.error('[%s:%s]: forgot to override get_patient()' % (self.__class__.__name__, self.pk_obj)) 349 return None
350 #--------------------------------------------------------
351 - def refetch_payload(self, ignore_changes=False):
352 """Fetch field values from backend. 353 """ 354 if self._is_modified: 355 if ignore_changes: 356 _log.critical('[%s:%s]: loosing payload changes' % (self.__class__.__name__, self.pk_obj)) 357 _log.debug('original: %s' % self.original_payload) 358 _log.debug('modified: %s' % self._payload) 359 else: 360 _log.critical('[%s:%s]: cannot reload, payload changed' % (self.__class__.__name__, self.pk_obj)) 361 return False 362 363 if type(self.pk_obj) == types.DictType: 364 arg = self.pk_obj 365 else: 366 arg = [self.pk_obj] 367 rows, self._idx = gmPG2.run_ro_queries ( 368 queries = [{'cmd': self.__class__._cmd_fetch_payload, 'args': arg}], 369 get_col_idx = True 370 ) 371 if len(rows) == 0: 372 _log.error('[%s:%s]: no such instance' % (self.__class__.__name__, self.pk_obj)) 373 return False 374 self._payload = rows[0] 375 return True
376 #--------------------------------------------------------
377 - def __noop(self):
378 pass
379 #--------------------------------------------------------
380 - def save(self, conn=None):
381 return self.save_payload(conn = conn)
382 #--------------------------------------------------------
383 - def save_payload(self, conn=None):
384 """Store updated values (if any) in database. 385 386 Optionally accepts a pre-existing connection 387 - returns a tuple (<True|False>, <data>) 388 - True: success 389 - False: an error occurred 390 * data is (error, message) 391 * for error meanings see gmPG2.run_rw_queries() 392 """ 393 if not self._is_modified: 394 return (True, None) 395 396 args = {} 397 for field in self._idx.keys(): 398 args[field] = self._payload[self._idx[field]] 399 self.modified_payload = args 400 401 close_conn = self.__noop 402 if conn is None: 403 conn = gmPG2.get_connection(readonly=False) 404 close_conn = conn.close 405 406 # query succeeded but failed to find the row to lock 407 # because another transaction committed an UPDATE or 408 # DELETE *before* we attempted to lock it ... 409 # FIXME: this can fail if savepoints are used since subtransactions change the xmin/xmax ... 410 411 queries = [] 412 for query in self.__class__._cmds_store_payload: 413 queries.append({'cmd': query, 'args': args}) 414 rows, idx = gmPG2.run_rw_queries ( 415 link_obj = conn, 416 queries = queries, 417 return_data = True, 418 get_col_idx = True 419 ) 420 421 # update cached XMIN values (should be in first-and-only result row of last query) 422 row = rows[0] 423 for key in idx: 424 try: 425 self._payload[self._idx[key]] = row[idx[key]] 426 except KeyError: 427 conn.rollback() 428 close_conn() 429 _log.error('[%s:%s]: cannot update instance, XMIN refetch key mismatch on [%s]' % (self.__class__.__name__, self.pk_obj, key)) 430 _log.error('payload keys: %s' % str(self._idx)) 431 _log.error('XMIN refetch keys: %s' % str(idx)) 432 _log.error(args) 433 raise 434 435 conn.commit() 436 close_conn() 437 438 self._is_modified = False 439 # update to new "original" payload 440 self.original_payload = {} 441 for field in self._idx.keys(): 442 self.original_payload[field] = self._payload[self._idx[field]] 443 444 return (True, None)
445 #============================================================ 446 if __name__ == '__main__': 447 #--------------------------------------------------------
448 - class cTestObj(cBusinessDBObject):
449 _cmd_fetch_payload = None 450 _cmds_store_payload = None 451 _updatable_fields = [] 452 #----------------------------------------------------
453 - def get_something(self):
454 pass
455 #----------------------------------------------------
456 - def set_something(self):
457 pass
458 #-------------------------------------------------------- 459 if len(sys.argv) > 1 and sys.argv[1] == u'test': 460 461 from Gnumed.pycommon import gmI18N 462 gmI18N.activate_locale() 463 gmI18N.install_domain() 464 465 data = { 466 'pk_field': 'bogus_pk', 467 'idx': {'bogus_pk': 0, 'bogus_field': 1}, 468 'data': [-1, 'bogus_data'] 469 } 470 obj = cTestObj(row=data) 471 #print obj['wrong_field'] 472 obj['wrong_field'] = 1 473 474 #============================================================ 475 # $Log: gmBusinessDBObject.py,v $ 476 # Revision 1.60 2009/12/21 15:02:17 ncq 477 # - fix typo 478 # 479 # Revision 1.59 2009/11/30 15:06:50 ncq 480 # - slightly improved __str__ 481 # 482 # Revision 1.58 2009/11/28 18:27:50 ncq 483 # - cleanup 484 # 485 # Revision 1.57 2009/09/13 18:27:38 ncq 486 # - cleanup 487 # 488 # Revision 1.56 2009/04/13 10:37:41 ncq 489 # - support same_payload 490 # - support save around save_payload 491 # 492 # Revision 1.55 2009/02/18 13:44:32 ncq 493 # - streamline exception handling in __init__ 494 # 495 # Revision 1.54 2009/01/02 11:37:09 ncq 496 # - teach refetch_payload to ignore changes on demand 497 # 498 # Revision 1.53 2008/12/26 22:33:57 ncq 499 # - cleanup 500 # 501 # Revision 1.52 2008/12/25 16:53:18 ncq 502 # - business object base class really should support properties 503 # so make it inherit from object 504 # 505 # Revision 1.51 2008/11/20 18:43:01 ncq 506 # - better logger name 507 # 508 # Revision 1.50 2008/10/22 12:06:48 ncq 509 # - more careful __str__ for early failure 510 # 511 # Revision 1.49 2008/10/12 15:39:49 ncq 512 # - set up instance vars before testing for consts so if we fail they exist 513 # 514 # Revision 1.48 2007/12/12 16:17:15 ncq 515 # - better logger names 516 # 517 # Revision 1.47 2007/12/11 14:17:18 ncq 518 # - use stdlib logging 519 # 520 # Revision 1.46 2007/11/28 13:58:32 ncq 521 # - hide one less exception 522 # 523 # Revision 1.45 2007/10/19 12:49:39 ncq 524 # - much improved XMIN docs, TODO for XMIN removal 525 # 526 # Revision 1.44 2007/10/12 07:26:25 ncq 527 # - somewhat improved docs 528 # 529 # Revision 1.43 2007/08/13 21:55:10 ncq 530 # - fix logging statement 531 # 532 # Revision 1.42 2007/05/21 14:47:22 ncq 533 # - no caching of get_*()ers anymore, but don't deprecate them eiter 534 # 535 # Revision 1.41 2007/05/19 23:12:28 ncq 536 # - cleanup 537 # - remove _subtable support 538 # 539 # Revision 1.40 2006/11/14 23:30:33 ncq 540 # - fix var name 541 # 542 # Revision 1.39 2006/10/31 15:59:47 ncq 543 # - we are dealing with gmPG2 now 544 # 545 # Revision 1.38 2006/10/23 13:22:07 ncq 546 # - no conn pool no more 547 # 548 # Revision 1.37 2006/10/21 20:39:48 ncq 549 # - a bunch of cleanup 550 # 551 # Revision 1.36 2006/10/09 11:42:16 ncq 552 # - in refetch_payload() properly handle scalar vs complex self.pk_obj 553 # 554 # Revision 1.35 2006/10/08 14:26:16 ncq 555 # - convert to use gmPG2 556 # - subtable support may still be suffering fallout 557 # - better docstrings 558 # - drop _cmds_lock_rows_for_update 559 # - must use xmin=... in UPDATE now 560 # - drop self._service 561 # - adjust test suite 562 # 563 # Revision 1.34 2006/07/19 20:27:03 ncq 564 # - gmPyCompat.py is history 565 # 566 # Revision 1.33 2006/06/18 13:20:29 ncq 567 # - cleanup, better logging 568 # 569 # Revision 1.32 2006/06/17 16:41:30 ncq 570 # - only modify self._data if it actually changes 571 # - don't close the connection if it was passed in 572 # 573 # Revision 1.31 2005/11/19 08:47:56 ihaywood 574 # tiny bugfixes 575 # 576 # Revision 1.30 2005/10/19 09:12:00 ncq 577 # - cleanup 578 # 579 # Revision 1.29 2005/10/15 18:17:06 ncq 580 # - error detection in subtable support much improved 581 # 582 # Revision 1.28 2005/10/10 17:40:57 ncq 583 # - slightly enhance Syans fixes on AttributeError 584 # 585 # Revision 1.27 2005/10/08 12:33:08 sjtan 586 # tree can be updated now without refetching entire cache; done by passing emr object to create_xxxx methods and calling emr.update_cache(key,obj);refresh_historical_tree non-destructively checks for changes and removes removed nodes and adds them if cache mismatch. 587 # 588 # Revision 1.26 2005/10/04 11:39:58 sjtan 589 # catch missing attribute error. 590 # 591 # Revision 1.25 2005/06/15 22:26:20 ncq 592 # - CAVEAT regarding XMIN vs. savepoints 593 # 594 # Revision 1.24 2005/05/04 08:54:00 ncq 595 # - improved __setitem__ handling 596 # - add_to_subtable()/del_from_subtable() now set _is_modified appropriately 597 # - some internal renaming for clarification 598 # 599 # Revision 1.23 2005/04/29 15:28:47 ncq 600 # - one fix to del_from_subtable() as approved by Ian 601 # - some internal renaming to clear things up 602 # 603 # Revision 1.22 2005/04/28 21:10:20 ncq 604 # - improved _subtable docs 605 # - avoid confusion: 606 # - add_subtable -> add_to_subtable 607 # - del_subtable -> del_from_subtable 608 # 609 # Revision 1.21 2005/04/18 19:19:15 ncq 610 # - cleanup 611 # 612 # Revision 1.20 2005/04/14 18:58:59 cfmoro 613 # Commented line to avoid hiding _subtables 614 # 615 # Revision 1.19 2005/04/11 17:55:10 ncq 616 # - update self.original_payload in the right places 617 # 618 # Revision 1.18 2005/03/20 16:49:56 ncq 619 # - improve concurrency error handling docs 620 # 621 # Revision 1.17 2005/03/14 14:31:17 ncq 622 # - add support for self.original_payload such that we can make 623 # available all the information to the user when concurrency 624 # conflicts are detected 625 # - init _subtables so child classes don't HAVE to have it 626 # 627 # Revision 1.16 2005/03/06 21:15:13 ihaywood 628 # coment expanded on _subtables 629 # 630 # Revision 1.15 2005/03/06 14:44:02 ncq 631 # - cleanup 632 # 633 # Revision 1.14 2005/03/06 08:17:02 ihaywood 634 # forms: back to the old way, with support for LaTeX tables 635 # 636 # business objects now support generic linked tables, demographics 637 # uses them to the same functionality as before (loading, no saving) 638 # They may have no use outside of demographics, but saves much code already. 639 # 640 # Revision 1.13 2005/02/03 20:20:14 ncq 641 # - really use class level static connection pool 642 # 643 # Revision 1.12 2005/02/01 10:16:07 ihaywood 644 # refactoring of gmDemographicRecord and follow-on changes as discussed. 645 # 646 # gmTopPanel moves to gmHorstSpace 647 # gmRichardSpace added -- example code at present, haven't even run it myself 648 # (waiting on some icon .pngs from Richard) 649 # 650 # Revision 1.11 2005/01/31 12:56:55 ncq 651 # - properly update xmin in save_payload() 652 # 653 # Revision 1.10 2005/01/31 06:25:35 ncq 654 # - brown paper bag bug, I wonder how it ever worked: 655 # connections are gotten from an instance of the pool 656 # 657 # Revision 1.9 2005/01/19 06:52:24 ncq 658 # - improved docstring 659 # 660 # Revision 1.8 2005/01/02 19:58:02 ncq 661 # - remove _xmins_refetch_col_pos 662 # 663 # Revision 1.7 2005/01/02 16:16:52 ncq 664 # - by Ian: improve XMIN update on save by using new commit() get_col_idx 665 # 666 # Revision 1.6 2004/12/20 16:46:55 ncq 667 # - improve docs 668 # - close last known concurrency issue (reget xmin values after save) 669 # 670 # Revision 1.5 2004/12/17 16:15:36 ncq 671 # - add extension method result caching as suggested by Ian 672 # - I maintain a bad feeling due to cache eviction policy being murky at best 673 # 674 # Revision 1.4 2004/11/03 22:30:35 ncq 675 # - improved docs 676 # - introduce class level SQL query _cmds_lock_rows_for_update 677 # - rewrite save_payload() to use that via gmPG.run_commit2() 678 # - report concurrency errors from save_payload() 679 # 680 # Revision 1.3 2004/10/27 12:13:37 ncq 681 # - __init_from_row_data -> _init_from_row_data so we can override it 682 # - more sanity checks 683 # 684 # Revision 1.2 2004/10/12 18:37:45 ncq 685 # - Carlos added passing in possibly bulk-fetched row data w/o 686 # touching the database in __init__() 687 # - note that some higher level things will be broken until all 688 # affected child classes are fixed 689 # - however, note that child classes that don't overload __init__() 690 # are NOT affected and support no-DB init transparently 691 # - changed docs accordingly 692 # - this is the initial bulk-loader work that is hoped to gain 693 # quite some performance in some areas (think lab results) 694 # 695 # Revision 1.1 2004/10/11 19:05:41 ncq 696 # - business object-in-db root class, used by cClinItem etc. 697 # 698 # Revision 1.17 2004/06/18 13:31:21 ncq 699 # - return False from save_payload on failure to update 700 # 701 # Revision 1.16 2004/06/02 21:50:32 ncq 702 # - much improved error logging in set/getitem() 703 # 704 # Revision 1.15 2004/06/02 12:51:47 ncq 705 # - add exceptions tailored to cClinItem __set/getitem__() 706 # errors as per Syan's suggestion 707 # 708 # Revision 1.14 2004/05/22 08:09:10 ncq 709 # - more in line w/ coding style 710 # - _service will never change (or else it wouldn't 711 # be cCLINitem) but it's still good coding practice 712 # to put it into a class attribute 713 # 714 # Revision 1.13 2004/05/21 15:36:51 sjtan 715 # 716 # moved 'historica' into the class attribute SERVICE , in case gmClinItem can 717 # be reused in other services. 718 # 719 # Revision 1.12 2004/05/12 14:28:53 ncq 720 # - allow dict style pk definition in __init__ for multicolum primary keys (think views) 721 # - self.pk -> self.pk_obj 722 # - __init__(aPKey) -> __init__(aPK_obj) 723 # 724 # Revision 1.11 2004/05/08 22:13:11 ncq 725 # - cleanup 726 # 727 # Revision 1.10 2004/05/08 17:27:21 ncq 728 # - speed up __del__ 729 # - use NoSuchClinItemError 730 # 731 # Revision 1.9 2004/04/20 13:32:33 ncq 732 # - improved __str__ output 733 # 734 # Revision 1.8 2004/04/19 12:41:30 ncq 735 # - self-check in __del__ 736 # 737 # Revision 1.7 2004/04/18 18:50:36 ncq 738 # - override __init__() thusly removing the unholy _pre/post_init() business 739 # 740 # Revision 1.6 2004/04/18 17:51:28 ncq 741 # - it's surely helpful to be able to say <item>.is_modified() and know the status... 742 # 743 # Revision 1.5 2004/04/16 12:46:35 ncq 744 # - set is_modified=False after save_payload 745 # 746 # Revision 1.4 2004/04/16 00:00:59 ncq 747 # - Carlos fixes 748 # - save_payload should now work 749 # 750 # Revision 1.3 2004/04/12 22:53:19 ncq 751 # - __init__ now handles arbitrary keyword args 752 # - _pre_/_post_init() 753 # - streamline 754 # - must do _payload[self._idx[attribute]] since payload not a dict 755 # 756 # Revision 1.2 2004/04/11 11:24:00 ncq 757 # - handle _is_modified 758 # - protect against reload if modified 759 # 760 # Revision 1.1 2004/04/11 10:16:53 ncq 761 # - first version 762 # 763