Mercurial > dive4elements > gnv-client
view geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEUtils.java @ 129:110e3ac1b7d2
Library Dependencies Added to pom.xml-File
Import of SDE-Datasources
geo-backend/trunk@5 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Wed, 02 Sep 2009 09:07:03 +0000 |
parents | |
children | e4eacd613356 |
line wrap: on
line source
/** * 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; } }