commit example

$this->query('RELEASE SAVEPOINT ' . $name);
      }
    }
  }

  /** * Do the actual commit, invoke post-commit callbacks. * * @internal */
  protected function doCommit() {
    $success = $this->connection->commit();
    if (!empty($this->rootTransactionEndCallbacks)) {
      $callbacks = $this->rootTransactionEndCallbacks;
      $this->rootTransactionEndCallbacks = [];
      foreach ($callbacks as $callback) {
        call_user_func($callback$success);
      }
    }

    if (!$success) {
      throw new TransactionCommitFailedException();
    }
  }


            // use SELECT ... FOR UPDATE to lock table             $stmt = $this->executeQuery(
                $sql.' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
                $query->getParameters(),
                $query->getParameterTypes()
            );
            $doctrineEnvelope = $stmt instanceof Result ? $stmt->fetchAssociative() : $stmt->fetch();

            if (false === $doctrineEnvelope) {
                $this->driverConnection->commit();
                $this->queueEmptiedAt = microtime(true) * 1000;

                return null;
            }
            // Postgres can "group" notifications having the same channel and payload             // We need to be sure to empty the queue before blocking again             $this->queueEmptiedAt = null;

            $doctrineEnvelope = $this->decodeEnvelopeHeaders($doctrineEnvelope);

            $queryBuilder = $this->driverConnection->createQueryBuilder()
                
$this->assertSame('saveDeferred', $call->name);
        $this->assertSame(['k' => true]$call->result);
        $this->assertSame(0, $call->hits);
        $this->assertSame(0, $call->misses);
        $this->assertNotEmpty($call->start);
        $this->assertNotEmpty($call->end);
    }

    public function testCommitTrace()
    {
        $pool = $this->createCachePool();
        $pool->commit();
        $calls = $pool->getCalls();
        $this->assertCount(1, $calls);

        $call = $calls[0];
        $this->assertSame('commit', $call->name);
        $this->assertTrue($call->result);
        $this->assertSame(0, $call->hits);
        $this->assertSame(0, $call->misses);
        $this->assertNotEmpty($call->start);
        $this->assertNotEmpty($call->end);
    }
}
$operations = json_decode($queue->getOperations(), true);

        // Wrap all this into a transaction in order to speed up the progress         // and to be able to roll it back at some point         $connection->beginTransaction();

        try {
            $details = $this->getQueue()->pop($queueId$this->getConfig()->getByNamespace('SwagMultiEdit', 'batchItemsPerRequest', 512));

            if (!empty($details)) {
                $this->updateDetails($details$operations);
                $connection->commit();
            }
        } catch (Exception $e) {
            $connection->rollBack();
            throw new RuntimeException(sprintf('Error updating details: %s', $e->getMessage()), 0, $e);
        }
        $remaining = $queue->getArticleDetails()->count();

        if ($remaining === 0) {
            $entityManager->remove($queue);
            $entityManager->flush();
        }

        
foreach ($entry->getRecipients() as $recipient) {
                    $mail = mb_strtolower(trim($recipient->getMailAddress()));

                    $this->connection->insert('s_mail_log_recipient', [
                        'log_id' => $mailLogId,
                        'contact_id' => $recipient->getId() ?: (int) $contacts[$mail],
                    ]);
                }
            }

            $this->connection->commit();
        } catch (Exception $exception) {
            $this->connection->rollback();
            throw $exception;
        }
    }

    /** * The error logger will in some cases try to send an e-mail when an uncaught exception occurs. * E-Mails are sent via register_shutdown_function in this case and therefore after the * KernelEvents::TERMINATE Event, so we have to make sure flush() is called anyway. */
    
return true;
    }

    /** * {@inheritdoc} * * @deprecated - Native return and parameter type will be added with Shopware 5.8 */
    #[ReturnTypeWillChange]     public function close()
    {
        $this->commit();

        while ($unlockStmt = array_shift($this->unlockStatements)) {
            $unlockStmt->execute();
        }

        if ($this->gcCalled) {
            $this->gcCalled = false;

            // delete the session records that have expired             $sql = "DELETE FROM $this->table WHERE $this->expiryCol < :time";

            
// if we cannot generate a unique series it is not worth trying further         if ($tmpSeries === $token->getSeries()) {
            return;
        }

        $this->conn->beginTransaction();
        try {
            $this->deleteTokenBySeries($tmpSeries);
            $lastUsed = \DateTime::createFromInterface($lastUsed);
            $this->createNewToken(new PersistentToken($token->getClass()$token->getUserIdentifier()$tmpSeries$token->getTokenValue()$lastUsed));

            $this->conn->commit();
        } catch (\Exception $e) {
            $this->conn->rollBack();
            throw $e;
        }
    }

    /** * Adds the Table to the Schema if "remember me" uses this Connection. * * @param \Closure $isSameDatabase */
    

