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);
 }
 /**
  * @param PDO $pdo
  * @param HermitProcedureParameter $parameter
  * @return HermitResultSet
  */
 public static function create(PDO $pdo, ReflectionMethod $method, HermitAnnote $annote, HermitProcedureParameter $parameter)
 {
     $dbms = HermitDatabaseMetaFactory::getDbms($pdo);
     if (isset(self::$resultsets[$dbms])) {
         $className = self::$resultsets[$dbms];
         return new $className($method, $annote, $parameter);
     }
     return new HermitProcedureResultSet($method, $annote, $parameter);
 }
 protected function getStaticSqlCreator(PDO $pdo)
 {
     $dbms = HermitDatabaseMetaFactory::getDbms($pdo);
     $sql = $this->annote->getSql($this->method, $dbms);
     if (null !== $sql) {
         return new HermitStaticSqlCreator($sql);
     }
     $sql = $this->annote->getFile($this->method, $dbms);
     if (null !== $sql) {
         return new HermitStaticSqlCreator($sql);
     }
     return null;
 }
 protected function createProcedureSqlCreator(PDO $pdo)
 {
     $dbms = HermitDatabaseMetaFactory::getDbms($pdo);
     $sql = $this->annote->getProcedure($this->method);
     if (null !== $sql) {
         return new HermitProcedureCallSqlCreator($sql);
     }
     $sql = $this->annote->getSql($this->method, $dbms);
     if (null !== $sql) {
         return new HermitProcedureCallSqlCreator($sql);
     }
     $sql = $this->annote->getFile($this->method);
     if (null !== $sql) {
         return new HermitProcedureCallSqlCreator($sql);
     }
     throw new BadMethodCallException('method: "' . $this->method->getName() . '" was not apply to Procedure command');
 }
Esempio n. 5
0
function db_init(PDO $pdo)
{
    $name = HermitDatabaseMetaFactory::getDbms($pdo);
    $_db_init = 'db_' . $name . '_init';
    $_db_init($pdo);
    $sqlpath = dirname(__FILE__) . '/resource/test-' . $name . '.sql.php';
    if (file_exists($sqlpath)) {
        require $sqlpath;
        $_db_query = 'db_' . $name . '_query_test';
        $_db_query($pdo);
    } else {
        $sqlpath = dirname(__FILE__) . '/resource/test-' . $name . '.sql';
        try {
            $pdo->beginTransaction();
            $pdo->exec(file_get_contents($sqlpath));
            $pdo->commit();
        } catch (PDOException $e) {
            $pdo->rollback();
            echo (string) $e, PHP_EOL;
            throw new RuntimeException(__FUNCTION__ . ' does not complete');
        }
    }
    $sqlpath = dirname(__FILE__) . '/resource/procedure-' . $name . '.sql.php';
    if (file_exists($sqlpath)) {
        require $sqlpath;
        $_db_query = 'db_' . $name . '_query_procedure';
        $_db_query($pdo);
    } else {
        $sqlpath = dirname(__FILE__) . '/resource/procedure-' . $name . '.sql';
        try {
            $pdo->beginTransaction();
            $pdo->exec(file_get_contents($sqlpath));
            $pdo->commit();
        } catch (PDOException $e) {
            $pdo->rollback();
            echo (string) $e, PHP_EOL;
            throw new RuntimeException(__FUNCTION__ . ' does not complete');
        }
    }
}