commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7772 - trunk/gnue-common/src/datasources/drivers/Base


From: reinhard
Subject: [gnue] r7772 - trunk/gnue-common/src/datasources/drivers/Base
Date: Tue, 2 Aug 2005 12:31:15 -0500 (CDT)

Author: reinhard
Date: 2005-08-02 12:31:13 -0500 (Tue, 02 Aug 2005)
New Revision: 7772

Modified:
   trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
Log:
More logical function order.


Modified: trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-08-02 
03:25:24 UTC (rev 7771)
+++ trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-08-02 
17:31:13 UTC (rev 7772)
@@ -201,110 +201,21 @@
 
 
   # ---------------------------------------------------------------------------
-  # Status information
+  # Get the number of records in the recordset
   # ---------------------------------------------------------------------------
 
-  def isFirstRecord (self):
-    """
-    Return True if the cursor is at the first record.
-    """
-    return (self.__currentRecord == 0)
-
-  # ---------------------------------------------------------------------------
-
-  def isLastRecord (self):
-    """
-    Return True if the cursor is at the last record.
-    """
-    if self.__currentRecord < len (self.__cachedRecords) - 1 or \
-       self.__cacheNextRecord ():
-      return False
-    else:
-      return True
-
-  # ---------------------------------------------------------------------------
-
-  def getRecordNumber (self):
-    """
-    Return the zero-based position of the cursor within the recordset.
-    """
-    return self.__currentRecord
-
-  # ---------------------------------------------------------------------------
-
   def getRecordCount (self):
     """
     Return the number of records currently in the recordset.
     """
+
     if self.__recordCount > 0:
       return self.__recordCount
     else:
       return len (self.__cachedRecords) # Fallback in case record count unknown
 
-  # ---------------------------------------------------------------------------
 
-  def isPending (self):
-    """
-    Return True if the resultset or a detail resultset has uncommitted changes.
-    """
-    for rec in self.__cachedRecords:
-      if rec.isPending ():
-        return True
-    return False
-
-
   # ---------------------------------------------------------------------------
-  # Create a new RecordSet instance
-  # ---------------------------------------------------------------------------
-
-  def __createRecord (self, initialData = {}, defaultData = {},
-      position = None):
-
-    __defaultData = self.__defaultData.copy ()
-    __defaultData.update (defaultData)
-
-    record = RecordSet (
-        initialData      = initialData,
-        defaultData      = __defaultData,
-        connection       = self.__connection,
-        tablename        = self.__tablename,
-        rowidField       = self.__rowidField,
-        primarykeyFields = self.__primarykeyFields,
-        primarykeySeq    = self.__primarykeySeq,
-        boundFields      = self.__boundFields,
-        requery          = self.__requery,
-        readonly         = self.__readonly,
-        details          = self.__details,
-        eventController  = self.__eventController)
-
-    if position is None:
-      self.__cachedRecords.append (record)
-    else:
-      self.__cachedRecords.insert (position, record)
-
-    return record
-
-
-  # ---------------------------------------------------------------------------
-  # Load next record from backend into cache
-  # ---------------------------------------------------------------------------
-
-  def __cacheNextRecord (self):
-
-    if not self.__generator:
-      return False
-
-    try:
-      row = self.__generator.next ()
-    except StopIteration:
-      return False
-
-    record = self.__createRecord (initialData = row)
-
-    return True
-
-
-  # ---------------------------------------------------------------------------
   # Get a specific record (0=based)
   # ---------------------------------------------------------------------------
 
