Changeset 3138
- Timestamp:
- 07/15/13 16:35:18 (11 years ago)
- 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 18 18 package eu.dasish.annotation.backend.dao; 19 19 20 import eu.dasish.annotation.schema.AnnotationInfo; 20 21 import eu.dasish.annotation.schema.Annotations; 22 import eu.dasish.annotation.schema.ResourceREF; 23 import java.util.List; 21 24 22 25 /** … … 26 29 */ 27 30 public 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 29 41 // Returns the annotations object for the notebook id. 30 42 Annotations getAnnotations(Number notebookID); 43 44 31 45 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3099 r3138 19 19 20 20 import eu.dasish.annotation.backend.dao.AnnotationDao; 21 import eu.dasish.annotation.schema.Annotation; 22 import eu.dasish.annotation.schema.AnnotationInfo; 21 23 import eu.dasish.annotation.schema.Annotations; 24 import eu.dasish.annotation.schema.ResourceREF; 25 import eu.dasish.annotation.schema.Sources; 26 import java.sql.ResultSet; 27 import java.sql.SQLException; 28 import java.util.List; 22 29 import javax.sql.DataSource; 30 import org.springframework.jdbc.core.RowMapper; 23 31 import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; 24 32 … … 28 36 * @author Peter Withers <peter.withers@mpi.nl> 29 37 */ 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 30 53 public class JdbcAnnotationDao extends SimpleJdbcDaoSupport implements AnnotationDao { 31 54 … … 33 56 setDataSource(dataSource); 34 57 } 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 //////////////////////////////////////////////////////////////////////////// 35 75 36 76 @Override 37 public Annotations getAnnotations(Number notebookID) {38 return new Annotations(); // todo: complete the query required here39 // 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)); 40 80 } 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 41 136 }
Note: See TracChangeset
for help on using the changeset viewer.