[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7801 - trunk/gnue-common/src/datasources
From: |
reinhard |
Subject: |
[gnue] r7801 - trunk/gnue-common/src/datasources |
Date: |
Mon, 8 Aug 2005 08:59:36 -0500 (CDT) |
Author: reinhard
Date: 2005-08-08 08:59:35 -0500 (Mon, 08 Aug 2005)
New Revision: 7801
Modified:
trunk/gnue-common/src/datasources/GSchema.py
Log:
Cleanup, docstrings, comments.
Modified: trunk/gnue-common/src/datasources/GSchema.py
===================================================================
--- trunk/gnue-common/src/datasources/GSchema.py 2005-08-08 13:14:46 UTC
(rev 7800)
+++ trunk/gnue-common/src/datasources/GSchema.py 2005-08-08 13:59:35 UTC
(rev 7801)
@@ -20,6 +20,9 @@
# - Suite 330, Boston, MA 02111-1307, USA.
#
# $Id$
+"""
+Classes for the schema object tree.
+"""
from gnue.common.definitions import GObjects, GParser, GParserHelpers, GRootObj
from gnue.common.formatting import GTypecast
@@ -32,6 +35,9 @@
# =============================================================================
class GSObject (GObjects.GObj):
+ """
+ Abstract base class for all objects of a schema tree.
+ """
# ---------------------------------------------------------------------------
# Constructor
@@ -44,143 +50,357 @@
# =============================================================================
-# This class implements the object tree for schema definitions
+# <schema>
# =============================================================================
class GSSchema (GRootObj.GRootObj, GSObject):
+ """
+ Database schema, the root of any schema tree.
+ """
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__(self, parent = None):
GRootObj.GRootObj.__init__(self, 'schema', getXMLelements, __name__)
GSObject.__init__(self, parent, 'GSSchema')
+
# =============================================================================
+# <tables>
+# =============================================================================
class GSTables (GSObject):
+ """
+ Collection of table definitions.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__(self, parent, **params):
+
GSObject.__init__(self, parent, 'GSTables', **params)
+
+ # ---------------------------------------------------------------------------
+ # Make sure that different types of table-collections aren't mixed up
+ # ---------------------------------------------------------------------------
+
def _id_ (self, maxIdLength = None):
- # Don't mix up different type of table-collections
+
return "%s" % self.type
# =============================================================================
+# <table>
+# =============================================================================
class GSTable (GSObject):
+ """
+ Definition of a single database table.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__(self, parent, **params):
+
GSObject.__init__(self, parent, 'GSTable', **params)
+
+ # ---------------------------------------------------------------------------
+ # Return a list of all fields
+ # ---------------------------------------------------------------------------
+
def fields (self, action = None):
+ """
+ Returns a list of all fields of this table.
+
+ @param action: if given, only returns the fields where the property
+ "action" is set to the value of this parameter.
+ @return: iterater over the requested fields.
+ """
+
for field in self.findChildrenOfType ('GSField', False, True):
if action is not None and field._action != action:
continue
else:
yield field
+
# =============================================================================
+# <fields>
+# =============================================================================
class GSFields (GSObject):
+ """
+ Collection of fields of a table.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__(self, parent, **params):
+
GSObject.__init__(self, parent, 'GSFields', **params)
# =============================================================================
+# <field>
+# =============================================================================
class GSField (GSObject, GParserHelpers.GLeafNode):
+ """
+ Definition of a single database field.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__(self, parent, **params):
+
GSObject.__init__(self, parent, 'GSField', **params)
+
# =============================================================================
+# <primarykey>
+# =============================================================================
class GSPrimaryKey (GObjects.GUndividedCollection):
+ """
+ Definition of a primary key of a database table.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GObjects.GUndividedCollection.__init__ (self, parent, 'GSPrimaryKey',
**params)
# =============================================================================
+# <pkfield>
+# =============================================================================
class GSPKField (GSObject, GParserHelpers.GLeafNode):
+ """
+ Definition of a primary key field.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__(self, parent, 'GSPKField', **params)
# =============================================================================
+# <constraints>
+# =============================================================================
class GSConstraints (GObjects.GUndividedCollection):
+ """
+ Collection of constraint definitions.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GObjects.GUndividedCollection.__init__ (self, parent, 'GSConstraints',
**params)
# =============================================================================
+# <foreignkey>
+# =============================================================================
class GSForeignKey (GSObject):
+ """
+ Definition of a foreign key constraint.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__ (self, parent, 'GSForeignKey', **params)
# =============================================================================
+# <fkfield>
+# =============================================================================
class GSFKField (GSObject, GParserHelpers.GLeafNode):
+ """
+ Definition of a foreign key field.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__(self, parent, 'GSFKField', **params)
+
# =============================================================================
+# <unique>
+# =============================================================================
class GSUnique (GSObject):
+ """
+ Definition of an unique constraint.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__ (self, parent, 'GSUnique', **params)
# =============================================================================
+# <uqfield>
+# =============================================================================
class GSUQField (GSObject, GParserHelpers.GLeafNode):
+ """
+ Definition of an unique constraint field.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__(self, parent, 'GSUQField', **params)
# =============================================================================
+# <indexes>
+# =============================================================================
class GSIndexes (GObjects.GUndividedCollection):
+ """
+ Collection of index definitions.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GObjects.GUndividedCollection.__init__ (self, parent, 'GSIndexes',
**params)
# =============================================================================
+# <index>
+# =============================================================================
class GSIndex (GSObject):
+ """
+ Definition of an index on a database table.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
GSObject.__init__(self, parent, 'GSIndex', **params)
# =============================================================================
+# <indexfield>
+# =============================================================================
class GSIndexField (GSObject, GParserHelpers.GLeafNode):
+ """
+ Definition of an index field.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
GSObject.__init__(self, parent, 'GSIndexField', **params)
-
# =============================================================================
+# <data>
+# =============================================================================
class GSData (GSObject):
+ """
+ Collection of tabledata to be included in a schema definition (e.g. for
+ initial loading of a table).
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__ (self, parent, 'GSData', **params)
# =============================================================================
+# <tabledata>
+# =============================================================================
class GSTableData (GSObject):
+ """
+ Data for one table.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__ (self, parent, 'GSTableData', **params)
# =============================================================================
+# <rows>
+# =============================================================================
class GSRows (GSObject):
+ """
+ Collection of data rows.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__ (self, parent, 'GSRows', **params)
# ---------------------------------------------------------------------------
@@ -200,23 +420,55 @@
# =============================================================================
+# <row>
+# =============================================================================
class GSRow (GSObject):
+ """
+ Definition of a single data row.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__ (self, parent, 'GSRow', **params)
# =============================================================================
+# <value>
+# =============================================================================
class GSValue (GSObject, GParserHelpers.GLeafNode):
+ """
+ Definition for a value in a row.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
GSObject.__init__ (self, parent, 'GSValue', **params)
# =============================================================================
+# <description>
+# =============================================================================
class GSDescription (GSObject, GParserHelpers.GLeafNode):
+ """
+ Clear text description of the schema.
+ """
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
def __init__ (self, parent, **params):
+
GSObject.__init__ (self, parent, 'GSDescription', **params)
@@ -231,7 +483,7 @@
"""
return GParser.loadXMLObject (buffer, xmlSchemaHandler, 'GSSchema', 'schema',
- initialize, attributes = {'_app': app})
+ initialize, attributes = {'_app': app})
# =============================================================================
@@ -248,222 +500,153 @@
if xmlElements is None:
xmlElements = {
- 'schema': {
- 'BaseClass': GSSchema,
- 'Required': True,
- 'SingleInstance': True,
- 'Attributes': {
- 'title': {
- 'Typecast': GTypecast.text },
- 'author': {
- 'Typecast': GTypecast.text },
- 'version': {
- 'Typecast': GTypecast.text },
- 'description': {
- 'Typecast': GTypecast.text } } ,
- 'ParentTags': None },
+ 'schema': {
+ 'BaseClass' : GSSchema,
+ 'Required' : True,
+ 'SingleInstance' : True,
+ 'Attributes' : {'title' : {'Typecast': GTypecast.text},
+ 'author' : {'Typecast': GTypecast.text},
+ 'version' : {'Typecast': GTypecast.text},
+ 'description': {'Typecast': GTypecast.text}},
+ 'ParentTags' : None },
+ 'tables': {
+ 'BaseClass' : GSTables,
+ 'SingleInstance' : False,
+ 'Attributes' : {'type': {'Typecast': GTypecast.name,
+ 'Default' : 'table'},
+ 'name': {'Typecast': GTypecast.name,
+ 'Default' : 'tables'}},
+ 'ParentTags' : ('schema',)},
+ 'table': {
+ 'BaseClass' : GSTable,
+ 'Importable' : True,
+ 'Attributes' : {'name' : {'Required': True,
+ 'Unique' : True,
+ 'Typecast': GTypecast.name},
+ 'description': {'Typecast': GTypecast.text},
+ 'type' : {'Typecast': GTypecast.name},
+ 'action' : {'Typecast': GTypecast.text,
+ 'ValueSet': {'create': {},
+ 'extend': {}},
+ 'Default' : 'create'}},
+ 'ParentTags' : ('tables',)},
+ 'fields': {
+ 'BaseClass' : GSFields,
+ 'Importable' : True,
+ 'SingleInstance' : True,
+ 'ParentTags' : ('table',)},
+ 'field': {
+ 'BaseClass' : GSField,
+ 'Importable' : True,
+ 'Attributes' : {'name' : {'Required': True,
+ 'Unique' : True,
+ 'Typecast': GTypecast.name},
+ 'description': {'Typecast': GTypecast.text},
+ 'type' : {'Required': True,
+ 'Typecast': GTypecast.name},
+ 'length' : {'Typecast': GTypecast.whole},
+ 'precision' : {'Typecast': GTypecast.whole,
+ 'Default' : 0},
+ 'nullable' : {'Typecast': GTypecast.boolean,
+ 'Default' : True},
+ 'default' : {'Typecast': GTypecast.text},
+ 'defaultwith': {'Typecast': GTypecast.text,
+ 'ValueSet': {'constant' : {},
+ 'timestamp': {},
+ 'serial' : {}},
+ 'Default': 'constant'}},
+ 'ParentTags' : ('fields',)},
+ 'primarykey': {
+ 'BaseClass' : GSPrimaryKey,
+ 'SingleInstance' : True,
+ 'Attributes' : {'name': {'Required': True,
+ 'Typecast': GTypecast.name}},
+ 'ParentTags' : ('table', 'tabledata')},
+ 'pkfield': {
+ 'BaseClass' : GSPKField,
+ 'Attributes' : {'name': {'Required': True,
+ 'Typecast': GTypecast.name}},
+ 'ParentTags' : ('primarykey',)},
+ 'constraints': {
+ 'BaseClass' : GSConstraints,
+ 'SingleInstance' : True,
+ 'ParentTags' : ('table',)},
+ 'foreignkey': {
+ 'BaseClass' : GSForeignKey,
+ 'Attributes' : {'name' : {'Required': True,
+ 'Typecast': GTypecast.name},
+ 'references': {'Typecast': GTypecast.name}},
+ 'ParentTags' : ('constraints',)},
+ 'fkfield': {
+ 'BaseClass' : GSFKField,
+ 'Attributes' : {'name' : {'Required': True,
+ 'Typecast': GTypecast.name},
+ 'references': {'Required': True,
+ 'Typecast': GTypecast.name}},
+ 'ParentTags' : ('foreignkey',)},
+ 'unique': {
+ 'BaseClass' : GSUnique,
+ 'Attributes' : {'name': {'Required': True,
+ 'Typecast': GTypecast.name}},
+ 'ParentTags' : ('constraints',)},
+ 'uqfield': {
+ 'BaseClass' : GSUQField,
+ 'Attributes' : {'name': {'Required': True,
+ 'Typecast': GTypecast.name}},
+ 'ParentTags' : ('unique',)},
+ 'indexes': {
+ 'BaseClass' : GSIndexes,
+ 'SingleInstance' : True,
+ 'ParentTags' : ('table',)},
+ 'index': {
+ 'BaseClass' : GSIndex,
+ 'Attributes' : {'name' : {'Required': True,
+ 'Typecast': GTypecast.name},
+ 'unique': {'Typecast': GTypecast.boolean,
+ 'Default' : False}},
+ 'ParentTags' : ('indexes',)},
- 'tables': {
- 'BaseClass': GSTables,
- 'SingleInstance': False,
- 'Attributes': {
- 'type': {'Typecast': GTypecast.name,
- 'Default' : 'table'},
- 'name': {'Typecast': GTypecast.name,
- 'Default' : 'tables'} },
- 'ParentTags': ('schema',) },
+ 'indexfield': {
+ 'BaseClass' : GSIndexField,
+ 'Attributes' : {'name': {'Required': True,
+ 'Typecast': GTypecast.name}},
+ 'ParentTags' : ('index',)},
+ 'data': {
+ 'BaseClass' : GSData,
+ 'SingleInstance' : True,
+ 'ParentTags' : ('schema',)},
+ 'tabledata': {
+ 'BaseClass' : GSTableData,
+ 'Importable' : True,
+ 'Attributes' : {'name' : {'Required': True,
+ 'Typecast': GTypecast.name},
+ 'tablename': {'Required': True,
+ 'Typecast': GTypecast.name}},
+ 'ParentTags' : ('data',)},
+ 'rows': {
+ 'BaseClass' : GSRows,
+ 'SingleInstance' : True,
+ 'ParentTags' : ('tabledata',)},
+ 'row': {
+ 'BaseClass' : GSRow,
+ 'ParentTags' : ('rows',)},
+ 'value': {
+ 'BaseClass' : GSValue,
+ 'Attributes' : {'field': {'Required': False,
+ 'Typecast': GTypecast.name},
+ 'type' : {'Required': False,
+ 'Typecast': GTypecast.name,
+ 'Default' : 'text' }},
+ 'ParentTags' : ('row',),
+ 'MixedContent' : True,
+ 'KeepWhitespace' : True},
+ 'description': {
+ 'BaseClass' : GSDescription,
+ 'SingleInstance' : True,
+ 'MixedContent' : True,
+ 'UsableBySiblings': True,
+ 'ParentTags' : ('schema',)}}
- 'table': {
- 'BaseClass': GSTable,
- 'Importable': 1,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Unique': 1,
- 'Typecast': GTypecast.name },
- 'description': {
- 'Typecast': GTypecast.text },
- 'type': {
- 'Typecast': GTypecast.name },
- 'action': {
- 'Typecast': GTypecast.text,
- 'ValueSet': {
- 'create': {},
- 'extend': {} },
- 'Default': 'create' }},
- 'ParentTags': ('tables',) },
-
- 'fields': {
- 'BaseClass': GSFields,
- 'Importable': 1,
- 'SingleInstance': 1,
- 'ParentTags': ('table',) },
-
- 'field': {
- 'BaseClass': GSField,
- 'Importable': 1,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Unique': 1,
- 'Typecast': GTypecast.name },
- 'description': {
- 'Typecast': GTypecast.text },
- 'type': {
- 'Required': 1,
- 'Typecast': GTypecast.name },
- 'length': {
- 'Typecast': GTypecast.whole },
- 'precision': {
- 'Typecast': GTypecast.whole,
- 'Default': 0 },
- 'nullable': {
- 'Typecast': GTypecast.boolean,
- 'Default': 1 },
- 'default': {
- 'Typecast': GTypecast.text },
- 'defaultwith': {
- 'Typecast': GTypecast.text,
- 'ValueSet': {
- 'constant': {},
- 'timestamp': {},
- 'serial': {} },
- 'Default': 'constant' },
- },
- 'ParentTags': ('fields',) },
-
- 'primarykey': {
- 'BaseClass': GSPrimaryKey,
- 'SingleInstance': 1,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name } },
- 'ParentTags': ('table', 'tabledata') },
-
- 'pkfield': {
- 'BaseClass': GSPKField,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name } },
- 'ParentTags': ('primarykey',) },
-
- 'constraints': {
- 'BaseClass': GSConstraints,
- 'SingleInstance': 1,
- 'ParentTags': ('table',) },
-
- 'foreignkey': {
- 'BaseClass': GSForeignKey,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name },
- 'references': {
- 'Typecast': GTypecast.name } },
- 'ParentTags': ('constraints',) },
-
- 'fkfield': {
- 'BaseClass': GSFKField,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name },
- 'references': {
- 'Required': 1,
- 'Typecast': GTypecast.name } },
- 'ParentTags': ('foreignkey',) },
-
- 'unique': {
- 'BaseClass': GSUnique,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name } },
- 'ParentTags': ('constraints',) },
-
- 'uqfield': {
- 'BaseClass': GSUQField,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name } },
- 'ParentTags': ('unique',) },
-
- 'indexes': {
- 'BaseClass': GSIndexes,
- 'SingleInstance': 1,
- 'ParentTags': ('table',) },
- 'index': {
- 'BaseClass': GSIndex,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name },
- 'unique': {
- 'Default': False,
- 'Typecast': GTypecast.boolean } },
- 'ParentTags': ('indexes',) },
-
- 'indexfield': {
- 'BaseClass': GSIndexField,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name } },
- 'ParentTags': ('index',) },
-
- 'data': {
- 'BaseClass': GSData,
- 'SingleInstance': 1,
- 'ParentTags': ('schema',) },
-
- 'tabledata': {
- 'BaseClass': GSTableData,
- 'Importable': 1,
- 'Attributes': {
- 'name': {
- 'Required': 1,
- 'Typecast': GTypecast.name },
- 'tablename': {
- 'Required': 1,
- 'Typecast': GTypecast.name } },
- 'ParentTags': ('data',) },
-
- 'rows': {
- 'BaseClass': GSRows,
- 'SingleInstance': 1,
- 'ParentTags': ('tabledata',) },
-
- 'row': {
- 'BaseClass': GSRow,
- 'ParentTags': ('rows',) },
-
- 'value': {
- 'BaseClass': GSValue,
- 'Attributes': {
- 'field': {
- 'Required': 0,
- 'Typecast': GTypecast.name },
- 'type': {
- 'Required': 0,
- 'Typecast': GTypecast.name,
- 'Default': 'text' },
- },
- 'ParentTags': ('row',),
- 'MixedContent': 1,
- 'KeepWhitespace': 1},
-
- 'description': {
- 'BaseClass': GSDescription,
- 'SingleInstance': 1,
- 'MixedContent': 1,
- 'UsableBySiblings': 1,
- 'ParentTags': ('schema',) },
-
- }
-
return GParser.buildImportableTags ('schema', xmlElements)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7801 - trunk/gnue-common/src/datasources,
reinhard <=