Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. package example.datasource;
  2.  
  3. import java.sql.*;
  4. import javax.sql.*;
  5.  
  6. public class HiveConnectionPoolDataSource extends org.apache.hive.jdbc.HiveDataSource implements ConnectionPoolDataSource {
  7. public PooledConnection getPooledConnection() throws SQLException {
  8. return new HivePooledConnection(null, null);
  9. }
  10.  
  11. public PooledConnection getPooledConnection(String user, String password) throws SQLException {
  12. return new HivePooledConnection(user, password);
  13. }
  14.  
  15. public boolean isWrapperFor(Class<?> iface) throws SQLException {
  16. return ConnectionPoolDataSource.class.equals(iface) || super.isWrapperFor(iface);
  17. }
  18.  
  19. public <T> T unwrap(Class<T> iface) throws SQLException {
  20. return ConnectionPoolDataSource.class.equals(iface) ? (T) this : super.unwrap(iface);
  21. }
  22.  
  23. class HivePooledConnection implements PooledConnection {
  24. private Connection con;
  25. private final String user;
  26. private final String password;
  27.  
  28. HivePooledConnection(String user, String password) {
  29. this.user = user;
  30. this.password = password;
  31. }
  32.  
  33. public void addConnectionEventListener(ConnectionEventListener listener) {}
  34.  
  35. public void addStatementEventListener(StatementEventListener listener) {}
  36.  
  37. public void close() throws SQLException {
  38. if (con != null) {
  39. con.close();
  40. con = null;
  41. }
  42. }
  43.  
  44. public Connection getConnection() throws SQLException {
  45. if (con == null) {
  46. con = user == null
  47. ? HiveConnectionPoolDataSource.this.getConnection()
  48. : HiveConnectionPoolDataSource.this.getConnection(user, password);
  49. return con;
  50. } else
  51. throw new IllegalStateException();
  52. }
  53.  
  54. public void removeConnectionEventListener(ConnectionEventListener listener) {}
  55.  
  56. public void removeStatementEventListener(StatementEventListener listener) {}
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement