Revision 31889 branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleServerExplorer.java
OracleServerExplorer.java | ||
---|---|---|
58 | 58 |
import org.gvsig.fmap.dal.store.jdbc.TransactionalAction; |
59 | 59 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException; |
60 | 60 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
61 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
62 |
import org.gvsig.oracle.extension.ExportToOracle; |
|
61 | 63 |
import org.slf4j.Logger; |
62 | 64 |
import org.slf4j.LoggerFactory; |
63 | 65 |
|
... | ... | |
377 | 379 |
throw new RuntimeException(e); |
378 | 380 |
} |
379 | 381 |
|
380 |
return result.booleanValue(); } |
|
381 |
/** |
|
382 |
* create new table |
|
383 |
* |
|
384 |
* @params ndsp |
|
385 |
* @params overwrite |
|
386 |
* @return |
|
387 |
*/ |
|
388 |
public boolean add(NewDataStoreParameters ndsp, boolean overwrite) |
|
389 |
throws DataException { |
|
382 |
return result.booleanValue(); |
|
383 |
} |
|
384 |
|
|
385 |
public void addWithEnvelopeAndDims(NewFeatureStoreParameters params, boolean b, |
|
386 |
Rectangle2D envelope, int thedims) throws DataException { |
|
387 |
|
|
388 |
String sql_create = add_SqlCreate(params, b); |
|
389 |
String sql_index = add_SqlIndex(params, b); |
|
390 |
String sql_meta = add_SqlMeta(params, b, envelope, new Integer(thedims)); |
|
391 |
doAdd(sql_create, sql_index, sql_meta); |
|
392 |
} |
|
390 | 393 |
|
391 |
if (!(ndsp instanceof NewFeatureStoreParameters)) { |
|
392 |
throw new IllegalArgumentException(); |
|
393 |
} |
|
394 |
this.checkIsMine(ndsp); |
|
395 |
|
|
396 |
NewFeatureStoreParameters nfdsp = (NewFeatureStoreParameters) ndsp; |
|
397 |
|
|
398 |
// SQL CREATE NEW TABLE |
|
399 |
StringBuilder sqlnewtable = new StringBuilder(); |
|
400 |
|
|
401 |
if (!nfdsp.isValid()) { |
|
402 |
throw new InitializeException(this.getName(), new Exception( |
|
403 |
"Parameters not valid")); |
|
404 |
} |
|
405 |
try { |
|
406 |
nfdsp.validate(); |
|
407 |
} catch (ValidateDataParametersException e1) { |
|
408 |
throw new InitializeException(this.getName(), e1); |
|
409 |
} |
|
410 |
|
|
411 |
FeatureType fType = nfdsp.getDefaultFeatureType(); |
|
412 |
|
|
413 |
sqlnewtable.append("CREATE TABLE " |
|
414 |
+ ((JDBCStoreParameters) ndsp).tableID() + "("); |
|
415 |
Iterator<FeatureAttributeDescriptor> attrs = fType.iterator(); |
|
416 |
String sqlAttr; |
|
417 |
List<String> sqlAttrs = new ArrayList<String>(); |
|
418 |
|
|
419 |
while (attrs.hasNext()) { |
|
420 |
sqlAttr = helper |
|
421 |
.getSqlFieldDescription((FeatureAttributeDescriptor) attrs |
|
422 |
.next()); |
|
423 |
if (sqlAttr != null) { |
|
424 |
sqlAttrs.add(sqlAttr); |
|
425 |
} |
|
426 |
} |
|
427 |
|
|
428 |
helper.stringJoin(sqlAttrs, ", ", sqlnewtable); |
|
429 |
|
|
430 |
String pk = "CONSTRAINT " |
|
431 |
+ OracleUtils.getDerivedName(((JDBCStoreParameters) ndsp) |
|
432 |
.tableID(), "PK") + " PRIMARY KEY (\"" |
|
433 |
+ OracleValues.DEFAULT_ID_FIELD_CASE_SENSITIVE + "\") ENABLE"; |
|
434 |
|
|
435 |
sqlnewtable.append(", "); |
|
436 |
sqlnewtable.append(pk); |
|
437 |
|
|
438 |
sqlnewtable.append(")"); |
|
439 |
final String sqlCreateNew = sqlnewtable.toString(); |
|
440 |
|
|
441 |
// SQL CREATE SPATIAL INDEX |
|
442 |
final String sqlindex = "CREATE INDEX " |
|
443 |
+ OracleUtils.getDerivedName(((JDBCStoreParameters) ndsp) |
|
444 |
.tableID(), "SX") + " ON " |
|
445 |
+ ((JDBCStoreParameters) ndsp).tableID() + " (\"" |
|
446 |
+ OracleValues.DEFAULT_GEO_FIELD |
|
447 |
+ "\") INDEXTYPE IS \"MDSYS\".\"SPATIAL_INDEX\" "; |
|
448 |
|
|
449 |
// SQL CREATE TABLE METADATA |
|
450 |
Rectangle2D bbox = new Rectangle2D.Double(0, 0, 1, 1); |
|
451 |
final String sqlmeta = ((OracleHelper) helper).getSqlUpdateMetadata( |
|
452 |
(OracleStoreParameters) ndsp, null, bbox, 2, true); |
|
453 |
|
|
394 |
private boolean doAdd(final String sql_create, final String sql_index, final String sql_meta) { |
|
395 |
|
|
454 | 396 |
TransactionalAction action = new TransactionalAction() { |
455 | 397 |
|
456 | 398 |
public boolean continueTransactionAllowed() { |
... | ... | |
471 | 413 |
|
472 | 414 |
// new table |
473 | 415 |
try { |
474 |
sqlnew = sqlCreateNew;
|
|
416 |
sqlnew = sql_create;
|
|
475 | 417 |
st.execute(sqlnew); |
476 | 418 |
|
477 | 419 |
} catch (SQLException e) { |
... | ... | |
480 | 422 |
} |
481 | 423 |
// new metadata |
482 | 424 |
try { |
483 |
sqlmetadata = sqlmeta; |
|
425 |
sqlmetadata = sql_meta;
|
|
484 | 426 |
st.execute(sqlmetadata); |
485 | 427 |
} catch (SQLException e) { |
486 | 428 |
try { st.close(); } catch (SQLException se) { logger.error("Exception closing statement", se); } |
... | ... | |
488 | 430 |
} |
489 | 431 |
// new spatial index |
490 | 432 |
try { |
491 |
sqlspatialindex = sqlindex; |
|
433 |
sqlspatialindex = sql_index;
|
|
492 | 434 |
st.execute(sqlspatialindex); |
493 | 435 |
|
494 | 436 |
} catch (SQLException e) { |
... | ... | |
512 | 454 |
return result.booleanValue(); |
513 | 455 |
} |
514 | 456 |
|
457 |
private String add_SqlMeta(NewFeatureStoreParameters params, boolean b, |
|
458 |
Rectangle2D bbox, Integer thedims) { |
|
459 |
|
|
460 |
// SQL CREATE TABLE METADATA |
|
461 |
Rectangle2D _bbox = bbox; |
|
462 |
if (_bbox == null) { |
|
463 |
logger.warn("Envelope not found in parameters: set (0,0) - (1,1)"); |
|
464 |
_bbox = OracleUtils.DEFAULT_BBOX; |
|
465 |
} |
|
466 |
|
|
467 |
int _dims = 2; |
|
468 |
if (thedims == null) { |
|
469 |
logger.warn("Dimensions not found in parameters: assumed 2"); |
|
470 |
} else { |
|
471 |
_dims = thedims.intValue(); |
|
472 |
} |
|
473 |
|
|
474 |
String sqlmeta = ((OracleHelper) helper).getSqlUpdateMetadata( |
|
475 |
(OracleStoreParameters) params, null, _bbox, _dims, true); |
|
476 |
// TODO Auto-generated method stub |
|
477 |
return sqlmeta; |
|
478 |
} |
|
479 |
|
|
480 |
private String add_SqlIndex(NewFeatureStoreParameters params, boolean b) { |
|
481 |
|
|
482 |
// SQL CREATE SPATIAL INDEX |
|
483 |
String sqlindex = "CREATE INDEX " |
|
484 |
+ OracleUtils.getDerivedName(((JDBCStoreParameters) params) |
|
485 |
.tableID(), "SX") + " ON " |
|
486 |
+ ((JDBCStoreParameters) params).tableID() + " (\"" |
|
487 |
+ OracleValues.DEFAULT_GEO_FIELD |
|
488 |
+ "\") INDEXTYPE IS \"MDSYS\".\"SPATIAL_INDEX\" "; |
|
489 |
return sqlindex; |
|
490 |
} |
|
491 |
|
|
492 |
private String add_SqlCreate(NewFeatureStoreParameters nfdsp, boolean b) throws DataException { |
|
493 |
|
|
494 |
// SQL CREATE NEW TABLE |
|
495 |
StringBuilder sqlnewtable = new StringBuilder(); |
|
496 |
|
|
497 |
FeatureType fType = nfdsp.getDefaultFeatureType(); |
|
498 |
|
|
499 |
sqlnewtable.append("CREATE TABLE " |
|
500 |
+ ((JDBCStoreParameters) nfdsp).tableID() + "("); |
|
501 |
Iterator<FeatureAttributeDescriptor> attrs = fType.iterator(); |
|
502 |
String sqlAttr; |
|
503 |
List<String> sqlAttrs = new ArrayList<String>(); |
|
504 |
|
|
505 |
while (attrs.hasNext()) { |
|
506 |
sqlAttr = helper |
|
507 |
.getSqlFieldDescription((FeatureAttributeDescriptor) attrs |
|
508 |
.next()); |
|
509 |
if (sqlAttr != null) { |
|
510 |
sqlAttrs.add(sqlAttr); |
|
511 |
} |
|
512 |
} |
|
513 |
|
|
514 |
helper.stringJoin(sqlAttrs, ", ", sqlnewtable); |
|
515 |
|
|
516 |
String pk = "CONSTRAINT " |
|
517 |
+ OracleUtils.getDerivedName(((JDBCStoreParameters) nfdsp) |
|
518 |
.tableID(), "PK") + " PRIMARY KEY (\"" |
|
519 |
+ OracleValues.DEFAULT_ID_FIELD_CASE_SENSITIVE + "\") ENABLE"; |
|
520 |
|
|
521 |
sqlnewtable.append(", "); |
|
522 |
sqlnewtable.append(pk); |
|
523 |
|
|
524 |
sqlnewtable.append(")"); |
|
525 |
return sqlnewtable.toString(); |
|
526 |
|
|
527 |
} |
|
528 |
|
|
515 | 529 |
/** |
530 |
* create new table |
|
531 |
* |
|
532 |
* @params ndsp |
|
533 |
* @params overwrite |
|
534 |
* @return |
|
535 |
*/ |
|
536 |
public boolean add(NewDataStoreParameters ndsp, boolean overwrite) |
|
537 |
throws DataException { |
|
538 |
|
|
539 |
if (!(ndsp instanceof NewFeatureStoreParameters)) { |
|
540 |
throw new IllegalArgumentException("Expected: NewFeatureStoreParameters"); |
|
541 |
} |
|
542 |
|
|
543 |
checkIsMine(ndsp); |
|
544 |
NewFeatureStoreParameters nfdsp = (NewFeatureStoreParameters) ndsp; |
|
545 |
|
|
546 |
if (!nfdsp.isValid()) { |
|
547 |
throw new InitializeException(this.getName(), new Exception( |
|
548 |
"Parameters not valid")); |
|
549 |
} |
|
550 |
try { |
|
551 |
nfdsp.validate(); |
|
552 |
} catch (ValidateDataParametersException e1) { |
|
553 |
throw new InitializeException(this.getName(), e1); |
|
554 |
} |
|
555 |
|
|
556 |
String sql_create = add_SqlCreate(nfdsp, overwrite); |
|
557 |
String sql_index = add_SqlIndex(nfdsp, overwrite); |
|
558 |
String sql_meta = add_SqlMeta(nfdsp, overwrite, null, null); |
|
559 |
return doAdd(sql_create, sql_index, sql_meta); |
|
560 |
} |
|
561 |
|
|
562 |
/** |
|
516 | 563 |
* create helper |
517 | 564 |
*/ |
518 | 565 |
protected JDBCHelper createHelper() throws InitializeException { |
... | ... | |
601 | 648 |
private OracleServerExplorerParameters getOracleServerExplorerParameters() { |
602 | 649 |
return (OracleServerExplorerParameters) getParameters(); |
603 | 650 |
} |
604 |
|
|
651 |
|
|
605 | 652 |
} |
Also available in: Unified diff