/** * This function returns an instance of the appropriate pre-compiler for the * specified data source/config. * * @access public * @static * @param mixed $config the data source configurations * @return DB_SQL_Precompiler an instance of the pre-compiler */ public static function precompiler($config = 'default') { $data_source = DB_DataSource::instance($config); $precompiler = 'DB_' . $data_source->dialect . '_Precompiler'; $object = new $precompiler($data_source); return $object; }
/** * This constructor instantiates this class using the specified model's name. * * @access public * @param string $model the model's name */ public function __construct($model) { $name = $model; $model = DB_ORM_Model::model_name($name); $this->data_source = DB_DataSource::instance($model::data_source(DB_DataSource::MASTER_INSTANCE)); $builder = 'DB_' . $this->data_source->dialect . '_Insert_Builder'; $this->builder = new $builder($this->data_source); $extension = DB_ORM_Model::builder_name($name); if (class_exists($extension)) { $this->extension = new $extension($this->builder); } $table = $model::table(); $this->builder->into($table); $this->model = $model; }
/** * This function returns a connection to the appropriate database based * on the specified configurations. * * @access public * @static * @param mixed $config the data source configurations * @return DB_Connection_Driver the database connection */ public static function factory($config = 'default') { $data_source = DB_DataSource::instance($config); $driver = 'DB_' . $data_source->dialect . '_Connection_' . $data_source->driver; $connection = new $driver($data_source); return $connection; }
/** * This constructor instantiates this class using the specified data source. * * @access public * @param mixed $config the data source configurations */ public function __construct($config) { $this->data_source = DB_DataSource::instance($config); $builder = 'DB_' . $this->data_source->dialect . '_Insert_Builder'; $this->builder = new $builder($this->data_source); }
/** * This constructor instantiates this class using the specified data source. * * @access public * @param mixed $config the data source configurations */ public function __construct($config) { $this->data_source = DB_DataSource::instance($config); $precompiler = 'DB_' . $this->data_source->dialect . '_Precompiler'; $this->precompiler = new $precompiler(); }
/** * This constructor instantiates this class using the specified model's name. * * @access public * @param string $model the model's name * @param array $columns the columns to be selected */ public function __construct($model, array $columns = array()) { $name = $model; $model = DB_ORM_Model::model_name($name); $this->data_source = DB_DataSource::instance($model::data_source(DB_DataSource::SLAVE_INSTANCE)); $builder = 'DB_' . $this->data_source->dialect . '_Select_Builder'; $this->table = $model::table(); $this->builder = new $builder($this->data_source, $columns); if (empty($columns)) { $this->builder->all("{$this->table}.*"); } $this->builder->from($this->table); $extension = DB_ORM_Model::builder_name($name); if (class_exists($extension)) { $this->extension = new $extension($this->builder); } $this->model = $model; }
/** * This function returns the appropriate connection from the pool. When there are * multiple connections created from the same data source, the last opened connection * will be returned when $new is set to "FALSE." * * @access public * @param mixed $config the data source configurations * @param boolean $new whether to create a new connection * @return DB_Connection_Driver the appropriate connection * @throws Throwable_Database_Exception indicates that no new connections * can be added */ public function get_connection($config = 'default', $new = FALSE) { $data_source = DB_DataSource::instance($config); if (isset($this->pool[$data_source->id]) and !empty($this->pool[$data_source->id])) { if ($new) { foreach ($this->pool[$data_source->id] as $connection) { if (!$connection->is_connected()) { $connection->open(); return $connection; } } } else { $connection = end($this->pool[$data_source->id]); do { if ($connection->is_connected()) { reset($this->pool[$data_source->id]); return $connection; } } while ($connection = prev($this->pool[$data_source->id])); $connection = end($this->pool[$data_source->id]); reset($this->pool[$data_source->id]); $connection->open(); return $connection; } } if ($this->count() >= $this->settings['max_size']) { throw new Throwable_Database_Exception('Message: Failed to create new connection. Reason: Exceeded maximum number of connections that may be held in the pool.', array(':source' => $data_source, ':new' => $new)); } $connection = DB_Connection_Driver::factory($data_source); $connection->open(); $connection_id = $connection->__hashCode(); $this->pool[$data_source->id][$connection_id] = $connection; $this->lookup[$connection_id] = $data_source->id; return $connection; }
/** * This constructor instantiates this class using the specified data source. * * @access public * @param mixed $config the data source configurations * @param array $columns the columns to be selected */ public function __construct($config, array $columns = array()) { $this->data_source = DB_DataSource::instance($config); $builder = 'DB_' . $this->data_source->dialect . '_Select_Builder'; $this->builder = new $builder($this->data_source, $columns); }