Changeset 3138


Ignore:
Timestamp:
07/15/13 16:35:18 (11 years ago)
Author:
olhsha
Message:

basic get-methods for annotations (given a notebook) have been implemented.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao
Files:
2 edited

Legend:

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

    r3071 r3138  
    1818package eu.dasish.annotation.backend.dao;
    1919
     20import eu.dasish.annotation.schema.AnnotationInfo;
    2021import eu.dasish.annotation.schema.Annotations;
     22import eu.dasish.annotation.schema.ResourceREF;
     23import java.util.List;
    2124
    2225/**
     
    2629 */
    2730public interface AnnotationDao {
    28 
     31   
     32     // Returns the list of annotation Id-s  for the notebook id.
     33    List<Number> getAnnotationIDs(Number notebookID);
     34   
     35     // Returns the list of annotation info-s  for the notebook id.
     36    List<AnnotationInfo> getAnnotationInfos(Number notebookID);
     37   
     38     // Returns the list of annotations Id-s  for the notebook id.
     39    List<ResourceREF> getAnnotationREFs(Number notebookID);
     40   
    2941    // Returns the annotations object for the notebook id.
    3042    Annotations getAnnotations(Number notebookID);
     43   
     44   
    3145}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3099 r3138  
    1919
    2020import eu.dasish.annotation.backend.dao.AnnotationDao;
     21import eu.dasish.annotation.schema.Annotation;
     22import eu.dasish.annotation.schema.AnnotationInfo;
    2123import eu.dasish.annotation.schema.Annotations;
     24import eu.dasish.annotation.schema.ResourceREF;
     25import eu.dasish.annotation.schema.Sources;
     26import java.sql.ResultSet;
     27import java.sql.SQLException;
     28import java.util.List;
    2229import javax.sql.DataSource;
     30import org.springframework.jdbc.core.RowMapper;
    2331import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
    2432
     
    2836 * @author Peter Withers <peter.withers@mpi.nl>
    2937 */
     38
     39/*
     40 *  annotation (
     41    annotation_id SERIAL UNIQUE NOT NULL,
     42    external_id UUID UNIQUE NOT NULL,
     43    time_stamp timestamp with time zone default now(),
     44    owner_id integer,
     45    headline tCRext,
     46    body_xml xml
     47);
     48 *
     49 *
     50 */
     51
     52
    3053public class JdbcAnnotationDao extends SimpleJdbcDaoSupport implements AnnotationDao {
    3154
     
    3356        setDataSource(dataSource);
    3457    }
     58   
     59    ////////////////////////////////////////////////////////////////////////
     60     @Override           
     61    public List<Number> getAnnotationIDs(Number notebookID) {
     62       String sql = "SELECT notebooks_annotations.annotation_id  FROM notebooks_annotations where notebook_id = ?";
     63       return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString());
     64    }
     65   
     66    private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {       
     67        @Override
     68        public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException {
     69            Integer annotationId = rs.getInt("annotation_id");
     70            return annotationId;
     71        }
     72    };
     73   
     74    ////////////////////////////////////////////////////////////////////////////
    3575
    3676    @Override
    37     public Annotations getAnnotations(Number notebookID) {
    38         return new Annotations(); // todo: complete the query required here
    39 //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
     77    public List<AnnotationInfo> getAnnotationInfos(Number notebookID) {       
     78        String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_id  IN ?";
     79        return getSimpleJdbcTemplate().query(sql, annotationInfoRowMapper, getAnnotationIDs(notebookID));
    4080    }
     81   
     82    private final RowMapper<AnnotationInfo> annotationInfoRowMapper = new RowMapper<AnnotationInfo>() {       
     83        @Override
     84        public AnnotationInfo mapRow(ResultSet rs, int rowNumber) throws SQLException {
     85           AnnotationInfo annotationInfo = new AnnotationInfo();
     86           annotationInfo.setOwner(getResourceREF(Integer.toString(rs.getInt("owner_id"))));
     87           annotationInfo.setHeadline(rs.getString("headline"));
     88           annotationInfo.setTargetSources(getSources(rs.getString("body_xml")));
     89           return annotationInfo;
     90        }
     91    };
     92   
     93   
     94    /////////////////////////////////////////////////
     95   
     96    @Override
     97    public List<ResourceREF> getAnnotationREFs(Number notebookID) {       
     98        String sql = "SELECT annotation.annotation_id FROM annotation WHERE annotation.annotation_id  IN ?";
     99        return getSimpleJdbcTemplate().query(sql, annotationREFRowMapper, getAnnotationIDs(notebookID));
     100    }
     101   
     102    private final RowMapper<ResourceREF> annotationREFRowMapper = new RowMapper<ResourceREF>() {       
     103        @Override
     104        public ResourceREF mapRow(ResultSet rs, int rowNumber) throws SQLException {
     105           ResourceREF annotationREF = new ResourceREF();
     106           annotationREF.setRef(Integer.toString(rs.getInt("annotation_id")));
     107           return annotationREF;
     108        }
     109    };
     110   
     111    /////////////////////////////////////////////////
     112    private ResourceREF getResourceREF(String resourceID){
     113       ResourceREF result = new ResourceREF();
     114       result.setRef(resourceID);
     115       return result;
     116    }
     117   
     118    //TODO implement when xml-body stucture is discussed!
     119    //BTW do we have to get source REF, not the whole sources here??
     120    private Sources getSources(String some_xml) {
     121        Sources result = new Sources();
     122        return result;
     123    }
     124   
     125   
     126   
     127    ////////////////////////////////////////////////////////////////////////////
     128
     129    @Override
     130    public Annotations getAnnotations(Number notebookID) {       
     131        String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_id  IN ?";
     132        return null; // not omplemented yet
     133       
     134    }
     135   
    41136}
Note: See TracChangeset for help on using the changeset viewer.