[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7321 - in trunk/gnue-common/src/datasources: . drivers/Base driv
From: |
reinhard |
Subject: |
[gnue] r7321 - in trunk/gnue-common/src/datasources: . drivers/Base drivers/special/static |
Date: |
Fri, 8 Apr 2005 03:10:46 -0500 (CDT) |
Author: reinhard
Date: 2005-04-08 03:10:45 -0500 (Fri, 08 Apr 2005)
New Revision: 7321
Removed:
trunk/gnue-common/src/datasources/drivers/special/static/Connection.py
Modified:
trunk/gnue-common/src/datasources/GDataSource.py
trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
trunk/gnue-common/src/datasources/drivers/special/static/DataObject.py
trunk/gnue-common/src/datasources/drivers/special/static/ResultSet.py
trunk/gnue-common/src/datasources/drivers/special/static/__init__.py
Log:
Cleaned up implementation of static dbdriver.
Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py 2005-04-08 07:23:06 UTC
(rev 7320)
+++ trunk/gnue-common/src/datasources/GDataSource.py 2005-04-08 08:10:45 UTC
(rev 7321)
@@ -242,9 +242,9 @@
dataObject = Base.DataObject(None)
else:
- from gnue.common.datasources.drivers.special.static import Connection
+ from gnue.common.datasources.drivers.special import static
gDebug (7, 'Using static data driver')
- dataObject = Connection.supportedDataObjects['object'](None)
+ dataObject = static.DataObject(None)
for child in self._children:
if isinstance(child, GStaticSet):
@@ -617,29 +617,59 @@
# <staticset>
# =============================================================================
-class GStaticSet(GObjects.GObj):
- def __init__(self, parent=None):
- GObjects.GObj.__init__(self, parent, type="GDStaticSet")
+class GStaticSet (GObjects.GObj):
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+ def __init__ (self, parent = None):
+ GObjects.GObj.__init__ (self, parent, type = "GDStaticSet")
+
+ # ---------------------------------------------------------------------------
+ # Build Object
+ # ---------------------------------------------------------------------------
+
+ def _buildObject (self):
+ self.data = [staticsetrow.data for staticsetrow in self._children]
+
+
# =============================================================================
# <staticsetrow>
# =============================================================================
-class GStaticSetRow(GObjects.GObj):
- def __init__(self, parent=None):
- GObjects.GObj.__init__(self, parent, type="GDStaticSetRow")
+class GStaticSetRow (GObjects.GObj):
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+ def __init__ (self, parent = None):
+ GObjects.GObj.__init__ (self, parent, type = "GDStaticSetRow")
+
+ # ---------------------------------------------------------------------------
+ # Build Object
+ # ---------------------------------------------------------------------------
+
+ def _buildObject (self):
+ self.data = dict ([(staticsetfield.name, staticsetfield.value) \
+ for staticsetfield in self._children])
+
+
# =============================================================================
# <staticsetfield>
# =============================================================================
-class GStaticSetField(GObjects.GObj):
- def __init__(self, parent=None):
- GObjects.GObj.__init__(self, parent, type="GDStaticSetField")
+class GStaticSetField (GObjects.GObj):
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+ def __init__ (self, parent = None):
+ GObjects.GObj.__init__ (self, parent, type = "GDStaticSetField")
+
+
# =============================================================================
# <connection>
# =============================================================================
Modified: trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
2005-04-08 07:23:06 UTC (rev 7320)
+++ trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
2005-04-08 08:10:45 UTC (rev 7321)
@@ -92,12 +92,19 @@
readonly = readOnly,
masterRecordSet = masterRecordSet)
- resultset.query ('object',
- table = self.table,
- fieldnames = self._fieldReferences.keys (),
- condition = GConditions.buildCondition (conditions),
- sortorder = self.sorting and self.sorting or [])
+ if self._dataSource.type == 'object':
+ resultset.query ('object',
+ table = self.table,
+ fieldnames = self._fieldReferences.keys (),
+ condition = GConditions.buildCondition (conditions),
+ sortorder = self.sorting and self.sorting or [])
+ elif self._dataSource.type == 'static':
+ resultset.query ('static', data = self._staticSet.data)
+
+ elif self._dataSource.type == 'sql':
+ resultset.query ('sql', sql = self._rawSQL.getChildrenAsContent ())
+
return resultset
# Do not over-ride by vendor code
Deleted: trunk/gnue-common/src/datasources/drivers/special/static/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/static/Connection.py
2005-04-08 07:23:06 UTC (rev 7320)
+++ trunk/gnue-common/src/datasources/drivers/special/static/Connection.py
2005-04-08 08:10:45 UTC (rev 7321)
@@ -1,45 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or(at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2000-2005 Free Software Foundation
-#
-# FILE:
-# static/Connection.py
-#
-# DESCRIPTION:
-# Basic connection object for static datasources
-#
-# NOTES:
-#
-
-__all__ = ['Connection']
-
-from gnue.common.apps import GConfig
-from gnue.common.datasources.drivers import Base
-from DataObject import *
-
-#### ####
-#### IF YOU MODIFY ANY CONNECTION ####
-#### ATTRIBUTES, PLEASE UPDATE info.py ####
-#### ####
-
-class Connection(Base.Connection):
-
- supportedDataObjects = {
- 'object': STATIC_DataObject
- }
Modified: trunk/gnue-common/src/datasources/drivers/special/static/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/static/DataObject.py
2005-04-08 07:23:06 UTC (rev 7320)
+++ trunk/gnue-common/src/datasources/drivers/special/static/DataObject.py
2005-04-08 08:10:45 UTC (rev 7321)
@@ -1,41 +1,39 @@
+# GNU Enterprise Common Library - Static DB Driver - DataObject
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2005 Free Software Foundation
#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
# version 2, or (at your option) any later version.
#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2001-2005 Free Software Foundation
-#
-# FILE:
-# _static/DBdriver.py
-#
-# DESCRIPTION:
-# Virtual database driver for a connectionless, static set of data
-#
-# NOTES:
-# Used whenever a fixed set of data is needed
-#
+# $Id$
-__all__ = ['STATIC_DataObject']
+__all__ = ['DataObject']
-from gnue.common.datasources.drivers.Base import DataObject
-from ResultSet import STATIC_ResultSet
+from gnue.common.datasources.drivers import Base
-class STATIC_DataObject (DataObject):
+from ResultSet import ResultSet
- _resultSetClass = STATIC_ResultSet
- def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None,
sql=""):
- return STATIC_ResultSet(self, masterRecordSet=masterRecordSet)
+# =============================================================================
+# DataObject class
+# =============================================================================
+
+class DataObject (Base.DataObject):
+ """
+ Implementation of DataObject for static datasources.
+ """
+ _resultSetClass = ResultSet
Modified: trunk/gnue-common/src/datasources/drivers/special/static/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/static/ResultSet.py
2005-04-08 07:23:06 UTC (rev 7320)
+++ trunk/gnue-common/src/datasources/drivers/special/static/ResultSet.py
2005-04-08 08:10:45 UTC (rev 7321)
@@ -1,67 +1,54 @@
+# GNU Enterprise Common Library - Static DB Driver - ResultSet
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2005 Free Software Foundation
#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
# version 2, or (at your option) any later version.
#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2001-2005 Free Software Foundation
-#
-# FILE:
-# _static/ResultSet.py
-#
-# DESCRIPTION:
-# Virtual database driver for a connectionless, static set of data
-#
-# NOTES:
-# Used whenever a fixed set of data is needed
-#
+# $Id$
-__all__ = ["STATIC_ResultSet"]
+__all__ = ['ResultSet']
from gnue.common.datasources.drivers import Base
-class STATIC_ResultSet(Base.ResultSet):
- # Returns 1=DataObject has uncommitted changes
- def isPending(self):
- return 0 # Static DataObjects cannot have pending changes :)
+# =============================================================================
+# ResultSet class
+# =============================================================================
- # Post changes to the database
- def post(self):
- # Leave this here in case (for some bizarro reason)
- # a bound dataobject uses us as a master
- for record in (self._cachedRecords):
- record.post()
+class ResultSet (Base.ResultSet):
+ """
+ Implementation of ResultSet for static datasources.
+ """
- # Load cacheCount number of new records
- def _loadNextRecord(self):
- if hasattr(self,"_alldataloaded"):
- return 0
-
- # Load static data
- for row in self._dataObject._staticSet._children:
- dict = {}
- for field in row._children:
- dict[field.name] = field.value
+ # ---------------------------------------------------------------------------
+ # Implementation of virtual methods
+ # ---------------------------------------------------------------------------
- record=self._recordSetClass(parent=self,initialData=dict)
-
- self._cachedRecords.append (record)
-
- self._recordCount=self._recordCount+1
+ def _query_static (self, connection, data):
+ self.__data = data
- self._alldataloaded = 1
-
- return 1
+ # ---------------------------------------------------------------------------
+
+ def _count (self):
+ return len (self.__data)
+
+ # ---------------------------------------------------------------------------
+
+ def _fetch (self, cachesize):
+ for row in self.__data:
+ yield row
Modified: trunk/gnue-common/src/datasources/drivers/special/static/__init__.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/static/__init__.py
2005-04-08 07:23:06 UTC (rev 7320)
+++ trunk/gnue-common/src/datasources/drivers/special/static/__init__.py
2005-04-08 08:10:45 UTC (rev 7321)
@@ -1,10 +1,13 @@
+# GNU Enterprise Common Library - Static DB Driver
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2005 Free Software Foundation
#
+# This file is part of GNU Enterprise
+#
# GNU Enterprise is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
-# version 2, or(at your option) any later version.
+# version 2, or (at your option) any later version.
#
# GNU Enterprise is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
@@ -16,16 +19,10 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2000-2005 Free Software Foundation
-#
+# $Id$
"""
-special/static init file
+DB driver for a static set of data
"""
-__description__ = _("Static Special Data Driver")
-__driverurl__ = "n/a"
-__examples__ = "n/a"
-__doc__ = ""
-
-# We need not defer import, because this driver has no dependency.
-from Connection import Connection
+from DataObject import DataObject
+from ResultSet import ResultSet
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7321 - in trunk/gnue-common/src/datasources: . drivers/Base drivers/special/static,
reinhard <=