public function getConnection($user = null, $password = null, \blaze\collections\map\Properties $options = null) { if ($user === null) { $user = $this->user; } if ($password === null) { $password = $this->password; } if ($options !== null) { $options->putAll($this->options); } else { $options = new \blaze\collections\map\Properties($this->options); } if ($this->loginTimeout !== -1) { $options->put('timeout', $this->loginTimeout); } return new ConnectionImpl($this->driver, $this->host, $this->port, $this->database, $user, $password, $options); }
/** * Returns a DataSource to a ressource with the given configuration. * * @param blaze\lang\String|string $dsn The connection string to the datasource. * @param blaze\lang\String|string $uid The uid which is used to establish a connection * @param blaze\lang\String|string $pwd The password which is used to establish a connection * @param \blaze\collections\map\Properties $options Driver specific options. * @return blaze\ds\DataSource A datasource object. * @throws blaze\ds\DataSourceException Is thrown if a database error occurs. */ public function getDataSource($dsn, $uid = null, $pwd = null, \blaze\collections\map\Properties $options = null) { $matches = array(); $uri = null; $url = null; try { $uri = \blaze\net\URI::parseURI($dsn); $url = \blaze\net\URL::parseURL($uri->getSchemeSpecificPart()); } catch (blaze\lang\Exception $e) { throw $e; } if (!$uri->getScheme()->equalsIgnoreCase('bdsc')) { throw new DataSourceException('Invalid DSN'); } $driverProtocol = $url->getScheme()->toNative(); $host = $url->getHost(); $port = $url->getPort(); $database = $url->getPath()->trim('/'); $user = null; $password = null; if ($options === null) { $options = new \blaze\collections\map\Properties(); } if (strlen($url->getQuery()) != 0) { $optParts = explode('&', $url->getQuery()); if (count($optParts) != 0) { foreach ($optParts as $opt) { $optPair = explode('=', $opt); if (count($optPair) == 2) { if (strcasecmp($optPair[0], 'uid') == 0) { $user = $optPair[1]; } else { if (strcasecmp($optPair[0], 'pwd') == 0) { $password = $optPair[1]; } else { if (!$options->containsKey($optPair[0])) { $options->setProperty($optPair[0], $optPair[1]); } } } } } } } if ($uid !== null) { $user = $uid; } if ($pwd !== null) { $password = $pwd; } $options->setProperty('timeout', '' . $this->timeout); if (!array_key_exists($driverProtocol, $this->drivers)) { throw new DataSourceException('No driver found for the given url.'); } return $this->drivers[$driverProtocol]->getDataSource($host, $port, $database, $user, $password, $options); }