Mercurial > dive4elements > gnv-client
comparison 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 |
comparison
equal
deleted
inserted
replaced
128:9b3f5a067c29 | 129:110e3ac1b7d2 |
---|---|
1 /** | |
2 * 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 $ | |
3 * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/ArcSDEUtils.java,v $ | |
4 * created by: Stefan Blume (blume) | |
5 * erstellt am: 21.11.2007 | |
6 * Copyright: con terra GmbH, 2005 | |
7 * | |
8 * modified by: $Author: blume $ | |
9 * modified on: $Date: 2007/11/28 14:05:39 $ | |
10 * Version: $Revision: 1.7 $ | |
11 * TAG: $Name: $ | |
12 * locked from: $Locker: $ | |
13 * CVS State: $State: Exp $ | |
14 * Project: $ProjectName$ | |
15 */ | |
16 package de.intevation.gnv.geobackend.sde.datasources; | |
17 | |
18 import java.util.Vector; | |
19 | |
20 import org.apache.log4j.Logger; | |
21 | |
22 import com.esri.sde.sdk.client.SDEPoint; | |
23 import com.esri.sde.sdk.client.SeColumnDefinition; | |
24 import com.esri.sde.sdk.client.SeConnection; | |
25 import com.esri.sde.sdk.client.SeError; | |
26 import com.esri.sde.sdk.client.SeException; | |
27 import com.esri.sde.sdk.client.SeQuery; | |
28 import com.esri.sde.sdk.client.SeQueryInfo; | |
29 import com.esri.sde.sdk.client.SeSqlConstruct; | |
30 import com.esri.sde.sdk.client.SeTable; | |
31 | |
32 import de.intevation.gnv.geobackend.sde.datasources.exception.ConnectionException; | |
33 import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; | |
34 | |
35 /** | |
36 * The class <code>ArcSDEUtils</code> fulfills the following purposes: | |
37 * <ol> | |
38 * <li></li> | |
39 * </ol> | |
40 * | |
41 * @author blume | |
42 * @version 1.0 | |
43 * @serial 1.0 | |
44 * @see | |
45 * @since 21.11.2007 08:20:40 | |
46 */ | |
47 public class ArcSDEUtils { | |
48 | |
49 /** | |
50 * Default Logging instance | |
51 */ | |
52 private static Logger sLogger = Logger.getLogger(ArcSDEUtils.class); | |
53 | |
54 | |
55 /** | |
56 * @param pTable e.g. "BSH.ARCMARINE_TIMESERIES_VIEW" | |
57 * @param pWhere where-Clause (can be empty, null-case not tested) | |
58 */ | |
59 public void getTableStats(String pTable, String pWhere) { | |
60 sLogger.debug("getTableStats()"); | |
61 SeConnection conn = null; | |
62 SeTable.SeTableStats tableStats; | |
63 try { | |
64 conn = getConnection(); | |
65 SeTable table = new SeTable(conn, pTable); | |
66 | |
67 SeSqlConstruct sqlCons = new SeSqlConstruct(table.getQualifiedName()); | |
68 sqlCons.setWhere(pWhere); | |
69 SeQuery query = new SeQuery(conn); | |
70 SeQueryInfo queryInfo = new SeQueryInfo(); | |
71 queryInfo.setConstruct(sqlCons); | |
72 int mask = SeTable.SeTableStats.SE_ALL_STATS; | |
73 int maxDistinct = 0; | |
74 | |
75 SeColumnDefinition[] colDefs = table.describe(); | |
76 | |
77 for (SeColumnDefinition lColDef : colDefs) { | |
78 sLogger.debug(lColDef.getName() + " - " + ArcSDEUtils.resolveType(lColDef.getType())); | |
79 } | |
80 | |
81 | |
82 tableStats = query.calculateTableStatistics(colDefs[1].getName(), mask, queryInfo, maxDistinct); | |
83 displayStats(tableStats); | |
84 | |
85 | |
86 } catch (SeException e) { | |
87 printError(e); | |
88 } catch (ConnectionException e) { | |
89 sLogger.error(e.getMessage(), e); | |
90 e.printError(); | |
91 } catch (TechnicalException e) { | |
92 sLogger.error(e.getMessage(), e); | |
93 } finally { | |
94 // return connection | |
95 returnConnection(conn); | |
96 } | |
97 | |
98 }// End method getTableStats | |
99 | |
100 | |
101 public void displayStats(SeTable.SeTableStats tableStats) { | |
102 | |
103 sLogger.debug("\n--> Table Statistics\n"); | |
104 if (tableStats != null) { | |
105 | |
106 sLogger.debug("Average - " + tableStats.getAverage()); | |
107 sLogger.debug("No of rows - " + tableStats.getCount()); | |
108 sLogger.debug("Maximum Value - " + tableStats.getMax()); | |
109 sLogger.debug("Minimum Value - " + tableStats.getMin()); | |
110 sLogger.debug("No of distinct values - " + tableStats.getNumDistinct()); | |
111 sLogger.debug("Standard Deviation - " + tableStats.getStdDev()); | |
112 | |
113 sLogger.debug("Distinct type - " + ArcSDEUtils.resolveType(tableStats.getDistinctType())); | |
114 | |
115 int[] distinctFreq = tableStats.getDistinctValueFrequencies(); | |
116 Vector distinctValues = tableStats.getDistinctValues(); | |
117 sLogger.debug("Distinct values & their frequencies : "); | |
118 for (int i = 0; i < distinctFreq.length; i++) | |
119 sLogger.debug(distinctValues.elementAt(i) + " - " + distinctFreq[i]); | |
120 }// End if | |
121 | |
122 }// End displayStats | |
123 | |
124 | |
125 /** | |
126 * Takes an integer corresponding to an ArcSDE data type | |
127 * and returns a string description of the type. | |
128 * | |
129 * @param type SDE data type bit-mask. | |
130 */ | |
131 public static String resolveType(int type) { | |
132 | |
133 String typeName = "Invalid Type"; | |
134 switch (type) { | |
135 | |
136 case SeColumnDefinition.TYPE_SMALLINT: | |
137 typeName = "Small Int"; | |
138 break; | |
139 case SeColumnDefinition.TYPE_INTEGER: | |
140 typeName = "Int"; | |
141 break; | |
142 case SeColumnDefinition.TYPE_FLOAT: | |
143 typeName = "Float"; | |
144 break; | |
145 case SeColumnDefinition.TYPE_DOUBLE: | |
146 typeName = "Double"; | |
147 break; | |
148 case SeColumnDefinition.TYPE_STRING: | |
149 typeName = "String"; | |
150 break; | |
151 case SeColumnDefinition.TYPE_BLOB: | |
152 typeName = "Blob"; | |
153 break; | |
154 case SeColumnDefinition.TYPE_DATE: | |
155 typeName = "Date"; | |
156 break; | |
157 case SeColumnDefinition.TYPE_SHAPE: | |
158 typeName = "Shape"; | |
159 break; | |
160 case SeColumnDefinition.TYPE_RASTER: | |
161 typeName = "Raster"; | |
162 break; | |
163 } | |
164 return typeName; | |
165 }// End method resolveType | |
166 | |
167 public static void printError(SeException exception) { | |
168 | |
169 SeError error = exception.getSeError(); | |
170 | |
171 sLogger.debug("\n ArcSDE Error Number : " + error.getSdeError()); | |
172 sLogger.debug(" Error Description : " + error.getErrDesc()); | |
173 | |
174 int extError = error.getExtError(); | |
175 if (extError != 0) | |
176 sLogger.debug(" Extended Error Number : " + extError); | |
177 | |
178 String desc = error.getSdeErrMsg(); | |
179 if (desc != null && desc.length() != 0) | |
180 sLogger.debug(" Extended Error Description : " + desc); | |
181 | |
182 desc = error.getExtErrMsg(); | |
183 if (desc != null && desc.length() != 0) | |
184 sLogger.debug(" Extended Error Description : " + desc); | |
185 | |
186 sLogger.debug(exception); | |
187 | |
188 }// End printError | |
189 | |
190 private SeConnection getConnection() throws TechnicalException { | |
191 //DatasourceConnection lConnection = ConnectionPoolManager.getInstance().getConnection(ConnectionPoolManager.CON_SDE); | |
192 //return ((SDEConnection) lConnection).getConnection(); | |
193 return null; | |
194 } | |
195 | |
196 private void returnConnection(SeConnection pConnection) { | |
197 //ConnectionPoolManager.getInstance().returnConnection(pConnection); | |
198 } | |
199 | |
200 public static SDEPoint[] createPoints(double[][] pPoints) { | |
201 sLogger.debug("createPoints()"); | |
202 SDEPoint[] lSDEPoints = new SDEPoint[pPoints.length]; | |
203 for (int i = 0; i < pPoints.length; i++) { | |
204 double[] lPoint = pPoints[i]; | |
205 lSDEPoints[i] = new SDEPoint(lPoint[0], lPoint[1]); | |
206 } | |
207 return lSDEPoints; | |
208 | |
209 } | |
210 } |