MyBatis-一級クエリーキャッシュ
4464 ワード
SqlSessionFactory ssf = null;
// sqlsessionFactory
@Before
public void init() {
try {
InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml");
ssf = new SqlSessionFactoryBuilder().build(in);
} catch (IOException e) {
e.printStackTrace();
}
}
//
@Test
public void associtation() {
// sqlsession, SQL
SqlSession session = ssf.openSession();
//
UserInfoDao dao = session.getMapper(UserInfoDao.class);
//
UserInfo info=dao.findExtraByUser(1);
// , ,
UserInfo info2=dao.findExtraByUser(1);
//
System.out.println(info);
System.out.println(info2);
//
session.close();
}
一度だけsqlを発行
DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - Opening JDBC Connection
DEBUG [main] - Created connection 1468303011.
DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@578486a3]
DEBUG [main] - ==> Preparing: SELECT * FROM user_info t1,user_extra t2 WHERE t1.id=t2.user_id AND t1.id=?
DEBUG [main] - ==> Parameters: 1(Integer)
DEBUG [main] - <== Total: 1
UserInfo [id=1, userName= , userAddr= , userAge=20, userExtra=UserExtra [id=1, work= , salary=100000.0, userId=1], orders=null]
UserInfo [id=1, userName= , userAddr= , userAge=20, userExtra=UserExtra [id=1, work= , salary=100000.0, userId=1], orders=null]
DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@578486a3]
DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@578486a3]
DEBUG [main] - Returned connection 1468303011 to pool.
SqlSessionFactory ssf = null;
// sqlsessionFactory
@Before
public void init() {
try {
InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml");
ssf = new SqlSessionFactoryBuilder().build(in);
} catch (IOException e) {
e.printStackTrace();
}
}
//
@Test
public void associtation() {
// sqlsession, SQL
SqlSession session = ssf.openSession();
//
UserInfoDao dao = session.getMapper(UserInfoDao.class);
//
UserInfo info=dao.findExtraByUser(1);
// , ,
UserInfo info2=dao.findExtraByUser(2);
//
System.out.println(info);
System.out.println(info2);
//
session.close();
}
DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - Opening JDBC Connection
DEBUG [main] - Created connection 1468303011.
DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@578486a3]
DEBUG [main] - ==> Preparing: SELECT * FROM user_info t1,user_extra t2 WHERE t1.id=t2.user_id AND t1.id=?
DEBUG [main] - ==> Parameters: 1(Integer)
DEBUG [main] - <== Total: 1
DEBUG [main] - ==> Preparing: SELECT * FROM user_info t1,user_extra t2 WHERE t1.id=t2.user_id AND t1.id=?
DEBUG [main] - ==> Parameters: 2(Integer)
DEBUG [main] - <== Total: 1
UserInfo [id=1, userName= , userAddr= , userAge=20, userExtra=UserExtra [id=1, work= , salary=100000.0, userId=1], orders=null]
UserInfo [id=2, userName= , userAddr= , userAge=30, userExtra=UserExtra [id=2, work= , salary=1000.0, userId=2], orders=null]
DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@578486a3]
DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@578486a3]
DEBUG [main] - Returned connection 1468303011 to pool.