[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5808 - in trunk/gnue-appserver: samples src
From: |
johannes |
Subject: |
r5808 - in trunk/gnue-appserver: samples src |
Date: |
Wed, 12 May 2004 12:09:44 -0500 (CDT) |
Author: johannes
Date: 2004-05-12 12:09:43 -0500 (Wed, 12 May 2004)
New Revision: 5808
Modified:
trunk/gnue-appserver/samples/sample.gfd
trunk/gnue-appserver/src/geasList.py
trunk/gnue-appserver/src/geasSession.py
Log:
Calculated fields are allowed as sort-fields
Modified: trunk/gnue-appserver/samples/sample.gfd
===================================================================
--- trunk/gnue-appserver/samples/sample.gfd 2004-05-12 11:28:43 UTC (rev
5807)
+++ trunk/gnue-appserver/samples/sample.gfd 2004-05-12 17:09:43 UTC (rev
5808)
@@ -3,7 +3,9 @@
<form title="GNUe Application Server test">
<parameter name="von" default="2270-06-20 09:00"/>
<parameter name="bis" default="2270-06-25 20:00"/>
- <datasource name="dtsPerson" connection="appserver" table="address_person">
+ <datasource name="dtsPerson" connection="appserver" table="address_person"
+ order_by="address_nextmeeting,address_zip">
+ <!--
<condition>
<and>
<or>
@@ -40,6 +42,7 @@
</or>
</and>
</condition>
+ -->
</datasource>
<datasource name="dtsCountry" connection="appserver" table="address_country"
cache="250"/>
Modified: trunk/gnue-appserver/src/geasList.py
===================================================================
--- trunk/gnue-appserver/src/geasList.py 2004-05-12 11:28:43 UTC (rev
5807)
+++ trunk/gnue-appserver/src/geasList.py 2004-05-12 17:09:43 UTC (rev
5808)
@@ -35,7 +35,7 @@
# ---------------------------------------------------------------------------
def __init__ (self, session, classdef, connection, recordset, propertylist,
- condition):
+ condition, dsSort, asSort):
self.__session = session
self.__classdef = classdef
self.__connection = connection
@@ -43,35 +43,99 @@
self.__prefetch = propertylist # property names to be prefetched
self.__condition = condition
self.__instances = []
+ self.__unsorted = []
self.__isComplete = False
+ self.__dsSorting = dsSort # sorted by datasource
+ self.__asSorting = asSort # additional sortorder of this list
+ if len (self.__asSorting):
+ self.__fillup = self.__fillupSorted
+ else:
+ self.__fillup = self.__fillupUnsorted
+
# ---------------------------------------------------------------------------
- # fill up the instance-cache with up to count instances
+ # fill up the instance list with up to count instances using sorting/grouping
# ---------------------------------------------------------------------------
- def __fillup (self, count):
+ def __fillupSorted (self, count):
"""
This function fills the internal list of instances with up to count
elements. If @count is 0 all available instances are added to the list.
"""
- if self.__isComplete:
- return
- while len (self.__instances) < count or not count:
- if self.__getInstance (len (self.__instances) == 0) is None:
+ while self.__wantMore (count):
+
+ # if a pending element is available, start with it; otherwise fetch the
+ # next one from the datasource
+ if len (self.__unsorted):
+ current = self.__unsorted.pop ()
+ else:
+ current = self.__getInstance (len (self.__instances) == 0)
+
+ while self.__wantMore (count) and current is not None:
+ group = self.__getGroup (current)
+
+ while current is not None and self.__getGroup (current) == group:
+ self.__unsorted.append (current)
+ current = self.__getInstance (False)
+
+ if len (self.__unsorted) > 1:
+ self.__sortBatch ()
+
+ self.__instances.extend (self.__unsorted)
+
+ # if no more instances are needed at the moment, but there was a valid
+ # element at the end, we hold it as a 'pending but still unsorted' one
+ if not self.__wantMore (count) and current is not None:
+ self.__unsorted = [current]
+ else:
+ self.__unsorted = []
+
+
+ if current is None:
break
# ---------------------------------------------------------------------------
+ # Fill up instance list without any sorting/grouping
+ # ---------------------------------------------------------------------------
+
+ def __fillupUnsorted (self, count):
+ """
+ This function fills up the internal list of instances with up to @count
+ elements.
+ """
+
+ while self.__wantMore (count):
+ current = self.__getInstance (len (self.__instances) == 0)
+ if current is not None:
+ self.__instances.append (current)
+
+
+ # ---------------------------------------------------------------------------
+ # wanna have more instances ?
+ # ---------------------------------------------------------------------------
+
+ def __wantMore (self, count):
+ """
+ This function returns TRUE if more instances are needed to fill up the
+ instance cache with @count elements. If @count is zero, an unlimited amount
+ of instances is accepted.
+ """
+ return not self.__isComplete and \
+ (not count or len (self.__instances) < count)
+
+
+
+ # ---------------------------------------------------------------------------
# Get the next usable instance and add it to the instance list
# ---------------------------------------------------------------------------
def __getInstance (self, fromStart = False):
"""
This function fetches the next usable instance from the recordset according
- to the list's condition. This instance will be added to the internal list
- of instances and returned as the functions result.
+ to the list's condition. This instance will be returned as function result.
"""
if fromStart:
@@ -88,7 +152,6 @@
if not self.__condition.evaluate (instance):
return self.__getInstance ()
- self.__instances.append (instance)
return instance
else:
@@ -96,6 +159,35 @@
# ---------------------------------------------------------------------------
+ # Get a grouping sequence for an instance
+ # ---------------------------------------------------------------------------
+
+ def __getGroup (self, instance):
+ """
+ This function returns a grouping list according to the datasource-sorting.
+ If no such sort order is defined, None is returned.
+ """
+ if len (self.__dsSorting):
+ return instance.get (self.__dsSorting)
+ else:
+ return None
+
+
+ # ---------------------------------------------------------------------------
+ # sort the current batch in __unsorted
+ # ---------------------------------------------------------------------------
+
+ def __sortBatch (self):
+ """
+ This function sorts the unsorted batch according to asSorting.
+ """
+ if len (self.__asSorting):
+ slist = [i.get (self.__asSorting) + [i] for i in self.__unsorted]
+ slist.sort ()
+ self.__unsorted = [item [-1] for item in slist]
+
+
+ # ---------------------------------------------------------------------------
# Get the length of the list (the number of entries)
# ---------------------------------------------------------------------------
@@ -130,3 +222,5 @@
result.append (self.__instances [pos].get (self.__prefetch))
return result
+
+
Modified: trunk/gnue-appserver/src/geasSession.py
===================================================================
--- trunk/gnue-appserver/src/geasSession.py 2004-05-12 11:28:43 UTC (rev
5807)
+++ trunk/gnue-appserver/src/geasSession.py 2004-05-12 17:09:43 UTC (rev
5808)
@@ -126,7 +126,7 @@
# the real (final) propertydef
p = c.properties [elements [-1]]
if skipCalculated and p.isCalculated:
- return
+ return None
# add new field to fieldlist
if add:
@@ -219,14 +219,26 @@
if dsCond is not None:
self.__convertCondition (classdef, dsCond, content)
- sortlist = []
- for p in sortorder:
- sortlist.append (self.__getFieldname (classdef, p, content, False))
+ sortlist = [] # translated sortlist for datasource
+ dsSort = [] # datasource sortlist
+ asSort = [] # appserver sortlist
+ for ix in range (0, len (sortorder)):
+ propName = sortorder [ix]
+ fieldName = self.__getFieldname (classdef, propName, content, False)
- recordset = self.__connection.query (content, dsCond, sortlist)
+ if fieldName is None:
+ asSort = sortorder [ix:]
+ for item in asSort:
+ self.__getFieldname (classdef, item, content, True)
+ break
+ else:
+ sortlist.append (fieldName)
+ dsSort.append (propName)
+ recordset = self.__connection.query (content, dsCond, dsSort)
+
list = geasList.geasList (self, classdef, self.__connection, recordset,
- [u'gnue_id'] + propertylist, asCond)
+ [u'gnue_id'] + propertylist, asCond, dsSort, asSort)
self.__listcount += 1
self.__lists [self.__listcount] = list
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5808 - in trunk/gnue-appserver: samples src,
johannes <=