commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r7566 - in trunk/gnue-common/src/datasources: . drivers/Base


From: reinhard
Subject: [gnue] r7566 - in trunk/gnue-common/src/datasources: . drivers/Base
Date: Wed, 1 Jun 2005 14:55:02 -0500 (CDT)

Author: reinhard
Date: 2005-06-01 14:55:00 -0500 (Wed, 01 Jun 2005)
New Revision: 7566

Modified:
   trunk/gnue-common/src/datasources/GDataSource.py
   trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
   trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
Log:
Master/detail handling is now completely the responsibility of the master.


Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py    2005-06-01 13:39:16 UTC 
(rev 7565)
+++ trunk/gnue-common/src/datasources/GDataSource.py    2005-06-01 19:55:00 UTC 
(rev 7566)
@@ -555,8 +555,15 @@
 
   def __newResultSet (self, readOnly, masterRecord):
 
+    # Merge the correct foreign key values into the default data dictionary
+    defaultData = self._defaultData.copy ()
+    for (masterfield, detailfield) in zip (
+        self._masterPkFields, self._masterFkFields):
+      defaultData [detailfield] = masterRecord.getField (masterfield)
+
+    # Create the ResultSet instance
     return self.__resultSetClass (
-        defaultData      = self._defaultData,
+        defaultData      = defaultData,
         connection       = self._connection,
         tablename        = self.table,
         rowidField       = self._rowidField,
@@ -565,9 +572,6 @@
         boundFields      = self._fieldReferences.keys (),
         requery          = self.requery,
         readonly         = readOnly,
-        masterRecord     = masterRecord,
-        masterPkFields   = self._masterPkFields,
-        masterFkFields   = self._masterFkFields,
         details          = self.__details,
         dataSource       = self)
 

Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-06-01 
13:39:16 UTC (rev 7565)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-06-01 
19:55:00 UTC (rev 7566)
@@ -47,17 +47,14 @@
   methods are separated so a caller can call the Connection's commit method in
   between.
 
