Revision 10942 branches/v10/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
 */
......
57 57
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
58 58

  
59 59
public class testSDE {
60
    public static void main(String[] args) 
61
    { 
60
    public static void main(String[] args)
61
    {
62 62
        // Conexi?n:
63 63
        SeConnection conn = null;
64
        String server     = "alvaro";
64
        String server     = "192.168.0.114";
65 65
        int instance      = 5151;
66
        String database   = "sigespa";
66
        String database   = "ProvinciasPruebas";
67 67
        String user       = "sde";
68
        String password   = "sde";
68
        String password   = "iver";
69 69
        try {
70
            conn = new SeConnection(server, instance, database, user, password); 
70
            conn = new SeConnection(server, instance, database, user, password);
71 71
        }catch (SeException e) {
72 72
            e.printStackTrace();
73 73
            return;
74
        }        
75
        
74
        }
75

  
76 76
        // Fetching data
77 77

  
78
        String layerName = "vias";
78
        String layerName = "EJES";
79 79
        SeObjectId layerID = null;
80 80
        String strSpatialColumn = "";
81 81
        try {
......
83 83
            for (int i=0; i < theLayers.size(); i++)
84 84
            {
85 85
                SeLayer layer = (SeLayer)theLayers.elementAt(i);
86
                if (layer.getName().compareToIgnoreCase(layerName) == 0 );
87
                {
86
                if (layer.getName().equals(layerName)){
88 87
                    layerID = layer.getID();
89 88
                    strSpatialColumn = layer.getSpatialColumn();
90
                    
89
                    System.err.println("Nombre de la capa= " + layer.getName());
90
                    for (int k=0;k<layerID.longValue();k++){
91
                    	layer.getAccess();
92
                    	layer.getQualifiedName();
93
                    	layer.getArraySize();
94
                    	layer.getDescription();
95
                    	layer.getInfo();
96
                    	layer.getShapeTypes();
97
//                    	try{
98
                    		System.err.println("Nombre campo= " + layerID.longValue());
99
//                    	} catch( SeException e ) {
100
//                    		//System.out.println(e.getSeError().getErrDesc());
101
//                    	}
102
                    }
91 103
                }
92 104
            }
93 105
            if (layerID == null)
......
95 107
                System.err.println("Capa no encontrada");
96 108
                return;
97 109
            }
98
            
110

  
99 111
            SeLayer layer = new SeLayer( conn, layerName, strSpatialColumn );
100 112
            SeSqlConstruct sqlConstruct = new SeSqlConstruct( layerName);
101 113
            long t1 = System.currentTimeMillis();
102 114
    //      Create a query stream between the client and server
103 115
            String[] cols = new String[2];
104
            cols[0] = new String("RD_5");
105
            cols[1] = layer.getSpatialColumn();        
116
            cols[0] = new String("FID");
117
            cols[1] = layer.getSpatialColumn();
106 118
            SeQuery query = new SeQuery( conn, cols, sqlConstruct );
107 119
            query.prepareQuery();
108 120
            query.execute();
109 121
            long t2 = System.currentTimeMillis();
110
    
122

  
111 123
            System.out.println("Tiempo de consulta:" + (t2 - t1) + " milisegundos");
112 124
            t1 = System.currentTimeMillis();
113 125
            int cont = 0;
114 126
            SeRow row = query.fetch();
115 127
            if( row == null ) {
116
                
128

  
117 129
                System.out.println(" No rows fetched");
118 130
                return;
119 131
            }
120 132
            // String rowID = "2";
121
            
133

  
122 134
            // Get the definitions of all the columns retrieved
123 135
            SeColumnDefinition[] colDefs = row.getColumns();
124 136
            while (row != null)
......
128 140
                cont++;
129 141
            }
130 142
            // Close the query.
131
    
143

  
132 144
            query.close();
133 145
            t2 = System.currentTimeMillis();
134 146

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

  
137
            /* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct );                       
138
            SeQueryInfo queryInfo = new SeQueryInfo();            
149
            /* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct );
150
            SeQueryInfo queryInfo = new SeQueryInfo();
139 151
            queryInfo.setConstruct(sqlConstruct);
140 152
            // queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_JFA);
141 153
            // query.prepareQueryInfo(queryInfo);
142
 
154

  
143 155
            SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo);
144 156
            extentQuery.close();
145 157
            System.out.println(seExtent.toString());
146
            
147
            
158

  
159

  
148 160
            SeQuery queryAux;
149 161
            t1 = System.currentTimeMillis();
150
            // queryAux = new SeQuery( conn, cols, sqlConstruct );            
162
            // queryAux = new SeQuery( conn, cols, sqlConstruct );
151 163
            for (int i=0; i < 250; i++)
152 164
            {
153 165
                queryAux = new SeQuery( conn, cols, sqlConstruct );
154 166
                SeObjectId rowID = new SeObjectId(i+1);
155 167
                row = queryAux.fetchRow("provin", rowID, cols);
156
                
168

  
157 169
                evaluateRow(row, colDefs);
158 170
                queryAux.close();
159 171
            }
160 172
            // queryAux.close();
161 173
            t2 = System.currentTimeMillis();
162 174
            System.out.println("Tiempo de recorrido:"  + (t2 - t1) + " milisegundos. "); */
163
            
175

  
164 176
            /* queryAux = new SeQuery( conn, cols, sqlConstruct );
165 177
            SeObjectId rowID = new SeObjectId(1);
166
            row = queryAux.fetchRow("provin", rowID, cols);            
178
            row = queryAux.fetchRow("provin", rowID, cols);
167 179
            evaluateRow(row, colDefs);
168
            row = queryAux.fetch();            
180
            row = queryAux.fetch();
169 181
            evaluateRow(row, colDefs);
170
            
182

  
171 183
            queryAux.close(); */
172
            
184

  
173 185
        } catch( SeException e ) {
174 186
            System.out.println(e.getSeError().getErrDesc());
175 187
        }
176 188

  
177
        
189

  
178 190
    }
