[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7568 - trunk/gnue-common/src/datasources/drivers/Base
From: |
reinhard |
Subject: |
[gnue] r7568 - trunk/gnue-common/src/datasources/drivers/Base |
Date: |
Wed, 1 Jun 2005 16:42:48 -0500 (CDT) |
Author: reinhard
Date: 2005-06-01 16:42:47 -0500 (Wed, 01 Jun 2005)
New Revision: 7568
Modified:
trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
Log:
Some minor code cleanup.
Modified: trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-06-01
21:18:12 UTC (rev 7567)
+++ trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-06-01
21:42:47 UTC (rev 7568)
@@ -95,13 +95,18 @@
self.__details = details
self.__dataSource = dataSource
- self.__staticData = [] # Data for static datasources
+ # Data for static datasources
+ self.__staticData = []
- self._cachedRecords = []
- self._currentRecord = -1
- self._recordCount = 0
- self._postingRecord = None
+ # List of all RecordSet objects cached in this ResultSet
+ self.__cachedRecords = []
+ # Index of the current record
+ self.__currentRecord = -1
+
+ # Number of records
+ self.__recordCount = 0
+
# Objects to get informed about record navigation events
self.__listeners = []
@@ -135,7 +140,7 @@
self.__generator = self._fetch (cache)
# (TODO: could be delayed to first call of getRecordCount)
- self._recordCount = self._count ()
+ self.__recordCount = self._count ()
# ---------------------------------------------------------------------------
@@ -143,13 +148,13 @@
# ---------------------------------------------------------------------------
def isFirstRecord (self):
- return (self._currentRecord == 0)
+ return (self.__currentRecord == 0)
# ---------------------------------------------------------------------------
def isLastRecord (self):
- if self._currentRecord < len(self._cachedRecords) - 1 or \
- self.__cacheNextRecord():
+ if self.__currentRecord < len (self.__cachedRecords) - 1 or \
+ self.__cacheNextRecord ():
return False
else:
return True
@@ -158,23 +163,21 @@
# returns -1=No records in memory, #=Current record #
def getRecordNumber (self):
- return self._currentRecord
+ return self.__currentRecord
# ---------------------------------------------------------------------------
- def getCacheCount (self):
- return len (self._cachedRecords)
-
- # ---------------------------------------------------------------------------
-
def getRecordCount (self):
- return self._recordCount > 0 and self._recordCount or self.getCacheCount()
+ if self.__recordCount > 0:
+ return self.__recordCount
+ else:
+ return len (self.__cachedRecords) # Fallback in case record count unknown
# ---------------------------------------------------------------------------
# Returns True if the resultset or a detail resultset has uncommitted changes
- def isPending(self):
- for rec in (self._cachedRecords):
+ def isPending (self):
+ for rec in (self.__cachedRecords):
if rec.isPending ():
return True
return False
@@ -182,8 +185,8 @@
# ---------------------------------------------------------------------------
# Returns True if the current record has uncommitted changes
- def isRecordPending(self):
- return self.current.isPending()
+ def isRecordPending (self):
+ return self.current.isPending ()
# ---------------------------------------------------------------------------
# Create a new RecordSet instance
@@ -210,9 +213,9 @@
dataSource = self.__dataSource)
if position is None:
- self._cachedRecords.append (record)
+ self.__cachedRecords.append (record)
else:
- self._cachedRecords.insert (position, record)
+ self.__cachedRecords.insert (position, record)
return record
@@ -241,13 +244,14 @@
# ---------------------------------------------------------------------------
def getRecord (self, record):
- while (record + 1 > len (self._cachedRecords)) and self.__cacheNextRecord
():
+ while (record + 1 > len (self.__cachedRecords)) \
+ and self.__cacheNextRecord ():
pass
- if record + 1 > len (self._cachedRecords):
+ if record + 1 > len (self.__cachedRecords):
return None
else:
- return self._cachedRecords [record]
+ return self.__cachedRecords [record]
# ---------------------------------------------------------------------------
@@ -261,12 +265,12 @@
"""
# First, load all records into the cache
- while self.__cacheNextRecord():
+ while self.__cacheNextRecord ():
pass
# Now build up the array
result = []
- for record in self._cachedRecords:
+ for record in self.__cachedRecords:
line = []
for field in fields:
line.append (record [field])
@@ -285,12 +289,12 @@
"""
# First, load all records into the cache
- while self.__cacheNextRecord():
+ while self.__cacheNextRecord ():
pass
# Now build up the array
result = {}
- for record in self._cachedRecords:
+ for record in self.__cachedRecords:
d = result
for field in keyfields:
d = d.setdefault (record [field], {})
@@ -310,20 +314,20 @@
self.__listeners.append (listener)
# Inform new listener about current record. This happens whenever the
# *Resultset* (not the current record but the whole resultset) changes.
- if self._currentRecord >= 0:
+ if self.__currentRecord >= 0:
listener.currentRecordMoved ()
# ---------------------------------------------------------------------------
- # Sync self.current with self._currentRecord and adjust detail resultsets and
+ # Sync self.current with self.__currentRecord and adjust detail resultsets
and
# the user interface
def __sync (self):
oldCurrent = self.current
- if self._currentRecord == -1:
+ if self.__currentRecord == -1:
self.current = None
else:
- self.current = self._cachedRecords [self._currentRecord]
+ 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,
@@ -342,18 +346,19 @@
# 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
+ if record != self.__currentRecord \
+ or (self.__currentRecord >= 0 \
+ and self.current != self.__cachedRecords [self.__currentRecord]):
+ self.__currentRecord = record
self.__sync ()
# ---------------------------------------------------------------------------
def setRecord (self, record):
- while (record > len(self._cachedRecords) -1) and self.__cacheNextRecord():
+ while (record > len (self.__cachedRecords) - 1) \
+ and self.__cacheNextRecord ():
pass
- if record >= len(self._cachedRecords):
+ if record >= len (self.__cachedRecords):
return None
else:
self.__move (record)
@@ -362,39 +367,39 @@
# ---------------------------------------------------------------------------
def nextRecord (self):
- if self._currentRecord + 1 == len (self._cachedRecords):
+ if self.__currentRecord + 1 == len (self.__cachedRecords):
if not self.__cacheNextRecord ():
return None
- self.__move (self._currentRecord + 1)
+ self.__move (self.__currentRecord + 1)
return self.current
# ---------------------------------------------------------------------------
def prevRecord (self):
- if self._currentRecord < 1:
+ if self.__currentRecord < 1:
return None
else:
- self.__move (self._currentRecord - 1)
+ self.__move (self.__currentRecord - 1)
return self.current
# ---------------------------------------------------------------------------
def firstRecord (self):
- if self._currentRecord < 0:
- if not self.__cacheNextRecord():
+ if self.__currentRecord < 0:
+ if not self.__cacheNextRecord ():
return None
self.__move (0)
return self.current
# ---------------------------------------------------------------------------
- def lastRecord(self):
- if self._currentRecord == -1:
+ def lastRecord (self):
+ if self.__currentRecord == -1:
return None
else:
- while self.__cacheNextRecord():
+ while self.__cacheNextRecord ():
pass
- self.__move (len (self._cachedRecords) - 1)
+ self.__move (len (self.__cachedRecords) - 1)
return self.current
@@ -411,12 +416,12 @@
"""
# Make sure that all records are cached
- while self.__cacheNextRecord():
+ while self.__cacheNextRecord ():
pass
# Find match
- for i in range (len (self._cachedRecords)):
- record = self._cachedRecords [i]
+ for i in range (len (self.__cachedRecords)):
+ record = self.__cachedRecords [i]
found = True
for (key, value) in fieldValues.items ():
if record [key] != value:
@@ -442,10 +447,10 @@
gDebug (8, 'Inserting a blank record in %s' % self)
- self._recordCount += 1
- self._currentRecord += 1
+ self.__recordCount += 1
+ self.__currentRecord += 1
record = self.__createRecord (defaultData = defaultData,
- position = self._currentRecord)
+ position = self.__currentRecord)
self.__sync ()
return record
@@ -454,9 +459,9 @@
# Create a new record with a copy of the existing one
# ---------------------------------------------------------------------------
- def duplicateRecord(self, exclude=(), include=()):
+ def duplicateRecord (self, exclude = (), include = ()):
current = self.current
- inserted = self.insertRecord()
+ inserted = self.insertRecord ()
if not inserted:
return None
@@ -493,7 +498,7 @@
# TODO: What's this??
# ---------------------------------------------------------------------------
- def getPostingRecordset(self):
+ def getPostingRecordset (self):
global postingRecordset
return postingRecordset
@@ -513,13 +518,14 @@
"""
global postingRecordset
+
# post our changes
recordPosition = 0
- while recordPosition < len(self._cachedRecords):
- self._postingRecord = self._cachedRecords[recordPosition]
- postingRecordset = self._postingRecord
+ while recordPosition < len (self.__cachedRecords):
+ record = self.__cachedRecords [recordPosition]
+ postingRecordset = record
- if (self._postingRecord.isEmpty () or self._postingRecord.isDeleted ()) \
+ if (record.isEmpty () or record.isDeleted ()) \
and self.__connection is not None:
# Adjust the current record if a preceding record or the current record
# is deleted
@@ -527,25 +533,25 @@
else:
recordPosition += 1
- if self._postingRecord.isInserted () or self._postingRecord.isModified
():
- self.__recordsToRequery.append (self._postingRecord)
+ if record.isInserted () or record.isModified ():
+ self.__recordsToRequery.append (record)
# Set the foreign keys for inserted records in case the master changed
# its primary key in a commit trigger
- if self._postingRecord.isInserted ():
+ if record.isInserted ():
for (fieldname, value) in fkData.items ():
- self._postingRecord [fieldname] = value
+ record [fieldname] = value
- if self._postingRecord.isPending ():
- self._postingRecord._post (recordPosition)
+ if record.isPending ():
+ record._post (recordPosition)
# Move to record 0 if all preceding records were deleted
# (or set to -1 if all records were deleted)
- if self._currentRecord < 0:
- if len(self._cachedRecords):
- self._currentRecord = 0
+ if self.__currentRecord < 0:
+ if len(self.__cachedRecords):
+ self.__currentRecord = 0
else:
- self._currentRecord = -1
+ self.__currentRecord = -1
# ---------------------------------------------------------------------------
@@ -596,7 +602,7 @@
newData = otherResultSet.getDictArray (keyFields, self.__boundFields)
- for (index, record) in enumerate (self._cachedRecords [:]):
+ for (index, record) in enumerate (self.__cachedRecords [:]):
if record.isEmpty ():
# keep empty record in old ResultSet
continue
@@ -632,11 +638,11 @@
# Move to record 0 if all preceding records were deleted
# (or set to -1 if all records were deleted)
- if self._currentRecord < 0:
- if len (self._cachedRecords):
- self._currentRecord = 0
+ if self.__currentRecord < 0:
+ if len (self.__cachedRecords):
+ self.__currentRecord = 0
else:
- self._currentRecord = -1
+ self.__currentRecord = -1
# We are completely up to date now.
self.__recordsToRequery = []
@@ -661,10 +667,10 @@
def __removeRecord (self, index):
- self._cachedRecords.pop (index)
- self._recordCount -= 1
- if index <= self._currentRecord:
- self._currentRecord -= 1
+ self.__cachedRecords.pop (index)
+ self.__recordCount -= 1
+ if index <= self.__currentRecord:
+ self.__currentRecord -= 1
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7568 - trunk/gnue-common/src/datasources/drivers/Base,
reinhard <=