Java Code Examples for org.springframework.transaction.annotation.Propagation#NESTED

The following examples show how to use org.springframework.transaction.annotation.Propagation#NESTED . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Spring   File: PetServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED, readOnly = true)
public String getPetsAsHtml(User owner) {
    Set<Pet> pets = petRepo.findByOwner(owner);
    if(pets.isEmpty()) {
        return "<p>User " + owner.getUsername() + " has no pets.</p>\n";
    }
    StringBuilder htmlSb = new StringBuilder("User " + owner.getUsername() + " has:\n");
    for (Pet pet : pets) {
        htmlSb.append("<p>Name: " + pet.getName() + ", type: " + pet.getPetType() + ", Age: " + pet.getAge() +"</p></br>\n");
    }
    return htmlSb.toString();
}
 
Example 2
Source Project: Spring   File: PetServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED, readOnly = true)
public String getPetsAsHtml(User owner) {
    Set<Pet> pets = petRepo.findByOwner(owner);
    if(pets.isEmpty()) {
        return "<p>User " + owner.getUsername() + " has no pets.</p>\n";
    }
    StringBuilder htmlSb = new StringBuilder("User " + owner.getUsername() + " has:\n");
    for (Pet pet : pets) {
        htmlSb.append("<p>Name: " + pet.getName() + ", type: " + pet.getPetType() + ", Age: " + pet.getAge() +"</p></br>\n");
    }
    return htmlSb.toString();
}
 
Example 3
Source Project: tutorial   File: PersonService.java    License: MIT License 5 votes vote down vote up
/**
 * PROPAGATION_NESTED 如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则进行与PROPAGATION_REQUIRED类似的操作。
 */
@Transactional(propagation=Propagation.NESTED)
public void insertNested(PersonDto person, boolean throwException) {
    personDao.insert(person);
    try {
        System.out.println("xxxxxxxWAITING************");
        Thread.sleep(10000);
    }catch(Exception e) {
        
    }
    if(throwException) {
        throw new RuntimeException("ERROR");
    }
}
 
Example 4
Source Project: fountain   File: CityDaoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Transactional(propagation = Propagation.NESTED)
public void testUpdate() {
    cityService.createCities(5);
    City city = CityHelper.getSingleCity();
    city.setCityId(CityHelper.CITY_ID_PREFIX + 2);
    cityService.updateCity(CityHelper.CITY_ID_PREFIX + 2);
    City city2 = cityService.getById(CityHelper.CITY_ID_PREFIX + 2);
    assertThat(city2, is(city));
}
 
Example 5
Source Project: fountain   File: CityDaoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Transactional(propagation = Propagation.NESTED)
public void testDelete() {
    cityService.createCities(5);
    cityService.deleteCityByIds(CityHelper.getMultipleCityIds(2));
    List<City> cities = cityService.getAll();
    assertThat(cities.size(), is(3));
}
 
Example 6
Source Project: fountain   File: StudentDaoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Transactional(propagation = Propagation.NESTED)
public void testUpdate() {
    studentService.createStudents(5);
    Student student = StudentHelper.getSingleStudent();
    student.setStudentId(StudentHelper.STUDENT_ID_LAST + 2);
    studentService.updateStudent(StudentHelper.STUDENT_ID_LAST + 2);
    Student student2 = studentService.getById(StudentHelper.STUDENT_ID_LAST + 2);
    assertThat(student2, is(student));
}
 
Example 7
Source Project: fountain   File: StudentDaoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Transactional(propagation = Propagation.NESTED)
public void testDelete() {
    studentService.createStudents(5);
    studentService.deleteStudentByIds(StudentHelper.getMultipleStudentIds(2));
    List<Student> students = studentService.getAll();
    assertThat(students.size(), is(3));
}
 
Example 8
Source Project: fountain   File: StudentDaoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Transactional(propagation = Propagation.NESTED)
public void testDeleteAll() {
    //studentService.createStudents(5);
    studentService.deleteAll();
    List<Student> students = studentService.getAll();
    assertThat(students.size(), is(0));
}
 
Example 9
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
    public void test1() {
        System.out.println("test1 run...");
//        int i = 1 / 0;
        System.out.println("test1 finish...");
    }
 
Example 10
Source Project: transaction-test   File: User2ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNested(User2 user){
	user2Mapper.insert(user);
}
 
Example 11
Source Project: transaction-test   File: User2ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNestedException(User2 user){
	user2Mapper.insert(user);
	throw new RuntimeException();
}
 
Example 12
Source Project: transaction-test   File: User1ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNested(User1 user){
	user1Mapper.insert(user);
}
 
Example 13
Source Project: transaction-test   File: User1ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNestedException(User1 user){
	user1Mapper.insert(user);
	throw new RuntimeException();
}
 
Example 14
Source Project: transaction-test   File: User1ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED,readOnly=true)
public User1 getNested(Integer id){
	return user1Mapper.selectByPrimaryKey(id);
}
 
Example 15
Source Project: transaction-test   File: User2ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNested(User2 user){
	user2Mapper.insert(user);
}
 
Example 16
Source Project: transaction-test   File: User2ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNestedException(User2 user){
	user2Mapper.insert(user);
	throw new RuntimeException();
}
 
Example 17
Source Project: transaction-test   File: User1ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNested(User1 user){
	user1Mapper.insert(user);
}
 
Example 18
Source Project: transaction-test   File: User1ServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNestedException(User1 user){
	user1Mapper.insert(user);
	throw new RuntimeException();
}
 
Example 19
@Transactional(propagation = Propagation.NESTED)
public void doNothingUnsupportedPropagation() {
	// This method does nothing, but should fail anyway because of the unsupported
	// propagation.
}