Revision 31886 branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleServerExplorer.java
OracleServerExplorer.java | ||
---|---|---|
104 | 104 |
/** |
105 | 105 |
* remove |
106 | 106 |
*/ |
107 |
public void removeMetadata(DataStoreParameters dsp) { |
|
108 |
|
|
109 |
final OracleStoreParameters oraParams = (OracleStoreParameters) dsp; |
|
110 |
|
|
111 |
TransactionalAction action = new TransactionalAction() { |
|
112 |
public boolean continueTransactionAllowed() { |
|
113 |
return false; |
|
114 |
} |
|
115 |
|
|
116 |
public Object action(Connection conn) throws DataException { |
|
117 |
|
|
118 |
Statement st; |
|
119 |
try { |
|
120 |
st = conn.createStatement(); |
|
121 |
} catch (SQLException e) { |
|
122 |
throw new JDBCSQLException(e); |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
// SQL DELETE METADATA |
|
127 |
String tname = oraParams.tableID(); |
|
128 |
String sqlDeleteMetadata = ""; |
|
129 |
int ind = tname.lastIndexOf("."); |
|
130 |
if (ind != -1) { |
|
131 |
String schema = tname.substring(0, ind); |
|
132 |
tname = tname.substring(ind + 1, tname.length()); |
|
133 |
sqlDeleteMetadata = "DELETE FROM " |
|
134 |
+ OracleValues.USER_ORACLE_GEOMETADATA_VIEW |
|
135 |
+ " WHERE TABLE_NAME = '" + tname + "'"; |
|
136 |
|
|
137 |
} else { |
|
138 |
sqlDeleteMetadata = "DELETE FROM " |
|
139 |
+ OracleValues.USER_ORACLE_GEOMETADATA_VIEW |
|
140 |
+ " WHERE TABLE_NAME = '" + tname + "'"; |
|
141 |
} |
|
142 |
|
|
143 |
try { |
|
144 |
st.execute(sqlDeleteMetadata); |
|
145 |
} catch (SQLException e) { |
|
146 |
logger.error("While deleting metadata: " + e.getMessage()); |
|
147 |
} |
|
148 |
|
|
149 |
if (st != null) { |
|
150 |
try { |
|
151 |
st.close(); |
|
152 |
} catch (SQLException e) { |
|
153 |
logger.error("While closing statement: " + e.getMessage()); |
|
154 |
} |
|
155 |
} |
|
156 |
return null; |
|
157 |
} |
|
158 |
}; |
|
159 |
try { |
|
160 |
this.helper.doConnectionAction(action); |
|
161 |
} catch (Exception e) { |
|
162 |
logger.error("While removing metadatat: " + e.getMessage()); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
|
|
167 |
/** |
|
168 |
* remove |
|
169 |
*/ |
|
107 | 170 |
public void remove(DataStoreParameters dsp) throws RemoveException { |
108 | 171 |
|
109 | 172 |
final OracleStoreParameters oraParams = (OracleStoreParameters) dsp; |
... | ... | |
266 | 329 |
} |
267 | 330 |
} |
268 | 331 |
|
332 |
public boolean dataStoreExists(DataStoreParameters dsp) { |
|
333 |
|
|
334 |
final String select_str = "SELECT * FROM " + ((JDBCStoreParameters) dsp).tableID(); |
|
335 |
TransactionalAction action = new TransactionalAction() { |
|
336 |
|
|
337 |
public boolean continueTransactionAllowed() { |
|
338 |
return false; |
|
339 |
} |
|
340 |
|
|
341 |
public Object action(Connection conn) throws DataException { |
|
342 |
Statement st = null; |
|
343 |
|
|
344 |
try { |
|
345 |
st = conn.createStatement(); |
|
346 |
} catch (SQLException e1) { |
|
347 |
throw new JDBCSQLException(e1); |
|
348 |
} |
|
349 |
|
|
350 |
boolean resp = true; |
|
351 |
|
|
352 |
// try select |
|
353 |
try { |
|
354 |
st.execute(select_str); |
|
355 |
logger.warn("Table exists: " + select_str); |
|
356 |
} catch (SQLException e) { |
|
357 |
logger.warn("Table does not exist: " + select_str); |
|
358 |
resp = false; |
|
359 |
} |
|
360 |
|
|
361 |
try { |
|
362 |
st.close(); |
|
363 |
} catch (Exception ex) { |
|
364 |
logger.error("Exception closing statement", ex); |
|
365 |
} |
|
366 |
|
|
367 |
return resp; |
|
368 |
} |
|
369 |
|
|
370 |
}; |
|
371 |
|
|
372 |
Boolean result = Boolean.FALSE; |
|
373 |
|
|
374 |
try { |
|
375 |
result = (Boolean) helper.doConnectionAction(action); |
|
376 |
} catch (Exception e) { |
|
377 |
throw new RuntimeException(e); |
|
378 |
} |
|
379 |
|
|
380 |
return result.booleanValue(); } |
|
269 | 381 |
/** |
270 | 382 |
* create new table |
271 | 383 |
* |
... | ... | |
323 | 435 |
sqlnewtable.append(", "); |
324 | 436 |
sqlnewtable.append(pk); |
325 | 437 |
|
326 |
sqlnewtable.append("); ");
|
|
438 |
sqlnewtable.append(")"); |
|
327 | 439 |
final String sqlCreateNew = sqlnewtable.toString(); |
328 | 440 |
|
329 | 441 |
// SQL CREATE SPATIAL INDEX |
... | ... | |
363 | 475 |
st.execute(sqlnew); |
364 | 476 |
|
365 | 477 |
} catch (SQLException e) { |
478 |
try { st.close(); } catch (SQLException se) { logger.error("Exception closing statement", se); } |
|
366 | 479 |
throw new JDBCExecuteSQLException(sqlnew, e); |
367 | 480 |
} |
368 |
// new spatial index
|
|
481 |
// new metadata
|
|
369 | 482 |
try { |
370 |
sqlspatialindex = sqlindex; |
|
371 |
st.execute(sqlspatialindex); |
|
372 |
|
|
483 |
sqlmetadata = sqlmeta; |
|
484 |
st.execute(sqlmetadata); |
|
373 | 485 |
} catch (SQLException e) { |
486 |
try { st.close(); } catch (SQLException se) { logger.error("Exception closing statement", se); } |
|
374 | 487 |
throw new JDBCExecuteSQLException(sqlspatialindex, e); |
375 | 488 |
} |
376 |
// new metadata
|
|
489 |
// new spatial index
|
|
377 | 490 |
try { |
378 |
sqlmetadata = sqlmeta;
|
|
379 |
st.execute(sqlmetadata);
|
|
491 |
sqlspatialindex = sqlindex;
|
|
492 |
st.execute(sqlspatialindex);
|
|
380 | 493 |
|
381 | 494 |
} catch (SQLException e) { |
495 |
try { st.close(); } catch (SQLException se) { logger.error("Exception closing statement", se); } |
|
382 | 496 |
throw new JDBCExecuteSQLException(sqlspatialindex, e); |
383 |
} finally { |
|
384 |
try { |
|
385 |
st.close(); |
|
386 |
} catch (SQLException e) { |
|
387 |
logger.error("Exception clossing statement", e); |
|
388 |
} |
|
389 |
; |
|
390 | 497 |
} |
391 | 498 |
|
392 | 499 |
return Boolean.TRUE; |
... | ... | |
476 | 583 |
*/ |
477 | 584 |
protected JDBCStoreParameters createStoreParams() |
478 | 585 |
throws InitializeException, ProviderNotRegisteredException { |
479 |
OracleStoreParameters params = (OracleStoreParameters) super |
|
480 |
.createStoreParams(); |
|
586 |
OracleStoreParameters params = (OracleStoreParameters) super.createStoreParams(); |
|
481 | 587 |
// add SSL and type driver (THIN or OCI) |
588 |
params.setSchema(params.getUser()); |
|
482 | 589 |
params.setUseSSL(this.getOracleServerExplorerParameters().getUseSSL()); |
483 | 590 |
params.setOraDriverType(this.getOracleServerExplorerParameters() |
484 | 591 |
.getOraDriverType()); |
Also available in: Unified diff