Ejemplo n.º 1
0
    def _GetConnection(self):
        """
        Creates a new database connection. Works before startup and application setup.
        """
        if self._dbpool:
            try:
                return self._dbpool.usedconnection
            except:
                pass

        cTag = self.dbConfiguration.connection
        poolTag = self.dbConfiguration.context
        if cTag:
            connObj = GetClassRef(cTag, self.reloadExtensions, True, None)
            connObj = connObj(config=self.dbConfiguration, connectNow=False)
            return connObj
        if self._dbpool:
            return self._dbpool.CreateConnection(self.dbConfiguration)
        if not cTag and not poolTag:
            raise TypeError, "Database connection type not set. application.dbConfiguration.connection and application.dbConfiguration.context is empty. Use Sqlite or Mysql!"
        poolTag = self.dbConfiguration.context
        if not poolTag:
            raise TypeError, "Database type not set. application.dbConfiguration.context is empty. Use Sqlite or Mysql!"
        elif poolTag.lower() in ("sqlite", "sqlite3"):
            poolTag = "nive.utils.dataPool2.sqlite.sqlite3Pool.Sqlite3"
        elif poolTag.lower() == "mysql":
            poolTag = "nive.utils.dataPool2.mysql.mySqlPool.MySql"
        elif poolTag.lower() in ("postgres", "postgresql"):
            poolTag = "nive.utils.dataPool2.postgres.postgreSqlPool.PostgreSql"
        dbObj = GetClassRef(poolTag, self.reloadExtensions, True, None)
        return dbObj._DefaultConnection(config=self.dbConfiguration,
                                        connectNow=False)
Ejemplo n.º 2
0
    def _GetConnection(self):
        """
        Creates a new database connection. Works before startup and application setup.
        """
        if self._dbpool:
            try:
                return self._dbpool.usedconnection
            except:
                pass

        cTag = self.dbConfiguration.connection
        poolTag = self.dbConfiguration.context
        if cTag:
            connObj = GetClassRef(cTag, self.reloadExtensions, True, None)
            connObj = connObj(config=self.dbConfiguration, connectNow=False)
            return connObj
        if self._dbpool:
            return self._dbpool.CreateConnection(self.dbConfiguration)
        if not cTag and not poolTag:
            raise TypeError, "Database connection type not set. application.dbConfiguration.connection and application.dbConfiguration.context is empty. Use Sqlite or Mysql!"
        poolTag = self.dbConfiguration.context
        if not poolTag:
            raise TypeError, "Database type not set. application.dbConfiguration.context is empty. Use Sqlite or Mysql!"
        elif poolTag.lower() in ("sqlite", "sqlite3"):
            poolTag = "nive.utils.dataPool2.sqlite.sqlite3Pool.Sqlite3"
        elif poolTag.lower() == "mysql":
            poolTag = "nive.utils.dataPool2.mysql.mySqlPool.MySql"
        elif poolTag.lower() in ("postgres", "postgresql"):
            poolTag = "nive.utils.dataPool2.postgres.postgreSqlPool.PostgreSql"
        dbObj = GetClassRef(poolTag, self.reloadExtensions, True, None)
        return dbObj._DefaultConnection(config=self.dbConfiguration, connectNow=False)
Ejemplo n.º 3
0
 def _GetObj(self, conf):
     # creates state and transition objects
     name = conf["id"]
     tag = conf["context"]
     wfObj = GetClassRef(tag, self.app_.reloadExtensions, True, None)
     wfObj = wfObj(name, conf, self)
     return wfObj
Ejemplo n.º 4
0
 def _GetToolObj(self, name, contextObject):
     """
     creates the tool object
     """
     if isinstance(name, basestring):
         conf = self.GetToolConf(name, contextObject)
         if isinstance(conf, (list, tuple)):
             conf = conf[0]
     else:
         conf = name
     if not conf:
         iface, conf = ResolveConfiguration(name)
         if not conf:
             raise ImportError, "Tool not found. Please load the tool by referencing the tool id. (%s)" % (str(name))
     tag = conf.context
     toolObj = GetClassRef(tag, self.reloadExtensions, True, None)
     toolObj = toolObj(conf, self)
     if not _IGlobal.providedBy(contextObject):
         toolObj.__parent__ = contextObject
     return toolObj
