Class Neo4jTransactionManager
java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager
- All Implemented Interfaces:
Serializable
,Aware
,ApplicationContextAware
,ConfigurableTransactionManager
,PlatformTransactionManager
,TransactionManager
@API(status=STABLE,
since="6.0")
public final class Neo4jTransactionManager
extends AbstractPlatformTransactionManager
implements 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 classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
AbstractPlatformTransactionManager.SuspendedResourcesHolder
-
Field Summary
Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
-
Constructor Summary
ConstructorDescriptionNeo4jTransactionManager
(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
doBegin
(Object transaction, TransactionDefinition definition) protected void
doCleanupAfterCompletion
(Object transaction) protected void
doCommit
(DefaultTransactionStatus status) protected Object
protected void
protected void
doRollback
(DefaultTransactionStatus status) protected void
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
(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, getTransactionExecutionListeners, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, prepareForCommit, prepareSynchronization, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionExecutionListeners, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransaction
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.transaction.ConfigurableTransactionManager
addListener
-
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
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
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 classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
isExistingTransaction
- Overrides:
isExistingTransaction
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doBegin
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException - Specified by:
doBegin
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doSuspend
- Overrides:
doSuspend
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doResume
- Overrides:
doResume
in classAbstractPlatformTransactionManager
-
doCommit
- Specified by:
doCommit
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doRollback
- Specified by:
doRollback
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doSetRollbackOnly
- Overrides:
doSetRollbackOnly
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doCleanupAfterCompletion
- Overrides:
doCleanupAfterCompletion
in classAbstractPlatformTransactionManager
-