Ejemplo n.º 1
0
 /**
  * 创建数据
  * @param array $request_data
  * @return int
  * @throws MyRuntimeException
  */
 public function create($requestData, $dbInstance = NULL)
 {
     try {
         //TODO 先申请资源ID流程再请求DB实例
         // TODO 根据$requestData组织特征向量做dbInstance;
         if (!array_key_exists('id', $requestData)) {
             // 先去seqservice 申请 id
             $seqService = $this->getSeqService();
             $seqId = $seqService->nextSeq($this->objectName);
             $requestData['id'] = $seqId;
         }
         is_null($dbInstance) && ($dbInstance = $this->servRouteInstance->getDbInstance($this->objectName, array('id' => $requestData['id']))->getInstance());
         $daoInstance = DaoDb::factory($this->objectName, $dbInstance);
         $data = $daoInstance->asArray();
         foreach ($requestData as $key => $val) {
             array_key_exists($key, $data) && ($daoInstance->{$key} = $val);
         }
         $daoInstance->save();
         if ($daoInstance->saved !== TRUE) {
             throw new MyRuntimeException(_('internal error'), 500);
         }
         //TODO 逻辑与数据分离:状态与数据分离
         return $daoInstance->id;
     } catch (MyRuntimeException $ex) {
         //TODO 自定义逻辑
         throw $ex;
     }
 }
Ejemplo n.º 2
0
 public function currentSeq($objectName = '')
 {
     $dbInstance = $this->getDbInstance();
     $daoInstance = DaoDb::factory($this->objectName . $objectName, $dbInstance);
     $queryStruct = array('orderSet' => array(array('id' => 'DESC')), 'limitOffset' => array('limit' => 1));
     $resultVar = $daoInstance->queryVar($queryStruct);
     return !empty($resultVar) ? intval($resultVar) : 0;
 }
Ejemplo n.º 3
0
 /**
  * 查询数据统计结果
  * @param array $queryStruct
  * @return int
  * @throws MyRuntimeException
  */
 public function queryCount($queryStruct = array(), $dbInstance = NULL)
 {
     try {
         // TODO 根据$queryStruct组织特征向量做dbInstance;
         $routeSet = array();
         if (!empty($queryStruct) && isset($queryStruct['conditionKey']) && isset($queryStruct['conditionKey']['id'])) {
             $routeSet = array('id' => $queryStruct['conditionKey']['id']);
         }
         if (!empty($routeSet)) {
             is_null($dbInstance) && ($dbInstance = $this->servRouteInstance->getDbInstance($this->objectName, $routeSet)->getInstance());
         } else {
             is_null($dbInstance) && ($dbInstance = $this->servRouteInstance->getDbInstance($this->objectName)->getInstance());
         }
         $daoInstance = DaoDb::factory($this->objectName, $dbInstance);
         return $daoInstance->queryCount($queryStruct);
     } catch (MyRuntimeException $ex) {
         //TODO 自定义逻辑
         throw $ex;
     }
 }