commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue-appserver/src/classrep SchemaSupport.py


From: Jan Ischebeck
Subject: gnue-appserver/src/classrep SchemaSupport.py
Date: Wed, 08 Oct 2003 10:31:41 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue-appserver
Branch:         
Changes by:     Jan Ischebeck <address@hidden>  03/10/08 10:31:41

Modified files:
        src/classrep   : SchemaSupport.py 

Log message:
        split schema writing into table data+table structure
        virtual schema reading support

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-appserver/src/classrep/SchemaSupport.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue-appserver/src/classrep/SchemaSupport.py
diff -c gnue-appserver/src/classrep/SchemaSupport.py:1.1 
gnue-appserver/src/classrep/SchemaSupport.py:1.2
*** gnue-appserver/src/classrep/SchemaSupport.py:1.1    Wed Oct  8 07:59:59 2003
--- gnue-appserver/src/classrep/SchemaSupport.py        Wed Oct  8 10:31:40 2003
***************
*** 19,25 ****
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: SchemaSupport.py,v 1.1 2003/10/08 11:59:59 siesel Exp $
  
  # read schema support
  from gnue.common.schema import GSParser
--- 19,25 ----
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: SchemaSupport.py,v 1.2 2003/10/08 14:31:40 siesel Exp $
  
  # read schema support
  from gnue.common.schema import GSParser
***************
*** 27,32 ****
--- 27,37 ----
  
  # write schema support
  from gnue.common.schema.Objects import *
+ from gnue.common.definitions.GParserHelpers import GContent
+ 
+ SCHEMA_STORE_BOTH = 0
+ SCHEMA_STORE_SCHEMA = 1
+ SCHEMA_STORE_DATA = 2
  
  class SchemaSupport:
  
***************
*** 46,55 ****
  
    def loadSchemaFromFile(self, filename, overwrite=0, install=0):
  
!       input = openResource(schema)
        
        schema = GSParser.loadFile(input)
  
  
        if overwrite:
            raise "Overwrite support not working yet."
--- 51,64 ----
  
    def loadSchemaFromFile(self, filename, overwrite=0, install=0):
  
!       input = openResource(filename)
        
        schema = GSParser.loadFile(input)
  
+       for table in schema.findChildrenOfType('GSTable',allowAllChildren=1):
+           print 'adding Table %s' % table.name
+           for field in table.findChildrenOfType('GSField',allowAllChildren=1):
+               print '   with field %s:' % field.name
  
        if overwrite:
            raise "Overwrite support not working yet."
***************
*** 65,73 ****
    # Parameter: filename:  name of file to write to
    #            classlist: list of classes to write to
    # TODO: a) add global class repository locking
    # 
---------------------------------------------------------------------------
  
!   def writeSchemaToFile(self, filename, classlist='all tables'):
        
        schema = GSSchema()
        schema.title='Appserver Schema Dump'
--- 74,83 ----
    # Parameter: filename:  name of file to write to
    #            classlist: list of classes to write to
    # TODO: a) add global class repository locking
+   #       b) add a (include system tables) parameter
    # 
---------------------------------------------------------------------------
  
!   def writeSchemaToFile(self, filename, classlist='all tables', 
type=SCHEMA_STORE_BOTH):
        
        schema = GSSchema()
        schema.title='Appserver Schema Dump'
***************
*** 77,106 ****
        
        gstables = GSTables(schema)
  
