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:org.opennms.web.rest.IfServicesRestServiceTest.java

@Override
protected void afterServletStart() throws Exception {
    MockLogAppender.setupLogging(true, "DEBUG");
    m_template.execute(new TransactionCallbackWithoutResult() {

        @Override/*from  ww w .  j  a  va 2s . c  om*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            m_databasePopulator.populateDatabase();
        }
    });
}

From source file:org.opennms.web.rest.RemotePollerAvailabilityRestServiceTest.java

@Test
public void testGetAvailability() {
    final long endMillis = System.currentTimeMillis();
    final long startMillis = endMillis - 12000;
    final long totalTime = endMillis - startMillis;

    TransactionTemplate txTemplate = getBean("transactionTemplate", TransactionTemplate.class);
    txTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override//  w ww. ja v a2 s  . c om
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            final TimeChunker timeChunker = new TimeChunker(totalTime, new Date(startMillis),
                    new Date(endMillis));
            // increment the time segment
            timeChunker.getNextSegment();
            final Collection<OnmsLocationSpecificStatus> allStatusChanges = m_locationMonitorDao
                    .getStatusChangesForApplicationBetween(new Date(startMillis), new Date(endMillis), "IPv6");
            final AvailCalculator calc = new AvailCalculator(timeChunker);

            for (final OnmsLocationSpecificStatus statusChange : allStatusChanges) {
                calc.onStatusChange(statusChange);
            }

            final Collection<OnmsMonitoredService> svcs = m_monServiceDao
                    .findByApplication(m_applicationDao.findByName("IPv6"));
            final double avail = calc.getAvailabilityFor(svcs, 0);
            assertEquals(0.8333, avail, 0.0333);
        }
    });

}

From source file:org.opennms.web.rest.RemotePollerAvailabilityRestServiceTest.java

private void createLocationMonitors() throws InterruptedException {
    TransactionTemplate txTemplate = getBean("transactionTemplate", TransactionTemplate.class);
    txTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override// w ww  .java2 s.  c om
        protected void doInTransactionWithoutResult(TransactionStatus status) {

            System.err.println("======= Starting createLocationMonitors() ======");
            OnmsLocationMonitor locMon1 = new OnmsLocationMonitor();
            locMon1.setDefinitionName("RDU");
            locMon1.setLastCheckInTime(new Date());
            locMon1.setStatus(MonitorStatus.STARTED);
            m_locationMonitorDao.save(locMon1);

            OnmsApplication ipv6App = new OnmsApplication();
            ipv6App.setName("IPv6");
            m_applicationDao.saveOrUpdate(ipv6App);

            OnmsApplication ipv4App = new OnmsApplication();
            ipv4App.setName("IPv4");
            m_applicationDao.saveOrUpdate(ipv4App);

            OnmsMonitoredService service2 = m_monServiceDao.findByType("HTTP").get(1);
            service2.addApplication(ipv4App);
            ipv4App.addMonitoredService(service2);
            m_monServiceDao.saveOrUpdate(service2);
            m_applicationDao.saveOrUpdate(ipv4App);

            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {

                service = m_monServiceDao.findByType("HTTP").get(0);
                service.addApplication(ipv6App);
                ipv6App.addMonitoredService(service);
                m_monServiceDao.saveOrUpdate(service);
                m_applicationDao.saveOrUpdate(ipv6App);

                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.available());
                statusChange.setMonitoredService(service);
                m_locationMonitorDao.saveStatusChange(statusChange);
            }

            System.err.println("======= End createLocationMonitors() ======");

        }
    });

    Thread.sleep(2000L);

    txTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {

                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.unavailable());
                statusChange.setMonitoredService(service);

                m_locationMonitorDao.saveStatusChange(statusChange);
            }
        }
    });

    Thread.sleep(2000L);

    txTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {

                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.available());
                statusChange.setMonitoredService(service);

                m_locationMonitorDao.saveStatusChange(statusChange);
            }
        }
    });

}

From source file:org.opennms.web.rest.v1.AcknowledgmentRestServiceIT.java

@Override
protected void afterServletStart() {
    m_template.execute(new TransactionCallbackWithoutResult() {
        @Override//from w  w w  .j a v  a2  s .c  o m
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            m_databasePopulator.populateDatabase();
        }
    });
}

From source file:org.opennms.web.rest.v1.RemotePollerAvailabilityRestServiceIT.java

@Test
public void testGetAvailability() {
    final long endMillis = System.currentTimeMillis();
    final long startMillis = endMillis - 12000;
    final long totalTime = endMillis - startMillis;

    m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override//from w  ww .  j  a v a2 s. co m
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            final TimeChunker timeChunker = new TimeChunker(totalTime, new Date(startMillis),
                    new Date(endMillis));
            // increment the time segment
            timeChunker.getNextSegment();
            final Collection<OnmsLocationSpecificStatus> allStatusChanges = m_locationMonitorDao
                    .getStatusChangesForApplicationBetween(new Date(startMillis), new Date(endMillis), "IPv6");
            final AvailCalculator calc = new AvailCalculator(timeChunker);

            for (final OnmsLocationSpecificStatus statusChange : allStatusChanges) {
                calc.onStatusChange(statusChange);
            }

            final Collection<OnmsMonitoredService> svcs = m_monServiceDao
                    .findByApplication(m_applicationDao.findByName("IPv6"));
            final double avail = calc.getAvailabilityFor(svcs, 0);
            assertEquals(0.8333, avail, 0.0333);
        }
    });

}

From source file:org.opennms.web.rest.v1.RemotePollerAvailabilityRestServiceIT.java

private void createLocationMonitors() throws InterruptedException {
    m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override/* w  w w. j  a va  2 s.  c  om*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {

            System.err.println("======= Starting createLocationMonitors() ======");
            OnmsLocationMonitor locMon1 = new OnmsLocationMonitor();
            locMon1.setId(UUID.randomUUID().toString());
            locMon1.setLocation("RDU");
            locMon1.setLastUpdated(new Date());
            locMon1.setStatus(MonitorStatus.STARTED);
            m_locationMonitorDao.save(locMon1);

            OnmsApplication ipv6App = new OnmsApplication();
            ipv6App.setName("IPv6");
            m_applicationDao.saveOrUpdate(ipv6App);

            OnmsApplication ipv4App = new OnmsApplication();
            ipv4App.setName("IPv4");
            m_applicationDao.saveOrUpdate(ipv4App);

            OnmsMonitoredService service2 = m_monServiceDao.findByType("HTTP").get(1);
            service2.addApplication(ipv4App);
            ipv4App.addMonitoredService(service2);
            m_monServiceDao.saveOrUpdate(service2);
            m_applicationDao.saveOrUpdate(ipv4App);

            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {

                service = m_monServiceDao.findByType("HTTP").get(0);
                service.addApplication(ipv6App);
                ipv6App.addMonitoredService(service);
                m_monServiceDao.saveOrUpdate(service);
                m_applicationDao.saveOrUpdate(ipv6App);

                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.available());
                statusChange.setMonitoredService(service);
                m_locationMonitorDao.saveStatusChange(statusChange);
            }

            System.err.println("======= End createLocationMonitors() ======");

        }
    });

    Thread.sleep(2000L);

    m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {

                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.unavailable());
                statusChange.setMonitoredService(service);

                m_locationMonitorDao.saveStatusChange(statusChange);
            }
        }
    });

    Thread.sleep(2000L);

    m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {

                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.available());
                statusChange.setMonitoredService(service);

                m_locationMonitorDao.saveStatusChange(statusChange);
            }
        }
    });

}

From source file:org.openvpms.web.workspace.patient.PatientMedicalRecordLinker.java

/**
 * Links the records.//from   w ww  . j av  a 2s  .c  om
 *
 * @param currentEvent   the current instance of the event. May be {@code null}
 * @param currentProblem the current instance of the problem. May be {@code null}
 * @param currentItem    the current instance of the item. May be {@code null}
 * @return {@code true} if the records were linked, {@code false} if an act is no longer available
 */
private boolean linkRecords(final Act currentEvent, final Act currentProblem, final Act currentItem) {
    boolean result = false;
    if (currentEvent == null && event != null) {
        logMissing(event);
    } else if (currentProblem == null && problem != null) {
        logMissing(problem);
    } else if (currentItem == null && item != null) {
        logMissing(item);
    } else {
        TransactionTemplate template = new TransactionTemplate(ServiceHelper.getTransactionManager());
        template.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                link(currentEvent, currentProblem, currentItem);
            }
        });
        this.currentEvent = currentEvent;
        this.currentProblem = currentProblem;
        this.currentItem = currentItem;
        result = true;
    }
    return result;
}

