Example #1
0
 def Close(self):
     """
     Close the object and all contained objects. Currently only used in combination with caches.
     
     Event
     - close()
     """
     self.Signal("close")
     if ICache.providedBy(self):
         # opt
         for o in self.GetAllFromCache():
             o.Close()
         p = self.parent
         if ICache.providedBy(p):
             p.RemoveCache(self.id)
     self.dbEntry.Close()
Example #2
0
 def Close(self):
     """
     Close the object and all contained objects. Currently only used in combination with caches.
     
     Event
     - close()
     """
     self.Signal("close")
     if ICache.providedBy(self):
         #opt
         for o in self.GetAllFromCache():
             o.Close()
         p = self.parent
         if ICache.providedBy(p):
             p.RemoveCache(self.id)
     self.dbEntry.Close()
Example #3
0
    def _GetObjBatch(self, ids, parentObj=None, **kw):
        """
        Load multiple objects at once.
        """
        if len(ids) == 0:
            return []
        useCache = ICache.providedBy(self)
        objs = []
        if useCache:
            load = []
            for id in ids:
                o = self.GetFromCache(id)
                if o:
                    objs.append(o)
                else:
                    load.append(id)
            if len(load) == 0:
                return objs
            ids = load

        app = self.app
        entries = app.db.GetBatch(ids, preload="all", **kw)

        # create object for type
        if not parentObj:
            parentObj = self
        securityContext = kw.get("securityContext")
        permission = kw.get("permission")
        for dbEntry in entries:
            obj = None
            type = dbEntry.meta.get("pool_type")
            if not type:
                continue
            configuration = app.GetObjectConf(type, skipRoot=1)
            if not configuration:
                continue
            obj = ClassFactory(configuration,
                               app.reloadExtensions,
                               True,
                               base=None)
            obj = obj(dbEntry.id,
                      dbEntry,
                      parent=parentObj,
                      configuration=configuration,
                      **kw)

            # check security if context passed in keywords
            if securityContext and permission:
                if not has_permission(permission, obj, securityContext):
                    continue

            if useCache:
                self.Cache(obj, obj.id)
            objs.append(obj)
        return objs
Example #4
0
    def _GetObj(self, id, dbEntry = None, parentObj = None, configuration = None, **kw):
        """
        Loads and initializes the object. ::
        
            id = id of the object to be loaded
            dbEntry = the database entry. Will be loaded automatically if None
            parentObj = if a different parent than the container
            configuration = the object configuration to be loaded
            returns the object or None
            
        """
        useCache = ICache.providedBy(self)
        if useCache:
            o = self.GetFromCache(id)
            if o:
                return o
        app = self.app
        if not dbEntry:
            # check restraints
            qr = kw.get("queryRestraints",None)
            if qr!=False:
                root = self.root()
                p,o = root.ObjQueryRestraints(self)
                p["id"] = id
                p["pool_unitref"] = self.id
                e = root.Select(parameter=p, operators=o)
                if len(e)==0:
                    return None

            dbEntry = app.db.GetEntry(id, **kw)
            if not dbEntry:
                return None
                #raise Exception, "NotFound"

            if dbEntry.meta["pool_unitref"]!=self.id:
                raise ContainmentError, "Object is not a child (%s)" % (str(id))

        # create object for type
        if not parentObj:
            parentObj = self
        obj = None
        if not configuration:
            type = dbEntry.GetMetaField("pool_type")
            if not type:
                # broken entry 
                #raise ConfigurationError, "Empty type"
                return None
            configuration = app.GetObjectConf(type)
            if not configuration:
                raise ConfigurationError, "Type not found (%s)" % (str(type))
        obj = ClassFactory(configuration, app.reloadExtensions, True, base=None)
        obj = obj(id, dbEntry, parent=parentObj, configuration=configuration, **kw)
        if useCache:
            self.Cache(obj, obj.id)
        return obj
