KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > transaction > IsolationLevel


1 package com.ibatis.sqlmap.engine.transaction;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.SQLException JavaDoc;
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 JavaDoc conn) throws SQLException JavaDoc {
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 JavaDoc conn) throws SQLException JavaDoc {
27     if (isolationLevel != originalIsolationLevel) {
28       conn.setTransactionIsolation(originalIsolationLevel);
29     }
30   }
31
32 }
33
Popular Tags