/[papo]/gnue/common/src/GDataSource.py
ViewVC logotype

Diff of /gnue/common/src/GDataSource.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by styxman, Fri Nov 15 15:32:54 2002 UTC revision 1.7.2.1 by anthonyl, Tue Mar 4 22:09:32 2003 UTC
# Line 16  Line 16 
16  # write to the Free Software Foundation, Inc., 59 Temple Place  # write to the Free Software Foundation, Inc., 59 Temple Place
17  # - Suite 330, Boston, MA 02111-1307, USA.  # - Suite 330, Boston, MA 02111-1307, USA.
18  #  #
19  # Copyright 2000-2002 Free Software Foundation  # Copyright 2000-2003 Free Software Foundation
20  #  #
21  # FILE:  # FILE:
22  # GDataSource.py  # GDataSource.py
# Line 51  class GDataSource(GObjects.GObj): Line 51  class GDataSource(GObjects.GObj):
51    def __init__(self, parent=None, type="GDataSource"):    def __init__(self, parent=None, type="GDataSource"):
52      GObjects.GObj.__init__(self, parent, type)      GObjects.GObj.__init__(self, parent, type)
53      self.type = "object"      self.type = "object"
54      self.database = None      self.connection = None
55      self._connections = None      self._connections = None
56      self._dataObject = None      self._dataObject = None
57      self._connectionComment = ""      self._connectionComment = ""
# Line 96  class GDataSource(GObjects.GObj): Line 96  class GDataSource(GObjects.GObj):
96    
97    def getCurrentResultSet(self):    def getCurrentResultSet(self):
98      return self._currentResultSet      return self._currentResultSet
99      
100    def getRecords(self):    def getRecords(self):
101      lResultSet = self.getCurrentResultSet()      lResultSet = self.getCurrentResultSet()
102      if lResultSet._currentRecord == -1:      if lResultSet._currentRecord == -1:
# Line 108  class GDataSource(GObjects.GObj): Line 108  class GDataSource(GObjects.GObj):
108    
109    def getCurrentRecord(self):    def getCurrentRecord(self):
110      return self.getCurrentResultSet().getCurrentRecord()      return self.getCurrentResultSet().getCurrentRecord()
111      
112    
113    def _buildObject(self):    def _buildObject(self):
114    
115        # Added 0.5.0 -- Delete before 1.0
116        if hasattr(self,'database'):
117          self.connection = self.database
118          del self.database
119    
120      try:      try:
121        for field in string.split(self.explicitfields,','):        for field in string.split(self.explicitfields,','):
122          self._fieldReferences[field] = 1          self._fieldReferences[field] = 1
123      except AttributeError:      except AttributeError:
124        pass        pass
125      try:      try:
126        # TODO: This **really** needs to be deprecated and        # TODO: This **really** needs to be deprecated and
127        # TODO: should be using <sorting> tags        # TODO: should be using <sorting> tags
128        for field in string.split(self.order_by,','):        for field in string.split(self.order_by,','):
129          if field[-5:].lower() == ' desc':          if field[-5:].lower() == ' desc':
130            field = field[:-5]            field = field[:-5]
131          self._fieldReferences[field] = 1          #self._fieldReferences[field] = 1
132      except AttributeError:      except AttributeError:
133        pass        pass
134      return GObjects.GObj._buildObject(self)      return GObjects.GObj._buildObject(self)
135    
   
