@@ -48,11 +48,6 @@ class MysqlAsynPool extends AsynPool
4848 */
4949 private $ active ;
5050
51- /**
52- * @var Miner 同步MySQL客户端
53- */
54- private $ mysqlClient ;
55-
5651 /**
5752 * MysqlAsynPool constructor.
5853 *
@@ -75,11 +70,7 @@ public function __construct($config, $active)
7570 public function __call ($ name , $ arguments )
7671 {
7772 $ context = array_pop ($ arguments );
78- if ($ this ->dbQueryBuilder == null ) {
79- $ this ->getDBQueryBuilder ($ context );
80- }
81-
82- return $ this ->dbQueryBuilder ->{$ name }(...$ arguments );
73+ return $ this ->getDBQueryBuilder ($ context )->{$ name }(...$ arguments );
8374 }
8475
8576 /**
@@ -260,17 +251,16 @@ public function getAsynName()
260251 }
261252
262253 /**
263- * 开启一个事务
254+ * 开启一个同步事务
264255 *
265- * @param callable $callback 执行完成后的回调函数
266256 * @param Context $context 请求上下文对象
267- * @return string
257+ * @return $this
268258 */
269- public function begin ($ callback , Context $ context = null )
259+ public function begin (Context $ context = null )
270260 {
271- $ id = $ this ->bind ($ context );
272- $ this -> query ( $ callback , $ id , ' begin ' , $ context );
273- return $ id ;
261+ $ this ->getDBQueryBuilder ($ context)-> go ( null , ' begin ' );
262+
263+ return $ this ;
274264 }
275265
276266 /**
@@ -324,25 +314,22 @@ public function query($callback, $bindId = null, $sql = null, Context $context =
324314 * @param Context $context 请求上下文对象
325315 * @return MySql
326316 */
327- public function coroutineBegin (Context $ context = null )
317+ public function goBegin (Context $ context = null )
328318 {
329- if ($ this ->dbQueryBuilder == null ) {
330- $ this ->getDBQueryBuilder ($ context );
331- }
332319 $ id = $ this ->bind ($ context );
333- return $ this ->dbQueryBuilder ->go ($ id , 'begin ' );
320+ return $ this ->getDBQueryBuilder ( $ context ) ->go ($ id , 'begin ' );
334321 }
335322
336323 /**
337- * 提交一个事务
324+ * 提交一个同步事务
338325 *
339326 * @param Context $context 请求上下文对象
340- * @param string $callback 执行完成后的回调函数
341- * @param int $id 绑定ID
327+ * @return $this
342328 */
343- public function commit ($ callback , $ id , Context $ context = null )
329+ public function commit (Context $ context = null )
344330 {
345- $ this ->query ($ callback , $ id , 'commit ' , $ context );
331+ $ this ->getDBQueryBuilder ($ context )->go (null , 'commit ' );
332+ return $ this ;
346333 }
347334
348335 /**
@@ -352,24 +339,21 @@ public function commit($callback, $id, Context $context = null)
352339 * @param int $id 绑定ID
353340 * @return MySql
354341 */
355- public function coroutineCommit ($ id , Context $ context = null )
342+ public function goCommit ($ id , Context $ context = null )
356343 {
357- if ($ this ->dbQueryBuilder == null ) {
358- $ this ->getDBQueryBuilder ($ context );
359- }
360- return $ this ->dbQueryBuilder ->go ($ id , 'commit ' );
344+ return $ this ->getDBQueryBuilder ($ context )->go ($ id , 'commit ' );
361345 }
362346
363347 /**
364348 * 回滚
365349 *
366350 * @param Context $context 请求上下文对象
367- * @param callable $callback 执行完成后的回调函数
368- * @param int $id 绑定ID
351+ * @return $this
369352 */
370- public function rollback ($ callback , $ id , Context $ context = null )
353+ public function rollback (Context $ context = null )
371354 {
372- $ this ->query ($ callback , $ id , 'rollback ' , $ context );
355+ $ this ->getDBQueryBuilder ($ context )->go (null , 'rollback ' );
356+ return $ this ;
373357 }
374358
375359 /**
@@ -379,26 +363,25 @@ public function rollback($callback, $id, Context $context = null)
379363 * @param int $id 绑定ID
380364 * @return MySql
381365 */
382- public function coroutineRollback ($ id , Context $ context = null )
366+ public function goRollback ($ id , Context $ context = null )
383367 {
384- if ($ this ->dbQueryBuilder == null ) {
385- $ this ->getDBQueryBuilder ($ context );
386- }
387- return $ this ->dbQueryBuilder ->go ($ id , 'rollback ' );
368+ return $ this ->getDBQueryBuilder ($ context )->go ($ id , 'rollback ' );
388369 }
389370
390371 /**
391372 * 获取同步
373+ *
374+ * @param Context $context 请求上下文对象
392375 * @return Miner
393376 */
394- public function getSync ()
377+ public function getSync (Context $ context = null )
395378 {
396- if (isset ($ this ->mysqlClient )) {
397- return $ this ->mysqlClient ;
398- }
399379 $ activeConfig = $ this ->config ['mysql ' ][$ this ->active ];
400- $ this ->mysqlClient = new Miner ();
401- $ this ->mysqlClient ->pdoConnect ($ activeConfig );
402- return $ this ->mysqlClient ;
380+ $ client = $ this ->getDBQueryBuilder ($ context );
381+ if ($ client ->getPdoConnection () === null ) {
382+ return $ client ->pdoConnect ($ activeConfig );
383+ } else {
384+ return $ client ;
385+ }
403386 }
404387}
0 commit comments