Revision 20802
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEFeatureCollection.java | ||
---|---|---|
119 | 119 |
* @return DOCUMENT ME! |
120 | 120 |
*/ |
121 | 121 |
public int size() { |
122 |
checkModified(); |
|
122 | 123 |
int size = 0; |
123 | 124 |
Iterator iterator = this.iterator(); |
124 | 125 |
size = 0; |
... | ... | |
185 | 186 |
} |
186 | 187 |
} catch (SeException e) { |
187 | 188 |
throw new RuntimeException(e); |
188 |
} |
|
189 |
} catch (ReadException e) { |
|
190 |
throw new RuntimeException(e); |
|
191 |
} |
|
189 | 192 |
SDEIterator dbfIter = new SDEIterator(this.store, this.featureType); |
190 | 193 |
|
191 | 194 |
return dbfIter; |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEFeatureCollectionEditing.java | ||
---|---|---|
157 | 157 |
} |
158 | 158 |
} catch (SeException e) { |
159 | 159 |
throw new RuntimeException(e); |
160 |
} |
|
160 |
} catch (ReadException e) { |
|
161 |
throw new RuntimeException(e); |
|
162 |
} |
|
161 | 163 |
|
162 | 164 |
SDEIterator dbfIter = new SDEIterator(this.store, this.featureType); |
163 | 165 |
|
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEFeaturesWriter.java | ||
---|---|---|
202 | 202 |
/* (non-Javadoc) |
203 | 203 |
* @see org.gvsig.data.datastores.vectorial.IFeaturesWriter#init(org.gvsig.data.vectorial.IFeatureStore) |
204 | 204 |
*/ |
205 |
public void init(IFeatureStore store) { |
|
205 |
public void init(IFeatureStore store) throws InitializeWriterException {
|
|
206 | 206 |
this.store = (SDEStore)store; |
207 |
this.conex = this.store.getConnection(); |
|
207 |
try { |
|
208 |
this.conex = this.store.getWriterConnection(); |
|
209 |
} catch (ReadException e) { |
|
210 |
throw new InitializeWriterException(this.getClass().getName(),e); |
|
211 |
} |
|
208 | 212 |
|
209 | 213 |
SDEStore sdeStore = (SDEStore) store; |
210 | 214 |
this.parameters = sdeStore.getParametersSDE(); |
... | ... | |
657 | 661 |
* @throws InitializeWriterException DOCUMENT ME! |
658 | 662 |
* @throws InitializeException DOCUMENT ME! |
659 | 663 |
*/ |
660 |
public static void create(SDEStoreParameters parameters, |
|
661 |
IFeatureType featureType) |
|
662 |
throws InitializeWriterException, InitializeException { |
|
663 |
SeConnection con = SDEUtils.getConnection(parameters.getHost(),parameters.getPort(),parameters.getDb(), |
|
664 |
parameters.getUser(), parameters.getPassw()); |
|
665 |
} |
|
664 |
// public static void create(SDEStoreParameters parameters,
|
|
665 |
// IFeatureType featureType)
|
|
666 |
// throws InitializeWriterException, InitializeException {
|
|
667 |
// SeConnection con = SDEUtils.getConnection(parameters.getHost(),parameters.getPort(),parameters.getDb(),
|
|
668 |
// parameters.getUser(), parameters.getPassw());
|
|
669 |
// }
|
|
666 | 670 |
|
667 | 671 |
protected static String getFliterForIDForPStatement(DBFeatureType fType) { |
668 | 672 |
if (fType.getFieldsId().length != 1) { |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEStoreParameters.java | ||
---|---|---|
88 | 88 |
this.geometryField = geometryColumn; |
89 | 89 |
} |
90 | 90 |
|
91 |
/** |
|
92 |
* DOCUMENT ME! |
|
93 |
* |
|
94 |
* @return DOCUMENT ME! |
|
95 |
*/ |
|
96 |
public String getUrl() { |
|
97 |
return SDEUtils.getSDEUrl(this.getHost(), this.getDb()); |
|
98 |
} |
|
91 |
// /**
|
|
92 |
// * DOCUMENT ME!
|
|
93 |
// *
|
|
94 |
// * @return DOCUMENT ME!
|
|
95 |
// */
|
|
96 |
// public String getUrl() {
|
|
97 |
// return SDEUtils.getSDEUrl(this.getHost(), this.getDb());
|
|
98 |
// }
|
|
99 | 99 |
|
100 | 100 |
/* |
101 | 101 |
* (non-Javadoc) |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEExplorerParameters.java | ||
---|---|---|
44 | 44 |
* |
45 | 45 |
* @return DOCUMENT ME! |
46 | 46 |
*/ |
47 |
public String getUrl() { |
|
48 |
return SDEUtils.getSDEUrl(this.getHost(), this.getDb()); |
|
49 |
} |
|
47 |
// public String getUrl() {
|
|
48 |
// return SDEUtils.getSDEUrl(this.getHost(), this.getDb());
|
|
49 |
// }
|
|
50 | 50 |
|
51 | 51 |
/** |
52 | 52 |
* DOCUMENT ME! |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEResource.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.data.datastores.vectorial.db.sde; |
|
32 |
|
|
33 |
import org.gvsig.data.Resource; |
|
34 |
import org.gvsig.data.exception.CloseException; |
|
35 |
import org.gvsig.data.exception.DataException; |
|
36 |
import org.gvsig.data.exception.InitializeException; |
|
37 |
import org.gvsig.data.exception.OpenException; |
|
38 |
import org.gvsig.data.exception.ReadException; |
|
39 |
import org.gvsig.data.exception.ResourceChangedException; |
|
40 |
|
|
41 |
import com.esri.sde.sdk.client.SeConnection; |
|
42 |
import com.esri.sde.sdk.client.SeException; |
|
43 |
|
|
44 |
/** |
|
45 |
* @author jmvivo |
|
46 |
* |
|
47 |
*/ |
|
48 |
public class SDEResource extends Resource { |
|
49 |
protected SeConnection connection = null; |
|
50 |
|
|
51 |
private String user; |
|
52 |
private String password; |
|
53 |
private String server; |
|
54 |
private String port; |
|
55 |
|
|
56 |
private String database; |
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
/* (non-Javadoc) |
|
61 |
* @see org.gvsig.data.Resource#doDispose() |
|
62 |
*/ |
|
63 |
protected void doDispose() throws DataException { |
|
64 |
this.connection = this.createConnection(); |
|
65 |
this.setOpened(); |
|
66 |
|
|
67 |
} |
|
68 |
|
|
69 |
/* (non-Javadoc) |
|
70 |
* @see org.gvsig.data.Resource#doOpen() |
|
71 |
*/ |
|
72 |
protected boolean doOpen() throws OpenException { |
|
73 |
try { |
|
74 |
this.connection = this.createConnection(); |
|
75 |
} catch (ReadException e) { |
|
76 |
throw new OpenException(this.getName(),e); |
|
77 |
} |
|
78 |
this.setOpened(); |
|
79 |
return true; |
|
80 |
} |
|
81 |
|
|
82 |
SDEResource(SDEStoreParameters params){ |
|
83 |
this.loadParamsData(params); |
|
84 |
} |
|
85 |
|
|
86 |
SDEResource(SDEExplorerParameters params){ |
|
87 |
this.loadParamsData(params); |
|
88 |
} |
|
89 |
|
|
90 |
/* (non-Javadoc) |
|
91 |
* @see org.gvsig.data.Resource#doClose() |
|
92 |
*/ |
|
93 |
protected boolean doClose() throws CloseException { |
|
94 |
try { |
|
95 |
connection.close(); |
|
96 |
} catch (SeException e) { |
|
97 |
throw new CloseException(this.getName(),e); |
|
98 |
} |
|
99 |
return super.doClose(); |
|
100 |
} |
|
101 |
|
|
102 |
protected void loadParamsData(SDEStoreParameters params){ |
|
103 |
this.user = params.getUser(); |
|
104 |
this.password = params.getPassw(); |
|
105 |
this.server=params.getHost(); |
|
106 |
this.port=params.getPort(); |
|
107 |
this.database=params.getDb(); |
|
108 |
} |
|
109 |
|
|
110 |
protected void loadParamsData(SDEExplorerParameters params){ |
|
111 |
this.user = params.getUser(); |
|
112 |
this.password = params.getPassw(); |
|
113 |
this.server=params.getHost(); |
|
114 |
this.port=params.getPort(); |
|
115 |
this.database=params.getDb(); |
|
116 |
} |
|
117 |
|
|
118 |
|
|
119 |
protected SeConnection createConnection() throws ReadException{ |
|
120 |
try { |
|
121 |
return new SeConnection(server, Integer.parseInt(port), database, |
|
122 |
user, password); |
|
123 |
} catch (SeException e) { |
|
124 |
throw new ReadException("SDE Connection", e); |
|
125 |
} catch (Exception e) { |
|
126 |
throw new ReadException("SDE Connection", e); |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
|
|
131 |
/* (non-Javadoc) |
|
132 |
* @see org.gvsig.data.Resource#description() |
|
133 |
*/ |
|
134 |
public String description() { |
|
135 |
return this.getName()+" SDE Connection Resource: server='"+this.getServer()+"' port='"+this.getPort()+"' db='"+this.getDatabase()+"' user='"+this.getUser()+"'"; |
|
136 |
} |
|
137 |
|
|
138 |
/* (non-Javadoc) |
|
139 |
* @see org.gvsig.data.Resource#doChanged() |
|
140 |
*/ |
|
141 |
protected void doChanged() { |
|
142 |
// No Operation |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* @return the password |
|
147 |
*/ |
|
148 |
public String getPassword() { |
|
149 |
return password; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* @param password the password to set |
|
154 |
* @throws InitializeException |
|
155 |
*/ |
|
156 |
public void setPassword(String password) throws InitializeException { |
|
157 |
if (this.getRefencesCount() > 0){ |
|
158 |
throw new InitializeException("Resource in use",this.description()); |
|
159 |
} |
|
160 |
this.password = password; |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* @return the user |
|
165 |
*/ |
|
166 |
public String getUser() { |
|
167 |
return user; |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* @param user the user to set |
|
172 |
* @throws InitializeException |
|
173 |
*/ |
|
174 |
public void setUser(String user) throws InitializeException { |
|
175 |
if (this.getRefencesCount() > 0){ |
|
176 |
throw new InitializeException("Resource in use",this.description()); |
|
177 |
} |
|
178 |
this.user = user; |
|
179 |
} |
|
180 |
|
|
181 |
protected SeConnection getConnection() throws ReadException{ |
|
182 |
this.checkOpen(); |
|
183 |
return this.connection; |
|
184 |
} |
|
185 |
|
|
186 |
protected SeConnection getWriterConnection() throws ReadException{ |
|
187 |
return this.createConnection(); |
|
188 |
} |
|
189 |
|
|
190 |
/* (non-Javadoc) |
|
191 |
* @see org.gvsig.data.Resource#checkChanged() |
|
192 |
*/ |
|
193 |
protected void checkChanged() throws ResourceChangedException { |
|
194 |
// NO Operation |
|
195 |
|
|
196 |
} |
|
197 |
|
|
198 |
public String getDatabase() { |
|
199 |
return database; |
|
200 |
} |
|
201 |
|
|
202 |
public void setDatabase(String database) { |
|
203 |
this.database = database; |
|
204 |
} |
|
205 |
|
|
206 |
public String getPort() { |
|
207 |
return port; |
|
208 |
} |
|
209 |
|
|
210 |
public void setPort(String port) { |
|
211 |
this.port = port; |
|
212 |
} |
|
213 |
|
|
214 |
public String getServer() { |
|
215 |
return server; |
|
216 |
} |
|
217 |
|
|
218 |
public void setServer(String server) { |
|
219 |
this.server = server; |
|
220 |
} |
|
221 |
/* (non-Javadoc) |
|
222 |
* @see org.gvsig.data.Resource#generateKey() |
|
223 |
*/ |
|
224 |
protected String generateKey() { |
|
225 |
return this.getName()+";"+this.getServer()+";"+this.getPort()+";"+this.getDatabase()+";"+this.getUser(); |
|
226 |
} |
|
227 |
|
|
228 |
/* (non-Javadoc) |
|
229 |
* @see org.gvsig.data.Resource#getName() |
|
230 |
*/ |
|
231 |
public String getName() { |
|
232 |
return "sde"; |
|
233 |
} |
|
234 |
|
|
235 |
} |
|
236 |
|
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/Register.java | ||
---|---|---|
47 | 47 |
dm.registerDataStore(SDEStore.DATASTORE_NAME, SDEStore.class, |
48 | 48 |
SDEStoreParameters.class); |
49 | 49 |
|
50 |
dm.registerDataExplorer(SDEExplorer.DATAEXPLORER_NAME, |
|
51 |
SDEExplorer.class, SDEExplorerParameters.class); |
|
50 |
// dm.registerDataExplorer(SDEExplorer.DATAEXPLORER_NAME,
|
|
51 |
// SDEExplorer.class, SDEExplorerParameters.class);
|
|
52 | 52 |
} |
53 | 53 |
} |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEFeatureCollectionEditingFiltered.java | ||
---|---|---|
178 | 178 |
} |
179 | 179 |
} catch (SeException e) { |
180 | 180 |
throw new RuntimeException(e); |
181 |
} |
|
181 |
} catch (ReadException e) { |
|
182 |
throw new RuntimeException(e); |
|
183 |
} |
|
182 | 184 |
|
183 | 185 |
SDEIterator dbfIter = new SDEIterator(this.store, this.featureType, |
184 | 186 |
this.featureManager); |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEStore.java | ||
---|---|---|
29 | 29 |
package org.gvsig.data.datastores.vectorial.db.sde; |
30 | 30 |
|
31 | 31 |
import java.lang.ref.WeakReference; |
32 |
import java.security.KeyException; |
|
32 | 33 |
import java.util.ArrayList; |
33 | 34 |
import java.util.Iterator; |
34 | 35 |
import java.util.List; |
... | ... | |
38 | 39 |
import org.gvsig.data.IDataCollection; |
39 | 40 |
import org.gvsig.data.IDataExplorer; |
40 | 41 |
import org.gvsig.data.IDataStoreParameters; |
42 |
import org.gvsig.data.ResourceManager; |
|
41 | 43 |
import org.gvsig.data.commands.implementation.AttributeCommand; |
42 | 44 |
import org.gvsig.data.commands.implementation.FeatureCommand; |
43 | 45 |
import org.gvsig.data.commands.implementation.UpdateAttributeCommand; |
... | ... | |
46 | 48 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
47 | 49 |
import org.gvsig.data.datastores.vectorial.db.DBStore; |
48 | 50 |
import org.gvsig.data.exception.CloseException; |
51 |
import org.gvsig.data.exception.DataException; |
|
49 | 52 |
import org.gvsig.data.exception.InitializeException; |
50 | 53 |
import org.gvsig.data.exception.InitializeWriterException; |
51 | 54 |
import org.gvsig.data.exception.OpenException; |
... | ... | |
85 | 88 |
*/ |
86 | 89 |
public static String DATASTORE_NAME = "SDEStore"; |
87 | 90 |
protected static Locale ukLocale = new Locale("en", "UK"); // English, UK version |
88 |
protected SeConnection connection = null; |
|
91 |
// protected SeConnection connection = null;
|
|
89 | 92 |
protected String sqlSelectPart; |
90 | 93 |
protected String baseWhereClause = null; |
91 | 94 |
protected String baseOrder = null; |
... | ... | |
93 | 96 |
protected boolean useSqlSource = false; |
94 | 97 |
protected DBFeatureType featureType; |
95 | 98 |
protected IMetadata metadata; |
99 |
protected SDEResource resource; |
|
96 | 100 |
|
97 | 101 |
/* |
98 | 102 |
* (non-Javadoc) |
... | ... | |
244 | 248 |
} |
245 | 249 |
|
246 | 250 |
selectiveWriter.postProcess(); |
251 |
|
|
252 |
this.resource.changed(this); |
|
247 | 253 |
} catch (ReadException e) { |
248 | 254 |
selectiveWriter.cancelProcess(); |
249 | 255 |
throw e; |
... | ... | |
388 | 394 |
*/ |
389 | 395 |
public void init(IDataStoreParameters parameters) |
390 | 396 |
throws InitializeException { |
391 |
super.init(parameters); |
|
392 |
this.initConnection(); |
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
SDEResource tmpResource = new SDEResource((SDEStoreParameters)parameters); |
|
401 |
SDEResource theResource; |
|
402 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
|
403 |
|
|
404 |
try { |
|
405 |
theResource = (SDEResource)resMan.addResource(tmpResource); |
|
406 |
} catch (DataException e1) { |
|
407 |
throw new InitializeException(this.getName(),e1); |
|
408 |
} |
|
409 |
|
|
410 |
super.init(parameters,theResource); |
|
411 |
this.resource=theResource; |
|
393 | 412 |
this.initFeatureType(); |
394 | 413 |
this.initSqlProperties(); |
395 | 414 |
} |
... | ... | |
398 | 417 |
SDEStoreParameters dParams = this.getParametersSDE(); |
399 | 418 |
|
400 | 419 |
try { |
401 |
this.featureType = SDEUtils.getFeatureType(this.connection, dParams);
|
|
420 |
this.featureType = SDEUtils.getFeatureType(this.getConnection(), dParams);
|
|
402 | 421 |
} catch (ReadException e) { |
403 | 422 |
throw new InitializeException(DATASTORE_NAME, e); |
404 | 423 |
} |
... | ... | |
421 | 440 |
} |
422 | 441 |
} |
423 | 442 |
|
424 |
private void initConnection() throws InitializeException { |
|
425 |
SDEStoreParameters dParams = this.getParametersSDE(); |
|
426 |
|
|
427 |
String dburl = dParams.getUrl(); |
|
428 |
String dbuser = dParams.getUser(); |
|
429 |
String dbpass = dParams.getPassw(); |
|
430 |
|
|
431 |
this.connection = SDEUtils.getConnection(dParams.getHost(), |
|
432 |
dParams.getPort(), dParams.getDb(), dbuser, dbpass); |
|
433 |
} |
|
434 |
|
|
435 | 443 |
/* |
436 | 444 |
* (non-Javadoc) |
437 | 445 |
* @see org.gvsig.data.vectorial.IFeatureStore#getDataCollection(org.gvsig.data.vectorial.IFeatureType, java.lang.String, java.lang.String) |
... | ... | |
480 | 488 |
* DOCUMENT ME! |
481 | 489 |
* |
482 | 490 |
* @return DOCUMENT ME! |
491 |
* @throws ReadException |
|
483 | 492 |
*/ |
484 |
protected SeConnection getConnection() { |
|
485 |
// FIXME: OJO REsource manager |
|
486 |
return this.connection; |
|
493 |
protected SeConnection getConnection() throws ReadException { |
|
494 |
return this.resource.getConnection(); |
|
487 | 495 |
} |
488 | 496 |
|
489 |
SeConnection getCurrentConnection() { |
|
490 |
return this.getConnection(); |
|
491 |
} |
|
492 | 497 |
|
498 |
|
|
493 | 499 |
private void initSqlProperties() throws InitializeException { |
494 | 500 |
SDEStoreParameters dParams = (SDEStoreParameters) this.getParameters(); |
495 | 501 |
|
... | ... | |
564 | 570 |
* @see org.gvsig.data.IDataStore#getExplorer() |
565 | 571 |
*/ |
566 | 572 |
public IDataExplorer getExplorer() throws ReadException { |
567 |
DataManager dm = DataManager.getManager(); |
|
568 |
SDEExplorerParameters explorerParams = (SDEExplorerParameters) dm.createDataExplorerParameters(SDEExplorer.DATAEXPLORER_NAME); |
|
569 |
explorerParams.loadFromStoreParameters(this.getParametersSDE()); |
|
570 |
|
|
571 |
return dm.createDataExplorer(explorerParams); |
|
573 |
// TODO No implementado |
|
574 |
return null; |
|
575 |
// DataManager dm = DataManager.getManager(); |
|
576 |
// SDEExplorerParameters explorerParams = (SDEExplorerParameters) dm.createDataExplorerParameters(SDEExplorer.DATAEXPLORER_NAME); |
|
577 |
// explorerParams.loadFromStoreParameters(this.getParametersSDE()); |
|
578 |
// |
|
579 |
// return dm.createDataExplorer(explorerParams); |
|
572 | 580 |
} |
573 | 581 |
|
574 | 582 |
static String getConnectionResourceID(String dbUrl, String dbUser) { |
... | ... | |
603 | 611 |
* @see org.gvsig.data.vectorial.FeatureStore#doClose() |
604 | 612 |
*/ |
605 | 613 |
protected void doClose() throws CloseException { |
606 |
// FIXME: Resource Manager |
|
607 |
try { |
|
608 |
connection.close(); |
|
609 |
} catch (SeException e) { |
|
610 |
throw new CloseException(this.getClass().getName(), e); |
|
611 |
} |
|
614 |
resource.close(); |
|
612 | 615 |
} |
613 | 616 |
|
614 | 617 |
/* |
... | ... | |
616 | 619 |
* @see org.gvsig.data.vectorial.FeatureStore#doDispose() |
617 | 620 |
*/ |
618 | 621 |
protected void doDispose() throws CloseException { |
619 |
super.doDispose(); |
|
620 |
|
|
621 |
//TODO: FALTA!!! |
|
622 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
|
623 |
try { |
|
624 |
resMan.remove(this.resource); |
|
625 |
} catch (DataException e1) { |
|
626 |
throw new CloseException(this.getName(),e1); |
|
627 |
} catch (KeyException e) { |
|
628 |
throw new CloseException(this.getName(),e); |
|
629 |
} |
|
630 |
this.featureType = null; |
|
631 |
this.metadata = null; |
|
632 |
super.doDispose(); |
|
622 | 633 |
} |
623 | 634 |
|
624 | 635 |
/* |
... | ... | |
680 | 691 |
throw new ReadException(this.getClass().getName(), e); |
681 | 692 |
} |
682 | 693 |
} |
694 |
|
|
695 |
public SeConnection getWriterConnection() throws ReadException { |
|
696 |
return this.resource.getWriterConnection(); |
|
697 |
} |
|
683 | 698 |
} |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEExplorer.java | ||
---|---|---|
35 | 35 |
import org.gvsig.data.IDataExplorerParameters; |
36 | 36 |
import org.gvsig.data.IDataStoreParameters; |
37 | 37 |
import org.gvsig.data.INewDataStoreParameters; |
38 |
import org.gvsig.data.ResourceManager; |
|
38 | 39 |
import org.gvsig.data.datastores.vectorial.db.DBExplorer; |
39 | 40 |
import org.gvsig.data.datastores.vectorial.db.DBParameters; |
41 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2ExplorerParameters; |
|
42 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2Resource; |
|
43 |
import org.gvsig.data.exception.DataException; |
|
40 | 44 |
import org.gvsig.data.exception.InitializeException; |
41 | 45 |
import org.gvsig.data.exception.InitializeWriterException; |
42 | 46 |
import org.gvsig.data.exception.ReadException; |
... | ... | |
60 | 64 |
public static String DATAEXPLORER_NAME = "SDEExplorer"; |
61 | 65 |
private SDEExplorerParameters parameters; |
62 | 66 |
private String defaultSchema; |
63 |
|
|
67 |
private SDEResource resource; |
|
64 | 68 |
/** |
65 | 69 |
* DOCUMENT ME! |
66 | 70 |
* |
... | ... | |
68 | 72 |
* |
69 | 73 |
* @throws InitializeException DOCUMENT ME! |
70 | 74 |
*/ |
71 |
protected SeConnection getConnection() throws InitializeException { |
|
72 |
String host = parameters.getHost(); |
|
73 |
String port = parameters.getPort(); |
|
74 |
String db = parameters.getDb(); |
|
75 |
String dbuser = parameters.getUser(); |
|
76 |
String dbpass = parameters.getPassw(); |
|
75 |
protected SeConnection getConnection() throws ReadException { |
|
77 | 76 |
|
78 |
return SDEUtils.getConnection(host, port, db, dbuser, dbpass); |
|
77 |
return this.resource.getConnection();//SDEUtils.getConnection(host, port, db, dbuser, dbpass);
|
|
79 | 78 |
} |
80 | 79 |
|
81 | 80 |
/** |
... | ... | |
90 | 89 |
*/ |
91 | 90 |
public IDataStoreParameters add(INewFeatureStoreParameters ndsp) |
92 | 91 |
throws InitializeException, InitializeWriterException { |
93 |
SeConnection conn = this.getConnection(); |
|
92 |
SeConnection conn; |
|
93 |
try { |
|
94 |
conn = this.getConnection(); |
|
95 |
} catch (ReadException e) { |
|
96 |
throw new InitializeException(DATAEXPLORER_NAME,e); |
|
97 |
} |
|
94 | 98 |
|
95 | 99 |
// try { |
96 | 100 |
// conn.setAutoCommit(true); |
... | ... | |
270 | 274 |
*/ |
271 | 275 |
public void init(IDataExplorerParameters parameters) |
272 | 276 |
throws InitializeException { |
273 |
this.parameters = (SDEExplorerParameters) parameters; |
|
277 |
SDEResource tmpResource = new SDEResource((SDEExplorerParameters)parameters); |
|
278 |
SDEResource theResource; |
|
279 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
|
274 | 280 |
|
275 |
// this.defaultSchema = SDEUtils.getDefaultSchema(this.getConnection(), this.parameters.getCatalog()); |
|
276 |
} |
|
281 |
try { |
|
282 |
theResource = (SDEResource)resMan.addResource(tmpResource); |
|
283 |
} catch (DataException e1) { |
|
284 |
throw new InitializeException(this.getName(),e1); |
|
285 |
} |
|
286 |
this.parameters = (SDEExplorerParameters) parameters; |
|
287 |
this.resource=theResource; |
|
288 |
} |
|
277 | 289 |
|
278 | 290 |
private SDEStoreParameters newStoreParamters() { |
279 | 291 |
DataManager manager = DataManager.getManager(); |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/sde/SDEUtils.java | ||
---|---|---|
149 | 149 |
return SDEStore.CONNECTION_STRING + ";" + dbUrl + ";" + dbUser; |
150 | 150 |
} |
151 | 151 |
|
152 |
static String getSDEUrl(String host, String db) { |
|
153 |
String url; |
|
154 |
url = "esri:sde:tcp://" + host; |
|
155 |
|
|
156 |
if ((db == null) || (db == "")) { |
|
157 |
url = url + "/default"; |
|
158 |
} else { |
|
159 |
url = url + "/" + db; |
|
160 |
} |
|
161 |
|
|
162 |
return url; |
|
163 |
} |
|
164 |
|
|
165 |
static SeConnection getConnection(String server, String port, |
|
166 |
String database, String dbUser, String dbPass) |
|
167 |
throws InitializeException { |
|
168 |
try { |
|
169 |
return new SeConnection(server, Integer.parseInt(port), database, |
|
170 |
dbUser, dbPass); |
|
171 |
} catch (SeException e) { |
|
172 |
throw new InitializeException("SDE Connection", e); |
|
173 |
} catch (Exception e) { |
|
174 |
throw new InitializeException("SDE Connection", e); |
|
175 |
} |
|
176 |
} |
|
152 |
// static String getSDEUrl(String host, String db) { |
|
153 |
// String url; |
|
154 |
// url = "esri:sde:tcp://" + host; |
|
155 |
// |
|
156 |
// if ((db == null) || (db == "")) { |
|
157 |
// url = url + "/default"; |
|
158 |
// } else { |
|
159 |
// url = url + "/" + db; |
|
160 |
// } |
|
161 |
// |
|
162 |
// return url; |
|
163 |
// } |
|
177 | 164 |
} |
trunk/libraries/libFMap_dataDB/src-test/org/gvsig/data/datastores/vectorial/db/sde/SDETest.java | ||
---|---|---|
4 | 4 |
import java.util.NoSuchElementException; |
5 | 5 |
|
6 | 6 |
import org.gvsig.data.DataManager; |
7 |
import org.gvsig.data.IDataCollection; |
|
7 | 8 |
import org.gvsig.data.IDataStoreParameters; |
9 |
import org.gvsig.data.Resource; |
|
10 |
import org.gvsig.data.ResourceManager; |
|
8 | 11 |
import org.gvsig.data.datastores.vectorial.db.DBTest; |
12 |
import org.gvsig.data.datastores.vectorial.file.FileResource; |
|
9 | 13 |
import org.gvsig.data.exception.CloseException; |
10 | 14 |
import org.gvsig.data.exception.DataException; |
11 | 15 |
import org.gvsig.data.exception.InitializeException; |
... | ... | |
13 | 17 |
import org.gvsig.data.exception.ReadException; |
14 | 18 |
import org.gvsig.data.exception.WriteException; |
15 | 19 |
import org.gvsig.data.vectorial.Feature; |
20 |
import org.gvsig.data.vectorial.FeatureStore; |
|
16 | 21 |
import org.gvsig.data.vectorial.IFeature; |
17 | 22 |
import org.gvsig.data.vectorial.IFeatureCollection; |
18 | 23 |
import org.gvsig.data.vectorial.IFeatureStore; |
19 | 24 |
import org.gvsig.data.vectorial.IFeatureType; |
20 | 25 |
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor; |
21 | 26 |
import org.gvsig.exceptions.BaseException; |
27 |
import org.gvsig.util.observer.IObserver; |
|
22 | 28 |
|
29 |
import com.esri.sde.sdk.client.SDEPoint; |
|
23 | 30 |
import com.esri.sde.sdk.client.SeConnection; |
24 | 31 |
|
25 | 32 |
public class SDETest extends DBTest { |
... | ... | |
84 | 91 |
|
85 | 92 |
storeTest(dparam, null, null, false); |
86 | 93 |
|
94 |
|
|
95 |
|
|
87 | 96 |
} |
88 | 97 |
|
89 | 98 |
protected void storeTest(IDataStoreParameters dp, String filter, String order, boolean testEdit) { |
... | ... | |
343 | 352 |
fail("Exception:" + e); |
344 | 353 |
} |
345 | 354 |
|
355 |
try{ |
|
356 |
fs.dispose(); |
|
357 |
}catch (Exception e) { |
|
358 |
e.printStackTrace(); |
|
359 |
fail("Exception:" + e); |
|
360 |
} |
|
361 |
|
|
346 | 362 |
} |
347 | 363 |
|
348 | 364 |
public void test2(){ |
... | ... | |
855 | 871 |
fail("Exception:" + e); |
856 | 872 |
} |
857 | 873 |
|
874 |
try { |
|
875 |
fs.dispose(); |
|
876 |
} catch (CloseException e) { |
|
877 |
e.printStackTrace();fail(); |
|
878 |
} |
|
858 | 879 |
|
880 |
testResources(dparam); |
|
859 | 881 |
|
860 | 882 |
} |
861 | 883 |
|
862 | 884 |
|
885 |
public void testResources(SDEStoreParameters params){ |
|
886 |
DataManager manager = DataManager.getManager(); |
|
887 |
|
|
888 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
|
889 |
|
|
890 |
FeatureStore store=null; |
|
891 |
FeatureStore store2=null; |
|
892 |
FeatureStore store3=null; |
|
893 |
try { |
|
894 |
store = (FeatureStore)manager.createDataStore(params); |
|
895 |
store2 = (FeatureStore)manager.createDataStore(params); |
|
896 |
store3 = (FeatureStore)manager.createDataStore(params); |
|
897 |
} catch (InitializeException e1) { |
|
898 |
e1.printStackTrace();fail(); |
|
899 |
} |
|
900 |
|
|
901 |
int i=0; |
|
902 |
Resource res = null; |
|
903 |
Resource tmpRes = null; |
|
904 |
Object obj = null; |
|
905 |
|
|
906 |
Iterator iter = resMan.iterator(); |
|
907 |
while (iter.hasNext()){ |
|
908 |
obj = iter.next(); |
|
909 |
if (obj instanceof SDEResource){ |
|
910 |
tmpRes = (Resource)obj; |
|
911 |
if (isTheSame((SDEResource)tmpRes,params)){ |
|
912 |
i++; |
|
913 |
res=tmpRes; |
|
914 |
} |
|
915 |
} |
|
916 |
} |
|
917 |
|
|
918 |
assertEquals(1, i); |
|
919 |
|
|
920 |
assertEquals(3, res.getRefencesCount()); |
|
921 |
|
|
922 |
try { |
|
923 |
store.close(); |
|
924 |
} catch (CloseException e1) { |
|
925 |
e1.printStackTrace();fail(); |
|
926 |
} |
|
927 |
|
|
928 |
assertEquals(false, res.isOpen()); |
|
929 |
|
|
930 |
IDataCollection coll = null; |
|
931 |
|
|
932 |
try { |
|
933 |
coll =store.getDataCollection(); |
|
934 |
} catch (ReadException e1) { |
|
935 |
e1.printStackTrace();fail(); |
|
936 |
} |
|
937 |
|
|
938 |
coll.iterator().next(); |
|
939 |
|
|
940 |
assertEquals(true, res.isOpen()); |
|
941 |
|
|
942 |
coll.dispose(); |
|
943 |
|
|
944 |
|
|
945 |
|
|
946 |
if (store.isEditable()){ |
|
947 |
/*Test edition notification*/ |
|
948 |
|
|
949 |
int fCountOrg=0; |
|
950 |
int fCountFin=0; |
|
951 |
try { |
|
952 |
fCountOrg = store.getDataCollection().size(); |
|
953 |
} catch (ReadException e2) { |
|
954 |
// TODO Auto-generated catch block |
|
955 |
e2.printStackTrace();fail(); |
|
956 |
} |
|
957 |
try { |
|
958 |
store.startEditing(); |
|
959 |
} catch (ReadException e1) { |
|
960 |
e1.printStackTrace();fail(); |
|
961 |
} |
|
962 |
|
|
963 |
try { |
|
964 |
coll = store2.getDataCollection(); |
|
965 |
} catch (ReadException e1) { |
|
966 |
e1.printStackTrace();fail(); |
|
967 |
} |
|
968 |
|
|
969 |
try { |
|
970 |
store.finishEditing(); |
|
971 |
} catch (WriteException e1) { |
|
972 |
e1.printStackTrace();fail(); |
|
973 |
} catch (ReadException e1) { |
|
974 |
// TODO Auto-generated catch block |
|
975 |
e1.printStackTrace();fail(); |
|
976 |
} |
|
977 |
|
|
978 |
try { |
|
979 |
fCountFin = store.getDataCollection().size(); |
|
980 |
} catch (ReadException e2) { |
|
981 |
// TODO Auto-generated catch block |
|
982 |
e2.printStackTrace();fail(); |
|
983 |
} |
|
984 |
|
|
985 |
assertEquals(fCountOrg, fCountFin); |
|
986 |
|
|
987 |
|
|
988 |
boolean isOk = false; |
|
989 |
try{ |
|
990 |
coll.iterator().next(); |
|
991 |
} catch (Exception e){ |
|
992 |
isOk=true; |
|
993 |
} |
|
994 |
assertTrue("Resource Changed Notification fails",isOk); |
|
995 |
|
|
996 |
coll.dispose(); |
|
997 |
|
|
998 |
/*Test edition notification END*/ |
|
999 |
|
|
1000 |
} |
|
1001 |
|
|
1002 |
|
|
1003 |
SDEExplorer explorer = null; |
|
1004 |
try { |
|
1005 |
explorer = (SDEExplorer) store.getExplorer(); |
|
1006 |
} catch (ReadException e) { |
|
1007 |
e.printStackTrace();fail(); |
|
1008 |
} |
|
1009 |
|
|
1010 |
if (explorer != null){ |
|
1011 |
assertEquals(4, res.getRefencesCount()); |
|
1012 |
|
|
1013 |
try { |
|
1014 |
explorer.list(); |
|
1015 |
} catch (ReadException e) { |
|
1016 |
e.printStackTrace();fail(); |
|
1017 |
} |
|
1018 |
|
|
1019 |
try { |
|
1020 |
explorer.dispose(); |
|
1021 |
} catch (DataException e1) { |
|
1022 |
e1.printStackTrace();fail(); |
|
1023 |
} |
|
1024 |
|
|
1025 |
|
|
1026 |
assertEquals(3, res.getRefencesCount()); |
|
1027 |
} |
|
1028 |
try { |
|
1029 |
store3.dispose(); |
|
1030 |
} catch (CloseException e1) { |
|
1031 |
e1.printStackTrace();fail(); |
|
1032 |
} |
|
1033 |
|
|
1034 |
assertEquals(2, res.getRefencesCount()); |
|
1035 |
|
|
1036 |
try { |
|
1037 |
store2.dispose(); |
|
1038 |
} catch (CloseException e1) { |
|
1039 |
e1.printStackTrace();fail(); |
|
1040 |
} |
|
1041 |
|
|
1042 |
assertEquals(1, res.getRefencesCount()); |
|
1043 |
|
|
1044 |
try { |
|
1045 |
store.dispose(); |
|
1046 |
} catch (CloseException e1) { |
|
1047 |
e1.printStackTrace();fail(); |
|
1048 |
} |
|
1049 |
|
|
1050 |
assertEquals(0, res.getRefencesCount()); |
|
1051 |
res = null; |
|
1052 |
|
|
1053 |
i=0; |
|
1054 |
iter = resMan.iterator(); |
|
1055 |
while (iter.hasNext()){ |
|
1056 |
obj = iter.next(); |
|
1057 |
if (obj instanceof SDEResource){ |
|
1058 |
tmpRes = (Resource)obj; |
|
1059 |
if (isTheSame((SDEResource)tmpRes,params)){ |
|
1060 |
i++; |
|
1061 |
res=tmpRes; |
|
1062 |
} |
|
1063 |
} |
|
1064 |
} |
|
1065 |
|
|
1066 |
assertEquals(0, i); |
|
1067 |
|
|
1068 |
doPrepareFileResourceTest(params); |
|
1069 |
|
|
1070 |
} |
|
1071 |
|
|
1072 |
public static boolean isTheSame(SDEResource resource,SDEStoreParameters params){ |
|
1073 |
return resource.getServer().equals(params.getHost()) && |
|
1074 |
resource.getPort().equals(params.getPort()) && |
|
1075 |
resource.getDatabase().equals(params.getDb()) && |
|
1076 |
resource.getUser().equals(params.getUser()); |
|
1077 |
} |
|
1078 |
|
|
1079 |
public void doPrepareFileResourceTest(SDEStoreParameters params){ |
|
1080 |
DataManager manager = DataManager.getManager(); |
|
1081 |
|
|
1082 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
|
1083 |
|
|
1084 |
String passw = params.getPassw(); |
|
1085 |
params.setPassw("--------------"); |
|
1086 |
|
|
1087 |
IObserver obs = new PrepareResourceObserver(params, passw); |
|
1088 |
|
|
1089 |
|
|
1090 |
resMan.addObserver(obs); |
|
1091 |
|
|
1092 |
FeatureStore store=null; |
|
1093 |
try { |
|
1094 |
store = (FeatureStore)manager.createDataStore(params); |
|
1095 |
} catch (InitializeException e1) { |
|
1096 |
e1.printStackTrace();fail(); |
|
1097 |
} catch (Exception e2){ |
|
1098 |
e2.printStackTrace();fail(); |
|
1099 |
} |
|
1100 |
|
|
1101 |
try { |
|
1102 |
store.getDataCollection().iterator().next(); |
|
1103 |
} catch (ReadException e) { |
|
1104 |
// TODO Auto-generated catch block |
|
1105 |
e.printStackTrace();fail(); |
|
1106 |
} |
|
1107 |
|
|
1108 |
try { |
|
1109 |
store.close(); |
|
1110 |
} catch (CloseException e) { |
|
1111 |
// TODO Auto-generated catch block |
|
1112 |
e.printStackTrace();fail(); |
|
1113 |
} |
|
1114 |
try { |
|
1115 |
store.dispose(); |
|
1116 |
} catch (CloseException e) { |
|
1117 |
// TODO Auto-generated catch block |
|
1118 |
e.printStackTrace();fail(); |
|
1119 |
} |
|
1120 |
params.setPassw(passw); |
|
1121 |
|
|
1122 |
} |
|
1123 |
|
|
863 | 1124 |
} |
trunk/libraries/libFMap_dataDB/src-test/org/gvsig/data/datastores/vectorial/db/sde/PrepareResourceObserver.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.data.datastores.vectorial.db.sde; |
|
32 |
|
|
33 |
import org.gvsig.data.IResourceNotification; |
|
34 |
import org.gvsig.data.exception.InitializeException; |
|
35 |
import org.gvsig.util.observer.IObservable; |
|
36 |
import org.gvsig.util.observer.IObserver; |
|
37 |
|
|
38 |
import com.esri.sde.sdk.client.SDEPoint; |
|
39 |
|
|
40 |
/** |
|
41 |
* @author jmvivo |
|
42 |
* |
|
43 |
*/ |
|
44 |
public class PrepareResourceObserver implements IObserver { |
|
45 |
|
|
46 |
private String passw; |
|
47 |
private SDEStoreParameters params; |
|
48 |
|
|
49 |
|
|
50 |
public PrepareResourceObserver(SDEStoreParameters params,String passw){ |
|
51 |
this.params=params; |
|
52 |
this.passw=passw; |
|
53 |
} |
|
54 |
|
|
55 |
public void update(IObservable observable, Object notification) { |
|
56 |
if (!(notification instanceof IResourceNotification)) { |
|
57 |
return; |
|
58 |
} |
|
59 |
IResourceNotification resNot = (IResourceNotification) notification; |
|
60 |
if (!resNot.getType().equals(IResourceNotification.PREPARE)){ |
|
61 |
return; |
|
62 |
} |
|
63 |
SDEResource res = (SDEResource)resNot.getResource(); |
|
64 |
if (SDETest.isTheSame(res,params)){ |
|
65 |
try { |
|
66 |
res.setPassword(passw); |
|
67 |
System.out.println("Prepared: "+res.getKey()+" Password <== "+res.getPassword()); |
|
68 |
} catch (InitializeException e) { |
|
69 |
throw new RuntimeException(e); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
|
Also available in: Unified diff