Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java @ 1003:c58da6dd15ed
Datacage: Update collection names on change. Remove artifacts from collections.
flys-artifacts/trunk@2443 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 01 Aug 2011 16:53:54 +0000 |
parents | db86c665ab6e |
children | 0e8c03b69627 |
comparison
equal
deleted
inserted
replaced
1002:db86c665ab6e | 1003:c58da6dd15ed |
---|---|
63 private String SQL_INSERT_ARTIFACT_DATA = "insert.artifact.data"; | 63 private String SQL_INSERT_ARTIFACT_DATA = "insert.artifact.data"; |
64 private String SQL_OUT_ID_NEXTVALUE = "out.id.nextval"; | 64 private String SQL_OUT_ID_NEXTVALUE = "out.id.nextval"; |
65 private String SQL_INSERT_OUT = "insert.out"; | 65 private String SQL_INSERT_OUT = "insert.out"; |
66 private String SQL_FACET_ID_NEXTVAL = "facet.id.nextval"; | 66 private String SQL_FACET_ID_NEXTVAL = "facet.id.nextval"; |
67 private String SQL_INSERT_FACET = "insert.facet"; | 67 private String SQL_INSERT_FACET = "insert.facet"; |
68 private String SQL_UPDATE_COLLECTION_NAME = "update.collection.name"; | |
69 private String SQL_DELETE_ARTIFACT_FROM_COLLECTION = | |
70 "delete.artifact.from.collection"; | |
68 | 71 |
69 protected SQLExecutor sqlExecutor; | 72 protected SQLExecutor sqlExecutor; |
70 | 73 |
71 public class InitialScan | 74 public class InitialScan |
72 implements ArtifactDatabase.ArtifactLoadedCallback | 75 implements ArtifactDatabase.ArtifactLoadedCallback |
347 SQL_INSERT_ARTIFACT_DATA = sql.get(SQL_INSERT_ARTIFACT_DATA); | 350 SQL_INSERT_ARTIFACT_DATA = sql.get(SQL_INSERT_ARTIFACT_DATA); |
348 SQL_OUT_ID_NEXTVALUE = sql.get(SQL_OUT_ID_NEXTVALUE); | 351 SQL_OUT_ID_NEXTVALUE = sql.get(SQL_OUT_ID_NEXTVALUE); |
349 SQL_INSERT_OUT = sql.get(SQL_INSERT_OUT); | 352 SQL_INSERT_OUT = sql.get(SQL_INSERT_OUT); |
350 SQL_FACET_ID_NEXTVAL = sql.get(SQL_FACET_ID_NEXTVAL); | 353 SQL_FACET_ID_NEXTVAL = sql.get(SQL_FACET_ID_NEXTVAL); |
351 SQL_INSERT_FACET = sql.get(SQL_INSERT_FACET); | 354 SQL_INSERT_FACET = sql.get(SQL_INSERT_FACET); |
355 SQL_UPDATE_COLLECTION_NAME = sql.get(SQL_UPDATE_COLLECTION_NAME); | |
356 SQL_DELETE_ARTIFACT_FROM_COLLECTION = | |
357 sql.get(SQL_DELETE_ARTIFACT_FROM_COLLECTION); | |
352 } | 358 } |
353 | 359 |
354 protected static final int numFacets(List<Output> outs) { | 360 protected static final int numFacets(List<Output> outs) { |
355 int sum = 0; | 361 int sum = 0; |
356 for (Output out: outs) { | 362 for (Output out: outs) { |
550 ) { | 556 ) { |
551 log.debug("addedArtifactToCollection"); | 557 log.debug("addedArtifactToCollection"); |
552 } | 558 } |
553 | 559 |
554 public void removedArtifactFromCollection( | 560 public void removedArtifactFromCollection( |
555 String artifactId, | 561 final String artifactId, |
556 String collectionId, | 562 final String collectionId, |
557 Backend backend, | 563 Backend backend, |
558 GlobalContext context | 564 GlobalContext context |
559 ) { | 565 ) { |
560 log.debug("removedArtifactFromCollection"); | 566 log.debug("removedArtifactFromCollection"); |
567 SQLExecutor.Instance exec = sqlExecutor.new Instance() { | |
568 @Override | |
569 public boolean doIt() throws SQLException { | |
570 prepareStatement(SQL_ARTIFACT_BY_GID); | |
571 stmnt.setString(1, artifactId); | |
572 result = stmnt.executeQuery(); | |
573 if (!result.next()) { | |
574 return false; | |
575 } | |
576 int aId = result.getInt(1); | |
577 reset(); | |
578 prepareStatement(SQL_COLLECTION_BY_GID); | |
579 stmnt.setString(1, collectionId); | |
580 result = stmnt.executeQuery(); | |
581 if (!result.next()) { | |
582 return false; | |
583 } | |
584 int cId = result.getInt(1); | |
585 reset(); | |
586 prepareStatement(SQL_DELETE_ARTIFACT_FROM_COLLECTION); | |
587 stmnt.setInt(1, cId); | |
588 stmnt.setInt(2, aId); | |
589 stmnt.execute(); | |
590 conn.commit(); | |
591 return true; | |
592 } | |
593 }; | |
594 if (!exec.runWrite()) { | |
595 log.error("removing artifact from collection failed"); | |
596 } | |
561 } | 597 } |
562 | 598 |
563 public void setCollectionName( | 599 public void setCollectionName( |
564 String collectionId, | 600 final String collectionId, |
565 String name, | 601 final String name, |
566 GlobalContext context | 602 GlobalContext context |
567 ) { | 603 ) { |
568 log.debug("setCollectionName"); | 604 log.debug("setCollectionName"); |
605 SQLExecutor.Instance exec = sqlExecutor.new Instance() { | |
606 @Override | |
607 public boolean doIt() throws SQLException { | |
608 prepareStatement(SQL_UPDATE_COLLECTION_NAME); | |
609 stmnt.setString(1, name); | |
610 stmnt.setString(2, collectionId); | |
611 stmnt.execute(); | |
612 conn.commit(); | |
613 return true; | |
614 } | |
615 }; | |
616 if (!exec.runWrite()) { | |
617 log.error("changing name failed"); | |
618 } | |
569 } | 619 } |
570 | 620 |
571 protected void storeData( | 621 protected void storeData( |
572 final int artifactId, | 622 final int artifactId, |
573 FLYSArtifact artifact | 623 FLYSArtifact artifact |
711 | 761 |
712 if (!exec.runWrite()) { | 762 if (!exec.runWrite()) { |
713 log.error("storing facets failed"); | 763 log.error("storing facets failed"); |
714 } | 764 } |
715 } | 765 } |
716 | |
717 } | 766 } |
718 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 767 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |