[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7564 - in trunk/gnue-common/src/datasources/drivers: Base appser
From: |
reinhard |
Subject: |
[gnue] r7564 - in trunk/gnue-common/src/datasources/drivers: Base appserver/appserver |
Date: |
Wed, 1 Jun 2005 08:30:43 -0500 (CDT) |
Author: reinhard
Date: 2005-06-01 08:30:42 -0500 (Wed, 01 Jun 2005)
New Revision: 7564
Modified:
trunk/gnue-common/src/datasources/drivers/Base/Connection.py
trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
Log:
Changed semantics of Connection.(_)initialize to deliver the default values for
a list of fieldnames, not only for the gnue_id. This makes the code much more
readable and straightforward.
Modified: trunk/gnue-common/src/datasources/drivers/Base/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/Connection.py
2005-06-01 13:06:04 UTC (rev 7563)
+++ trunk/gnue-common/src/datasources/drivers/Base/Connection.py
2005-06-01 13:30:42 UTC (rev 7564)
@@ -127,16 +127,17 @@
# Initialize a new record with default data
# ---------------------------------------------------------------------------
- def initialize (self, table):
+ def initialize (self, table, fields):
"""
Return default values for new records.
@param table: Table name.
+ @param fields: List of field names.
@return: Dictionary with fieldname/value pairs.
"""
gEnter (8)
- return gLeave (8, self._initialize (table))
+ return gLeave (8, self._initialize (table, fields))
# ---------------------------------------------------------------------------
@@ -559,18 +560,22 @@
# ---------------------------------------------------------------------------
- def _initialize (self, table):
+ def _initialize (self, table, fields):
"""
- Return default values for new records (to be implemented by descendants).
+ Return default values for new records (can be overwritten by descendants).
- Database drivers can overwrite this method to return default data that has
- to be included in the _insert newfields dictionary. Appserver uses this to
- get the gnue_id for new records.
+ The basic implementation of this method simply returns a dictionary where
+ every fieldname is assigned a None value.
+ Database drivers can overwrite this method to return default data.
+ The appserver driver uses this to get the gnue_id and the result of the
+ OnInit procedures for new records.
+
@param table: Table name.
+ @param fields: List of field names.
@return: Dictionary with fieldname/value pairs.
"""
- return {}
+ return dict.fromkeys (fields, None)
# ---------------------------------------------------------------------------
Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-06-01
13:06:04 UTC (rev 7563)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-06-01
13:30:42 UTC (rev 7564)
@@ -172,50 +172,25 @@
# 1. mark as new
self.__status = 'empty'
- # 2. Set all fields to None, so that the dictionary at least contains a
- # key for every field
- for field in self.__boundFields:
- self.__fields [field] = None
-
- # 3. Get default values from driver - here the appserver dbdriver
- # requests a new gnue_id and runs OnInit on server side.
- # Note that the fields returned from initialize (i.e. the gnue_id) are
- # considered dirty, this is necessary so the appserver dbdriver
- # includes them in the store call when executing the insert.
- # TODO: Consider this cleaner solution: Connection.initialize takes a
- # second parameter with a field list, does the necessary requery itself,
- # and returns all fields with their new values. All those fields are
- # considered non-dirty and then, simply all primarykeyFields could be set
- # as dirty for new records. If the Base Connection._initialize returns a
- # dictionary with None for every field given, the call to
- # Connection.initialize fully replaces steps 2., 3., and 4. except for
- # the case that self.__connection is None.
+ # 2. Get the default values from the driver
if self.__connection:
- defaults = self.__connection.initialize (self.__tablename)
- for (fieldname, value) in defaults.items ():
- self.__setField (fieldname, value)
+ defaults = self.__connection.initialize (self.__tablename,
+ self.__boundFields)
+ self.__fields.update (defaults)
+ else:
+ self.__fields = dict.fromkeys (self.__boundFields, None)
+ self.__initialData = self.__fields.copy ()
- # 4. Query current data from the backend, if the primary key was
- # initialized above. This is used for appserver to retrieve the
- # result of OnInit.
- # Note that the fields we get from this requery are *not* considered
- # dirty.
- if self.__primarykeyFields:
- primarykeyIsComplete = True
- for fieldname in self.__primarykeyFields:
- if self.__fields [fieldname] is None:
- primarykeyIsComplete = False
- break
- if primarykeyIsComplete:
- self.__initialData = self.__fields.copy ()
- self.__do_requery (self.__boundFields)
+ # 3. Set the primary key fields to dirty, so they will be included in the
+ # insert statement in any case.
+ for fieldname in self.__primarykeyFields:
+ self.__modifiedFlags [fieldname] = True
- # 5. Get default values from DataSource. This has to be done after the
- # requery, as these changes remain local until the first post.
+ # 4. Get default values from DataSource.
for (fieldname, value) in defaultData.items ():
self.__setField (fieldname, value)
- # 6. Link to the master record
+ # 5. Link to the master record
self.__setMasterLink ()
Modified:
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
2005-06-01 13:06:04 UTC (rev 7563)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
2005-06-01 13:30:42 UTC (rev 7564)
@@ -192,9 +192,9 @@
# ---------------------------------------------------------------------------
- def _initialize (self, table):
+ def _initialize (self, table, fields):
id = self._sm.store (self._sess_id, table, [None], [], [[]]) [0]
- return {u'gnue_id': id}
+ return self.requery (table, {u'gnue_id': id}, fields)
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7564 - in trunk/gnue-common/src/datasources/drivers: Base appserver/appserver,
reinhard <=