# HG changeset patch # User Tim Englich # Date 1251904552 0 # Node ID e4eacd613356901ec991c46ee1ca8bfc176267b3 # Parent 110e3ac1b7d2b0f68289263c2def95e9497e4bee Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken ChangeLog wird nachgereicht da SubversionClientincompatiblitäten vorhanden sind. geo-backend/trunk@7 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/Changelog --- a/geo-backend/Changelog Wed Sep 02 09:07:03 2009 +0000 +++ b/geo-backend/Changelog Wed Sep 02 15:15:52 2009 +0000 @@ -3,4 +3,4 @@ * README, Changelog, Changes, NEWS, TODO: New. Initial setup * Java-Project generated * Library Dependencies Added to pom.xml - * Import of SDE-Datasources + * Import of SDE-Datasources Revision: 3101 from Repository of principal de/intevation/gnv/geobackend/sde/datasources/**/* diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/pom.xml --- a/geo-backend/pom.xml Wed Sep 02 09:07:03 2009 +0000 +++ b/geo-backend/pom.xml Wed Sep 02 15:15:52 2009 +0000 @@ -37,5 +37,10 @@ log4j [1.2,) + + commons-pool + commons-pool + 1.5.2 + diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/base/connectionpool/ConnectionPool.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/connectionpool/ConnectionPool.java Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,35 @@ +package de.intevation.gnv.geobackend.base.connectionpool; + +import java.sql.Connection; +import java.util.Properties; + +import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; + +/** + * Interfacedefinition for an Generic ConnectionPool + * @author Tim Englich + */ +public interface ConnectionPool { + + /** + * Delivers the Connection to the Database + * @param connectionID the ID of the Connection + * @return the Connection to the Database + * @throws ConnectionException + */ + public Connection getConnection(String connectionID) throws ConnectionException; + + /** + * Returns the Connection to the Pool + * @param connection the Connection which should be returned to the Pool + * @throws ConnectionException + */ + public void closeConnection(Connection connection) throws ConnectionException; + + /** + * Initializes the ConnectionPool + * @param properties The Properties which should be used for initializing theConnectionPool + */ + public void initialize(Properties properties); + +} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/base/connectionpool/ConnectionPoolFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/connectionpool/ConnectionPoolFactory.java Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,88 @@ +/** + * + */ +package de.intevation.gnv.geobackend.base.connectionpool; + +import java.util.Properties; + +import org.apache.log4j.Logger; + +import de.intevation.gnv.geobackend.sde.connectionpool.ArcSDEConnectionPool; + +/** + * Factoryimplementation for the Interface ConnectionPool. + * This factory delivers Instances of the Interface ConnectionPool. + * @author Tim Englich + */ +public class ConnectionPoolFactory { + + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(ConnectionPoolFactory.class); + + + /** + * The singleton Instance of this Factory. + */ + private static ConnectionPoolFactory instance = null; + + /** + * The ConnectionPool providing the Connections to the DatabaseBackends + */ + private ConnectionPool connectionPool = null; + + /** + * Basic-Constructor of this Class + */ + private ConnectionPoolFactory() { + super(); + } + + + /** + * This Method provides an singleton Instance of this Class. + * @return an singleton Instance of this Class + */ + public static ConnectionPoolFactory getInstance(){ + if (instance == null){ + instance = new ConnectionPoolFactory(); + } + return instance; + } + + + /** + * Getting the ConnectionPool + * @return the ConnectionPool + */ + public ConnectionPool getConnectionPool(){ + return this.connectionPool; + } + + + /** + * Initializes the ConnectionPool. + * Should only be called once on system startup + * @param properties the Properties for the Individual Configuration of the ConnectionPool + */ + public void initializeConnectionPool(Properties properties){ + log.debug("ConnectionPoolFactory.initializeConnectionPool"); + if (this.connectionPool == null){ + //TODO: Hier könnte anhand eines Flags die Instanz des Connectionpools umgeschaltet werden. + this.connectionPool = new ArcSDEConnectionPool(); + this.connectionPool.initialize(properties); + }else{ + log.warn("ConnectionPool already initialized"); + } + } + + /** + * Checks if the ConnectionPool has already been initialized. + * @return true if the ConnectionPool is initialized. + */ + public boolean isInitialized(){ + return this.connectionPool != null; + } +} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/base/connectionpool/exception/ConnectionException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/connectionpool/exception/ConnectionException.java Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,114 @@ +/** + * Title: lConnectionException, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/exception/ConnectionException.java,v 1.2 2008/08/18 14:50:33 drewnak Exp $ + * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/exception/ConnectionException.java,v $ + * created by: Stefan Blume (blume) + * erstellt am: 21.11.2007 + * Copyright: con terra GmbH, 2005 + * + * modified by: $Author: drewnak $ + * modified on: $Date: 2008/08/18 14:50:33 $ + * Version: $Revision: 1.2 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.geobackend.base.connectionpool.exception; + +import com.esri.sde.sdk.client.SeError; +import com.esri.sde.sdk.client.SeException; + +import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; + +import org.apache.log4j.Logger; + +/** + * The class lConnectionException fulfills the following purposes: + *
    + *
  1. + *
+ * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 08:13:05 + */ +public class ConnectionException extends TechnicalException { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(ConnectionException.class); + + /** + * Constructs a new exception with null as its detail message. + * The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause}. + */ + public ConnectionException() { + } + + /** + * Constructs a new exception with the specified detail message. The + * cause is not initialized, and may subsequently be initialized by + * a call to {@link #initCause}. + * + * @param message the detail message. The detail message is saved for + * later retrieval by the {@link #getMessage()} method. + */ + public ConnectionException(String message) { + super(message); + } + public ConnectionException(Throwable pCause) { + super(pCause); + } + + /** + * Constructs a new exception with the specified detail message and + * cause.

Note that the detail message associated with + * cause is not automatically incorporated in + * this exception's detail message. + * + * @param message the detail message (which is saved for later retrieval + * by the {@link #getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.4 + */ + public ConnectionException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Displays the details of an SeException (if available). + * + */ + public void printError() { + if (getCause() != null && getCause() instanceof SeException) { + SeException exception = (SeException) getCause(); + SeError error = exception.getSeError(); + + sLogger.debug("\n ArcSDE Error Number : " + error.getSdeError()); + sLogger.debug(" Error Description : " + error.getErrDesc()); + + int extError = error.getExtError(); + if (extError != 0) + sLogger.debug(" Extended Error Number : " + extError); + + String desc = error.getSdeErrMsg(); + if (desc != null && desc.length() != 0) + sLogger.debug(" Extended Error Description : " + desc); + + desc = error.getExtErrMsg(); + if (desc != null && desc.length() != 0) + sLogger.debug(" Extended Error Description : " + desc); + + sLogger.debug(exception); + + } + + } +} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,81 @@ +package de.intevation.gnv.geobackend.sde.connectionpool; + +import java.sql.Connection; +import java.util.Properties; + +import org.apache.commons.pool.PoolableObjectFactory; +import org.apache.commons.pool.impl.GenericObjectPool; +import org.apache.log4j.Logger; + +import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool; +import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; + +/** + *This is the ArcSDE specific implementation of the Interface ConnectionPool + * @author Tim Englich + */ +public class ArcSDEConnectionPool implements ConnectionPool { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); + + /** + * The Pool which stores the Connections to the ArcSDE Backend + */ + private GenericObjectPool pool = null; + + /** + * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#closeConnection(java.lang.Object) + */ + public void closeConnection(Connection connection) throws ConnectionException { + + try { + //TODO: Muss Connection geschlossen werden? + this.pool.returnObject(connection); + } catch (Exception e) { + log.error(e,e); + throw new ConnectionException(e); + } + + } + + /** + * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#getConnection(java.lang.String) + */ + public synchronized Connection getConnection(String connectionID) throws ConnectionException{ + try { + Object object = this.pool.borrowObject(); + + if (object instanceof Connection){ + return (Connection)object; + }else{ + throw new ConnectionException("Created Object is not an java.sql.Connection"); + } + + } catch (Exception e) { + log.error(e,e); + throw new ConnectionException(e); + } + } + + /** + * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#initialize(java.util.Properties) + */ + public void initialize(Properties properties) { + log.info("ArcSDEConnectionPool.initialize has been called"); + log.info("ConnectionPool will be initialized"); + + PoolableObjectFactory poolableObjectFactory = new ArcSDEPoolableObjectFactory(properties); + + int maxActive = Integer.parseInt(properties.getProperty("maxActive", "10")); + + log.info("Maximum Number of active Connections: "+maxActive); + // TODO weitere Werte einparsen und setzen. + + this.pool = new GenericObjectPool(poolableObjectFactory,maxActive); + + } + +} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,120 @@ +/** + * + */ +package de.intevation.gnv.geobackend.sde.connectionpool; + +import java.sql.Connection; +import java.util.Properties; + +import org.apache.commons.pool.PoolableObjectFactory; +import org.apache.log4j.Logger; + +import com.esri.sde.sdk.client.SeConnection; + +import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; +import de.intevation.gnv.geobackend.sde.datasources.ArcSDEConnection; + +/** + * @author Tim Englich + * + */ +public class ArcSDEPoolableObjectFactory implements PoolableObjectFactory { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); + + /** + * The URL to the ArcSDE Server + */ + private String server = null; + /** + * The Port the ArcSDE Server is connected to. + */ + private String port = null; + /** + * The Name of the Database + */ + private String database = null; + /** + * The Username for the Authentication + */ + private String username = null; + /** + * The Credentials which belongs to the User + */ + private String credentials = null; + + + /** + * Constructor of this Class + * @param properties the Properties which includes the ConnectionParams to the Database + */ + public ArcSDEPoolableObjectFactory(Properties properties) { + + this.server = properties.getProperty("server"); + this.port = properties.getProperty("port"); + this.database = properties.getProperty("database"); + this.username = properties.getProperty("username"); + this.credentials = properties.getProperty("credentials"); + + log.info("ArcSDEPoolableObjectFactory initialized"); + log.info("Server: "+this.server); + log.info("Port: "+this.port); + log.info("Database: "+this.database); + log.info("User: "+this.username); + } + + /** + * @see org.apache.commons.pool.PoolableObjectFactory#activateObject(java.lang.Object) + */ + public void activateObject(Object arg0) throws Exception { + log.debug("ArcSDEPoolableObjectFactory.activateObject"); + // TODO Was muss hier passieren? + } + + /** + * @see org.apache.commons.pool.PoolableObjectFactory#destroyObject(java.lang.Object) + */ + public void destroyObject(Object arg0) throws Exception { + log.debug("ArcSDEPoolableObjectFactory.destroyObjectb"); + if (arg0 instanceof SeConnection){ + ((SeConnection)arg0).close(); + }else{ + log.warn("Object cannot be handled"); + } + } + + /** + * @see org.apache.commons.pool.PoolableObjectFactory#makeObject() + */ + public Object makeObject() throws Exception { + log.debug("ArcSDEPoolableObjectFactory.makeObject"); + Connection con; + try { + con = new ArcSDEConnection(this.server, this.port, this.database, this.username, this.credentials); + } + catch (ConnectionException e) { + throw new ConnectionException("Establishing a connection to database failed: " + e.toString(), e); + } + return con; + } + + /** + * @see org.apache.commons.pool.PoolableObjectFactory#passivateObject(java.lang.Object) + */ + public void passivateObject(Object arg0) throws Exception { + log.debug("ArcSDEPoolableObjectFactory.passivateObject"); + // TODO Was muss hier passieren? + } + + /** + * @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object) + */ + public boolean validateObject(Object arg0) { + // TODO Was muss hier passieren? + log.debug("ArcSDEPoolableObjectFactory.validateObject"); + return true; + } +} \ No newline at end of file diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,352 @@ +/** + * + */ + package de.intevation.gnv.geobackend.sde.datasources; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Savepoint; +import java.sql.Statement; +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.esri.sde.sdk.client.SeConnection; +import com.esri.sde.sdk.client.SeException; + +import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; +import de.intevation.gnv.geobackend.sde.connectionpool.ArcSDEPoolableObjectFactory; + +/** + * @author Tim Englich + * + */ +public class ArcSDEConnection implements Connection { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); + + private SeConnection seConnection = null; + + + + /** + * Constructor + */ + public ArcSDEConnection(String server,String port,String database,String username,String credentials) throws ConnectionException { + try { + seConnection = new SeConnection(server,port,database,username,credentials); + } catch (SeException e) { + log.error(e,e); + throw new ConnectionException(e); + } + } + + /** + * @see java.sql.Connection#clearWarnings() + */ + public void clearWarnings() throws SQLException { + } + + /** + * @see java.sql.Connection#close() + */ + public void close() throws SQLException { + try { + this.seConnection.close(); + } catch (SeException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.Connection#commit() + */ + public void commit() throws SQLException { + try{ + this.seConnection.commitTransaction(); + } catch (SeException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.Connection#createStatement() + */ + public Statement createStatement() throws SQLException { + + return new ArcSDEStatement(this); + } + + /** + * @see java.sql.Connection#createStatement(int, int) + */ + public Statement createStatement(int resultSetType, int resultSetConcurrency) + throws SQLException { + // TODO: Übergabeparameter beachten + return new ArcSDEStatement(this); + } + + /** + * @see java.sql.Connection#createStatement(int, int, int) + */ + public Statement createStatement(int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + // TODO: Übergabeparameter beachtenbb + return new ArcSDEStatement(this); + } + + /** + * @see java.sql.Connection#getAutoCommit() + */ + public boolean getAutoCommit() throws SQLException { + return false; + } + + /** + * @see java.sql.Connection#getCatalog() + */ + public String getCatalog() throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#getHoldability() + */ + public int getHoldability() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Connection#getMetaData() + */ + public DatabaseMetaData getMetaData() throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#getTransactionIsolation() + */ + public int getTransactionIsolation() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Connection#getTypeMap() + */ + public Map> getTypeMap() throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#getWarnings() + */ + public SQLWarning getWarnings() throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#isClosed() + */ + public boolean isClosed() throws SQLException { + try{ + return this.seConnection.isClosed(); + } catch (Exception e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.Connection#isReadOnly() + */ + public boolean isReadOnly() throws SQLException { + return false; + } + + /** + * @see java.sql.Connection#nativeSQL(java.lang.String) + */ + public String nativeSQL(String sql) throws SQLException { + return null; + } + + /** + * @see java.sql.Connection#prepareCall(java.lang.String) + */ + public CallableStatement prepareCall(String sql) throws SQLException { + return null; + } + + /** + * @see java.sql.Connection#prepareCall(java.lang.String, int, int) + */ + public CallableStatement prepareCall(String sql, int resultSetType, + int resultSetConcurrency) throws SQLException { + return null; + } + + /** + * @see java.sql.Connection#prepareCall(java.lang.String, int, int, int) + */ + public CallableStatement prepareCall(String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#prepareStatement(java.lang.String) + */ + public PreparedStatement prepareStatement(String sql) throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#prepareStatement(java.lang.String, int) + */ + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) + throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#prepareStatement(java.lang.String, int[]) + */ + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) + throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#prepareStatement(java.lang.String, java.lang.String[]) + */ + public PreparedStatement prepareStatement(String sql, String[] columnNames) + throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#prepareStatement(java.lang.String, int, int) + */ + public PreparedStatement prepareStatement(String sql, int resultSetType, + int resultSetConcurrency) throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#prepareStatement(java.lang.String, int, int, int) + */ + public PreparedStatement prepareStatement(String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#releaseSavepoint(java.sql.Savepoint) + */ + public void releaseSavepoint(Savepoint savepoint) throws SQLException { + } + + /** + * @see java.sql.Connection#rollback() + */ + public void rollback() throws SQLException { + try { + this.seConnection.rollbackTransaction(); + } catch (SeException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.Connection#rollback(java.sql.Savepoint) + */ + public void rollback(Savepoint savepoint) throws SQLException { + this.rollback(); + } + + /** + * @see java.sql.Connection#setAutoCommit(boolean) + */ + public void setAutoCommit(boolean autoCommit) throws SQLException { + } + + /** + * @see java.sql.Connection#setCatalog(java.lang.String) + */ + public void setCatalog(String catalog) throws SQLException { + } + + /** + * @see java.sql.Connection#setHoldability(int) + */ + public void setHoldability(int holdability) throws SQLException { + } + + /** + * @see java.sql.Connection#setReadOnly(boolean) + */ + public void setReadOnly(boolean readOnly) throws SQLException { + } + + /** + * @see java.sql.Connection#setSavepoint() + */ + public Savepoint setSavepoint() throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#setSavepoint(java.lang.String) + */ + public Savepoint setSavepoint(String name) throws SQLException { + + return null; + } + + /** + * @see java.sql.Connection#setTransactionIsolation(int) + */ + public void setTransactionIsolation(int level) throws SQLException { + } + + /** + * @see java.sql.Connection#setTypeMap(java.util.Map) + */ + public void setTypeMap(Map> map) throws SQLException { + } + + /** + * @return the seConnection + */ + public SeConnection getSeConnection() { + return seConnection; + } + +} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPool.java --- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPool.java Wed Sep 02 09:07:03 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,288 +0,0 @@ -/******************************************************************************* - * Copyright © 2007 52°North Initiative for Geospatial Open Source Software GmbH - * - * Author: Oliver Meyer, University of Muenster - * - * Contact: Andreas Wytzisk, 52°North Initiative for Geospatial Open Source - * Software GmbH, Martin-Luther-King-Weg 24, 48155 Muenster, Germany, - * info@52north.org - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License version 2 as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; even without the implied WARRANTY OF MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program (see gnu-gpl v2.txt). If not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA or - * visit the Free Software Foundation’s web page, http://www.fsf.org. - * - ******************************************************************************/ -// Last changes on: 2007-06-03 -// Last changes by: Oliver Meyer - -package de.intevation.gnv.geobackend.sde.datasources; - -import java.util.Date; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; -import java.util.Map.Entry; - -import org.apache.log4j.Logger; - -import com.esri.sde.sdk.client.SeConnection; -import com.esri.sde.sdk.client.SeException; - -import de.intevation.gnv.geobackend.sde.datasources.exception.ConnectionException; -import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; - -/** - * Connection Pool for ArcSDE databases. - * - * @author Oliver Meyer - * @version 1.0 - */ -public class ArcSDEConnectionPool { - - /** - * Default Logging instance - */ - private static final Logger sLogger = Logger.getLogger(ArcSDEConnectionPool.class); - private static boolean sDebug = sLogger.isDebugEnabled(); - - /** - * timer for holding connections - */ - private Timer timer; - - /** - * the logger, used to log exceptions and additonaly information - */ - private static Logger log = Logger.getLogger(ArcSDEConnectionPool.class); - - /** - * Hashtable containing the connections as keys and Boolean as value (False if the connection is not used) - */ - private Hashtable connections; - - private static ArcSDEConnectionPool sInstance = null; - - private static ArcSDEConnectionParams sParams = null; - - public static ArcSDEConnectionPool getInstance() throws TechnicalException { - if (sInstance == null) { - throw new TechnicalException("The ArcSDEConnectionPool has to be configured first!"); - } - return sInstance; - } - - public static boolean isConfigured() { - return sParams != null; - } - - public static void configure(ArcSDEConnectionParams pParams) throws TechnicalException { - if (sDebug) sLogger.debug("configure()"); - - if (sInstance == null) { - synchronized (ArcSDEConnectionPool.class) { - sInstance = new ArcSDEConnectionPool(pParams); - } - } else { - throw new TechnicalException("The ArcSDEConnectionPool is already configured: " + pParams.toString()); - } - - } - - - private ArcSDEConnectionPool(ArcSDEConnectionParams pParams) throws ConnectionException { - if (sDebug) sLogger.debug("ArcSDEConnectionPool()"); - sParams = pParams; - - connections = new Hashtable(); - initPool(sParams.getInitConnections()); - timer = new Timer("ArcSDEConnectionPoolTimer"); - startConnectionTask(); - } - - /** - * help method for initializing the connection pool - * - * @param initConnections number of initial connections - * @throws OwsExceptionReport if creating connections failed while initializing the connection pool - */ - protected void initPool(int initConnections) throws ConnectionException { - - // initialize connections; - // "false" indicates that the connection is not used yet - for (int i = 0; i < initConnections; ++i) { - SeConnection con = getNewConnection(); - connections.put(con, Boolean.FALSE); - } - } - - /** - * Method returns an available connection from the pool, and sets it on "not available". After the query - * operation, you have to "give back" the connection to the pool with the returnConnection method! - * - * @return ArcSDE connection to execute the query - * @throws OwsExceptionReport If all connections are in use and no further connection could be established - * @throws OwsExceptionReport - */ - protected SeConnection getConnection() throws ConnectionException { - - SeConnection con = null; - - Enumeration cons = connections.keys(); - - // no other operation (maybe adding a connection) while checking which - // (or whether a) connection is available - synchronized (connections) { - - while (cons.hasMoreElements()) { - con = cons.nextElement(); - Boolean b = connections.get(con); - - // checking whether connection is available - if (b == Boolean.FALSE) { - // connection is available, now test, whether connection is - // OK (with setAutoCommit) - try { - con.setTransactionAutoCommit(1000); - } - catch (SeException sdeEx) { - // problem with connection, so remove and create new - // connection - connections.remove(con); - - con = getNewConnection(); - - } - // set connection "not available" (Value=true) - connections.put(con, Boolean.TRUE); - return con; - } - } - } - - // if no connections are available, create new one - if (connections.size() <= sParams.getMaxConnections()) { - - con = getNewConnection(); - - connections.put(con, Boolean.TRUE); - } - // if maximal number of connections is arrived, throw exception! - else { - throw new ConnectionException("All db connections are in use. Please try again later!"); - } - - // return new Connection - return con; - } - - /** - * abstract method creates a new connection; must be implemented by all subclasses! - * - * @return Returns connection - new connection to the database - * @throws OwsExceptionReport if creating a new connection failed - */ - private SeConnection getNewConnection() throws ConnectionException { - SeConnection con; - - // creating new connection - try { - - con = new SeConnection(sParams.getServer(), sParams.getInstance(), sParams.getDatabase(), sParams.getUser(), sParams.getPwd()); - - // Class.forName("org.postgresql.Driver"); - // con = DriverManager.getConnection(props.getProperty("CONNECTION"), props); - - } - catch (SeException sdeEx) { - throw new ConnectionException("Establishing a connection to database failed: " + sdeEx.toString(), sdeEx); - } - - return con; - } - - /** - * Invoke this method after executing the query with this connection, so that the connection is already - * available in the pool - * - * @param con the connection which was used and now is available again - */ - public void returnConnection(SeConnection con) { - if (connections.containsKey(con)) { - connections.put(con, Boolean.FALSE); - } - } - - /** - * method sends a query for every connection - */ - private void holdConnections() { - Set> entrySet = connections.entrySet(); - Iterator> iter = entrySet.iterator(); - SeConnection con = null; - while (iter.hasNext()) { - Entry entry = iter.next(); - - //Connection in use? - if (entry.getValue() == false) { - con = entry.getKey(); - try { - con.setTransactionAutoCommit(1000); - } - catch (SeException sdeEx) { - - //if sql exception occurs, try to built new connection and put connection into pool - connections.remove(con); - try { - SeConnection conNew = getNewConnection(); - connections.put(conNew, Boolean.FALSE); - } - catch (ConnectionException e) { - log.debug("Erroe while refreshing connections: " + e.getMessage()); - } - log.error("An error occurred while holding connections through query!", sdeEx); - } - } - } - } - - /** - * method invokes the schedule method of the timer with a new InstantFeederTask, the actual date and the - * period from the config file as parameters. - * - * @throws OwsExceptionReport if creation of the InstantFeederTask failed - */ - private void startConnectionTask() throws ConnectionException { - timer.schedule(new ConnectionTask(), new Date(), sParams.getTimeToHold()); - } - - /** - * connection task used for holding connections and making sure, that these - * - * @author Christoph Stasch - */ - protected class ConnectionTask extends TimerTask { - - /** - * overwritten run method of TimerTask which queries offeringIDs from db to make sure, that - * connections won't be blocked by the firewalls - */ - public void run() { - holdConnections(); - } - - } - -} \ No newline at end of file diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEStatement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEStatement.java Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,351 @@ +/** + * + */ + package de.intevation.gnv.geobackend.sde.datasources; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Statement; + +import org.apache.log4j.Logger; + +import com.esri.sde.sdk.client.SeColumnDefinition; +import com.esri.sde.sdk.client.SeConnection; +import com.esri.sde.sdk.client.SeException; +import com.esri.sde.sdk.client.SeQuery; +import com.esri.sde.sdk.client.SeRow; + + /** + * @author Tim Englich + * + */ +public class ArcSDEStatement implements Statement { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(ArcSDEStatement.class); + + private ArcSDEConnection connection = null; + + /** + * Constructor + */ + public ArcSDEStatement(ArcSDEConnection connection) { + this.connection = connection; + } + + /** + * @see java.sql.Statement#addBatch(java.lang.String) + */ + public void addBatch(String arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#cancel() + */ + public void cancel() throws SQLException { + } + + /** + * @see java.sql.Statement#clearBatch() + */ + public void clearBatch() throws SQLException { + } + + /** + * @see java.sql.Statement#clearWarnings() + */ + public void clearWarnings() throws SQLException { + } + + /** + * @see java.sql.Statement#close() + */ + public void close() throws SQLException { + } + + /** + * @see java.sql.Statement#execute(java.lang.String) + */ + public boolean execute(String arg0) throws SQLException { + + return false; + } + + /** + * @see java.sql.Statement#execute(java.lang.String, int) + */ + public boolean execute(String arg0, int arg1) throws SQLException { + + return false; + } + + /** + * @see java.sql.Statement#execute(java.lang.String, int[]) + */ + public boolean execute(String arg0, int[] arg1) throws SQLException { + + return false; + } + + /** + * @see java.sql.Statement#execute(java.lang.String, java.lang.String[]) + */ + public boolean execute(String arg0, String[] arg1) throws SQLException { + + return false; + } + + /** + * @see java.sql.Statement#executeBatch() + */ + public int[] executeBatch() throws SQLException { + + return null; + } + + /** + * @see java.sql.Statement#executeQuery(java.lang.String) + */ + public ResultSet executeQuery(String statement) throws SQLException { + try { + SeQuery query = new SeQuery(this.connection.getSeConnection()); + query.prepareSql(statement); + query.execute(); + return this.handleResultSet(query); + } catch (SeException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + + + } + + /** + * @see java.sql.Statement#executeUpdate(java.lang.String) + */ + public int executeUpdate(String arg0) throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#executeUpdate(java.lang.String, int) + */ + public int executeUpdate(String arg0, int arg1) throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#executeUpdate(java.lang.String, int[]) + */ + public int executeUpdate(String arg0, int[] arg1) throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[]) + */ + public int executeUpdate(String arg0, String[] arg1) throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getConnection() + */ + public Connection getConnection() throws SQLException { + return this.connection; + } + + /** + * @see java.sql.Statement#getFetchDirection() + */ + public int getFetchDirection() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getFetchSize() + */ + public int getFetchSize() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getGeneratedKeys() + */ + public ResultSet getGeneratedKeys() throws SQLException { + + return null; + } + + /** + * @see java.sql.Statement#getMaxFieldSize() + */ + public int getMaxFieldSize() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getMaxRows() + */ + public int getMaxRows() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getMoreResults() + */ + public boolean getMoreResults() throws SQLException { + + return false; + } + + /** + * @see java.sql.Statement#getMoreResults(int) + */ + public boolean getMoreResults(int arg0) throws SQLException { + + return false; + } + + /** + * @see java.sql.Statement#getQueryTimeout() + */ + public int getQueryTimeout() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getResultSet() + */ + public ResultSet getResultSet() throws SQLException { + + return null; + } + + /** + * @see java.sql.Statement#getResultSetConcurrency() + */ + public int getResultSetConcurrency() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getResultSetHoldability() + */ + public int getResultSetHoldability() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getResultSetType() + */ + public int getResultSetType() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getUpdateCount() + */ + public int getUpdateCount() throws SQLException { + + return 0; + } + + /** + * @see java.sql.Statement#getWarnings() + */ + public SQLWarning getWarnings() throws SQLException { + + return null; + } + + /** + * @see java.sql.Statement#setCursorName(java.lang.String) + */ + public void setCursorName(String arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setEscapeProcessing(boolean) + */ + public void setEscapeProcessing(boolean arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setFetchDirection(int) + */ + public void setFetchDirection(int arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setFetchSize(int) + */ + public void setFetchSize(int arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setMaxFieldSize(int) + */ + public void setMaxFieldSize(int arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setMaxRows(int) + */ + public void setMaxRows(int arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setQueryTimeout(int) + */ + public void setQueryTimeout(int arg0) throws SQLException { + } + + /** + * Copied from de.intevation.gnv.geobackend.sde.datasources.SDEQuery + * @param pSeQuery + * @return + * @throws SeException + */ + private ResultSet handleResultSet(SeQuery pSeQuery) throws SeException { + log.debug("ArcSDEStatement,handleResultSet()"); + SDEResultSet lSet = new SDEResultSet(); + SeRow row; + int lCount; + for (lCount = 0; (row = pSeQuery.fetch()) != null; lCount++) { + // one time execution + if (lCount == 0) { + // analyze cols of result set + SeColumnDefinition[] lCols = row.getColumns(); + for (SeColumnDefinition lCol : lCols) { + lSet.addCol(new ColDefinition(lCol.getName(), lCol.getType()));// notice: esri-types have been copied into colDefinition class! + } + } + short lNumCols = row.getNumColumns(); + Row lBackingRow = new Row(lNumCols); + for (int i = 0; i < lNumCols; i++) { + lBackingRow.addObject(row.getObject(i), i); + } + lSet.addRow(lBackingRow); + } + pSeQuery.close(); + return lSet; + } + +} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEUtils.java --- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEUtils.java Wed Sep 02 09:07:03 2009 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEUtils.java Wed Sep 02 15:15:52 2009 +0000 @@ -29,7 +29,7 @@ import com.esri.sde.sdk.client.SeSqlConstruct; import com.esri.sde.sdk.client.SeTable; -import de.intevation.gnv.geobackend.sde.datasources.exception.ConnectionException; +import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; /** diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ResultSet.java --- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ResultSet.java Wed Sep 02 09:07:03 2009 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ResultSet.java Wed Sep 02 15:15:52 2009 +0000 @@ -29,7 +29,7 @@ * @see * @since 21.11.2007 09:26:53 */ -public abstract class ResultSet { +public abstract class ResultSet implements java.sql.ResultSet { /** * Default Logging instance diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEConnection.java --- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEConnection.java Wed Sep 02 09:07:03 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/** - * Title: SdeConnection, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/SDEConnection.java,v 1.4 2008/01/30 12:38:34 blume Exp $ - * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/SDEConnection.java,v $ - * created by: Stefan Blume (blume) - * erstellt am: 21.11.2007 - * Copyright: con terra GmbH, 2005 - * - * modified by: $Author: blume $ - * modified on: $Date: 2008/01/30 12:38:34 $ - * Version: $Revision: 1.4 $ - * TAG: $Name: $ - * locked from: $Locker: $ - * CVS State: $State: Exp $ - * Project: $ProjectName$ - */ -package de.intevation.gnv.geobackend.sde.datasources; - -import org.apache.log4j.Logger; - -import com.esri.sde.sdk.client.SeConnection; - -import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; - -/** - * The class SDEConnection fulfills the following purposes: - *

    - *
  1. Providing an implementation of DatasourceConnection-Interface for a SDE database.
  2. - *
- * - * @author blume - * @version 1.0 - * @serial 1.0 - * @see - * @since 21.11.2007 08:51:43 - */ -public class SDEConnection implements DatasourceConnection { - - /** - * Default Logging instance - */ - private static final Logger sLogger = Logger.getLogger(SDEConnection.class); - private static boolean sDebug = sLogger.isDebugEnabled(); - - public SDEConnection() { - } - - /** - * Get a SeConnection. Therefore this method will ask {@link de.conterra.bsh.gdi.gnviewer.datasources.sde.ArcSDEConnectionPool} for a connection. - * - * @return SeConnection - * @throws TechnicalException - */ - public SeConnection getConnection() throws TechnicalException { - if (sDebug) sLogger.debug("getConnection()"); - return ArcSDEConnectionPool.getInstance().getConnection(); - } - - /** - * Return a connection (to a connection pool). - * This method is executed after an executed query. - * - * @param pConnection the connection used for a query. - */ - public void returnConnection(SeConnection pConnection) { - if (sDebug) sLogger.debug("returnConnection()"); - try { - ArcSDEConnectionPool.getInstance().returnConnection(pConnection); - } catch (TechnicalException e) { - sLogger.error(e.getMessage(), e); - } - } -} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEDatasource.java --- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEDatasource.java Wed Sep 02 09:07:03 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -/* Copyright (C) 2007 con terra GmbH (http://www.conterra.de) - * All rights reserved - * - * $Id: SDEDatasource.java,v 1.6 2008/01/30 12:38:34 blume Exp $ - * - * created by: drewnak - * created at : 21.11.2007 - * created at : 14:35:53 - * - * modified by: $Author: blume $ - * modified at: $Date: 2008/01/30 12:38:34 $ - */ -package de.intevation.gnv.geobackend.sde.datasources; - -import java.util.Map; - -import org.apache.log4j.Logger; - -import com.esri.sde.sdk.client.SeConnection; - -import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; - -/** - * Concrete Implementation of the datasource interface. - * - * @author drewnak - */ -public class SDEDatasource extends Datasource { - - /** - * Default Logging instance - */ - private static final Logger sLogger = Logger.getLogger(SDEDatasource.class); - private static boolean sDebug = sLogger.isDebugEnabled(); - - public static final String KEY_URL = "sde.url"; - public static final String KEY_PORT = "sde.port"; - public static final String KEY_USER = "sde.user"; - public static final String KEY_PWD = "sde.password"; - public static final String KEY_DATABASE = "sde.database"; - - - /* (non-Javadoc) - * @see de.conterra.bsh.gdi.gnviewer.datasources.Datasource#init(java.lang.String, java.util.Map) - */ - protected void init(String pName, Map pParams) { - mName = pName; - mParameters = pParams; - if (!ArcSDEConnectionPool.isConfigured()) { - /* - - localhost - bsh - bsh - 5151 - - */ - - String lServer; - int lPort = 0; - String lDatabase; - String lUser; - String lPwd; - - lServer = setStringParameter(pParams, KEY_URL); - lUser = setStringParameter(pParams, KEY_USER); - lPwd = setStringParameter(pParams, KEY_PWD); - lDatabase = setStringParameter(pParams, KEY_DATABASE); - lPort = setIntParameter(pParams, KEY_PORT); - // todo: read techparams from config(# of initial connections, TTL) - - ArcSDEConnectionParams lParams = new ArcSDEConnectionParams(lServer, lPort, lDatabase, lUser, lPwd, 0, 10, 60000); - try { - ArcSDEConnectionPool.configure(lParams); - } catch (TechnicalException e) { - sLogger.error(e.getMessage(), e); - - } - } - } - - private String setStringParameter(Map pParams, String pMapKey) { - if (pParams.containsKey(pMapKey)) { - return (String) pParams.get(pMapKey); - } else { - if (sDebug) sLogger.debug("no param config for key " + pMapKey); - return ""; - } - } - - private int setIntParameter(Map pParams, String pMapKey) { - if (pParams.containsKey(pMapKey)) { - return Integer.parseInt((String) pParams.get(pMapKey)); - } else { - if (sDebug) sLogger.debug("no param config for key " + pMapKey); - return -1; - } - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - return super.toString() + " " + mName; - } - - - /** - * (non-Javadoc) - * - * @see de.conterra.bsh.gdi.gnviewer.datasources.Datasource#getConnection() - */ - public DatasourceConnection getConnection() { - return new SDEConnection(); - } - - /** - * (non-Javadoc) - * - * @see de.conterra.bsh.gdi.gnviewer.datasources.Datasource#returnConnection(de.conterra.bsh.gdi.gnviewer.datasources.DatasourceConnection) - */ - public void returnConnection(DatasourceConnection pConnection) { - if (null != pConnection) { - try { - ArcSDEConnectionPool.getInstance().returnConnection((SeConnection) pConnection); - } catch (TechnicalException e) { - sLogger.error(e.getMessage(), e); - } - } - } -} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEQuery.java --- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEQuery.java Wed Sep 02 09:07:03 2009 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEQuery.java Wed Sep 02 15:15:52 2009 +0000 @@ -15,6 +15,9 @@ */ package de.intevation.gnv.geobackend.sde.datasources; +import java.sql.Connection; +import java.sql.Statement; + import org.apache.log4j.Logger; import com.esri.sde.sdk.client.SDEPoint; @@ -30,6 +33,8 @@ import com.esri.sde.sdk.client.SeShapeFilter; import com.esri.sde.sdk.client.SeSqlConstruct; +import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool; +import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; import de.intevation.gnv.geobackend.util.DateUtils; @@ -51,11 +56,12 @@ private static boolean sDebug = sLogger.isDebugEnabled(); - DatasourceConnection mConnection; + private ConnectionPool connectionPool = null; + private String connectionID = "N/N"; - public SDEQuery(DatasourceConnection pConnection) { + public SDEQuery(ConnectionPool connectionPool) { if (sDebug) sLogger.debug("SDEQuery()"); - mConnection = pConnection; + this.connectionPool = connectionPool; } /** @@ -71,22 +77,22 @@ */ public ResultSet executeQuery(String pTables[], String pCols[], String pWhere) throws TechnicalException { sLogger.debug("executeQuery()"); - SeConnection con = null; + Connection con = null; try { con = getConnection(); - SeSqlConstruct lSeSqlConstruct = new SeSqlConstruct(pTables, pWhere); - SeQuery lSeQuery = new SeQuery(con, pCols, lSeSqlConstruct); - long lStart = System.currentTimeMillis(); - lSeQuery.prepareQuery(); - ResultSet lSet = handleResultSet(lSeQuery); - long lEnd = System.currentTimeMillis(); - if (sDebug) - sLogger.debug((new StringBuilder()).append("lSeQuery lasts ").append((double) (lEnd - lStart) / 1000D).append(" seconds").toString()); +// SeSqlConstruct lSeSqlConstruct = new SeSqlConstruct(pTables, pWhere); +// SeQuery lSeQuery = new SeQuery(con, pCols, lSeSqlConstruct); +// long lStart = System.currentTimeMillis(); +// lSeQuery.prepareQuery(); + ResultSet lSet = null;//handleResultSet(lSeQuery); +// long lEnd = System.currentTimeMillis(); +// if (sDebug) +// sLogger.debug((new StringBuilder()).append("lSeQuery lasts ").append((double) (lEnd - lStart) / 1000D).append(" seconds").toString()); return lSet; } catch (TechnicalException e) { sLogger.error(e.getMessage(), e); throw e; - } catch (SeException e) { + } catch (Exception e) { sLogger.error(e.getMessage(), e); throw new TechnicalException("Error during executeQuery", e); } finally { @@ -105,30 +111,24 @@ */ public ResultSet executeQuery(String pSQLStatement) throws TechnicalException { if (sDebug) sLogger.debug("executeQuery():\n" + pSQLStatement); - SeConnection con = null; + Connection con = null; try { con = getConnection(); - SeQuery lSeQuery = new SeQuery(con); - long lStart = System.currentTimeMillis(); - lSeQuery.prepareSql(pSQLStatement); - lSeQuery.execute(); - ResultSet lSet = handleResultSet(lSeQuery); + long lStart = System.currentTimeMillis(); - //TmpFile erstellen - //Row auslesen - //Row -> TmpFile - //TmpFile close - + Statement stmt = con.createStatement(); + java.sql.ResultSet rs = stmt.executeQuery(pSQLStatement); + long lEnd = System.currentTimeMillis(); if (sDebug) sLogger.debug((new StringBuilder()).append("lSeQuery lasts ").append((double) (lEnd - lStart) / 1000D).append(" seconds").toString()); - return lSet; + return (ResultSet)rs; } catch (TechnicalException e) { sLogger.error(e.getMessage(), e); throw e; - } catch (SeException e) { + } catch (Exception e) { sLogger.error(e.getMessage(), e); throw new TechnicalException("Error during executeQuery", e); } finally { @@ -194,42 +194,42 @@ */ public ResultSet executeQuery(String pLayername, String pSpatialColumnName, double[][] pPoints, String[] pReturnFields) throws TechnicalException { sLogger.debug("executeQuery()"); - SeConnection con = null; + Connection con = null; try { con = getConnection(); - // get the layer for querying - SeLayer lLayer = new SeLayer(con, pLayername, pSpatialColumnName); - SeCoordinateReference cref = lLayer.getCoordRef(); - - - SeShape shape = new SeShape(); - shape.setCoordRef(lLayer.getCoordRef()); - SDEPoint[] lPoints = ArcSDEUtils.createPoints(pPoints); +// // get the layer for querying +// SeLayer lLayer = new SeLayer(con, pLayername, pSpatialColumnName); +// SeCoordinateReference cref = lLayer.getCoordRef(); +// +// +// SeShape shape = new SeShape(); +// shape.setCoordRef(lLayer.getCoordRef()); +// SDEPoint[] lPoints = ArcSDEUtils.createPoints(pPoints); +// +// /* +// * int numPts, int numParts, int[] partOffsets,SDEPoint[] ptArray +// * */ +// shape.generatePolygon(lPoints.length, 1, null, lPoints); +// SeShapeFilter filter = new SeShapeFilter(pLayername, pSpatialColumnName, shape, SeFilter.METHOD_AI); +// SeShapeFilter[] filters = new SeShapeFilter[1]; +// filters[0] = filter; +// +// SeQuery spatialQuery = null; +// SeSqlConstruct sqlCons = new SeSqlConstruct(pLayername); +// spatialQuery = new SeQuery(con, pReturnFields, sqlCons); +// spatialQuery.prepareQuery(); +// /* +// * Set spatial constraints +// */ +// spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, filters); +// spatialQuery.execute(); - /* - * int numPts, int numParts, int[] partOffsets,SDEPoint[] ptArray - * */ - shape.generatePolygon(lPoints.length, 1, null, lPoints); - SeShapeFilter filter = new SeShapeFilter(pLayername, pSpatialColumnName, shape, SeFilter.METHOD_AI); - SeShapeFilter[] filters = new SeShapeFilter[1]; - filters[0] = filter; - - SeQuery spatialQuery = null; - SeSqlConstruct sqlCons = new SeSqlConstruct(pLayername); - spatialQuery = new SeQuery(con, pReturnFields, sqlCons); - spatialQuery.prepareQuery(); - /* - * Set spatial constraints - */ - spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, filters); - spatialQuery.execute(); - - return handleResultSet(spatialQuery); + return null;//handleResultSet(spatialQuery); } catch (TechnicalException e) { sLogger.error(e.getMessage(), e); throw e; - } catch (SeException e) { + } catch (Exception e) { sLogger.error(e.getMessage(), e); throw new TechnicalException("Error accessing Spatial Database: " + e.getMessage(), e); } finally { @@ -251,60 +251,59 @@ */ public ResultSet executeQuery(String pLayername, String pSpatialColumnName, String pWhere, double[][] pPoints, String[] pReturnFields) throws TechnicalException { sLogger.debug("executeQuery()"); - SeConnection con = null; + Connection con = null; try { con = getConnection(); - // get the layer for querying - SeLayer lLayer = new SeLayer(con, pLayername, pSpatialColumnName); - SeCoordinateReference cref = lLayer.getCoordRef(); - - - SeShape shape = new SeShape(); - shape.setCoordRef(lLayer.getCoordRef()); - SDEPoint[] lPoints = ArcSDEUtils.createPoints(pPoints); +// // get the layer for querying +// SeLayer lLayer = new SeLayer(con, pLayername, pSpatialColumnName); +// SeCoordinateReference cref = lLayer.getCoordRef(); +// +// +// SeShape shape = new SeShape(); +// shape.setCoordRef(lLayer.getCoordRef()); +// SDEPoint[] lPoints = ArcSDEUtils.createPoints(pPoints); +// +// /* +// * int numPts, int numParts, int[] partOffsets,SDEPoint[] ptArray +// * */ +// shape.generatePolygon(lPoints.length, 1, null, lPoints); +// SeShapeFilter filter = new SeShapeFilter(pLayername, pSpatialColumnName, shape, SeFilter.METHOD_AI); +// SeShapeFilter[] filters = new SeShapeFilter[1]; +// filters[0] = filter; +// +// SeQuery spatialQuery = null; +// SeSqlConstruct sqlCons = new SeSqlConstruct(pLayername,pWhere); +// spatialQuery = new SeQuery(con, pReturnFields, sqlCons); +// spatialQuery.prepareQuery(); +// /* +// * Set spatial constraints +// */ +// spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, filters); +// spatialQuery.execute(); - /* - * int numPts, int numParts, int[] partOffsets,SDEPoint[] ptArray - * */ - shape.generatePolygon(lPoints.length, 1, null, lPoints); - SeShapeFilter filter = new SeShapeFilter(pLayername, pSpatialColumnName, shape, SeFilter.METHOD_AI); - SeShapeFilter[] filters = new SeShapeFilter[1]; - filters[0] = filter; - - SeQuery spatialQuery = null; - SeSqlConstruct sqlCons = new SeSqlConstruct(pLayername,pWhere); - spatialQuery = new SeQuery(con, pReturnFields, sqlCons); - spatialQuery.prepareQuery(); - /* - * Set spatial constraints - */ - spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, filters); - spatialQuery.execute(); - - return handleResultSet(spatialQuery); + return null;//handleResultSet(spatialQuery); } catch (TechnicalException e) { sLogger.error(e.getMessage(), e); throw e; - } catch (SeException e) { + } catch (Exception e) { sLogger.error(e.getMessage(), e); throw new TechnicalException("Error accessing Spatial Database: " + e.getMessage(), e); } finally { returnConnection(con); } } - private SeConnection getConnection() throws TechnicalException { - SeConnection lConnection = ((SDEConnection) mConnection).getConnection(); - if (sDebug) try { - sLogger.debug("get connection to server: " + lConnection.getServer() + ", ServerTime: " + DateUtils.getPatternedDateAmer(lConnection.getServerTime()) + ", Release: " + lConnection.getRelease().getDesc()); - } catch (SeException e) { - sLogger.error(e.getMessage(), e); - } - return lConnection; + private Connection getConnection() throws TechnicalException { + Connection connection = connectionPool.getConnection(connectionID); + return connection; } - private void returnConnection(SeConnection pSeConnection) { - ((SDEConnection) mConnection).returnConnection(pSeConnection); + private void returnConnection(Connection connection) { + try { + this.connectionPool.closeConnection(connection); + } catch (ConnectionException e) { + sLogger.error(e,e); + } } diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEResultSet.java --- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEResultSet.java Wed Sep 02 09:07:03 2009 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEResultSet.java Wed Sep 02 15:15:52 2009 +0000 @@ -15,12 +15,31 @@ */ package de.intevation.gnv.geobackend.sde.datasources; +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.Ref; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; +import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; + /** * @author blume * @version 1.0 @@ -30,42 +49,1109 @@ */ public class SDEResultSet extends ResultSet { - /** - * Default Logging instance - */ - private static Logger sLogger = Logger.getLogger(SDEResultSet.class); - - - private List mRows = Collections.synchronizedList(new ArrayList()); - private List mCols = Collections.synchronizedList(new ArrayList()); - - public SDEResultSet() { - } - - public int getCount() { - return mRows.size(); - } + /** + * Default Logging instance + */ + private static Logger log = Logger.getLogger(SDEResultSet.class); - public int getNumberOfColumns() { - return mCols.size(); - } - - public ColDefinition[] getColumnDefinitions() { - ColDefinition[] lColDefinitions = new ColDefinition[mCols.size()]; - return mCols.toArray(lColDefinitions); - } + private List mRows = Collections.synchronizedList(new ArrayList()); + private List mCols = Collections.synchronizedList(new ArrayList()); - public Row[] getResults() { - Row[] lRows = new Row[mRows.size()]; - return mRows.toArray(lRows); - } + private Row currentRow = null; + private int cursor = 0; + + public SDEResultSet() { + } - public void addRow(Row pRow) { - mRows.add(pRow); - } + public int getCount() { + return mRows.size(); + } - public void addCol(ColDefinition pColDefinition) { - mCols.add(pColDefinition); - } + public int getNumberOfColumns() { + return mCols.size(); + } + + public ColDefinition[] getColumnDefinitions() { + ColDefinition[] lColDefinitions = new ColDefinition[mCols.size()]; + return mCols.toArray(lColDefinitions); + } + + public Row[] getResults() { + Row[] lRows = new Row[mRows.size()]; + return mRows.toArray(lRows); + } + + public void addRow(Row pRow) { + mRows.add(pRow); + } + + public void addCol(ColDefinition pColDefinition) { + mCols.add(pColDefinition); + } + + /** + * @see java.sql.ResultSet#absolute(int) + */ + public boolean absolute(int row) throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#afterLast() + */ + public void afterLast() throws SQLException { + } + + /** + * @see java.sql.ResultSet#beforeFirst() + */ + public void beforeFirst() throws SQLException { + } + + /** + * @see java.sql.ResultSet#cancelRowUpdates() + */ + public void cancelRowUpdates() throws SQLException { + } + + /** + * @see java.sql.ResultSet#clearWarnings() + */ + public void clearWarnings() throws SQLException { + } + + /** + * @see java.sql.ResultSet#close() + */ + public void close() throws SQLException { + } + + /** + * @see java.sql.ResultSet#deleteRow() + */ + public void deleteRow() throws SQLException { + } + + /** + * @see java.sql.ResultSet#findColumn(java.lang.String) + */ + public int findColumn(String columnName) throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#first() + */ + public boolean first() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#getArray(int) + */ + public Array getArray(int i) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getArray(java.lang.String) + */ + public Array getArray(String colName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getAsciiStream(int) + */ + public InputStream getAsciiStream(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getAsciiStream(java.lang.String) + */ + public InputStream getAsciiStream(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBigDecimal(int) + */ + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBigDecimal(java.lang.String) + */ + public BigDecimal getBigDecimal(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBigDecimal(int, int) + */ + public BigDecimal getBigDecimal(int columnIndex, int scale) + throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBigDecimal(java.lang.String, int) + */ + public BigDecimal getBigDecimal(String columnName, int scale) + throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBinaryStream(int) + */ + public InputStream getBinaryStream(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBinaryStream(java.lang.String) + */ + public InputStream getBinaryStream(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBlob(int) + */ + public Blob getBlob(int i) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBlob(java.lang.String) + */ + public Blob getBlob(String colName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBoolean(int) + */ + public boolean getBoolean(int columnIndex) throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#getBoolean(java.lang.String) + */ + public boolean getBoolean(String columnName) throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#getByte(int) + */ + public byte getByte(int columnIndex) throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getByte(java.lang.String) + */ + public byte getByte(String columnName) throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getBytes(int) + */ + public byte[] getBytes(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getBytes(java.lang.String) + */ + public byte[] getBytes(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getCharacterStream(int) + */ + public Reader getCharacterStream(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getCharacterStream(java.lang.String) + */ + public Reader getCharacterStream(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getClob(int) + */ + public Clob getClob(int i) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getClob(java.lang.String) + */ + public Clob getClob(String colName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getConcurrency() + */ + public int getConcurrency() throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getCursorName() + */ + public String getCursorName() throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getDate(int) + */ + public Date getDate(int columnIndex) throws SQLException { + try { + return new java.sql.Date(this.currentRow.getDateValue(columnIndex-1).getTime()); + } catch (TechnicalException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.ResultSet#getDate(java.lang.String) + */ + public Date getDate(String columnName) throws SQLException { + int columnIndex = this.getColumnIndex(columnName); + return this.getDate(columnIndex); + } + + /** + * @see java.sql.ResultSet#getDate(int, java.util.Calendar) + */ + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getDate(java.lang.String, java.util.Calendar) + */ + public Date getDate(String columnName, Calendar cal) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getDouble(int) + */ + public double getDouble(int columnIndex) throws SQLException { + try { + return this.currentRow.getDoubleValue(columnIndex-1); + } catch (TechnicalException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.ResultSet#getDouble(java.lang.String) + */ + public double getDouble(String columnName) throws SQLException { + int columnIndex = this.getColumnIndex(columnName); + return this.getDouble(columnIndex); + } + + /** + * @see java.sql.ResultSet#getFetchDirection() + */ + public int getFetchDirection() throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getFetchSize() + */ + public int getFetchSize() throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getFloat(int) + */ + public float getFloat(int columnIndex) throws SQLException { + try { + return this.currentRow.getFloatValue(columnIndex-1); + } catch (TechnicalException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.ResultSet#getFloat(java.lang.String) + */ + public float getFloat(String columnName) throws SQLException { + int columnIndex = this.getColumnIndex(columnName); + return this.getFloat(columnIndex); + } + + /** + * @see java.sql.ResultSet#getInt(int) + */ + public int getInt(int columnIndex) throws SQLException { + + try { + return this.currentRow.getIntValue(columnIndex-1); + } catch (TechnicalException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.ResultSet#getInt(java.lang.String) + */ + public int getInt(String columnName) throws SQLException { + int columnIndex = this.getColumnIndex(columnName); + return this.getInt(columnIndex); + } + + /** + * @see java.sql.ResultSet#getLong(int) + */ + public long getLong(int columnIndex) throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getLong(java.lang.String) + */ + public long getLong(String columnName) throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getMetaData() + */ + public ResultSetMetaData getMetaData() throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getObject(int) + */ + public Object getObject(int columnIndex) throws SQLException { + try { + return this.currentRow.getValue(columnIndex-1); + } catch (TechnicalException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.ResultSet#getObject(java.lang.String) + */ + public Object getObject(String columnName) throws SQLException { + int columnIndex = this.getColumnIndex(columnName); + return this.getObject(columnIndex); + } + + /** + * @see java.sql.ResultSet#getObject(int, java.util.Map) + */ + public Object getObject(int i, Map> map) + throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getObject(java.lang.String, java.util.Map) + */ + public Object getObject(String colName, Map> map) + throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getRef(int) + */ + public Ref getRef(int i) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getRef(java.lang.String) + */ + public Ref getRef(String colName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getRow() + */ + public int getRow() throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getShort(int) + */ + public short getShort(int columnIndex) throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getShort(java.lang.String) + */ + public short getShort(String columnName) throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getStatement() + */ + public Statement getStatement() throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getString(int) + */ + public String getString(int columnIndex) throws SQLException { + + try { + return this.currentRow.getStringValue(columnIndex-1); + } catch (TechnicalException e) { + log.error(e,e); + throw new SQLException(e.getMessage()); + } + } + + /** + * @see java.sql.ResultSet#getString(java.lang.String) + */ + public String getString(String columnName) throws SQLException { + int columnIndex = this.getColumnIndex(columnName); + return this.getString(columnIndex); + } + + /** + * @see java.sql.ResultSet#getTime(int) + */ + public Time getTime(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getTime(java.lang.String) + */ + public Time getTime(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getTime(int, java.util.Calendar) + */ + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getTime(java.lang.String, java.util.Calendar) + */ + public Time getTime(String columnName, Calendar cal) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getTimestamp(int) + */ + public Timestamp getTimestamp(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getTimestamp(java.lang.String) + */ + public Timestamp getTimestamp(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getTimestamp(int, java.util.Calendar) + */ + public Timestamp getTimestamp(int columnIndex, Calendar cal) + throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getTimestamp(java.lang.String, + * java.util.Calendar) + */ + public Timestamp getTimestamp(String columnName, Calendar cal) + throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getType() + */ + public int getType() throws SQLException { + + return 0; + } + + /** + * @see java.sql.ResultSet#getURL(int) + */ + public URL getURL(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getURL(java.lang.String) + */ + public URL getURL(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getUnicodeStream(int) + */ + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getUnicodeStream(java.lang.String) + */ + public InputStream getUnicodeStream(String columnName) throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#getWarnings() + */ + public SQLWarning getWarnings() throws SQLException { + + return null; + } + + /** + * @see java.sql.ResultSet#insertRow() + */ + public void insertRow() throws SQLException { + } + + /** + * @see java.sql.ResultSet#isAfterLast() + */ + public boolean isAfterLast() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#isBeforeFirst() + */ + public boolean isBeforeFirst() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#isFirst() + */ + public boolean isFirst() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#isLast() + */ + public boolean isLast() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#last() + */ + public boolean last() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#moveToCurrentRow() + */ + public void moveToCurrentRow() throws SQLException { + } + + /** + * @see java.sql.ResultSet#moveToInsertRow() + */ + public void moveToInsertRow() throws SQLException { + } + + /** + * @see java.sql.ResultSet#next() + */ + public boolean next() throws SQLException { + + boolean next = this.mRows.size() > this.cursor; + if (next){ + log.debug("Zeile "+(cursor+1)+" von "+this.mRows.size()+" wird angesteuert."); + this.currentRow = this.mRows.get(this.cursor); + this.cursor++; + }else{ + this.currentRow = null; + } + return next; + } + + /** + * @see java.sql.ResultSet#previous() + */ + public boolean previous() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#refreshRow() + */ + public void refreshRow() throws SQLException { + } + + /** + * @see java.sql.ResultSet#relative(int) + */ + public boolean relative(int rows) throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#rowDeleted() + */ + public boolean rowDeleted() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#rowInserted() + */ + public boolean rowInserted() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#rowUpdated() + */ + public boolean rowUpdated() throws SQLException { + + return false; + } + + /** + * @see java.sql.ResultSet#setFetchDirection(int) + */ + public void setFetchDirection(int direction) throws SQLException { + } + + /** + * @see java.sql.ResultSet#setFetchSize(int) + */ + public void setFetchSize(int rows) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateArray(int, java.sql.Array) + */ + public void updateArray(int columnIndex, Array x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateArray(java.lang.String, java.sql.Array) + */ + public void updateArray(String columnName, Array x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateAsciiStream(int, java.io.InputStream, int) + */ + public void updateAsciiStream(int columnIndex, InputStream x, int length) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateAsciiStream(java.lang.String, + * java.io.InputStream, int) + */ + public void updateAsciiStream(String columnName, InputStream x, int length) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBigDecimal(int, java.math.BigDecimal) + */ + public void updateBigDecimal(int columnIndex, BigDecimal x) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBigDecimal(java.lang.String, + * java.math.BigDecimal) + */ + public void updateBigDecimal(String columnName, BigDecimal x) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBinaryStream(int, java.io.InputStream, int) + */ + public void updateBinaryStream(int columnIndex, InputStream x, int length) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBinaryStream(java.lang.String, + * java.io.InputStream, int) + */ + public void updateBinaryStream(String columnName, InputStream x, int length) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBlob(int, java.sql.Blob) + */ + public void updateBlob(int columnIndex, Blob x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBlob(java.lang.String, java.sql.Blob) + */ + public void updateBlob(String columnName, Blob x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBoolean(int, boolean) + */ + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBoolean(java.lang.String, boolean) + */ + public void updateBoolean(String columnName, boolean x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateByte(int, byte) + */ + public void updateByte(int columnIndex, byte x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateByte(java.lang.String, byte) + */ + public void updateByte(String columnName, byte x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBytes(int, byte[]) + */ + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateBytes(java.lang.String, byte[]) + */ + public void updateBytes(String columnName, byte[] x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateCharacterStream(int, java.io.Reader, int) + */ + public void updateCharacterStream(int columnIndex, Reader x, int length) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateCharacterStream(java.lang.String, + * java.io.Reader, int) + */ + public void updateCharacterStream(String columnName, Reader reader, + int length) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateClob(int, java.sql.Clob) + */ + public void updateClob(int columnIndex, Clob x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateClob(java.lang.String, java.sql.Clob) + */ + public void updateClob(String columnName, Clob x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateDate(int, java.sql.Date) + */ + public void updateDate(int columnIndex, Date x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateDate(java.lang.String, java.sql.Date) + */ + public void updateDate(String columnName, Date x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateDouble(int, double) + */ + public void updateDouble(int columnIndex, double x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateDouble(java.lang.String, double) + */ + public void updateDouble(String columnName, double x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateFloat(int, float) + */ + public void updateFloat(int columnIndex, float x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateFloat(java.lang.String, float) + */ + public void updateFloat(String columnName, float x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateInt(int, int) + */ + public void updateInt(int columnIndex, int x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateInt(java.lang.String, int) + */ + public void updateInt(String columnName, int x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateLong(int, long) + */ + public void updateLong(int columnIndex, long x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateLong(java.lang.String, long) + */ + public void updateLong(String columnName, long x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateNull(int) + */ + public void updateNull(int columnIndex) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateNull(java.lang.String) + */ + public void updateNull(String columnName) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateObject(int, java.lang.Object) + */ + public void updateObject(int columnIndex, Object x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateObject(java.lang.String, java.lang.Object) + */ + public void updateObject(String columnName, Object x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateObject(int, java.lang.Object, int) + */ + public void updateObject(int columnIndex, Object x, int scale) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateObject(java.lang.String, java.lang.Object, + * int) + */ + public void updateObject(String columnName, Object x, int scale) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateRef(int, java.sql.Ref) + */ + public void updateRef(int columnIndex, Ref x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateRef(java.lang.String, java.sql.Ref) + */ + public void updateRef(String columnName, Ref x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateRow() + */ + public void updateRow() throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateShort(int, short) + */ + public void updateShort(int columnIndex, short x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateShort(java.lang.String, short) + */ + public void updateShort(String columnName, short x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateString(int, java.lang.String) + */ + public void updateString(int columnIndex, String x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateString(java.lang.String, java.lang.String) + */ + public void updateString(String columnName, String x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateTime(int, java.sql.Time) + */ + public void updateTime(int columnIndex, Time x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateTime(java.lang.String, java.sql.Time) + */ + public void updateTime(String columnName, Time x) throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateTimestamp(int, java.sql.Timestamp) + */ + public void updateTimestamp(int columnIndex, Timestamp x) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#updateTimestamp(java.lang.String, + * java.sql.Timestamp) + */ + public void updateTimestamp(String columnName, Timestamp x) + throws SQLException { + } + + /** + * @see java.sql.ResultSet#wasNull() + */ + public boolean wasNull() throws SQLException { + + return false; + } + + + private int getColumnIndex(String columnName) throws SQLException{ + //TODO: Es gibt effizentere Lösungen. Hier noch mal über HashMap nachdenken + for (int i = 0 ; i < this.mCols.size();i++){ + if(this.mCols.get(i).getName().equalsIgnoreCase(columnName)){ + return i +1; // PLUS 1 da SQL-Cursor 1 nasiert sind + } + } + throw new SQLException("Column "+columnName+" does not exist in ResulSet"); + + } } diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/exception/ConnectionException.java --- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/exception/ConnectionException.java Wed Sep 02 09:07:03 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -/** - * Title: lConnectionException, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/exception/ConnectionException.java,v 1.2 2008/08/18 14:50:33 drewnak Exp $ - * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/exception/ConnectionException.java,v $ - * created by: Stefan Blume (blume) - * erstellt am: 21.11.2007 - * Copyright: con terra GmbH, 2005 - * - * modified by: $Author: drewnak $ - * modified on: $Date: 2008/08/18 14:50:33 $ - * Version: $Revision: 1.2 $ - * TAG: $Name: $ - * locked from: $Locker: $ - * CVS State: $State: Exp $ - * Project: $ProjectName$ - */ -package de.intevation.gnv.geobackend.sde.datasources.exception; - -import com.esri.sde.sdk.client.SeError; -import com.esri.sde.sdk.client.SeException; -import org.apache.log4j.Logger; - -/** - * The class lConnectionException fulfills the following purposes: - *
    - *
  1. - *
- * - * @author blume - * @version 1.0 - * @serial 1.0 - * @see - * @since 21.11.2007 08:13:05 - */ -public class ConnectionException extends TechnicalException { - - /** - * Default Logging instance - */ - private static Logger sLogger = Logger.getLogger(ConnectionException.class); - - /** - * Constructs a new exception with null as its detail message. - * The cause is not initialized, and may subsequently be initialized by a - * call to {@link #initCause}. - */ - public ConnectionException() { - } - - /** - * Constructs a new exception with the specified detail message. The - * cause is not initialized, and may subsequently be initialized by - * a call to {@link #initCause}. - * - * @param message the detail message. The detail message is saved for - * later retrieval by the {@link #getMessage()} method. - */ - public ConnectionException(String message) { - super(message); - } - public ConnectionException(Throwable pCause) { - super(pCause); - } - - /** - * Constructs a new exception with the specified detail message and - * cause.

Note that the detail message associated with - * cause is not automatically incorporated in - * this exception's detail message. - * - * @param message the detail message (which is saved for later retrieval - * by the {@link #getMessage()} method). - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A null value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - * @since 1.4 - */ - public ConnectionException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Displays the details of an SeException (if available). - * - */ - public void printError() { - if (getCause() != null && getCause() instanceof SeException) { - SeException exception = (SeException) getCause(); - SeError error = exception.getSeError(); - - sLogger.debug("\n ArcSDE Error Number : " + error.getSdeError()); - sLogger.debug(" Error Description : " + error.getErrDesc()); - - int extError = error.getExtError(); - if (extError != 0) - sLogger.debug(" Extended Error Number : " + extError); - - String desc = error.getSdeErrMsg(); - if (desc != null && desc.length() != 0) - sLogger.debug(" Extended Error Description : " + desc); - - desc = error.getExtErrMsg(); - if (desc != null && desc.length() != 0) - sLogger.debug(" Extended Error Description : " + desc); - - sLogger.debug(exception); - - } - - } -} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/test/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPoolTestCase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/test/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPoolTestCase.java Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,123 @@ +package de.intevation.gnv.geobackend.sde.datasources; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; +import java.sql.ResultSet; + +import junit.framework.TestCase; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Logger; + +import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool; +import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory; +import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; +import de.intevation.gnv.geobackend.sde.connectionpool.ArcSDEPoolableObjectFactory; + +/** + * TestCase for the usage of the ArcSDEConnectionPool. + * @author Tim Englich + * + */ +public class ArcSDEConnectionPoolTestCase extends TestCase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = null; + + static { + BasicConfigurator.configure(); + log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); + } + + + + /** + * + */ + public ArcSDEConnectionPoolTestCase() { + super(); + } + + /** + * + * @param name + */ + public ArcSDEConnectionPoolTestCase(String name) { + super(name); + } + + public void testArcSDEConnectionPool(){ + log.debug("ArcSDEConnectionPoolTestCase.testArcSDEConnectionPool"); + try { + InputStream inputStream = new FileInputStream("src/test/ressources/ArcSDEConnectionPoolTestCase.properties"); + Properties properties = new Properties(); + properties.load(inputStream); + + ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance(); + cpf.initializeConnectionPool(properties); + + assertTrue(cpf.isInitialized()); + log.debug("ConnectionPoolFactory ist initialisiert."); + + ConnectionPool cp = cpf.getConnectionPool(); + assertNotNull(cp); + log.debug("ConnectionPool ist initialisiert."); + + Connection connection = null; + try{ + try { + connection = cp.getConnection("N/N"); + assertNotNull(connection); + log.debug("Connection ist initialisiert."); + } catch (ConnectionException e) { + log.error("Es traten Probleme bei der Verbinung zur Datenbank auf."); + fail(); + } + + + try { + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery("Select MESHID, NAME from MEDIAN.MESH"); + + while (rs.next()){ + log.debug(rs.getInt(1)); + log.debug(rs.getString(2)); + + log.debug(rs.getInt("MESHID")); + log.debug(rs.getString("NAME")); + } + + } catch (SQLException e) { + log.error(e,e); + } + }finally{ + if (connection != null){ + try { + connection.close(); + } catch (SQLException e) { + log.error(e,e); + fail(); + } + } + } + + + + } catch (FileNotFoundException e) { + log.error(e,e); + fail(); + } catch (IOException e) { + log.error(e,e); + fail(); + } + } + +} diff -r 110e3ac1b7d2 -r e4eacd613356 geo-backend/src/test/ressources/ArcSDEConnectionPoolTestCase.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/test/ressources/ArcSDEConnectionPoolTestCase.properties Wed Sep 02 15:15:52 2009 +0000 @@ -0,0 +1,6 @@ +maxActive=2 +server=localhost +username=gast +credentials=gast +port=22119 +database=esri_sde \ No newline at end of file