Checks whether a transaction is currently active.
public isTransactionActive ( ) : boolean | ||
return | boolean | TRUE if a transaction is currently active, FALSE otherwise. |
public function shutdown() { if ($this->connection->isTransactionActive()) { $this->rollback(); } $this->connection->close(); }
/** * {@inheritDoc} */ public function selectGlobal() { if ($this->conn->isTransactionActive()) { throw ShardingException::activeTransaction(); } $sql = "USE FEDERATION ROOT WITH RESET"; $this->conn->exec($sql); $this->currentDistributionValue = null; }
/** * {@inheritdoc} */ public function register(EventDispatcher $dispatcher) { $dispatcher->addListener(RouteMatchedEvent::class, function (RouteMatchedEvent $event) { $annotation = $this->getTransactionalAnnotation($event->getRouteMatch()); if ($annotation) { $this->connection->setTransactionIsolation($annotation->getIsolationLevel()); $this->connection->beginTransaction(); } }); $dispatcher->addListener(ControllerInvocatedEvent::class, function (ControllerInvocatedEvent $event) { $annotation = $this->getTransactionalAnnotation($event->getRouteMatch()); if ($annotation) { if ($this->connection->isTransactionActive()) { $this->connection->rollback(); } } }); }
/** * {@inheritDoc} */ public function selectShard($distributionValue) { if ($this->conn->isTransactionActive()) { throw ShardingException::activeTransaction(); } if ($distributionValue === null || is_bool($distributionValue) || !is_scalar($distributionValue)) { throw ShardingException::noShardDistributionValue(); } $platform = $this->conn->getDatabasePlatform(); $sql = sprintf("USE FEDERATION %s (%s = %s) WITH RESET, FILTERING = %s;", $platform->quoteIdentifier($this->federationName), $platform->quoteIdentifier($this->distributionKey), $this->conn->quote($distributionValue), $this->filteringEnabled ? 'ON' : 'OFF'); $this->conn->exec($sql); $this->currentDistributionValue = $distributionValue; }
/** * Check the migration of a table on a copy so we can detect errors before messing with the real table * * @param \Doctrine\DBAL\Schema\Table $table * @throws \OC\DB\MigrationException */ protected function checkTableMigrate(Table $table) { $name = $table->getName(); $tmpName = $this->generateTemporaryTableName($name); $this->copyTable($name, $tmpName); //create the migration schema for the temporary table $tmpTable = $this->renameTableSchema($table, $tmpName); $schemaConfig = new SchemaConfig(); $schemaConfig->setName($this->connection->getDatabase()); $schema = new Schema(array($tmpTable), array(), $schemaConfig); try { $this->applySchema($schema); $this->dropTable($tmpName); } catch (DBALException $e) { // pgsql needs to commit it's failed transaction before doing anything else if ($this->connection->isTransactionActive()) { $this->connection->commit(); } $this->dropTable($tmpName); throw new MigrationException($table->getName(), $e->getMessage()); } }
public function testNoTransactionActiveByDefault() { $this->assertFalse($this->_conn->isTransactionActive()); }
/** * {@inheritDoc} */ public function isTransactionActive() { $this->setTransactionNestingLevel($this->getPersistedTransactionNestingLevel()); return parent::isTransactionActive(); }
/** * @return bool */ public function isTransactionActive() { return $this->connection->isTransactionActive(); }
/** * @group DBAL-81 */ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() { $driverMock = $this->getMock('Doctrine\\DBAL\\Driver'); $driverMock->expects($this->any())->method('connect')->will($this->returnValue(new DriverConnectionMock())); $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); $conn->connect(); $conn->beginTransaction(); $conn->beginTransaction(); $conn->setAutoCommit(false); $this->assertSame(1, $conn->getTransactionNestingLevel()); $conn->beginTransaction(); $conn->beginTransaction(); $conn->setAutoCommit(true); $this->assertFalse($conn->isTransactionActive()); }
/** * Safe rollback. * * @return void */ public function rollback() { if ($this->db->isTransactionActive()) { $this->db->rollBack(); } }