1 3 package jodd.db; 4 5 import jodd.db.connection.ConnectionProvider; 6 7 12 public class DbThreadSession extends DbSession { 13 14 19 public DbThreadSession(ConnectionProvider connectionProvider) { 20 super(connectionProvider); 21 DbThreadSession session = (DbThreadSession) SESSION.get(); 22 if (session != null) { 23 session.closeSession(); 24 } 25 SESSION.set(this); 26 } 27 28 private static final ThreadLocal SESSION = new ThreadLocal () { 29 protected synchronized Object initialValue() { 30 return null; 31 } 32 }; 33 34 38 public static DbSession getCurrentSession() { 39 return (DbSession) SESSION.get(); 40 } 41 42 43 47 public void closeSession() { 48 super.closeSession(); 49 SESSION.set(null); 50 } 51 } 52 | Popular Tags |