Mercurial > dive4elements > gnv-client
changeset 129:110e3ac1b7d2
Library Dependencies Added to pom.xml-File
Import of SDE-Datasources
geo-backend/trunk@5 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/geo-backend/Changelog Wed Sep 02 08:27:12 2009 +0000 +++ b/geo-backend/Changelog Wed Sep 02 09:07:03 2009 +0000 @@ -2,3 +2,5 @@ * README, Changelog, Changes, NEWS, TODO: New. Initial setup * Java-Project generated + * Library Dependencies Added to pom.xml + * Import of SDE-Datasources
--- a/geo-backend/pom.xml Wed Sep 02 08:27:12 2009 +0000 +++ b/geo-backend/pom.xml Wed Sep 02 09:07:03 2009 +0000 @@ -1,7 +1,7 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>gnv</groupId> + <groupId>de.intevation.gnv</groupId> <artifactId>geo-backend</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> @@ -14,5 +14,28 @@ <version>3.8.1</version> <scope>test</scope> </dependency> + <dependency> + <groupId>com.esri.sde</groupId> + <artifactId>jsde_sdk</artifactId> + <version>9.2.5</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>com.esri.sde</groupId> + <artifactId>jpe_sdk</artifactId> + <version>9.2.5</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>com.ibm</groupId> + <artifactId>icu4j</artifactId> + <version>3.2</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>[1.2,)</version> + </dependency> </dependencies> </project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionParams.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,92 @@ +/** + * Title: ArcSDEConnectionParams, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/ArcSDEConnectionParams.java,v 1.1 2007/11/22 07:40:11 blume Exp $ + * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/ArcSDEConnectionParams.java,v $ + * created by: Stefan Blume (blume) + * erstellt am: 22.11.2007 + * Copyright: con terra GmbH, 2005 + * + * modified by: $Author: blume $ + * modified on: $Date: 2007/11/22 07:40:11 $ + * Version: $Revision: 1.1 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.geobackend.sde.datasources; + +import org.apache.log4j.Logger; + +/** + * The class <code>ArcSDEConnectionParams</code> fulfills the following purposes: + * <ol> + * <li></li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 22.11.2007 08:10:11 + */ +public class ArcSDEConnectionParams { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(ArcSDEConnectionParams.class); + private static boolean sDebug = sLogger.isDebugEnabled(); + + private String mServer; + private int mInstance; + private String mDatabase; + private String mUser; + private String mPwd; + private int mInitConnections; + private int mMaxConnections; + private long mTimeToHold; + + public ArcSDEConnectionParams(String pServer, int pInstance, String pDatabase, String pUser, String pPwd, int pInitConnections, int pMaxConnections, long pTimeToHold) { + mServer = pServer; + mInstance = pInstance; + mDatabase = pDatabase; + mUser = pUser; + mPwd = pPwd; + mMaxConnections = pMaxConnections; + mInitConnections = pInitConnections; + mTimeToHold = pTimeToHold; + } + + + public String getServer() { + return mServer; + } + + public int getInstance() { + return mInstance; + } + + public String getDatabase() { + return mDatabase; + } + + public String getUser() { + return mUser; + } + + public String getPwd() { + return mPwd; + } + + public int getInitConnections() { + return mInitConnections; + } + + public int getMaxConnections() { + return mMaxConnections; + } + + public long getTimeToHold() { + return mTimeToHold; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPool.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,288 @@ +/******************************************************************************* + * 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<SeConnection, Boolean> 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<SeConnection, Boolean>(); + 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<SeConnection> 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<Entry<SeConnection, Boolean>> entrySet = connections.entrySet(); + Iterator<Entry<SeConnection, Boolean>> iter = entrySet.iterator(); + SeConnection con = null; + while (iter.hasNext()) { + Entry<SeConnection, Boolean> 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEUtils.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,210 @@ +/** + * Title: ArcSDEUtils, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/ArcSDEUtils.java,v 1.7 2007/11/28 14:05:39 blume Exp $ + * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/ArcSDEUtils.java,v $ + * created by: Stefan Blume (blume) + * erstellt am: 21.11.2007 + * Copyright: con terra GmbH, 2005 + * + * modified by: $Author: blume $ + * modified on: $Date: 2007/11/28 14:05:39 $ + * Version: $Revision: 1.7 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.geobackend.sde.datasources; + +import java.util.Vector; + +import org.apache.log4j.Logger; + +import com.esri.sde.sdk.client.SDEPoint; +import com.esri.sde.sdk.client.SeColumnDefinition; +import com.esri.sde.sdk.client.SeConnection; +import com.esri.sde.sdk.client.SeError; +import com.esri.sde.sdk.client.SeException; +import com.esri.sde.sdk.client.SeQuery; +import com.esri.sde.sdk.client.SeQueryInfo; +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.sde.datasources.exception.TechnicalException; + +/** + * The class <code>ArcSDEUtils</code> fulfills the following purposes: + * <ol> + * <li></li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 08:20:40 + */ +public class ArcSDEUtils { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(ArcSDEUtils.class); + + + /** + * @param pTable e.g. "BSH.ARCMARINE_TIMESERIES_VIEW" + * @param pWhere where-Clause (can be empty, null-case not tested) + */ + public void getTableStats(String pTable, String pWhere) { + sLogger.debug("getTableStats()"); + SeConnection conn = null; + SeTable.SeTableStats tableStats; + try { + conn = getConnection(); + SeTable table = new SeTable(conn, pTable); + + SeSqlConstruct sqlCons = new SeSqlConstruct(table.getQualifiedName()); + sqlCons.setWhere(pWhere); + SeQuery query = new SeQuery(conn); + SeQueryInfo queryInfo = new SeQueryInfo(); + queryInfo.setConstruct(sqlCons); + int mask = SeTable.SeTableStats.SE_ALL_STATS; + int maxDistinct = 0; + + SeColumnDefinition[] colDefs = table.describe(); + + for (SeColumnDefinition lColDef : colDefs) { + sLogger.debug(lColDef.getName() + " - " + ArcSDEUtils.resolveType(lColDef.getType())); + } + + + tableStats = query.calculateTableStatistics(colDefs[1].getName(), mask, queryInfo, maxDistinct); + displayStats(tableStats); + + + } catch (SeException e) { + printError(e); + } catch (ConnectionException e) { + sLogger.error(e.getMessage(), e); + e.printError(); + } catch (TechnicalException e) { + sLogger.error(e.getMessage(), e); + } finally { + // return connection + returnConnection(conn); + } + + }// End method getTableStats + + + public void displayStats(SeTable.SeTableStats tableStats) { + + sLogger.debug("\n--> Table Statistics\n"); + if (tableStats != null) { + + sLogger.debug("Average - " + tableStats.getAverage()); + sLogger.debug("No of rows - " + tableStats.getCount()); + sLogger.debug("Maximum Value - " + tableStats.getMax()); + sLogger.debug("Minimum Value - " + tableStats.getMin()); + sLogger.debug("No of distinct values - " + tableStats.getNumDistinct()); + sLogger.debug("Standard Deviation - " + tableStats.getStdDev()); + + sLogger.debug("Distinct type - " + ArcSDEUtils.resolveType(tableStats.getDistinctType())); + + int[] distinctFreq = tableStats.getDistinctValueFrequencies(); + Vector distinctValues = tableStats.getDistinctValues(); + sLogger.debug("Distinct values & their frequencies : "); + for (int i = 0; i < distinctFreq.length; i++) + sLogger.debug(distinctValues.elementAt(i) + " - " + distinctFreq[i]); + }// End if + + }// End displayStats + + + /** + * Takes an integer corresponding to an ArcSDE data type + * and returns a string description of the type. + * + * @param type SDE data type bit-mask. + */ + public static String resolveType(int type) { + + String typeName = "Invalid Type"; + switch (type) { + + case SeColumnDefinition.TYPE_SMALLINT: + typeName = "Small Int"; + break; + case SeColumnDefinition.TYPE_INTEGER: + typeName = "Int"; + break; + case SeColumnDefinition.TYPE_FLOAT: + typeName = "Float"; + break; + case SeColumnDefinition.TYPE_DOUBLE: + typeName = "Double"; + break; + case SeColumnDefinition.TYPE_STRING: + typeName = "String"; + break; + case SeColumnDefinition.TYPE_BLOB: + typeName = "Blob"; + break; + case SeColumnDefinition.TYPE_DATE: + typeName = "Date"; + break; + case SeColumnDefinition.TYPE_SHAPE: + typeName = "Shape"; + break; + case SeColumnDefinition.TYPE_RASTER: + typeName = "Raster"; + break; + } + return typeName; + }// End method resolveType + + public static void printError(SeException exception) { + + 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); + + }// End printError + + private SeConnection getConnection() throws TechnicalException { + //DatasourceConnection lConnection = ConnectionPoolManager.getInstance().getConnection(ConnectionPoolManager.CON_SDE); + //return ((SDEConnection) lConnection).getConnection(); + return null; + } + + private void returnConnection(SeConnection pConnection) { + //ConnectionPoolManager.getInstance().returnConnection(pConnection); + } + + public static SDEPoint[] createPoints(double[][] pPoints) { + sLogger.debug("createPoints()"); + SDEPoint[] lSDEPoints = new SDEPoint[pPoints.length]; + for (int i = 0; i < pPoints.length; i++) { + double[] lPoint = pPoints[i]; + lSDEPoints[i] = new SDEPoint(lPoint[0], lPoint[1]); + } + return lSDEPoints; + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ColDefinition.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,86 @@ +/** + * Title: ColDefinition, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/ColDefinition.java,v 1.2 2007/12/21 12:31:15 blume Exp $ + * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/ColDefinition.java,v $ + * created by: Stefan Blume (blume) + * erstellt am: 21.11.2007 + * Copyright: con terra GmbH, 2005 + * + * modified by: $Author: blume $ + * modified on: $Date: 2007/12/21 12:31:15 $ + * Version: $Revision: 1.2 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.geobackend.sde.datasources; + +import org.apache.log4j.Logger; + +/** + * The class <code>ColDefinition</code> fulfills the following purposes: + * <ol> + * <li></li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 10:59:45 + */ +public class ColDefinition { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(ColDefinition.class); + + /** + * @deprecated + */ + public static final int SMALLINT = 1; + /** + * @deprecated + */ + public static final int INTEGER = 2; + /** + * @deprecated + */ + public static final int FLOAT = 3; + /** + * @deprecated + */ + public static final int DOUBLE = 4; + public static final int INT16 = 1; + public static final int INT32 = 2; + public static final int FLOAT32 = 3; + public static final int FLOAT64 = 4; + public static final int STRING = 5; + public static final int BLOB = 6; + public static final int DATE = 7; + public static final int SHAPE = 8; + public static final int RASTER = 9; + public static final int XML = 10; + public static final int INT64 = 11; + public static final int UUID = 12; + public static final int CLOB = 13; + public static final int NSTRING = 14; + public static final int NCLOB = 15; + + private String mName; + private int mType; + + public ColDefinition(String pName, int pType) { + mName = pName; + mType = pType; + } + + public String getName() { + return mName; + } + + public int getType() { + return mType; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Datasource.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,92 @@ +/* Copyright (C) 2007 con terra GmbH (http://www.conterra.de) + * All rights reserved + * + * $Id: Datasource.java,v 1.4 2008/01/30 12:38:34 blume Exp $ + * + * created by: drewnak + * created at : 21.11.2007 + * created at : 14:25:50 + * + * 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 de.intevation.gnv.geobackend.sde.datasources.exception.DatasourceException; + +/** + * Abstract class for handling different datasources. + * This method provides a static method for creating dataosurce objects. + * + * @author drewnak + */ +public abstract class Datasource { + + protected Map mParameters; + + protected String mName; + + + /** + * Triggers the creation of a dataosurce object. Following the guidelines, the parameters for creating this datasource are delivered by the configuration file. + * + * @param pName a name for the datasource. + * @param pClassname The name of the class extending this abstract datasource class. Used to create a new instance. + * @param pParams a Map of Parameters needed for the initialization of the datasource. + * @return a datasourceobject + * @throws DatasourceException if the class could not be found or the initialization of the datasource fails. + */ + public static final Datasource create(String pName, String pClassname, + Map pParams) throws DatasourceException { + Class lDatasourceClass; + try { + lDatasourceClass = Class.forName(pClassname); + } catch (ClassNotFoundException e) { + throw new DatasourceException("Could not load class " + pClassname); + } + Datasource lNewInstance; + try { + lNewInstance = (Datasource) lDatasourceClass.newInstance(); + } catch (Exception e) { + throw new DatasourceException("Could not create instance of " + pClassname, e); + } + lNewInstance.init(pName, pParams); + + return lNewInstance; + } + + /** + * An abstract method for the initialization of a datasource instance. + * Of course, only the concrete implementation knwos about the ncessary parameters for the initialization. + * + * @param pName a name for the datasource. + * @param pParams a Map of Parameters needed for the initialization of the datasource. + */ + protected abstract void init(String pName, Map pParams) throws DatasourceException; + + /** + * @return + */ + public String getName() { + return mName; + } + + + /** + * This method returns a datasourceconnection. + * Only the concrete implementation of the Datasource knwos about the DatasourceConnection-Implementation to return. + * + * @return a DatasourceConnection + */ + public abstract DatasourceConnection getConnection(); + + /** + * Returns a DatasourceConnection. This method is usualy called after an executed query. + * See: Some datasource implementations need to explicitly close an existing connection. + * + * @param pConnection the connection to be returned. + */ + public abstract void returnConnection(DatasourceConnection pConnection); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/DatasourceConnection.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,31 @@ +/** + * Title: IDatasourceConnection, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/DatasourceConnection.java,v 1.2 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/DatasourceConnection.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.2 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.geobackend.sde.datasources; + +/** + * The interface <code>DatasourceConnection</code> fulfills the following purposes: + * <ol> + * <li>Beeing a marker interface for datasource connections.</li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 08:50:20 + */ +public interface DatasourceConnection { +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ResultSet.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,68 @@ +/** + * Title: ResultSet, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/ResultSet.java,v 1.2 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/ResultSet.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.2 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.geobackend.sde.datasources; + +import org.apache.log4j.Logger; + +/** + * The class <code>ResultSet</code> fulfills the following purposes: + * <ol> + * <li>Providing an abstract object for dealing with result sets.</li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 09:26:53 + */ +public abstract class ResultSet { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(ResultSet.class); + + /** + * Returns the number of hits. + * + * @return count of results. + */ + public abstract int getCount(); + + /** + * Returns the number of columns returned through the query. + * + * @return the number of columns. + */ + public abstract int getNumberOfColumns(); + + /** + * A ResultSet can tell about the concrete definition of each column. + * This method returns an array of {@link de.conterra.bsh.gdi.gnviewer.datasources.ColDefinition}-Objects. + * + * @return the definitions describing the result set. + */ + public abstract ColDefinition[] getColumnDefinitions(); + + /** + * Returns an array of Rows. The rows contain the "content" of the current ResultSet. + * + * @return the results itself. + */ + public abstract Row[] getResults(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,249 @@ +/** + * Title: Row, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/Row.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/Row.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 java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; + +import org.apache.log4j.Logger; + +import com.esri.sde.sdk.client.SDEPoint; +import com.esri.sde.sdk.client.SeException; +import com.esri.sde.sdk.client.SeShape; + +import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; +import de.intevation.gnv.geobackend.util.DateUtils; + +/** + * A Row represents a set of values. + * In a technical manner (e.g. database manner) a row contains all attributes of a single "hit". + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 11:00:54 + */ +public class Row { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(Row.class); + private static boolean sDebug = sLogger.isDebugEnabled(); + + /** + * Data container. + */ + private Object[] mObjects; + + /** + * Constructor. + * + * @param pRowSize the number of attributes contained by this row. + */ + public Row(int pRowSize) { + mObjects = new Object[pRowSize]; + } + + /** + * Constructor. + * + * @param ArrayStr a line from CSV-File. + */ + public Row (String[] ArrayStr){ + this (ArrayStr.length); + int nLength = ArrayStr.length; + for (int i=0; i < nLength; i++){ + //if (sDebug) + // sLogger.debug(" ArrayStr["+i+" ]=" + ArrayStr[i]); + addObject(ArrayStr[i], i); + + } + + } + + + /** + * Adds an attribute value to a specific position of this row. + * + * @param pObject the object to be stored. + * @param pPos the postion the value to be saved + */ + public void addObject(Object pObject, int pPos) { + mObjects[pPos] = pObject; + } + + /** + * Returns a Value out of the Row. + * + * @param pPos the position of the value to be returned. + * @return an Object! (not strongly typed) + * @throws TechnicalException + */ + public Object getValue(int pPos) throws TechnicalException { + if (pPos < mObjects.length) { + return mObjects[pPos]; + } else { + throw new TechnicalException("Cannot access this field position. Size is: " + mObjects.length); + } + } + + + /** + * This is a covenient method for getting strongly typed objects out of the row. + * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). + * In fact, this method executes a simple cast to the desired type. + * + * @param pPos the position of the object to be resolved. + * @return a strongly typed Date + * @throws TechnicalException + * @see #getValue(int) + */ + public Date getDateValue(int pPos) throws TechnicalException { + Date date = null; + try { + Calendar lCalendar = (Calendar) getValue(pPos); + date = lCalendar.getTime(); + } + catch (ClassCastException e) { + try{ + //SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); + date = DateUtils.getDateFromString ((String)getValue(pPos)); //(Date)formatter.parse((String)getValue(pPos)); + + + } + catch (Exception ex){ + sLogger.error(getValue(pPos) + " " + ex.getMessage(), ex); + throw new TechnicalException("Could not cast this value to the Date Type. Object is of value type: " + getValue(pPos).getClass().getName()); + } + } + + return date; + } + + /** + * This is a covenient method for getting strongly typed objects out of the row. + * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). + * In fact, this method executes a simple cast to the desired type. + * + * @param pPos the position of the object to be resolved. + * @return a strongly typed String + * @throws TechnicalException + * @see #getValue(int) + */ + public String getStringValue(int pPos) throws TechnicalException { + try { + return (String) getValue(pPos); + } catch (ClassCastException e) { + throw new TechnicalException("Could not cast this value to the String Type. Object is of value type: " + getValue(pPos).getClass().getName()); + } + } + + /** + * This is a covenient method for getting strongly typed objects out of the row. + * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). + * In fact, this method executes a simple cast to the desired type. + * + * @param pPos the position of the object to be resolved. + * @throws TechnicalException + * @see #getValue(int) + * * @return a strongly typed int + */ + public int getIntValue(int pPos) throws TechnicalException { + try { + return (Integer) getValue(pPos); + } catch (ClassCastException e) { + throw new TechnicalException("Could not cast this value to the Integer Type. Object is of value type: " + getValue(pPos).getClass().getName()); + } + } + + /** + * This is a covenient method for getting strongly typed objects out of the row. + * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). + * In fact, this method executes a simple cast to the desired type. + * + * @param pPos the position of the object to be resolved. + * @throws TechnicalException + * @see #getValue(int) + * * @return a strongly typed Double + */ + public Double getDoubleValue(int pPos) throws TechnicalException { + try { + return (Double) getValue(pPos); + } catch (ClassCastException e) { + try{ + return new Double ((String)getValue(pPos)); + } + catch(Exception ex){ + sLogger.error(getValue(pPos) + " " + ex.getMessage(), ex); + throw new TechnicalException("Could not cast this value to the Double Type. Object is of value type: " + getValue(pPos).getClass().getName()); + } + } + } + + /** + * This is a covenient method for getting strongly typed objects out of the row. + * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). + * In fact, this method executes a simple cast to the desired type. + * + * @param pPos the position of the object to be resolved. + * @return a strongly typed Float + * @throws TechnicalException + * @see #getValue(int) + */ + public Float getFloatValue(int pPos) throws TechnicalException { + try { + return (Float) getValue(pPos); + } catch (ClassCastException e) { + throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName()); + } + } + /** + * This is a covenient method for getting strongly typed objects out of the row. + * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). + * In fact, this method executes a simple cast to the desired type. + * + * @param pPos the position of the object to be resolved. + * @return a strongly typed Float + * @throws TechnicalException + * @see #getValue(int) + */ + public String getPosValue(int pPos)throws TechnicalException{ + SeShape val; + ArrayList aList; + SDEPoint mPoint[]; + double lat,lon; + try { + val = (SeShape) getValue(pPos); + aList = val.getAllPoints(0,false); + mPoint = (SDEPoint[])aList.get(0); + lat = mPoint[0].getY(); + lon = mPoint[0].getX(); + String nord="N"; + String ost="E"; + if (lat <0 ){nord="S"; lat=-lat;} + if (lon <0 ){ost="W"; lon=-lon;} + return String.format("%1$02d°%2$1S %3$05.2f' %4$03d°%5$1S %6$05.2f'", + (int)lat, nord,60.*(lat-((int)lat)),(int)lon,ost,60.*(lon-((int)lon))); + + + } catch (SeException e) { + throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEConnection.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,72 @@ +/** + * 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 <code>SDEConnection</code> fulfills the following purposes: + * <ol> + * <li>Providing an implementation of DatasourceConnection-Interface for a SDE database.</li> + * </ol> + * + * @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); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEDatasource.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,131 @@ +/* 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()) { + /* + <DataSource name="sde" classname="de.conterra.bsh.gdi.gnviewer.datasources.sde.SDEDatasource"> + <Parameter name="sde.url">localhost</Parameter> + <Parameter name="sde.user">bsh</Parameter> + <Parameter name="sde.password">bsh</Parameter> + <Parameter name="sde.port">5151</Parameter> + </DataSource> + */ + + 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); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEQuery.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,385 @@ +/** + * Title: SdeQuery, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/SDEQuery.java,v 1.3 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/SDEQuery.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.3 $ + * 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.SDEPoint; +import com.esri.sde.sdk.client.SeColumnDefinition; +import com.esri.sde.sdk.client.SeConnection; +import com.esri.sde.sdk.client.SeCoordinateReference; +import com.esri.sde.sdk.client.SeException; +import com.esri.sde.sdk.client.SeFilter; +import com.esri.sde.sdk.client.SeLayer; +import com.esri.sde.sdk.client.SeQuery; +import com.esri.sde.sdk.client.SeRow; +import com.esri.sde.sdk.client.SeShape; +import com.esri.sde.sdk.client.SeShapeFilter; +import com.esri.sde.sdk.client.SeSqlConstruct; + +import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; +import de.intevation.gnv.geobackend.util.DateUtils; + +/** + * // todo: supply a general interface for Query-Objects (Query = read access to datasource implementation) + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 11:32:19 + */ +public class SDEQuery { + + /** + * Default Logging instance + */ + private static final Logger sLogger = Logger.getLogger(SDEQuery.class); + private static boolean sDebug = sLogger.isDebugEnabled(); + + + DatasourceConnection mConnection; + + public SDEQuery(DatasourceConnection pConnection) { + if (sDebug) sLogger.debug("SDEQuery()"); + mConnection = pConnection; + } + + /** + * Execute a query against a sde datasource. + * This Query method is responsible for getting and returning a valid {@link SeConnection}-Object. + * + * @param pTables + * @param pCols + * @param pWhere the where-clause to be executed. + * @return a ResultSet + * @see SeSqlConstruct + * @see SeQuery + */ + public ResultSet executeQuery(String pTables[], String pCols[], String pWhere) throws TechnicalException { + sLogger.debug("executeQuery()"); + SeConnection 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()); + return lSet; + } catch (TechnicalException e) { + sLogger.error(e.getMessage(), e); + throw e; + } catch (SeException e) { + sLogger.error(e.getMessage(), e); + throw new TechnicalException("Error during executeQuery", e); + } finally { + returnConnection(con); + } + + } + + /** + * Execute a query against a sde datasource. + * This Query method is responsible for getting and returning a valid {@link SeConnection}-Object. + * + * @param pSQLStatement the SQL-Statement to be executed. + * @return a ResultSet + * @see SeQuery + */ + public ResultSet executeQuery(String pSQLStatement) throws TechnicalException { + if (sDebug) sLogger.debug("executeQuery():\n" + pSQLStatement); + SeConnection con = null; + try { + con = getConnection(); + + SeQuery lSeQuery = new SeQuery(con); + long lStart = System.currentTimeMillis(); + lSeQuery.prepareSql(pSQLStatement); + lSeQuery.execute(); + + ResultSet lSet = handleResultSet(lSeQuery); + + //TmpFile erstellen + //Row auslesen + //Row -> TmpFile + //TmpFile close + + 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) { + sLogger.error(e.getMessage(), e); + throw new TechnicalException("Error during executeQuery", e); + } finally { + returnConnection(con); + } + + + } + +// /** +// * Execute a query against a sde datasource. +// * This Query method is responsible for getting and returning a valid {@link SeConnection}-Object. +// * +// * @param pSQLStatement the SQL-Statement to be executed. +// * @return File +// * @see SeQuery +// */ +// public TempFile executeQueryDiagram (String pSQLStatement) throws TechnicalException { +// if (sDebug) sLogger.debug("executeQueryDiagram():\n" + pSQLStatement); +// SeConnection con = null; +// TempFile lImageFile = null; +// try { +// con = getConnection(); +// +// SeQuery lSeQuery = new SeQuery(con); +// long lStart = System.currentTimeMillis(); +// lSeQuery.prepareSql(pSQLStatement); +// lSeQuery.execute(); +// +// //ResultSet lSet = handleResultSet(lSeQuery); +// lImageFile = handleRowToCSVFile(lSeQuery); +// +// +// long lEnd = System.currentTimeMillis(); +// if (sDebug) +// sLogger.debug((new StringBuilder()).append("lSeQuery lasts ").append((double) (lEnd - lStart) / 1000D).append(" seconds").toString()); +// +// } catch (TechnicalException e) { +// sLogger.error(e.getMessage(), e); +// throw e; +// } catch (SeException e) { +// sLogger.error(e.getMessage(), e); +// throw new TechnicalException("Error during executeQuery", e); +// } finally { +// returnConnection(con); +// } +// return lImageFile; +// +// } + + /** + * Execute a spatial query against a sde datasource. + * This Query method is responsible for getting and returning a valid {@link SeConnection}-Object. + * // todo: there is work needed to fully implement the wanted functionality. + * + * @param pLayername + * @param pSpatialColumnName + * @param pPoints + * @param pReturnFields + * @return a ResultSet + * @see SeShapeFilter + * @see SeQuery + */ + public ResultSet executeQuery(String pLayername, String pSpatialColumnName, double[][] pPoints, String[] pReturnFields) throws TechnicalException { + sLogger.debug("executeQuery()"); + SeConnection 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); + + /* + * 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); + + } catch (TechnicalException e) { + sLogger.error(e.getMessage(), e); + throw e; + } catch (SeException e) { + sLogger.error(e.getMessage(), e); + throw new TechnicalException("Error accessing Spatial Database: " + e.getMessage(), e); + } finally { + returnConnection(con); + } + } + /** + * Execute a spatial query against a sde datasource. + * This Query method is responsible for getting and returning a valid {@link SeConnection}-Object. + * // todo: there is work needed to fully implement the wanted functionality. + * + * @param pLayername + * @param pSpatialColumnName + * @param pPoints + * @param pReturnFields + * @return a ResultSet + * @see SeShapeFilter + * @see SeQuery + */ + public ResultSet executeQuery(String pLayername, String pSpatialColumnName, String pWhere, double[][] pPoints, String[] pReturnFields) throws TechnicalException { + sLogger.debug("executeQuery()"); + SeConnection 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); + + /* + * 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); + + } catch (TechnicalException e) { + sLogger.error(e.getMessage(), e); + throw e; + } catch (SeException 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 void returnConnection(SeConnection pSeConnection) { + ((SDEConnection) mConnection).returnConnection(pSeConnection); + } + + + private ResultSet handleResultSet(SeQuery pSeQuery) throws SeException { + sLogger.debug("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; + } + +// private TempFile handleRowToCSVFile(SeQuery pSeQuery) throws SeException { +// sLogger.debug("handleRowToTempFile()"); +// TempFile lImageFile = TemporaryFileDirectory.getInstance().createFile(".csv"); +// sLogger.debug("handleRowToTempFile() erstellen " + lImageFile.getFile().getName()); +// CSVWriter writer = null; +// ColDefinition[] lColDefinitions = null; +// +// SeRow row; +// int lCount; +// try { +// writer = new CSVWriter(new FileWriter(lImageFile.getFile()), ';'); +// for (lCount = 0; (row = pSeQuery.fetch()) != null; lCount++) { +// // one time execution +// if (lCount == 0) { +// lColDefinitions = new ColDefinition[row.getNumColumns()]; +// // analyze cols of result set +// SeColumnDefinition[] lCols = row.getColumns(); +// int j = 0; +// for (SeColumnDefinition lCol : lCols) { +// lColDefinitions[j] = new ColDefinition(lCol.getName(), lCol.getType()); +// j = j + 1; +// } +// } +// short lNumCols = row.getNumColumns(); +// Row lBackingRow = new Row(lNumCols); +// for (int i = 0; i < lNumCols; i++) { +// lBackingRow.addObject(row.getObject(i), i); +// } +// +// writer.writeRow(lBackingRow,lColDefinitions, false); +// } +// } catch (IOException e) { +// sLogger.error(e.getMessage(), e); +// } catch (TechnicalException e) { +// sLogger.error(e.getMessage(), e); +// } +// finally { +// pSeQuery.close(); +// try{ +// writer.close(); +// } +// catch (Exception e){ +// sLogger.error(e.getMessage(), e); +// } +// } +// +// return lImageFile; +// } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/SDEResultSet.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,71 @@ +/** + * Title: SDEResultSet, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/SDEResultSet.java,v 1.2 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/SDEResultSet.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.2 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.geobackend.sde.datasources; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.log4j.Logger; + +/** + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 11:01:27 + */ +public class SDEResultSet extends ResultSet { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(SDEResultSet.class); + + + private List<Row> mRows = Collections.synchronizedList(new ArrayList<Row>()); + private List<ColDefinition> mCols = Collections.synchronizedList(new ArrayList<ColDefinition>()); + + public SDEResultSet() { + } + + public int getCount() { + return mRows.size(); + } + + 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); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/exception/ConnectionException.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,111 @@ +/** + * 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 <code>lConnectionException</code> fulfills the following purposes: + * <ol> + * <li></li> + * </ol> + * + * @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 <code>null</code> 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. <p>Note that the detail message associated with + * <code>cause</code> is <i>not</i> 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 <tt>null</tt> 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); + + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/exception/DatasourceException.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,37 @@ +/* Copyright (C) 2007 con terra GmbH (http://www.conterra.de) + * All rights reserved + * + * $Id: DatasourceException.java,v 1.2 2008/01/30 12:38:34 blume Exp $ + * + * created by: drewnak + * created at : 21.11.2007 + * created at : 14:56:32 + * + * modified by: $Author: blume $ + * modified at: $Date: 2008/01/30 12:38:34 $ + */ +package de.intevation.gnv.geobackend.sde.datasources.exception; + +/** + * A Class for encapsulating implementation specific datasource exceptions. + * This exception class can be used for all exceptions occuring in connection to "datasources actions". + */ +public class DatasourceException extends Exception { + + public DatasourceException() { + super(); + } + + public DatasourceException(String pMessage) { + super(pMessage); + } + + public DatasourceException(String pMessage, Throwable pCause) { + super(pMessage, pCause); + } + + public DatasourceException(Throwable pCause) { + super(pCause); + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/exception/TechnicalException.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,79 @@ +/** + * Title: TechnicalException, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/exception/TechnicalException.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/TechnicalException.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 org.apache.log4j.Logger; + +/** + * The class <code>TechnicalException</code> fulfills the following purposes: + * <ol> + * <li></li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.11.2007 08:12:08 + */ +public class TechnicalException extends Exception{ + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(TechnicalException.class); + + /** + * Constructs a new exception with <code>null</code> as its detail message. + * The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause}. + */ + public TechnicalException() { + } + + /** + * 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 TechnicalException(String message) { + super(message); + } + public TechnicalException(Throwable pCause) { + super(pCause); + } + + /** + * Constructs a new exception with the specified detail message and + * cause. <p>Note that the detail message associated with + * <code>cause</code> is <i>not</i> 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 <tt>null</tt> value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.4 + */ + public TechnicalException(String message, Throwable cause) { + super(message, cause); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/util/DateUtils.java Wed Sep 02 09:07:03 2009 +0000 @@ -0,0 +1,128 @@ +/** + * Title: DateUtisl, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/util/DateUtils.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/util/DateUtils.java,v $ + * created by: Stefan Blume (blume) + * erstellt am: 21.12.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.util; + +import org.apache.log4j.Logger; + +import java.text.SimpleDateFormat; +import java.util.Date; + + +/** + * The class <code>DateUtisl</code> fulfills the following purposes: + * <ol> + * <li></li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.12.2007 10:34:01 + */ +public class DateUtils { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(DateUtils.class); + private static boolean sDebug = sLogger.isDebugEnabled(); + + private static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss"; + private static final String DATE_PATTERN1 = "dd-MMM-yyyy HH:mm:ss"; + private static final String TimeRangeFilterPattern = "yyyy-MM-dd'T'HH:mm:ssZ"; + private static final String TimeRangeFilterFormPattern = "dd.MM.yyyy HH:mm"; + + public static String getPatternedDateSDF(Date pDate) { + SimpleDateFormat fmt = new SimpleDateFormat(); + fmt.applyPattern(DATE_PATTERN); + return fmt.format(pDate); + } + + public static String getPatternedDate(Date pDate, String sPattern) { +// DateTimeZone.setDefault(DateTimeZone.UTC); +// DateTime dtf = new DateTime (pDate); +// String sStr = dtf.toString(sPattern); +// return sStr; + SimpleDateFormat fmt = new SimpleDateFormat(); + fmt.applyPattern(sPattern); + return fmt.format(pDate); + } + + public static String getPatternedDateAmer(Date pDate) { + + String sStr = getPatternedDate(pDate, DATE_PATTERN); + return sStr; + } + + public static String getPatternedDateGerm(Date pDate) { + + String sStr = getPatternedDate(pDate, DATE_PATTERN1); + return sStr; + } + + public static String getPatternedDateTimeRangeFilter(Date pDate) { + + String sStr = getPatternedDate(pDate, TimeRangeFilterPattern); + return sStr; + } + + public static String getPatternedDateTimeRangeFilterForm(Date pDate) { + + String sStr = getPatternedDate(pDate, TimeRangeFilterFormPattern); + return sStr; + } + + public synchronized static Date getDateFromStringSDF (String sStr)throws Exception { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); + Date date = (Date)formatter.parse(sStr); + return date; + } + + public static Date getDateFromString (String sStr)throws Exception { + + Date date = getDateFromString (sStr, DATE_PATTERN1); + return date; + } + + public static Date getDateFromStringTimeRangeFilter (String sStr)throws Exception { + + Date date = getDateFromString (sStr, TimeRangeFilterPattern); + return date; + } + + public static Date getDateFromStringTimeRangeFilterForm (String sStr)throws Exception { + + Date date = getDateFromString (sStr, TimeRangeFilterFormPattern); + return date; + } + + public static Date getDateFromString (String sStr, String sPattern)throws Exception { +// DateTime dtf = null; +// DateTimeZone.setDefault(DateTimeZone.UTC); +// +// dtf = DateTimeFormat.forPattern(sPattern).parseDateTime(sStr); +// +// Date date = dtf.toDate(); +// +// return date; + SimpleDateFormat fmt = new SimpleDateFormat(); + fmt.applyPattern(sPattern); + return fmt.parse(sStr); + } + + +}