Skip to content

Commit

Permalink
[DDC-2757] Update documentation with regard to manually closing the E…
Browse files Browse the repository at this point in the history
…ntityManager when an Exception occurs.
  • Loading branch information
beberlei committed Oct 26, 2013
1 parent cedcac2 commit 514dd4e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions docs/en/reference/transactions-and-concurrency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ looks like this:
$em->getConnection()->commit();
} catch (Exception $e) {
$em->getConnection()->rollback();
$em->close();
throw $e;
}
Expand All @@ -81,14 +80,12 @@ require an active transaction. Such methods will throw a
``TransactionRequiredException`` to inform you of that
requirement.

A more convenient alternative for explicit transaction demarcation
is the use of provided control abstractions in the form of
``Connection#transactional($func)`` and
``EntityManager#transactional($func)``. When used, these control
abstractions ensure that you never forget to rollback the
transaction or close the ``EntityManager``, apart from the obvious
code reduction. An example that is functionally equivalent to the
previously shown code looks as follows:
A more convenient alternative for explicit transaction demarcation is the use
of provided control abstractions in the form of
``Connection#transactional($func)`` and ``EntityManager#transactional($func)``.
When used, these control abstractions ensure that you never forget to rollback
the transaction, in addition to the obvious code reduction. An example that is
functionally equivalent to the previously shown code looks as follows:

.. code-block:: php
Expand All @@ -104,8 +101,8 @@ previously shown code looks as follows:
The difference between ``Connection#transactional($func)`` and
``EntityManager#transactional($func)`` is that the latter
abstraction flushes the ``EntityManager`` prior to transaction
commit and also closes the ``EntityManager`` properly when an
exception occurs (in addition to rolling back the transaction).
commit and rolls back the transaction when an
exception occurs.

Exception Handling
~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 514dd4e

Please sign in to comment.