comparison geo-backend/src/test/java/de/intevation/gnv/geobackend/base/query/ToCharSample.java @ 554:0ee3c0ed40e4

Added two Sample-Application demonstrating Bugs in the ArcSDE geo-backend/trunk@630 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 26 Jan 2010 13:55:55 +0000
parents
children 1c3efbd2fc5a
comparison
equal deleted inserted replaced
553:5b536542ef56 554:0ee3c0ed40e4
1 package de.intevation.gnv.geobackend.base.query;
2
3 import com.esri.sde.sdk.client.SDEPoint;
4 import com.esri.sde.sdk.client.SeColumnDefinition;
5 import com.esri.sde.sdk.client.SeConnection;
6 import com.esri.sde.sdk.client.SeException;
7 import com.esri.sde.sdk.client.SeFilter;
8 import com.esri.sde.sdk.client.SeLayer;
9 import com.esri.sde.sdk.client.SeQuery;
10 import com.esri.sde.sdk.client.SeQueryInfo;
11 import com.esri.sde.sdk.client.SeRow;
12 import com.esri.sde.sdk.client.SeShape;
13 import com.esri.sde.sdk.client.SeShapeFilter;
14 import com.esri.sde.sdk.client.SeSqlConstruct;
15
16 public class ToCharSample {
17
18
19 public boolean executeQuery(SeConnection con, String[] pLayername,
20 String pSpatialColumnName, String pWhere,
21 SDEPoint[] g, String[] pReturnFields, String byClause) {
22
23 try {
24 // get the layer for querying
25
26 SeShapeFilter[] filters = null;
27 if (g != null){
28 SeLayer lLayer = new SeLayer(con, pLayername[0], pSpatialColumnName);
29 SeShape shape = new SeShape();
30 shape.setCoordRef(lLayer.getCoordRef());
31
32
33
34 shape.generatePolygon(g.length, 1, null, g);
35 SeShapeFilter filter = new SeShapeFilter(pLayername[0],
36 pSpatialColumnName, shape, SeFilter.METHOD_AI);
37 filters = new SeShapeFilter[1];
38 filters[0] = filter;
39 }
40
41 SeQuery spatialQuery = null;
42 SeSqlConstruct sqlCons = new SeSqlConstruct(pLayername, pWhere);
43 spatialQuery = new SeQuery(con);
44
45 SeQueryInfo queryInfo = new SeQueryInfo();
46 queryInfo.setColumns(pReturnFields);
47
48 if (byClause != null){
49 queryInfo.setByClause(byClause);
50 }
51
52 queryInfo.setConstruct(sqlCons);
53 spatialQuery.prepareQueryInfo(queryInfo);
54
55 /*
56 * Set spatial constraints
57 */
58 if (filters != null){
59 spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false,
60 filters);
61 }
62 spatialQuery.execute();
63
64 SeRow row;
65 int lCount;
66 for (lCount = 0; (row =spatialQuery.fetch()) != null; lCount++) {
67 // one time execution
68 if (lCount == 0) {
69 // analyze cols of result set
70 SeColumnDefinition[] lCols = row.getColumns();
71
72 }
73 short lNumCols = row.getNumColumns();
74
75 for (int i = 0; i < lNumCols; i++) {
76 System.out.println(row.getObject(i));
77 }
78
79 }
80 spatialQuery.close();
81 return true;
82 } catch (Exception e){
83 e.printStackTrace();
84 return false;
85 }
86
87 }
88
89
90 /**
91 * @param args
92 */
93 public static void main(String[] args) {
94
95 try {
96
97 String[] layerNames = new String[] { "MEDIAN.TRACK" };
98 String spatialColumnName = "SHAPE";
99 String where = "MEDIAN.TRACK.CRUISEID = 47";
100 String[] returnFields = new String[] { "MEDIAN.TRACK.TRACKID KEY",
101 "to_char(STARTDATE,'DD.MM.YYYY HH24:MI') || ' - '|| to_char(ENDDATE,'DD.MM.YYYY HH24:MI') || ' - '|| NAME VALUE",
102 "NAME" };
103 String byClause = "ORDER BY STARTDATE, ENDDATE, NAME";
104 SDEPoint[] g = new SDEPoint[5];
105 g[0] = new SDEPoint(52, 8);
106 g[1] = new SDEPoint(52, 9);
107 g[2] = new SDEPoint(53, 9);
108 g[3] = new SDEPoint(53, 8);
109 g[4] = new SDEPoint(52, 8);
110
111 String server = "";
112 String port = "";
113 String database = "";
114 String username = "";
115 String credentials = "";
116
117 SeConnection con = new SeConnection(server, port,
118 database, username,
119 credentials);
120 boolean success = new ToCharSample().executeQuery(con, layerNames, spatialColumnName,
121 where, g, returnFields, byClause);
122
123 if (success){
124 System.out.println("Terminated successful.");
125 }else{
126 System.out.println("Terminated with an Exception.");
127 }
128 } catch (SeException e) {
129 e.printStackTrace();
130 }
131 }
132 }

http://dive4elements.wald.intevation.org