

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02
Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

| java代码: |
|
1 2 public static DbSession openSession() { ...}
3 DbSession dbSession = null; 4 try { ...}
5 //System.out.println("session is start"); 6 ConnectionPool connectionPool = PooledConnectionFactory.getConnectionPool(); 7 Connection con = connectionPool.getConnection(); 8 9 Session s = (Session) session.get(); 10 if (s == null) { ...}
11 s = fact.openSession(con);//在此,使用外部连接池所给的连接 14 12 session.set(s); 13 } 15 dbSession = new DbSession(s); 16 } catch (Throwable t) { 17 String msg = "couldn´t open a hibernate session for SessionFactory ´" + "´"; 18 log.error( msg, t ); 19 throw new DbException( msg + " : " + t.getMessage() ); 20 } 21 return dbSession; 22 } 23 |
| java代码: |
|
1 2 public static void closeSession() throws HibernateException,Exception{ ...}
3 Session s = (Session) session.get(); 13 4 session.set(null); 5 if (s != null){ ...}
6 s.connection().close(); 12 }7 s.close(); 8 System.out.println("session closing"); 9 //s = null; 10 11 } |