package com.mybatis;

import com.mybatis.mapper.UserMapper;
import com.mybatis.model.Context;
import com.mybatis.model.User;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
class MybatisApplicationTests {

    private static final AnnotationConfigApplicationContext context =
            new AnnotationConfigApplicationContext("application.yml");

    @Autowired
    DataSource dataSource;

    @Autowired
    UserMapper userMapper;

    @Test
    void contextLoads() throws SQLException {
        Context context = new Context("123","阿萨德");
        User user = new User("test","男",context);
        userMapper.insert(user);
    }

    @Test
    void batchInsert(){
        List<User> users = new ArrayList<User>();
        for(int i=0;i<2;i++){
            Context context = new Context("context"+i,"lowww"+i);
            User user = new User("名字"+i,"男"+i,context);
            users.add(user);
        }
        boolean isSuccess = userMapper.batchInsert(users);
    }
}
