[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/appserver src/geasInstance.py src/geasList...
From: |
Reinhard Mueller |
Subject: |
gnue/appserver src/geasInstance.py src/geasList... |
Date: |
Mon, 06 May 2002 16:27:59 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Reinhard Mueller <address@hidden> 02/05/06 16:27:57
Modified files:
appserver/src : geasInstance.py geasList.py geasSession.py
test.py
Added files:
appserver/samples: setup-pgsql.sh
Log message:
Implemented basic read-only data access using the GNUe Common database
driver.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/samples/setup-pgsql.sh?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/geasInstance.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/geasList.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/geasSession.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/test.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: gnue/appserver/src/geasInstance.py
diff -c gnue/appserver/src/geasInstance.py:1.1
gnue/appserver/src/geasInstance.py:1.2
*** gnue/appserver/src/geasInstance.py:1.1 Wed May 1 16:56:22 2002
--- gnue/appserver/src/geasInstance.py Mon May 6 16:27:57 2002
***************
*** 19,44 ****
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
! # $Id: geasInstance.py,v 1.1 2002/05/01 20:56:22 reinhard Exp $
#
=============================================================================
# Instance class
#
=============================================================================
class geasInstance:
! def __init__ (self, classname):
self.classname = classname
def get (self, fieldname):
! if fieldname == "name":
! return "James T. Kirk"
! if fieldname == "street":
! return "Enterprise Road 17"
! if fieldname == "city":
! return "Gnutown"
def put (self, fieldname, value):
! pass
def call (self, methodname):
pass
--- 19,61 ----
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
! # $Id: geasInstance.py,v 1.2 2002/05/06 20:27:57 reinhard Exp $
#
=============================================================================
# Instance class
#
=============================================================================
class geasInstance:
!
! #
---------------------------------------------------------------------------
! # Initalize
! #
---------------------------------------------------------------------------
!
! def __init__ (self, classname, record):
self.classname = classname
+ self._record = record
+
+ #
---------------------------------------------------------------------------
+ # Get the value of a field
+ #
---------------------------------------------------------------------------
def get (self, fieldname):
! # TODO: look up the field type (calculated, reference etc.), translate
! # the field name into a column name
! return self._record.getField (fieldname)
!
! #
---------------------------------------------------------------------------
! # Set the value of a field
! #
---------------------------------------------------------------------------
def put (self, fieldname, value):
! # TODO: translate the field name into a column name
! self._record.setField (fieldname, value)
! self._record.post () # FIXME: Do that here? or elsewhere? later?
!
! #
---------------------------------------------------------------------------
! # Call a method
! #
---------------------------------------------------------------------------
def call (self, methodname):
pass
Index: gnue/appserver/src/geasList.py
diff -c gnue/appserver/src/geasList.py:1.1 gnue/appserver/src/geasList.py:1.2
*** gnue/appserver/src/geasList.py:1.1 Wed May 1 16:56:22 2002
--- gnue/appserver/src/geasList.py Mon May 6 16:27:57 2002
***************
*** 19,55 ****
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
! # $Id: geasList.py,v 1.1 2002/05/01 20:56:22 reinhard Exp $
! from geasInstance import *
#
=============================================================================
# List class
#
=============================================================================
class geasList:
! def __init__ (self, classname):
self._classname = classname
self._prefetch = []
self._conditions = []
self._sort = []
! def populate (self):
! pass
! def setPrefetch(self,prefetch):
! self._prefetch=prefetch
! def setConditions(self,conditions):
! self._conditions=conditions
! def setSort(self,sort):
! self._sort=sort
def firstInstance (self):
! return geasInstance (self._classname)
! pass
def nextInstance (self):
! return geasInstance (self._classname)
! pass
--- 19,88 ----
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
! # $Id: geasList.py,v 1.2 2002/05/06 20:27:57 reinhard Exp $
! from gnue.common import GDataSource
! import geasInstance
#
=============================================================================
# List class
#
=============================================================================
class geasList:
!
! #
---------------------------------------------------------------------------
! # Initalize
! #
---------------------------------------------------------------------------
!
! def __init__ (self, session, classname):
! self._session = session
self._classname = classname
self._prefetch = []
self._conditions = []
self._sort = []
! #
---------------------------------------------------------------------------
! # Actually these 3 only set variables
! #
---------------------------------------------------------------------------
! def setPrefetch (self, prefetch):
! self._prefetch = prefetch
! def setConditions (self, conditions):
! self._conditions = conditions
! def setSort (self, sort):
! self._sort = sort
!
! #
---------------------------------------------------------------------------
! # Populate the list with data from the database backend
! #
---------------------------------------------------------------------------
!
! def populate (self):
! self._datasource = GDataSource.GDataSource ()
! # TODO: get the table name from the class name
! self._datasource.buildObject (name = "",
! database = "gnue",
! table = self._classname)
! self._datasource.setConnectionManager (self._session._connections)
! self._datasource.phaseInit ()
! # TODO: get the column names from the prefetch field names
! for field in self._prefetch:
! self._datasource.referenceField (field)
! self._resultset = self._datasource.createResultSet ()
!
! #
---------------------------------------------------------------------------
! # Get the first instance in the list
! #
---------------------------------------------------------------------------
def firstInstance (self):
! self._resultset.firstRecord ()
! return geasInstance.geasInstance (self._classname,
self._resultset.current)
!
! #
---------------------------------------------------------------------------
! # Get the next instance in the list
! #
---------------------------------------------------------------------------
def nextInstance (self):
! self._resultset.nextRecord ()
! return geasInstance.geasInstance (self._classname,
self._resultset.current)
Index: gnue/appserver/src/geasSession.py
diff -c gnue/appserver/src/geasSession.py:1.1
gnue/appserver/src/geasSession.py:1.2
*** gnue/appserver/src/geasSession.py:1.1 Wed May 1 16:56:22 2002
--- gnue/appserver/src/geasSession.py Mon May 6 16:27:57 2002
***************
*** 19,41 ****
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
! # $Id: geasSession.py,v 1.1 2002/05/01 20:56:22 reinhard Exp $
! from geasList import *
#
=============================================================================
# Session class
#
=============================================================================
class geasSession:
! def __init__ (self):
self.loggedIn = 0
def login (self, user, password):
self.loggedIn = 1
def logout (self):
self.loggedIn = 0
def createList (self, classname):
! return geasList (classname)
--- 19,44 ----
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
! # $Id: geasSession.py,v 1.2 2002/05/06 20:27:57 reinhard Exp $
! import geasList
#
=============================================================================
# Session class
#
=============================================================================
class geasSession:
! def __init__ (self, connections):
self.loggedIn = 0
+ self._connections = connections
def login (self, user, password):
+ # This username/password is for the Application Server, not for the
+ # database.
self.loggedIn = 1
def logout (self):
self.loggedIn = 0
def createList (self, classname):
! return geasList.geasList (self, classname)
Index: gnue/appserver/src/test.py
diff -c gnue/appserver/src/test.py:1.5 gnue/appserver/src/test.py:1.6
*** gnue/appserver/src/test.py:1.5 Sun May 5 19:38:27 2002
--- gnue/appserver/src/test.py Mon May 6 16:27:57 2002
***************
*** 19,58 ****
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
! # $Id: test.py,v 1.5 2002/05/05 23:38:27 siesel Exp $
! from geasSession import *
! from geasList import *
! from geasInstance import *
! print "Creating session object ..."
! session = geasSession ()
! #session = sessionManager.getNewSession()
! print "Logging into the session ..."
! session.login ("hacker", "secret")
! print "Creating list object ..."
! list = session.createList ("addressbook::person")
! print "Setting up list object ..."
! list.setPrefetch(["name", "street", "city"])
! list.setConditions([])
! list.setSort(["zip"])
! print "Populating list ..."
! list.populate
! print "Retrieving first instance ..."
! instance = list.firstInstance ()
! print "These are the values of the first instance:"
! print instance.get ("name")
! print instance.get ("street")
! print instance.get ("city")
! #print "Get the status of the session manager again"
! #print "Status: ",sessionManager.Status()
! print "Thank you for playing!"
--- 19,84 ----
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
! # $Id: test.py,v 1.6 2002/05/06 20:27:57 reinhard Exp $
! import os
! from gnue.common import GClientApp
! from gnue.common import GLoginHandler
! import geasSession
+ #
=============================================================================
+ # Test application
+ #
=============================================================================
! class testApp (GClientApp.GClientApp):
! #
---------------------------------------------------------------------------
! # Main program
! #
---------------------------------------------------------------------------
! def run (self):
! # set up login handler
! self.connections.setLoginHandler (testLoginHandler ())
! print "Creating session object ..."
! session = geasSession.geasSession (self.connections)
! print "Logging into the session ..."
! session.login ("hacker", "secret")
! print "Creating list object ..."
! list = session.createList ("person")
! print "Setting up list object ..."
! list.setPrefetch (["name", "street", "city"])
! list.setConditions ([])
! list.setSort (["zip"])
! print "Populating list ..."
! list.populate ()
! print "Retrieving first instance ..."
! instance = list.firstInstance ()
!
! print "These are the values of the first instance:"
! print " Name :", instance.get ("name")
! print " Street:", instance.get ("street")
! print " City :", instance.get ("city")
!
! print "Thank you for playing!"
!
! #
=============================================================================
! # Login Handler
! #
=============================================================================
!
! class testLoginHandler (GLoginHandler.LoginHandler):
! def getLogin (self, *arguments):
! # for this test program, try to log into the database as the current user
! username = os.environ ["LOGNAME"]
! return {"_username": username, "_password": "(none)"}
!
! #
=============================================================================
! # Let it rock
! #
=============================================================================
!
! (testApp ()).run ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/appserver src/geasInstance.py src/geasList...,
Reinhard Mueller <=