comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 178:535e4ea2ef9b

Added code to get the attribute of a collection item artifacts/trunk@1404 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 06 Mar 2011 10:27:16 +0000
parents 77cd37a93fca
children 644fd11ddd9f
comparison
equal deleted inserted replaced
177:77cd37a93fca 178:535e4ea2ef9b
161 public static final String SQL_COLLECTION_ITEMS_ID_NEXTVAL = 161 public static final String SQL_COLLECTION_ITEMS_ID_NEXTVAL =
162 SQL.get("collection.check.artifact"); 162 SQL.get("collection.check.artifact");
163 163
164 public static final String SQL_COLLECTION_ITEMS_INSERT = 164 public static final String SQL_COLLECTION_ITEMS_INSERT =
165 SQL.get("collection.items.insert"); 165 SQL.get("collection.items.insert");
166
167 public static final String SQL_COLLECTION_ITEM_GET_ATTRIBUTE =
168 SQL.get("collection.item.get.attribute");
166 169
167 /** The singleton.*/ 170 /** The singleton.*/
168 protected static Backend instance; 171 protected static Backend instance;
169 172
170 /** 173 /**
1107 }; 1110 };
1108 return exec.runWrite(); 1111 return exec.runWrite();
1109 } 1112 }
1110 1113
1111 public Document getCollectionAttribute( 1114 public Document getCollectionAttribute(
1112 String collectionId, 1115 final String collectionId,
1113 String artifactId 1116 final String artifactId
1114 ) { 1117 ) {
1115 // TODO: Implement me! 1118 if (!isValidIdentifier(collectionId)) {
1116 return null; 1119 logger.debug("collection id is not valid: " + collectionId);
1120 return null;
1121 }
1122 if (!isValidIdentifier(artifactId)) {
1123 logger.debug("artifact id is not valid: " + artifactId);
1124 }
1125
1126 final Document [] document = new Document[1];
1127
1128 SQLExecutor exec = new SQLExecutor() {
1129 public boolean doIt() throws SQLException {
1130 prepareStatement(SQL_COLLECTION_ITEM_GET_ATTRIBUTE);
1131 stmnt.setString(1, collectionId);
1132 stmnt.setString(2, artifactId);
1133 result = stmnt.executeQuery();
1134 if (!result.next()) {
1135 logger.debug("No such collection item");
1136 return false;
1137 }
1138 document[0] = XMLUtils.fromByteArray(result.getBytes(1));
1139 return true;
1140 }
1141 };
1142
1143 return exec.runRead() ? document[0] : null;
1117 } 1144 }
1118 1145
1119 public boolean setCollectionAttribute( 1146 public boolean setCollectionAttribute(
1120 String collectionId, 1147 String collectionId,
1121 String artifactId, 1148 String artifactId,

http://dive4elements.wald.intevation.org