public function __construct(\blaze\collections\map\Properties $properties, \blaze\collections\ListI $ressources) { $driverName = $properties->getProperty('persistence.connection.datasource.class'); $dsUsername = $properties->getProperty('persistence.connection.datasource.username'); $dsPassword = $properties->getProperty('persistence.connection.datasource.password'); $dsOptions = $properties->getProperty('persistence.connection.datasource.options'); if ($driverName != null) { $dsClass = \blaze\lang\ClassWrapper::forName($driverName); $dsHost = $properties->getProperty('persistence.connection.datasource.host'); $dsPort = $properties->getProperty('persistence.connection.datasource.port'); $dsDatabase = $properties->getProperty('persistence.connection.datasource.database'); $this->ds = $dsClass->getMethod('getDataSource')->invokeArgs(null, array($dsHost, $dsPort, $dsDatabase, $dsUsername, $dsPassword, $dsOptions)); } else { $dsn = $properties->getProperty('persistence.connection.datasource.url'); $this->ds = \blaze\ds\DataSourceManager::getInstance()->getDataSource($dsn, $dsUsername, $dsPassword, $dsOptions); } $this->dialect = \blaze\lang\ClassWrapper::forName($properties->getProperty('persistence.dialect'))->newInstance(); foreach ($ressources as $ressource) { $this->loadMapping($ressource); } $this->properties = $properties; $this->ressources = $ressources; $this->freeConnections = new \blaze\collections\queue\Stack(); $this->usedConnections = new \blaze\collections\map\HashMap(); }
public function __construct($driver, $host, $port, $database, $user, $password, \blaze\collections\map\Properties $options = null) { $opts = array(); if ($options !== null) { $timeout = $options->remove('timeout'); if ($timeout !== null && $timeout > 0) { $opts[PDO::ATTR_TIMEOUT] = $timeout; } foreach ($options as $key => $value) { $opts[$key] = $value; } } $opts[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $this->driver = $driver; $this->host = $host; $this->port = $port; $this->database = $database; $this->user = $user; $this->password = $password; $this->options = $options; $dsn = $driver . ':host=' . $host . ';port=' . $port . ';dbname=' . $database; try { $this->pdo = new PDO($dsn, $user, $password, $opts); } catch (\PDOException $e) { throw new \blaze\ds\DataSourceException($e->getMessage(), $e->getCode(), $e); } }
/** * {@inheritDoc} */ public function buildCache(\blaze\collections\map\Properties $properties = null) { if ($properties === null) { return new LocalCache(null); } else { return new LocalCache($properties->get('cacheDir')); } }
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); }