Connection.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace common\replaces;
  3. use yii\db\Transaction;
  4. /**
  5. * 兼容mycat的操作
  6. * @Author bing
  7. * @DateTime 2021-10-14 10:42:07
  8. * @copyright: Copyright (c) 2020 广东七件事集团
  9. */
  10. class Connection extends \yii\db\Connection
  11. {
  12. /**
  13. * @var array An array of [[setQueryBuilder()]] calls, holding the passed arguments.
  14. * Is used to restore a QueryBuilder configuration after the connection close/open cycle.
  15. *
  16. * @see restoreQueryBuilderConfiguration()
  17. */
  18. private $_queryBuilderConfigurations = [];
  19. /**
  20. * @var Transaction the currently active transaction
  21. */
  22. private $_transaction;
  23. /**
  24. * @var Schema the database schema
  25. */
  26. private $_schema;
  27. /**
  28. * @var string driver name
  29. */
  30. private $_driverName;
  31. /**
  32. * @var Connection|false the currently active master connection
  33. */
  34. private $_master = false;
  35. /**
  36. * @var Connection|false the currently active slave connection
  37. */
  38. private $_slave = false;
  39. /**
  40. * @var array query cache parameters for the [[cache()]] calls
  41. */
  42. private $_queryCacheInfo = [];
  43. /**
  44. * @var string[] quoted table name cache for [[quoteTableName()]] calls
  45. */
  46. private $_quotedTableNames;
  47. /**
  48. * @var string[] quoted column name cache for [[quoteColumnName()]] calls
  49. */
  50. private $_quotedColumnNames;
  51. /**
  52. * Starts a transaction.
  53. * @param string|null $isolationLevel The isolation level to use for this transaction.
  54. * See [[Transaction::begin()]] for details.
  55. * @return Transaction the transaction initiated
  56. */
  57. public function beginTransaction($isolationLevel = null)
  58. {
  59. $this->open();
  60. if (($transaction = $this->getTransaction()) === null) {
  61. $transaction = $this->_transaction = new Transaction(['db' => $this]);
  62. $transaction->begin($isolationLevel);
  63. }
  64. return $transaction;
  65. }
  66. public function getTransaction()
  67. {
  68. return $this->_transaction && $this->_transaction->getIsActive() ? $this->_transaction : null;
  69. }
  70. }