Example usage for org.springframework.transaction.annotation Propagation REQUIRES_NEW

List of usage examples for org.springframework.transaction.annotation Propagation REQUIRES_NEW

Introduction

In this page you can find the example usage for org.springframework.transaction.annotation Propagation REQUIRES_NEW.

Prototype

Propagation REQUIRES_NEW

To view the source code for org.springframework.transaction.annotation Propagation REQUIRES_NEW.

Click Source Link

Document

Create a new transaction, and suspend the current transaction if one exists.

Usage

From source file:com.glaf.core.id.MyBatisDbIdGenerator.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
public synchronized String getNextId() {
    return Long.toString(this.nextId());
}

From source file:com.jfootball.business.impl.SeasonServiceImpl.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void saveEntity(Serializable obj) {
    Season season = (Season) obj;
    seasonDao.saveOrUpdateSeason(season);
}

From source file:fi.hsl.parkandride.back.LockDao.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.SERIALIZABLE)
public Lock acquireLock(String lockName, Duration lockDuration) {
    Optional<Lock> lock = selectLockIfExists(lockName);
    if (lock.isPresent()) {
        Lock existingLock = lock.get();
        if (!existingLock.validUntil.isAfter(DateTime.now())) {
            return claimExpiredLock(existingLock, lockDuration);
        } else {/* ww w  . j  a  v  a 2s.c  o m*/
            throw new LockAcquireFailedException("Existing lock " + existingLock + " is still valid");
        }
    }
    return insertLock(lockName, lockDuration);
}

From source file:com.orange.clara.tool.schedulers.tasks.RefreshTask.java

@Async
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Future<Boolean> runTask(Integer watchedResourceId) throws AsyncTaskException {
    WatchedResource watchedResource = this.watchedResourceRepo.findOne(watchedResourceId);
    logger.debug("Task: refresh {} from {} with type {} ...", watchedResourceId, watchedResource.getLink(),
            watchedResource.getType());/*from ww w  . jav a 2s. c  o m*/
    Crawler crawler = crawlerFactory.findCrawler(watchedResource.getType());
    List<ContentResource> contentResources = null;
    try {
        contentResources = crawler.getLastContent(watchedResource);
    } catch (CrawlerGetContentException e) {
        throw new AsyncTaskException(e.getMessage(), e);
    }
    for (ContentResource contentResource : contentResources) {
        watchedResource.addContentResource(contentResource);
        this.contentResourceRepo.save(contentResource);
    }
    watchedResource.setUpdatedResourceAt(Calendar.getInstance().getTime());
    watchedResource.setLocked(false);
    this.watchedResourceRepo.save(watchedResource);
    if (contentResources.size() > 0) {
        this.publishNotification(watchedResource, contentResources);
    }
    logger.debug("Finished Task: refresh {} from {} with type {}. {} new content(s) found.", watchedResourceId,
            watchedResource.getLink(), watchedResource.getType(), contentResources.size());
    return new AsyncResult<Boolean>(true);
}

From source file:es.emergya.comunications.MessageGenerator.java

/**
 * /*from   ww  w.  j a va 2 s  .c  o  m*/
 * @param tipo
 * @param prioridad
 * @param cuerpo
 * @param destino
 * @return
 */
@Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public static Outbox sendMessage(Integer codigo, Integer tipo, Integer prioridad, String cuerpo, String destino)
        throws MessageGeneratingException {

    if (destino == null) {
        throw new MessageGeneratingException("Destino nulo.");
    }
    if (codigo == null) {
        throw new MessageGeneratingException("Mensaje sin codigo.");
    }
    if (tipo == null) {
        throw new MessageGeneratingException("Mensaje sin tipo.");
    }
    if (prioridad == null) {
        throw new MessageGeneratingException("Prioridad nula");
    }
    if (cuerpo == null) {
        cuerpo = "";
    }

    log.info("sendMessage(" + codigo + "," + tipo + "," + prioridad + "," + cuerpo + "," + destino + ")");

    try {
        Integer tipo_tetra = TipoMensajeConsultas.getTipoByCode(codigo).getTipoTetra();

        // Limpiamos las comillas:
        cuerpo = StringUtils.remove(cuerpo, "'");

        String datagramaTetra = getDatagrama(codigo, tipo, cuerpo);

        Outbox out = new Outbox();
        out.setMarcaTemporal(Calendar.getInstance().getTime());
        out.setDatagramaTetra(datagramaTetra);
        out.setPrioridad(prioridad);
        out.setDestino(StringUtils.leftPad(destino, LogicConstants.getInt("LONGITUD_ISSI", 8), '0'));
        out.setTipo(tipo_tetra);

        log.info("Enviamos el mensaje " + datagramaTetra + " a " + destino + " con prioridad " + prioridad);

        out = bandejaSalidaDAO.save(out);
        log.info("Enviando " + out);
        return out;
    } catch (Exception e) {
        throw new MessageGeneratingException("Error al generar mensaje", e);
    }
}

