You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/12/08 11:37:44 UTC

[GitHub] [ignite] ololo3000 opened a new pull request #8556: IGNITE-13708 Adds thin client support for Spring Transactions.

ololo3000 opened a new pull request #8556:
URL: https://github.com/apache/ignite/pull/8556


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ololo3000 commented on a change in pull request #8556: IGNITE-13708 Adds thin client support for Spring Transactions.

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on a change in pull request #8556:
URL: https://github.com/apache/ignite/pull/8556#discussion_r539252769



##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringClientTransactionManagerTest.java
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.ClientCacheProxy;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.TransactionSystemException;

Review comment:
       Done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] asfgit closed pull request #8556: IGNITE-13708 Adds thin client support for Spring Transactions.

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #8556:
URL: https://github.com/apache/ignite/pull/8556


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ololo3000 commented on a change in pull request #8556: IGNITE-13708 Adds thin client support for Spring Transactions.

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on a change in pull request #8556:
URL: https://github.com/apache/ignite/pull/8556#discussion_r539252073



##########
File path: modules/spring/src/main/java/org/apache/ignite/transactions/spring/AbstractSpringTransactionManager.java
##########
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxy;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxyFactory;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.transaction.CannotCreateTransactionException;
+import org.springframework.transaction.InvalidIsolationLevelException;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.support.AbstractPlatformTransactionManager;
+import org.springframework.transaction.support.DefaultTransactionStatus;
+import org.springframework.transaction.support.ResourceTransactionManager;
+import org.springframework.transaction.support.SmartTransactionObject;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
+import org.springframework.transaction.support.TransactionSynchronizationUtils;
+
+/** Abstract implementation of Spring Transaction manager with omitted Ignite cluster access logic. */
+public abstract class AbstractSpringTransactionManager extends AbstractPlatformTransactionManager
+    implements ResourceTransactionManager, ApplicationListener<ContextRefreshedEvent>
+{
+    /** Transaction factory.*/
+    private TransactionProxyFactory txFactory;
+
+    /** Ignite logger. */
+    private IgniteLogger log;
+
+    /** Transaction concurrency level. */
+    private TransactionConcurrency transactionConcurrency;
+
+    /** Default transaction isolation. */
+    private TransactionIsolation dfltTxIsolation;
+
+    /** Default transaction timeout. */
+    private long dfltTxTimeout;
+
+    /**
+     * Gets transaction concurrency level.
+     *
+     * @return Transaction concurrency level.
+     */
+    public TransactionConcurrency getTransactionConcurrency() {
+        return transactionConcurrency;
+    }
+
+    /**
+     * Sets transaction concurrency level.
+     *
+     * @param transactionConcurrency transaction concurrency level.
+     */
+    public void setTransactionConcurrency(TransactionConcurrency transactionConcurrency) {
+        this.transactionConcurrency = transactionConcurrency;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onApplicationEvent(ContextRefreshedEvent evt) {
+        if (transactionConcurrency == null)
+            transactionConcurrency = defaultTransactionConcurrency();
+
+        dfltTxIsolation = defaultTransactionIsolation();
+
+        dfltTxTimeout = defaultTransactionTimeout();
+
+        log = log();
+
+        txFactory = createTransactionFactory();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object doGetTransaction() throws TransactionException {
+        IgniteTransactionObject txObj = new IgniteTransactionObject();
+
+        txObj.setTransactionHolder(
+            (IgniteTransactionHolder)TransactionSynchronizationManager.getResource(txFactory), false);
+
+        return txObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
+        if (definition.getIsolationLevel() == TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
+            throw new InvalidIsolationLevelException("Ignite does not support READ_UNCOMMITTED isolation level.");
+
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+        TransactionProxy tx = null;
+
+        try {
+            if (txObj.getTransactionHolder() == null || txObj.getTransactionHolder().isSynchronizedWithTransaction()) {
+                long timeout = dfltTxTimeout;
+
+                if (definition.getTimeout() > 0)
+                    timeout = TimeUnit.SECONDS.toMillis(definition.getTimeout());
+
+                TransactionProxy newTx = txFactory.txStart(transactionConcurrency,
+                    convertToIgniteIsolationLevel(definition.getIsolationLevel()), timeout);
+
+                if (log.isDebugEnabled())
+                    log.debug("Started Ignite transaction: " + newTx);
+
+                txObj.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
+            }
+
+            txObj.getTransactionHolder().setSynchronizedWithTransaction(true);
+            txObj.getTransactionHolder().setTransactionActive(true);
+
+            tx = txObj.getTransactionHolder().getTransaction();
+
+            // Bind the session holder to the thread.
+            if (txObj.isNewTransactionHolder())
+                TransactionSynchronizationManager.bindResource(txFactory, txObj.getTransactionHolder());
+        }
+        catch (Exception ex) {
+            if (tx != null)
+                tx.close();
+
+            throw new CannotCreateTransactionException("Could not create Ignite transaction", ex);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Committing Ignite transaction: " + tx);
+
+        try {
+            tx.commit();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not commit Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Rolling back Ignite transaction: " + tx);
+
+        try {
+            tx.rollback();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not rollback Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        assert tx != null;
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Setting Ignite transaction rollback-only: " + tx);
+
+        tx.setRollbackOnly();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCleanupAfterCompletion(Object transaction) {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+
+        // Remove the transaction holder from the thread, if exposed.
+        if (txObj.isNewTransactionHolder()) {
+            TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+            TransactionSynchronizationManager.unbindResource(txFactory);
+
+            if (log.isDebugEnabled())
+                log.debug("Releasing Ignite transaction: " + tx);
+        }
+
+        txObj.getTransactionHolder().clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean isExistingTransaction(Object transaction) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+
+        return (txObj.getTransactionHolder() != null && txObj.getTransactionHolder().isTransactionActive());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getResourceFactory() {
+        return txFactory;
+    }
+
+    /**
+     * @param isolationLevel Spring isolation level.
+     * @return Ignite isolation level.
+     */
+    private TransactionIsolation convertToIgniteIsolationLevel(int isolationLevel) {
+        TransactionIsolation isolation = dfltTxIsolation;
+        switch (isolationLevel) {
+            case TransactionDefinition.ISOLATION_READ_COMMITTED:
+                isolation = TransactionIsolation.READ_COMMITTED;
+                break;
+            case TransactionDefinition.ISOLATION_REPEATABLE_READ:
+                isolation = TransactionIsolation.REPEATABLE_READ;
+                break;
+            case TransactionDefinition.ISOLATION_SERIALIZABLE:
+                isolation = TransactionIsolation.SERIALIZABLE;
+        }
+        return isolation;
+    }
+
+    /** @return Default transaction isolation. */
+    protected abstract TransactionIsolation defaultTransactionIsolation();
+
+    /** @return Default transaction timeout. */
+    protected abstract long defaultTransactionTimeout();
+
+    /** @return Default transaction concurrency. */
+    protected abstract TransactionConcurrency defaultTransactionConcurrency();
+
+    /** Creates instance of {@link TransactionProxyFactory} that will be used to start new Ignite transactions. */
+    protected abstract TransactionProxyFactory createTransactionFactory();
+
+    /** @return Ignite logger.  */
+    protected abstract IgniteLogger log();
+
+    /**
+     * An object representing a managed Ignite transaction.
+     */
+    protected static class IgniteTransactionObject implements SmartTransactionObject {
+        /** */
+        private IgniteTransactionHolder transactionHolder;

Review comment:
       Done.

##########
File path: modules/spring/src/main/java/org/apache/ignite/transactions/spring/AbstractSpringTransactionManager.java
##########
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxy;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxyFactory;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.transaction.CannotCreateTransactionException;
+import org.springframework.transaction.InvalidIsolationLevelException;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.support.AbstractPlatformTransactionManager;
+import org.springframework.transaction.support.DefaultTransactionStatus;
+import org.springframework.transaction.support.ResourceTransactionManager;
+import org.springframework.transaction.support.SmartTransactionObject;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
+import org.springframework.transaction.support.TransactionSynchronizationUtils;
+
+/** Abstract implementation of Spring Transaction manager with omitted Ignite cluster access logic. */
+public abstract class AbstractSpringTransactionManager extends AbstractPlatformTransactionManager
+    implements ResourceTransactionManager, ApplicationListener<ContextRefreshedEvent>
+{
+    /** Transaction factory.*/
+    private TransactionProxyFactory txFactory;
+
+    /** Ignite logger. */
+    private IgniteLogger log;
+
+    /** Transaction concurrency level. */
+    private TransactionConcurrency transactionConcurrency;
+
+    /** Default transaction isolation. */
+    private TransactionIsolation dfltTxIsolation;
+
+    /** Default transaction timeout. */
+    private long dfltTxTimeout;
+
+    /**
+     * Gets transaction concurrency level.
+     *
+     * @return Transaction concurrency level.
+     */
+    public TransactionConcurrency getTransactionConcurrency() {
+        return transactionConcurrency;
+    }
+
+    /**
+     * Sets transaction concurrency level.
+     *
+     * @param transactionConcurrency transaction concurrency level.
+     */
+    public void setTransactionConcurrency(TransactionConcurrency transactionConcurrency) {
+        this.transactionConcurrency = transactionConcurrency;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onApplicationEvent(ContextRefreshedEvent evt) {
+        if (transactionConcurrency == null)
+            transactionConcurrency = defaultTransactionConcurrency();
+
+        dfltTxIsolation = defaultTransactionIsolation();
+
+        dfltTxTimeout = defaultTransactionTimeout();
+
+        log = log();
+
+        txFactory = createTransactionFactory();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object doGetTransaction() throws TransactionException {
+        IgniteTransactionObject txObj = new IgniteTransactionObject();
+
+        txObj.setTransactionHolder(
+            (IgniteTransactionHolder)TransactionSynchronizationManager.getResource(txFactory), false);
+
+        return txObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
+        if (definition.getIsolationLevel() == TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
+            throw new InvalidIsolationLevelException("Ignite does not support READ_UNCOMMITTED isolation level.");
+
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+        TransactionProxy tx = null;
+
+        try {
+            if (txObj.getTransactionHolder() == null || txObj.getTransactionHolder().isSynchronizedWithTransaction()) {
+                long timeout = dfltTxTimeout;
+
+                if (definition.getTimeout() > 0)
+                    timeout = TimeUnit.SECONDS.toMillis(definition.getTimeout());
+
+                TransactionProxy newTx = txFactory.txStart(transactionConcurrency,
+                    convertToIgniteIsolationLevel(definition.getIsolationLevel()), timeout);
+
+                if (log.isDebugEnabled())
+                    log.debug("Started Ignite transaction: " + newTx);
+
+                txObj.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
+            }
+
+            txObj.getTransactionHolder().setSynchronizedWithTransaction(true);
+            txObj.getTransactionHolder().setTransactionActive(true);
+
+            tx = txObj.getTransactionHolder().getTransaction();
+
+            // Bind the session holder to the thread.
+            if (txObj.isNewTransactionHolder())
+                TransactionSynchronizationManager.bindResource(txFactory, txObj.getTransactionHolder());
+        }
+        catch (Exception ex) {
+            if (tx != null)
+                tx.close();
+
+            throw new CannotCreateTransactionException("Could not create Ignite transaction", ex);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Committing Ignite transaction: " + tx);
+
+        try {
+            tx.commit();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not commit Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Rolling back Ignite transaction: " + tx);
+
+        try {
+            tx.rollback();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not rollback Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        assert tx != null;
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Setting Ignite transaction rollback-only: " + tx);
+
+        tx.setRollbackOnly();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCleanupAfterCompletion(Object transaction) {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+
+        // Remove the transaction holder from the thread, if exposed.
+        if (txObj.isNewTransactionHolder()) {
+            TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+            TransactionSynchronizationManager.unbindResource(txFactory);
+
+            if (log.isDebugEnabled())
+                log.debug("Releasing Ignite transaction: " + tx);
+        }
+
+        txObj.getTransactionHolder().clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean isExistingTransaction(Object transaction) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+
+        return (txObj.getTransactionHolder() != null && txObj.getTransactionHolder().isTransactionActive());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getResourceFactory() {
+        return txFactory;
+    }
+
+    /**
+     * @param isolationLevel Spring isolation level.
+     * @return Ignite isolation level.
+     */
+    private TransactionIsolation convertToIgniteIsolationLevel(int isolationLevel) {
+        TransactionIsolation isolation = dfltTxIsolation;
+        switch (isolationLevel) {

Review comment:
       Done.

##########
File path: modules/spring/src/main/java/org/apache/ignite/transactions/spring/AbstractSpringTransactionManager.java
##########
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxy;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxyFactory;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.transaction.CannotCreateTransactionException;
+import org.springframework.transaction.InvalidIsolationLevelException;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.support.AbstractPlatformTransactionManager;
+import org.springframework.transaction.support.DefaultTransactionStatus;
+import org.springframework.transaction.support.ResourceTransactionManager;
+import org.springframework.transaction.support.SmartTransactionObject;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
+import org.springframework.transaction.support.TransactionSynchronizationUtils;
+
+/** Abstract implementation of Spring Transaction manager with omitted Ignite cluster access logic. */
+public abstract class AbstractSpringTransactionManager extends AbstractPlatformTransactionManager
+    implements ResourceTransactionManager, ApplicationListener<ContextRefreshedEvent>
+{
+    /** Transaction factory.*/
+    private TransactionProxyFactory txFactory;
+
+    /** Ignite logger. */
+    private IgniteLogger log;
+
+    /** Transaction concurrency level. */
+    private TransactionConcurrency transactionConcurrency;
+
+    /** Default transaction isolation. */
+    private TransactionIsolation dfltTxIsolation;
+
+    /** Default transaction timeout. */
+    private long dfltTxTimeout;
+
+    /**
+     * Gets transaction concurrency level.
+     *
+     * @return Transaction concurrency level.
+     */
+    public TransactionConcurrency getTransactionConcurrency() {
+        return transactionConcurrency;
+    }
+
+    /**
+     * Sets transaction concurrency level.
+     *
+     * @param transactionConcurrency transaction concurrency level.
+     */
+    public void setTransactionConcurrency(TransactionConcurrency transactionConcurrency) {
+        this.transactionConcurrency = transactionConcurrency;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onApplicationEvent(ContextRefreshedEvent evt) {
+        if (transactionConcurrency == null)
+            transactionConcurrency = defaultTransactionConcurrency();
+
+        dfltTxIsolation = defaultTransactionIsolation();
+
+        dfltTxTimeout = defaultTransactionTimeout();
+
+        log = log();
+
+        txFactory = createTransactionFactory();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object doGetTransaction() throws TransactionException {
+        IgniteTransactionObject txObj = new IgniteTransactionObject();
+
+        txObj.setTransactionHolder(
+            (IgniteTransactionHolder)TransactionSynchronizationManager.getResource(txFactory), false);
+
+        return txObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
+        if (definition.getIsolationLevel() == TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
+            throw new InvalidIsolationLevelException("Ignite does not support READ_UNCOMMITTED isolation level.");
+
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+        TransactionProxy tx = null;
+
+        try {
+            if (txObj.getTransactionHolder() == null || txObj.getTransactionHolder().isSynchronizedWithTransaction()) {
+                long timeout = dfltTxTimeout;
+
+                if (definition.getTimeout() > 0)
+                    timeout = TimeUnit.SECONDS.toMillis(definition.getTimeout());
+
+                TransactionProxy newTx = txFactory.txStart(transactionConcurrency,
+                    convertToIgniteIsolationLevel(definition.getIsolationLevel()), timeout);
+
+                if (log.isDebugEnabled())
+                    log.debug("Started Ignite transaction: " + newTx);
+
+                txObj.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
+            }
+
+            txObj.getTransactionHolder().setSynchronizedWithTransaction(true);
+            txObj.getTransactionHolder().setTransactionActive(true);
+
+            tx = txObj.getTransactionHolder().getTransaction();
+
+            // Bind the session holder to the thread.
+            if (txObj.isNewTransactionHolder())
+                TransactionSynchronizationManager.bindResource(txFactory, txObj.getTransactionHolder());
+        }
+        catch (Exception ex) {
+            if (tx != null)
+                tx.close();
+
+            throw new CannotCreateTransactionException("Could not create Ignite transaction", ex);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Committing Ignite transaction: " + tx);
+
+        try {
+            tx.commit();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not commit Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Rolling back Ignite transaction: " + tx);
+
+        try {
+            tx.rollback();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not rollback Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        assert tx != null;
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Setting Ignite transaction rollback-only: " + tx);

Review comment:
       Done. But ClientTransaction implementation don't have toSring() implementation itself. I'l file the corresponding ticket.

##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/GridSpringTransactionService.java
##########
@@ -26,12 +28,16 @@
  * Service.
  */
 public class GridSpringTransactionService {
+    /** */
+    @Autowired

Review comment:
       I think it is not really necessary since we don't use Spring class auto-detection. 

##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringClientTransactionManagerTest.java
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.ClientCacheProxy;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.TransactionSystemException;

Review comment:
       Done.

##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringClientTransactionManagerTest.java
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.ClientCacheProxy;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.UnexpectedRollbackException;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.configuration.ClientConnectorConfiguration.DFLT_PORT;
+
+/** Tests Spring Transactions manager implementation that uses thin client to access the Ignite cluster. */
+public class SpringClientTransactionManagerTest extends GridSpringTransactionManagerAbstractTest {
+    /** Spring application context. */
+    private static AnnotationConfigApplicationContext ctx;
+
+    /** Ignite thin client instance. */
+    private static IgniteClient cli;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setName(CACHE_NAME)
+                .setAtomicityMode(TRANSACTIONAL));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid();
+
+        ctx = new AnnotationConfigApplicationContext(SpringClientTransactionManagerApplicationContext.class);
+        cli = ctx.getBean(IgniteClient.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        ctx.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheProxy<Integer, String> cache() {
+        return new ClientCacheProxy<>(cli.cache(CACHE_NAME));
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridSpringTransactionService service() {
+        return ctx.getBean(GridSpringTransactionService.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testDoSetRollbackOnlyInExistingTransaction(){
+        GridTestUtils.assertThrowsAnyCause(
+            log,
+            () -> {
+                service().putWithNestedError(cache(), 1_000);
+
+                return null;
+            },
+            UnexpectedRollbackException.class,
+            "Transaction rolled back because it has been marked as rollback-only");
+

Review comment:
       Done.

##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringClientTransactionManagerTest.java
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.ClientCacheProxy;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.UnexpectedRollbackException;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.configuration.ClientConnectorConfiguration.DFLT_PORT;
+
+/** Tests Spring Transactions manager implementation that uses thin client to access the Ignite cluster. */
+public class SpringClientTransactionManagerTest extends GridSpringTransactionManagerAbstractTest {
+    /** Spring application context. */
+    private static AnnotationConfigApplicationContext ctx;
+
+    /** Ignite thin client instance. */
+    private static IgniteClient cli;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setName(CACHE_NAME)
+                .setAtomicityMode(TRANSACTIONAL));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid();
+
+        ctx = new AnnotationConfigApplicationContext(SpringClientTransactionManagerApplicationContext.class);
+        cli = ctx.getBean(IgniteClient.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        ctx.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheProxy<Integer, String> cache() {
+        return new ClientCacheProxy<>(cli.cache(CACHE_NAME));
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridSpringTransactionService service() {
+        return ctx.getBean(GridSpringTransactionService.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testDoSetRollbackOnlyInExistingTransaction(){

Review comment:
       Done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] NSAmelchev commented on a change in pull request #8556: IGNITE-13708 Adds thin client support for Spring Transactions.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #8556:
URL: https://github.com/apache/ignite/pull/8556#discussion_r539173748



##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/GridSpringTransactionService.java
##########
@@ -26,12 +28,16 @@
  * Service.
  */
 public class GridSpringTransactionService {
+    /** */
+    @Autowired

Review comment:
       Seems the service should be annotated with `@Service`

##########
File path: modules/spring/src/main/java/org/apache/ignite/transactions/spring/AbstractSpringTransactionManager.java
##########
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxy;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxyFactory;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.transaction.CannotCreateTransactionException;
+import org.springframework.transaction.InvalidIsolationLevelException;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.support.AbstractPlatformTransactionManager;
+import org.springframework.transaction.support.DefaultTransactionStatus;
+import org.springframework.transaction.support.ResourceTransactionManager;
+import org.springframework.transaction.support.SmartTransactionObject;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
+import org.springframework.transaction.support.TransactionSynchronizationUtils;
+
+/** Abstract implementation of Spring Transaction manager with omitted Ignite cluster access logic. */
+public abstract class AbstractSpringTransactionManager extends AbstractPlatformTransactionManager
+    implements ResourceTransactionManager, ApplicationListener<ContextRefreshedEvent>
+{
+    /** Transaction factory.*/
+    private TransactionProxyFactory txFactory;
+
+    /** Ignite logger. */
+    private IgniteLogger log;
+
+    /** Transaction concurrency level. */
+    private TransactionConcurrency transactionConcurrency;
+
+    /** Default transaction isolation. */
+    private TransactionIsolation dfltTxIsolation;
+
+    /** Default transaction timeout. */
+    private long dfltTxTimeout;
+
+    /**
+     * Gets transaction concurrency level.
+     *
+     * @return Transaction concurrency level.
+     */
+    public TransactionConcurrency getTransactionConcurrency() {
+        return transactionConcurrency;
+    }
+
+    /**
+     * Sets transaction concurrency level.
+     *
+     * @param transactionConcurrency transaction concurrency level.
+     */
+    public void setTransactionConcurrency(TransactionConcurrency transactionConcurrency) {
+        this.transactionConcurrency = transactionConcurrency;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onApplicationEvent(ContextRefreshedEvent evt) {
+        if (transactionConcurrency == null)
+            transactionConcurrency = defaultTransactionConcurrency();
+
+        dfltTxIsolation = defaultTransactionIsolation();
+
+        dfltTxTimeout = defaultTransactionTimeout();
+
+        log = log();
+
+        txFactory = createTransactionFactory();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object doGetTransaction() throws TransactionException {
+        IgniteTransactionObject txObj = new IgniteTransactionObject();
+
+        txObj.setTransactionHolder(
+            (IgniteTransactionHolder)TransactionSynchronizationManager.getResource(txFactory), false);
+
+        return txObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
+        if (definition.getIsolationLevel() == TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
+            throw new InvalidIsolationLevelException("Ignite does not support READ_UNCOMMITTED isolation level.");
+
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+        TransactionProxy tx = null;
+
+        try {
+            if (txObj.getTransactionHolder() == null || txObj.getTransactionHolder().isSynchronizedWithTransaction()) {
+                long timeout = dfltTxTimeout;
+
+                if (definition.getTimeout() > 0)
+                    timeout = TimeUnit.SECONDS.toMillis(definition.getTimeout());
+
+                TransactionProxy newTx = txFactory.txStart(transactionConcurrency,
+                    convertToIgniteIsolationLevel(definition.getIsolationLevel()), timeout);
+
+                if (log.isDebugEnabled())
+                    log.debug("Started Ignite transaction: " + newTx);
+
+                txObj.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
+            }
+
+            txObj.getTransactionHolder().setSynchronizedWithTransaction(true);
+            txObj.getTransactionHolder().setTransactionActive(true);
+
+            tx = txObj.getTransactionHolder().getTransaction();
+
+            // Bind the session holder to the thread.
+            if (txObj.isNewTransactionHolder())
+                TransactionSynchronizationManager.bindResource(txFactory, txObj.getTransactionHolder());
+        }
+        catch (Exception ex) {
+            if (tx != null)
+                tx.close();
+
+            throw new CannotCreateTransactionException("Could not create Ignite transaction", ex);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Committing Ignite transaction: " + tx);
+
+        try {
+            tx.commit();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not commit Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Rolling back Ignite transaction: " + tx);
+
+        try {
+            tx.rollback();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not rollback Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        assert tx != null;
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Setting Ignite transaction rollback-only: " + tx);
+
+        tx.setRollbackOnly();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCleanupAfterCompletion(Object transaction) {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+
+        // Remove the transaction holder from the thread, if exposed.
+        if (txObj.isNewTransactionHolder()) {
+            TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+            TransactionSynchronizationManager.unbindResource(txFactory);
+
+            if (log.isDebugEnabled())
+                log.debug("Releasing Ignite transaction: " + tx);
+        }
+
+        txObj.getTransactionHolder().clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean isExistingTransaction(Object transaction) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+
+        return (txObj.getTransactionHolder() != null && txObj.getTransactionHolder().isTransactionActive());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getResourceFactory() {
+        return txFactory;
+    }
+
+    /**
+     * @param isolationLevel Spring isolation level.
+     * @return Ignite isolation level.
+     */
+    private TransactionIsolation convertToIgniteIsolationLevel(int isolationLevel) {
+        TransactionIsolation isolation = dfltTxIsolation;
+        switch (isolationLevel) {

Review comment:
       Add missed line breaks according to the code style:
   https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines

##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringClientTransactionManagerTest.java
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.ClientCacheProxy;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.TransactionSystemException;

Review comment:
       Unused import

##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringClientTransactionManagerTest.java
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.ClientCacheProxy;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.UnexpectedRollbackException;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.configuration.ClientConnectorConfiguration.DFLT_PORT;
+
+/** Tests Spring Transactions manager implementation that uses thin client to access the Ignite cluster. */
+public class SpringClientTransactionManagerTest extends GridSpringTransactionManagerAbstractTest {
+    /** Spring application context. */
+    private static AnnotationConfigApplicationContext ctx;
+
+    /** Ignite thin client instance. */
+    private static IgniteClient cli;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setName(CACHE_NAME)
+                .setAtomicityMode(TRANSACTIONAL));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid();
+
+        ctx = new AnnotationConfigApplicationContext(SpringClientTransactionManagerApplicationContext.class);
+        cli = ctx.getBean(IgniteClient.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        ctx.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheProxy<Integer, String> cache() {
+        return new ClientCacheProxy<>(cli.cache(CACHE_NAME));
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridSpringTransactionService service() {
+        return ctx.getBean(GridSpringTransactionService.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testDoSetRollbackOnlyInExistingTransaction(){

Review comment:
       Missed space `) {`

##########
File path: modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringClientTransactionManagerTest.java
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
+import org.apache.ignite.transactions.spring.GridSpringTransactionService.ClientCacheProxy;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.UnexpectedRollbackException;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.configuration.ClientConnectorConfiguration.DFLT_PORT;
+
+/** Tests Spring Transactions manager implementation that uses thin client to access the Ignite cluster. */
+public class SpringClientTransactionManagerTest extends GridSpringTransactionManagerAbstractTest {
+    /** Spring application context. */
+    private static AnnotationConfigApplicationContext ctx;
+
+    /** Ignite thin client instance. */
+    private static IgniteClient cli;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setName(CACHE_NAME)
+                .setAtomicityMode(TRANSACTIONAL));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid();
+
+        ctx = new AnnotationConfigApplicationContext(SpringClientTransactionManagerApplicationContext.class);
+        cli = ctx.getBean(IgniteClient.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        ctx.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheProxy<Integer, String> cache() {
+        return new ClientCacheProxy<>(cli.cache(CACHE_NAME));
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridSpringTransactionService service() {
+        return ctx.getBean(GridSpringTransactionService.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testDoSetRollbackOnlyInExistingTransaction(){
+        GridTestUtils.assertThrowsAnyCause(
+            log,
+            () -> {
+                service().putWithNestedError(cache(), 1_000);
+
+                return null;
+            },
+            UnexpectedRollbackException.class,
+            "Transaction rolled back because it has been marked as rollback-only");
+

Review comment:
       Too much line breaks

##########
File path: modules/spring/src/main/java/org/apache/ignite/transactions/spring/AbstractSpringTransactionManager.java
##########
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxy;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxyFactory;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.transaction.CannotCreateTransactionException;
+import org.springframework.transaction.InvalidIsolationLevelException;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.support.AbstractPlatformTransactionManager;
+import org.springframework.transaction.support.DefaultTransactionStatus;
+import org.springframework.transaction.support.ResourceTransactionManager;
+import org.springframework.transaction.support.SmartTransactionObject;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
+import org.springframework.transaction.support.TransactionSynchronizationUtils;
+
+/** Abstract implementation of Spring Transaction manager with omitted Ignite cluster access logic. */
+public abstract class AbstractSpringTransactionManager extends AbstractPlatformTransactionManager
+    implements ResourceTransactionManager, ApplicationListener<ContextRefreshedEvent>
+{
+    /** Transaction factory.*/
+    private TransactionProxyFactory txFactory;
+
+    /** Ignite logger. */
+    private IgniteLogger log;
+
+    /** Transaction concurrency level. */
+    private TransactionConcurrency transactionConcurrency;
+
+    /** Default transaction isolation. */
+    private TransactionIsolation dfltTxIsolation;
+
+    /** Default transaction timeout. */
+    private long dfltTxTimeout;
+
+    /**
+     * Gets transaction concurrency level.
+     *
+     * @return Transaction concurrency level.
+     */
+    public TransactionConcurrency getTransactionConcurrency() {
+        return transactionConcurrency;
+    }
+
+    /**
+     * Sets transaction concurrency level.
+     *
+     * @param transactionConcurrency transaction concurrency level.
+     */
+    public void setTransactionConcurrency(TransactionConcurrency transactionConcurrency) {
+        this.transactionConcurrency = transactionConcurrency;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onApplicationEvent(ContextRefreshedEvent evt) {
+        if (transactionConcurrency == null)
+            transactionConcurrency = defaultTransactionConcurrency();
+
+        dfltTxIsolation = defaultTransactionIsolation();
+
+        dfltTxTimeout = defaultTransactionTimeout();
+
+        log = log();
+
+        txFactory = createTransactionFactory();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object doGetTransaction() throws TransactionException {
+        IgniteTransactionObject txObj = new IgniteTransactionObject();
+
+        txObj.setTransactionHolder(
+            (IgniteTransactionHolder)TransactionSynchronizationManager.getResource(txFactory), false);
+
+        return txObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
+        if (definition.getIsolationLevel() == TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
+            throw new InvalidIsolationLevelException("Ignite does not support READ_UNCOMMITTED isolation level.");
+
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+        TransactionProxy tx = null;
+
+        try {
+            if (txObj.getTransactionHolder() == null || txObj.getTransactionHolder().isSynchronizedWithTransaction()) {
+                long timeout = dfltTxTimeout;
+
+                if (definition.getTimeout() > 0)
+                    timeout = TimeUnit.SECONDS.toMillis(definition.getTimeout());
+
+                TransactionProxy newTx = txFactory.txStart(transactionConcurrency,
+                    convertToIgniteIsolationLevel(definition.getIsolationLevel()), timeout);
+
+                if (log.isDebugEnabled())
+                    log.debug("Started Ignite transaction: " + newTx);
+
+                txObj.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
+            }
+
+            txObj.getTransactionHolder().setSynchronizedWithTransaction(true);
+            txObj.getTransactionHolder().setTransactionActive(true);
+
+            tx = txObj.getTransactionHolder().getTransaction();
+
+            // Bind the session holder to the thread.
+            if (txObj.isNewTransactionHolder())
+                TransactionSynchronizationManager.bindResource(txFactory, txObj.getTransactionHolder());
+        }
+        catch (Exception ex) {
+            if (tx != null)
+                tx.close();
+
+            throw new CannotCreateTransactionException("Could not create Ignite transaction", ex);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Committing Ignite transaction: " + tx);
+
+        try {
+            tx.commit();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not commit Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Rolling back Ignite transaction: " + tx);
+
+        try {
+            tx.rollback();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not rollback Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        assert tx != null;
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Setting Ignite transaction rollback-only: " + tx);

Review comment:
       Is `tx` have readable `toString` implementation?

##########
File path: modules/spring/src/main/java/org/apache/ignite/transactions/spring/AbstractSpringTransactionManager.java
##########
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.transactions.spring;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxy;
+import org.apache.ignite.internal.transactions.proxy.TransactionProxyFactory;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.transaction.CannotCreateTransactionException;
+import org.springframework.transaction.InvalidIsolationLevelException;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionSystemException;
+import org.springframework.transaction.support.AbstractPlatformTransactionManager;
+import org.springframework.transaction.support.DefaultTransactionStatus;
+import org.springframework.transaction.support.ResourceTransactionManager;
+import org.springframework.transaction.support.SmartTransactionObject;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
+import org.springframework.transaction.support.TransactionSynchronizationUtils;
+
+/** Abstract implementation of Spring Transaction manager with omitted Ignite cluster access logic. */
+public abstract class AbstractSpringTransactionManager extends AbstractPlatformTransactionManager
+    implements ResourceTransactionManager, ApplicationListener<ContextRefreshedEvent>
+{
+    /** Transaction factory.*/
+    private TransactionProxyFactory txFactory;
+
+    /** Ignite logger. */
+    private IgniteLogger log;
+
+    /** Transaction concurrency level. */
+    private TransactionConcurrency transactionConcurrency;
+
+    /** Default transaction isolation. */
+    private TransactionIsolation dfltTxIsolation;
+
+    /** Default transaction timeout. */
+    private long dfltTxTimeout;
+
+    /**
+     * Gets transaction concurrency level.
+     *
+     * @return Transaction concurrency level.
+     */
+    public TransactionConcurrency getTransactionConcurrency() {
+        return transactionConcurrency;
+    }
+
+    /**
+     * Sets transaction concurrency level.
+     *
+     * @param transactionConcurrency transaction concurrency level.
+     */
+    public void setTransactionConcurrency(TransactionConcurrency transactionConcurrency) {
+        this.transactionConcurrency = transactionConcurrency;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onApplicationEvent(ContextRefreshedEvent evt) {
+        if (transactionConcurrency == null)
+            transactionConcurrency = defaultTransactionConcurrency();
+
+        dfltTxIsolation = defaultTransactionIsolation();
+
+        dfltTxTimeout = defaultTransactionTimeout();
+
+        log = log();
+
+        txFactory = createTransactionFactory();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object doGetTransaction() throws TransactionException {
+        IgniteTransactionObject txObj = new IgniteTransactionObject();
+
+        txObj.setTransactionHolder(
+            (IgniteTransactionHolder)TransactionSynchronizationManager.getResource(txFactory), false);
+
+        return txObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
+        if (definition.getIsolationLevel() == TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
+            throw new InvalidIsolationLevelException("Ignite does not support READ_UNCOMMITTED isolation level.");
+
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+        TransactionProxy tx = null;
+
+        try {
+            if (txObj.getTransactionHolder() == null || txObj.getTransactionHolder().isSynchronizedWithTransaction()) {
+                long timeout = dfltTxTimeout;
+
+                if (definition.getTimeout() > 0)
+                    timeout = TimeUnit.SECONDS.toMillis(definition.getTimeout());
+
+                TransactionProxy newTx = txFactory.txStart(transactionConcurrency,
+                    convertToIgniteIsolationLevel(definition.getIsolationLevel()), timeout);
+
+                if (log.isDebugEnabled())
+                    log.debug("Started Ignite transaction: " + newTx);
+
+                txObj.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
+            }
+
+            txObj.getTransactionHolder().setSynchronizedWithTransaction(true);
+            txObj.getTransactionHolder().setTransactionActive(true);
+
+            tx = txObj.getTransactionHolder().getTransaction();
+
+            // Bind the session holder to the thread.
+            if (txObj.isNewTransactionHolder())
+                TransactionSynchronizationManager.bindResource(txFactory, txObj.getTransactionHolder());
+        }
+        catch (Exception ex) {
+            if (tx != null)
+                tx.close();
+
+            throw new CannotCreateTransactionException("Could not create Ignite transaction", ex);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Committing Ignite transaction: " + tx);
+
+        try {
+            tx.commit();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not commit Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Rolling back Ignite transaction: " + tx);
+
+        try {
+            tx.rollback();
+        }
+        catch (Exception e) {
+            throw new TransactionSystemException("Could not rollback Ignite transaction", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+
+        assert tx != null;
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Setting Ignite transaction rollback-only: " + tx);
+
+        tx.setRollbackOnly();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doCleanupAfterCompletion(Object transaction) {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+
+        // Remove the transaction holder from the thread, if exposed.
+        if (txObj.isNewTransactionHolder()) {
+            TransactionProxy tx = txObj.getTransactionHolder().getTransaction();
+            TransactionSynchronizationManager.unbindResource(txFactory);
+
+            if (log.isDebugEnabled())
+                log.debug("Releasing Ignite transaction: " + tx);
+        }
+
+        txObj.getTransactionHolder().clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean isExistingTransaction(Object transaction) throws TransactionException {
+        IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
+
+        return (txObj.getTransactionHolder() != null && txObj.getTransactionHolder().isTransactionActive());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getResourceFactory() {
+        return txFactory;
+    }
+
+    /**
+     * @param isolationLevel Spring isolation level.
+     * @return Ignite isolation level.
+     */
+    private TransactionIsolation convertToIgniteIsolationLevel(int isolationLevel) {
+        TransactionIsolation isolation = dfltTxIsolation;
+        switch (isolationLevel) {
+            case TransactionDefinition.ISOLATION_READ_COMMITTED:
+                isolation = TransactionIsolation.READ_COMMITTED;
+                break;
+            case TransactionDefinition.ISOLATION_REPEATABLE_READ:
+                isolation = TransactionIsolation.REPEATABLE_READ;
+                break;
+            case TransactionDefinition.ISOLATION_SERIALIZABLE:
+                isolation = TransactionIsolation.SERIALIZABLE;
+        }
+        return isolation;
+    }
+
+    /** @return Default transaction isolation. */
+    protected abstract TransactionIsolation defaultTransactionIsolation();
+
+    /** @return Default transaction timeout. */
+    protected abstract long defaultTransactionTimeout();
+
+    /** @return Default transaction concurrency. */
+    protected abstract TransactionConcurrency defaultTransactionConcurrency();
+
+    /** Creates instance of {@link TransactionProxyFactory} that will be used to start new Ignite transactions. */
+    protected abstract TransactionProxyFactory createTransactionFactory();
+
+    /** @return Ignite logger.  */
+    protected abstract IgniteLogger log();
+
+    /**
+     * An object representing a managed Ignite transaction.
+     */
+    protected static class IgniteTransactionObject implements SmartTransactionObject {
+        /** */
+        private IgniteTransactionHolder transactionHolder;

Review comment:
       Lets use `tx` in var names




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org