1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.jdbc;
22
23 import org.apache.hadoop.hbase.HBaseConfiguration;
24 import org.apache.hadoop.hbase.hbql.client.HBqlException;
25 import org.apache.hadoop.hbase.hbql.client.HConnectionPool;
26 import org.apache.hadoop.hbase.hbql.client.HConnectionPoolManager;
27 import org.apache.hadoop.hbase.jdbc.impl.ConnectionImpl;
28
29 import javax.sql.ConnectionPoolDataSource;
30 import javax.sql.PooledConnection;
31 import java.io.PrintWriter;
32 import java.sql.SQLException;
33
34 public class ConnectionPool implements ConnectionPoolDataSource {
35
36 private final HConnectionPool connectionPool;
37
38 public ConnectionPool(final int initPoolSize,
39 final int maxConnectionPoolSize) throws HBqlException {
40 this(initPoolSize, maxConnectionPoolSize, null, null);
41 }
42
43 public ConnectionPool(final int initPoolSize,
44 final int maxConnectionPoolSize,
45 final String connectionPoolName) throws HBqlException {
46 this(initPoolSize, maxConnectionPoolSize, connectionPoolName, null);
47 }
48
49 public ConnectionPool(final int initConnectionPoolSize,
50 final int maxConnectionPoolSize,
51 final HBaseConfiguration config) throws HBqlException {
52 this(initConnectionPoolSize, maxConnectionPoolSize, null, config);
53 }
54
55 public ConnectionPool(final int initPoolSize,
56 final int maxConnectionPoolSize,
57 final String poolName,
58 final HBaseConfiguration config) throws HBqlException {
59 this.connectionPool = HConnectionPoolManager.newConnectionPool(initPoolSize,
60 maxConnectionPoolSize,
61 poolName,
62 config);
63 }
64
65 public static int getMaxPoolReferencesPerTablePerConnection() {
66 return HConnectionPoolManager.getMaxPoolReferencesPerTablePerConnection();
67 }
68
69 public static void setMaxPoolReferencesPerTablePerConnection(final int maxPoolReferencesPerTablePerConnection) {
70 HConnectionPoolManager.setMaxPoolReferencesPerTablePerConnection(maxPoolReferencesPerTablePerConnection);
71 }
72
73 private HConnectionPool getConnectionPool() {
74 return this.connectionPool;
75 }
76
77 public PooledConnection getPooledConnection() throws SQLException {
78 return new ConnectionImpl(this.getConnectionPool().takeConnection());
79 }
80
81 public PooledConnection getPooledConnection(final String s, final String s1) throws SQLException {
82 return this.getPooledConnection();
83 }
84
85 public PrintWriter getLogWriter() throws SQLException {
86 return null;
87 }
88
89 public void setLogWriter(final PrintWriter printWriter) throws SQLException {
90
91 }
92
93 public void setLoginTimeout(final int i) throws SQLException {
94
95 }
96
97 public int getLoginTimeout() throws SQLException {
98 return 0;
99 }
100 }