Revision 29932

View differences:

branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleSetProvider.java
45 45
	public OracleSetProvider(JDBCStoreProvider store, FeatureQuery query,
46 46
			FeatureType featureType) throws DataException {
47 47
		super(store, query, featureType);
48
		// TODO Auto-generated constructor stub
49 48
	}
50 49

  
51 50

  
branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleResource.java
39 39

  
40 40
public class OracleResource extends JDBCResource {
41 41

  
42
	public final static String NAME = "OracleSpatialResource";
43
	public static final String DESCRIPTION = "OracleSpatial Connection";
42
	public final static String NAME = "OracleResource";
43
	public static final String DESCRIPTION = "Oracle Connection";
44 44

  
45 45
	public OracleResource(OracleResourceParameters parameters)
46 46
			throws InitializeException {
......
49 49

  
50 50
	public String getName() throws AccessResourceException {
51 51
		OracleResourceParameters params = (OracleResourceParameters) this.getParameters();
52
		return MessageFormat.format("OracleSpatialResource({0},{1})",
52
		return MessageFormat.format("OracleResource({0},{1})",
53 53
				new Object[] { params.getUrl(),params.getUser() });
54 54
	}
55 55

  
......
68 68

  
69 69
		dataSource.setMaxWait(60L * 1000); // FIXME
70 70

  
71
		// FIXME Set Pool parameters:
72
		/*
73
		dataSource.setMaxActive(maxActive);
74
		dataSource.setMaxIdle(maxActive);
75
		dataSource.setMaxOpenPreparedStatements(maxActive);
76
		dataSource.setMaxWait(maxActive);
77
		dataSource.setInitialSize(initialSize);
78
		dataSource.setDefaultReadOnly(defaultReadOnly);
79
		dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
80
		dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
81
		dataSource.setMinIdle(minIdle);
82
		dataSource.setTestOnBorrow(testOnBorrow);
83
		dataSource.setTestOnReturn(testOnReturn);
84
		dataSource.setTestWhileIdle(testOnReturn);
85
		dataSource
86
			.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
87

  
88
		dataSource.setAccessToUnderlyingConnectionAllowed(allow);
89
		dataSource.setLoginTimeout(seconds);
90
		dataSource.setLogWriter(out);
91
		 */
71
	
92 72
		return dataSource;
93 73
	}
94 74

  
branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleServerExplorer.java
30 30
 */
31 31
package org.gvsig.fmap.dal.store.oracle;
32 32

  
33
import java.awt.geom.Rectangle2D;
33 34
import java.sql.Connection;
34 35
import java.sql.ResultSet;
35 36
import java.sql.SQLException;
......
61 62
import org.slf4j.LoggerFactory;
62 63

  
63 64
/**
65
 * ORACLE SERVER EXPLORER
66
 * 
64 67
 * @author vsanjaime
65 68
 * 
66 69
 */
67 70
public class OracleServerExplorer extends JDBCServerExplorer {
71

  
68 72
	final static private Logger logger = LoggerFactory
69 73
			.getLogger(OracleServerExplorer.class);
70 74

  
71
	public static final String NAME = "OracleSpatialExplorer";
75
	public static final String NAME = "OracleServerExplorer";
72 76

  
73 77
	/**
74 78
	 * Constructor
......
77 81
	 * @param services
78 82
	 * @throws InitializeException
79 83
	 */
80
	public OracleServerExplorer(
81
			OracleServerExplorerParameters parameters,
84
	public OracleServerExplorer(OracleServerExplorerParameters parameters,
82 85
			DataServerExplorerProviderServices services)
83 86
			throws InitializeException {
84 87
		super(parameters, services);
......
103 106
	 */
104 107
	public void remove(DataStoreParameters dsp) throws RemoveException {
105 108

  
106
		// TODO arreglar este metodo para borrar la tabla y los metadatos
107
		final OracleStoreParameters osParams = (OracleStoreParameters) dsp;
109
		final OracleStoreParameters oraParams = (OracleStoreParameters) dsp;
108 110

  
109 111
		TransactionalAction action = new TransactionalAction() {
110 112
			public boolean continueTransactionAllowed() {
......
119 121
				} catch (SQLException e) {
120 122
					throw new JDBCSQLException(e);
121 123
				}
124
				// SQL REMOVE TABLE
125
				String sqlDropTable = "DROP TABLE " + oraParams.tableID()
126
						+ " CASCADE CONSTRAINTS";
122 127

  
123
				String sqlDrop = "DROP TABLE " + osParams.tableID();
128
				// SQL DELETE METADATA
129
				String tname = oraParams.tableID();
130
				String sqlDeleteMetadata = "";
131
				int ind = tname.lastIndexOf(".");
132
				if (ind != -1) {
133
					String schema = tname.substring(0, ind);
134
					tname = tname.substring(ind + 1, tname.length());
135
					sqlDeleteMetadata = "DELETE FROM "
136
							+ OracleValues.USER_ORACLE_GEOMETADATA_VIEW
137
							+ " WHERE TABLE_NAME = '" + tname + "'";
124 138

  
125
				StringBuilder strb = new StringBuilder();
126
				strb
127
						.append("Delete from GEOMETRY_COLUMNS where f_table_schema = ");
128
				if (osParams.getSchema() == null
129
						|| osParams.getSchema().length() == 0) {
130
					strb.append("current_schema() ");
131 139
				} else {
132
					strb.append('\'');
133
					strb.append(osParams.getSchema());
134
					strb.append("' ");
140
					sqlDeleteMetadata = "DELETE FROM "
141
							+ OracleValues.USER_ORACLE_GEOMETADATA_VIEW
142
							+ " WHERE TABLE_NAME = '" + tname + "'";
135 143
				}
136
				strb.append("and f_table_name = '");
137
				strb.append(osParams.getTable());
138
				strb.append('\'');
139 144

  
140
				String sqlDeleteFromGeometry_column = strb.toString();
141 145
				try {
146
					// DROP TABLE
142 147
					try {
143
						st.execute(sqlDrop);
148
						st.execute(sqlDropTable);
144 149
					} catch (SQLException e) {
145
						throw new JDBCExecuteSQLException(sqlDrop, e);
150
						throw new JDBCExecuteSQLException(sqlDropTable, e);
146 151
					}
147

  
152
					// DELETE METADATA
148 153
					try {
149
						st.execute(sqlDeleteFromGeometry_column);
154
						st.execute(sqlDeleteMetadata);
150 155
					} catch (SQLException e) {
151
						throw new JDBCExecuteSQLException(
152
								sqlDeleteFromGeometry_column, e);
156
						throw new JDBCExecuteSQLException(sqlDeleteMetadata, e);
153 157
					}
154 158

  
155 159
				} finally {
......
185 189
		params.setJDBCDriverClassName(parameters.getJDBCDriverClassName());
186 190
		params.setUrl(parameters.getUrl());
187 191
		params.setUseSSL(parameters.getUseSSL());
192
		params.setOraDriverType(parameters.getOraDriverType());
188 193

  
189 194
		params.setDefaultFeatureType(this.getServerExplorerProviderServices()
190 195
				.createNewFeatureType());
......
200 205
	}
201 206

  
202 207
	/**
203
	 * 
208
	 * Get list of table availables in Oracle schema registered in geometry
209
	 * metadata view
204 210
	 */
205
	public List list(final int mode, final boolean showInformationDBTables)
206
			throws DataException {
211
	public List<JDBCStoreParameters> list(final int mode,
212
			final boolean showInformationDBTables) throws DataException {
207 213

  
208 214
		final JDBCStoreParameters orgParams = createStoreParams();
209 215

  
......
212 218
			public Object action(Connection conn) throws DataException {
213 219
				ResultSet rs = null;
214 220
				Statement st = null;
215
				List sqls = getSQLForList(mode, showInformationDBTables);
216 221

  
222
				List<String> sqls = getSQLForList(mode, showInformationDBTables);
223

  
217 224
				try {
218
					JDBCStoreParameters params;
225
					JDBCStoreParameters params = null;
219 226

  
220
					List paramList = new ArrayList();
227
					List<JDBCStoreParameters> paramList = new ArrayList<JDBCStoreParameters>();
221 228

  
222 229
					conn = helper.getConnection();
223 230
					st = conn.createStatement();
224 231
					String sql;
225
					Iterator sqlIter = sqls.iterator();
232
					Iterator<String> sqlIter = sqls.iterator();
226 233
					while (sqlIter.hasNext()) {
227
						sql = (String) sqlIter.next();
234
						sql = sqlIter.next();
228 235
						rs = st.executeQuery(sql);
229 236
						while (rs.next()) {
230 237
							params = (JDBCStoreParameters) orgParams.getCopy();
......
259 266
		}
260 267
	}
261 268

  
269
	/**
270
	 * create new table
271
	 * 
272
	 * @params ndsp
273
	 * @params overwrite
274
	 * @return
275
	 */
262 276
	public boolean add(NewDataStoreParameters ndsp, boolean overwrite)
263 277
			throws DataException {
264 278

  
265 279
		if (!(ndsp instanceof NewFeatureStoreParameters)) {
266 280
			throw new IllegalArgumentException();
267 281
		}
268
		checkIsMine(ndsp);
282
		this.checkIsMine(ndsp);
269 283

  
270 284
		NewFeatureStoreParameters nfdsp = (NewFeatureStoreParameters) ndsp;
271 285

  
272
		StringBuilder sql = new StringBuilder();
286
		// SQL CREATE NEW TABLE
287
		StringBuilder sqlnewtable = new StringBuilder();
273 288

  
274 289
		if (!nfdsp.isValid()) {
275 290
			throw new InitializeException(this.getName(), new Exception(
......
283 298

  
284 299
		FeatureType fType = nfdsp.getDefaultFeatureType();
285 300

  
286
		sql.append("CREATE TABLE " + ((JDBCStoreParameters) ndsp).tableID()
301
		sqlnewtable.append("CREATE TABLE " + ((JDBCStoreParameters) ndsp).tableID()
287 302
				+ "(");
288 303
		Iterator<FeatureAttributeDescriptor> attrs = fType.iterator();
289 304
		String sqlAttr;
......
298 313
			}
299 314
		}
300 315

  
301
		helper.stringJoin(sqlAttrs, ", ", sql);
316
		helper.stringJoin(sqlAttrs, ", ", sqlnewtable);
302 317

  
303 318
		String pk = "CONSTRAINT "
304
				+ getDerivedNAme(((JDBCStoreParameters) ndsp).tableID(), "PK")
319
				+ OracleUtils.getDerivedName(
320
						((JDBCStoreParameters) ndsp).tableID(), "PK")
305 321
				+ " PRIMARY KEY (\""
306
				+ OracleValues.DEFAULT_ID_FIELD_CASE_SENSITIVE
307
				+ "\") ENABLE";
322
				+ OracleValues.DEFAULT_ID_FIELD_CASE_SENSITIVE + "\") ENABLE";
308 323

  
309
		sql.append(", ");
310
		sql.append(pk);
324
		sqlnewtable.append(", ");
325
		sqlnewtable.append(pk);
311 326

  
312
		sql.append(")");
327
		sqlnewtable.append("); ");
328
		final String sqlCreateNew = sqlnewtable.toString();
329
		
330
		// SQL CREATE SPATIAL INDEX
331
		final String sqlindex = "CREATE INDEX "
332
			+ OracleUtils.getDerivedName(((JDBCStoreParameters) ndsp).tableID(), "SX") + " ON "
333
			+ ((JDBCStoreParameters) ndsp).tableID() + " (\"" + OracleValues.DEFAULT_GEO_FIELD
334
			+ "\") INDEXTYPE IS \"MDSYS\".\"SPATIAL_INDEX\" ";
313 335

  
314
		final String sqlCreate = sql.toString();
336
		// SQL CREATE TABLE METADATA
337
		Rectangle2D bbox = new Rectangle2D.Double(0,0,1,1);
338
		final String sqlmeta = ((OracleHelper) helper)
339
				.getSqlUpdateMetadata((OracleStoreParameters)ndsp, null, bbox, 2, true);		
315 340

  
316 341
		TransactionalAction action = new TransactionalAction() {
317 342

  
......
327 352
				} catch (SQLException e1) {
328 353
					throw new JDBCSQLException(e1);
329 354
				}
330
				String sql = null;
355
				String sqlnew = null;
356
				String sqlspatialindex = null;
357
				String sqlmetadata = null;
331 358

  
359
				// new table
332 360
				try {
333
					sql = sqlCreate;
334
					st.execute(sql);
361
					sqlnew = sqlCreateNew;
362
					st.execute(sqlnew);
335 363

  
336 364
				} catch (SQLException e) {
337
					throw new JDBCExecuteSQLException(sql, e);
365
					throw new JDBCExecuteSQLException(sqlnew, e);
366
				}
367
				//new spatial index
368
				try {
369
					sqlspatialindex = sqlindex;
370
					st.execute(sqlspatialindex);
371

  
372
				} catch (SQLException e) {
373
					throw new JDBCExecuteSQLException(sqlspatialindex, e);
374
				}
375
				//new metadata
376
				try {
377
					sqlmetadata = sqlmeta;
378
					st.execute(sqlmetadata);
379

  
380
				} catch (SQLException e) {
381
					throw new JDBCExecuteSQLException(sqlspatialindex, e);
338 382
				} finally {
339 383
					try {
340 384
						st.close();
......
368 412
	}
369 413

  
370 414
	/**
371
	 * get store name
415
	 * Get store name
416
	 * 
417
	 * @return
372 418
	 */
373 419
	protected String getStoreName() {
374 420
		return OracleStoreProvider.NAME;
375 421
	}
376 422

  
377 423
	/**
378
	 * get helper
424
	 * get Oracle helper
379 425
	 * 
380 426
	 * @return
381 427
	 */
382
	protected OracleHelper getOSHelper() {
428
	protected OracleHelper getOracleHelper() {
383 429
		return (OracleHelper) getHelper();
384 430
	}
385 431

  
386 432
	/**
387
	 * get sql sentence for list available tables
433
	 * Get list sql sentences for list available tables
434
	 * 
435
	 * @param mode
436
	 * @param showInformationDBtables
437
	 * @return
388 438
	 */
389 439
	protected List<String> getSQLForList(int mode,
390 440
			boolean showInformationDBTables) {
......
396 446
	}
397 447

  
398 448
	/**
399
	 * check parameters
449
	 * check oracle data store parameters, validate SSL and type driver (THIN or
450
	 * OCI)
451
	 * 
452
	 * @param dsp
400 453
	 */
401 454
	protected void checkIsMine(DataStoreParameters dsp) {
402 455
		if (!(dsp instanceof OracleStoreParameters)) {
......
408 461
		OracleStoreParameters orap = (OracleStoreParameters) dsp;
409 462
		if (orap.getUseSSL().booleanValue() != getOracleSpatialParameters()
410 463
				.getUseSSL()) {
411
			throw new IllegalArgumentException("worng explorer: Host");
464
			throw new IllegalArgumentException("worng explorer: SSL");
412 465
		}
466
		if (orap.getOraDriverType().compareToIgnoreCase(
467
				getOracleSpatialParameters().getOraDriverType()) != 0) {
468
			throw new IllegalArgumentException(
469
					"worng explorer: Oracle type driver: THIN or OCI");
470
		}
413 471
	}
414 472

  
415 473
	/**
......
417 475
	 */
418 476
	protected JDBCStoreParameters createStoreParams()
419 477
			throws InitializeException, ProviderNotRegisteredException {
420
		OracleStoreParameters orgParams = (OracleStoreParameters) super
478
		OracleStoreParameters params = (OracleStoreParameters) super
421 479
				.createStoreParams();
480
		// add SSL and type driver (THIN or OCI)
481
		params.setUseSSL(getOracleSpatialParameters().getUseSSL());
482
		params
483
				.setOraDriverType(getOracleSpatialParameters()
484
						.getOraDriverType());
422 485

  
423
		orgParams.setUseSSL(getOracleSpatialParameters().getUseSSL());
424

  
425
		return orgParams;
486
		return params;
426 487
	}
427 488

  
428 489
	/**
490
	 * Get Oracle server explorer parameters
429 491
	 * 
430
	 * @param tname
431
	 * @param suffix
432 492
	 * @return
433 493
	 */
434
	private static String getDerivedNAme(String tname, String suffix) {
435

  
436
		int ind = tname.lastIndexOf(".");
437
		if (ind == -1) {
438

  
439
			int l = Math.min(28, tname.length());
440
			return tname.substring(0, l) + "_" + suffix;
441

  
442
		} else {
443

  
444
			String pre = tname.substring(0, ind);
445
			String post = tname.substring(ind + 1, tname.length());
446
			int lpost = Math.min(24, post.length());
447
			int lpre = Math.min(3, pre.length());
448
			return pre.substring(0, lpre) + "_" + post.substring(0, lpost)
449
					+ "_" + suffix;
450
		}
451

  
452
	}
453

  
454
	/**
455
	 * Get server explorer parameters
456
	 * 
457
	 * @return
458
	 */
459 494
	private OracleServerExplorerParameters getOracleSpatialParameters() {
460 495
		return (OracleServerExplorerParameters) getParameters();
461 496
	}
branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleStoreProvider.java
27 27

  
28 28
package org.gvsig.fmap.dal.store.oracle;
29 29

  
30
import java.util.ArrayList;
30 31
import java.util.List;
31 32
import java.util.regex.Matcher;
32 33
import java.util.regex.Pattern;
......
61 62
			.getLogger(OracleStoreProvider.class);
62 63

  
63 64
	public static String NAME = "OracleSpatial";
64
	public static String DESCRIPTION = "OracleSpatial source";
65
	private static final String DYNCLASS_NAME = "OracleSpatialStore";
65
	public static String DESCRIPTION = "Oracle source";
66
	private static final String DYNCLASS_NAME = "OracleStore";
66 67
	private static DynClass DYNCLASS = null;
67 68

  
68 69

  
......
84 85
				.createDynObject(DYNCLASS));
85 86
	}
86 87

  
87
	private OracleStoreParameters getOSParameters() {
88
	private OracleStoreParameters getOracleParameters() {
88 89
		return (OracleStoreParameters) this.getParameters();
89 90
	}
90 91

  
91 92
	protected JDBCHelper createHelper() throws InitializeException {
92
		return new OracleHelper(this, getOSParameters());
93
		return new OracleHelper(this, getOracleParameters());
93 94
	}
94 95

  
95 96
	protected String fixFilter(String filter) {
......
138 139
	public DataServerExplorer getExplorer() throws ReadException {
139 140
		DataManager manager = DALLocator.getDataManager();
140 141
		OracleServerExplorerParameters exParams;
141
		OracleStoreParameters params = getOSParameters();
142
		OracleStoreParameters params = getOracleParameters();
142 143
		try {
143 144
			exParams = (OracleServerExplorerParameters) manager
144 145
					.createServerExplorerParameters(OracleServerExplorer.NAME);
......
152 153
			exParams.setSchema(params.getSchema());
153 154
			exParams.setJDBCDriverClassName(params.getJDBCDriverClassName());
154 155
			exParams.setUseSSL(params.getUseSSL());
156
			exParams.setOraDriverType(params.getOraDriverType());
155 157

  
156 158
			return manager.createServerExplorer(exParams);
157 159
		} catch (DataException e) {
......
171 173
		return true;
172 174
	}
173 175

  
174
	// ************************************************************************************//
175 176

  
176 177

  
177
	// ************************************************************************************//
178 178

  
179

  
180

  
181 179
	protected OracleHelper getOSHelper() {
182 180
		return (OracleHelper) getHelper();
183 181
	}
182
	
184 183

  
185
	// ************************************************************************************//
186 184

  
187
	// ************************************************************************************//
188

  
189

  
190

  
191 185
	public boolean canWriteGeometry(int geometryType, int geometrySubtype)
192 186
			throws DataException {
193 187
		FeatureType type = getFeatureStore().getDefaultFeatureType();
......
262 256
	protected String getSqlStatementAddField(FeatureAttributeDescriptor attr,
263 257
			List additionalStatement) throws DataException {
264 258
		if (attr.getDataType() == DataTypes.GEOMETRY) {
265
			OracleStoreParameters params = getOSParameters();
259
			OracleStoreParameters params = getOracleParameters();
266 260
			additionalStatement.add(((OracleHelper) helper)
267 261
					.getSqlGeometyFieldAdd(attr, params.getTable(), params
268 262
							.getSchema()));
......
273 267
	}
274 268
	private Object getSqlGeometyFieldDrop(FeatureAttributeDescriptor attr) {
275 269
		StringBuilder strb = new StringBuilder();
276
		OracleStoreParameters params = getOSParameters();
270
		OracleStoreParameters params = getOracleParameters();
277 271
		strb.append("Delete from geometry_columns where f_geometry_column = '");
278 272
		strb.append(attr.getName());
279 273
		strb.append("' and f_table_nam = '");
......
312 306
		List actions = super.getSqlStatementAlterField(attrOrg, attrTrg,
313 307
				additionalStatement);
314 308
		StringBuilder strb;
315
		OracleStoreParameters params = getOSParameters();
309
		OracleStoreParameters params = getOracleParameters();
316 310
		if (attrOrg.getDataType() != attrTrg.getDataType()) {
317 311
			if (attrOrg.getDataType() == DataTypes.GEOMETRY) {
318 312
				additionalStatement.add(getSqlGeometyFieldDrop(attrOrg));
......
330 324

  
331 325
		return actions;
332 326
	}
327
	
328
	public List getSqlGeometyFieldAdd(FeatureAttributeDescriptor attr,
329
			String table, String schema) {
330
	
333 331

  
332
		List sqls = new ArrayList();
333

  
334
		StringBuilder strb = new StringBuilder();
335
		strb.append("SELECT AddGeometryColumn('");
336
		if (schema != null && schema.length() > 0) {
337
			strb.append(schema);
338
			strb.append("', '");
339
		}
340
		strb.append(table);
341
		strb.append("', '");
342
		strb.append(attr.getName());
343
		strb.append("', ");
344
		// strb.append("-1");
345
		strb.append(getProviderSRID(attr.getSRS()));
346
		strb.append(", '");
347
		strb.append(getPostgisGeomType(attr.getGeometryType(), attr
348
				.getGeometrySubType()));
349
		strb.append("', ");
350
		strb.append(getPostgisGeomDimensions(attr.getGeometrySubType()));
351
		strb.append(")");
352

  
353

  
354
		sqls.add(strb.toString());
355

  
356
		/*ALTER TABLE muni10000_peq_test DROP CONSTRAINT enforce_srid_the_geom;*/
357
		/*
358
		strb = new StringBuilder();
359
		strb.append("Alter table ");
360
		if (schema != null && schema.length() > 0) {
361
			strb.append(schema);
362
			strb.append(".");
363
		}
364
		strb.append("f_table_name = '");
365
		strb.append(table);
366
		strb.append("' AND f_geometry_column = '");
367
		strb.append(attr.getName());
368
		strb.append("' AND srid = -1");
369

  
370

  
371
		sqls.add(strb.toString());
372
		*/
373
		return sqls;
374
	}
375

  
334 376
}
branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleNewStoreParameters.java
39 39
		implements
40 40
        NewFeatureStoreParameters {
41 41

  
42
    public static final String DYNCLASS_NAME = "OracleSpatialNewStoreParameters";
42
    public static final String DYNCLASS_NAME = "OracleNewStoreParameters";
43 43

  
44 44
    private FeatureType defaultFeatureType;
45 45

  
branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleResourceParameters.java
1 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
*/
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 22

  
23 23
/*
24 24
 * AUTHORS (In addition to CIT):
......
34 34
import org.gvsig.tools.dynobject.DynField;
35 35
import org.gvsig.tools.dynobject.DynObjectManager;
36 36

  
37
public class OracleResourceParameters extends JDBCResourceParameters
38
		implements OracleConnectionParameters {
37
public class OracleResourceParameters extends JDBCResourceParameters implements
38
		OracleConnectionParameters {
39 39

  
40 40
	private static DynClass DYNCLASS = null;
41 41

  
42
	public static final String DYNCLASS_NAME = "OracleSpatialResourceParameters";
42
	public static final String DYNCLASS_NAME = "OracleResourceParameters";
43 43

  
44 44
	public OracleResourceParameters() {
45 45
		super();
46 46
	}
47 47

  
48
    public OracleResourceParameters(String url, String host, Integer port,
48
	public OracleResourceParameters(String url, String host, Integer port,
49 49
			String dbName, String user, String password,
50
			String jdbcDriverClassName, Boolean ssl) {
50
			String jdbcDriverClassName, Boolean ssl, String oraDriverType) {
51 51
		super(url, host, port, dbName, user, password, jdbcDriverClassName);
52 52
		if (ssl != null) {
53 53
			this.setUseSSL(ssl.booleanValue());
54 54
		}
55
		if (oraDriverType.compareToIgnoreCase("THIN")==0 && oraDriverType.compareToIgnoreCase("OCI")==0) {
56
			this.setOraDriverType(oraDriverType);
57
		}
58
		else{
59
			this.setOraDriverType("THIN");
60
		}
55 61
	}
56 62

  
63
	/**
64
	 * register dynamic class
65
	 */
57 66
	protected static void registerDynClass() {
58 67
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
59 68
		DynClass dynClass = dynman.get(DYNCLASS_NAME);
......
76 85
			field.setType(DataTypes.STRING);
77 86
			field.setDefaultValue(OracleLibrary.DEFAULT_JDCB_DRIVER_NAME);
78 87

  
88
			field = dynClass.addDynField(DYNFIELDNAME_JDBC_DRIVER_CLASS_NAME);
89
			field.setTheTypeOfAvailableValues(DynField.SINGLE);
90
			field.setDescription("ora Driver");
91
			field.setMandatory(true);
92
			field.setType(DataTypes.STRING);
93
			field.setDefaultValue(OracleLibrary.DEFAULT_JDCB_DRIVER_NAME);
79 94

  
80 95
		}
81 96
		DYNCLASS = dynClass;
82 97
	}
83 98

  
84

  
85 99
	public String getUrl() {
86
		return OracleLibrary.getJdbcUrl(getHost(),
87
				getPort(),
100
		return OracleLibrary.getJdbcUrl(getOraDriverType(), getHost(), getPort(),
88 101
				getDBName());
89 102
	}
90 103

  
......
96 109
		return (Boolean) this.getDynValue(DYNFIELDNAME_USESSL);
97 110
	}
98 111

  
112
	public String getOraDriverType() {
113
		return (String) this.getDynValue(DYNFIELDNAME_ORADRIVERTYPE);
114
	}
115

  
99 116
	public void setUseSSL(Boolean useSSL) {
100 117
		this.setDynValue(DYNFIELDNAME_USESSL, useSSL);
101 118
	}
......
103 120
	public void setUseSSL(boolean useSSL) {
104 121
		this.setDynValue(DYNFIELDNAME_USESSL, new Boolean(useSSL));
105 122
	}
123
	
124
	public void setOraDriverType(String oraDriverType) {
125
		this.setDynValue(DYNFIELDNAME_ORADRIVERTYPE, oraDriverType);
126
	}
106 127

  
107 128
	protected String getDynClassName() {
108 129
		return DYNCLASS_NAME;
109 130
	}
131

  
110 132
}
branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleServerExplorerParameters.java
1 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
*/
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 22

  
23 23
/*
24 24
 * AUTHORS (In addition to CIT):
......
39 39

  
40 40
/**
41 41
 * @author vsanjaime
42
 *
42
 * 
43 43
 */
44 44
public class OracleServerExplorerParameters extends
45 45
		JDBCServerExplorerParameters implements OracleConnectionParameters {
46 46

  
47
	public static final String DYNCLASS_NAME = "OracleServerExplorerParameters";
47 48

  
48
	public static final String DYNCLASS_NAME = "OracleSpatialServerExplorerParameters";
49

  
50 49
	protected DynClass registerDynClass() {
51 50
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
52 51
		DynClass dynClass = dynman.get(DYNCLASS_NAME);
......
63 62
		return dynClass;
64 63
	}
65 64

  
66
	/* (non-Javadoc)
65
	/*
66
	 * (non-Javadoc)
67
	 * 
67 68
	 * @see org.gvsig.fmap.dal.DataServerExplorerParameters#getExplorerName()
68 69
	 */
69 70
	public String getExplorerName() {
......
74 75
		return (Boolean) this.getDynValue(DYNFIELDNAME_USESSL);
75 76
	}
76 77

  
78
	public String getOraDriverType() {
79
		return (String) this.getDynValue(DYNFIELDNAME_ORADRIVERTYPE);
80
	}
81

  
77 82
	public void setUseSSL(Boolean useSSL) {
78 83
		this.setDynValue(DYNFIELDNAME_USESSL, useSSL);
79 84
	}
......
82 87
		this.setDynValue(DYNFIELDNAME_USESSL, new Boolean(useSSL));
83 88
	}
84 89

  
90
	public void setOraDriverType(String oraDriverType) {
91
		this.setDynValue(DYNFIELDNAME_ORADRIVERTYPE, oraDriverType);
92
	}
93

  
85 94
	public void validate() throws ValidateDataParametersException {
86 95
		if (getJDBCDriverClassName() == null) {
87 96
			setJDBCDriverClassName(OracleLibrary.DEFAULT_JDCB_DRIVER_NAME);
88 97
		}
89 98
		if (getUrl() == null) {
90
			setUrl(OracleLibrary.getJdbcUrl(getHost(), getPort(),
91
					getDBName()));
99
			setUrl(OracleLibrary.getJdbcUrl(getOraDriverType(), getHost(),
100
					getPort(), getDBName()));
92 101
		}
93 102

  
94 103
		if (getPort() == null) {
95 104
			setPort(new Integer(1521));
96 105
		}
106

  
107
		if (getOraDriverType().compareToIgnoreCase("THIN") != 0
108
				&& getOraDriverType().compareToIgnoreCase("OCI") != 0) {
109
			setOraDriverType("thin");
110
		}
111
		
97 112
		super.validate();
98 113
	}
99 114

  
100

  
101

  
102

  
103

  
104 115
}
branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleHelper.java
50 50
import org.gvsig.fmap.dal.DALLocator;
51 51
import org.gvsig.fmap.dal.DataManager;
52 52
import org.gvsig.fmap.dal.DataTypes;
53
import org.gvsig.fmap.dal.NewDataStoreParameters;
54 53
import org.gvsig.fmap.dal.exception.DataException;
55 54
import org.gvsig.fmap.dal.exception.InitializeException;
56 55
import org.gvsig.fmap.dal.exception.ReadException;
......
61 60
import org.gvsig.fmap.dal.feature.FeatureQuery;
62 61
import org.gvsig.fmap.dal.feature.FeatureSet;
63 62
import org.gvsig.fmap.dal.feature.FeatureStore;
64
import org.gvsig.fmap.dal.feature.FeatureType;
65 63
import org.gvsig.fmap.dal.feature.exception.UnsupportedDataTypeException;
66 64
import org.gvsig.fmap.dal.feature.exception.UnsupportedGeometryException;
67 65
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
......
83 81
import org.slf4j.LoggerFactory;
84 82

  
85 83
/**
84
 * Oracle helper
85
 * 
86 86
 * @author vsanjaime
87 87
 * 
88 88
 */
89 89
public class OracleHelper extends JDBCHelper {
90 90

  
91
	private static Logger logger = LoggerFactory
92
			.getLogger(OracleHelper.class);
91
	private static Logger logger = LoggerFactory.getLogger(OracleHelper.class);
93 92

  
94 93
	private boolean tableHasSrid = true;
95 94
	private String oracleSRID;
......
102 101
	 * @throws InitializeException
103 102
	 */
104 103
	public OracleHelper(JDBCHelperUser consumer,
105
			OracleConnectionParameters params)
106
			throws InitializeException {
104
			OracleConnectionParameters params) throws InitializeException {
107 105

  
108 106
		super(consumer, params);
109 107
	}
......
114 112
	protected void initializeResource() throws InitializeException {
115 113
		ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator
116 114
				.getResourceManager();
117
		OracleResource resource = (OracleResource) manager
118
				.createResource(OracleResource.NAME, new Object[] {
119
						params.getUrl(),
120
						params.getHost(),
121
						params.getPort(),
122
						params.getDBName(),
123
						params.getUser(),
124
						params.getPassword(),
115
		OracleResource resource = (OracleResource) manager.createResource(
116
				OracleResource.NAME, new Object[] { params.getUrl(),
117
						params.getHost(), params.getPort(), params.getDBName(),
118
						params.getUser(), params.getPassword(),
125 119
						params.getJDBCDriverClassName(),
126
						((OracleConnectionParameters) params)
127
								.getUseSSL() });
120
						((OracleConnectionParameters) params).getUseSSL(),
121
						((OracleConnectionParameters) params).getOraDriverType() });
128 122
		this.setResource(resource);
129 123
	}
130 124

  
131 125
	/**
132
	 * Get default schema
126
	 * Get default schema name
127
	 * 
128
	 * @param conn
129
	 * @return
133 130
	 */
134 131
	protected String getDefaultSchema(Connection conn) throws JDBCException {
135 132
		if (defaultSchema == null) {
136
			String sql = "SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual;";
133
			String sql = "SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual";
137 134
			ResultSet rs = null;
138 135
			Statement st = null;
139 136
			String schema = null;
......
176 173
	public Envelope getFullEnvelopeOfField(JDBCStoreParameters storeParams,
177 174
			String geometryAttrName, Envelope limit) throws DataException {
178 175

  
176
		// FIXME
177

  
179 178
		StringBuilder strb = new StringBuilder();
180 179
		strb.append("Select asbinary(extent(");
181 180
		strb.append(escapeFieldName(geometryAttrName));
......
261 260

  
262 261
	}
263 262

  
263
	/**
264
	 * 
265
	 */
264 266
	protected void initializeFromWKBOperation() throws BaseException {
265 267
		if (fromWKB == null) {
266 268
			fromWKB = (FromWKB) GeometryLocator.getGeometryManager()
267 269
					.getGeometryOperation(FromWKB.CODE,
268 270
							Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D);
269 271
			fromWKBContext = new FromWKBGeometryOperationContext();
270

  
271 272
		}
272 273
	}
273 274

  
......
287 288
		return geom;
288 289
	}
289 290

  
290
	// /**
291
	// * Fill <code>featureType</code> geometry attributes with SRS and
292
	// ShapeType
293
	// * information stored in the table GEOMETRY_COLUMNS
294
	// *
295
	// * @param conn
296
	// * @param rsMetadata
297
	// * @param featureType
298
	// * @throws ReadException
299
	// */
300
	// protected void loadSRS_and_shapeType(Connection conn,
301
	// ResultSetMetaData rsMetadata, EditableFeatureType featureType,
302
	// String baseSchema, String baseTable) throws JDBCException {
303
	//
304
	// Statement st = null;
305
	// ResultSet rs = null;
306
	// try {
307
	// // Sacamos la lista de los attributos geometricos
308
	// EditableFeatureAttributeDescriptor attr;
309
	// List geoAttrs = new ArrayList();
310
	//
311
	// Iterator iter = featureType.iterator();
312
	// while (iter.hasNext()) {
313
	// attr = (EditableFeatureAttributeDescriptor) iter.next();
314
	// if (attr.getDataType() == DataTypes.GEOMETRY) {
315
	// geoAttrs.add(attr);
316
	// }
317
	// }
318
	// if (geoAttrs.size() < 1) {
319
	// return;
320
	// }
321
	//
322
	// // preparamos un set con las lista de tablas de origen
323
	// // de los campos
324
	// class TableId {
325
	// public String schema = null;
326
	// public String table = null;
327
	// public String field = null;
328
	//
329
	// public void appendToSQL(StringBuilder strb) {
330
	// if (schema == null || schema.length() == 0) {
331
	// strb
332
	// .append("( F_TABLE_SCHEMA = current_schema() AND F_TABLE_NAME = '");
333
	// } else {
334
	// strb.append("( F_TABLE_SCHEMA = '");
335
	// strb.append(schema);
336
	// strb.append("' AND F_TABLE_NAME = '");
337
	// }
338
	// strb.append(table);
339
	// strb.append("' AND F_GEOMETRY_COLUMN = '");
340
	// strb.append(field);
341
	// strb.append("' )");
342
	// }
343
	//
344
	// }
345
	// Comparator cmp = new Comparator() {
346
	// public int compare(Object arg0, Object arg1) {
347
	// TableId a0 = (TableId) arg0;
348
	// TableId a1 = (TableId) arg1;
349
	//
350
	// if (!a0.field.equals(a1.field)) {
351
	// return -1;
352
	// }
353
	// if (!a0.table.equals(a1.table)) {
354
	// return -1;
355
	// }
356
	// if (!a0.schema.equals(a1.schema)) {
357
	// return -1;
358
	// }
359
	// return 0;
360
	// }
361
	// };
362
	// TreeSet set = new TreeSet(cmp);
363
	// TableId tableId;
364
	// iter = geoAttrs.iterator();
365
	// int rsIndex;
366
	// while (iter.hasNext()) {
367
	// attr = (EditableFeatureAttributeDescriptor) iter.next();
368
	// tableId = new TableId();
369
	// rsIndex = attr.getIndex() + 1;
370
	//
371
	// if (baseSchema == null && baseTable == null) {
372
	// if (rsMetadata instanceof OracleResultSetMetaData) {
373
	// tableId.schema = ((OracleResultSetMetaData) rsMetadata)
374
	// .getSchemaName(rsIndex);
375
	// tableId.table = ((OracleResultSetMetaData) rsMetadata)
376
	// .getTableName(rsIndex);
377
	// tableId.field = ((OracleResultSetMetaData) rsMetadata)
378
	// .getColumnName(rsIndex);
379
	//
380
	// } else {
381
	// tableId.schema = rsMetadata.getSchemaName(rsIndex);
382
	// tableId.table = rsMetadata.getTableName(rsIndex);
383
	// tableId.field = rsMetadata.getColumnName(rsIndex);
384
	// }
385
	// } else {
386
	// tableId.schema = baseSchema;
387
	// tableId.table = baseTable;
388
	// tableId.field = rsMetadata.getColumnName(rsIndex);
389
	// }
390
	// if (tableId.table == null || tableId.table.length() == 0) {
391
	// // Si no tiene tabla origen (viene de algun calculo por ej.)
392
	// // lo saltamos ya que no estara en la tabla GEOMETRY_COLUMNS
393
	// continue;
394
	// }
395
	// set.add(tableId);
396
	// }
397
	//
398
	// if (set.size() == 0) {
399
	// return;
400
	// }
401
	//
402
	// // Preparamos una sql para que nos saque el resultado
403
	// StringBuilder strb = new StringBuilder();
404
	// strb
405
	// .append("Select geometry_columns.*,auth_name || ':' || auth_srid as SRSID ");
406
	// strb.append("from geometry_columns left join spatial_ref_sys on ");
407
	// strb.append("geometry_columns.srid = spatial_ref_sys.srid WHERE ");
408
	// iter = set.iterator();
409
	// for (int i = 0; i < set.size() - 1; i++) {
410
	// tableId = (TableId) iter.next();
411
	// tableId.appendToSQL(strb);
412
	// strb.append(" OR ");
413
	// }
414
	// tableId = (TableId) iter.next();
415
	// tableId.appendToSQL(strb);
416
	// String sql = strb.toString();
417
	//
418
	// st = conn.createStatement();
419
	// try {
420
	// rs = st.executeQuery(sql);
421
	// } catch (SQLException e) {
422
	// throw new JDBCExecuteSQLException(sql, e);
423
	// }
424
	// String srsID;
425
	// int oraSrid;
426
	// int geometryType;
427
	// int geometrySubtype;
428
	// String geomTypeStr;
429
	// int dimensions;
430
	// IProjection srs;
431
	//
432
	// while (rs.next()) {
433
	// srsID = rs.getString("SRSID");
434
	// oraSrid = rs.getInt("SRID");
435
	// geomTypeStr = rs.getString("TYPE").toUpperCase();
436
	// geometryType = Geometry.TYPES.GEOMETRY;
437
	// if (geomTypeStr.startsWith("POINT")) {
438
	// geometryType = Geometry.TYPES.POINT;
439
	// } else if (geomTypeStr.startsWith("LINESTRING")) {
440
	// geometryType = Geometry.TYPES.CURVE;
441
	// } else if (geomTypeStr.startsWith("POLYGON")) {
442
	// geometryType = Geometry.TYPES.SURFACE;
443
	// } else if (geomTypeStr.startsWith("MULTIPOINT")) {
444
	// geometryType = Geometry.TYPES.MULTIPOINT;
445
	// } else if (geomTypeStr.startsWith("MULTILINESTRING")) {
446
	// geometryType = Geometry.TYPES.MULTICURVE;
447
	// } else if (geomTypeStr.startsWith("MULTIPOLYGON")) {
448
	// geometryType = Geometry.TYPES.MULTISURFACE;
449
	// }
450
	// dimensions = rs.getInt("coord_dimension");
451
	// geometrySubtype = Geometry.SUBTYPES.GEOM2D;
452
	// if (dimensions > 2) {
453
	// if (dimensions == 3) {
454
	// if (geomTypeStr.endsWith("M")) {
455
	// geometrySubtype = Geometry.SUBTYPES.GEOM2DM;
456
	// } else {
457
	// geometrySubtype = Geometry.SUBTYPES.GEOM3D;
458
	// }
459
	//
460
	// } else {
461
	// geometrySubtype = Geometry.SUBTYPES.GEOM3DM;
462
	// }
463
	// }
464
	//
465
	// iter = geoAttrs.iterator();
466
	// while (iter.hasNext()) {
467
	// attr = (EditableFeatureAttributeDescriptor) iter.next();
468
	// rsIndex = attr.getIndex() + 1;
469
	// if (!rsMetadata.getColumnName(rsIndex).equals(
470
	// rs.getString("f_geometry_column"))) {
471
	// continue;
472
	// }
473
	//
474
	// if (baseSchema == null && baseTable == null) {
475
	//
476
	// if (rsMetadata instanceof PGResultSetMetaData) {
477
	// if (!((PGResultSetMetaData) rsMetadata)
478
	// .getBaseTableName(rsIndex).equals(
479
	// rs.getString("f_table_name"))) {
480
	// continue;
481
	// }
482
	// String curSchema = rs.getString("f_table_schema");
483
	// String metaSchema = ((PGResultSetMetaData) rsMetadata)
484
	// .getBaseSchemaName(rsIndex);
485
	// if (!metaSchema.equals(curSchema)) {
486
	// if (metaSchema.length() == 0
487
	// && metaSchema == getDefaultSchema(conn)) {
488
	// } else {
489
	// continue;
490
	// }
491
	// }
492
	//
493
	// } else {
494
	//
495
	// if (!rsMetadata.getTableName(rsIndex).equals(
496
	// rs.getString("f_table_name"))) {
497
	// continue;
498
	// }
499
	// String curSchema = rs.getString("f_table_schema");
500
	// String metaSchema = rsMetadata
501
	// .getSchemaName(rsIndex);
502
	// if (!metaSchema.equals(curSchema)) {
503
	// if (metaSchema.length() == 0
504
	// && metaSchema == getDefaultSchema(conn)) {
505
	// } else {
506
	// continue;
507
	// }
508
	// }
509
	// }
510
	// }
511
	// attr.setGeometryType(geometryType);
512
	// attr.setGeometrySubType(geometrySubtype);
513
	// if (srsID != null && srsID.length() > 0) {
514
	// attr.setSRS(CRSFactory.getCRS(srsID));
515
	// }
516
	// iter.remove();
517
	// }
518
	// iter = geoAttrs.iterator();
519
	// while (iter.hasNext()) {
520
	// attr = (EditableFeatureAttributeDescriptor) iter.next();
521
	// attr.setSRS(null);
522
	// attr.setGeometryType(Geometry.TYPES.GEOMETRY);
523
	//
524
	// }
525
	// }
526
	//
527
	// } catch (java.sql.SQLException e) {
528
	// throw new JDBCSQLException(e);
529
	// } finally {
530
	// try {
531
	// rs.close();
532
	// } catch (Exception e) {
533
	// }
534
	// ;
535
	// try {
536
	// st.close();
537
	// } catch (Exception e) {
538
	// }
539
	// ;
540
	// }
541
	//
542
	// }
543

  
544 291
	/**
545 292
	 * get geometry column name "SDO_GEOMETRY"
546 293
	 */
......
588 335
			if (typeName != null) {
589 336
				return typeName;
590 337
			}
591

  
592 338
			throw new UnsupportedDataTypeException(attr.getDataTypeName(), attr
593 339
					.getDataType());
594 340
		}
......
596 342
	}
597 343

  
598 344
	/**
599
	 * get geometry dimension
345
	 * Get geometry dimension
600 346
	 * 
601 347
	 * @param geometrySubType
602 348
	 * @return
......
618 364
		}
619 365
	}
620 366

  
367
	/**
368
	 * Get Oracle geometry type
369
	 * 
370
	 * @param geometryType
371
	 * @param geometrySubType
372
	 * @return
373
	 */
621 374
	public String getOraGeomType(int geometryType, int geometrySubType) {
622 375
		String oraGeomType;
623 376
		switch (geometryType) {
......
673 426
			throw new UnsupportedGeometryException(geometryType,
674 427
					geometrySubType);
675 428
		}
676

  
677 429
		return oraGeomType;
678 430
	}
679 431

  
......
715 467
		}
716 468
		return -1;
717 469
	}
718
	
470

  
719 471
	/**
720 472
	 * Get oracle srid from srs code(EPSG code)
721 473
	 */
......
771 523
		return -1;
772 524
	}
773 525

  
774
	// private int searchOraSRID(final IProjection srs) {
775
	// if (srs == null) {
776
	// return -1;
777
	// }
778
	// return searchOraSRID(srs.getAbrev());
779
	// }
780
	//
781
	// private int searchOraSRID(final String srsID) {
782
	// if (srsID == null) {
783
	// return -1;
784
	// }
785
	//
786
	// ConnectionAction action = new ConnectionAction() {
787
	//
788
	// public Object action(Connection conn) throws DataException {
789
	// // select srid from spatial_ref_sys where auth_name = 'EPSG' and
790
	// // auth_srid = 23030
791
	// String[] abrev = srsID.split(":");
792
	// StringBuilder sqlb = new StringBuilder();
793
	// sqlb.append("select SRID from MDSYS.CS_SRS where ");
794
	// if (abrev.length > 1) {
795
	// sqlb.append("auth_name = ? and ");
796
	// }
797
	// sqlb.append("auth_srid = ?");
798
	//
799
	// String sql = sqlb.toString();
800
	// PreparedStatement st;
801
	// try {
802
	// st = conn.prepareStatement(sql);
803
	// } catch (SQLException e) {
804
	// throw new JDBCPreparingSQLException(sql, e);
805
	// }
806
	// ResultSet rs = null;
807
	// try {
808
	// int i = 0;
809
	// if (abrev.length > 1) {
810
	// st.setString(i + 1, abrev[i]);
811
	// i++;
812
	// }
813
	// st.setInt(i + 1, Integer.parseInt(abrev[i]));
814
	//
815
	// try {
816
	// rs = st.executeQuery();
817
	// } catch (SQLException e) {
818
	// throw new JDBCExecutePreparedSQLException(sql, abrev, e);
819
	// }
820
	//
821
	// if (!rs.next()) {
822
	// return null;
823
	// }
824
	//
825
	// return new Integer(rs.getInt(1));
826
	//
827
	// } catch (SQLException e) {
828
	// throw new JDBCSQLException(e);
829
	// } finally {
830
	// try {
831
	// rs.close();
832
	// } catch (Exception e) {
833
	// }
834
	// ;
835
	// try {
836
	// st.close();
837
	// } catch (Exception e) {
838
	// }
839
	// ;
840
	// }
841
	//
842
	// }
843
	//
844
	// };
845
	//
846
	// Integer oraSRSID = null;
847
	// try {
848
	// oraSRSID = (Integer) doConnectionAction(action);
849
	// return oraSRSID.intValue();
850
	// } catch (Exception e) {
851
	// logger.error("Excetion searching pgSRS", e);
852
	// return -1;
853
	// }
854
	// }
855 526

  
856
	public List getSqlGeometyFieldAdd(FeatureAttributeDescriptor attr,
857
			String table, String schema) {
858
		// SELECT AddGeometryColumn({schema}, {table}, {field}, {srid}(int),
859
		// {geomType}(Str), {dimensions}(int))
860 527

  
861
		// gemoType:
862
		/*
863
		 * POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING,
864
		 * MULTIPOLYGON, GEOMETRYCOLLECTION POINTM, LINESTRINGM, POLYGONM,
865
		 * MULTIPOINTM, MULTILINESTRINGM, MULTIPOLYGONM, GEOMETRYCOLLECTIONM
866
		 */
528
	
867 529

  
868
		List sqls = new ArrayList();
869

  
870
		StringBuilder strb = new StringBuilder();
871
		strb.append("SELECT AddGeometryColumn('");
872
		if (schema != null && schema.length() > 0) {
873
			strb.append(schema);
874
			strb.append("', '");
875
		}
876
		strb.append(table);
877
		strb.append("', '");
878
		strb.append(attr.getName());
879
		strb.append("', ");
880
		// strb.append("-1");
881
		strb.append(getProviderSRID(attr.getSRS()));
882
		strb.append(", '");
883
		strb.append(getOraGeomType(attr.getGeometryType(), attr
884
				.getGeometrySubType()));
885
		strb.append("', ");
886
		strb.append(getOraGeomDimensions(attr.getGeometrySubType()));
887
		strb.append(")");
888

  
889
		sqls.add(strb.toString());
890

  
891
		/* ALTER TABLE muni10000_peq_test DROP CONSTRAINT enforce_srid_the_geom; */
892
		/*
893
		 * strb = new StringBuilder(); strb.append("Alter table "); if (schema
894
		 * != null && schema.length() > 0) { strb.append(schema);
895
		 * strb.append("."); } strb.append("f_table_name = '");
896
		 * strb.append(table); strb.append("' AND f_geometry_column = '");
897
		 * strb.append(attr.getName()); strb.append("' AND srid = -1");
898
		 * 
899
		 * 
900
		 * sqls.add(strb.toString());
901
		 */
902
		return sqls;
903
	}
904

  
905 530
	public String getSqlFieldName(FeatureAttributeDescriptor attribute) {
906 531
		if (attribute.getDataType() == DataTypes.GEOMETRY) {
907 532
			return "asBinary(" + super.getSqlFieldName(attribute) + ")";
......
923 548
		return super.createAttributeFromJDBC(type, conn, rsMetadata, colIndex);
924 549
	}
925 550

  
926
	
927

  
928 551
	public boolean allowAutomaticValues() {
929 552
		return Boolean.TRUE;
930 553
	}
......
937 560
		return true;
938 561
	}
939 562

  
563
	/**
564
	 * get sql with fields description
565
	 * @param attr
566
	 * @return 
567
	 */
940 568
	public String getSqlFieldDescription(FeatureAttributeDescriptor attr)
941 569
			throws DataException {
942 570

  
......
952 580
		return strb.toString();
953 581
	}
954 582

  
955
	public static int nvarchar2Limited(int n) {
583
	
584
	
585
	 /**
586
     * UTility method to get the SQL sentence needed to update the geographic metadata table
587
     * with a new bounding box and SRS
588
     *
589
     * @param tName table name
590
     * @param ora_srid new SRS
591
     * @param bbox new bounding box
592
     * @param dim geometries dimension
593
     * @param withsrid False if the SRS is set to NULL. True otherwise.
594
     * @return the SQL sentence to perform the update
595
     */
596
    public String getSqlUpdateMetadata(OracleStoreParameters params, String ora_srid,
597
        Rectangle2D bbox, int dim, boolean withsrid) {
598
    	
599
        String[] dim_name = new String[dim];
600
        double tolerance = 0.5;
601
        
602
        String _ora_srid = ora_srid;
603
        if (_ora_srid == null) _ora_srid = "NULL";
956 604

  
957
		if (n <= OracleValues.VARCHAR2_STANDARD_SIZE)
958
			return OracleValues.VARCHAR2_STANDARD_SIZE;
959
		if (n <= OracleValues.VARCHAR2_LONG_SIZE)
960
			return n;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff