001
014
015 package com.liferay.portal.dao.shard;
016
017 import com.liferay.portal.kernel.dao.shard.ShardUtil;
018
019 import java.io.PrintWriter;
020
021 import java.sql.Connection;
022 import java.sql.SQLException;
023
024 import java.util.logging.Logger;
025
026 import javax.sql.DataSource;
027
028
031 public class ShardDataSource implements DataSource {
032
033 public static DataSource getInstance() {
034 return _instance;
035 }
036
037 public Connection getConnection() throws SQLException {
038 return getDataSource().getConnection();
039 }
040
041 public Connection getConnection(String username, String password)
042 throws SQLException {
043
044 return getDataSource().getConnection(username, password);
045 }
046
047 public int getLoginTimeout() throws SQLException {
048 return getDataSource().getLoginTimeout();
049 }
050
051 public PrintWriter getLogWriter() throws SQLException {
052 return getDataSource().getLogWriter();
053 }
054
055 public Logger getParentLogger() {
056
057
058
059 throw new UnsupportedOperationException();
060 }
061
062 public boolean isWrapperFor(Class<?> clazz) {
063
064
065
066
067 return DataSource.class.equals(clazz);
068 }
069
070 public void setLoginTimeout(int seconds) throws SQLException {
071 getDataSource().setLoginTimeout(seconds);
072 }
073
074 public void setLogWriter(PrintWriter printWriter) throws SQLException {
075 getDataSource().setLogWriter(printWriter);
076 }
077
078 public <T> T unwrap(Class<T> clazz) throws SQLException {
079
080
081
082
083 if (!DataSource.class.equals(clazz)) {
084 throw new SQLException("Invalid class " + clazz);
085 }
086
087 return (T)this;
088 }
089
090 protected DataSource getDataSource() {
091 return ShardUtil.getDataSource();
092 }
093
094 private static ShardDataSource _instance = new ShardDataSource();
095
096 }