Revision 11193 trunk/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/testSDE.java

View differences:

testSDE.java
2 2
 * Created on 13-may-2005
3 3
 *
4 4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 * 
5
 *
6 6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 * 
7
 *
8 8
 * This program is free software; you can redistribute it and/or
9 9
 * modify it under the terms of the GNU General Public License
10 10
 * as published by the Free Software Foundation; either version 2
11 11
 * of the License, or (at your option) any later version.
12
 *  
12
 *
13 13
 * This program is distributed in the hope that it will be useful,
14 14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
 * GNU General Public License for more details.
17
 * 
17
 *
18 18
 * You should have received a copy of the GNU General Public License
19 19
 * along with this program; if not, write to the Free Software
20 20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *  
21
 *
22 22
 * For more information, contact:
23 23
 *
24 24
 *  Generalitat Valenciana
......
30 30
 *      +34 963862235
31 31
 *   gvsig@gva.es
32 32
 *      www.gvsig.gva.es
33
 * 
33
 *
34 34
 *    or
35
 * 
35
 *
36 36
 *   IVER T.I. S.A
37 37
 *   Salamanca 50
38 38
 *   46005 Valencia
39 39
 *   Spain
40
 * 
40
 *
41 41
 *   +34 963163400
42 42
 *   dac@iver.es
43 43
 */
......
56 56
import com.esri.sde.sdk.client.SeSqlConstruct;
57 57
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
58 58

  
59

  
60
/**
61
 * DOCUMENT ME!
62
 *
63
 * @author Vicente Caballero Navarro
64
 */
