1 package com.ibatis.sqlmap.engine.transaction; 2 3 import java.sql.Connection ; 4 import java.sql.SQLException ; 5 6 public class IsolationLevel { 7 8 public static final int UNSET_ISOLATION_LEVEL = -9999; 9 10 private int isolationLevel = UNSET_ISOLATION_LEVEL; 11 private int originalIsolationLevel = UNSET_ISOLATION_LEVEL; 12 13 public void setIsolationLevel(int isolationLevel) { 14 this.isolationLevel = isolationLevel; 15 } 16 17 public void applyIsolationLevel(Connection conn) throws SQLException { 18 if (isolationLevel != UNSET_ISOLATION_LEVEL) { 19 originalIsolationLevel = conn.getTransactionIsolation(); 20 if (isolationLevel != originalIsolationLevel) { 21 conn.setTransactionIsolation(isolationLevel); 22 } 23 } 24 } 25 26 public void restoreIsolationLevel(Connection conn) throws SQLException { 27 if (isolationLevel != originalIsolationLevel) { 28 conn.setTransactionIsolation(originalIsolationLevel); 29 } 30 } 31 32 } 33 | Popular Tags |