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
173d7ec1
Commit
173d7ec1
authored
Oct 01, 2010
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DBAL-55 - Refactored a bit and expaned tests
parent
0e460e8d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
32 deletions
+87
-32
Connection.php
lib/Doctrine/DBAL/Connection.php
+20
-30
ConnectionException.php
lib/Doctrine/DBAL/ConnectionException.php
+1
-1
ConnectionTest.php
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
+66
-1
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
173d7ec1
...
@@ -751,6 +751,7 @@ class Connection implements DriverConnection
...
@@ -751,6 +751,7 @@ class Connection implements DriverConnection
* Set if nested transactions should use savepoints
* Set if nested transactions should use savepoints
*
*
* @param boolean
* @param boolean
* @return void
*/
*/
public
function
setNestTransactionsWithSavepoints
(
$nestTransactionsWithSavepoints
)
public
function
setNestTransactionsWithSavepoints
(
$nestTransactionsWithSavepoints
)
{
{
...
@@ -758,8 +759,8 @@ class Connection implements DriverConnection
...
@@ -758,8 +759,8 @@ class Connection implements DriverConnection
throw
ConnectionException
::
mayNotAlterNestedTransactionWithSavepointsInTransaction
();
throw
ConnectionException
::
mayNotAlterNestedTransactionWithSavepointsInTransaction
();
}
}
if
(
$nestTransactionsWithSavepoints
&&
!
$this
->
_platform
->
supportsSavepoints
())
{
if
(
!
$this
->
_platform
->
supportsSavepoints
())
{
ConnectionException
::
savepointsNotSupported
();
throw
ConnectionException
::
savepointsNotSupported
();
}
}
$this
->
_nestTransactionsWithSavepoints
=
$nestTransactionsWithSavepoints
;
$this
->
_nestTransactionsWithSavepoints
=
$nestTransactionsWithSavepoints
;
...
@@ -781,12 +782,9 @@ class Connection implements DriverConnection
...
@@ -781,12 +782,9 @@ class Connection implements DriverConnection
*
*
* @return mixed a string with the savepoint name or false
* @return mixed a string with the savepoint name or false
*/
*/
protected
function
_getNestedTransactionSavePointName
()
{
protected
function
_getNestedTransactionSavePointName
()
if
(
$this
->
_platform
->
supportsSavepoints
()
&&
!
empty
(
$this
->
_nestTransactionsWithSavepoints
))
{
{
return
'DOCTRINE2_SAVEPOINT_'
.
$this
->
_transactionNestingLevel
;
return
'DOCTRINE2_SAVEPOINT_'
.
$this
->
_transactionNestingLevel
;
}
return
false
;
}
}
/**
/**
...
@@ -802,11 +800,8 @@ class Connection implements DriverConnection
...
@@ -802,11 +800,8 @@ class Connection implements DriverConnection
if
(
$this
->
_transactionNestingLevel
==
1
)
{
if
(
$this
->
_transactionNestingLevel
==
1
)
{
$this
->
_conn
->
beginTransaction
();
$this
->
_conn
->
beginTransaction
();
}
else
{
}
else
if
(
$this
->
_nestTransactionsWithSavepoints
)
{
$savepointName
=
$this
->
_getNestedTransactionSavePointName
();
$this
->
createSavepoint
(
$this
->
_getNestedTransactionSavePointName
());
if
(
$savepointName
)
{
$this
->
createSavePoint
(
$savepointName
);
}
}
}
}
}
...
@@ -830,11 +825,8 @@ class Connection implements DriverConnection
...
@@ -830,11 +825,8 @@ class Connection implements DriverConnection
if
(
$this
->
_transactionNestingLevel
==
1
)
{
if
(
$this
->
_transactionNestingLevel
==
1
)
{
$this
->
_conn
->
commit
();
$this
->
_conn
->
commit
();
}
else
{
}
else
if
(
$this
->
_nestTransactionsWithSavepoints
)
{
$savepointName
=
$this
->
_getNestedTransactionSavePointName
();
$this
->
releaseSavepoint
(
$this
->
_getNestedTransactionSavePointName
());
if
(
$savepointName
&&
$this
->
_platform
->
supportsReleaseSavepoints
())
{
$this
->
releaseSavePoint
(
$savepointName
);
}
}
}
--
$this
->
_transactionNestingLevel
;
--
$this
->
_transactionNestingLevel
;
...
@@ -860,13 +852,11 @@ class Connection implements DriverConnection
...
@@ -860,13 +852,11 @@ class Connection implements DriverConnection
$this
->
_transactionNestingLevel
=
0
;
$this
->
_transactionNestingLevel
=
0
;
$this
->
_conn
->
rollback
();
$this
->
_conn
->
rollback
();
$this
->
_isRollbackOnly
=
false
;
$this
->
_isRollbackOnly
=
false
;
}
else
if
(
$this
->
_nestTransactionsWithSavepoints
)
{
$this
->
rollbackSavepoint
(
$this
->
_getNestedTransactionSavePointName
());
--
$this
->
_transactionNestingLevel
;
}
else
{
}
else
{
$savepointName
=
$this
->
_getNestedTransactionSavePointName
();
$this
->
_isRollbackOnly
=
true
;
if
(
!
$this
->
_isRollbackOnly
&&
$savepointName
)
{
$this
->
rollbackSavePoint
(
$savepointName
);
}
else
{
$this
->
_isRollbackOnly
=
true
;
}
--
$this
->
_transactionNestingLevel
;
--
$this
->
_transactionNestingLevel
;
}
}
}
}
...
@@ -878,10 +868,10 @@ class Connection implements DriverConnection
...
@@ -878,10 +868,10 @@ class Connection implements DriverConnection
* @param string $savepoint name of a savepoint to set
* @param string $savepoint name of a savepoint to set
* @return void
* @return void
*/
*/
public
function
createSave
P
oint
(
$savepoint
)
public
function
createSave
p
oint
(
$savepoint
)
{
{
if
(
!
$this
->
_platform
->
supportsSavepoints
())
{
if
(
!
$this
->
_platform
->
supportsSavepoints
())
{
ConnectionException
::
savepointsNotSupported
();
throw
ConnectionException
::
savepointsNotSupported
();
}
}
$this
->
_conn
->
exec
(
$this
->
_platform
->
createSavePoint
(
$savepoint
));
$this
->
_conn
->
exec
(
$this
->
_platform
->
createSavePoint
(
$savepoint
));
...
@@ -894,10 +884,10 @@ class Connection implements DriverConnection
...
@@ -894,10 +884,10 @@ class Connection implements DriverConnection
* @param string $savepoint name of a savepoint to release
* @param string $savepoint name of a savepoint to release
* @return void
* @return void
*/
*/
public
function
releaseSave
P
oint
(
$savepoint
)
public
function
releaseSave
p
oint
(
$savepoint
)
{
{
if
(
!
$this
->
_platform
->
supportsSavepoints
())
{
if
(
!
$this
->
_platform
->
supportsSavepoints
())
{
ConnectionException
::
savepointsNotSupported
();
throw
ConnectionException
::
savepointsNotSupported
();
}
}
if
(
$this
->
_platform
->
supportsReleaseSavepoints
())
{
if
(
$this
->
_platform
->
supportsReleaseSavepoints
())
{
...
@@ -912,10 +902,10 @@ class Connection implements DriverConnection
...
@@ -912,10 +902,10 @@ class Connection implements DriverConnection
* @param string $savepoint name of a savepoint to rollback to
* @param string $savepoint name of a savepoint to rollback to
* @return void
* @return void
*/
*/
public
function
rollbackSave
P
oint
(
$savepoint
)
public
function
rollbackSave
p
oint
(
$savepoint
)
{
{
if
(
!
$this
->
_platform
->
supportsSavepoints
())
{
if
(
!
$this
->
_platform
->
supportsSavepoints
())
{
ConnectionException
::
savepointsNotSupported
();
throw
ConnectionException
::
savepointsNotSupported
();
}
}
$this
->
_conn
->
exec
(
$this
->
_platform
->
rollbackSavePoint
(
$savepoint
));
$this
->
_conn
->
exec
(
$this
->
_platform
->
rollbackSavePoint
(
$savepoint
));
...
...
lib/Doctrine/DBAL/ConnectionException.php
View file @
173d7ec1
...
@@ -44,7 +44,7 @@ class ConnectionException extends DBALException
...
@@ -44,7 +44,7 @@ class ConnectionException extends DBALException
public
static
function
savepointsNotSupported
()
public
static
function
savepointsNotSupported
()
{
{
return
new
self
(
"Savepoints are not supported
transaction
."
);
return
new
self
(
"Savepoints are not supported
by this driver
."
);
}
}
public
static
function
mayNotAlterNestedTransactionWithSavepointsInTransaction
()
public
static
function
mayNotAlterNestedTransactionWithSavepointsInTransaction
()
...
...
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
View file @
173d7ec1
...
@@ -14,6 +14,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -14,6 +14,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
parent
::
setUp
();
parent
::
setUp
();
}
}
public
function
tearDown
()
{
parent
::
tearDown
();
$this
->
resetSharedConn
();
}
public
function
testGetWrappedConnection
()
public
function
testGetWrappedConnection
()
{
{
$this
->
assertType
(
'Doctrine\DBAL\Driver\Connection'
,
$this
->
_conn
->
getWrappedConnection
());
$this
->
assertType
(
'Doctrine\DBAL\Driver\Connection'
,
$this
->
_conn
->
getWrappedConnection
());
...
@@ -93,6 +99,65 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -93,6 +99,65 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
}
}
public
function
testTransactionNestingBehaviorCantBeChangedInActiveTransaction
()
{
if
(
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsSavepoints
())
{
$this
->
markTestSkipped
(
'This test requires the platform to support savepoints.'
);
}
$this
->
_conn
->
beginTransaction
();
try
{
$this
->
_conn
->
setNestTransactionsWithSavepoints
(
true
);
$this
->
fail
(
'An exception should have been thrown by chaning the nesting transaction behavior within an transaction.'
);
}
catch
(
ConnectionException
$e
)
{
$this
->
_conn
->
rollBack
();
}
}
public
function
testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException
()
{
if
(
$this
->
_conn
->
getDatabasePlatform
()
->
supportsSavepoints
())
{
$this
->
markTestSkipped
(
'This test requires the platform not to support savepoints.'
);
}
$this
->
setExpectedException
(
'Doctrine\DBAL\ConnectionException'
,
"Savepoints are not supported by this driver."
);
$this
->
_conn
->
setNestTransactionsWithSavepoints
(
true
);
}
public
function
testCreateSavepointsNotSupportedThrowsException
()
{
if
(
$this
->
_conn
->
getDatabasePlatform
()
->
supportsSavepoints
())
{
$this
->
markTestSkipped
(
'This test requires the platform not to support savepoints.'
);
}
$this
->
setExpectedException
(
'Doctrine\DBAL\ConnectionException'
,
"Savepoints are not supported by this driver."
);
$this
->
_conn
->
createSavepoint
(
'foo'
);
}
public
function
testReleaseSavepointsNotSupportedThrowsException
()
{
if
(
$this
->
_conn
->
getDatabasePlatform
()
->
supportsSavepoints
())
{
$this
->
markTestSkipped
(
'This test requires the platform not to support savepoints.'
);
}
$this
->
setExpectedException
(
'Doctrine\DBAL\ConnectionException'
,
"Savepoints are not supported by this driver."
);
$this
->
_conn
->
releaseSavepoint
(
'foo'
);
}
public
function
testRollbackSavepointsNotSupportedThrowsException
()
{
if
(
$this
->
_conn
->
getDatabasePlatform
()
->
supportsSavepoints
())
{
$this
->
markTestSkipped
(
'This test requires the platform not to support savepoints.'
);
}
$this
->
setExpectedException
(
'Doctrine\DBAL\ConnectionException'
,
"Savepoints are not supported by this driver."
);
$this
->
_conn
->
rollbackSavepoint
(
'foo'
);
}
public
function
testTransactionBehaviorWithRollback
()
public
function
testTransactionBehaviorWithRollback
()
{
{
try
{
try
{
...
@@ -101,7 +166,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -101,7 +166,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
throw
new
\Exception
;
throw
new
\Exception
;
$this
->
_conn
x
->
commit
();
// never reached
$this
->
_conn
->
commit
();
// never reached
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
$this
->
assertEquals
(
1
,
$this
->
_conn
->
getTransactionNestingLevel
());
$this
->
assertEquals
(
1
,
$this
->
_conn
->
getTransactionNestingLevel
());
$this
->
_conn
->
rollback
();
$this
->
_conn
->
rollback
();
...
...
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