Guest

artemb

By: a guest on Oct 7th, 2009  |  syntax: Java  |  size: 1.12 KB  |  hits: 331  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. public class MyOwnConnectionProvider implements ConnectionProvider {
  2.  
  3.     StandardXADataSource ds;
  4.  
  5.     public void configure(Properties properties) throws HibernateException {
  6.         try {
  7.             ds = new StandardXADataSource();
  8.             ds.setDriverName((String) properties.get("hibernate.connection.driver_class"));
  9.             ds.setTransactionManager(Current.getTransactionManager());
  10.             ds.setUrl((String) properties.get("hibernate.connection.url"));
  11.             ds.setUser((String) properties.get("hibernate.connection.username"));
  12.             ds.setPassword((String) properties.get("hibernate.connection.password"));
  13.         } catch (SQLException e) {
  14.             throw new HibernateException(e);
  15.         }
  16.     }
  17.  
  18.     public Connection getConnection() throws SQLException {
  19.         return ds.getXAConnection().getConnection();
  20.     }
  21.  
  22.     public void closeConnection(Connection connection) throws SQLException {
  23.         connection.close();
  24.     }
  25.  
  26.     public void close() throws HibernateException {
  27.  
  28.     }
  29.  
  30.     public boolean supportsAggressiveRelease() {
  31.         return false;
  32.     }
  33. }