package com.Service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import com.Domain.Context;
import com.Domain.User;
import com.Mapper.UserMapper;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    // 脏读
    @Transactional(isolation = Isolation.READ_UNCOMMITTED)
    public void insert() {
        User user = new User();
        user.setUsername("user");
        user.setPassword("123456");
        Context build = Context.builder().id("123456").username("aaa").password("123456")
                .context("hello world").build();
        user.setContext(build);
        userMapper.insert(user);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        throw new RuntimeException();
    }
    public List<User> findUser() {
        return userMapper.selectAll();
    }
}