136    def getTimeStamp(self):    def getTimeStamp(self):
137      return self._dataObject.triggerExtensions.getTimeStamp()      return self._dataObject.triggerExtensions.getTimeStamp()
138      
139    
140    def triggerSimpleQuery(self,maskDict):    def triggerSimpleQuery(self,maskDict):
141      queryDict = {}      queryDict = {}
142      okToProcess = 1      okToProcess = 1
# Line 161  class GDataSource(GObjects.GObj): Line 168  class GDataSource(GObjects.GObj):
168      if hasattr(rset,'callFunc'):      if hasattr(rset,'callFunc'):
169        rset.callFunc(name,params)        rset.callFunc(name,params)
170      else:      else:
171        raise StandardError, \        tmsg = _("Backend doesn't support the trigger 'call' function")
172              _("Backend doesn't support the trigger 'call' function")        raise StandardError, tmsg
173    
174    #    #
175    # get/set the static condition assosiated with a datasource    # get/set the static condition assosiated with a datasource
# Line 175  class GDataSource(GObjects.GObj): Line 182  class GDataSource(GObjects.GObj):
182    
183    def getCondition():    def getCondition():
184      return dataObject._staticCondition      return dataObject._staticCondition
185        
186    #    #
187    # This method should be called after the object is created    # This method should be called after the object is created
188    # but before any other methods are called    # but before any other methods are called
# Line 184  class GDataSource(GObjects.GObj): Line 191  class GDataSource(GObjects.GObj):
191      self._connections = connectionManager      self._connections = connectionManager
192    
193    def initialize(self):    def initialize(self):
194      if not self.database:      if not self.connection:
195        # We are a connectionless datasource (virtual?)              # We are a connectionless datasource (virtual?)      
196        # We have to bind to something, so bind to empty or static driver        # We have to bind to something, so bind to empty or static driver
197        if not self.type=="static":        if not self.type=="static":
198          from gnue.common.dbdrivers._empty import DBdriver          from gnue.common.dbdrivers._empty import DBdriver
199          GDebug.printMesg (7, 'Using empty data driver')          GDebug.printMesg (7, 'Using empty data driver')
200          dataObject = DBdriver.supportedDataObjects['object']()          dataObject = DBdriver.supportedDataObjects['object']()
201            
202        else:        else:
203          from gnue.common.dbdrivers._static import DBdriver          from gnue.common.dbdrivers._static import DBdriver
204          GDebug.printMesg (7, 'Using static data driver')          GDebug.printMesg (7, 'Using static data driver')
205          dataObject = DBdriver.supportedDataObjects['static']()          dataObject = DBdriver.supportedDataObjects['static']()
206            
207          for child in self._children:          for child in self._children:
208            if isinstance(child, GStaticSet):            if isinstance(child, GStaticSet):
209              dataObject._staticSet = child              dataObject._staticSet = child
210              break              break
211            
212    
213      elif self._connections:      elif self._connections:
214        self.database = string.lower(self.database)        self.connection = string.lower(self.connection)
215        # This will throw a GConnections.NotFoundError if an unknown        # This will throw a GConnections.NotFoundError if an unknown
216        # connection name is specified.  The calling method should        # connection name is specified.  The calling method should
217        # catch this exception and handle it properly (exit w/message)        # catch this exception and handle it properly (exit w/message)
218        dataObject = \        dataObject = \
219           self._connections.getDataObject(self.database, self.type)           self._connections.getDataObject(self.connection, self.type)
220        GDebug.printMesg (7, "GDataSource.py bound to %s " % self._dataObject)        GDebug.printMesg (7, "GDataSource.py bound to %s " % self._dataObject)
221    
222      self.name = string.lower(self.name)      self.name = string.lower(self.name)
# Line 247  class GDataSource(GObjects.GObj): Line 254  class GDataSource(GObjects.GObj):
254    
255    
256    def connect(self):    def connect(self):
257      if self.database != None:      if self.connection != None:
258        self._connections.\        self._connections.\
259             requestConnection(self._dataObject, self.database)             requestConnection(self._dataObject, self.connection)
260    
261    def getDataObject(self):    def getDataObject(self):
262      return self._dataObject      return self._dataObject
# Line 338  class GDataSource(GObjects.GObj): Line 345  class GDataSource(GObjects.GObj):
345              .getDataObject().addDetailDataObject(self.getDataObject(),              .getDataObject().addDetailDataObject(self.getDataObject(),
346                                                   self)                                                   self)
347        else:        else:
348          raise StandardError, \          tmsg = _("Detail source '%s' references non-existant master '%s'") \
            _("Detail source '%s' references non-existant master '%s'") \  
