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:org.trpr.platform.core.impl.persistence.PersistenceDelegate.java

/**
 * Updates the underlying data store with information available in the specified Criteria using the specified PersistenceProvider
 * Note that this method is transactional by default.
 * It is advisable to use {@link PersistenceManagerProvider#update(Criteria)} instead of calling this method directly.    
 * @param criteria the Criteria instance containing update data fields and values
 * @param provider the PersistenceProvider to use for the persistence call
 * @return int identifying the success status of update operation
 * @throws PersistenceException in case of errors during persistence
 *//* w  w w.j  ava  2  s .  c om*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.DEFAULT, rollbackForClassName = {
        "Exception" })
public int update(Criteria criteria, PersistenceProvider provider) throws PersistenceException {
    return provider.update(criteria);
}

From source file:com.ibm.asset.trails.service.impl.ReconServiceImpl.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void breakResultToQueue(List<BreakResult> breakResultList) {
    // TODO Auto-generated method stub

    Set<ReconLicense> reconLicenseSet = new HashSet<ReconLicense>();

    // save ReconInstalledSoftware and construct reconLicenseSet
    for (BreakResult breakResult : breakResultList) {
        ReconInstalledSoftware reconInstalledSoftware = breakResult.getReconInstalledSoftware();

        if (reconInstalledSoftware != null) {
            ReconInstalledSoftware dbRis = findQueueByInstalledSoftwareId(
                    reconInstalledSoftware.getInstalledSoftware().getId());
            if (null == dbRis) {
                getEntityManager().persist(reconInstalledSoftware);
            }/*from   w  w  w. ja  v  a2  s  .  c  o m*/
        }

        Set<ReconLicense> rlSet = breakResult.getReconLicenseSet();
        if (null != rlSet && rlSet.size() > 0) {
            reconLicenseSet.addAll(rlSet);
        }
    }

    // Save ReconLicense
    for (ReconLicense reconLicense : reconLicenseSet) {
        // always persist result
        ReconLicense dbRl = reconLicenseDAO.getExistingReconLicense(reconLicense.getLicense().getId());
        if (null == dbRl) {
            getEntityManager().persist(reconLicense);
        }
    }
}

From source file:es.emergya.bbdd.dao.UsuarioHome.java

@Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public boolean delete(Usuario entity) {
    if (entity == null)
        throw new NullPointerException("El usuario a borrar es nulo.");

    org.hibernate.Session currentSession = getSession();
    currentSession.clear();//from   w  w w.ja v  a 2  s  . co  m
    if (entity.getId() == null)
        return true;

    try {
        entity = this.get(entity.getId());
    } catch (Throwable t) {
        log.error("Tiene toda la pinta de que estamos borrando algo ya borrado.", t);
    }

    if (entity == null)
        return true;

    if (entity.getClientesConectados() != null && entity.getClientesConectados().size() > 0) {
        log.debug("Se intent borrar a un usuario conectado a una estacin fija.");
        return false;
    }

    currentSession
            .createSQLQuery("delete from  usuarios_x_capas_informacion where fk_usuarios=" + entity.getId())
            .executeUpdate();

    this.remove(entity.getId());

    return true;
}

From source file:es.emergya.bbdd.dao.HistoricoGPSHome.java

@Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public HistoricoGPS saveOrUpdate(HistoricoGPS hgps) {

    Session currentSession = getSession();
    currentSession.clear();//from w w  w . j a va2s  . c  o  m

    HistoricoGPS entity = null;

    if (hgps.getId() == null || (hgps.getId() != null && this.get(hgps.getId()) == null))
        entity = hgps;
    else
        entity = (HistoricoGPS) currentSession.merge(hgps);

    currentSession.saveOrUpdate(entity);
    return entity;
}

From source file:bean.RedSocial.java

/**
 * /*from   ww  w .j  ava2  s.  c  om*/
 * @param _username
 * @param _email
 * @param _password 
 */
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = transactionalBusinessException.ComentariosViaException.class)
public void solicitarAcceso(String _username, String _email, String _password) {
    if (daoUsuario.obtenerUsuario(_username) != null) {
        throw new exceptionsBusiness.UsernameNoDisponible();
    }

    String hash = BCrypt.hashpw(_password, BCrypt.gensalt());

    Token token = new Token(_username, _email, hash);
    daoToken.guardarToken(token);

    //enviar token de acceso a la direccion email

    String correoEnvia = "skala2climbing@gmail.com";
    String claveCorreo = "vNspLa5H";

    // La configuracin para enviar correo
    Properties properties = new Properties();
    properties.put("mail.smtp.host", "smtp.gmail.com");
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.port", "587");
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.user", correoEnvia);
    properties.put("mail.password", claveCorreo);

    // Obtener la sesion
    Session session = Session.getInstance(properties, null);

    try {
        // Crear el cuerpo del mensaje
        MimeMessage mimeMessage = new MimeMessage(session);

        // Agregar quien enva el correo
        mimeMessage.setFrom(new InternetAddress(correoEnvia, "Skala2Climbing"));

        // Los destinatarios
        InternetAddress[] internetAddresses = { new InternetAddress(token.getEmail()) };

        // Agregar los destinatarios al mensaje
        mimeMessage.setRecipients(Message.RecipientType.TO, internetAddresses);

        // Agregar el asunto al correo
        mimeMessage.setSubject("Confirmacin de registro");

        // Creo la parte del mensaje
        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        String ip = "90.165.24.228";
        mimeBodyPart.setText("Confirme su registro pulsando en el siguiente enlace: http://" + ip
                + ":8383/redsocialcolaborativaclientangularjs/confirmacion.html?" + "token="
                + token.getToken());
        //mimeBodyPart.setText("Confirme su registro pulsando en el siguiente enlace: "+"Enlace an no disponible");

        // Crear el multipart para agregar la parte del mensaje anterior
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(mimeBodyPart);

        // Agregar el multipart al cuerpo del mensaje
        mimeMessage.setContent(multipart);

        // Enviar el mensaje
        Transport transport = session.getTransport("smtp");
        transport.connect(correoEnvia, claveCorreo);
        transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
        transport.close();

    } catch (UnsupportedEncodingException | MessagingException ex) {
        throw new ErrorEnvioEmail();
    }

}