Ejemplo n.º 5
0
    def _GetWfObj(self, name, contextObject):
        """
        creates the root object
        """
        wfConf = None
        if isinstance(name, basestring):
            wfConf = self.GetWorkflowConf(name, contextObject)
            if isinstance(wfConf, (list, tuple)):
                wfConf = wfConf[0]
        if not wfConf:
            iface, wfConf = ResolveConfiguration(name)
            if not wfConf:
                raise ImportError, "Workflow process not found. Please load the workflow by referencing the process id. (%s)" % (str(name))

        wfTag = wfConf.context
        wfObj = GetClassRef(wfTag, self.reloadExtensions, True, None)
        wfObj = wfObj(wfConf, self)
        if not _IGlobal.providedBy(contextObject):
            wfObj.__parent__ = contextObject
        return wfObj
Ejemplo n.º 6
0
    def _GetWfObj(self, name, contextObject):
        """
        creates the root object
        """
        wfConf = None
        if isinstance(name, basestring):
            wfConf = self.GetWorkflowConf(name, contextObject)
            if isinstance(wfConf, (list, tuple)):
                wfConf = wfConf[0]
        if not wfConf:
            iface, wfConf = ResolveConfiguration(name)
            if not wfConf:
                raise ImportError, "Workflow process not found. Please load the workflow by referencing the process id. (%s)" % (
                    str(name))

        wfTag = wfConf.context
        wfObj = GetClassRef(wfTag, self.reloadExtensions, True, None)
        wfObj = wfObj(wfConf, self)
        if not _IGlobal.providedBy(contextObject):
            wfObj.__parent__ = contextObject
        return wfObj
Ejemplo n.º 7
0
 def _GetToolObj(self, name, contextObject):
     """
     creates the tool object
     """
     if isinstance(name, basestring):
         conf = self.GetToolConf(name, contextObject)
         if isinstance(conf, (list, tuple)):
             conf = conf[0]
     else:
         conf = name
     if not conf:
         iface, conf = ResolveConfiguration(name)
         if not conf:
             raise ImportError, "Tool not found. Please load the tool by referencing the tool id. (%s)" % (
                 str(name))
     tag = conf.context
     toolObj = GetClassRef(tag, self.reloadExtensions, True, None)
     toolObj = toolObj(conf, self)
     if not _IGlobal.providedBy(contextObject):
         toolObj.__parent__ = contextObject
     return toolObj
Ejemplo n.º 8
0
    def _GetDataPoolObj(self, cachedDbConnection=None):
        """
        creates the database object
        """
        if not self.dbConfiguration:
            raise ConfigurationError, "Database configuration empty. application.dbConfiguration is None."
        poolTag = self.dbConfiguration.context
        if not poolTag:
            raise TypeError, "Database type not set. application.dbConfiguration.context is empty. Use Sqlite or Mysql!"
        elif poolTag.lower() in ("sqlite", "sqlite3"):
            poolTag = "nive.utils.dataPool2.sqlite.sqlite3Pool.Sqlite3"
        elif poolTag.lower() == "mysql":
            poolTag = "nive.utils.dataPool2.mysql.mySqlPool.MySql"
        elif poolTag.lower() in ("postgres", "postgresql"):
            poolTag = "nive.utils.dataPool2.postgres.postgreSqlPool.PostgreSql"

        # if a database connection other than the default is configured
        if cachedDbConnection is not None:
            connObj = cachedDbConnection
        elif self.dbConfiguration.connection:
            connObj = GetClassRef(self.dbConfiguration.connection,
                                  self.reloadExtensions, True, None)
            connObj = connObj(config=self.dbConfiguration, connectNow=False)
        else:
            connObj = None

        dbObj = GetClassRef(poolTag, self.reloadExtensions, True, None)
        conn = self.dbConfiguration
        dbObj = dbObj(
            connection=connObj,
            connParam=
            conn,  # use the default connection defined in db if connection is none
            structure=self._structure,
            root=conn.fileRoot,
            useTrashcan=conn.useTrashcan,
            dbCodePage=conn.dbCodePage,
            debug=conn.querylog[0],
            log=conn.querylog[1])
        return dbObj