Search in sources :

Example 51 with TransactionCallbackWithoutResult

use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project ma-modules-public by infiniteautomation.

the class MaintenanceEventDao method deleteMaintenanceEvent.

public void deleteMaintenanceEvent(final int maintenanceEventId) {
    MaintenanceEventVO me = getMaintenanceEvent(maintenanceEventId);
    final ExtendedJdbcTemplate ejt2 = ejt;
    if (me != null) {
        getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                ejt2.update("delete from eventHandlersMapping where eventTypeName=? and eventTypeRef1=?", new Object[] { MaintenanceEventType.TYPE_NAME, maintenanceEventId });
                ejt2.update("delete from maintenanceEvents where id=?", new Object[] { maintenanceEventId });
            }
        });
        AuditEventType.raiseDeletedEvent(AuditEvent.TYPE_NAME, me);
    }
}
Also used : ExtendedJdbcTemplate(com.serotonin.db.spring.ExtendedJdbcTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 52 with TransactionCallbackWithoutResult

use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project ma-modules-public by infiniteautomation.

the class GraphicalViewDao method saveView.

public void saveView(final GraphicalView view) {
    getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            // Decide whether to insert or update.
            if (view.getId() == Common.NEW_ID)
                insertView(view);
            else
                updateView(view);
        }
    });
}
Also used : TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 53 with TransactionCallbackWithoutResult

use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project otter by alibaba.

the class CanalServiceImpl method modify.

/**
 * 修改
 */
public void modify(final Canal canal) {
    Assert.assertNotNull(canal);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                CanalDO canalDo = modelToDo(canal);
                if (canalDao.checkUnique(canalDo)) {
                    canalDao.update(canalDo);
                } else {
                    String exceptionCause = "exist the same repeat canal in the database.";
                    logger.warn("WARN ## " + exceptionCause);
                    throw new RepeatConfigureException(exceptionCause);
                }
            } catch (RepeatConfigureException rce) {
                throw rce;
            } catch (Exception e) {
                logger.error("ERROR ## modify canal(" + canal.getId() + ") has an exception!");
                throw new ManagerException(e);
            }
        }
    });
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) CanalDO(com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO) TransactionStatus(org.springframework.transaction.TransactionStatus) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 54 with TransactionCallbackWithoutResult

use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project otter by alibaba.

the class ChannelServiceImpl method create.

/**
 * 添加Channel
 */
public void create(final Channel channel) {
    Assert.assertNotNull(channel);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                ChannelDO channelDo = modelToDo(channel);
                channelDo.setId(0L);
                if (!channelDao.checkUnique(channelDo)) {
                    String exceptionCause = "exist the same name channel in the database.";
                    logger.warn("WARN ## " + exceptionCause);
                    throw new RepeatConfigureException(exceptionCause);
                }
                channelDao.insert(channelDo);
                arbitrateManageService.channelEvent().init(channelDo.getId());
            } catch (RepeatConfigureException rce) {
                throw rce;
            } catch (Exception e) {
                logger.error("ERROR ## create channel has an exception ", e);
                throw new ManagerException(e);
            }
        }
    });
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) TransactionStatus(org.springframework.transaction.TransactionStatus) ChannelDO(com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) InvalidConfigureException(com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException)

Example 55 with TransactionCallbackWithoutResult

use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project otter by alibaba.

the class ChannelServiceImpl method remove.

/**
 * 删除Channel
 */
public void remove(final Long channelId) {
    Assert.assertNotNull(channelId);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                arbitrateManageService.channelEvent().destory(channelId);
                channelDao.delete(channelId);
            } catch (Exception e) {
                logger.error("ERROR ## remove channel has an exception ", e);
                throw new ManagerException(e);
            }
        }
    });
}
Also used : TransactionStatus(org.springframework.transaction.TransactionStatus) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) InvalidConfigureException(com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException)

Aggregations

TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)328 TransactionStatus (org.springframework.transaction.TransactionStatus)277 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)179 Test (org.junit.jupiter.api.Test)158 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)70 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)54 UserTransaction (jakarta.transaction.UserTransaction)43 SQLException (java.sql.SQLException)37 UncategorizedSQLException (org.springframework.jdbc.UncategorizedSQLException)29 Test (org.junit.Test)25 Connection (java.sql.Connection)23 TransactionSynchronization (org.springframework.transaction.support.TransactionSynchronization)22 InOrder (org.mockito.InOrder)21 Date (java.util.Date)18 UnexpectedRollbackException (org.springframework.transaction.UnexpectedRollbackException)18 List (java.util.List)16 DataSource (javax.sql.DataSource)15 ArrayList (java.util.ArrayList)14 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)13 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)13