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:test.TestBackAction.java

/**
 * {@inheritDoc}//from ww  w .  ja  v  a  2  s. com
 */
@Override
public boolean execute(IActionHandler actionHandler, Map<String, Object> context) {
    Date start = new Date();
    try {
        for (int i = 1; i <= 10; i++) {
            Thread.sleep(1000);
            setProgress(((double) i) / 10);
        }
        final HibernateBackendController bc = (HibernateBackendController) getController(context);
        bc.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                EnhancedDetachedCriteria cityCrit = EnhancedDetachedCriteria.forClass(City.class);
                cityCrit.add(Restrictions.eq(City.ZIP, "69000"));
                City lyon = bc.findFirstByCriteria(cityCrit, EMergeMode.MERGE_KEEP, City.class);
                lyon.setName(Long.toString(System.currentTimeMillis()));
            }
        });
        //      if (System.currentTimeMillis() % 2 == 0) {
        //        throw new NullPointerException(
        //            "This is a test for an unhandled exception on thread " + Thread.currentThread().getName());
        //      }
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    Date end = new Date();
    Map<String, Object> completionContext = new HashMap<>();
    setActionParameter("Asynchronous action that was started at " + start + "has completed at " + end,
            completionContext);
    actionHandler.executeLater(completionAction, completionContext);
    return super.execute(actionHandler, context);
}

From source file:com.bitsofproof.supernode.core.GetHeadersHandler.java

@Override
public void process(GetHeadersMessage m, BitcoinPeer peer) {
    log.trace("received getheader from " + peer.getAddress());
    List<String> locator = new ArrayList<String>();
    for (byte[] h : m.getLocators()) {
        locator.add(new Hash(h).toString());
    }/*from  w w  w .  ja  v  a  2s.com*/
    List<String> inventory = store.getInventory(locator, new Hash(m.getStop()).toString(), 2000);
    final HeadersMessage hm = (HeadersMessage) peer.createMessage("headers");
    for (final String h : inventory) {
        new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                status.setRollbackOnly();

                Blk b;
                try {
                    b = store.getBlock(h);
                    if (b != null) {
                        WireFormat.Writer writer = new WireFormat.Writer();
                        b.toWireHeaderOnly(writer);
                        hm.getBlockHeader().add(writer.toByteArray());
                    }
                } catch (ValidationException e) {
                }
            }
        });
    }
    if (hm.getBlockHeader().size() > 0) {
        peer.send(hm);
        log.debug("sent  " + hm.getBlockHeader().size() + " block headers to " + peer.getAddress());
    }
}

From source file:org.terasoluna.tourreservation.domain.service.tourinfo.PriceCalculateSharedServiceImpl.java

@PostConstruct
public void loadAges() {
    // use TransactionTemplate to avoid SQLException which tells set-readonly is not allowed
    // see https://github.com/terasolunaorg/terasoluna-tourreservation/issues/163
    TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override//from   ww  w .ja  va  2  s . c om
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            childAge = ageRepository.findOne("1");
            adultAge = ageRepository.findOne("0");
        }
    });
}

From source file:org.osiam.auth.oauth_client.OsiamAuthServerClientProvider.java

