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

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

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

revision 1.33 by reinhard, Mon Sep 1 16:54:43 2003 UTC revision 1.34 by reinhard, Mon Sep 1 18:01:45 2003 UTC
# Line 4  Line 4 
4  #  #
5  # This file is part of GNU Enterprise.  # This file is part of GNU Enterprise.
6  #  #
7  # GNU Enterprise is free software; you can redistribute it  # GNU Enterprise is free software; you can redistribute it
8  # and/or modify it under the terms of the GNU General Public  # and/or modify it under the terms of the GNU General Public
9  # License as published by the Free Software Foundation; either  # License as published by the Free Software Foundation; either
10  # version 2, or (at your option) any later version.  # version 2, or (at your option) any later version.
11  #  #
12  # GNU Enterprise is distributed in the hope that it will be  # GNU Enterprise is distributed in the hope that it will be
13  # useful, but WITHOUT ANY WARRANTY; without even the implied  # useful, but WITHOUT ANY WARRANTY; without even the implied
14  # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR  # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  # PURPOSE. See the GNU General Public License for more details.  # PURPOSE. See the GNU General Public License for more details.
16  #  #
17  # You should have received a copy of the GNU General Public  # You should have received a copy of the GNU General Public
18  # License along with program; see the file COPYING. If not,  # License along with program; see the file COPYING. If not,
19  # write to the Free Software Foundation, Inc., 59 Temple Place  # write to the Free Software Foundation, Inc., 59 Temple Place
20  # - Suite 330, Boston, MA 02111-1307, USA.  # - Suite 330, Boston, MA 02111-1307, USA.
21  #  #
22  # $Id$  # $Id$
23    
24  import geasList  import geasList
 import geasTrigger  
 import geasAuthentication  
25  import classrep  import classrep
26  import whrandom  import whrandom
27    
# Line 52  class geasSession: Line 50  class geasSession:
50    # Initalize    # Initalize
51    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
52    
53    def __init__ (self, connections, authAdapter, triggerMg):    def __init__ (self, connections, authAdapter):
54      self.loggedIn = 0      self.loggedIn = 0
55      self.connections = connections      self.connections = connections
56      try:      try:
# Line 61  class geasSession: Line 59  class geasSession:
59        self.database = "gnue"        self.database = "gnue"
60      self._user = ""      self._user = ""
61      self._lists = {}      self._lists = {}
62      self._listcount=0      self._listcount = 0
63      self._authAdapter=authAdapter      self._authAdapter = authAdapter
     self._triggerMg=triggerMg  
64    
65    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
66    # Get class definition from class name    # Get class definition from class name
# Line 78  class geasSession: Line 75  class geasSession:
75    
76    def login (self, user, password):    def login (self, user, password):
77      # This username/password is for the Application Server, not for the      # This username/password is for the Application Server, not for the
78      # database.          # database.
79      self._user = user      self._user = user
80      self.loggedIn = self._authAdapter.authenticate(self, user,      self.loggedIn = self._authAdapter.authenticate(self, user,
81                                                     {'password':password} )                                                     {'password':password} )
# Line 97  class geasSession: Line 94  class geasSession:
94    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
95    
96    def createList (self, classname):    def createList (self, classname):
97        
98      classdef = self._getClassdef (classname)      classdef = self._getClassdef (classname)
99    
100      # check if user has access rights for this list      # check if user has access rights for this list
101      if not self._authAdapter.hasAccess (self, self._user, classname):      if not self._authAdapter.hasAccess (self, self._user, classname):
102        return None        return None
103          
     # pre_new_list trigger  
 #   if classname != "appserver_pytrigger" \  
 #      and classname != "gnue_module":  
 #     tr=self._triggerMg.getTriggerByEvent('%s:pre_new_list' % classname)  
 #     if tr!=None:  
 #       tr()  
         