59 65
public class testSDE {
60
    public static void main(String[] args) 
61
    { 
66
    /**
67
     * DOCUMENT ME!
68
     *
69
     * @param args DOCUMENT ME!
70
     */
71
    public static void main(String[] args) {
62 72
        // Conexi?n:
63 73
        SeConnection conn = null;
64
        String server     = "alvaro";
65
        int instance      = 5151;
66
        String database   = "sigespa";
67
        String user       = "sde";
68
        String password   = "sde";
74
        String server = "192.168.0.114";
75
        int instance = 5151;
76
        String database = "ProvinciasPruebas";
77
        String user = "sde";
78
        String password = "iver";
79

  
69 80
        try {
70
            conn = new SeConnection(server, instance, database, user, password); 
71
        }catch (SeException e) {
81
            conn = new SeConnection(server, instance, database, user, password);
82
        } catch (SeException e) {
72 83
            e.printStackTrace();
84

  
73 85
            return;
74
        }        
75
        
86
        }
87

  
76 88
        // Fetching data
77

  
78
        String layerName = "vias";
89
        String layerName = "EJES";
79 90
        SeObjectId layerID = null;
80 91
        String strSpatialColumn = "";
92

  
81 93
        try {
82 94
            Vector theLayers = conn.getLayers();
83
            for (int i=0; i < theLayers.size(); i++)
84
            {
85
                SeLayer layer = (SeLayer)theLayers.elementAt(i);
86
                if (layer.getName().compareToIgnoreCase(layerName) == 0 );
87
                {
95

  
96
            for (int i = 0; i < theLayers.size(); i++) {
97
                SeLayer layer = (SeLayer) theLayers.elementAt(i);
98

  
99
                if (layer.getName().equals(layerName)) {
88 100
                    layerID = layer.getID();
89 101
                    strSpatialColumn = layer.getSpatialColumn();
90
                    
102
                    System.err.println("Nombre de la capa= " + layer.getName());
103

  
104
                    for (int k = 0; k < layerID.longValue(); k++) {
105
                        layer.getAccess();
106
                        layer.getQualifiedName();
107
                        layer.getArraySize();
108
                        layer.getDescription();
109
                        layer.getInfo();
110
                        layer.getShapeTypes();
111

  
112
                        //                    	try{
113
                        System.err.println("Nombre campo= " +
114
                            layerID.longValue());
115

  
116
                        //                    	} catch( SeException e ) {
117
                        //                    		//System.out.println(e.getSeError().getErrDesc());
118
                        //                    	}
119
                    }
91 120
                }
92 121
            }
93
            if (layerID == null)
94
            {
122

  
123
            if (layerID == null) {
95 124
                System.err.println("Capa no encontrada");
125

  
96 126
                return;
97 127
            }
98
            
99
            SeLayer layer = new SeLayer( conn, layerName, strSpatialColumn );
100
            SeSqlConstruct sqlConstruct = new SeSqlConstruct( layerName);
128

  
129
            SeLayer layer = new SeLayer(conn, layerName, strSpatialColumn);
130
            SeSqlConstruct sqlConstruct = new SeSqlConstruct(layerName);
101 131
            long t1 = System.currentTimeMillis();
102
    //      Create a query stream between the client and server
132

  
133
            //      Create a query stream between the client and server
103 134
            String[] cols = new String[2];
104
            cols[0] = new String("RD_5");
105
            cols[1] = layer.getSpatialColumn();        
106
            SeQuery query = new SeQuery( conn, cols, sqlConstruct );
135
            cols[0] = new String("FID");
136
            cols[1] = layer.getSpatialColumn();
137

  
138
            SeQuery query = new SeQuery(conn, cols, sqlConstruct);
107 139
            query.prepareQuery();
108 140
            query.execute();
141

  
109 142
            long t2 = System.currentTimeMillis();
110
    
111
            System.out.println("Tiempo de consulta:" + (t2 - t1) + " milisegundos");
143

  
144
            System.out.println("Tiempo de consulta:" + (t2 - t1) +
145
                " milisegundos");
112 146
            t1 = System.currentTimeMillis();
147

  
113 148
            int cont = 0;
114 149
            SeRow row = query.fetch();
115
            if( row == null ) {
116
                
150

  
151
            if (row == null) {
117 152
                System.out.println(" No rows fetched");
153

  
118 154
                return;
119 155
            }
156

  
120 157
            // String rowID = "2";
121
            
122 158
            // Get the definitions of all the columns retrieved
123 159
            SeColumnDefinition[] colDefs = row.getColumns();
124
            while (row != null)
125
            {
160

  
161
            while (row != null) {
126 162
                evaluateRow(row, colDefs);
127 163
                row = query.fetch();
128 164
                cont++;
129 165
            }
166

  
130 167
            // Close the query.
131
    
132 168
            query.close();
133 169
            t2 = System.currentTimeMillis();
134 170

  
135
            System.out.println("Tiempo de recorrido:"  + (t2 - t1) + " milisegundos. " + cont + " registros.");
171
            System.out.println("Tiempo de recorrido:" + (t2 - t1) +
172
                " milisegundos. " + cont + " registros.");
136 173

  
137
            /* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct );                       
138
            SeQueryInfo queryInfo = new SeQueryInfo();            
174
            /* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct );
175
            SeQueryInfo queryInfo = new SeQueryInfo();
139 176
            queryInfo.setConstruct(sqlConstruct);
140 177
            // queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_JFA);
141 178
            // query.prepareQueryInfo(queryInfo);
142
 
179

  
143 180
            SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo);
144 181
            extentQuery.close();
145 182
            System.out.println(seExtent.toString());
146
            
147
            
183

  
184

  
148 185
            SeQuery queryAux;
149 186
            t1 = System.currentTimeMillis();
150
            // queryAux = new SeQuery( conn, cols, sqlConstruct );            
187
            // queryAux = new SeQuery( conn, cols, sqlConstruct );
151 188
            for (int i=0; i < 250; i++)
152 189
            {
153 190
                queryAux = new SeQuery( conn, cols, sqlConstruct );
154 191
                SeObjectId rowID = new SeObjectId(i+1);
155 192
                row = queryAux.fetchRow("provin", rowID, cols);
156
                
193

  
157 194
                evaluateRow(row, colDefs);
158 195
                queryAux.close();
159 196
            }
160 197
            // queryAux.close();
161 198
            t2 = System.currentTimeMillis();
162 199
            System.out.println("Tiempo de recorrido:"  + (t2 - t1) + " milisegundos. "); */
163
            
164 200
            /* queryAux = new SeQuery( conn, cols, sqlConstruct );
165 201
            SeObjectId rowID = new SeObjectId(1);
166
            row = queryAux.fetchRow("provin", rowID, cols);            
202
            row = queryAux.fetchRow("provin", rowID, cols);
167 203
            evaluateRow(row, colDefs);
168
            row = queryAux.fetch();            
204
            row = queryAux.fetch();
169 205
            evaluateRow(row, colDefs);
170
            
206

  
171 207
            queryAux.close(); */
172
            
173
        } catch( SeException e ) {
208
        } catch (SeException e) {
174 209
            System.out.println(e.getSeError().getErrDesc());
175 210
        }
176

  
177
        
178 211
    }
179 212

  
180
    static GeneralPathX convertSeShapeToGeneralPathX(SeShape spVal) throws SeException
181
    {
213
    static GeneralPathX convertSeShapeToGeneralPathX(SeShape spVal)
214
        throws SeException {
182 215
        double[][][] points = spVal.getAllCoords();
183 216
        GeneralPathX gpx = new GeneralPathX();
217

  
184 218
        // Display the X and Y values
185 219
        boolean bStartPart;
186
        for( int partNo = 0 ; partNo < points.length ; partNo++)
187
        {
220

  
221
        for (int partNo = 0; partNo < points.length; partNo++) {
188 222
            bStartPart = true;
189
            for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++) 
190
                for( int pointNo = 0 ; pointNo < points[partNo][subPartNo].length ; pointNo+=2)
191
                {
192
                    if (bStartPart)
193
                    {
223

  
224
            for (int subPartNo = 0; subPartNo < points[partNo].length;
225
                    subPartNo++)
226
                for (int pointNo = 0;
227
                        pointNo < points[partNo][subPartNo].length;
228
                        pointNo += 2) {
229
                    if (bStartPart) {
194 230
                        bStartPart = false;
195 231
                        gpx.moveTo(points[partNo][subPartNo][pointNo],
196
                                points[partNo][subPartNo][(pointNo+1)]);
232
                            points[partNo][subPartNo][(pointNo + 1)]);
233
                    } else {
234
                        gpx.lineTo(points[partNo][subPartNo][pointNo],
235
                            points[partNo][subPartNo][(pointNo + 1)]);
197 236
                    }
198
                    else
199
                        gpx.lineTo(points[partNo][subPartNo][pointNo],
200
                                points[partNo][subPartNo][(pointNo+1)]);
237
                }
238
        }
201 239

  
202
                }
203
        }  
204 240
        return gpx;
205 241
    }
206
    static void evaluateRow(SeRow row, SeColumnDefinition[] colDefs)
207
    {
208
        try
209
        {
210
            for (int colNum = 0; colNum < colDefs.length; colNum++)
211
            {                
242

  
243
    static void evaluateRow(SeRow row, SeColumnDefinition[] colDefs) {
244
        try {
245
            for (int colNum = 0; colNum < colDefs.length; colNum++) {
212 246
                SeColumnDefinition colDef = colDefs[colNum];
213 247
                int dataType = colDef.getType();
214
                if ( row.getIndicator((short)colNum) != SeRow.SE_IS_NULL_VALUE)
215
                {
216
                    switch( dataType )
217
                    {
218
                        case SeColumnDefinition.TYPE_SMALLINT:
219
                            break;
220
                            
221
                        case SeColumnDefinition.TYPE_DATE:
222
                            break;
223
                            
224
                        case SeColumnDefinition.TYPE_INTEGER:
225
                            break;
226
                                                        
227
                        case SeColumnDefinition.TYPE_FLOAT:
228
                            break;
229
                            
230
                        case SeColumnDefinition.TYPE_DOUBLE:
231
                            break;
232
                            
233
                        case SeColumnDefinition.TYPE_STRING:
234
                            // System.out.println(row.getString(colNum));
235
                            break;
236
                            
237
                        case SeColumnDefinition.TYPE_SHAPE:
238
                            SeShape spVal = row.getShape(colNum);
239
                            convertSeShapeToGeneralPathX(spVal);
240 248

  
241
                            // GeneralPath gp = spVal.toGeneralPath();
242
                            // GeneralPathX gpx = new GeneralPathX(gp);
243
                            // System.out.println("spVal.FID = " + spVal.getFeatureId().longValue());
244
                            // getShapeDetails(spVal);
245
                            break;
249
                if (row.getIndicator((short) colNum) != SeRow.SE_IS_NULL_VALUE) {
250
                    switch (dataType) {
251
                    case SeColumnDefinition.TYPE_SMALLINT:
252
                        break;
253

  
254
                    case SeColumnDefinition.TYPE_DATE:
255
                        break;
256

  
257
                    case SeColumnDefinition.TYPE_INTEGER:
258
                        break;
259

  
260
                    case SeColumnDefinition.TYPE_FLOAT:
261
                        break;
262

  
263
                    case SeColumnDefinition.TYPE_DOUBLE:
264
                        break;
265

  
266
                    case SeColumnDefinition.TYPE_STRING:
267

  
268
                        // System.out.println(row.getString(colNum));
269
                        break;
270

  
271
                    case SeColumnDefinition.TYPE_SHAPE:
272

  
273
                        SeShape spVal = row.getShape(colNum);
274
                        convertSeShapeToGeneralPathX(spVal);
275

  
276
                        // GeneralPath gp = spVal.toGeneralPath();
277
                        // GeneralPathX gpx = new GeneralPathX(gp);
278
                        // System.out.println("spVal.FID = " + spVal.getFeatureId().longValue());
279
                        // getShapeDetails(spVal);
280
                        break;
246 281
                    } // End switch
247 282
                } // End if
248 283
            } // for
249
        } catch (SeException e)
250
        {
284
        } catch (SeException e) {
251 285
            e.printStackTrace();
252 286
        }
253 287
    }

Also available in: Unified diff