1
14
15 package com.liferay.portal.dao.shard;
16
17 import com.liferay.portal.kernel.dao.shard.ShardUtil;
18
19 import java.io.PrintWriter;
20
21 import java.sql.Connection;
22 import java.sql.SQLException;
23
24 import java.util.logging.Logger;
25
26 import javax.sql.DataSource;
27
28
33 public class ShardDataSource implements DataSource {
34
35 public static DataSource getInstance() {
36 return _instance;
37 }
38
39 public Connection getConnection() throws SQLException {
40 return getDataSource().getConnection();
41 }
42
43 public Connection getConnection(String username, String password)
44 throws SQLException {
45
46 return getDataSource().getConnection(username, password);
47 }
48
49 public int getLoginTimeout() throws SQLException {
50 return getDataSource().getLoginTimeout();
51 }
52
53 public PrintWriter getLogWriter() throws SQLException {
54 return getDataSource().getLogWriter();
55 }
56
57 public Logger getParentLogger() {
58
59
61 throw new UnsupportedOperationException();
62 }
63
64 public boolean isWrapperFor(Class<?> clazz) {
65
66
69 return DataSource.class.equals(clazz);
70 }
71
72 public void setLoginTimeout(int seconds) throws SQLException {
73 getDataSource().setLoginTimeout(seconds);
74 }
75
76 public void setLogWriter(PrintWriter printWriter) throws SQLException {
77 getDataSource().setLogWriter(printWriter);
78 }
79
80 public <T> T unwrap(Class<T> clazz) throws SQLException {
81
82
85 if (!DataSource.class.equals(clazz)) {
86 throw new SQLException("Invalid class " + clazz);
87 }
88
89 return (T)this;
90 }
91
92 protected DataSource getDataSource() {
93 return ShardUtil.getDataSource();
94 }
95
96 private static ShardDataSource _instance = new ShardDataSource();
97
98 }