Example #5
0
 def Close(self):
     """
     Close the root and all contained objects. Currently only used in combination with caches.
     
     Event
     - close()
     """
     self.Signal("close")
     if ICache.providedBy(self):
         #opt
         for o in self.GetAllFromCache():
             o.Close()
     return
Example #6
0
 def Close(self):
     """
     Close the root and all contained objects. Currently only used in combination with caches.
     
     Event
     - close()
     """
     self.Signal("close")
     if ICache.providedBy(self):
         #opt
         for o in self.GetAllFromCache():
             o.Close()
     return
Example #7
0
    def _GetObjBatch(self, ids, parentObj = None, **kw):
        """
        Load multiple objects at once.
        """
        if len(ids)==0:
            return []
        useCache = ICache.providedBy(self)
        objs = []
        if useCache:
            load = []
            for id in ids:
                o = self.GetFromCache(id)
                if o:
                    objs.append(o)
                else:
                    load.append(id)
            if len(load)==0:
                return objs
            ids = load

        app = self.app
        entries = app.db.GetBatch(ids, preload="all", **kw)

        # create object for type
        if not parentObj:
            parentObj = self
        securityContext = kw.get("securityContext")
        permission = kw.get("permission")
        for dbEntry in entries:
            obj = None
            type = dbEntry.meta.get("pool_type")
            if not type:
                continue
            configuration = app.GetObjectConf(type, skipRoot=1)
            if not configuration:
                continue
            obj = ClassFactory(configuration, app.reloadExtensions, True, base=None)
            obj = obj(dbEntry.id, dbEntry, parent=parentObj, configuration=configuration, **kw)

            # check security if context passed in keywords
            if securityContext and permission:
                if not has_permission(permission, obj, securityContext):
                    continue

            if useCache:
                self.Cache(obj, obj.id)
            objs.append(obj)
        return objs
Example #8
0
    def _GetObj(self,
                id,
                dbEntry=None,
                parentObj=None,
                configuration=None,
                **kw):
        """
        Loads and initializes the object. ::
        
            id = id of the object to be loaded
            dbEntry = the database entry. Will be loaded automatically if None
            parentObj = if a different parent than the container
            configuration = the object configuration to be loaded
            returns the object or None
            
        """
        useCache = ICache.providedBy(self)
        if useCache:
            o = self.GetFromCache(id)
            if o:
                return o
        app = self.app
        if not dbEntry:
            # check restraints
            qr = kw.get("queryRestraints", None)
            if qr != False:
                root = self.dataroot
                p, o = root.ObjQueryRestraints(self)
                p["id"] = id
                p["pool_unitref"] = self.id
                e = root.Select(parameter=p, operators=o)
                if len(e) == 0:
                    return None

            dbEntry = app.db.GetEntry(id, **kw)
            if not dbEntry:
                return None
                #raise Exception, "NotFound"

            if dbEntry.meta["pool_unitref"] != self.id:
                raise ContainmentError, "Object is not a child (%s)" % (
                    str(id))

        # create object for type
        if not parentObj:
            parentObj = self
        obj = None
        if not configuration:
            type = dbEntry.GetMetaField("pool_type")
            if not type:
                # broken entry
                #raise ConfigurationError, "Empty type"
                return None
            configuration = app.GetObjectConf(type)
            if not configuration:
                raise ConfigurationError, "Type not found (%s)" % (str(type))
        obj = ClassFactory(configuration,
                           app.reloadExtensions,
                           True,
                           base=None)
        obj = obj(id,
                  dbEntry,
                  parent=parentObj,
                  configuration=configuration,
                  **kw)

        # check security if context passed in keywords
        if kw.get("securityContext") and kw.get("permission"):
            if not has_permission(kw["permission"], obj,
                                  kw["securityContext"]):
                raise PermissionError, "Permission check failed (%s)" % (
                    str(id))

        if useCache:
            self.Cache(obj, obj.id)
        return obj