class DoctrineTransactionMiddleware extends AbstractDoctrineMiddleware
{
    protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope
    {
        $entityManager->getConnection()->beginTransaction();
        try {
            $envelope = $stack->next()->handle($envelope$stack);
            $entityManager->flush();
            $entityManager->getConnection()->commit();

            return $envelope;
        } catch (\Throwable $exception) {
            $entityManager->getConnection()->rollBack();

            if ($exception instanceof HandlerFailedException) {
                // Remove all HandledStamp from the envelope so the retry will execute all handlers again.                 // When a handler fails, the queries of allegedly successful previous handlers just got rolled back.                 throw new HandlerFailedException($exception->getEnvelope()->withoutAll(HandledStamp::class)$exception->getNestedExceptions());
            }

            

        return $this->doSave($item, __FUNCTION__);
    }

    public function saveDeferred(CacheItemInterface $item): bool
    {
        return $this->doSave($item, __FUNCTION__);
    }

    public function commit(): bool
    {
        return $this->pool->commit();
    }

    private function doSave(CacheItemInterface $item, string $method): bool
    {
        if (!$item instanceof CacheItem) {
            return false;
        }
        $castItem = (array) $item;

        if (null === $castItem["\0*\0expiry"] && 0 < $this->defaultLifetime) {
            $castItem["\0*\0expiry"] = microtime(true) + $this->defaultLifetime;
        }
foreach ($items as $key => $item) {
            if ($valuesIsArray) {
                $item->set($values[$key]);
            }
            if (null !== $ttl) {
                $item->expiresAfter($ttl);
            }
            $ok = $this->pool->saveDeferred($item) && $ok;
        }

        return $this->pool->commit() && $ok;
    }

    public function deleteMultiple($keys): bool
    {
        if ($keys instanceof \Traversable) {
            $keys = iterator_to_array($keys, false);
        } elseif (!\is_array($keys)) {
            throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given.', get_debug_type($keys)));
        }

        try {
            

        $this->connID->autocommit(false);

        return $this->connID->begin_transaction();
    }

    /** * Commit Transaction */
    protected function _transCommit(): bool
    {
        if ($this->connID->commit()) {
            $this->connID->autocommit(true);

            return true;
        }

        return false;
    }

    /** * Rollback Transaction */
    
->setParameter(':interval', $interval)
                ->execute();

            $queryBuilder->delete('s_user')
                ->where('doubleOptinEmailSentDate < NOW() - INTERVAL :interval DAY')
                ->andWhere('doubleOptinConfirmDate IS NULL')
                ->andWhere('doubleOptinRegister = true')
                ->andWhere('active = 0')
                ->setParameter(':interval', $interval)
                ->execute();

            $this->connection->commit();
        } catch (DBALException $exp) {
            return false;
        }

        return true;
    }
}


    public function testCommit()
    {
        $adapter = $this->createCachePool();

        $item = $adapter->getItem('key');
        $this->assertFalse($item->isHit());
        $this->assertNull($item->get(), "Item's value must be null when isHit is false.");

        $this->assertTrue($adapter->saveDeferred($item));
        $this->assertTrue($this->createCachePool()->commit());
    }
}


        return $saved;
    }

    public function commit(): bool
    {
        $committed = true;
        $i = $this->adapterCount;

        while ($i--) {
            $committed = $this->adapters[$i]->commit() && $committed;
        }

        return $committed;
    }

    public function prune(): bool
    {
        $pruned = true;

        foreach ($this->adapters as $adapter) {
            if ($adapter instanceof PruneableInterface) {
                

        $this->dbalConnection->beginTransaction();
    }

    /** * Commit a transaction. * * @return void */
    protected function _commit()
    {
        $this->dbalConnection->commit();
    }

    /** * Roll-back a transaction. * * @return void */
    protected function _rollBack()
    {
        $this->dbalConnection->rollBack();
    }

    
Home | Imprint | This part of the site doesn't use cookies.