public class SpringTransactionManager extends org.springframework.transaction.support.AbstractPlatformTransactionManager implements org.springframework.transaction.support.ResourceTransactionManager, org.springframework.transaction.PlatformTransactionManager, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>, org.springframework.context.ApplicationContextAware
SpringTransactionManager
as a transaction manager
in the Spring application context.
SpringTransactionManager
can start a node itself on its startup
based on provided Ignite configuration. You can provide path to a
Spring configuration XML file, like below (path can be absolute or
relative to IGNITE_HOME
):
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <-- Provide configuration file path. --> <bean id="transactionManager" class="org.apache.ignite.transactions.spring.SpringTransactionManager"> <property name="configurationPath" value="examples/config/spring-transaction.xml"/> </bean> <-- Use annotation-driven transaction configuration. --> <tx:annotation-driven/> </beans>Or you can provide a
IgniteConfiguration
bean, like below:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <-- Provide configuration bean. --> <bean id="transactionManager" class="org.apache.ignite.transactions.spring.SpringTransactionManager"> <property name="configuration"> <bean id="gridCfg" class="org.apache.ignite.configuration.IgniteConfiguration"> ... </bean> </property> </bean> <-- Use annotation-driven transaction configuration. --> <tx:annotation-driven/> </beans>Note that providing both configuration path and configuration bean is illegal and results in
IllegalArgumentException
.
If you already have Ignite node running within your application,
simply provide correct Ignite instance name, like below (if there is no Grid
instance with such name, exception will be thrown):
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <-- Provide Ignite instance name. --> <bean id="transactionManager" class="org.apache.ignite.transactions.spring.SpringTransactionManager"> <property name="igniteInstanceName" value="myGrid"/> </bean> <-- Use annotation-driven transaction configuration. --> <tx:annotation-driven/> </beans>This can be used, for example, when you are running your application in a J2EE Web container and use
ServletContextListenerStartup
for node startup.
If neither configurationPath
,
configuration
, nor
igniteInstanceName
are provided, transaction manager
will try to use default Grid instance (the one with the null
name). If it doesn't exist, exception will be thrown.
SpringTransactionManager
can be configured to support Ignite transaction concurrency.
For this you need to provide SpringTransactionManager
with transactionConcurrency property.
If this property is not set then default transaction concurrency will be used
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <-- Provide Ignite instance name. --> <bean id="transactionManager" class="org.apache.ignite.transactions.spring.SpringTransactionManager"> <property name="igniteInstanceName" value="myGrid"/> <property name="transactionConcurrency" value="OPTIMISTIC"/> </bean> <-- Use annotation-driven transaction configuration. --> <tx:annotation-driven/> </beans>In case you need to support both "OPTIMISTIC" and "PESSIMISTIC" transaction concurrency in you application, you need to create two transaction managers with different transaction concurrency
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="optimisticTransactionManager" class="org.apache.ignite.transactions.spring.SpringTransactionManager"> <property name="igniteInstanceName" value="myGrid"/> <property name="transactionConcurrency" value="OPTIMISTIC"/> </bean> <bean id="pessimisticTransactionManager" class="org.apache.ignite.transactions.spring.SpringTransactionManager"> <property name="igniteInstanceName" value="myGrid"/> <property name="transactionConcurrency" value="PESSIMISTIC"/> </bean> <-- Use annotation-driven transaction configuration. --> <tx:annotation-driven/> </beans>Then use them with qualifiers in your application:
public class TransactionalService { @Transactional("optimisticTransactionManager") public void doOptimistically() { ... } @Transactional("pessimisticTransactionManager") public void doPessimistically() { ... } }
Constructor and Description |
---|
SpringTransactionManager()
Constructs the transaction manager with no target Ignite instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doBegin(Object transaction,
org.springframework.transaction.TransactionDefinition definition) |
protected void |
doCleanupAfterCompletion(Object transaction) |
protected void |
doCommit(org.springframework.transaction.support.DefaultTransactionStatus status) |
protected Object |
doGetTransaction() |
protected void |
doRollback(org.springframework.transaction.support.DefaultTransactionStatus status) |
protected void |
doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status) |
IgniteConfiguration |
getConfiguration()
Gets configuration bean.
|
String |
getConfigurationPath()
Gets configuration file path.
|
String |
getGridName()
Deprecated.
|
String |
getIgniteInstanceName()
Gets Ignite instance name.
|
Object |
getResourceFactory() |
TransactionConcurrency |
getTransactionConcurrency()
Gets transaction concurrency level.
|
protected boolean |
isExistingTransaction(Object transaction) |
void |
onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event) |
void |
setApplicationContext(org.springframework.context.ApplicationContext ctx) |
void |
setConfiguration(IgniteConfiguration cfg)
Sets configuration bean.
|
void |
setConfigurationPath(String cfgPath)
Sets configuration file path.
|
void |
setGridName(String gridName)
Deprecated.
|
void |
setIgniteInstanceName(String igniteInstanceName)
Sets Ignite instance name.
|
void |
setTransactionConcurrency(TransactionConcurrency transactionConcurrency)
Sets transaction concurrency level.
|
commit, determineTimeout, doResume, doSuspend, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public SpringTransactionManager()
public void setApplicationContext(org.springframework.context.ApplicationContext ctx)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
public TransactionConcurrency getTransactionConcurrency()
public void setTransactionConcurrency(TransactionConcurrency transactionConcurrency)
transactionConcurrency
- transaction concurrency level.public String getConfigurationPath()
public void setConfigurationPath(String cfgPath)
cfgPath
- Grid configuration file path.public IgniteConfiguration getConfiguration()
public void setConfiguration(IgniteConfiguration cfg)
cfg
- Grid configuration bean.@Deprecated public String getGridName()
getIgniteInstanceName()
.@Deprecated public void setGridName(String gridName)
setIgniteInstanceName(String)
.gridName
- Grid name.public String getIgniteInstanceName()
public void setIgniteInstanceName(String igniteInstanceName)
igniteInstanceName
- Ignite instance name.public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
onApplicationEvent
in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
protected Object doGetTransaction() throws org.springframework.transaction.TransactionException
doGetTransaction
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition) throws org.springframework.transaction.TransactionException
doBegin
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException
doCommit
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException
doRollback
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException
doSetRollbackOnly
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doCleanupAfterCompletion(Object transaction)
doCleanupAfterCompletion
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
protected boolean isExistingTransaction(Object transaction) throws org.springframework.transaction.TransactionException
isExistingTransaction
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
public Object getResourceFactory()
getResourceFactory
in interface org.springframework.transaction.support.ResourceTransactionManager
GridGain In-Memory Computing Platform : ver. 8.9.14 Release Date : November 5 2024