org.h2gis.utilities.wrapper.DataSourceWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spatial-utilities Show documentation
Show all versions of spatial-utilities Show documentation
Collection of methods to fetch spatial metadata in SFS database like PostGIS or H2Spatial.
Theses functions can be commonly used either in PostGIS or in H2.
Spatial utilities publish also a DataSourceFactory wrapper that provide JDBC Wrapper for spatial functionality.
package org.h2gis.utilities.wrapper;
import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
/**
* Entry point for spatial wrapper of SQL Interfaces.
* @author Nicolas Fortin
*/
public class DataSourceWrapper implements DataSource {
private DataSource dataSource;
public DataSourceWrapper(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public Connection getConnection() throws SQLException {
return new ConnectionWrapper(dataSource.getConnection());
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
return new ConnectionWrapper(dataSource.getConnection(username, password));
}
@Override
public PrintWriter getLogWriter() throws SQLException {
return dataSource.getLogWriter();
}
@Override
public void setLogWriter(PrintWriter out) throws SQLException {
dataSource.setLogWriter(out);
}
@Override
public void setLoginTimeout(int seconds) throws SQLException {
dataSource.setLoginTimeout(seconds);
}
@Override
public int getLoginTimeout() throws SQLException {
return dataSource.getLoginTimeout();
}
// @Override -- Commented out for Java 6 compatibility.
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new UnsupportedOperationException("This Java 7 method is not yet supported.");
}
@Override
public T unwrap(Class iface) throws SQLException {
return dataSource.unwrap(iface);
}
@Override
public boolean isWrapperFor(Class> iface) throws SQLException {
return dataSource.isWrapperFor(iface);
}
}