Class Neo4jTransactionManager
java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager
- All Implemented Interfaces:
Serializable
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.transaction.PlatformTransactionManager
,org.springframework.transaction.TransactionManager
@API(status=STABLE,
since="6.0")
public final class Neo4jTransactionManager
extends org.springframework.transaction.support.AbstractPlatformTransactionManager
implements org.springframework.context.ApplicationContextAware
Dedicated
PlatformTransactionManager
for native Neo4j transactions. This
transaction manager will synchronize a pair of a native Neo4j session/transaction with the transaction.- Since:
- 6.0
- Author:
- Michael J. Simons
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.support.AbstractPlatformTransactionManager.SuspendedResourcesHolder
-
Field Summary
Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
-
Constructor Summary
ConstructorsConstructorDescriptionNeo4jTransactionManager
(org.neo4j.driver.Driver driver) This will create a transaction manager for the default database.Neo4jTransactionManager
(org.neo4j.driver.Driver driver, DatabaseSelectionProvider databaseSelectionProvider) This will create a transaction manager targeting whatever the database selection provider determines.Neo4jTransactionManager
(org.neo4j.driver.Driver driver, DatabaseSelectionProvider databaseSelectionProvider, Neo4jBookmarkManager bookmarkManager) This constructor can be used to configure the bookmark manager being used. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
doCleanupAfterCompletion
(Object transaction) protected void
doCommit
(org.springframework.transaction.support.DefaultTransactionStatus status) protected Object
protected void
protected void
doRollback
(org.springframework.transaction.support.DefaultTransactionStatus status) protected void
doSetRollbackOnly
(org.springframework.transaction.support.DefaultTransactionStatus status) protected Object
protected boolean
isExistingTransaction
(Object transaction) static org.neo4j.driver.Transaction
retrieveTransaction
(org.neo4j.driver.Driver driver, String targetDatabase) Deprecated.since 6.2, use #retrieveTransaction(Driver, DatabaseSelection, UserSelection)static org.neo4j.driver.Transaction
retrieveTransaction
(org.neo4j.driver.Driver driver, DatabaseSelection targetDatabase, UserSelection asUser) This method provides a native Neo4j transaction to be used from within aNeo4jClient
.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) with
(org.neo4j.driver.Driver driver) Start building a new transaction manager for the given driver instance.Methods inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareForCommit, prepareSynchronization, prepareTransactionStatus, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransaction
-
Constructor Details
-
Neo4jTransactionManager
public Neo4jTransactionManager(org.neo4j.driver.Driver driver) This will create a transaction manager for the default database.- Parameters:
driver
- A driver instance
-
Neo4jTransactionManager
public Neo4jTransactionManager(org.neo4j.driver.Driver driver, DatabaseSelectionProvider databaseSelectionProvider) This will create a transaction manager targeting whatever the database selection provider determines.- Parameters:
driver
- A driver instancedatabaseSelectionProvider
- The database selection provider to determine the database in which the transactions should happen
-
Neo4jTransactionManager
public Neo4jTransactionManager(org.neo4j.driver.Driver driver, DatabaseSelectionProvider databaseSelectionProvider, Neo4jBookmarkManager bookmarkManager) This constructor can be used to configure the bookmark manager being used. It is useful when you need to seed the bookmark manager or if you want to capture new bookmarks.- Parameters:
driver
- A driver instancedatabaseSelectionProvider
- The database selection provider to determine the database in which the transactions should happenbookmarkManager
- A bookmark manager
-
-
Method Details
-
with
@API(status=STABLE, since="6.2") public static Neo4jTransactionManager.Builder with(org.neo4j.driver.Driver driver) Start building a new transaction manager for the given driver instance.- Parameters:
driver
- A fixed driver instance.- Returns:
- A builder for a transaction manager
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
retrieveTransaction
@Deprecated @Nullable public static org.neo4j.driver.Transaction retrieveTransaction(org.neo4j.driver.Driver driver, @Nullable String targetDatabase) Deprecated.since 6.2, use #retrieveTransaction(Driver, DatabaseSelection, UserSelection)- Parameters:
driver
- The driver that has been used as a synchronization object.targetDatabase
- The target database- Returns:
- An optional managed transaction or null if the method hasn't been called inside an ongoing Spring transaction
- See Also:
-
retrieveTransaction
@Nullable public static org.neo4j.driver.Transaction retrieveTransaction(org.neo4j.driver.Driver driver, DatabaseSelection targetDatabase, UserSelection asUser) This method provides a native Neo4j transaction to be used from within aNeo4jClient
. In most cases this the native transaction will be controlled from the Neo4j specificPlatformTransactionManager
. However, SDN provides support for other transaction managers as well. This method registers a session synchronization in such cases on the foreign transaction manager.- Parameters:
driver
- The driver that has been used as a synchronization object.targetDatabase
- The target databaseasUser
- The user for which the tx is being retrieved- Returns:
- An optional managed transaction or null if the method hasn't been called inside an ongoing Spring transaction
-
doGetTransaction
- Specified by:
doGetTransaction
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
- Throws:
org.springframework.transaction.TransactionException
-
isExistingTransaction
protected boolean isExistingTransaction(Object transaction) throws org.springframework.transaction.TransactionException - Overrides:
isExistingTransaction
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
- Throws:
org.springframework.transaction.TransactionException
-
doBegin
protected void doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition) throws org.springframework.transaction.TransactionException - Specified by:
doBegin
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
- Throws:
org.springframework.transaction.TransactionException
-
doSuspend
protected Object doSuspend(Object transaction) throws org.springframework.transaction.TransactionException - Overrides:
doSuspend
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
- Throws:
org.springframework.transaction.TransactionException
-
doResume
- Overrides:
doResume
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
-
doCommit
protected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException - Specified by:
doCommit
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
- Throws:
org.springframework.transaction.TransactionException
-
doRollback
protected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException - Specified by:
doRollback
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
- Throws:
org.springframework.transaction.TransactionException
-
doSetRollbackOnly
protected void doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException - Overrides:
doSetRollbackOnly
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
- Throws:
org.springframework.transaction.TransactionException
-
doCleanupAfterCompletion
- Overrides:
doCleanupAfterCompletion
in classorg.springframework.transaction.support.AbstractPlatformTransactionManager
-