-  If the RecordSet is the detail in a master/detail relationship, it is aware
-  of its master record and makes sure that its foreign key fields are set to
-  the values from the master's primary key fields before inserting a new record
-  into the database backend, even if the master's primary key fields have
-  changed since the RecordSet instance was created (for example, because the
-  master record's primary key was set in an OnInsert database trigger).
-
   If the RecordSet is the master in a master/detail relationship, it is aware
   of all its details. It notifies all its detail L{DataSource} objects whenever
   it becomes the current record, and it posts/requeries all detail
   L{ResultSet} objects after posting/requerying its own data.
+
+  If the RecordSet is the detail in a master/detail relationship, it is not
+  aware of the master. It is the full responsibility of the master to keep its
+  details in sync.
   """
 
   # ---------------------------------------------------------------------------
@@ -75,9 +72,6 @@
       boundFields      = [],
       requery          = True,
       readonly         = False,
-      masterRecord     = None,
-      masterPkFields   = [],
-      masterFkFields   = [],
       details          = {},
       dataSource       = None):
     """
@@ -107,12 +101,6 @@
       something.
     @param readonly: True if the RecordSet is read only. If set, an attempt to
       modify or delete this record raises an exception.
-    @param masterRecord: RecordSet instance of the master of this record, or
-      None if this record has no master.
-    @param masterPkFields: Fields in the master record matching the
-      masterFkFields in this record.
-    @param masterFkFields: Fields in this record matching the masterPkFields
-      of the master record.
     @param details: Dictionary defining all details of this ResultSet, where
       the key is the @L{GDataSource} object and the values are tuples
       containing a list of primary key fields and a list of the corresponding
@@ -128,9 +116,6 @@
     self.__boundFields      = boundFields
     self.__requery          = requery
     self.__readonly         = readonly
-    self.__masterRecord     = masterRecord
-    self.__masterPkFields   = masterPkFields
-    self.__masterFkFields   = masterFkFields
     self.__details          = details
     self.__dataSource       = dataSource
 
@@ -190,10 +175,7 @@
       for (fieldname, value) in defaultData.items ():
         self.__setField (fieldname, value)
 
-      # 5. Link to the master record
-      self.__setMasterLink ()
 
-
   # ---------------------------------------------------------------------------
   # Field access
   # ---------------------------------------------------------------------------
@@ -447,10 +429,6 @@
     if not self.isPending ():
       return
 
-    # Update the link to our master record, in case any key fields were updated
-    # in the master when it was posted.
-    self.__setMasterLink ()
-
     # Save the initial status so we know if any triggers changed us
     status = self.__status
 
@@ -506,8 +484,11 @@
         self.__initialData   = self.__fields.copy ()
 
     # Post all detail records
-    for child in (self.__cachedDetailResultSets.values ()):
-      child.post ()
+    for (dataSource, resultSet) in (self.__cachedDetailResultSets.items ()):
+      fkData = {}
+      for (pkField, fkField) in zip (*self.__details [dataSource]):
+        fkData [fkField] = self.getField (pkField)
+      resultSet.post (fkData = fkData)
 
 
   # ---------------------------------------------------------------------------
@@ -574,17 +555,6 @@
 
 
   # ---------------------------------------------------------------------------
-  # Set the master link
-  # ---------------------------------------------------------------------------
-
-  def __setMasterLink (self):
-
-    if self.__masterRecord is not None:
-      for (pk, fk) in zip (self.__masterPkFields, self.__masterFkFields):
-        self.__setField (fk, self.__masterRecord.getField (pk))
-
-
-  # ---------------------------------------------------------------------------
   # Set a field and mark it as dirty, leaving the record state unchanged
   # ---------------------------------------------------------------------------
 

Modified: trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-06-01 
13:39:16 UTC (rev 7565)
+++ trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-06-01 
19:55:00 UTC (rev 7566)
@@ -49,9 +49,6 @@
       boundFields      = [],
       requery          = True,
       readonly         = False,
-      masterRecord     = None,
-      masterPkFields   = [],
-      masterFkFields   = [],
       details          = {},
       dataSource       = None):
     """
@@ -79,12 +76,6 @@
     @param readonly: True if the ResultSet is read only. If set, an attempt to
       insert, modify or delete any record in this RecordSet raises an
       exception.
-    @param masterRecord: RecordSet instance of the master of this result set,
-      or None if this result set has no master.
-    @param masterPkFields: Fields in the master record matching the
-      masterFkFields in the records of this result set.
-    @param masterFkFields: Fields in the records of this result set matching
-      the masterPkFields of the master record.
     @param details: Dictionary defining all details of this ResultSet, where
       the key is the L{GDataSource} object and the values are tuples
       containing a list of primary key fields and a list of the corresponding
@@ -101,9 +92,6 @@
     self.__boundFields      = boundFields
     self.__requery          = requery
     self.__readonly         = readonly
-    self.__masterRecord     = masterRecord
-    self.__masterPkFields   = masterPkFields
-    self.__masterFkFields   = masterFkFields
     self.__details          = details
     self.__dataSource       = dataSource
 
@@ -218,9 +206,6 @@
         boundFields      = self.__boundFields,
         requery          = self.__requery,
         readonly         = self.__readonly,
-        masterRecord     = self.__masterRecord,
-        masterPkFields   = self.__masterPkFields,
-        masterFkFields   = self.__masterFkFields,
         details          = self.__details,
         dataSource       = self.__dataSource)
 
@@ -517,7 +502,7 @@
   # Post changes to the backend
   # ---------------------------------------------------------------------------
 
-  def post (self):
+  def post (self, fkData = {}):
 
     """
     Post all local changes to the backend.
@@ -545,6 +530,12 @@
       if self._postingRecord.isInserted () or self._postingRecord.isModified 
():
         self.__recordsToRequery.append (self._postingRecord)
 
+      # Set the foreign keys for inserted records in case the master changed
+      # its primary key in a commit trigger
+      if self._postingRecord.isInserted ():
+        for (fieldname, value) in fkData.items ():
+          self._postingRecord.setField (fieldname, value)
+
       if self._postingRecord.isPending ():
         self._postingRecord.post (recordPosition)
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]