Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 179:644fd11ddd9f
Added code to set attribute of a collection item.
artifacts/trunk@1405 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 06 Mar 2011 10:55:37 +0000 |
parents | 535e4ea2ef9b |
children | 38fbbeffe8fe |
comparison
equal
deleted
inserted
replaced
178:535e4ea2ef9b | 179:644fd11ddd9f |
---|---|
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 | 166 |
167 public static final String SQL_COLLECTION_ITEM_GET_ATTRIBUTE = | 167 public static final String SQL_COLLECTION_ITEM_GET_ATTRIBUTE = |
168 SQL.get("collection.item.get.attribute"); | 168 SQL.get("collection.item.get.attribute"); |
169 | |
170 public static final String SQL_COLLECTION_ITEM_SET_ATTRIBUTE = | |
171 SQL.get("collection.item.set.attribute"); | |
172 | |
173 public static final String SQL_COLLECTIONS_TOUCH_BY_GID = | |
174 SQL.get("collections.touch.by,gid"); | |
169 | 175 |
170 /** The singleton.*/ | 176 /** The singleton.*/ |
171 protected static Backend instance; | 177 protected static Backend instance; |
172 | 178 |
173 /** | 179 /** |
1119 logger.debug("collection id is not valid: " + collectionId); | 1125 logger.debug("collection id is not valid: " + collectionId); |
1120 return null; | 1126 return null; |
1121 } | 1127 } |
1122 if (!isValidIdentifier(artifactId)) { | 1128 if (!isValidIdentifier(artifactId)) { |
1123 logger.debug("artifact id is not valid: " + artifactId); | 1129 logger.debug("artifact id is not valid: " + artifactId); |
1130 return null; | |
1124 } | 1131 } |
1125 | 1132 |
1126 final Document [] document = new Document[1]; | 1133 final Document [] document = new Document[1]; |
1127 | 1134 |
1128 SQLExecutor exec = new SQLExecutor() { | 1135 SQLExecutor exec = new SQLExecutor() { |
1142 | 1149 |
1143 return exec.runRead() ? document[0] : null; | 1150 return exec.runRead() ? document[0] : null; |
1144 } | 1151 } |
1145 | 1152 |
1146 public boolean setCollectionAttribute( | 1153 public boolean setCollectionAttribute( |
1147 String collectionId, | 1154 final String collectionId, |
1148 String artifactId, | 1155 final String artifactId, |
1149 Document attribute | 1156 Document attribute |
1150 ) { | 1157 ) { |
1151 // TODO: Implement me! | 1158 if (!isValidIdentifier(collectionId)) { |
1152 return false; | 1159 logger.debug("collection id is not valid: " + collectionId); |
1160 return false; | |
1161 } | |
1162 if (!isValidIdentifier(artifactId)) { | |
1163 logger.debug("artifact id is not valid: " + artifactId); | |
1164 return false; | |
1165 } | |
1166 | |
1167 final byte [] data = XMLUtils.toByteArray(attribute); | |
1168 | |
1169 return new SQLExecutor() { | |
1170 public boolean doIt() throws SQLException { | |
1171 | |
1172 // set the column in collection items | |
1173 prepareStatement(SQL_COLLECTION_ITEM_SET_ATTRIBUTE); | |
1174 if (data == null) { | |
1175 stmnt.setNull(1, Types.BINARY); | |
1176 } | |
1177 else { | |
1178 stmnt.setBytes(1, data); | |
1179 } | |
1180 stmnt.setString(2, collectionId); | |
1181 stmnt.setString(3, artifactId); | |
1182 stmnt.execute(); | |
1183 reset(); | |
1184 | |
1185 // touch the collection | |
1186 prepareStatement(SQL_COLLECTIONS_TOUCH_BY_GID); | |
1187 stmnt.setString(1, collectionId); | |
1188 stmnt.execute(); | |
1189 | |
1190 conn.commit(); | |
1191 return true; | |
1192 } | |
1193 }.runWrite(); | |
1153 } | 1194 } |
1154 | 1195 |
1155 public boolean addCollectionArtifact( | 1196 public boolean addCollectionArtifact( |
1156 final String collectionId, | 1197 final String collectionId, |
1157 final String artifactId, | 1198 final String artifactId, |