Ejemplo n.º 1
0
    def __updateTo(self, obj, level):
        self.db.updateObject(
            obj._objId,
            obj._objName,
            obj.getClassName(),
            self.__getObjectValue(obj),
            obj._objParentId,
            obj._objLabel,
            obj._objComment,
        )
        if obj.getObjId() in self.updateDict:
            print "id: %d found already in dict. " % obj.getObjId()
            print "FULL DICT:"
            #            for k, v in self.updateDict.iteritems():
            #                print "%d -> %s" % (k, v.getName())
            raise Exception("Circular reference, object: %s found twice" % obj.getName())

        self.updateDict[obj._objId] = obj
        for key, attr in obj.getAttributesToStore():
            if attr._objId is None:  # Insert new items from the previous state
                attr._objParentId = obj._objId
                namePrefix = self.__getNamePrefix(obj)
                attr._objName = joinExt(namePrefix, key)
                self.__insert(attr, namePrefix)
            else:
                self.__updateTo(attr, level + 2)
Ejemplo n.º 2
0
    def updateTo(self, obj, level=1):
        """obj exists in the database and has been modified outside, so it must be
        updated in the database"""
        if obj.getObjId() in self.objectsUpdatedToDb:
            for k, v in self.objectsUpdatedToDb.iteritems():
                print "%d -> %s" % (k, v.getName())
            raise Exception('Circular reference, object: %s found twice' %
                            obj.getName())

        # print "updateTo - %s %s" % (obj.getObjId(), self.__getObjectValue(obj))
        self.db.updateObject(obj.getObjId(), obj.getName(), obj.getClassName(),
                             self.__getObjectValue(obj), obj._objParentId)
        self.objDict[obj.getObjId()] = obj
        self.objectsUpdatedToDb[obj._objId] = obj

        for key, attr in obj.getAttributesToStore():
            namePrefix = self.__getNamePrefix(obj)
            name = joinExt(namePrefix, key)
            attributesInDb = self.db.selectObjectsBy(name=name)
            attr._objName = name
            attr._objParentId = obj._objId
            if attributesInDb is None:
                self.__insert(attr, namePrefix)
            else:
                attr._objId = attributesInDb[0]["id"]
                self.updateTo(attr, level + 2)

        self.objectsUpdatedToDb = {}
Ejemplo n.º 3
0
    def updateTo(self, obj, level=1):
        """obj exists in the database and has been modified outside, so it must be
        updated in the database"""
        if  obj.getObjId() in self.objectsUpdatedToDb:
            for k, v in self.objectsUpdatedToDb.iteritems():
                print "%d -> %s" % (k, v.getName())
            raise Exception('Circular reference, object: %s found twice' % obj.getName())

        # print "updateTo - %s %s" % (obj.getObjId(), self.__getObjectValue(obj))
        self.db.updateObject(obj.getObjId(), obj.getName(), obj.getClassName(),
                             self.__getObjectValue(obj), obj._objParentId)        
        self.objDict[obj.getObjId()]=obj
        self.objectsUpdatedToDb[obj._objId] = obj

        for key, attr in obj.getAttributesToStore():
            namePrefix = self.__getNamePrefix(obj)
            name = joinExt(namePrefix, key)
            attributesInDb=self.db.selectObjectsBy(name=name)
            attr._objName = name
            attr._objParentId = obj._objId
            if attributesInDb is None: 
                self.__insert(attr, namePrefix)
            else:  
                attr._objId=attributesInDb[0]["id"]
                self.updateTo(attr, level + 2)

        self.objectsUpdatedToDb={}
Ejemplo n.º 4
0
 def __insert(self, obj, namePrefix=None):
     obj._objId = self.db.insertObject(obj._objName, obj.getClassName(),
                                       self.__getObjectValue(obj), obj._objParentId)
     sid = obj.strId()
     if namePrefix is None:
         namePrefix = sid
     else:
         namePrefix = joinExt(namePrefix, sid)
     self.insertChilds(obj, namePrefix)
     return(obj._objId)
Ejemplo n.º 5
0
    def insertChild(self, obj, key, attr, namePrefix=None):
        if not hasattr(attr, "_objDoStore"):
            print "MAPPER: object '%s' doesn't seem to be an Object subclass," % attr
            print "       it does not have attribute '_objDoStore'. Insert skipped."
            return

        if namePrefix is None:
            namePrefix = self.__getNamePrefix(obj)
        attr._objName = joinExt(namePrefix, key)
        attr._objParentId = obj._objId
        self.__insert(attr, namePrefix)
