Changeset 3146


Ignore:
Timestamp:
07/17/13 10:02:15 (11 years ago)
Author:
olhsha
Message:

refactored Daos for Notebooks and annotations. Their common part ResourceDao? is created. Test-classes are changed respectively

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

Legend:

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

    r3142 r3146  
    3232
    3333
    34 public interface AnnotationDao {
     34public interface AnnotationDao extends ResourceDao{
    3535   
    3636     // Returns the list of annotation Id-s  for the notebook id.
     
    4141     
    4242     // Returns the list of annotation info-s  for the notebook id.
    43     List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID);
    44    
     43    List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID);   
    4544   
    4645     // Returns the list of annotations Id-s  for the notebook id.
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java

    r3095 r3146  
    3030 * @author Peter Withers <peter.withers@mpi.nl>
    3131 */
    32 public interface NotebookDao {
     32public interface NotebookDao extends ResourceDao {
    3333
    3434    // Returns a list of notebook-info for the notebooks accessible to the current user.
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3144 r3146  
    4040
    4141
    42 public class JdbcAnnotationDao extends SimpleJdbcDaoSupport implements AnnotationDao {
     42public class JdbcAnnotationDao extends JdbcResourceDao implements AnnotationDao {
    4343
    4444    public JdbcAnnotationDao(DataSource dataSource) {
     
    4646    }
    4747   
    48     //////////////////////////////////////////
    49     /**
    50      *
    51      * @param notebookID
    52      * @return false if notebookID == null or the notebook with notebookID is not in the DB;
    53      * @return true if the notebook with notebookID in the DB
    54      */
    55     public boolean isNotebookInTheDataBase(Number notebookID){
    56        
    57         if (notebookID == null) {
    58            return false;
    59        }
    60        String sql = "SELECT notebook.notebook_id  FROM notebook where notebook_id = ?";
    61        List<Number> result=getSimpleJdbcTemplate().query(sql, isNotebookInTheDataBaseRowMapper, notebookID.toString());
    62        if (result == null) {
    63            return false;
    64        }
    65        if (result.isEmpty()) {
    66            return false;
    67        }
    68        return true;
    69     }
    70    
    71     private final RowMapper<Number> isNotebookInTheDataBaseRowMapper = new RowMapper<Number>() {       
    72         @Override
    73         public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException {
    74             Integer notebookId = rs.getInt("notebook_id");
    75             return notebookId;
    76         }
    77     };
    7848   
    7949    ////////////////////////////////////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r3105 r3146  
    4646 * @author Peter Withers <peter.withers@mpi.nl>
    4747 */
    48 public class JdbcNotebookDao extends SimpleJdbcDaoSupport implements NotebookDao {
     48public class JdbcNotebookDao extends JdbcResourceDao implements NotebookDao {
    4949
    5050    @Autowired
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3145 r3146  
    4848@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/annotationDao.xml"})
    4949
    50 public class JdbcAnnotationDaoTest extends JdbcResourceDaoTestBasic{
     50public class JdbcAnnotationDaoTest extends JdbcResourceDaoTest{
    5151   
    5252    @Autowired
    5353    JdbcAnnotationDao jdbcAnnotationDao;   
    5454   
     55    @Test
     56    public void testIsNotebookInTheDataBase(){
     57        super.testIsNotebookInTheDataBase(jdbcAnnotationDao);
     58    }
    5559   
    56    
    57      /**
    58      * Test of getAnnotationIDs method, of class JdbcAnnotationDao.
    59      * boolean isNotebookInTheDataBase(Number notebookID)
    60      */
    61     @Test
    62     public void testIsNotebookInTheDataBase() {
    63         System.out.println("isNotebookInTheDataBase");
    64        
    65         final boolean testOne =  jdbcAnnotationDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_1_INT);
    66         assertEquals(true, testOne);
    67        
    68         final boolean testTwo =  jdbcAnnotationDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_2_INT);
    69         assertEquals(true, testTwo);
    70        
    71         final boolean testThree =  jdbcAnnotationDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_3_INT);
    72         assertEquals(true, testThree);
    73        
    74         final boolean testFour =  jdbcAnnotationDao.isNotebookInTheDataBase(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
    75         assertEquals(false, testFour);
    76        
    77         final boolean testFive =  jdbcAnnotationDao.isNotebookInTheDataBase(null);
    78         assertEquals(false, testFive);
    79     }
    80 
    8160    /**
    8261     * Test of getAnnotationIDs method, of class JdbcAnnotationDao.
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3145 r3146  
    4646@RunWith(SpringJUnit4ClassRunner.class)
    4747@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"})
    48 public class JdbcNotebookDaoTest extends JdbcResourceDaoTestBasic{
     48public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{
    4949
    5050    @Autowired
     
    5555    private Mockery mockery;
    5656
     57    @Test
     58    public void testIsNotebookInTheDataBase(){
     59        super.testIsNotebookInTheDataBase(jdbcNotebookDao);
     60    }
     61   
    5762   
    5863    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDaoTest.java

    r3145 r3146  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.TestBackendConstants;
    2021import java.io.File;
    2122import java.io.FileNotFoundException;
     
    2526import org.junit.After;
    2627import org.junit.Before;
    27 import org.junit.runner.RunWith;
    2828import org.springframework.beans.factory.annotation.Autowired;
    2929import org.springframework.dao.DataAccessException;
    3030import org.springframework.jdbc.core.JdbcTemplate;
    31 import org.springframework.test.context.ContextConfiguration;
    32 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    33 
     31import static org.junit.Assert.assertEquals;
    3432/**
    3533 *
     
    3735 */
    3836
    39 public class JdbcResourceDaoTestBasic {
     37public class JdbcResourceDaoTest {
     38   
    4039   @Autowired
    41     private JdbcTemplate jdbcTemplate;
     40   private JdbcTemplate jdbcTemplate;
    4241   
    4342   private String getNormalisedSql() throws FileNotFoundException, URISyntaxException {
     
    8281    public void tearDown() {
    8382    }
     83   
     84   
     85     /**
     86     * Test-helper of isNotebookInTheDataBase method, of class JdbcResourceDao.
     87     * boolean isNotebookInTheDataBase(Number notebookID)
     88     */
     89    protected <T  extends JdbcResourceDao> void testIsNotebookInTheDataBase(T jdbcResourceDao) {
     90        System.out.println("isNotebookInTheDataBase");
     91       
     92        final boolean testOne =  jdbcResourceDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_1_INT);
     93        assertEquals(true, testOne);
     94       
     95        final boolean testTwo =  jdbcResourceDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_2_INT);
     96        assertEquals(true, testTwo);
     97       
     98        final boolean testThree =  jdbcResourceDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_3_INT);
     99        assertEquals(true, testThree);
     100       
     101        final boolean testFour =  jdbcResourceDao.isNotebookInTheDataBase(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
     102        assertEquals(false, testFour);
     103       
     104        final boolean testFive =  jdbcResourceDao.isNotebookInTheDataBase(null);
     105        assertEquals(false, testFive);
     106    }
     107
    84108
    85109}
Note: See TracChangeset for help on using the changeset viewer.