From source file:org.orcid.core.cli.CheckAndFixContributorNameVisibility.java

private void processOrcid(final String orcid) {
    LOG.info("Checking and fixing profile: {}", orcid);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/*from  ww w . j  a  va2s .  c o  m*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            OrcidProfile orcidProfile = orcidProfileManager.retrieveOrcidProfile(orcid);
            OrcidWorks orcidWorks = orcidProfile.retrieveOrcidWorks();
            if (orcidWorks != null) {
                for (OrcidWork orcidWork : orcidWorks.getOrcidWork()) {
                    WorkContributors workContributors = orcidWork.getWorkContributors();
                    if (workContributors != null) {
                        for (Contributor contributor : workContributors.getContributor()) {
                            ContributorOrcid contributorOrcid = contributor.getContributorOrcid();
                            if (contributorOrcid != null) {
                                String orcid = contributorOrcid.getPath();
                                ProfileEntity contributorProfile = profileDao.find(orcid);
                                if (!Visibility.PUBLIC.equals(contributorProfile.getCreditNameVisibility())) {
                                    contributor.setCreditName(null);
                                }
                            }
                        }
                    }
                }
            }
            orcidProfileManager.updateOrcidProfile(orcidProfile);
        }
    });
}

From source file:org.orcid.core.cli.MigrateEmails.java

private void migrateProfiles() {
    long startTime = System.currentTimeMillis();
    @SuppressWarnings("unchecked")
    List<String> orcids = Collections.EMPTY_LIST;
    int doneCount = 0;
    do {/*from w ww . j av a 2  s.c  o m*/
        orcids = profileDao.findOrcidsNeedingEmailMigration(CHUNK_SIZE);
        for (final String orcid : orcids) {
            LOG.info("Migrating emails for profile: {}", orcid);
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {
                @Override
                protected void doInTransactionWithoutResult(TransactionStatus status) {
                    OrcidProfile orcidProfile = orcidProfileManager.retrieveOrcidProfile(orcid);
                    // Save it straight back - it will be saved back in the
                    // new DB table automatically
                    orcidProfileManager.updateOrcidProfile(orcidProfile);
                }
            });
            doneCount++;
        }
    } while (!orcids.isEmpty());
    long endTime = System.currentTimeMillis();
    String timeTaken = DurationFormatUtils.formatDurationHMS(endTime - startTime);
    LOG.info("Finished migrating emails: doneCount={}, timeTaken={} (H:m:s.S)", doneCount, timeTaken);
}