179 191

  
180 192
    static GeneralPathX convertSeShapeToGeneralPathX(SeShape spVal) throws SeException
......
186 198
        for( int partNo = 0 ; partNo < points.length ; partNo++)
187 199
        {
188 200
            bStartPart = true;
189
            for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++) 
201
            for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++)
190 202
                for( int pointNo = 0 ; pointNo < points[partNo][subPartNo].length ; pointNo+=2)
191 203
                {
192 204
                    if (bStartPart)
......
200 212
                                points[partNo][subPartNo][(pointNo+1)]);
201 213

  
202 214
                }
203
        }  
215
        }
204 216
        return gpx;
205 217
    }
206 218
    static void evaluateRow(SeRow row, SeColumnDefinition[] colDefs)
......
208 220
        try
209 221
        {
210 222
            for (int colNum = 0; colNum < colDefs.length; colNum++)
211
            {                
223
            {
212 224
                SeColumnDefinition colDef = colDefs[colNum];
213 225
                int dataType = colDef.getType();
214 226
                if ( row.getIndicator((short)colNum) != SeRow.SE_IS_NULL_VALUE)
......
217 229
                    {
218 230
                        case SeColumnDefinition.TYPE_SMALLINT:
219 231
                            break;
220
                            
232

  
221 233
                        case SeColumnDefinition.TYPE_DATE:
222 234
                            break;
223
                            
235

  
224 236
                        case SeColumnDefinition.TYPE_INTEGER:
225 237
                            break;
226
                                                        
238

  
227 239
                        case SeColumnDefinition.TYPE_FLOAT:
228 240
                            break;
229
                            
241

  
230 242
                        case SeColumnDefinition.TYPE_DOUBLE:
231 243
                            break;
232
                            
244

  
233 245
                        case SeColumnDefinition.TYPE_STRING:
234 246
                            // System.out.println(row.getString(colNum));
235 247
                            break;
236
                            
248

  
237 249
                        case SeColumnDefinition.TYPE_SHAPE:
238 250
                            SeShape spVal = row.getShape(colNum);
239 251
                            convertSeShapeToGeneralPathX(spVal);

Also available in: Unified diff