Index: pykota/trunk/pykota/storages/pgstorage.py
===================================================================
--- pykota/trunk/pykota/storages/pgstorage.py (revision 1115)
+++ pykota/trunk/pykota/storages/pgstorage.py (revision 1130)
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.13  2003/10/02 20:23:18  jalet
+# Storage caching mechanism added.
+#
 # Revision 1.12  2003/08/17 14:20:25  jalet
 # Bug fix by Oleg Biteryakov
@@ -64,6 +67,5 @@
 #
 
-from pykota.storage import PyKotaStorageError
-from pykota.storage import StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
+from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
 
 try :
@@ -74,10 +76,8 @@
     raise PyKotaStorageError, "This python version (%s) doesn't seem to have the PygreSQL module installed correctly." % sys.version.split()[0]
 
-class Storage :
+class Storage(BaseStorage) :
     def __init__(self, pykotatool, host, dbname, user, passwd) :
         """Opens the PostgreSQL database connection."""
-        self.tool = pykotatool
-        self.debug = pykotatool.config.getDebug()
-        self.closed = 1
+        BaseStorage.__init__(self, pykotatool)
         try :
             (host, port) = host.split(":")
@@ -92,11 +92,6 @@
         else :    
             self.closed = 0
-            if self.debug :
-                self.tool.logger.log_message("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user), "debug")
-            
-    def __del__(self) :        
-        """Ensures that the database connection is closed."""
-        self.close()
-        
+            self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user))
+            
     def close(self) :    
         """Closes the database connection."""
@@ -104,24 +99,20 @@
             self.database.close()
             self.closed = 1
-            if self.debug :
-                self.tool.logger.log_message("Database closed.", "debug")
+            self.tool.logdebug("Database closed.")
         
     def beginTransaction(self) :    
         """Starts a transaction."""
         self.database.query("BEGIN;")
-        if self.debug :
-            self.tool.logger.log_message("Transaction begins...", "debug")
+        self.tool.logdebug("Transaction begins...")
         
     def commitTransaction(self) :    
         """Commits a transaction."""
         self.database.query("COMMIT;")
-        if self.debug :
-            self.tool.logger.log_message("Transaction committed.", "debug")
+        self.tool.logdebug("Transaction committed.")
         
     def rollbackTransaction(self) :     
         """Rollbacks a transaction."""
         self.database.query("ROLLBACK;")
-        if self.debug :
-            self.tool.logger.log_message("Transaction aborted.", "debug")
+        self.tool.logdebug("Transaction aborted.")
         
     def doSearch(self, query) :
@@ -131,6 +122,5 @@
             query += ';'
         try :
-            if self.debug :
-                self.tool.logger.log_message("QUERY : %s" % query, "debug")
+            self.tool.logdebug("QUERY : %s" % query)
             result = self.database.query(query)
         except pg.error, msg :    
@@ -146,6 +136,5 @@
             query += ';'
         try :
-            if self.debug :
-                self.tool.logger.log_message("QUERY : %s" % query, "debug")
+            self.tool.logdebug("QUERY : %s" % query)
             result = self.database.query(query)
         except pg.error, msg :    
@@ -164,5 +153,5 @@
         return pg._quote(field, typ)
         
-    def getUser(self, username) :    
+    def getUserFromBackend(self, username) :    
         """Extracts user information given its name."""
         user = StorageUser(self, username)
@@ -178,5 +167,5 @@
         return user
        
-    def getGroup(self, groupname) :    
+    def getGroupFromBackend(self, groupname) :    
         """Extracts group information given its name."""
         group = StorageGroup(self, groupname)
@@ -194,5 +183,5 @@
         return group
        
-    def getPrinter(self, printername) :        
+    def getPrinterFromBackend(self, printername) :        
         """Extracts printer information given its name."""
         printer = StoragePrinter(self, printername)
@@ -206,31 +195,6 @@
             printer.Exists = 1
         return printer    
-            
-    def getUserGroups(self, user) :        
-        """Returns the user's groups list."""
-        groups = []
-        result = self.doSearch("SELECT groupname FROM groupsmembers JOIN groups ON groupsmembers.groupid=groups.id WHERE userid=%s" % self.doQuote(user.ident))
-        if result :
-            for record in result :
-                groups.append(self.getGroup(record.get("groupname")))
-        return groups        
-        
-    def getGroupMembers(self, group) :        
-        """Returns the group's members list."""
-        groupmembers = []
-        result = self.doSearch("SELECT * FROM groupsmembers JOIN users ON groupsmembers.userid=users.id WHERE groupid=%s" % self.doQuote(group.ident))
-        if result :
-            for record in result :
-                user = StorageUser(self, record.get("username"))
-                user.ident = record.get("userid")
-                user.LimitBy = record.get("limitby")
-                user.AccountBalance = record.get("balance")
-                user.LifeTimePaid = record.get("lifetimepaid")
-                user.Email = record.get("email")
-                user.Exists = 1
-                groupmembers.append(user)
-        return groupmembers        
-        
-    def getUserPQuota(self, user, printer) :        
+        
+    def getUserPQuotaFromBackend(self, user, printer) :        
         """Extracts a user print quota."""
         userpquota = StorageUserPQuota(self, user, printer)
@@ -248,5 +212,5 @@
         return userpquota
         
-    def getGroupPQuota(self, group, printer) :        
+    def getGroupPQuotaFromBackend(self, group, printer) :        
         """Extracts a group print quota."""
         grouppquota = StorageGroupPQuota(self, group, printer)
@@ -267,5 +231,5 @@
         return grouppquota
         
-    def getPrinterLastJob(self, printer) :        
+    def getPrinterLastJobFromBackend(self, printer) :        
         """Extracts a printer's last job information."""
         lastjob = StorageLastJob(self, printer)
@@ -282,4 +246,29 @@
             lastjob.Exists = 1
         return lastjob
+            
+    def getUserGroups(self, user) :        
+        """Returns the user's groups list."""
+        groups = []
+        result = self.doSearch("SELECT groupname FROM groupsmembers JOIN groups ON groupsmembers.groupid=groups.id WHERE userid=%s" % self.doQuote(user.ident))
+        if result :
+            for record in result :
+                groups.append(self.getGroup(record.get("groupname")))
+        return groups        
+        
+    def getGroupMembers(self, group) :        
+        """Returns the group's members list."""
+        groupmembers = []
+        result = self.doSearch("SELECT * FROM groupsmembers JOIN users ON groupsmembers.userid=users.id WHERE groupid=%s" % self.doQuote(group.ident))
+        if result :
+            for record in result :
+                user = StorageUser(self, record.get("username"))
+                user.ident = record.get("userid")
+                user.LimitBy = record.get("limitby")
+                user.AccountBalance = record.get("balance")
+                user.LifeTimePaid = record.get("lifetimepaid")
+                user.Email = record.get("email")
+                user.Exists = 1
+                groupmembers.append(user)
+        return groupmembers        
         
     def getMatchingPrinters(self, printerpattern) :
