Changeset 3372
- Timestamp:
- 08/13/13 15:41:02 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/CachedRepresentationDao.java
r3298 r3372 66 66 67 67 68 68 69 69 70 70 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java
r3299 r3372 75 75 public int deleteVersionCachedRepresentationRow(Number versionID); 76 76 77 78 /** 79 * 80 * @param sourceID 81 * @param cachedRepresentationID 82 * @return 83 * 1) the amount of rows affected by deleting cached representation "cachedRepresentationID" 84 * from the table "versions_cached_representations", if the corresponding version is a sibling-version of the source surceID 85 * 2) the amount of rows affected by SAFE removing cachedRepresentationID from cached_representation table, 86 * if the first number>0 87 * 88 * used to fulfill DELETE api/sources/<sid>/cached/<cid> 89 */ 90 public int[] deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID); 77 91 } 92 93 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r3330 r3372 123 123 124 124 if (result.isEmpty()) { 125 // rou can remove the cached representation125 // you can remove the cached representation 126 126 String sql = "DELETE FROM " + cachedRepresentationTableName + " where " + cached_representation_id + " = ?"; 127 127 return getSimpleJdbcTemplate().update(sql, internalID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3367 r3372 265 265 return result; 266 266 } 267 267 268 268 269 //////// HELPERS ////////////////////// 269 270 //////////////////////////////////////////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java
r3330 r3372 177 177 return null; 178 178 } 179 179 180 180 // adding the corresponding cached representation is initiated from the separate service POST api/sources/<sid>/cached 181 181 // so it is not implemented here 182 182 } 183 183 184 @Override 185 public int[] deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID) { 186 List<Number> versions = retrieveVersionList(sourceID); 187 int[] result = new int[2]; 188 189 if (versions == null) { 190 result[0] = 0; 191 result[1] = 0; 192 return result; 193 } 194 if (versions.isEmpty()) { 195 result[0] = 0; 196 result[1] = 0; 197 return result; 198 } 199 200 String values = makeListOfValues(versions); 201 StringBuilder sql = new StringBuilder("DELETE FROM "); 202 sql.append(versionsCachedRepresentationsTableName).append(" WHERE ").append(version_id).append(" IN ").append(values); 203 sql.append(" AND ").append(cached_representation_id).append(" = ?"); 204 result[0] = getSimpleJdbcTemplate().update(sql.toString(), cachedRepresentationID); 205 206 // safe remove from the DB 207 if (result[0] > 0) { 208 result[1] = jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedRepresentationID); 209 } else { 210 result[1] = 0; 211 } 212 return result; 213 } 214 215 ////////////////////// HELPERS /////////////////////////////// 184 216 private Version makeFreshCopy(Version version) { 185 217 Version result = new Version(); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java
r3299 r3372 177 177 178 178 179 179 /** 180 * test 181 * public int deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID) 182 * 183 **/ 180 184 185 186 @Test 187 public void tesDeleteCachedRepresentationForSource() { 188 System.out.println("test delete CachedRepresentationForSource"); 189 190 /// TEST 1 ///// 191 mockery.checking(new Expectations() { 192 { 193 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5); 194 will(returnValue(0)); 195 196 } 197 }); 198 int[] result = jdbcVersionDao.deleteCachedRepresentationForSource(1, 5); // source 1 has versions {1,2}, versions 1 and 2 have cached representations {1, 5} and {3} respectively 199 assertEquals(1, result[0]); 200 assertEquals(0, result[1]); //cahced representation 5 is also connected version 6, therefore cannot be removed 201 202 203 // TEST 2 //////// 204 mockery.checking(new Expectations() { 205 { 206 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(4); 207 will(returnValue(1)); 208 209 } 210 }); 211 int[] result_2 = jdbcVersionDao.deleteCachedRepresentationForSource(3, 4); //source 1 --> version 4 --> cached 4 212 assertEquals(1, result_2[0]); 213 assertEquals(1, result_2[1]); 214 } 181 215 }
Note: See TracChangeset
for help on using the changeset viewer.