/*
 * Copyright 2008-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aspectran.support.orm.mybatis;

import java.sql.SQLException;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
*
* @author Juho Jeong
*
* <p>Created: 2015. 04. 03</p>
*
*/
public class SqlSessionTransactionAdvice {
	
	private final SqlSessionFactory sqlSessionFactory;
	
	private SqlSession sqlSession;
	
	private boolean autoCommit;
	
	public SqlSessionTransactionAdvice(SqlSessionFactoryBean factoryBean) {
		this.sqlSessionFactory = factoryBean.getObject();
	}
	
	public SqlSession getSqlSession() {
		return sqlSession;
	}

	public boolean isAutoCommit() {
		return autoCommit;
	}

	public void setAutoCommit(boolean autoCommit) {
		this.autoCommit = autoCommit;
	}

	public SqlSession open() throws SQLException {
		return sqlSessionFactory.openSession();
	}
	
	public SqlSession open(boolean autoCommit) throws SQLException {
		this.autoCommit = autoCommit;
		return sqlSessionFactory.openSession(autoCommit);
	}
	
	public void commit() throws SQLException {
		if(!autoCommit)
			sqlSession.commit();
	}
	
	public void commit(boolean force) throws SQLException {
		if(!autoCommit)
			sqlSession.commit(force);
	}
	
	public void close() throws SQLException {
		sqlSession.close();
	}
	
}

@@ -819,48 +819,584 @@
 *%0D%0A*
-%0D%0A* @author Juho Jeong%0D%0A*%0D%0A* %3Cp%3ECreated:
+ SqlSession Transaction Advice%0D%0A* %0D%0A* %3Cblockquote cite=%22https://mybatis.github.io/mybatis-3/java-api.html%22%3E%0D%0A* By default MyBatis does not actually commit unless it detects that the database has been changed by a call to insert, update or delete. If you've somehow made changes without calling these methods, then you can pass true into the commit and rollback methods to guarantee that it will be committed (note, you still can't force a session in auto-commit mode, or one that is using an external transaction manager).%0D%0A* %3C/blockquote%3E%0D%0A*  %0D%0A* @author Juho Jeong%0D%0A* @since
  201
@@ -1408,15 +1408,8 @@
 . 03
-%3C/p%3E%0D%0A*
 %0D%0A*/
@@ -1578,24 +1578,94 @@
 Commit;%0D%0A%09%0D%0A
+%09private boolean forceCommit;%0D%0A%09%0D%0A%09private boolean forceRollback;%0D%0A%09%0D%0A
 %09public SqlS
@@ -1856,70 +1856,8 @@
 %0D%0A%0D%0A
-%09public boolean isAutoCommit() %7B%0D%0A%09%09return autoCommit;%0D%0A%09%7D%0D%0A%0D%0A
 %09pub
@@ -1933,32 +1933,226 @@
 oCommit;%0D%0A%09%7D%0D%0A%0D%0A
+%09public void setForceCommit(boolean forceCommit) %7B%0D%0A%09%09this.forceCommit = forceCommit;%0D%0A%09%7D%0D%0A%0D%0A%09public void setForceRollback(boolean forceRollback) %7B%0D%0A%09%09this.forceRollback = forceRollback;%0D%0A%09%7D%0D%0A%0D%0A
 %09public SqlSessi
@@ -2479,16 +2479,27 @@
 .commit(
+forceCommit
 );%0D%0A%09%7D%0D%0A
@@ -2607,32 +2607,725 @@
 force);%0D%0A%09%7D%0D%0A%09%0D%0A
+%09/**%0D%0A%09 * Rollback.%0D%0A%09 * %0D%0A%09 * %3Cblockquote cite=%22https://mybatis.github.io/mybatis-3/java-api.html%22%3E%0D%0A%09 * Most of the time you won't have to call rollback(), as MyBatis will do that for you if you don't call commit. However, if you need more fine grained control over a session where multiple commits and rollbacks are possible, you have the rollback option there to make that possible.%0D%0A%09 * %3C/blockquote%3E%0D%0A%09 *%0D%0A%09 * @throws SQLException the SQL exception%0D%0A%09 */%0D%0A%09public void rollback() throws SQLException %7B%0D%0A%09%09if(!autoCommit)%0D%0A%09%09%09sqlSession.rollback(forceRollback);%0D%0A%09%7D%0D%0A%09%0D%0A%09public void rollback(boolean force) throws SQLException %7B%0D%0A%09%09if(!autoCommit)%0D%0A%09%09%09sqlSession.rollback(force);%0D%0A%09%7D%0D%0A%09%0D%0A
 %09public void clo

add forceCommit and forceRollback