From source file:org.motechproject.mobile.omi.service.OMIServiceWorkerImpl.java

/**
 * Syncs the status of a <code>GatewayRequest</code> to its corresponding <code>MessageRequest</code>
 *
 * @param response the <code>Gateway</code> to sync
 * @see org.motechproject.mobile.omi.service.OMIServiceWorker#processMessageResponse
 *//* ww w. j a  v  a 2 s. com*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void processMessageResponse(GatewayResponse response) {
    if (response != null) {
        MessageRequestDAO msgReqDao = getCoreManager().createMessageRequestDAO();

        MessageRequest message = response.getGatewayRequest().getMessageRequest();
        if (response.getMessageStatus() == MStatus.RETRY && message.getTryNumber() >= getMaxTries()) {
            response.setMessageStatus(MStatus.FAILED);
        }

        getStatHandler().handleStatus(response);

        message.setStatus(response.getMessageStatus());

        msgReqDao.merge(message);
    }
}

From source file:architecture.ee.web.community.poll.DefaultPollManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void deletePollOptions(Poll poll, List<PollOption> options) {
    try {/*from w  w  w .  java 2 s .  c  o  m*/
        pollDao.deletePollOptions(poll, options);
        updatePoll(poll);
    } catch (NotFoundException e) {
        e.printStackTrace();
    }
}

From source file:es.emergya.bbdd.dao.CapaInformacionHome.java

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public void removeUsuarios(CapaInformacion ci) {
    try {//from ww w . j ava 2s  .com
        final Session currentSession = getSession();
        currentSession.clear();
        CapaInformacion r = this.get(ci.getId());
        if (r != null && r.getCapasInformacion() != null) {
            for (CapaInformacionUsuario capaUsuario : r.getCapasInformacion()) {
                currentSession.delete(capaUsuario);
            }
        }
    } catch (Throwable t) {
        log.error(t, t);
    }

}

From source file:com.epam.catgenome.dao.ReferenceGenomeDaoTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testNewFileRegister() {
    Reference newreference = getTestReference();

    final Long referenceId = newreference.getId();
    newreference.setName(newreference.getName() + referenceId);
    biologicalDataItemDao.createBiologicalDataItem(newreference);
    referenceGenomeDao.createReferenceGenome(newreference, referenceId);

    final Reference newReferenceGenomeFile = referenceGenomeDao.loadReferenceGenome(newreference.getId());
    assertNotNull("Reference isn't found by the given ID.", newReferenceGenomeFile);
    assertEquals("not equals param", newreference.getName(), newReferenceGenomeFile.getName());
    assertEquals("not equals param", newreference.getPath(), newReferenceGenomeFile.getPath());
    assertEquals("not equals param", newreference.getCreatedDate(), newReferenceGenomeFile.getCreatedDate());

    final List<Reference> newList = referenceGenomeDao.loadAllReferenceGenomes();
    assertNotNull(newList);/*from  w w w  .j  a v  a  2  s  .c om*/
}

From source file:com.google.ie.business.service.impl.ShardedCounterServiceImpl.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void updateTotalPoints(String parentKey, long points) {
    logger.debug(// w  w w.  ja v a2 s. co m
            "updating total point in sharded counter for parent key: " + parentKey + "with points " + points);
    if (parentKey == null) {
        logger.debug("Parent key value is null : ");
        return;
    }
    // Choose the shard randomly from the available shards.
    Random generator = new Random();
    int shardNum = generator.nextInt(DaoConstants.SHARDED_COUNTERS);
    List<ShardedCounter> shards = shardedCounterDao.getShardsByParentKeyAndShardNum(parentKey, shardNum);
    ShardedCounter shard = null;
    ShardedCounter shardToUpdate = null;
    if (shards == null || shards.isEmpty()) {
        shardToUpdate = new ShardedCounter(parentKey);
        shardToUpdate.setTotalPoint(points);
        shardToUpdate.setShardNumber(shardNum);

    } else {
        shard = shards.get(0);
        shardToUpdate = getShardCopy(shard);
        shardToUpdate.setTotalPoint(shardToUpdate.getTotalPoint() + points);
    }

    shardedCounterDao.createOrUpdateShardedCounter(shardToUpdate);
    logger.debug("Total point updated in sharded counter for parent key : " + parentKey);

}