/[gnue]/gnue-appserver/src/geasList.py
ViewVC logotype

Diff of /gnue-appserver/src/geasList.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28 by reinhard, Mon Sep 1 18:24:15 2003 UTC revision 1.29 by reinhard, Mon Sep 1 20:11:37 2003 UTC
# Line 35  class geasList: Line 35  class geasList:
35    # Initalize    # Initalize
36    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
37    
38    def __init__ (self, session, classdef):    def __init__ (self, session, classdef, propertylist, sortorder):
39      self._session = session      self._session = session
40      self._classdef = classdef      self._classdef = classdef
41      self._prefetch = []         # property names to be prefetched      self._prefetch = propertylist       # property names to be prefetched
42      self._conditions = []       # conditions using property names      self._sort = sortorder              # property names of the sort key
     self._sort = []             # property names to be used as sort key  
     self._prefColumns = []      # (db) column names to be prefetched  
     self._sortColumns = []      # (db) column names to be used as sort key  
43    
44    # ---------------------------------------------------------------------------      self._prefColumns = []              # (db) column names to be prefetched
45    # Actually these 3 only set variables      self._sortColumns = []              # (db) column names of the sort key
   # ---------------------------------------------------------------------------  
46    
   def setPrefetch (self, prefetch):  
     self._prefetch = prefetch  
47      # test if all properties in prefetch list are valid and find column names      # test if all properties in prefetch list are valid and find column names
     self._prefColumns = []  
48      for propertyname in self._prefetch:      for propertyname in self._prefetch:
49        propertydef = self._classdef.properties [propertyname]        propertydef = self._classdef.properties [propertyname]
50        self._prefColumns.append (propertydef.column)        self._prefColumns.append (propertydef.column)
51    
   # conditions = a list consisting of condition elements written down in  
   # prefix notation i.e. (a=12) AND (c=121) -> AND = a 12 = c 121  
   # every element of the list is a tuple containing the following parts:  
   # type (eq,and,const...)  value  i.e. ('eq','') or ('const',12)  
   
   def setConditions (self, conditions):  
     self._conditions = conditions  
     # TODO: translate property names to column names  
     # now building GCondition tree  
     self._conditionTree = GConditions.buildTreeFromPrefix (conditions)  
   
   def setSort (self, sort):  
     self._sort = sort  
52      # test if all properties in sort list are valid and find column names      # test if all properties in sort list are valid and find column names
53      for propertyname in self._sort:      for propertyname in self._sort:
54        propertydef = self._classdef.properties [propertyname]        propertydef = self._classdef.properties [propertyname]
55        self._sortColumns.append (propertydef.column)        self._sortColumns.append (propertydef.column)
56    
57    # ---------------------------------------------------------------------------      # prepare attributes of the datasource
   # Populate the list with data from the database backend  
   # ---------------------------------------------------------------------------  
   
   def populate (self):  
58      attributes = {}      attributes = {}
59      attributes ["name"]     = ""      attributes ["name"]     = ""
60      attributes ["database"] = self._session.database      attributes ["database"] = self._session.database
# Line 86  class geasList: Line 62  class geasList:
62      if self._sortColumns != []:      if self._sortColumns != []:
63        attributes ["order_by"] = string.joinfields (self._sortColumns, ",")        attributes ["order_by"] = string.joinfields (self._sortColumns, ",")
64    
65        # create the datasource
66      self._datasource = GDataSource.DataSourceWrapper (      self._datasource = GDataSource.DataSourceWrapper (
67        connections = self._session.connections,        connections = self._session.connections,
68        attributes = attributes,        attributes = attributes,
69        fields = self._prefColumns)        fields = self._prefColumns)
70    
71      self._resultset = self._datasource.createResultSet (self._conditionTree)    # ---------------------------------------------------------------------------
72      # Populate the list with data from the database backend
73      # ---------------------------------------------------------------------------
74      # conditions = a list consisting of condition elements written down in
75      # prefix notation i.e. (a=12) AND (c=121) -> AND = a 12 = c 121
76      # every element of the list is a tuple containing the following parts:
77      # type (eq,and,const...)  value  i.e. ('eq','') or ('const',12)
78      # ---------------------------------------------------------------------------
79    
80      def populate (self, conditions):
81        # TODO: translate property names to column names in conditions
82        # now building GCondition tree
83        conditionTree = GConditions.buildTreeFromPrefix (conditions)
84        self._resultset = self._datasource.createResultSet (conditionTree)
85    
86      # ---------------------------------------------------------------------------
87      # Populate the list with a single instance with given gnue_id, and return
88      # that instance
89      # ---------------------------------------------------------------------------
90    
91      def find (self, object_id):
92        self.populate ([['eq', ''], ['field', 'gnue_id'], ['const', object_id]])
93        return self.firstInstance ()
94    
95      # ---------------------------------------------------------------------------
96      # Populate the list with a single empty instance, and return that instance
97      # ---------------------------------------------------------------------------
98    
99      def newInstance (self):
100        self._resultset = self._datasource.createEmptyResultSet ()
101        self._resultset.insertRecord ()
102        return geasInstance.geasInstance (self, self._resultset.current,
103                                          self._classdef)
104    
105    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
106    # Get the first instance in the list    # Get the first instance in the list
# Line 116  class geasList: Line 125  class geasList:
125        return None        return None
126    
127    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
128    # get the length of the list (the number of entries)    # Get the length of the list (the number of entries)
129    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
130    
131    def count (self):    def count (self):
# Line 139  class geasList: Line 148  class geasList:
148        c += 1        c += 1
149        instance = self.nextInstance ()        instance = self.nextInstance ()
150      return result      return result
   
   # ---------------------------------------------------------------------------  
   # insert a new empty instance in the list and return it  
   # ---------------------------------------------------------------------------  
   
   def insertNewInstance (self):  
     self._resultset.insertRecord ()  
     return geasInstance.geasInstance (self, self._resultset.current,  
                                       self._classdef)  

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26