/**
  * Prepare the database connection instance.
  *
  * @param  \Database\Connection  $connection
  * @return \Database\Connection
  */
 protected function prepare(Connection $connection)
 {
     $connection->setFetchMode($this->app['config']['database.fetch']);
     if ($this->app->bound('events')) {
         $connection->setEventDispatcher($this->app['events']);
     }
     $app = $this->app;
     $connection->setCacheManager(function () use($app) {
         return $app['cache'];
     });
     $connection->setPaginator(function () use($app) {
         return $app['paginator'];
     });
     $connection->setReconnector(function ($connection) {
         $this->reconnect($connection->getName());
     });
     return $connection;
 }