Changeset 3167 for DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
- Timestamp:
- 07/19/13 09:56:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3154 r3167 43 43 public class JdbcAnnotationDao extends JdbcResourceDao implements AnnotationDao { 44 44 45 45 46 public JdbcAnnotationDao(DataSource dataSource) { 46 47 setDataSource(dataSource); … … 71 72 72 73 String values = makeListOfValues(annotationIDs); 73 String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_idIN "+values;74 String sql = "SELECT "+annotationStar+" FROM "+annotationTableName +" WHERE "+annotationAnnotation_id+" IN "+values; 74 75 return getSimpleJdbcTemplate().query(sql, annotationInfoRowMapper); 75 76 } … … 79 80 public AnnotationInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 80 81 AnnotationInfo annotationInfo = new AnnotationInfo(); 81 annotationInfo.setOwner(getResourceREF(Integer.toString(rs.getInt( "owner_id"))));82 annotationInfo.setHeadline(rs.getString( "headline"));83 annotationInfo.setTargetSources(getSources(rs.getString( "body_xml")));82 annotationInfo.setOwner(getResourceREF(Integer.toString(rs.getInt(owner_id)))); 83 annotationInfo.setHeadline(rs.getString(headline)); 84 annotationInfo.setTargetSources(getSources(rs.getString(body_xml))); 84 85 return annotationInfo; 85 86 } … … 109 110 110 111 String values = makeListOfValues(annotationIDs); 111 String sql = "SELECT annotation.annotation_id FROM annotation WHERE annotation.annotation_idIN "+values;112 String sql = "SELECT "+annotationAnnotation_id+" FROM "+annotationTableName+" WHERE "+annotationAnnotation_id+" IN "+values; 112 113 return getSimpleJdbcTemplate().query(sql, annotationREFRowMapper); 113 114 } … … 117 118 public ResourceREF mapRow(ResultSet rs, int rowNumber) throws SQLException { 118 119 ResourceREF annotationREF = new ResourceREF(); 119 annotationREF.setRef(Integer.toString(rs.getInt( "annotation_id")));120 annotationREF.setRef(Integer.toString(rs.getInt(annotation_id))); 120 121 return annotationREF; 121 122 } … … 136 137 return null; 137 138 } 138 String sql = "SELECT * FROM annotation WHERE annotation.annotation_id= ?";139 String sql = "SELECT "+annotationStar+" FROM "+annotationTableName+" WHERE "+annotationAnnotation_id +"= ?"; 139 140 List<Annotation> result= getSimpleJdbcTemplate().query(sql, annotationRowMapper, annotationID); 140 141 … … 147 148 148 149 if (result.size()>1) { 149 throw new SQLException("There are "+result.size()+" annotations with annotation_id"+annotationID);150 throw new SQLException("There are "+result.size()+" annotations with "+ annotation_id + " "+annotationID); 150 151 } 151 152 return result.get(0); … … 156 157 public Annotation mapRow(ResultSet rs, int rowNumber) throws SQLException { 157 158 Annotation result = new Annotation(); 158 result.setHeadline(rs.getString( "headline"));159 result.setHeadline(rs.getString(headline)); 159 160 160 161 ResourceREF ownerREF = new ResourceREF(); 161 ownerREF.setRef(String.valueOf(rs.getInt( "owner_id")));162 ownerREF.setRef(String.valueOf(rs.getInt(owner_id))); 162 163 result.setOwner(ownerREF); 163 164 … … 173 174 // TODO add external reference 174 175 175 result.setBody(convertToAnnotationBody(rs.getString( "body_xml")));176 result.setBody(convertToAnnotationBody(rs.getString(body_xml))); 176 177 return result; 177 178 } … … 198 199 } 199 200 200 String sql = "SELECT annotation.annotation_id FROM annotation WHERE annotation.external_id= ?";201 String sql = "SELECT "+annotationAnnotation_id+" FROM "+annotationTableName+" WHERE "+annotationExternal_id+" = ?"; 201 202 List<Number> result= getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, externalID.toString()); 202 203 if (result == null) { … … 208 209 209 210 if (result.size()>1) { 210 throw new SQLException("There are "+result.size()+" annotations with external_id"+externalID);211 throw new SQLException("There are "+result.size()+" annotations with"+ external_id +" "+externalID); 211 212 } 212 213 return result.get(0); … … 216 217 @Override 217 218 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 218 Number result = rs.getInt( "annotation_id");219 Number result = rs.getInt(annotation_id); 219 220 return result; 220 221 } 221 222 }; 223 224 225 public int deleteNotebook(Number annotationId) throws SQLException{ 226 String sqlAnnotation = "DELETE FROM " + annotationTableName + " where "+annotation_id + " = ?"; 227 //String sqSources = "DELETE FROM " + sourceTableName + " where "+ notebook_id +"= ?"; 228 int affectedAnnotations = getSimpleJdbcTemplate().update(sqlAnnotation, annotationId); 229 if (affectedAnnotations>1) { 230 throw new SQLException("There was more than one annotation ("+affectedAnnotations+") with the same ID "+annotationId); 231 } 232 return affectedAnnotations; 233 //TODO implement deleting sources (see the specification document and the interfaces' javadoc 234 } 222 235 223 236
Note: See TracChangeset
for help on using the changeset viewer.