Changeset 3372


Ignore:
Timestamp:
08/13/13 15:41:02 (11 years ago)
Author:
olhsha
Message:

removing cached given representation of a given source. tested as well.

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  
    6666   
    6767   
    68  
     68   
    6969 
    7070}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java

    r3299 r3372  
    7575    public int deleteVersionCachedRepresentationRow(Number versionID);
    7676   
     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);
    7791}
     92   
     93
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3330 r3372  
    123123
    124124        if (result.isEmpty()) {
    125             // rou can remove the cached representation
     125            // you can remove the cached representation
    126126            String sql = "DELETE FROM " + cachedRepresentationTableName + " where " + cached_representation_id + " = ?";
    127127            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  
    265265      return result;
    266266    }
    267 
     267   
     268 
    268269    //////// HELPERS //////////////////////
    269270    ////////////////////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java

    r3330 r3372  
    177177            return null;
    178178        }
    179        
     179
    180180        // adding the corresponding cached representation is initiated from the separate service POST api/sources/<sid>/cached
    181181        // so it is not implemented here
    182182    }
    183183
     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 ///////////////////////////////
    184216    private Version makeFreshCopy(Version version) {
    185217        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  
    177177
    178178 
    179  
     179    /**
     180     * test
     181     * public int deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID)
     182     *
     183     **/
    180184 
     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    }
    181215}
Note: See TracChangeset for help on using the changeset viewer.