From source file:org.orcid.core.cli.MigrateFundingAmountToANumericValue.java

public void execute() {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/*from   ww w .ja v  a2 s .c  o  m*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            List<ProfileFundingEntity> allEntityesWithAmount = profileFundingDao.getProfileFundingWithAmount();
            for (ProfileFundingEntity entity : allEntityesWithAmount) {
                //Amount filed was removed by card https://trello.com/c/WxbJLlCt/1884-remove-the-amount-field-from-the-profilefundingentity-since-we-now-use-the-bigdecimal-numericamount
                //String amount = entity.getAmount();
                //So, lets leave this empty just in case we need a rollback later
                String amount = "";
                String currencyCode = entity.getCurrencyCode();
                ProfileEntity profile = entity.getProfile();
                Locale locale = getLocaleFromProfile(profile);
                String fixedAmount = fixAmount(amount);
                try {
                    BigDecimal bigDecimal = getAmountAsBigDecimal(fixedAmount, currencyCode, locale);
                    LOGGER.info("FROM: " + amount + " TO: " + fixedAmount + " BigDecimal: " + bigDecimal);
                    entity.setNumericAmount(bigDecimal);
                    profileFundingDao.merge(entity);
                } catch (Exception e) {
                    LOGGER.error("Exception migrating: " + entity.getProfile().getId() + ", " + amount + " = "
                            + fixedAmount);
                }
            }
        }
    });
}