/**
  * @override
  */
 public function bind(PDOStatement $stmt, $value)
 {
     $param = $value[0];
     $param->__init__();
     $logger = HermitLoggerManager::getLogger();
     if ($logger->isDebugEnabled()) {
         $buf = '';
         foreach ($this->bindKeys as $key) {
             $v = null;
             if ($param instanceof HermitParam) {
                 $v = $param->get($key);
             } else {
                 $method = $this->reflector->getMethod('get' . ucfirst($key));
                 $v = $method->invoke($param);
             }
             $buf .= $key . ' => ' . $v;
             $buf .= ', ';
         }
         $logger->debug('{%s} statement binds parameter {:key => param} = %s', __CLASS__, $buf);
     }
     foreach ($this->bindKeys as $index => $key) {
         if ($this->info->typeofIn($key)) {
             $stmt->bindValue(':' . $key, $param->get($key));
         }
     }
 }
 public function build(PDO $pdo, array $inputParameters)
 {
     self::checkProcedureParameter($this->method);
     $procedureName = $this->annote->getProcedure($this->method);
     $meta = HermitDatabaseMetaFactory::get($pdo);
     $info = $meta->getProcedureInfo($procedureName);
     $dbms = HermitDatabaseMetaFactory::getDbms($pdo);
     $parameter = null;
     if (isset(self::$procedureParameters[$dbms])) {
         $className = self::$procedureParameters[$dbms];
         $parameter = new $className($info, $dbms);
     } else {
         $parameter = new HermitProcedureParameter($info, $dbms);
     }
     $parameter->setInputParameters($inputParameters);
     $parameter->setTargetClass($this->targetClass);
     $parameter->setTargetMethod($this->method);
     $sql = self::preparedSql($parameter, $this->sqlCreator->createSql());
     $logger = HermitLoggerManager::getLogger();
     if ($logger->isDebugEnabled()) {
         $logger->debug('{%s} preparedSql: "%s"', __CLASS__, $sql);
     }
     $statement = $pdo->prepare($sql);
     return new HermitDefaultStatement($parameter, $statement);
 }
 public function rebuild(HermitSqlParameter $parameter, PDO $pdo, $sql)
 {
     $sql = self::preparedSql($parameter, $sql);
     $logger = HermitLoggerManager::getLogger();
     if ($logger->isDebugEnabled()) {
         $logger->debug('{%s} preparedSql: "%s"', __CLASS__, $sql);
     }
     $statement = $pdo->prepare($sql);
     return new HermitDefaultStatement($parameter, $statement);
 }
 public function bind(PDOStatement $stmt, $value)
 {
     $logger = HermitLoggerManager::getLogger();
     if ($logger->isDebugEnabled()) {
         $buf = '';
         foreach ($this->names as $name => $pos) {
             $buf .= ':' . $name . ' => ' . $value[$pos];
         }
         $logger->debug('{%s} statement binds parameter {:key => param} = %s', __CLASS__, $buf);
     }
     foreach ($this->names as $name => $pos) {
         $stmt->bindValue(':' . $name, $value[$pos]);
     }
 }
示例#5
0
 public function __construct($targetClass, $timeout = self::DEFAULT_QUEUE_TIMEOUT)
 {
     $hermit = new parent($targetClass);
     $it = new HermitQueueIterator($hermit);
     $reflector = $hermit->context->getTargetClass();
     if (!$reflector->hasConstant('TABLE')) {
         throw new RuntimeException($hermit->context->getName() . ' has not constant "TABLE"');
     }
     $it->setTable($reflector->getConstant('TABLE'));
     $it->setTimeout($timeout);
     $this->queue = $hermit;
     $this->iterator = $it;
     $this->filter = new HermitQueueFilter($it);
     $this->logger = HermitLoggerManager::getLogger();
     register_shutdown_function(array($this, '__destruct'));
 }
 public function bind(PDOStatement $stmt, $value)
 {
     $logger = HermitLoggerManager::getLogger();
     if ($logger->isDebugEnabled()) {
         $buf = '';
         foreach ($value as $obj) {
             foreach ($this->bindKeys as $key) {
                 $v = null;
                 if ($obj instanceof HermitParam) {
                     $v = $obj->get($key);
                 } else {
                     $methodName = 'get' . ucfirst($key);
                     if ($this->reflector->hasMethod($methodName)) {
                         $method = $this->reflector->getMethod($methodName);
                         $v = $method->invoke($obj);
                     } else {
                         if (!isset($obj->{$key})) {
                             continue;
                         }
                         $v = $obj->{$key};
                     }
                 }
                 $buf .= $key . ' => ' . $v;
                 $buf .= ', ';
             }
         }
         $logger->debug('{%s} statement binds parameter {:key => param} = %s', __CLASS__, $buf);
     }
     foreach ($value as $obj) {
         foreach ($this->bindKeys as $key) {
             if ($obj instanceof HermitParam) {
                 $stmt->bindValue(':' . $key, $obj->get($key));
             } else {
                 $methodName = 'get' . ucfirst($key);
                 if ($this->reflector->hasMethod($methodName)) {
                     $method = $this->reflector->getMethod($methodName);
                     $stmt->bindValue(':' . $key, $method->invoke($obj));
                 } else {
                     if (!isset($obj->{$key})) {
                         continue;
                     }
                     $stmt->bindValue(':' . $key, $obj->{$key});
                 }
             }
         }
     }
 }
 public function bind(PDOStatement $stmt, $value)
 {
     $logger = HermitLoggerManager::getLogger();
     if ($logger->isDebugEnabled()) {
         $buf = '';
         foreach ($this->names as $name => $pos) {
             $buf .= $pos . ' => ' . join(',', $value[$pos]);
         }
         $logger->debug('{%s} statement binds parameter {:index => param} = %s', __CLASS__, $buf);
     }
     foreach ($this->names as $name => $pos) {
         $index = 0;
         foreach ($value[$pos] as $v) {
             $stmt->bindValue(self::key_prefix . $name . $index++, $v);
         }
     }
 }
示例#8
0
 public function __construct(HermitQueueIterator $queue)
 {
     $this->queue = $queue;
     $this->logger = HermitLoggerManager::getLogger();
 }
示例#9
0
 public static function init()
 {
     self::$logger = new HermitNopLogger();
 }