diff geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEQuery.java @ 130:e4eacd613356

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
author Tim Englich <tim.englich@intevation.de>
date Wed, 02 Sep 2009 15:15:52 +0000
parents 110e3ac1b7d2
children 122fdc9da5f0
line wrap: on
line diff
--- 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);
+        }
     }
 
 

http://dive4elements.wald.intevation.org