ingo@1127: /* ingo@1127: * Copyright (c) 2010 by Intevation GmbH ingo@1127: * ingo@1127: * This program is free software under the LGPL (>=v2.1) ingo@1127: * Read the file LGPL.txt coming with the software for details ingo@1127: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1127: */ ingo@1127: tim@884: package de.intevation.gnv.geobackend.sde.datasources; tim@130: tim@380: import java.sql.Array; tim@380: import java.sql.Blob; tim@130: import java.sql.CallableStatement; tim@380: import java.sql.Clob; tim@130: import java.sql.Connection; tim@130: import java.sql.DatabaseMetaData; tim@380: import java.sql.NClob; tim@130: import java.sql.PreparedStatement; tim@380: import java.sql.SQLClientInfoException; tim@130: import java.sql.SQLException; tim@130: import java.sql.SQLWarning; tim@380: import java.sql.SQLXML; tim@130: import java.sql.Savepoint; tim@130: import java.sql.Statement; tim@380: import java.sql.Struct; tim@130: import java.util.Map; tim@380: import java.util.Properties; tim@130: tim@130: import org.apache.log4j.Logger; tim@130: tim@890: import com.esri.sde.sdk.client.SeConnection; tim@890: import com.esri.sde.sdk.client.SeException; tim@890: tim@890: import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; tim@890: import de.intevation.gnv.geobackend.sde.connectionpool.ArcSDEPoolableObjectFactory; tim@890: tim@130: /** sascha@885: * Wrapperclass between an @see java.sql.Connection and an tim@884: * @see com.esri.sde.sdk.client.SeConnection sascha@887: * @author Tim Englich tim@130: */ tim@130: public class ArcSDEConnection implements Connection { tim@130: tim@884: /** tim@130: * the logger, used to log exceptions and additonaly information tim@130: */ tim@130: private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); sascha@885: tim@884: /** tim@884: * The Connection to the ArcSDE-backend. tim@884: */ tim@884: private SeConnection seConnection = null; tim@884: /** sascha@885: * Time that have to be gone until the Server will be requested if tim@884: * the Connection is valid. tim@884: */ tim@884: private long serverRoundtripInterval ; sascha@553: tim@884: /** sascha@885: * The Time which a Connection can be inactive until the Connection tim@884: * will be set to invalid. tim@884: */ sascha@553: private long inactiveInterval; sascha@553: tim@884: /** tim@884: * The TimeStamp of the last usage of this Connection. tim@884: */ sascha@553: private long lastTouch; sascha@885: tim@130: tim@884: /** tim@884: * Constructor tim@884: * @param server the URL to the Server tim@884: * @param port the Port of the Server tim@884: * @param database the Name of the Database tim@884: * @param username the Name of the User tim@884: * @param credentials the Credentials to the User- tim@884: * @param serverRoundtripInterval Time that have to be gone until the Server tim@884: * will be requested if the Connection is valid. tim@884: * @param inactiveInterval the Time which a Connection can be inactive until tim@884: * the Connection will be set to invalid. tim@884: * @throws ConnectionException tim@884: */ tim@884: public ArcSDEConnection( sascha@553: String server, sascha@553: String port, sascha@553: String database, sascha@553: String username, sascha@885: String credentials, sascha@553: long serverRoundtripInterval, sascha@553: long inactiveInterval sascha@885: ) sascha@553: throws ConnectionException sascha@553: { sascha@553: this.serverRoundtripInterval = serverRoundtripInterval; sascha@553: this.inactiveInterval = inactiveInterval; sascha@553: lastTouch = System.currentTimeMillis(); sascha@553: tim@884: try { tim@884: seConnection = new SeConnection( server, port, database, username, credentials); sascha@553: } sascha@553: catch (SeException e) { tim@884: log.error(e,e); tim@884: throw new ConnectionException(e); tim@130: } tim@884: } tim@130: tim@884: /** tim@890: * Validates if the Connection is active tim@890: * @return true if the Connection is active. False if not. tim@884: */ sascha@553: public boolean isActive() { sascha@553: long current = System.currentTimeMillis(); sascha@553: long last; sascha@553: synchronized (this) { sascha@553: last = lastTouch; sascha@553: } sascha@553: return Math.abs(current - last) < inactiveInterval; sascha@553: } sascha@553: tim@884: /** tim@884: * Sets the last-Usage-Time to the Current-time tim@884: */ sascha@553: public void touch() { sascha@553: long time = System.currentTimeMillis(); sascha@553: synchronized (this) { sascha@553: lastTouch = time; sascha@553: } sascha@553: } sascha@553: tim@884: /** tim@884: * @see java.sql.Connection#clearWarnings() tim@884: */ tim@884: public void clearWarnings() throws SQLException { tim@884: } tim@130: tim@884: /** tim@884: * @see java.sql.Connection#close() tim@884: */ tim@884: public void close() throws SQLException { tim@884: try { tim@884: this.seConnection.close(); tim@884: } catch (SeException e) { tim@884: log.error(e,e); tim@884: throw new SQLException(e.getMessage()); tim@884: } tim@884: } tim@130: tim@884: /** tim@884: * @see java.sql.Connection#commit() tim@884: */ tim@884: public void commit() throws SQLException { tim@884: try{ tim@884: this.seConnection.commitTransaction(); tim@130: } catch (SeException e) { tim@884: log.error(e,e); tim@884: throw new SQLException(e.getMessage()); tim@130: } tim@884: } tim@130: tim@884: /** tim@884: * @see java.sql.Connection#createStatement() tim@884: */ tim@884: public Statement createStatement() throws SQLException { tim@884: return new ArcSDEStatement(this); tim@884: } tim@130: tim@884: /** tim@884: * @see java.sql.Connection#createStatement(int, int) tim@884: */ tim@884: public Statement createStatement(int resultSetType, int resultSetConcurrency) tim@884: throws SQLException { tim@884: return new ArcSDEStatement(this); tim@884: } tim@130: tim@884: /** tim@884: * @see java.sql.Connection#createStatement(int, int, int) tim@884: */ tim@884: public Statement createStatement(int resultSetType, tim@884: int resultSetConcurrency, int resultSetHoldability) tim@884: throws SQLException { tim@884: return new ArcSDEStatement(this); tim@884: } tim@130: tim@884: /** tim@884: * @see java.sql.Connection#getAutoCommit() tim@884: */ tim@884: public boolean getAutoCommit() throws SQLException { tim@884: return false; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#getCatalog() tim@884: */ tim@884: public String getCatalog() throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#getHoldability() tim@884: */ tim@884: public int getHoldability() throws SQLException { tim@884: return 0; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#getMetaData() tim@884: */ tim@884: public DatabaseMetaData getMetaData() throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#getTransactionIsolation() tim@884: */ tim@884: public int getTransactionIsolation() throws SQLException { tim@884: return 0; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#getTypeMap() tim@884: */ tim@884: public Map> getTypeMap() throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#getWarnings() tim@884: */ tim@884: public SQLWarning getWarnings() throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#isClosed() tim@884: */ tim@884: public boolean isClosed() throws SQLException { tim@884: try{ tim@884: return this.seConnection.isClosed(); tim@884: } catch (Exception e) { tim@884: log.error(e,e); tim@884: throw new SQLException(e.getMessage()); tim@884: } tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#isReadOnly() tim@884: */ tim@884: public boolean isReadOnly() throws SQLException { tim@884: return false; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#nativeSQL(java.lang.String) tim@884: */ tim@884: public String nativeSQL(String sql) throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareCall(java.lang.String) tim@884: */ tim@884: public CallableStatement prepareCall(String sql) throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareCall(java.lang.String, int, int) tim@884: */ tim@884: public CallableStatement prepareCall(String sql, int resultSetType, tim@884: int resultSetConcurrency) throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareCall(java.lang.String, int, int, int) tim@884: */ tim@884: public CallableStatement prepareCall(String sql, int resultSetType, tim@884: int resultSetConcurrency, int resultSetHoldability) tim@884: throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareStatement(java.lang.String) tim@884: */ tim@884: public PreparedStatement prepareStatement(String sql) throws SQLException { tim@884: tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareStatement(java.lang.String, int) tim@884: */ tim@884: public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) tim@884: throws SQLException { tim@884: tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareStatement(java.lang.String, int[]) tim@884: */ tim@884: public PreparedStatement prepareStatement(String sql, int[] columnIndexes) tim@884: throws SQLException { tim@884: tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareStatement(java.lang.String, java.lang.String[]) tim@884: */ tim@884: public PreparedStatement prepareStatement(String sql, String[] columnNames) tim@884: throws SQLException { tim@884: tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareStatement(java.lang.String, int, int) tim@884: */ tim@884: public PreparedStatement prepareStatement(String sql, int resultSetType, tim@884: int resultSetConcurrency) throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#prepareStatement(java.lang.String, int, int, int) tim@884: */ tim@884: public PreparedStatement prepareStatement(String sql, int resultSetType, tim@884: int resultSetConcurrency, int resultSetHoldability) tim@884: throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#releaseSavepoint(java.sql.Savepoint) tim@884: */ tim@884: public void releaseSavepoint(Savepoint savepoint) throws SQLException { tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#rollback() tim@884: */ tim@884: public void rollback() throws SQLException { tim@884: try { tim@884: this.seConnection.rollbackTransaction(); tim@884: } catch (SeException e) { tim@884: log.error(e,e); tim@884: throw new SQLException(e.getMessage()); tim@884: } tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#rollback(java.sql.Savepoint) tim@884: */ tim@884: public void rollback(Savepoint savepoint) throws SQLException { tim@884: this.rollback(); tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#setAutoCommit(boolean) tim@884: */ tim@884: public void setAutoCommit(boolean autoCommit) throws SQLException { tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#setCatalog(java.lang.String) tim@884: */ tim@884: public void setCatalog(String catalog) throws SQLException { tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#setHoldability(int) tim@884: */ tim@884: public void setHoldability(int holdability) throws SQLException { tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#setReadOnly(boolean) tim@884: */ tim@884: public void setReadOnly(boolean readOnly) throws SQLException { tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#setSavepoint() tim@884: */ tim@884: public Savepoint setSavepoint() throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#setSavepoint(java.lang.String) tim@884: */ tim@884: public Savepoint setSavepoint(String name) throws SQLException { tim@884: return null; tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#setTransactionIsolation(int) tim@884: */ tim@884: public void setTransactionIsolation(int level) throws SQLException { tim@884: } tim@884: tim@884: /** tim@884: * @see java.sql.Connection#setTypeMap(java.util.Map) tim@884: */ tim@884: public void setTypeMap(Map> map) throws SQLException { tim@884: } sascha@885: tim@884: /** tim@130: * @return the seConnection tim@130: */ tim@130: public SeConnection getSeConnection() { tim@884: return seConnection; tim@130: } tim@130: tim@380: public Array createArrayOf(String arg0, Object[] arg1) throws SQLException { tim@380: return null; tim@380: } tim@380: tim@380: public Blob createBlob() throws SQLException { tim@380: return null; tim@380: } tim@380: tim@380: public Clob createClob() throws SQLException { tim@380: return null; tim@380: } tim@380: tim@380: public NClob createNClob() throws SQLException { tim@380: return null; tim@380: } tim@380: tim@380: public SQLXML createSQLXML() throws SQLException { tim@380: return null; tim@380: } tim@380: tim@380: public Struct createStruct(String arg0, Object[] arg1) throws SQLException { tim@380: return null; tim@380: } tim@380: tim@380: public Properties getClientInfo() throws SQLException { tim@380: return null; tim@380: } tim@380: tim@380: public String getClientInfo(String arg0) throws SQLException { tim@380: return null; tim@380: } tim@380: tim@380: public boolean isValid(int arg0) throws SQLException { tim@551: boolean valid = true; tim@551: try { tim@551: this.seConnection.testServer(serverRoundtripInterval); tim@551: } catch (SeException e) { tim@551: log.debug("The validation of the Connection has occured an Error. The connection is invalid."); tim@551: valid = false; tim@551: } sascha@885: tim@551: return valid; tim@380: } tim@380: tim@380: public void setClientInfo(Properties arg0) throws SQLClientInfoException { tim@380: } tim@380: tim@380: public void setClientInfo(String arg0, String arg1) tim@380: throws SQLClientInfoException { tim@380: } tim@380: tim@380: public boolean isWrapperFor(Class iface) throws SQLException { tim@380: return false; tim@380: } tim@380: tim@380: public T unwrap(Class iface) throws SQLException { tim@380: return null; tim@380: } tim@380: tim@130: }