/**
  * Connect to the database
  *
  * @throws     AgaviDatabaseException If a connection could not be established
  *
  * @author     Simon Thulbourn <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  */
 protected function connect()
 {
     if ($this->hasParameter('adapter') && $this->hasParameter('adapter[class]')) {
         $cls = $this->getParameter('adapter[class]');
         if ($this->hasParameter('adapter[arguments]')) {
             // we have ctor arguments for our adapter
             // must use reflection for this
             $rcls = new ReflectionClass($cls);
             $rcls->newInstanceArgs($this->getParameter('adapter[arguments]'));
         } else {
             $adapter = new $cls();
         }
     } else {
         $adapter = null;
     }
     $con = new \phpcouch\connection\Connection($this->getParameter('uri'), $adapter);
     \phpcouch\Phpcouch::registerConnection($this->getParameter('name', $this->getName()), $con, $this->getParameter('default', true));
     $this->connection = $this->resource = $con;
     if ($this->hasParameter('database')) {
         $this->database = $this->getConnection()->retrieveDatabase($this->getParameter('database'));
     }
 }