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