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

The following examples show how to use org.springframework.transaction.annotation.Propagation#NESTED . 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 File: PetServiceImpl.java    From Spring with 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 File: StudentDaoTest.java    From fountain with 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 3
Source File: StudentDaoTest.java    From fountain with 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 4
Source File: StudentDaoTest.java    From fountain with 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 5
Source File: CityDaoTest.java    From fountain with 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 File: CityDaoTest.java    From fountain with 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 7
Source File: PersonService.java    From tutorial with 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 8
Source File: PetServiceImpl.java    From Spring with 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 9
Source File: User1ServiceImpl.java    From transaction-test with MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNested(User1 user){
	user1Mapper.insert(user);
}
 
Example 10
Source File: User1ServiceImpl.java    From transaction-test with 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 11
Source File: User1ServiceImpl.java    From transaction-test with 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 12
Source File: User2ServiceImpl.java    From transaction-test with MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNested(User2 user){
	user2Mapper.insert(user);
}
 
Example 13
Source File: User2ServiceImpl.java    From transaction-test with 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 14
Source File: User1ServiceImpl.java    From transaction-test with MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNested(User1 user){
	user1Mapper.insert(user);
}
 
Example 15
Source File: User1ServiceImpl.java    From transaction-test with 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 16
Source File: DatastoreTransactionTemplateTests.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Transactional(propagation = Propagation.NESTED)
public void doNothingUnsupportedPropagation() {
	// This method does nothing, but should fail anyway because of the unsupported
	// propagation.
}
 
Example 17
Source File: User2ServiceImpl.java    From transaction-test with 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 18
Source File: User2ServiceImpl.java    From transaction-test with MIT License 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NESTED)
public void addNested(User2 user){
	user2Mapper.insert(user);
}
 
Example 19
Source File: DemoService.java    From spring-boot-source-analysis-code with Apache License 2.0 4 votes vote down vote up
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
    public void test1() {
        System.out.println("test1 run...");
//        int i = 1 / 0;
        System.out.println("test1 finish...");
    }