Changeset 3237


Ignore:
Timestamp:
08/05/13 14:41:03 (11 years ago)
Author:
olhsha
Message:

purge(cached_id): removes "cacherepresentation" from the table if its id is not referred from the table "versions_cached_representation". Dao-tested

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

    r3236 r3237  
    6262     * @return the amount of rows affected by removing from the DB the cached representation with the id "intenalID"
    6363     * should be "1" (or 0 with  a non-existing id on the input)
     64     * as a obligadory side-effect: deletes all the rows in the table versions_cached_representations containing "internalId" as a cached_representaton_ID
    6465     */
    6566    public int deleteCachedRepresentationInfo(Number internalID);
     
    7172     */
    7273    public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached);
     74   
     75   
     76    /**
     77     *
     78     * @param internalID
     79     * removes the version with internalId from the DB is there is no reference to to it n the table versions_cached_representations
     80     * @return the amount of removed rows
     81     */
     82    public int purge(Number internalID);
    7383   
    7484}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java

    r3222 r3237  
    2020import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
    2121import eu.dasish.annotation.schema.Version;
     22import java.util.List;
    2223
    2324/**
     
    4041     * @return internal identifier of the resource with externalID
    4142     */
    42     public  Number getExternalId(VersionIdentifier externalID);
     43    public  Number getInternalId(VersionIdentifier externalID);
    4344   
    4445   
     
    4647     *
    4748     * @param internalID
    48      * @return the object which fields have the corresponding column values of the row internalID
     49     * @return the insance of Version.class  where the veriosn internal Id is "internalID"
     50     *
    4951     */
    5052    public Version getVersion(Number internalID);
    5153   
     54    /**
     55     *
     56     * @param sourceID
     57     * @return the list of the internal version id-s for the  target source with the internal Id "sourceID"
     58     */
     59    public List<Number> retrieveVersionList(Number sourceID);
     60   
     61    /**
     62     *
     63     * @param versionID
     64     * removes the version with the internal id "versionID". Obligatory side effect: removes the corresponding rows in the tables
     65     * "versions_cached_representations" and "sources_versions"
     66     * @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")
     67     */
     68    public int deleteVersion(Number versionID);
     69   
     70    /**
     71     *
     72     * @param version
     73     * @return the copy of "version" with the new external Id set in "version" text field  (for now)
     74     *
     75     */
     76    public Version addVersion(Version version);
     77   
     78    /**
     79     * Removes the all the rows in the internal ID "internalID" if no references to this versions from the table sources.
     80     * @return the amount of removed rows
     81     */
     82    public int purgeVersions(Number internalID);
    5283}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3236 r3237  
    167167      }
    168168     
     169      //////////////////////////////////////////////////////////////////////////////////////////////
     170      @Override
     171      public int purge(Number internalID){       
     172       String sqlCheck = "SELECT "+cached_representation_id+" FROM "+versionsCachedRepresentationsTableName+" WHERE "+cached_representation_id  +"= ?";
     173       List<Number> result= getSimpleJdbcTemplate().query(sqlCheck, cachedRepresentationCheckerRowMapper, internalID);
     174       if (result.size() < 1) {
     175           String sql ="DELETE FROM " + cachedRepresentationTableName + " where "+cached_representation_id + " = ?";
     176           return getSimpleJdbcTemplate().update(sql,  internalID);
     177       }
     178       else {
     179           return 0;
     180       }
     181     }
     182     
     183     private final RowMapper<Number> cachedRepresentationCheckerRowMapper = new RowMapper<Number>() {       
     184        @Override
     185        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     186            Number result = rs.getInt(cached_representation_id);
     187            return result;
     188        }
     189     };
     190     
    169191      ////////// Helpers ///////////////////
    170192     
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java

    r3236 r3237  
    2020import eu.dasish.annotation.backend.dao.VersionDao;
    2121import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
    22 import eu.dasish.annotation.schema.CachedRepresentationInfo;
    2322import eu.dasish.annotation.schema.Version;
    2423import java.sql.ResultSet;
     
    6766      //////////////////////////////////////////////////////////////////////////////////////////////////////
    6867     @Override
    69      public Number getExternalId(VersionIdentifier externalID){
     68     public Number getInternalId(VersionIdentifier externalID){
    7069       if (externalID == null) {
    7170            return null;
     
    121120     };
    122121     
     122     
     123     
     124     /////////////////////////////////////////
     125     
     126    @Override
     127    public List<Number> retrieveVersionList(Number sourceID){
     128        return null;
     129    }
     130           
     131     /////////////////////////////////////////       
     132    @Override
     133    public int deleteVersion(Number versionID){
     134        return -1;
     135    }
     136   
     137    @Override
     138    public Version addVersion(Version version){
     139        return null;
     140    }
     141     
     142    @Override
     143    public int purgeVersions(Number internalID){
     144        return -1;
     145    }
    123146}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3236 r3237  
    6666
    6767    /**
    68      * Test of getExternalId method, of class JdbcCachedRepresentationDao.
    69      * public  Number getExternalId(CachedRepresentationIdentifier externalID);
     68     * Test of getInternalId method, of class JdbcCachedRepresentationDao.
     69     * public  Number getInternalId(CachedRepresentationIdentifier externalID);
    7070     */
    7171    @Test
     
    138138     * public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached);   
    139139     */
    140     @Test   
    141     @Ignore
     140    @Test 
    142141    public void testAddCachedRepresentationInfo() {
    143142        System.out.println("addCachedRepresentationInfo");
     
    153152        assertEquals("text", result.getType());
    154153    }
     154   
     155    /**
     156     * Test of purge, of class JdbcCachedRepresentationDao.
     157     * public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached);   
     158     */
     159    @Test 
     160    public void testPurge() {
     161        System.out.println(" purge");
     162        int result = jdbcCachedRepresentationDao.purge(6);
     163        assertEquals(1, result);
     164    }
     165   
    155166}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3236 r3237  
    124124INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000054', 'text/html', 'oxygen', 'text', 'corpus1'); --4
    125125INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000055', 'image/jpg', 'photomaster', 'image', 'TLAscratch'); --5
     126INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000056', 'text/plain', 'some tool', 'text', 'TLAscratch'); --6
    126127
    127128--------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.