jp.co.tis.gsp.tools.db.DataSourceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gsp-dba-maven-plugin Show documentation
Show all versions of gsp-dba-maven-plugin Show documentation
To automate the routine work of the DBA, it is a tool to be able to concentrate on the data modeling work.
package jp.co.tis.gsp.tools.db;
import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
/**
* {@link DataSource}の簡易実装クラス。
*
*
* s2-extentionに含まれるDataSourceを利用するとJava11では動作しないため、
* GSPを動作させるための最小限の実装を提供します。
*/
public class DataSourceImpl implements DataSource {
private final String url;
private final String user;
private final String password;
public DataSourceImpl(String url, String user, String password) {
this.url = url;
this.user = user;
this.password = password;
}
@Override
public Connection getConnection() throws SQLException {
return getConnection(user, password);
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
return DriverManager.getConnection(url, username, password);
}
@Override
public T unwrap(Class iface) throws SQLException {
throw new UnsupportedOperationException("unwrap");
}
@Override
public boolean isWrapperFor(Class> iface) throws SQLException {
return false;
}
@Override
public PrintWriter getLogWriter() throws SQLException {
throw new SQLFeatureNotSupportedException("getLogWriter");
}
@Override
public void setLogWriter(PrintWriter out) throws SQLException {
throw new SQLFeatureNotSupportedException("setLogWriter");
}
@Override
public void setLoginTimeout(int seconds) throws SQLException {
DriverManager.setLoginTimeout(seconds);
}
@Override
public int getLoginTimeout() throws SQLException {
return DriverManager.getLoginTimeout();
}
/**
* 本メソッドのInterfaceは1.7で追加されているため、1.6互換のために@Overrideは設定していません。
*
* @return しない。(例外を送出します。)
* @throws SQLFeatureNotSupportedException
*/
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new SQLFeatureNotSupportedException("getParentLogger()");
}
}