/**
  * @see \Components\Persistence_Resource::driver() \Components\Persistence_Resource::driver()
  *
  * @return \PDO
  */
 public function driver()
 {
     if (null === $this->m_driver) {
         if ($host = $this->m_uri->getHost()) {
             $dsn = "{$this->m_uri->getScheme()}:host={$host}";
             $database = $this->m_uri->getPathParam(0);
             $username = $this->m_uri->getUsername();
             $password = $this->m_uri->getPassword();
         } else {
             $dsn = "{$this->m_uri->getScheme()}:unix_socket={$this->m_uri->getPath()}";
             $database = $this->m_uri->getFragment();
             $username = $this->m_uri->getQueryParam('username');
             $password = $this->m_uri->getQueryParam('password');
         }
         $create = false;
         try {
             if (0 !== Persistence::$debugMode & Persistence::BIT_LOG_STATEMENTS) {
                 Log::debug('persistence/resource/pdo', 'Connecting to database [%s;dbname=%s].', $dsn, $database);
             }
             $this->m_driver = new \PDO("{$dsn};dbname={$database}", $username, $password, $this->driverOptions());
         } catch (\PDOException $e) {
             if (Persistence_Exception_Pdo::ERROR_UNKNOWN_DATABASE === $e->getCode() && Boolean::valueIsTrue($this->m_uri->getQueryParam('create'))) {
                 $create = true;
             } else {
                 throw new Persistence_Exception_Pdo('persistence/resource/pdo', 'Failed to connect to database.', $e);
             }
         }
         if ($create) {
             try {
                 if (0 !== Persistence::$debugMode & Persistence::BIT_LOG_STATEMENTS) {
                     Log::debug('persistence/resource/pdo', 'Connecting to database [%s].', $dsn);
                 }
                 $this->m_driver = new \PDO($dsn, $username, $password, $this->driverOptions());
             } catch (\PDOException $e) {
                 throw new Persistence_Exception_Pdo('persistence/resource/pdo', 'Failed to connect to database system.', $e);
             }
             $this->createDatabase($database, $username);
             $this->execute("USE {$database};");
         }
         // TODO (CSH) Can be added to driverOptions()?
         $this->m_driver->setAttribute(\PDO::ATTR_AUTOCOMMIT, $this->m_uri->hasQueryParam('autocommit') && Boolean::valueIsTrue($this->m_uri->getQueryParam('autocommit')));
     }
     return $this->m_driver;
 }
 /**
  * @see \Components\Persistence_Resource::driver() \Components\Persistence_Resource::driver()
  *
  * @return \MongoClient
  */
 public function driver()
 {
     if (null === $this->m_driver) {
         if (Boolean::valueIsTrue($this->m_uri->getQueryParam('isolate'))) {
             $this->m_isolated = true;
             $this->m_uri->removeQueryParam('isolate');
         }
         if ($this->m_uri->getHost()) {
             $this->m_databaseName = $this->m_uri->getPathParam(0);
             $this->m_connectionString = (string) $this->m_uri;
             $this->m_connectionOptions = [];
         } else {
             $this->m_databaseName = $this->m_uri->getFragment();
             $this->m_connectionString = "mongodb://{$this->m_uri->getPath()}";
             $this->m_connectionOptions = $this->m_uri->getQueryParams();
         }
         if ($this->m_isolated) {
             $this->m_databaseNameIsolated = $this->m_databaseName . '_' . Runtime::getInstanceNamespace();
         }
         if (0 !== Persistence::$debugMode & Persistence::BIT_LOG_STATEMENTS) {
             Log::debug('persistence/resource/mongodb', 'Connecting to database [%s].', $this);
         }
         $this->m_driver = new \MongoClient($this->m_connectionString, $this->m_connectionOptions);
     }
     return $this->m_driver;
 }
 protected function initialize()
 {
     $a = Annotations::get($this->entityType);
     $this->entityName = Runtime_Classloader::lookupName($this->entityType);
     if ($annotation = $a->getTypeAnnotation(Annotation_Name::NAME)) {
         $this->collectionName = $a->getTypeAnnotation(Annotation_Name::NAME)->value;
     } else {
         $this->collectionName = strtolower(substr($this->entityType, strrpos($this->entityType, '_') + 1));
     }
     if ($annotation = $a->getTypeAnnotation(Annotation_Collection::NAME)) {
         $this->collectionType = Runtime_Classloader::lookup($annotation->value);
     } else {
         $this->collectionType = Entity_Collection::TYPE;
     }
     $this->autoIncrement = true;
     foreach ($a->getPropertyAnnotations() as $property => $annotations) {
         if (isset($annotations[Annotation_Id::NAME])) {
             $this->collectionPrimaryKey = $property;
             $this->collectionPrimaryKeyAutoIncrement = Boolean::valueIsTrue($annotations[Annotation_Id::NAME]->auto);
         }
     }
 }