Changeset 3238


Ignore:
Timestamp:
08/05/13 15:07:00 (11 years ago)
Author:
olhsha
Message:

2: methods:
-- returning all the internal id-s of cached representations
-- removing all the cached representations which are not referred from the versions_cached_representations tabel

DAO-tested

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
3 edited

Legend:

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

    r3237 r3238  
    2020import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
    2121import eu.dasish.annotation.schema.CachedRepresentationInfo;
    22 import eu.dasish.annotation.schema.CachedRepresentations;
    2322import java.util.List;
    2423
     
    8281    public int purge(Number internalID);
    8382   
     83    /**
     84     *
     85     * @return the list of all the internal id-s of the cached representations.
     86     */
     87    public List<Number> cachedRepresentationIDs();
     88   
     89    /**
     90     * removes all the cahed representations which are not referred from the versions_cached_representations table
     91     * @return the number of affected rows
     92     */
     93    public int purgeAll();
    8494}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3237 r3238  
    188188        }
    189189     };
     190     
     191     //////////////////////////////////////////////////////////////////////////////////////////////
     192      @Override
     193      public List<Number> cachedRepresentationIDs(){       
     194       String sqlCheck = "SELECT "+cached_representation_id+" FROM "+cachedRepresentationTableName;
     195       List<Number> result= getSimpleJdbcTemplate().query(sqlCheck, cachedRepresentationRunnerRowMapper);
     196       return result;
     197     }
     198     
     199     private final RowMapper<Number> cachedRepresentationRunnerRowMapper = new RowMapper<Number>() {       
     200        @Override
     201        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     202            Number result = rs.getInt(cached_representation_id);
     203            return result;
     204        }
     205     };
     206     
     207     
     208     @Override
     209     public int purgeAll(){
     210         List<Number> ids = cachedRepresentationIDs();
     211         int countRemoved = 0;
     212         for (Number id: ids){
     213             countRemoved = countRemoved + purge(id);
     214         }
     215         return countRemoved;
     216     }
    190217     
    191218      ////////// Helpers ///////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3237 r3238  
    155155    /**
    156156     * Test of purge, of class JdbcCachedRepresentationDao.
    157      * public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached);   
     157     *  public int purge(Number internalID)
    158158     */
    159159    @Test 
    160160    public void testPurge() {
    161         System.out.println(" purge");
     161        System.out.println("test purge");
    162162        int result = jdbcCachedRepresentationDao.purge(6);
    163163        assertEquals(1, result);
    164164    }
    165165   
     166    /**
     167     * test public List<Number> cachedRepresentationIDs()
     168     * public List<Number> cachedRepresentationIDs()
     169     */
     170    @Test 
     171    public void testCachedRepresentationIDs() {
     172        System.out.println(" test cachedRepresentationIDs");
     173        List<Number>  result = jdbcCachedRepresentationDao.cachedRepresentationIDs();
     174        assertEquals(6, result.size());
     175        assertEquals(1, result.get(0));
     176        assertEquals(2, result.get(1));
     177        assertEquals(3, result.get(2));
     178        assertEquals(4, result.get(3));
     179        assertEquals(5, result.get(4));
     180        assertEquals(6, result.get(5));
     181    }
     182   
     183     /**
     184     * Test of purgeAll, of class JdbcCachedRepresentationDao.
     185     * public  int purgeAll()
     186     */
     187    @Test 
     188    public void testPurgeAll() {
     189        System.out.println("test purge All");
     190        int result = jdbcCachedRepresentationDao.purgeAll();
     191        assertEquals(1, result);
     192    }
    166193}
Note: See TracChangeset for help on using the changeset viewer.