104      # create new List      # create new List
105      newlist = geasList.geasList (self, classdef)      newlist = geasList.geasList (self, classdef)
106      # every new list will be added to the _lists list      # every new list will be added to the _lists list
# Line 118  class geasSession: Line 108  class geasSession:
108      self._listcount += 1      self._listcount += 1
109      self._lists [self._listcount] = newlist      self._lists [self._listcount] = newlist
110      return newlist;      return newlist;
111      
112    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
113    # Commit the active transaction    # Commit the active transaction
114    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
# Line 126  class geasSession: Line 116  class geasSession:
116    def commit (self):    def commit (self):
117      # FIXME: gnue-common should support the concept of a session and commits      # FIXME: gnue-common should support the concept of a session and commits
118      #        on session level      #        on session level
119      for l in self._lists.keys():            for l in self._lists.keys ():
120        if hasattr(self._lists[l],"_datasource"):        if hasattr (self._lists[l], "_datasource"):
121          self._lists[l]._resultset.post()          self._lists[l]._resultset.post ()
122          self._lists[l]._datasource.commit()          self._lists[l]._datasource.commit ()
123    
124    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
125    # Rollback the active transaction    # Rollback the active transaction
# Line 138  class geasSession: Line 128  class geasSession:
128    def rollback (self):    def rollback (self):
129      # FIXME: gnue-common should support the concept of a session and rollbacks      # FIXME: gnue-common should support the concept of a session and rollbacks
130      #        on session level      #        on session level
131      for l in self._lists.keys():        for l in self._lists.keys ():
132        if hasattr(self._lists[l],"_datasource"):        if hasattr (self._lists[l], "_datasource"):
133          self._lists[l]._datasource.rollback()              self._lists[l]._datasource.rollback ()
134    
135    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
136    # Create a new list of business objects of a given class    # Create a new list of business objects of a given class
# Line 149  class geasSession: Line 139  class geasSession:
139    def request (self, classname, conditions, sortorder, propertylist):    def request (self, classname, conditions, sortorder, propertylist):
140      # FIXME: this list needn't be considered by commit and rollback      # FIXME: this list needn't be considered by commit and rollback
141      list = self.createList (classname)      list = self.createList (classname)
142      if list==None:      if list == None:
143        return 0        return 0
144        
145      list_id = self._listcount      list_id = self._listcount
146      list.setPrefetch (["gnue_id"] + propertylist)      list.setPrefetch (["gnue_id"] + propertylist)
147      list.setConditions (conditions)      list.setConditions (conditions)
148      list.setSort (sortorder)      list.setSort (sortorder)
149      list.populate ()      list.populate ()
150        
151      return list_id;      return list_id;
152    
153    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
# Line 168  class geasSession: Line 158  class geasSession:
158      try:      try:
159         list = self._lists [list_id]         list = self._lists [list_id]
160      except:      except:
161        raise Error,'The list you are truing to access does not exist.'        raise Error, 'The list you are trying to access does not exist.'
162      return list.count ();      return list.count ();
163    
164    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
# Line 179  class geasSession: Line 169  class geasSession:
169      try:      try:
170        list = self._lists [list_id]        list = self._lists [list_id]
171      except:      except:
172        raise Error,'The list you are truing to access does not exist.'        raise Error, 'The list you are trying to access does not exist.'
173      return list.fetch (start, count)      return list.fetch (start, count)
174    
175    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
# Line 203  class geasSession: Line 193  class geasSession:
193        row = []        row = []
194        for property in propertylist:        for property in propertylist:
195          value = object.get (property)          value = object.get (property)
196          ## TRANSFER None as ""          # transfer None as ""
197          if value == None:          if value == None:
198            value = ""            value = ""
199          row.append (value)          row.append (value)
# Line 218  class geasSession: Line 208  class geasSession:
208      result = []      result = []
209      i = 0      i = 0
210      for object_id in obj_id_list:      for object_id in obj_id_list:
       # FIXME: if we already have (in this session) a geasInstance that holds  
       # exactly this object, then we _must_ reuse it, or the existing  
       # geasInstance won't reflect our change!  
   
       # FIXME: when new geasInstance is inserted, and we have (in this session)  
       # a geasList that this geasInstance would belong into, then insert it  
       # into that geasList.  
   
211        # We have to create a geasList for each object, because commit only        # We have to create a geasList for each object, because commit only
212        # operates on lists. We should change that. -- Reinhard        # operates on lists. We should change that. -- Reinhard
213        list = self.createList (classname)        list = self.createList (classname)
# Line 267  class geasSession: Line 249  class geasSession:
249        list.populate ()        list.populate ()
250        object = list.firstInstance ()        object = list.firstInstance ()
251        object.delete ()        object.delete ()
       # FIXME: remove this instance from all lists of this session it was  
       # a member of.  
252    
253    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
254    # Call a procedure of business objects    # Call a procedure of business objects
255    # ---------------------------------------------------------------------------    # ---------------------------------------------------------------------------
256    
257    def call(self,classname,obj_id_list,methodname,parameters):        def call (self, classname, obj_id_list, procedurename, parameters):
258      # create a temporary geasList      # create a temporary geasList
259      classdef = self._getClassdef (classname)      classdef = self._getClassdef (classname)
260      list = geasList.geasList (self, classdef)      list = geasList.geasList (self, classdef)
# Line 288  class geasSession: Line 268  class geasSession:
268                             ['const', object_id]])                             ['const', object_id]])
269        list.populate ()        list.populate ()
270        object = list.firstInstance ()        object = list.firstInstance ()
271        result.append (object.call(methodname,parameters))        result.append (object.call (methodname, parameters))
       # FIXME: at the moment the method itself has to care for data which has to  
       # be stored back into the database -- Siesel  
   
272      return result      return result
 #   FIXME: This function should be moved to the geasBClass object, once  
 #   it is working  -- Siesel  
 #   return self._getClass(classname).call(obj_id_list,methodname,parameters)  

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.34

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