Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
5dbd4056
Commit
5dbd4056
authored
May 13, 2010
by
Roman S. Borschel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added control abstractions for transaction demarcation.
parent
e62b51cf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
6 deletions
+67
-6
Connection.php
lib/Doctrine/DBAL/Connection.php
+23
-1
EntityManager.php
lib/Doctrine/ORM/EntityManager.php
+28
-1
UnitOfWork.php
lib/Doctrine/ORM/UnitOfWork.php
+2
-0
ConnectionTest.php
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
+10
-0
BasicFunctionalTest.php
tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
+4
-4
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
5dbd4056
...
...
@@ -19,7 +19,7 @@
namespace
Doctrine\DBAL
;
use
PDO
,
Closure
,
use
PDO
,
Closure
,
Exception
,
Doctrine\DBAL\Types\Type
,
Doctrine\DBAL\Driver\Connection
as
DriverConnection
,
Doctrine\Common\EventManager
,
...
...
@@ -705,6 +705,28 @@ class Connection implements DriverConnection
return
$this
->
_conn
->
lastInsertId
(
$seqName
);
}
/**
* Executes a function in a transaction.
*
* The function gets passed this Connection instance as an (optional) parameter.
*
* If an exception occurs during execution of the function or transaction commit,
* the transaction is rolled back and the exception re-thrown.
*
* @param Closure $func The function to execute transactionally.
*/
public
function
transactional
(
Closure
$func
)
{
$this
->
beginTransaction
();
try
{
$func
(
$this
);
$this
->
commit
();
}
catch
(
Exception
$e
)
{
$this
->
rollback
();
throw
$e
;
}
}
/**
* Starts a transaction by suspending auto-commit mode.
*
...
...
lib/Doctrine/ORM/EntityManager.php
View file @
5dbd4056
...
...
@@ -19,7 +19,8 @@
namespace
Doctrine\ORM
;
use
Doctrine\Common\EventManager
,
use
Closure
,
Exception
,
Doctrine\Common\EventManager
,
Doctrine\DBAL\Connection
,
Doctrine\ORM\Mapping\ClassMetadata
,
Doctrine\ORM\Mapping\ClassMetadataFactory
,
...
...
@@ -176,6 +177,32 @@ class EntityManager
$this
->
_conn
->
beginTransaction
();
}
/**
* Executes a function in a transaction.
*
* The function gets passed this EntityManager instance as an (optional) parameter.
*
* {@link flush} is invoked prior to transaction commit.
*
* If an exception occurs during execution of the function or flushing or transaction commit,
* the transaction is rolled back, the EntityManager closed and the exception re-thrown.
*
* @param Closure $func The function to execute transactionally.
*/
public
function
transactional
(
Closure
$func
)
{
$this
->
_conn
->
beginTransaction
();
try
{
$func
(
$this
);
$this
->
flush
();
$this
->
_conn
->
commit
();
}
catch
(
Exception
$e
)
{
$this
->
close
();
$this
->
_conn
->
rollback
();
throw
$e
;
}
}
/**
* Commits a transaction on the underlying database connection.
*
...
...
lib/Doctrine/ORM/UnitOfWork.php
View file @
5dbd4056
...
...
@@ -1290,6 +1290,8 @@ class UnitOfWork implements PropertyChangedListener
* @return object The managed copy of the entity.
* @throws OptimisticLockException If the entity uses optimistic locking through a version
* attribute and the version check against the managed copy fails.
*
* @todo Require active transaction!? OptimisticLockException may result in undefined state!?
*/
public
function
merge
(
$entity
)
{
...
...
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
View file @
5dbd4056
...
...
@@ -59,6 +59,16 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
_conn
->
rollback
();
$this
->
assertEquals
(
0
,
$this
->
_conn
->
getTransactionNestingLevel
());
}
$this
->
assertEquals
(
0
,
$this
->
_conn
->
getTransactionNestingLevel
());
try
{
$this
->
_conn
->
transactional
(
function
(
$conn
)
{
$conn
->
executeQuery
(
"select 1"
);
throw
new
\RuntimeException
(
"Ooops!"
);
});
}
catch
(
\RuntimeException
$expected
)
{
$this
->
assertEquals
(
0
,
$this
->
_conn
->
getTransactionNestingLevel
());
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
View file @
5dbd4056
...
...
@@ -643,9 +643,10 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$address
->
zip
=
'12345'
;
$user
->
setAddress
(
$address
);
$this
->
_em
->
persist
(
$user
);
$this
->
_em
->
flush
();
$this
->
_em
->
transactional
(
function
(
$em
)
use
(
$user
)
{
$em
->
persist
(
$user
);
});
$this
->
_em
->
clear
();
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
...
...
@@ -661,7 +662,6 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
assertEquals
(
'Germany'
,
$address2
->
country
);
$this
->
assertEquals
(
'Berlin'
,
$address2
->
city
);
$this
->
assertEquals
(
'12345'
,
$address2
->
zip
);
}
//DRAFT OF EXPECTED/DESIRED BEHAVIOR
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment