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:be.peerassistedlearning.repository.ApplicationRepositoryTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testUpdate() {
    applicationRepository.save(a1);/* ww  w  .ja v  a 2s  .  c o m*/

    assertNotNull(a1.getId());

    a1.reject();

    applicationRepository.save(a1);

    Application a3 = applicationRepository.findOne(a1.getId());

    assertEquals(a1, a3);

}

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

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testGetById() {
    Room r1 = new Room("2.25", Campus.PROXIMUS, RoomType.COMPUTER);

    repository.save(r1);/*from  w  w  w .j a v a2s. c  o  m*/

    Room r2 = repository.findOne(r1.getId());

    assertNotNull(r2);
    assertEquals(r1, r2);
}

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

@Test
@Override//from www. jav a 2 s.c  o m
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testUpdate() {
    Request request = new Request("some title", "some description", c1, s1);
    requestRepository.save(request);
    assertNotNull(request.getId());

    request.setTitle("some other title");
    requestRepository.save(request);
    assertEquals("some other title", request.getTitle());
}

From source file:com.nec.harvest.service.impl.UserDetailServiceImpl.java

/**
 * Locates the user based on the username. In the actual implementation, the
 * search may possibly be case sensitive, or case insensitive depending on
 * how the implementation instance is configured. In this case, the
 * <code>UserDetails</code> object that comes back may have a username that
 * is of a different case than what was actually requested..
 * //from  ww  w .j a va 2s. c  o  m
 * @param username
 *            the username identifying the user whose data is required.
 * 
 * @return a fully populated user record (never <code>null</code>)
 * 
 * @throws UsernameNotFoundException
 *             if the user could not be found or the user has no
 *             GrantedAuthority
 */
@Override
@Transactional(readOnly = true, rollbackFor = {
        HibernateException.class }, propagation = Propagation.REQUIRES_NEW)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    if (logger.isDebugEnabled()) {
        logger.debug("Locates the user based on the username or usercode");
    }

    // The username or usercode identifying the user whose data is required
    if (StringUtils.isEmpty(username)) {
        logger.warn("The username or usercode identifying the user whose data is required");

        // ??????????
        throw new HarvestAuthenticationException(
                "??????????");
    }

    // Trying to authenticate by username or usercode {} and password [ protected ]
    logger.info("Trying to authenticate by username or usercode {} and password [ protected ]", username);

    try {
        user = userService.findByUsrCode(username);
    } catch (IllegalArgumentException ex) {
        // User's code must not be null or empty
        logger.warn(ex.getMessage());

        // ??????????
        throw new HarvestAuthenticationException(
                "??????????");
    } catch (ObjectNotFoundException ex) {
        logger.warn(ex.getMessage());

        // ??????????
        throw new HarvestAuthenticationException(
                "??????????");
    } catch (org.hibernate.ObjectNotFoundException ex) {
        logger.warn(ex.getMessage());

        // ?????????????
        throw new OrganizationNotFoundException(
                "?????????????");
    } catch (TooManyObjectsException ex) {
        logger.error(ex.getMessage(), ex);

        // ???????????
        throw new TooManyObjectsException("???????????");
    } catch (ConnectionException | ServiceException ex) {
        logger.error(ex.getMessage(), ex);

        // ???????????
        throw new ServiceException("???????????");
    }

    // Wait seconds... The system trying to check the granted authorities for authenticating user {usernameOrUsrCode}
    logger.info(
            "Please wait second(s)... The system trying to check the granted authorities for authenticating user "
                    + username);

    // ?
    // 1?2?3??4
    int kengenkodo = 0;
    String usrKbn = user.getUsrKbn();
    if (StringUtils.isNotEmpty(usrKbn)) {
        kengenkodo = Integer.parseInt(usrKbn);
    }

    // The authorities that should be granted to the caller if they
    // presented the correct username and password and the user is enabled. Not null.
    Collection<GrantedAuthority> authorities = getRolesToBeGranted(kengenkodo);

    // Construct the User with the details required by DaoAuthenticationProvider
    return new org.springframework.security.core.userdetails.User(username, user.getPassword(), authorities);
}

From source file:nl.tranquilizedquality.itest.AbstractDefaultTestPart.java

/**
 * Executes the SQL scripts if they are defined.
 *//*from w w  w  .j  ava2  s.co  m*/
@Before
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void executeSQLScripts() {

    if (this.sqlScripts != null) {
        for (final String script : this.sqlScripts.getSetupScripts()) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Executing script: " + script);
            }
            executeSqlScript(script, false);
        }
    }
}

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

@SuppressWarnings("unchecked")
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public List<Street> getStreet(String nombre) {
    List<Street> res = new LinkedList<Street>();
    Session currentSession = getSession();
    currentSession.flush();//  w ww  .  jav  a2  s .  co m
    Criteria criteria = currentSession.createCriteria(Street.class)
            .add(Restrictions.ilike("nombreviaine", nombre)).addOrder(Order.asc("nombreviaine"))
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    res = criteria.list();
    return res;
}

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

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<String> getAllString() {
    Session currentSession = getSession();
    currentSession.clear();//w  w  w.  j a  va  2  s .c om
    Criteria criteria = currentSession.createCriteria(Rol.class)
            .setProjection(Projections.distinct(Projections.property("nombre"))).addOrder(Order.asc("nombre"))
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

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

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

    repository.save(c1);/*  w w  w .  j  ava  2  s .  c o m*/

    Course c2 = repository.findOne(c1.getId());

    assertNotNull(c2);
    assertEquals(c1, c2);
}

From source file:org.fuin.auction.query.server.AuctionQueryServiceImpl.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public final CategoryDto findById(final Long id) {
    final Category category = categoryDao.find(id);
    // TODO michael Create domain object to dto converter structure
    return new CategoryDto(category.getId(), category.getName(), category.isActive());
}

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

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAdd() {
    Tutor t = new Tutor(s1, courses);

    tutorRepository.save(t);

    assertNotNull(t.getId());
}