public function __construct($parameters = array()) { $this->dbConnection = Main\HttpApplication::getConnection(); $this->dbHelper = $this->dbConnection->getSqlHelper(); $map = array(); if (strlen($parameters['entityName'])) { $table = $parameters['entityName']; $this->tableName = $table::getTableName(); $this->tableMap = $table::getMap(); // filter map throught $parameters['exactFields'] if (is_array($parameters['exactFields']) && !empty($parameters['exactFields'])) { foreach ($parameters['exactFields'] as $fld) { if (!isset($this->tableMap[$fld])) { throw new Main\SystemException('Field does not exist in ORM class, but present in "exactFields" parameter: ' . $fld, 0, __FILE__, __LINE__); } $map[] = $fld; $this->fldVector[$fld] = true; } } else { foreach ($this->tableMap as $fld => $params) { $map[] = $fld; $this->fldVector[$fld] = true; } } } elseif (strlen($parameters['tableName'])) { $this->tableName = $this->dbHelper->forSql($parameters['tableName']); $this->tableMap = $parameters['exactFields']; // $this->tableMap as $fld => $params - is the right way! /* required for $loc2site = new DB\BlockInserter(array( 'tableName' => 'b_sale_loc_2site', 'exactFields' => array( 'LOCATION_ID' => array('data_type' => 'integer'), 'SITE_ID' => array('data_type' => 'string') ), 'parameters' => array( 'mtu' => 9999, 'autoIncrementFld' => 'ID' ) )); */ foreach ($this->tableMap as $fld => $params) { $map[] = $fld; $this->fldVector[$fld] = true; } } // automatically insert to this field an auto-increment value // beware of TransactSQL`s IDENTITY_INSERT when setting autoIncrementFld to a database-driven auto-increment field if (strlen($parameters['parameters']['autoIncrementFld'])) { $this->autoIncFld = $this->dbHelper->forSql($this->autoIncFld); $this->autoIncFld = $parameters['parameters']['autoIncrementFld']; if (!isset($this->fldVector[$this->autoIncFld])) { $map[] = $this->autoIncFld; $this->fldVector[$this->autoIncFld] = true; $this->tableMap[$this->autoIncFld] = array('data_type' => 'integer'); } $this->initIndexFromField(); } $this->dbType = Main\HttpApplication::getConnection()->getType(); if (!($this->mtu = intval($parameters['parameters']['mtu']))) { $this->mtu = 9999; } $dbMtu = Helper::getMaxTransferUnit(); if ($this->mtu > $dbMtu) { $this->mtu = $dbMtu; } $this->insertHead = Helper::getBatchInsertHead($this->tableName, $map); $this->insertTail = Helper::getBatchInsertTail(); if (is_callable($parameters['parameters']['CALLBACKS']['ON_BEFORE_FLUSH'])) { $this->callbacks['ON_BEFORE_FLUSH'] = $parameters['parameters']['CALLBACKS']['ON_BEFORE_FLUSH']; } $this->map = $map; }