Ejemplo n.º 6
0
 def __insert(self, obj, namePrefix=None):
     obj._objId = self.db.insertObject(obj._objName, obj.getClassName(),
                                       self.__getObjectValue(obj),
                                       obj._objParentId)
     sid = obj.strId()
     if namePrefix is None:
         namePrefix = sid
     else:
         namePrefix = joinExt(namePrefix, sid)
     self.insertChilds(obj, namePrefix)
     return (obj._objId)
Ejemplo n.º 7
0
    def insertChild(self, obj, key, attr, namePrefix=None):
        if not hasattr(attr, '_objDoStore'):
            print "MAPPER: object '%s' doesn't seem to be an Object subclass," % attr
            print "       it does not have attribute '_objDoStore'. Insert skipped."
            return

        if namePrefix is None:
            namePrefix = self.__getNamePrefix(obj)
        attr._objName = joinExt(namePrefix, key)
        attr._objParentId = obj._objId
        self.__insert(attr, namePrefix)
Ejemplo n.º 8
0
 def __insert(self, obj, namePrefix=None):
     if not hasattr(obj, '_objDoStore'):
         print "MAPPER: object '%s' doesn't seem to be an Object subclass," % obj
         print "       it does not have attribute '_objDoStore'. Insert skipped."
         return 
     obj._objId = self.db.insertObject(obj._objName, obj.getClassName(),
                                       self.__getObjectValue(obj), obj._objParentId,
                                       obj._objLabel, obj._objComment)
     sid = obj.strId()
     if namePrefix is None:
         namePrefix = sid
     else:
         namePrefix = joinExt(namePrefix, sid)
     self.insertChilds(obj, namePrefix)
Ejemplo n.º 9
0
 def __insert(self, obj, namePrefix=None):
     if not hasattr(obj, '_objDoStore'):
         print "MAPPER: object '%s' doesn't seem to be an Object subclass," % obj
         print "       it does not have attribute '_objDoStore'. Insert skipped."
         return
     obj._objId = self.db.insertObject(obj._objName, obj.getClassName(),
                                       self.__getObjectValue(obj),
                                       obj._objParentId, obj._objLabel,
                                       obj._objComment)
     sid = obj.strId()
     if namePrefix is None:
         namePrefix = sid
     else:
         namePrefix = joinExt(namePrefix, sid)
     self.insertChilds(obj, namePrefix)
Ejemplo n.º 10
0
    def __updateTo(self, obj, level):
        self.db.updateObject(obj._objId, obj._objName, obj.getClassName(),
                             self.__getObjectValue(obj), obj._objParentId, 
                             obj._objLabel, obj._objComment)

        if obj.getObjId() in self.updateDict:
            raise Exception('Circular reference, object: %s found twice'
                            % obj.getName())
        
        self.updateDict[obj._objId] = obj

        for key, attr in obj.getAttributesToStore():
            if attr._objId is None: # Insert new items from the previous state
                attr._objParentId = obj._objId
                namePrefix = self.__getNamePrefix(obj)
                attr._objName = joinExt(namePrefix, key)
                self.__insert(attr, namePrefix)
            else:  
                self.__updateTo(attr, level + 2)
Ejemplo n.º 11
0
    def __updateTo(self, obj, level):
        self.db.updateObject(obj._objId, obj._objName, obj.getClassName(),
                             self.__getObjectValue(obj), obj._objParentId,
                             obj._objLabel, obj._objComment)

        if obj.getObjId() in self.updateDict:
            raise Exception('Circular reference, object: %s found twice' %
                            obj.getName())

        self.updateDict[obj._objId] = obj

        for key, attr in obj.getAttributesToStore():
            if attr._objId is None:  # Insert new items from the previous state
                attr._objParentId = obj._objId
                namePrefix = self.__getNamePrefix(obj)
                attr._objName = joinExt(namePrefix, key)
                self.__insert(attr, namePrefix)
            else:
                self.__updateTo(attr, level + 2)
Ejemplo n.º 12
0
 def insertChild(self, obj, key, attr, namePrefix=None):
     if namePrefix is None:
         namePrefix = self.__getNamePrefix(obj)
     attr._objName = joinExt(namePrefix, key)
     attr._objParentId = obj._objId
     self.__insert(attr, namePrefix)
Ejemplo n.º 13
0
 def insertChild(self, obj, key, attr, namePrefix=None):
     if namePrefix is None:
         namePrefix = self.__getNamePrefix(obj)
     attr._objName = joinExt(namePrefix, key)
     attr._objParentId = obj._objId
     self.__insert(attr, namePrefix)