@@ -315,6 +226,7 @@
     @param record: the zero-based position of the record to return.
     @return: the L{RecordSet.RecordSet} instance.
     """
+
     while (record + 1 > len (self.__cachedRecords)) \
         and self.__cacheNextRecord ():
       pass
@@ -389,80 +301,20 @@
 
 
   # ---------------------------------------------------------------------------
-  # Notification of record navigation
-  # ---------------------------------------------------------------------------
-
-  # Sync self.current with self.__currentRecord and adjust detail resultsets 
and
-  # the user interface
-  def __sync (self):
-
-    oldCurrent = self.current
-    if self.__currentRecord == -1:
-      self.current = None
-    else:
-      self.current = self.__cachedRecords [self.__currentRecord]
-
-    # If the current record has *really* changed (this method can be called for
-    # non-changing records after requery or merge) to a new current record,
-    # bring all detail records in sync.
-    if self.current and self.current != oldCurrent:
-      self.current._activate ()
-
-    if self.__eventController is not None:
-      self.__eventController.dispatchEvent ('dsCursorMoved')
-
-
-  # ---------------------------------------------------------------------------
   # Record navigation
   # ---------------------------------------------------------------------------
 
-  # Move to a record number already in cache
-  # -1 sets the current record to None
-  def __move (self, record):
-    if record != self.__currentRecord \
-         or (self.__currentRecord >= 0 \
-             and self.current != self.__cachedRecords [self.__currentRecord]):
-      self.__currentRecord = record
-      self.__sync ()
-
-  # ---------------------------------------------------------------------------
-
-  def setRecord (self, record):
+  def firstRecord (self):
     """
-    Set the cursor to a specific record.
+    Move the cursor to the first record.
 
-    If the number of the record to set the cursor to is greater than the number
-    of records in the resultset, the cursor is not moved.
-
-    @param record: zero-based number of the record to set the cursor to.
     @return: the new current record as a L{RecordSet.RecordSet} instance, or
-      None if the record number to set the cursor to is greater than the number
-      of records in the resultset.
+      None if the resultset is empty.
     """
-    while (record > len (self.__cachedRecords) - 1) \
-        and self.__cacheNextRecord ():
-      pass
-    if record >= len (self.__cachedRecords):
-      return None
-    else:
-      self.__move (record)
-      return self.current
-
-  # ---------------------------------------------------------------------------
-
-  def nextRecord (self):
-    """
-    Move the cursor forward by one record.
-
-    If the cursor already points to the last record, it is not moved.
-
-    @return: the new current record as a L{RecordSet.RecordSet} instance, or
-      None if the cursor already pointed to the last record.
-    """
-    if self.__currentRecord + 1 == len (self.__cachedRecords):
+    if self.__currentRecord < 0:
       if not self.__cacheNextRecord ():
         return None
-    self.__move (self.__currentRecord + 1)
+    self.__move (0)
     return self.current
 
   # ---------------------------------------------------------------------------
@@ -484,17 +336,19 @@
 
   # ---------------------------------------------------------------------------
 
-  def firstRecord (self):
+  def nextRecord (self):
     """
-    Move the cursor to the first record.
+    Move the cursor forward by one record.
 
+    If the cursor already points to the last record, it is not moved.
+
     @return: the new current record as a L{RecordSet.RecordSet} instance, or
-      None if the resultset is empty.
+      None if the cursor already pointed to the last record.
     """
-    if self.__currentRecord < 0:
+    if self.__currentRecord + 1 == len (self.__cachedRecords):
       if not self.__cacheNextRecord ():
         return None
-    self.__move (0)
+    self.__move (self.__currentRecord + 1)
     return self.current
 
   # ---------------------------------------------------------------------------
@@ -514,10 +368,30 @@
       self.__move (len (self.__cachedRecords) - 1)
       return self.current
 
+  # ---------------------------------------------------------------------------
 
+  def setRecord (self, record):
+    """
+    Set the cursor to a specific record.
+
+    If the number of the record to set the cursor to is greater than the number
+    of records in the resultset, the cursor is not moved.
+
+    @param record: zero-based number of the record to set the cursor to.
+    @return: the new current record as a L{RecordSet.RecordSet} instance, or
+      None if the record number to set the cursor to is greater than the number
+      of records in the resultset.
+    """
+    while (record > len (self.__cachedRecords) - 1) \
+        and self.__cacheNextRecord ():
+      pass
+    if record >= len (self.__cachedRecords):
+      return None
+    else:
+      self.__move (record)
+      return self.current
+
   # ---------------------------------------------------------------------------
-  # Find a record by field values
-  # ---------------------------------------------------------------------------
 
   def findRecord (self, fieldValues):
     """
