documentStore

Module documentStore |
[hide private]
[frames] | no frames]

## Source Code for Module documentStore

      1
      2  from baseObjects import DocumentStore
      3  from c3errors import *
      4  from document import StringDocument
      5  from baseStore import BdbStore, BdbIter
      6
      7  try:
      8      # name when installed by hand
      9      import bsddb3 as bdb
     10  except:
     11      # name that comes in python 2.3
     12      import bsddb as bdb
     13
     14
     15 -class SimpleDocumentStore(DocumentStore):
     16      inPreParser = None
     17      outPreParser = None
     18      inWorkflow = None
     19      outWorkflow = None
     20
     21 -    def __init__(self, session, node, parent):
     22          if (not self.paths):
     23              DocumentStore.__init__(self, session, node, parent)
     24          self.inPreParser = self.get_path(None, 'inPreParser')
     25          self.outPreParser = self.get_path(None, 'outPreParser')
     26          self.inWorkflow = self.get_path(None, 'inWorkflow')
     27          self.outWorkflow = self.get_path(None, 'outWorkflow')
     28
     29
     30 -    def create_document(self, session, doc=None):
     31          id = self.generate_id(session)
     32          if (doc == None):
     33              # Create a placeholder
     34              doc = StringDocument("")
     35          else:
     36              doc.id = id
     37
     38          try:
     39              self.store_document(session, doc)
     40          except ObjectAlreadyExistsException:
     41              self.currentId -= 1
     42              raise
     43          except:
     44              raise
     45          return id
     46
     47 -    def store_document(self, session, doc):
     48          doc.documentStore = self.id
     49          if (self.inPreParser <> None):
     50              doc = self.inPreParser.process_document(session, doc)
     51          data = doc.get_raw()
     52          self.store_data(session, doc.id, data, doc.size)
     53
     54 -    def fetch_document(self, session, id):
     55          data = self.fetch_data(session, id)
     56          if (data):
     57              if (self.outPreParser <> None):
     58                  doc = StringDocument(data)
     59                  doc = self.outPreParser.process_document(session, doc)
     60              else:
     61                  doc = StringDocument(data)
     62              doc.id = id
     63              doc.documentStore = self.id
     64              doc.parent = ('document', self.id, id)
     65              return doc
     66          else:
     67              return None
     68
     69 -    def delete_document(self, session, id):
     70          self.delete_item(session, id)
     71
     72
     73
     74 -class BdbDocIter(BdbIter):
     75 -    def next(self):
     76          d = BdbIter.next(self)
     77          doc = StringDocument(d[1])
     78          doc.id = d[0]
     79          return doc
     80
     81
     82 -class BdbDocumentStore(BdbStore, SimpleDocumentStore):
     83      # Instantiate some type of simple doc store
     84 -    def __init__(self, session, node, parent):
     85          BdbStore.__init__(self, session, node, parent)
     86          SimpleDocumentStore.__init__(self, session, node, parent)
     87
     88 -    def __iter__(self):
     89          return BdbDocIter(self)
     90
     91
     92
     93
     94
     95  try:
     96      from baseStore import SrbStore, SrbBdbCombineStore
     97
     98      class SrbDocumentStore(SrbStore, SimpleDocumentStore):
     99          def __init__(self, session, node, parent):
    100              SrbStore.__init__(self, session, node, parent)
    101              SimpleDocumentStore.__init__(self, session, node, parent)

102 103 class CachingSrbDocumentStore(SrbBdbCombineStore, SimpleDocumentStore): 104 def __init__(self, session, node, parent): 105 SrbBdbCombineStore. __init__(self, session, node, parent) 106 SimpleDocumentStore. __init__(self, session, node, parent) 107 108 except: 109 pass 110