349                           % (self.name, self.master)                           % (self.name, self.master)
350            raise StandardError, tmsg
351    
352    def tertiaryInit(self):    def tertiaryInit(self):
353      if hasattr(self, 'prequery'):      if hasattr(self, 'prequery'):
# Line 363  class GDataSource(GObjects.GObj): Line 370  class GDataSource(GObjects.GObj):
370    def _onModification(self, record):    def _onModification(self, record):
371      return 1      return 1
372    
373    def _onNewRecordQueried(self, record):    def _onRecordLoaded(self, record):
374      return 1      return 1
375    
376    
# Line 379  class GSql(GObjects.GObj): Line 386  class GSql(GObjects.GObj):
386    
387  ######  ######
388  #  #
389  #  # Static Datasource Support
390  #  #
391  ######  ######
392  class GStaticSet(GObjects.GObj):  class GStaticSet(GObjects.GObj):
# Line 394  class GStaticSetField(GObjects.GObj): Line 401  class GStaticSetField(GObjects.GObj):
401    def __init__(self, parent=None):    def __init__(self, parent=None):
402       GObjects.GObj.__init__(self, parent, type="GDStaticSetField")       GObjects.GObj.__init__(self, parent, type="GDStaticSetField")
403    
404    
405    ######
406    #
407    #
408    #
409    ######
410    class GConnection(GObjects.GObj):
411      def __init__(self, parent=None):
412        GObjects.GObj.__init__(self, parent, "GCConnection")
413        self.comment = ""
414        self.name = ""
415        self._inits =[self.initialize]
416    
417      def _buildObject(self):
418        self.name = string.lower(self.name)
419        return GObjects.GObj._buildObject(self)
420    
421      def initialize(self):
422        # Add our database connection information to the connections
423        # manager, then let it handle everything from there.
424        root = self.findParentOfType(None)
425        root._instance.connections.\
426            addConnectionSpecification(self.name, {
427               'name': self.name,
428               'provider': self.provider,
429               'dbname': self.dbname,
430               'host': self.host } )
431    
432    
433    
434  ######  ######
435  #  #
436  # Used by client GParsers to automatically pull supported xml tags  # Used by client GParsers to automatically pull supported xml tags
# Line 421  def getXMLelements(updates={}): Line 458  def getXMLelements(updates={}):
458              'type':        {              'type':        {
459                 'Typecast': GTypecast.name,                 'Typecast': GTypecast.name,
460                 'Default':  "object" },                 'Default':  "object" },
461              'database':    {              'connection':    {
462                 'Typecast': GTypecast.name },                 'Typecast': GTypecast.name },
463                'database':    {
464                   'Typecast': GTypecast.name,
465                   'Deprecated': 'Use {connection} attribute instead' },
466              'table':       {              'table':       {
467                 'Typecast': GTypecast.name },                 'Typecast': GTypecast.name },
468              'historytable':       {              'historytable':       {
# Line 453  def getXMLelements(updates={}): Line 493  def getXMLelements(updates={}):
493        'staticset': {        'staticset': {
494           'BaseClass': GStaticSet,           'BaseClass': GStaticSet,
495  #  TODO: This should be replaced by a SingleInstanceInParentObject  #  TODO: This should be replaced by a SingleInstanceInParentObject
496  #        instead of SingleInstance (in the whole file)          #        instead of SingleInstance (in the whole file)
497  #         'SingleInstance': 1,  #         'SingleInstance': 1,
498           'Attributes': {           'Attributes': {
499              'fields':        {              'fields':        {
# Line 473  def getXMLelements(updates={}): Line 513  def getXMLelements(updates={}):
513                 'Typecast': GTypecast.text,                 'Typecast': GTypecast.text,
514                 'Required': 1 } },                 'Required': 1 } },
515           'ParentTags': ('staticsetrow',) },           'ParentTags': ('staticsetrow',) },
516          'connection': {
517             'BaseClass': GConnection,
518             'Attributes': {
519                'name': {
520                   'Required': 1,
521                   'Unique': 1,
522                   'Typecast': GTypecast.name,
523                   'Description': 'TODO' },
524                'provider': {
525                   'Required': 1,
526                   'Typecast': GTypecast.name,
527                   'Description': 'TODO' },
528                'dbname': {
529                   'Required': 0,
530                   'Typecast': GTypecast.text,
531                   'Description': 'TODO' },
532                'service': {
533                   'Required': 0,
534                   'Typecast': GTypecast.text,
535                   'Description': 'TODO' },
536                'comment': {
537                   'Required': 0,
538                   'Typecast': GTypecast.text,
539                   'Description': 'TODO' },
540                'host': {
541                   'Required': 0,
542                   'Typecast': GTypecast.text,
543                   'Description': 'TODO' } },
544             'ParentTags': None,
545             'Description': 'TODO' },
546    }    }
547    
548    # Add conditional elements    # Add conditional elements
# Line 483  def getXMLelements(updates={}): Line 553  def getXMLelements(updates={}):
553    for alteration in updates.keys():    for alteration in updates.keys():
554      xmlElements[alteration].update(updates[alteration])      xmlElements[alteration].update(updates[alteration])
555    
556      # Connections will have the same parent as datasources
557      xmlElements['connection']['ParentTags'] = xmlElements['datasource']['ParentTags']
558    
559    return xmlElements    return xmlElements
560    
561    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.7.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26