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:es.emergya.bbdd.dao.CapaInformacionHome.java

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Integer getTotal() {
    try {//from w  w w. ja  v  a 2 s  .  c o m
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class)
                .setProjection(Projections.rowCount());
        return (Integer) criteria.uniqueResult();
    } catch (Throwable t) {
        log.error(t, t);
        return -1;
    }
}

From source file:be.peerassistedlearning.repository.CourseRepositoryTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testRemove() {
    Course c = new Course("MBI80x", ".NET Programmeren", ".NET", Curriculum.TI, 3);

    repository.save(c);//from ww  w  .  j a v  a  2  s. com

    repository.delete(c);

    c = repository.findOne(c.getId());

    assertNull(c);
}

From source file:cs544.blog.service.BlogService.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override//w  ww . j ava 2s .  c  om
public Post createPost(long id, String title, String contents) {
    //Transaction tx = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
    // Transaction tx = sessionFactory.getCurrentSession().beginTransaction();
    User user = loadUser(id);
    Post post = new Post(title, contents);
    post.setUser(user);
    //userDAO.updateUser(user);
    postDAO.savePost(post);
    //  tx.commit();
    return post;
}

From source file:org.openeos.wf.internal.BaseWorkflowService.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
private Deployment internalDeployBuilder(DeploymentBuilderImpl deploymentBuilderImpl) {
    checkDeploymentIsOk(deploymentBuilderImpl);
    Deployment deployment = saveDeployment(deploymentBuilderImpl);
    for (URL url : deploymentBuilderImpl.urlList) {
        saveWorkflowDefinition(deployment, url);
    }//www  .j  a v a 2 s  . co  m
    return deployment;
}

From source file:be.peerassistedlearning.repository.ApplicationRepositoryTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAdd() {
    applicationRepository.save(a1);
    assertNotNull(a1.getId());
}

From source file:org.brekka.pegasus.core.services.impl.EventServiceImpl.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void transferUnlock(final Transfer transfer, final boolean success) {
    TransferUnlockEvent event = new TransferUnlockEvent();
    event.setTransfer(transfer);/*from w w  w. j a v a  2  s.  c o m*/
    event.setSuccess(success);
    populate(event);
    bundleUnlockEventDAO.create(event);
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Integer getTotal() {
    try {/*from   w  w w.j a  v a2  s  . c o  m*/
        org.hibernate.Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Patrulla.class).setProjection(Projections.rowCount());
        Integer count = (Integer) criteria.uniqueResult();
        return count.intValue();
    } catch (Throwable t) {
        log.error("Error en getTotal()", t);
        return -1;
    }
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public void remove(ClienteConectado persistentInstance) {
    log.debug("removing ClienteConectado instance");
    try {// ww  w . jav a 2 s .  c o  m
        getSession().delete(persistentInstance);
        log.debug("remove successful");
    } catch (RuntimeException re) {
        log.error("remove failed", re);
        throw re;
    }
}

From source file:eu.trentorise.smartcampus.permissionprovider.oauth.NonRemovingTokenServices.java

@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.SERIALIZABLE)
public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, AuthorizationRequest request)
        throws AuthenticationException {
    return refreshWithRepeat(refreshTokenValue, request, false);
}

From source file:org.motechproject.mobile.omp.service.SMSMessagingServiceWorkerImpl.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
public Map<Boolean, Set<GatewayResponse>> sendMessage(GatewayRequest gatewayRequest) {
    logger.debug("Sending message to gateway");
    Set<GatewayResponse> responseList = null;
    Map<Boolean, Set<GatewayResponse>> result = new HashMap<Boolean, Set<GatewayResponse>>();
    try {//from   w  w w .  j a  va2 s.  c o  m
        if ((gatewayRequest.getRecipientsNumber() == null || gatewayRequest.getRecipientsNumber().isEmpty())
                && !ContactNumberType.PUBLIC.toString()
                        .equals(gatewayRequest.getMessageRequest().getPhoneNumberType())) {
            gatewayRequest.setMessageStatus(MStatus.INVALIDNUM);
        } else {
            responseList = this.getGatewayManager().sendMessage(gatewayRequest);
            result.put(true, responseList);
            logger.debug(responseList);
            logger.debug("Updating message status");
            gatewayRequest.setResponseDetails(responseList);
            gatewayRequest.setMessageStatus(MStatus.SENT);
        }
    } catch (MotechException me) {
        logger.error("Error sending message", me);
        gatewayRequest.setMessageStatus(MStatus.SCHEDULED);

        GatewayMessageHandler orHandler = getGatewayManager().getMessageHandler();
        responseList = orHandler.parseMessageResponse(gatewayRequest,
                "error: 901 - Cannot Connect to gateway | Details: " + me.getMessage());
        result.put(false, responseList);
    }
    this.getCache().mergeMessage(gatewayRequest);

    return result;
}