@@ -550,8 +424,45 @@
         return self.current
       i += 1
 
+  # ---------------------------------------------------------------------------
 
+  def __move (self, record):
+    if record != self.__currentRecord \
+         or (self.__currentRecord >= 0 \
+             and self.current != self.__cachedRecords [self.__currentRecord]):
+      self.__currentRecord = record
+      self.__sync ()
+
   # ---------------------------------------------------------------------------
+
+  def isFirstRecord (self):
+    """
+    Return True if the cursor is at the first record.
+    """
+    return (self.__currentRecord == 0)
+
+  # ---------------------------------------------------------------------------
+
+  def isLastRecord (self):
+    """
+    Return True if the cursor is at the last record.
+    """
+    if self.__currentRecord < len (self.__cachedRecords) - 1 or \
+       self.__cacheNextRecord ():
+      return False
+    else:
+      return True
+
+  # ---------------------------------------------------------------------------
+
+  def getRecordNumber (self):
+    """
+    Return the zero-based position of the cursor within the recordset.
+    """
+    return self.__currentRecord
+
+
+  # ---------------------------------------------------------------------------
   # Insert a new record after the current one
   # ---------------------------------------------------------------------------
 
@@ -630,6 +541,20 @@
 
 
   # ---------------------------------------------------------------------------
+  # Find out if there is anything to post
+  # ---------------------------------------------------------------------------
+
+  def isPending (self):
+    """
+    Return True if the resultset or a detail resultset has uncommitted changes.
+    """
+    for rec in self.__cachedRecords:
+      if rec.isPending ():
+        return True
+    return False
+
+
+  # ---------------------------------------------------------------------------
   # Post changes to the backend
   # ---------------------------------------------------------------------------
 
@@ -792,9 +717,83 @@
 
 
   # ---------------------------------------------------------------------------
-  # Remove a record from the list of cached records
+  # Sync self.current with self.__currentRecord and adjust detail resultsets
+  # and the user interface
   # ---------------------------------------------------------------------------
 
+  def __sync (self):
+
+    oldCurrent = self.current
+    if self.__currentRecord == -1:
+      self.current = None
+    else:
+      self.current = self.__cachedRecords [self.__currentRecord]
+
+    # If the current record has *really* changed (this method can be called for
+    # non-changing records after requery or merge) to a new current record,
+    # bring all detail records in sync.
+    if self.current and self.current != oldCurrent:
+      self.current._activate ()
+
+    if self.__eventController is not None:
+      self.__eventController.dispatchEvent ('dsCursorMoved')
+
+
+  # ---------------------------------------------------------------------------
+  # Load next record from backend into cache
+  # ---------------------------------------------------------------------------
+
+  def __cacheNextRecord (self):
+
+    if not self.__generator:
+      return False
+
+    try:
+      row = self.__generator.next ()
+    except StopIteration:
+      return False
+
+    record = self.__createRecord (initialData = row)
+
+    return True
+
+
+  # ---------------------------------------------------------------------------
+  # Create a new record in the cache
+  # ---------------------------------------------------------------------------
+
+  def __createRecord (self, initialData = {}, defaultData = {},
+      position = None):
+
+    __defaultData = self.__defaultData.copy ()
+    __defaultData.update (defaultData)
+
+    record = RecordSet (
+        initialData      = initialData,
+        defaultData      = __defaultData,
+        connection       = self.__connection,
+        tablename        = self.__tablename,
+        rowidField       = self.__rowidField,
+        primarykeyFields = self.__primarykeyFields,
+        primarykeySeq    = self.__primarykeySeq,
+        boundFields      = self.__boundFields,
+        requery          = self.__requery,
+        readonly         = self.__readonly,
+        details          = self.__details,
+        eventController  = self.__eventController)
+
+    if position is None:
+      self.__cachedRecords.append (record)
+    else:
+      self.__cachedRecords.insert (position, record)
+
+    return record
+
+
+  # ---------------------------------------------------------------------------
+  # Remove a record from the cache
+  # ---------------------------------------------------------------------------
+
   def __removeRecord (self, index):
 
     self.__cachedRecords.pop (index)





reply via email to

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