!       # load all tables first
!       
! 
!       for tablename in self._classes.keys():
!           if (classlist=='all tables') or (tablename in classlist):
!               table=GSTable(gstables)
!               table.name=tablename
!               #table.description=''
!               
!               # add fields listing (required)
!               fields=GSFields(table)
!               
!               proplist=self._classes[tablename].properties
!               
!               for propname in proplist.keys():
!                   # add one field per property
!                   field = GSField(fields)                           
!                   field.name=propname
!                   field.type=proplist[propname].gnue_type
!                   field.length=int(proplist[propname].gnue_length)
!                   field.precision=int(proplist[propname].gnue_scale)
!                   field.description=proplist[propname].gnue_comment
!                   # TODO: where should 'gnue_module' be stored?
!       
        dest = open(filename,"w")
        
        dest.write("""<?xml version="1.0"?>
--- 87,108 ----
        
        gstables = GSTables(schema)
  
!       if (classlist=='all tables'):
!           # load all tables first                
!           tablelist=[]
!           for tablename in self._classes.keys():
!               tablelist.append(tablename)
!       else:
!           tablelist=classlist
! 
!       if (type==SCHEMA_STORE_BOTH) or (type==SCHEMA_STORE_SCHEMA):
!           for tablename in tablelist:
!               self.createTableDef(gstables, tablename)
! 
!       if (type==SCHEMA_STORE_BOTH) or (type==SCHEMA_STORE_DATA):
!           gsdata = GSData(schema)
!           self.createDataList(gsdata, tablelist)
!                 
        dest = open(filename,"w")
        
        dest.write("""<?xml version="1.0"?>
***************
*** 111,116 ****
--- 113,191 ----
        dest.write(schema.dumpXML())
        dest.close()
  
+   def createTableDef(self, gstables, tablename):
+       table=GSTable(gstables)
+       table.name=tablename
+       #table.description=''
+       
+       # add fields listing (required)
+       fields=GSFields(table)
+       GSConstraints(table)
+       GSIndexes(table)
+       
+       proplist=self._classes[tablename].properties
+       
+       for propname in proplist.keys():
+           # add one field per property
+           field = GSField(fields)                           
+           field.name=propname
+           field.type=proplist[propname].gnue_type
+           field.length=int(proplist[propname].gnue_length)
+           field.precision=int(proplist[propname].gnue_scale)
+           field.description=proplist[propname].gnue_comment
+           # TODO: where should 'gnue_module' be stored?
+ 
+           # set gnue_id to be a primary key
+           if (propname=='gnue_id') and (proplist[propname].gnue_type=='id'):
+               pk=GSPrimaryKey(table)
+               pk.name='gnue_id_pk'
+               pkf=GSPKField(pk)
+               pkf.name='gnue_id'
+ 
+           
+                   
+   def createDataList(self, gsdata, tablelist):
+       # TODO: do we need to add information about modules too?
+       
+       tabledata=GSTableData(gsdata)
+       tabledata.name='gnue_class_dump'
+       tabledata.tablename='gnue_class'
+       tablerows=GSRows(tabledata)
+       
+       propdata=GSTableData(gsdata)
+       propdata.name='gnue_property_dump'
+       propdata.tablename='gnue_property'
+       proprows=GSRows(propdata)
+ 
+       for tablename in tablelist:
+           classdef = self._classes[tablename]
+           proplist=classdef.properties
+           
+           # save tabledata
+           row = GSRow(tablerows)              
+           self._buildValue(row,'gnue_id',classdef.gnue_id)
+           self._buildValue(row,'gnue_module',classdef.gnue_module)
+           self._buildValue(row,'gnue_name',classdef.gnue_name)
+           self._buildValue(row,'gnue_comment',classdef.gnue_comment)
+           
+           for propname in proplist.keys():
+               # add one field per property
+               row = GSRow(proprows)                           
+               row.name=propname
+               self._buildValue(row,'gnue_id',proplist[propname].gnue_id)
+               
self._buildValue(row,'gnue_module',proplist[propname].gnue_module)
+               self._buildValue(row,'gnue_class',proplist[propname].gnue_class)
+               self._buildValue(row,'gnue_name',proplist[propname].gnue_name)
+               self._buildValue(row,'gnue_type',proplist[propname].gnue_type)
+               
self._buildValue(row,'gnue_length',int(proplist[propname].gnue_length))
+               
self._buildValue(row,'gnue_scale',int(proplist[propname].gnue_scale))
+               
self._buildValue(row,'gnue_comment',proplist[propname].gnue_comment)
+                   
+   def _buildValue(self,row,field,data):
+       val = GSValue(row)
+       #val.field=field
+       GContent(val,"'%s'" % data)
+ 
  # 
=============================================================================
  # test program
  # 
=============================================================================
***************
*** 125,130 ****
    gsdSupp = SchemaSupport(sm._modules,sm._classes)
  
    gsdSupp.writeSchemaToFile('AS_schema.gsd')
  
!   #gsdSupp.loadSchemaFromFile('AS_schema.gsd',overwrite=1)
    
--- 200,206 ----
    gsdSupp = SchemaSupport(sm._modules,sm._classes)
  
    gsdSupp.writeSchemaToFile('AS_schema.gsd')
+   gsdSupp.writeSchemaToFile('AS_schema2.gsd',['address_person'])
  
!   gsdSupp.loadSchemaFromFile('AS_schema.gsd',overwrite=0)
    




reply via email to

[Prev in Thread] Current Thread [Next in Thread]