Example usage for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult

List of usage examples for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult

Introduction

In this page you can find the example usage for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult.

Prototype

TransactionCallbackWithoutResult

Source Link

Usage

From source file:com.thoughtworks.go.server.dao.UserSqlMapDao.java

private void changeEnabledStatus(final List<String> usernames, final boolean enabled) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/*from w w w.j  a  v a  2 s.  c o m*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                @Override
                public void afterCommit() {
                    clearEnabledUserCountFromCache();
                }
            });
            String queryString = String.format("update %s set enabled = :enabled where name in (:userNames)",
                    User.class.getName());
            Query query = sessionFactory.getCurrentSession().createQuery(queryString);
            query.setParameter("enabled", enabled);
            query.setParameterList("userNames", usernames);
            query.executeUpdate();
        }
    });
}

From source file:com.hs.mail.imap.user.DefaultUserManager.java

public void deleteAlias(final long id) {
    getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
        public void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                UserDao dao = DaoFactory.getUserDao();
                dao.deleteAlias(id);//  w  w w .ja va 2s  .  c o  m
            } catch (DataAccessException ex) {
                status.setRollbackOnly();
                throw ex;
            }
        }
    });
}

From source file:ch.tatool.app.service.impl.UserAccountServiceImpl.java

/**
 * Closes an opened account.//from ww  w  . jav a2 s  .c o m
 * This method should free all opened resources.
 * 
 * Note: This method does NOT save the account data!
 */
public void closeAccount(UserAccount account) {
    // force the database to shutdown
    final UserAccountImpl userAccount = (UserAccountImpl) account;
    // shutdown the database - necessary for hsql. we do it currently by adding a shutdown=true parameter to the connection string
    userAccount.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
        public void doInTransactionWithoutResult(TransactionStatus status) {
            UserAccountDAO userAccountDAO = userAccount.getUserAccountDAO();
            userAccountDAO.shutdown();
        }
    });

    // destroy all singletons - this will trigger the close method of the DataSource 
    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) userAccount.getBeanFactory();
    beanFactory.destroySingletons();
}

From source file:eu.databata.Propagator.java

private void propagateSingleEntry(final String id, final File file) {
    if (LOG.isInfoEnabled()) {
        LOG.info("Processing entry with id = " + id);
    }//from w  w w  .  j a  v  a  2 s.com
    try {
        historyLogger.setCurrentDbChange(id);
        if (!simulationMode) {
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {
                @Override
                protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                    try {
                        reloadFired = sqlExecutor.executeFile(id, file);
                    } catch (Exception e) {
                        transactionStatus.setRollbackOnly();
                        throw new RuntimeException(e);
                    }
                }
            });
        } else {
            reloadFired = sqlExecutor.executeFile(id, file);
        }
    } finally {
        historyLogger.setCurrentDbChange(null);
    }
}

From source file:edu.wisc.jmeter.dao.JdbcMonitorDao.java

@Override
public void purgeRequestLog(final String host, final Date before) {
    final Map<String, Object> params = new LinkedHashMap<String, Object>();
    params.put("before", before);
    params.put("host", host);

    this.transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/*from  w w  w . j  a  va  2s .  c  o m*/
        protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
            final int purgedRequests = jdbcTemplate.update(
                    "DELETE FROM MONITOR_LOG " + "WHERE HOST_NAME = :host AND LAST_SAMPLE < :before", params);
            if (purgedRequests > 0) {
                log.info("Purged " + purgedRequests + " requests for " + host + " older than " + before
                        + " from database");
            }
        }
    });
}

From source file:com.thoughtworks.go.server.service.ScheduleServiceIntegrationTest.java

@Test
public void shouldUnlockPipelineWhenLastStageCompletes() throws Exception {
    String pipelineName = "cruise";
    String firstStageName = JOB_NAME;
    String secondStageName = "twist";
    configHelper.addPipeline(pipelineName, firstStageName);
    configHelper.addStageToPipeline(pipelineName, "twist");
    configHelper.lockPipeline(pipelineName);
    final Pipeline pipeline = PipelineMother.completedPipelineWithStagesAndBuilds(pipelineName,
            new ArrayList<>(Arrays.asList(firstStageName, secondStageName)),
            new ArrayList<>(Arrays.asList(JOB_NAME, "twist")));
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/* ww  w .  j  a  va2s  . c  o m*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            materialRepository.save(pipeline.getBuildCause().getMaterialRevisions());
        }
    });
    pipelineService.save(pipeline);
    assertThat(pipelineLockService.isLocked(pipelineName), is(true));
    scheduleService.unlockIfNecessary(pipeline, pipeline.getStages().first());
    assertThat(pipelineLockService.isLocked(pipelineName), is(true));
    scheduleService.unlockIfNecessary(pipeline, pipeline.getStages().last());
    assertThat(pipelineLockService.isLocked(pipelineName), is(false));
}

From source file:com.thoughtworks.go.server.persistence.OauthRepository.java

public void deleteUsersOauthGrants(final List<String> userIds) {
    txnTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override//from  w w w .j  a  va 2  s .co m
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            getHibernateTemplate().execute(new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException, SQLException {
                    deleteEntitiesByUserIds(OauthAuthorization.class, session, userIds);
                    deleteEntitiesByUserIds(OauthToken.class, session, userIds);
                    return true;
                }
            });
        }
    });
}

From source file:com.serotonin.mango.db.dao.UserDao.java

public void deleteUser(final int userId) {
    getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
        @SuppressWarnings("synthetic-access")
        @Override//from www . j  a va  2  s.  com
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            Object[] args = new Object[] { userId };
            ejt.update("update userComments set userId=null where userId=?", args);
            ejt.update("delete from mailingListMembers where userId=?", args);
            ejt.update("update pointValueAnnotations set sourceId=null where sourceId=? and sourceType="
                    + SetPointSource.Types.USER, args);
            ejt.update("delete from userEvents where userId=?", args);
            ejt.update(
                    "update events set ackUserId=null, alternateAckSource="
                            + EventInstance.AlternateAcknowledgementSources.DELETED_USER + " where ackUserId=?",
                    args);
            ejt.update("delete from users where id=?", args);
        }
    });
}

From source file:com.thoughtworks.go.server.dao.PipelineSqlMapDaoIntegrationTest.java

private void save(final Pipeline pipeline) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/* w  w  w. j a  v  a 2  s  .c  om*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            materialRepository.save(pipeline.getBuildCause().getMaterialRevisions());
            pipelineDao.save(pipeline);
        }
    });
}