From source file:fr.treeptik.cloudunit.service.impl.MessageServiceImpl.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Message create(Message message) throws ServiceException {
    try {/*from ww  w  .  j  av a 2 s .  c  o m*/
        return messageDAO.save(message);
    } catch (PersistenceException e) {
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:org.terasoluna.gfw.functionaltest.domain.DBLogCleaner.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void cleanupAll() {
    LOGGER.info("Begin cleanupAll.");

    cleanup(0L);//from w  w w  .  j av  a2 s .  c  o  m

    LOGGER.info("Finished cleanupAll.");
}

From source file:annis.administration.DeleteCorpusDao.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
public void deleteCorpora(List<Long> ids, boolean acquireLock) {
    if (acquireLock && !lockRepositoryMetadataTable(false)) {
        log.error("Another import is currently running");
        return;//from  w  w w .ja  va 2  s  . c o m
    }

    if (ids == null || ids.isEmpty()) {
        return;
    }

    File dataDir = getRealDataDir();

    for (long l : ids) {
        log.info("deleting external data files");

        List<String> filesToDelete = getJdbcTemplate()
                .queryForList("SELECT filename FROM media_files AS m, corpus AS top, corpus AS child\n"
                        + "WHERE\n" + "  m.corpus_ref = child.id AND\n" + "  top.id = ? AND\n"
                        + "  child.pre >= top.pre AND child.post <= top.post", String.class, l);
        for (String fileName : filesToDelete) {
            File f = new File(dataDir, fileName);
            if (f.exists()) {
                if (!f.delete()) {
                    log.warn("Could not delete {}", f.getAbsolutePath());
                }
            }
        }

        log.info("dropping tables");

        log.debug("dropping facts table for corpus " + l);
        getJdbcTemplate().execute("DROP TABLE IF EXISTS facts_" + l);
        getJdbcTemplate().execute("DROP TABLE IF EXISTS facts_edge_" + l);
        getJdbcTemplate().execute("DROP TABLE IF EXISTS facts_node_" + l);
        log.debug("dropping annotation_pool table for corpus " + l);
        getJdbcTemplate().execute("DROP TABLE IF EXISTS annotation_pool_" + l);
        log.debug("dropping annotations table for corpus " + l);
        getJdbcTemplate().execute("DROP TABLE IF EXISTS annotations_" + l);
    }

    log.info("recursivly deleting corpora: " + ids);

    executeSqlFromScript("delete_corpus.sql", makeArgs().addValue(":ids", StringUtils.join(ids, ", ")));
}

From source file:br.com.thiaguten.persistence.demo.hbmcore.HibernatePersistenceProviderImpl.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public <ID extends Serializable, T extends Persistable<ID>> T save(T entity) {
    return super.save(entity);
}

From source file:com.orange.clara.cloud.servicedbdumper.task.ScheduledDeleteDbDumperServiceInstanceTask.java

@Scheduled(fixedDelay = 11000)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void deleteDbDumperServiceInstance() throws JobCreationException {
    List<Job> jobs = jobRepo.findByJobTypeAndJobEvent(JobType.DELETE_DB_DUMPER_SERVICE_INSTANCE,
            JobEvent.START);//from  w  w  w  .j a  v  a 2s .c o m

    logger.debug("Running: delete database reference scheduled task ...");

    for (Job job : jobs) {
        job.setJobEvent(JobEvent.RUNNING);
        jobRepo.save(job);
        DbDumperServiceInstance dbDumperServiceInstance = job.getDbDumperServiceInstance();
        if (!dbDumperServiceInstance.isDeleted()) {
            continue;
        }
        if (dbDumperServiceInstance.getDatabaseDumpFiles().size() > 0) {
            this.jobFactory.createJobDeleteDumps(dbDumperServiceInstance.getDatabaseRef(),
                    dbDumperServiceInstance);

            job.setJobEvent(JobEvent.FINISHED);
            jobRepo.save(job);
            continue;
        }
        job.setDatabaseRefSrc(null);
        jobRepo.save(job);
        try {
            DatabaseRef databaseRef = dbDumperServiceInstance.getDatabaseRef();
            databaseRef.removeDbDumperServiceInstance(dbDumperServiceInstance);
            this.databaseRefRepo.save(databaseRef);

            if (databaseRef.getDbDumperServiceInstances().size() == 0) {
                this.deleteDatabaseRef(dbDumperServiceInstance.getDatabaseRef());
            }
            serviceInstanceRepo.delete(dbDumperServiceInstance);
        } catch (Exception e) {
            job.setJobEvent(JobEvent.ERRORED);
            job.setErrorMessage(e.getMessage());
            jobRepo.save(job);
            continue;
        }

        job.setJobEvent(JobEvent.FINISHED);
        jobRepo.save(job);
    }
    logger.debug("Finished: delete database reference scheduled task ...");

}