@PostConstruct
private void createAuthServerClient() {
    TransactionTemplate tmpl = new TransactionTemplate(txManager);
    tmpl.execute(new TransactionCallbackWithoutResult() {
        @Override/*  w ww  .j  a va 2s  .c o  m*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            ClientEntity clientEntity = null;

            try {
                clientEntity = clientDao.getClient(AUTH_SERVER_CLIENT_ID);
            } catch (ResourceNotFoundException e) {
                LOGGER.log(Level.INFO, "No auth server found. The auth server will be created.");
            }

            if (clientEntity == null) {
                int validity = 10;

                clientEntity = new ClientEntity();
                Set<String> scopes = new HashSet<String>();
                scopes.add(Scope.GET.toString());
                scopes.add(Scope.POST.toString());
                scopes.add(Scope.PATCH.toString());

                Set<String> grants = new HashSet<String>();
                grants.add(GrantType.CLIENT_CREDENTIALS.toString());

                clientEntity.setId(AUTH_SERVER_CLIENT_ID);
                clientEntity.setRefreshTokenValiditySeconds(validity);
                clientEntity.setAccessTokenValiditySeconds(validity);
                clientEntity.setRedirectUri(authServerHome);
                clientEntity.setScope(scopes);
                clientEntity.setImplicit(true);
                clientEntity.setValidityInSeconds(validity);
                clientEntity.setGrants(grants);

                clientEntity = clientDao.create(clientEntity);
            }

            authServerClientSecret = clientEntity.getClientSecret();
        }
    });
}

From source file:org.openmrs.module.imbmetadata.deploy.bundle.ImbMetadataBundle.java

/**
 * Setting multiple GPs is much faster in a single transaction
 *//* w  w w.  j  av a 2s.c  o  m*/
protected void setGlobalProperties(final Map<String, String> properties) {
    TransactionTemplate transactionTemplate = new TransactionTemplate(platformTransactionManager);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            for (Map.Entry<String, String> entry : properties.entrySet()) {
                setGlobalProperty(entry.getKey(), entry.getValue());
            }
        }
    });
}

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

public void transaction(final Runnable txn) {
    txnTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override//from www.ja va  2  s .c  o m
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            txn.run();
        }
    });
}

From source file:ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc.java

@Scheduled(fixedDelay = 10 * DateUtils.MILLIS_PER_SECOND)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public synchronized void pollForStaleSearches() {
    Date cutoff = new Date(System.currentTimeMillis() - myDaoConfig.getExpireSearchResultsAfterMillis());
    ourLog.debug("Searching for searches which are before {}", cutoff);

    Collection<Search> toDelete = mySearchDao.findWhereCreatedBefore(cutoff);
    if (toDelete.isEmpty()) {
        return;//from   w  w w . j av  a 2s . c  o  m
    }

    TransactionTemplate tt = new TransactionTemplate(myTransactionManager);
    for (final Search next : toDelete) {
        tt.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus theArg0) {
                Search searchToDelete = mySearchDao.findOne(next.getId());
                ourLog.info("Expiring stale search {} / {}", searchToDelete.getId(), searchToDelete.getUuid());
                mySearchIncludeDao.deleteForSearch(searchToDelete.getId());
                mySearchResultDao.deleteForSearch(searchToDelete.getId());
                mySearchDao.delete(searchToDelete);
            }
        });
    }

    ourLog.info("Deleted {} searches, {} remaining", toDelete.size(), mySearchDao.count());

}

From source file:com.alibaba.otter.manager.biz.config.canal.impl.CanalServiceImpl.java

/**
 * //from ww w . ja  va2 s.com
 */
public void create(final Canal canal) {
    Assert.assertNotNull(canal);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(TransactionStatus status) {

            try {
                CanalDO canalDO = modelToDo(canal);
                canalDO.setId(0L);
                if (!canalDao.checkUnique(canalDO)) {
                    String exceptionCause = "exist the same repeat canal in the database.";
                    logger.warn("WARN ## " + exceptionCause);
                    throw new RepeatConfigureException(exceptionCause);
                }
                canalDao.insert(canalDO);
                canal.setId(canalDO.getId());
            } catch (RepeatConfigureException rce) {
                throw rce;
            } catch (Exception e) {
                logger.error("ERROR ## create canal has an exception!");
                throw new ManagerException(e);
            }
        }
    });
}

From source file:net.cpollet.jixture.tests.integration.hibernate3.BaseTestDatabaseTestSupport.java

private void cleanup() {
    executeInNewTransaction(new TransactionCallbackWithoutResult() {
        @Override//from   www .j av a 2 s.c o  m
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            unitDaoFactory.getUnitDao().deleteAll(User.class);
        }
    });

    assertDatabaseDoesNotContainUser();
}

From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.UserRoleDaoTransactionDecorator.java

public void createRole(final IRole roleToCreate)
        throws AlreadyExistsException, UncategorizedUserRoleDaoException {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            userRoleDao.createRole(roleToCreate);
        }/*w ww.java  2 s.  c  om*/
    });
}