Changeset 3297


Ignore:
Timestamp:
08/07/13 11:56:51 (11 years ago)
Author:
olhsha
Message:

CachedRepresentationDao? and VersionDao? are simplfied and tested: purge is kicked off and delete takes care about safe removal (do not remove if the resource is referred by a another ressource) and removal of depending resources, like f version is removed then it cached repr are removed (unless they are referred by other versions)

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/CachedRepresentationDao.java

    r3272 r3297  
    4949    public List<Number> retrieveCachedRepresentationList(Number versionID);
    5050   
     51     
    5152    /**
    5253     *
    5354     * @param internalID
    54      * @return the amount of rows affected by removing from the DB the cached representation with the id "intenalID"
    55      * should be "1" (or 0 with  a non-existing id on the input)
    56      * as a obligadory side-effect: deletes all the rows in the table versions_cached_representations containing "internalId" as a cached_representaton_ID
     55     * removes the cached representation with internalId from the DB if there is no reference to it in the table "versions_cached_representations"
     56     * @return the amount of removed rows in the table "cached_representation"
    5757     */
    5858    public int deleteCachedRepresentationInfo(Number internalID);
     
    6565    public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached);
    6666   
    67    
    68     /**
    69      *
    70      * @param internalID
    71      * removes the version with internalId from the DB is there is no reference to to it n the table versions_cached_representations
    72      * @return the amount of removed rows
    73      */
    74     public int purge(Number internalID);
    7567   
    7668    /**
     
    8072    public List<Number> cachedRepresentationIDs();
    8173   
    82     /**
    83      * removes all the cahed representations which are not referred from the versions_cached_representations table
    84      * @return the number of affected rows
    85      */
    86     public int purgeAll();
     74 
    8775}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java

    r3292 r3297  
    5353    /**
    5454     *
    55      * @param internalID
    56      * @return delete the source with the internal ID "internalID"
     55     * @param internalId
     56     * removes the source with the ID "internalId" from the DB, if it is not a target source of some annotation
     57     * @return the amount of affected rows in the "source" table
    5758     */
    5859    public int deleteSource(Number internalID);
     
    6667    public Source addSource(Source freshSource);
    6768   
    68     /**
    69      *
    70      * @param internalId
    71      * removes the source with the ID "internalId" from the DB, if it is not a target source of some annotation
    72      * @return the amount of affected rows in the "source" table
    73      */
    74     public int purge(Number internalId);
    75    
     69   
    7670    /**
    7771     *
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java

    r3272 r3297  
    5252    public List<Number> retrieveVersionList(Number sourceID);
    5353   
    54     /**
    55      *
    56      * @param versionID
    57      * removes the version with the internal id "versionID". Obligatory side effect: removes the corresponding rows in the tables
    58      * "versions_cached_representations" and "sources_versions"
    59      * @return the number of affected rows in "version" table, which normally must be 1 (or 0 if there is no version with this inut "versionID")
     54     
     55    /** @param versionID
     56     * removes the row of "version" with the internal ID "internalID" if no references to this version from the tables "sources_versions" and "source"
     57     * @return the amount of removed rows
    6058     */
     59   
    6160    public int deleteVersion(Number versionID);
    6261   
     
    6867     */
    6968    public Version addVersion(Version version);
    70    
    71     /**
    72      * Removes the all the rows in the internal ID "internalID" if no references to this versions from the table sources.
    73      * @return the amount of removed rows
    74      */
    75     public int purge(Number internalID);
     69   
     70
    7671   
    7772    /**
     
    8176    public List<Number> versionIDs();
    8277   
    83     /**
    84      * removes all the versions which are not referred from the sources_versions table
    85      * @return
    86      */
    87     public int purgeAll();
    8878}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3292 r3297  
    9191
    9292    ;
    93      
    94       ////////////////////////////////////////////////////////////////////////////
    95       @Override
    96     public int deleteCachedRepresentationInfo(Number internalID) {
    97         String sql = "DELETE FROM " + cachedRepresentationTableName + " where " + cached_representation_id + " = ?";
    98         return (getSimpleJdbcTemplate().update(sql, internalID));
    99     }
    100 
    101    
    10293     
    10394      ////////////////////////////////////////////////////////////////////////////
     
    123114    //////////////////////////////////////////////////////////////////////////////////////////////
    124115    @Override
    125     public int purge(Number internalID) {
     116    public int deleteCachedRepresentationInfo(Number internalID) {
     117        //check if there are versions referring to the cached with the "internalID"
    126118        String sqlCheck = "SELECT " + cached_representation_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + cached_representation_id + "= ?";
    127119        List<Number> result = getSimpleJdbcTemplate().query(sqlCheck, cachedRepresentationCheckerRowMapper, internalID);
    128         if (result.size() < 1) {
     120       
     121        if (result.isEmpty()) {
     122            // remove the cached representation safely
    129123            String sql = "DELETE FROM " + cachedRepresentationTableName + " where " + cached_representation_id + " = ?";
    130124            return getSimpleJdbcTemplate().update(sql, internalID);
    131125        } else {
     126            // do not delete, it is in use!!
    132127            return 0;
    133128        }
    134129    }
     130   
    135131    private final RowMapper<Number> cachedRepresentationCheckerRowMapper = new RowMapper<Number>() {
    136132        @Override
     
    156152    };
    157153
    158     @Override
    159     public int purgeAll() {
    160         List<Number> ids = cachedRepresentationIDs();
    161         return super.purgeAll(ids, this);
    162     }
     154   
    163155
    164156    ////////// Helpers ///////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3292 r3297  
    3535    final static protected String notebookTableName = "notebook";
    3636    final static protected String annotationTableName = "annotation";
    37     final static protected String sourceTableName = "source";   
    38     final static protected String sourcesTableName = "target_source";
     37    final static protected String sourceTableName = "target_source";
    3938    final static protected String cachedRepresentationTableName = "cached_representation_info";
    4039    final static protected String versionTableName = "version";
     
    210209    }
    211210   
    212     ///////////////////////////////////////////////
    213    
    214     protected int purge(Number id){
    215         return 0;
    216     }
    217    
    218     protected <T extends JdbcResourceDao> int purgeAll(List<Number> ids, T instance) {
    219          int countRemoved = 0;
    220          for (Number id: ids){
    221              countRemoved = countRemoved + instance.purge(id);
    222          }
    223          return countRemoved;
    224     }
    225211}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java

    r3292 r3297  
    7676   
    7777    public Source getSource(Number internalID) {
    78        String sql = "SELECT "+sourceStar+"FROM "+sourcesTableName+" WHERE "+source_id  +" = ?";
     78       String sql = "SELECT "+sourceStar+"FROM "+sourceTableName+" WHERE "+source_id  +" = ?";
    7979       List<Source> result= getSimpleJdbcTemplate().query(sql, SourceRowMapper, internalID);       
    8080       return result.get(0);
     
    108108   
    109109   
    110     public int purge(Number internalId){
    111         return -1;
    112     }
    113    
    114    
    115110    public List<Number> sourceIDs(){
    116111        return null;
     
    126121    public List<SourceInfo> getSourceInfos(Number annotationID){
    127122       String sourceIDs = makeListOfValues(retrieveSourceIDs(annotationID));
    128        String sql = "SELECT "+external_id+","+ link +"," + version+"FROM "+sourcesTableName+" WHERE "+source_id  +" IN "+sourceIDs;
     123       String sql = "SELECT "+external_id+","+ link +"," + version+"FROM "+sourceTableName+" WHERE "+source_id  +" IN "+sourceIDs;
    129124       List<SourceInfo> result= getSimpleJdbcTemplate().query(sql, SourceInfoRowMapper);       
    130125       return result;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java

    r3272 r3297  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
    2021import eu.dasish.annotation.backend.dao.VersionDao;
    2122import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
     
    2728import java.util.Map;
    2829import javax.sql.DataSource;
     30import org.springframework.beans.factory.annotation.Autowired;
    2931import org.springframework.jdbc.core.RowMapper;
    3032
     
    3335 * @author olhsha
    3436 */
    35 public class JdbcVersionDao extends JdbcResourceDao implements VersionDao{
    36    
    37       public JdbcVersionDao(DataSource dataSource) {         
    38         setDataSource(dataSource);       
     37public class JdbcVersionDao extends JdbcResourceDao implements VersionDao {
     38
     39    @Autowired
     40    CachedRepresentationDao jdbcCachedRepresentationDao;
     41
     42    public JdbcVersionDao(DataSource dataSource) {
     43        setDataSource(dataSource);
    3944        internalIdName = version_id;
    4045        resourceTableName = versionTableName;
    4146    }
    42      
    43        //////////////////////////////////////////////////////////////////////////////////////////////////////   
    44       @Override
    45       public VersionIdentifier getExternalID(Number internalID){
    46           return new VersionIdentifier(super.getExternalIdentifier(internalID));
    47       }
    48       ///////////////////////////////////////////////////////////////
    49      @Override
    50      public Version getVersion(Number internalID){
    51          
    52        String sql = "SELECT "+versionStar+" FROM "+versionTableName+" WHERE "+version_id  +"= ?";
    53        List<Version> result= getSimpleJdbcTemplate().query(sql, versionRowMapper, internalID);
    54        
    55        if (result == null) {
    56            return null;
    57        }
    58        if (result.isEmpty()) {
    59            return null;
    60        }
    61        return result.get(0);
    62      }
    63      
    64      private final RowMapper<Version> versionRowMapper = new RowMapper<Version>() {       
     47
     48    //////////////////////////////////////////////////////////////////////////////////////////////////////   
     49    @Override
     50    public VersionIdentifier getExternalID(Number internalID) {
     51        return new VersionIdentifier(super.getExternalIdentifier(internalID));
     52    }
     53    ///////////////////////////////////////////////////////////////
     54
     55    @Override
     56    public Version getVersion(Number internalID) {
     57
     58        String sql = "SELECT " + versionStar + " FROM " + versionTableName + " WHERE " + version_id + "= ?";
     59        List<Version> result = getSimpleJdbcTemplate().query(sql, versionRowMapper, internalID);
     60
     61        if (result == null) {
     62            return null;
     63        }
     64        if (result.isEmpty()) {
     65            return null;
     66        }
     67        return result.get(0);
     68    }
     69    private final RowMapper<Version> versionRowMapper = new RowMapper<Version>() {
    6570        @Override
    6671        public Version mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    7277            return result;
    7378        }
    74      };
    75      
    76      
    77      
    78      /////////////////////////////////////////
    79      
     79    };
     80
     81    /////////////////////////////////////////
    8082    @Override
    81     public List<Number> retrieveVersionList(Number sourceID){
    82        String sql = "SELECT "+version_id+" FROM "+sourcesVersionsTableName+" WHERE "+source_id + " = ?";
    83        List<Number> result= getSimpleJdbcTemplate().query(sql, versionsSourcesRunnerRowMapper, sourceID);
    84        return result;
    85      }
    86      
    87      private final RowMapper<Number> versionsSourcesRunnerRowMapper = new RowMapper<Number>() {       
     83    public List<Number> retrieveVersionList(Number sourceID) {
     84        String sql = "SELECT " + version_id + " FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?";
     85        List<Number> result = getSimpleJdbcTemplate().query(sql, versionsSourcesRunnerRowMapper, sourceID);
     86        return result;
     87    }
     88    private final RowMapper<Number> versionsSourcesRunnerRowMapper = new RowMapper<Number>() {
    8889        @Override
    8990        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    9192            return result;
    9293        }
    93      };
    94      
     94    };
     95
     96    /////////////////////////////////////////
     97    //TODO: refactor ???
     98    @Override
     99    public int deleteVersion(Number internalID) {
     100
     101        // check if there are sources referring to the version with "internalID", in the table "sources"versions"
     102        String sqlSourcesVersions = "SELECT " + source_id + " FROM " + sourcesVersionsTableName + " WHERE " + version_id + "= ?";
     103        List<Number> resultSourcesVersions = getSimpleJdbcTemplate().query(sqlSourcesVersions, sourcesVersionsRowMapper, internalID);
     104       
     105        // check if there is a source referring to the version "intrenalID", in the table "source"
     106        String sqlSource = "SELECT " + source_id + " FROM " + sourceTableName + " WHERE " + version_id + "= ?";
     107        List<Number> resultSource = getSimpleJdbcTemplate().query(sqlSource, sourceRowMapper, internalID);
     108       
     109
     110        if (resultSourcesVersions.isEmpty() && resultSource.isEmpty()) {
     111
     112            // You can remove the version safely!!!
     113
     114            // retrieve the list of cached representations of the version to be deleted
     115            List<Number> cachedRepresentations = jdbcCachedRepresentationDao.retrieveCachedRepresentationList(internalID);
     116
     117            // remove all the pairs (internalID, cached_representation) from the joint table       
     118            String sqlVersionsCachedRepresentations = "DELETE FROM " + versionsCachedRepresentationsTableName + " where " + version_id + " = ?";
     119            int affected_versions_cached_representations_rows = getSimpleJdbcTemplate().update(sqlVersionsCachedRepresentations, internalID);
     120
     121            // the main action: remove the version with internalID from "version" table
     122            String sql = "DELETE FROM " + versionTableName + " where " + version_id + " = ?";
     123            int affected_version_rows = getSimpleJdbcTemplate().update(sql, internalID);
     124
     125            // remove the cached representations of "cachedRepresentations" from the DB unless they are still mentioned in "versions_cached_representations"
     126            for (Number cachedID : cachedRepresentations) {
     127                jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);
     128            }
     129
     130            return (affected_version_rows);
     131        } else {
     132            // do not remove
     133            return 0;
     134        }
     135    }
     136     
    95137   
    96            
    97      /////////////////////////////////////////       
    98     @Override
    99     public int deleteVersion(Number internalID){
    100         String sql = "DELETE FROM " + versionTableName + " where "+version_id + " = ?";
    101         return (getSimpleJdbcTemplate().update(sql, internalID));
    102     }
    103    
    104     @Override
    105     public Version addVersion(Version freshVersion){
    106           VersionIdentifier externalIdentifier = new VersionIdentifier();
    107           String newExternalIdentifier = externalIdentifier.toString();
    108          
    109           Map<String, Object> params = new HashMap<String, Object>();
    110           params.put("externalId", newExternalIdentifier);
    111           //TODO: till the schema is fixed, version-text and version's external Id are the same (now version do not have URI's/ext id's)
    112           params.put("version", newExternalIdentifier);
    113           String sql = "INSERT INTO "+versionTableName + "("+external_id+","+ version+" ) VALUES (:externalId, :version)";
    114           final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    115           Version versionAdded = makeFreshCopy(freshVersion);
    116           // TODO change for external identifier when the shcem is fixed
    117           versionAdded.setVersion(newExternalIdentifier);
    118         return versionAdded;
    119     }
    120      
    121     ///////////////////////////////////////////////////////////////////
    122     @Override
    123     public int purge(Number internalID){
    124        String sqlCheck = "SELECT "+source_id+" FROM "+sourcesVersionsTableName+" WHERE "+version_id  +"= ?";
    125        List<Number> result= getSimpleJdbcTemplate().query(sqlCheck, versionCheckerRowMapper, internalID);
    126        if (result.size() < 1) {
    127            String sql ="DELETE FROM " + versionTableName + " where "+version_id + " = ?";
    128            return getSimpleJdbcTemplate().update(sql,  internalID);
    129        }
    130        else {
    131            return 0;
    132        }
    133     }
    134    
    135     private final RowMapper<Number> versionCheckerRowMapper = new RowMapper<Number>() {       
     138    private final RowMapper<Number> sourcesVersionsRowMapper = new RowMapper<Number>() {
    136139        @Override
    137140        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    139142            return result;
    140143        }
    141      };
     144    };
    142145   
     146   
     147    private final RowMapper<Number> sourceRowMapper = new RowMapper<Number>() {
     148        @Override
     149        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     150            Number result = rs.getInt(source_id);
     151            return result;
     152        }
     153    };
     154   
     155
     156    /////////////////////////////////////////////////
     157    @Override
     158    public Version addVersion(Version freshVersion) {
     159        VersionIdentifier externalIdentifier = new VersionIdentifier();
     160        String newExternalIdentifier = externalIdentifier.toString();
     161
     162        Map<String, Object> params = new HashMap<String, Object>();
     163        params.put("externalId", newExternalIdentifier);
     164        //TODO: till the schema is fixed, version-text and version's external Id are the same (now version do not have URI's/ext id's)
     165        params.put("version", newExternalIdentifier);
     166        String sql = "INSERT INTO " + versionTableName + "(" + external_id + "," + version + " ) VALUES (:externalId, :version)";
     167        final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
     168        Version versionAdded = makeFreshCopy(freshVersion);
     169        // TODO change for external identifier when the shcem is fixed
     170        versionAdded.setVersion(newExternalIdentifier);
     171        return versionAdded;
     172    }
     173
     174   
     175
    143176    //////////////////////////////////////////////////////
    144    
    145     @Override
    146     public List<Number> versionIDs(){
    147        String sqlCheck = "SELECT "+version_id+" FROM "+versionTableName;
    148        List<Number> result= getSimpleJdbcTemplate().query(sqlCheck, versionRunnerRowMapper);
    149        return result;
     177    @Override
     178    public List<Number> versionIDs() {
     179        String sqlCheck = "SELECT " + version_id + " FROM " + versionTableName;
     180        List<Number> result = getSimpleJdbcTemplate().query(sqlCheck, versionRunnerRowMapper);
     181        return result;
    150182    }
    151    
    152     private final RowMapper<Number> versionRunnerRowMapper = new RowMapper<Number>() {       
     183    private final RowMapper<Number> versionRunnerRowMapper = new RowMapper<Number>() {
    153184        @Override
    154185        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    156187            return result;
    157188        }
    158      };
    159      
    160     /////////////////////////////////////////////////////////////
    161     @Override
    162     public int purgeAll(){
    163          List<Number> ids = versionIDs();
    164          return super.purgeAll(ids, this);
    165     }
    166    
    167    
     189    };
     190
     191   
     192
    168193    private Version makeFreshCopy(Version version) {
    169          Version result = new Version();
    170          // TOD: add external ID when the schema is corrected
    171          result.setVersion(version.getVersion());
    172          return result;
     194        Version result = new Version();
     195        // TOD: add external ID when the schema is corrected
     196        result.setVersion(version.getVersion());
     197        return result;
    173198    }
    174199}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3272 r3297  
    126126    public void testDeleteCachedRepresentationInfo() {
    127127        System.out.println("deleteCachedRepresentationInfo");
    128         Number internalID = 6; /// safe to deleate becasue no version refers to it
     128        Number internalID = 6; /// deleted because no version refers to it
    129129        int result = jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(internalID);
    130130        assertEquals(1, result);
     
    132132        int resultTwo = jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(internalID);
    133133        assertEquals(0, resultTwo);
     134       
     135        Number internalIDDoNotDelete = 5;
     136        int resultThree =jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(internalIDDoNotDelete);
     137        assertEquals(0, resultThree);
    134138    }
    135139
     
    154158    }
    155159   
    156     /**
    157      * Test of purge, of class JdbcCachedRepresentationDao.
    158      *  public int purge(Number internalID)
    159      */
    160     @Test 
    161     public void testPurge() {
    162         System.out.println("test purge");
    163         int result = jdbcCachedRepresentationDao.purge(6);
    164         assertEquals(1, result);
    165     }
     160 
    166161   
    167162    /**
     
    183178    }
    184179   
    185      /**
    186      * Test of purgeAll, of class JdbcCachedRepresentationDao.
    187      * public  int purgeAll()
    188      */
    189     @Test 
    190     public void testPurgeAll() {
    191         System.out.println("test purge All");
    192         int result = jdbcCachedRepresentationDao.purgeAll();
    193         assertEquals(2, result);
    194     }
     180   
    195181}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java

    r3272 r3297  
    1919
    2020import eu.dasish.annotation.backend.TestBackendConstants;
     21import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
    2122import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
    2223import eu.dasish.annotation.schema.Version;
     24import java.util.ArrayList;
    2325import java.util.List;
     26import org.jmock.Expectations;
     27import org.jmock.Mockery;
    2428import org.junit.Test;
    2529import static org.junit.Assert.*;
    26 import org.junit.Ignore;
    2730import org.junit.runner.RunWith;
    2831import org.springframework.beans.factory.annotation.Autowired;
     
    3538 */
    3639@RunWith(SpringJUnit4ClassRunner.class)
    37 //@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
    38 //    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-config/cachedRepresentationDao.xml"})
    39 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/versionDao.xml"})
     40@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
     41    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml",
     42    "/spring-test-config/mockCachedRepresentationDao.xml", "/spring-config/versionDao.xml"})
    4043
    4144public class JdbcVersionDaoTest extends JdbcResourceDaoTest{
     
    4346    @Autowired
    4447    JdbcVersionDao jdbcVersionDao;
    45 
     48   
     49    @Autowired
     50    private CachedRepresentationDao cachedRepresentationDao;   
     51   
     52    @Autowired
     53    private Mockery mockery;
     54   
     55   
    4656    /**
    4757     * Test of getExternalId method, of class JdbcVersionDao.
     
    100110    public void testDeleteVersion() {
    101111        System.out.println("deleteVersion");
    102         Number internalID = 5; // there is no sources (in target_source and sources_versions - sibling table) connected to this version in the test table
    103         int result = jdbcVersionDao.deleteVersion(internalID);
     112        final Number internalID = 5; // there is no sources (in target_source and sources_versions - sibling table) connected to this version in the test table
     113        final Number cachedID =5;
     114        final List<Number> versions = new ArrayList<Number>();
     115        versions.add(cachedID);
     116       
     117        //jdbcCachedRepresentationDao.retrieveCachedRepresentationList(internalID);
     118        //jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);
     119       
     120        mockery.checking(new Expectations() {
     121            {
     122                oneOf(cachedRepresentationDao).retrieveCachedRepresentationList(internalID);
     123                will(returnValue(versions));
     124               
     125                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(cachedID);
     126                will(returnValue(0));
     127               
     128            }
     129        });
     130       
     131        int result = jdbcVersionDao.deleteVersion(internalID);
    104132        assertEquals(1, result);
    105133       
    106134        // try to delete one more time
     135         mockery.checking(new Expectations() {
     136            {
     137                oneOf(cachedRepresentationDao).retrieveCachedRepresentationList(internalID);
     138                will(returnValue(new ArrayList<Number>()));
     139               
     140            }
     141        });
    107142        int resultTwo = jdbcVersionDao.deleteVersion(internalID);
    108143        assertEquals(0, resultTwo);
     144       
     145        // the version in use, shoul not be deleted
     146        final Number internalIDNotToDelete = 4;         
     147        int resultThree = jdbcVersionDao.deleteVersion(internalIDNotToDelete);
     148        assertEquals(0, resultThree);
    109149    }
    110150
     
    125165    }
    126166
    127     /**
    128      * Test of purge method, of class JdbcVersionDao.
    129      */
    130     @Test
    131     public void testPurge() {
    132         System.out.println("purge");
    133         Number internalID = 5;
    134         int result = jdbcVersionDao.purge(internalID);
    135         assertEquals(1, result);
    136        
    137         int resultTwo = jdbcVersionDao.purge(internalID);
    138         assertEquals(0, resultTwo);
    139     }
    140 
     167 
    141168    /**
    142169     * Test of versionIDs method, of class JdbcVersionDao.
     
    155182    }
    156183
    157     /**
    158      * Test of purgeAll method, of class JdbcVersionDao.
    159      */
    160     @Test
    161     public void testPurgeAll() {
    162         System.out.println("purgeAll");
    163         int result = jdbcVersionDao.purgeAll();
    164         assertEquals(2, result);
    165     }
     184 
    166185}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/spring-test-config/mockCachedRepresentationDao.xml

    r3250 r3297  
    2626    <!-- Context for testing the annotations service with mock implementations -->
    2727           
    28     <!-- Mocked annotations -->
     28    <!-- Mocked cached repreenttaions -->
    2929    <bean id="cachedRepresentationDao" factory-bean="mockObjectsFactory" factory-method="newCachedRepresentationDao" />
    3030   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3292 r3297  
    144144INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (4, 4);
    145145INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (1, 5);
     146INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (5, 5);
    146147
    147148---- PERMISSIONS --------------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.