Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 177:77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
artifacts/trunk@1403 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 06 Mar 2011 10:03:53 +0000 |
parents | a0eff2227588 |
children | 535e4ea2ef9b |
comparison
equal
deleted
inserted
replaced
176:a0eff2227588 | 177:77cd37a93fca |
---|---|
334 public String newIdentifier() { | 334 public String newIdentifier() { |
335 // TODO: check database for collisions. | 335 // TODO: check database for collisions. |
336 return StringUtils.newUUID(); | 336 return StringUtils.newUUID(); |
337 } | 337 } |
338 | 338 |
339 public boolean isValidIdentifier(String identifier) { | |
340 return StringUtils.checkUUID(identifier); | |
341 } | |
342 | |
339 /** | 343 /** |
340 * Stores a new artifact into the database. | 344 * Stores a new artifact into the database. |
341 * @param artifact The artifact to be stored | 345 * @param artifact The artifact to be stored |
342 * @param factory The factory which build the artifact | 346 * @param factory The factory which build the artifact |
343 * @param ttl The initial time to life of the artifact. | 347 * @param ttl The initial time to life of the artifact. |
443 */ | 447 */ |
444 public Object loadArtifact( | 448 public Object loadArtifact( |
445 final String identifer, | 449 final String identifer, |
446 final ArtifactLoader loader | 450 final ArtifactLoader loader |
447 ) { | 451 ) { |
448 if (!StringUtils.checkUUID(identifer)) { | 452 if (!isValidIdentifier(identifer)) { |
449 return null; | 453 return null; |
450 } | 454 } |
451 | 455 |
452 final Object [] loaded = new Object[1]; | 456 final Object [] loaded = new Object[1]; |
453 | 457 |
547 final ArtifactFactory factory, | 551 final ArtifactFactory factory, |
548 final Long ttl | 552 final Long ttl |
549 ) { | 553 ) { |
550 final String uuid = artifact.identifier(); | 554 final String uuid = artifact.identifier(); |
551 | 555 |
552 if (!StringUtils.checkUUID(uuid)) { | 556 if (!isValidIdentifier(uuid)) { |
553 throw new RuntimeException("No valid UUID"); | 557 throw new RuntimeException("No valid UUID"); |
554 } | 558 } |
555 | 559 |
556 final int [] id = new int[1]; | 560 final int [] id = new int[1]; |
557 | 561 |
779 return exec.runWrite() ? user[0] : null; | 783 return exec.runWrite() ? user[0] : null; |
780 } | 784 } |
781 | 785 |
782 public boolean deleteUser(final String identifier) { | 786 public boolean deleteUser(final String identifier) { |
783 | 787 |
784 if (!StringUtils.checkUUID(identifier)) { | 788 if (!isValidIdentifier(identifier)) { |
785 return false; | 789 return false; |
786 } | 790 } |
787 | 791 |
788 SQLExecutor exec = new SQLExecutor() { | 792 SQLExecutor exec = new SQLExecutor() { |
789 public boolean doIt() throws SQLException { | 793 public boolean doIt() throws SQLException { |
842 public User getUser( | 846 public User getUser( |
843 final String identifier, | 847 final String identifier, |
844 final UserFactory factory, | 848 final UserFactory factory, |
845 final Object context | 849 final Object context |
846 ) { | 850 ) { |
847 if (!StringUtils.checkUUID(identifier)) { | 851 if (!isValidIdentifier(identifier)) { |
848 logger.debug("Invalid UUID: '" + identifier + "'"); | 852 logger.debug("Invalid UUID: '" + identifier + "'"); |
849 return null; | 853 return null; |
850 } | 854 } |
851 | 855 |
852 final User [] user = new User[1]; | 856 final User [] user = new User[1]; |
915 if (name == null) { | 919 if (name == null) { |
916 logger.debug("Name is null"); | 920 logger.debug("Name is null"); |
917 return null; | 921 return null; |
918 } | 922 } |
919 | 923 |
920 if (!StringUtils.checkUUID(ownerIdentifier)) { | 924 if (!isValidIdentifier(ownerIdentifier)) { |
921 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); | 925 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); |
922 return null; | 926 return null; |
923 } | 927 } |
924 | 928 |
925 final ArtifactCollection [] collection = | 929 final ArtifactCollection [] collection = |
1006 final ArtifactCollectionFactory collectionFactory, | 1010 final ArtifactCollectionFactory collectionFactory, |
1007 final UserFactory userFactory, | 1011 final UserFactory userFactory, |
1008 final Object context | 1012 final Object context |
1009 ) { | 1013 ) { |
1010 if (ownerIdentifier != null | 1014 if (ownerIdentifier != null |
1011 && !StringUtils.checkUUID(ownerIdentifier)) { | 1015 && !isValidIdentifier(ownerIdentifier)) { |
1012 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); | 1016 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); |
1013 return null; | 1017 return null; |
1014 } | 1018 } |
1015 | 1019 |
1016 final ArrayList<ArtifactCollection> collections = | 1020 final ArrayList<ArtifactCollection> collections = |
1061 : null; | 1065 : null; |
1062 } | 1066 } |
1063 | 1067 |
1064 | 1068 |
1065 public boolean deleteCollection(final String collectionId) { | 1069 public boolean deleteCollection(final String collectionId) { |
1066 if (!StringUtils.checkUUID(collectionId)) { | 1070 if (!isValidIdentifier(collectionId)) { |
1067 logger.debug("Invalid collection id: '" + collectionId + "'"); | 1071 logger.debug("Invalid collection id: '" + collectionId + "'"); |
1068 return false; | 1072 return false; |
1069 } | 1073 } |
1070 SQLExecutor exec = new SQLExecutor() { | 1074 SQLExecutor exec = new SQLExecutor() { |
1071 public boolean doIt() throws SQLException { | 1075 public boolean doIt() throws SQLException { |
1124 public boolean addCollectionArtifact( | 1128 public boolean addCollectionArtifact( |
1125 final String collectionId, | 1129 final String collectionId, |
1126 final String artifactId, | 1130 final String artifactId, |
1127 final Document attribute | 1131 final Document attribute |
1128 ) { | 1132 ) { |
1129 if (!StringUtils.checkUUID(collectionId)) { | 1133 if (!isValidIdentifier(collectionId)) { |
1130 logger.debug("Invalid collection id: '" + collectionId + "'"); | 1134 logger.debug("Invalid collection id: '" + collectionId + "'"); |
1131 return false; | 1135 return false; |
1132 } | 1136 } |
1133 | 1137 |
1134 if (!StringUtils.checkUUID(artifactId)) { | 1138 if (!isValidIdentifier(artifactId)) { |
1135 logger.debug("Invalid artifact id: '" + artifactId + "'"); | 1139 logger.debug("Invalid artifact id: '" + artifactId + "'"); |
1136 return false; | 1140 return false; |
1137 } | 1141 } |
1138 | 1142 |
1139 SQLExecutor exec = new SQLExecutor() { | 1143 SQLExecutor exec = new SQLExecutor() { |