mybatis의 SqlSession에서 commit();close(); vs close(); 어떤걸 해야 하나요?
from Apache Project/Ibatis/Mybatis 2011/04/29 19:51
코드를 보다보니, 아래와 같은 코드가 있어서 확인해 봤습니다.. ^^;;
그래서, http://code.google.com/p/mybatis/source/browse/tags/mybatis-3.0.4/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java 의 session코드에서 commit메쏘드와 close메쏘드를 살펴 봤습니다..
* commit() : 오버로딩하는 두개의 메쏘드가 있네요.. ^^
* close()
위 코드를 보시면, commit();close(); 코드와 close();가 있습니다..
코드를 따라가다 보면, 결국, http://code.google.com/p/mybatis/source/browse/tags/mybatis-3.0.4/src/main/java/org/apache/ibatis/transaction/jdbc/JdbcTransaction.java 에서, 아래와 같은 코드를 볼 수 있습니다.
흠, 따라서 commit();close();와 close();가 동일할 거라는 심증만 가지게 되네요..^^;;
commit();close();해야 하나요?? close();만 하면 되까요?? ㅋㅋ
try {
session = createSqlSession();
// db 처리.. .
// db 처리.. .
} finally {
// db 세션 종료
if(session != null) {
session.commit();
session.close();
session.close();
}
}
그래서, http://code.google.com/p/mybatis/source/browse/tags/mybatis-3.0.4/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java 의 session코드에서 commit메쏘드와 close메쏘드를 살펴 봤습니다..
* commit() : 오버로딩하는 두개의 메쏘드가 있네요.. ^^
public void commit() {
commit(false);
}
public void commit(boolean force) {
try {
executor.commit(isCommitOrRollbackRequired(force));
dirty = false;
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error committing transaction. Cause: " + e, e);
} finally {
ErrorContext.instance().reset();
}
}
commit(false);
}
public void commit(boolean force) {
try {
executor.commit(isCommitOrRollbackRequired(force));
dirty = false;
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error committing transaction. Cause: " + e, e);
} finally {
ErrorContext.instance().reset();
}
}
* close()
public void close() {
try {
executor.close(isCommitOrRollbackRequired(false));
dirty = false;
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error closing transaction. Cause: " + e, e);
} finally {
ErrorContext.instance().reset();
}
}
try {
executor.close(isCommitOrRollbackRequired(false));
dirty = false;
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error closing transaction. Cause: " + e, e);
} finally {
ErrorContext.instance().reset();
}
}
위 코드를 보시면, commit();close(); 코드와 close();가 있습니다..
코드를 따라가다 보면, 결국, http://code.google.com/p/mybatis/source/browse/tags/mybatis-3.0.4/src/main/java/org/apache/ibatis/transaction/jdbc/JdbcTransaction.java 에서, 아래와 같은 코드를 볼 수 있습니다.
public void commit() throws SQLException {
if (!connection.getAutoCommit()) {
connection.commit();
}
}
if (!connection.getAutoCommit()) {
connection.commit();
}
}
public void close() throws SQLException {
resetAutoCommit();
connection.close();
}
resetAutoCommit();
connection.close();
}
protected void resetAutoCommit() {
try {
if (!connection.getAutoCommit()) {
// for compatibility we always use true, as some drivers don't like being left in "false" mode.
connection.setAutoCommit(true);
}
} catch (SQLException e) {
// Only a very poorly implemented driver would fail here,
// and there's not much we can do about that.
throw new TransactionException("Error configuring AutoCommit. " +
"Your driver may not support getAutoCommit() or setAutoCommit(). Cause: " + e, e);
}
}
try {
if (!connection.getAutoCommit()) {
// for compatibility we always use true, as some drivers don't like being left in "false" mode.
connection.setAutoCommit(true);
}
} catch (SQLException e) {
// Only a very poorly implemented driver would fail here,
// and there's not much we can do about that.
throw new TransactionException("Error configuring AutoCommit. " +
"Your driver may not support getAutoCommit() or setAutoCommit(). Cause: " + e, e);
}
}
흠, 따라서 commit();close();와 close();가 동일할 거라는 심증만 가지게 되네요..^^;;
commit();close();해야 하나요?? close();만 하면 되까요?? ㅋㅋ
'Apache Project > Ibatis/Mybatis' 카테고리의 다른 글
| mybatis의 SqlSession에서 commit();close(); vs close(); 어떤걸 해야 하나요? (0) | 2011/04/29 |
|---|---|
| ibatis/mybatis에서 oracle connection detect 하기.. (0) | 2011/01/11 |
| java.lang.IllegalArgumentException: Mapped Statements collection does not contain value xxx.xxx.xxx.xxx (0) | 2010/09/13 |
| mssql 2008 jdbc 세팅하기.. (0) | 2010/06/11 |
| Apache iBatis에서 다중 데이터 베이스 사용 방법 (0) | 2008/08/01 |