Return database singleton instance.

    This function will always return the same database instance for the same
    connection_string. It stores instances in a dict saved as an attribute of
    this function.
339742
def database(connection_string, db_class=SimplDB):
    
    if not hasattr(database, "singletons"):
        database.singletons = {}
    if connection_string not in database.singletons:
        instance = db_class(connection_string)
        database.singletons[connection_string] = instance
    return database.singletons[connection_string]
1331912
private function _getDefaultDB()
    {
        // For ReadDatabase checking Master first
        if ($this->_db) {
            return $this->_db;
        }
        
        if (!isset($this->db)) {
            get_instance()->load->database();
        }
        // No need to set as reference because $this->db is refered to &DB already.
        return get_instance()->db;
    }
554649
def get_db(db_name=None):
    
    import pymongo
    return pymongo.Connection(host=DB_HOST,
                              port=DB_PORT)[db_name]
821342
def _database_create(self, engine, database):
        
        logger.info('Creating database "%s" in "%s"', database, engine)
        database_operation(engine, 'create', database)
        url = copy(engine.url)
        url.database = database
        return str(url)
813979
public synchronized Connection getConnection() throws DatabaseException {
        initialize();
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(connectionString, userName, password);
        } catch (SQLException ex) {
            LOGGER.debug("", ex);
            throw new DatabaseException("Unable to connect to the database", ex);
        }
        return conn;
    }
1265832
def create(cls):
        
        obj = cls(
            id=uuid.uuid4(),
            writable=True,
            readable=False,
            size=0,
        )
        db.session.add(obj)
        return obj
64883
def _check_db_exists(self, instance):
        

        dsn, host, username, password, database, driver = self._get_access_info(instance, self.DEFAULT_DB_KEY)
        context = "{} - {}".format(host, database)
        if self.existing_databases is None:
            cursor = self.get_cursor(instance, None, self.DEFAULT_DATABASE)

            try:
                self.existing_databases = {}
                cursor.execute(DATABASE_EXISTS_QUERY)
                for row in cursor:
                    self.existing_databases[row.name] = True

            except Exception as e:
                self.log.error("Failed to check if database {} exists: {}".format(database, e))
                return False, context
            finally:
                self.close_cursor(cursor)

        return database in self.existing_databases, context
56126
static function getInstance($databaseNameOrResource = '*LOCAL', $userOrI5NamingFlag = '', $password = '', $transportType = '', $isPersistent = false)
    {
        return new Toolkit($databaseNameOrResource, $userOrI5NamingFlag, $password, $transportType, $isPersistent);
    }
246642
def _get_instance(self, **kwargs):
        '''
        '''
        return session.query(self.response_class).filter_by(**kwargs).first()
635932
def db(self, connection_string=None):
        """"""

        connection_string = connection_string or self.settings["db"]

        if not hasattr(self, "_db_conns"):
            self._db_conns = {}
        if not connection_string in self._db_conns:
            self._db_conns[connection_string] = oz.sqlalchemy.session(connection_string=connection_string)

        return self._db_conns[connection_string]
1197832
static function getInstance($databaseNameOrResource = '*LOCAL', $userOrI5NamingFlag = '', $password = '', $extensionPrefix = '', $isPersistent = false, $forceNew = false)
    {
        // if we're forcing a new instance, close db conn first if exists.
        if ($forceNew && self::hasInstance() && isset(self::$instance->conn))
        {
            self::$instance->disconnect();
        }

        // if we're forcing a new instance, or an instance hasn't been created yet, create one
        if ($forceNew || self::$instance == NULL) {
            $toolkitService = __CLASS__;
            self::$instance = new $toolkitService($databaseNameOrResource, $userOrI5NamingFlag, $password, $extensionPrefix, $isPersistent);
        }

        if (self::$instance) {
            // instance exists
            return self::$instance;
        } else {
            // some problem
            return false;
        }
    }
944210
def retrieve_instances(self, query=None):
        
        if query is None:
            data = javabridge.call(self.jobject, "retrieveInstances", "()Lweka/core/Instances;")
        else:
            data = javabridge.call(self.jobject, "retrieveInstances", "(Ljava/lang/String;)Lweka/core/Instances;")
        return Instances(data)
947892
def database(self):
        
        if self._database:
            return self._database
        if self._recordSet is not None:
            return self._recordSet.database()
        else:
            return Orb.instance().database()
273695
def _get_database(self, database_name):
        
        try:
            return self._client[database_name]
        except InvalidName as ex:
            raise DataSourceError("Cannot connect to database %s!"
                                  % self._database) from ex
982870
protected DBInstance getDbInstance(String identifier) throws IllegalStateException {
		DBInstance instance;
		try {
			DescribeDBInstancesResult describeDBInstancesResult = this.amazonRds
					.describeDBInstances(new DescribeDBInstancesRequest()
							.withDBInstanceIdentifier(identifier));
			instance = describeDBInstancesResult.getDBInstances().get(0);
		}
		catch (DBInstanceNotFoundException e) {
			throw new IllegalStateException(MessageFormat.format(
					"No database instance with id:''{0}'' found. Please specify a valid db instance",
					identifier));
		}
		return instance;
	}
84729
def using_db(self, _db: BaseDBAsyncClient) -> "QuerySet":
        
        queryset = self._clone()
        queryset._db = _db
        return queryset
184002
def get_instance(model, instance_id):
    
    try:
        model = get_model(model)
    except ImportError:
        return None

    return model.query.get(instance_id)