Changeset 3373
- Timestamp:
- 08/13/13 16:03:31 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ResourceDao.java
r3272 r3373 40 40 */ 41 41 42 // TODO: remoev this after notebooks are corrected so they do not use it!!43 public boolean isNotebookInTheDataBase(Number notebookID);44 45 42 46 43 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r3241 r3373 52 52 @Autowired 53 53 private AnnotationDao jdbcAnnotationDao; 54 55 54 56 55 public JdbcNotebookDao(DataSource dataSource) { … … 60 59 @Override 61 60 public List<NotebookInfo> getNotebookInfos(UserIdentifier userID) { 62 String sql = "SELECT " +notebookTitle+", "+notebookExternal_id+" FROM "+notebookTableName+", "+principalTableName+" where "+principalPrincipal_id+" = "+notebookOwner_id+" and "+principalExternal_id+" = ?";61 String sql = "SELECT " + notebookTitle + ", " + notebookExternal_id + " FROM " + notebookTableName + ", " + principalTableName + " where " + principalPrincipal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?"; 63 62 return getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, userID.toString()); 64 63 } … … 66 65 @Override 67 66 public List<Notebook> getUsersNotebooks(UserIdentifier userID) { 68 String sql = "SELECT " +notebookStar+" FROM "+notebookTableName+", "+principalTableName+" where "+principal_id+" = "+owner_id+" and "+principalExternal_id+" = ?";67 String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + owner_id + " and " + principalExternal_id + " = ?"; 69 68 return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString()); 70 69 } … … 74 73 try { 75 74 final NotebookIdentifier notebookIdentifier = new NotebookIdentifier(); 76 String sql = "INSERT INTO " +notebookTableName+" ("+external_id+", "+this.title+","+ owner_id+") VALUES (:notebookId, :title, (SELECT "+principal_id+" FROM "+principalTableName+" WHERE "+principalExternal_id+" = :userID))";75 String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + owner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))"; 77 76 Map<String, Object> params = new HashMap<String, Object>(); 78 77 params.put("notebookId", notebookIdentifier.getUUID().toString()); … … 118 117 @Override 119 118 public int deleteNotebook(NotebookIdentifier notebookId) { 120 String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " +notebook_id +"= (SELECT "+notebook_id+" FROM "+notebookTableName+" WHERE "+external_id+" = ?)";119 String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)"; 121 120 String sql2 = "DELETE FROM notebook where external_id = ?"; 122 121 int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.getUUID().toString()); … … 138 137 } 139 138 } 140 141 142 /** 143 * 144 * @param notebookID 145 * @return the list of annotation-ids belonging to the notebook with notebookId146 * returns null if notebookId is null or is not in the DB147 * TODO:do we need to return null here? using an additional check.148 */ 149 @Override139 140 //////////////////////////////////////////////////////////////////////// 141 /** 142 * 143 * @param notebookID 144 * @return the list of annotation-ids belonging to the notebook with 145 * notebookId returns null if notebookId is null or is not in the DB TODO: 146 * do we need to return null here? using an additional check. 147 */ 148 @Override 150 149 public List<Number> getAnnotationIDs(Number notebookID) { 151 150 if (notebookID == null) { 152 151 return null; 153 152 } 154 155 // TODO remove "isNoteBookInTheDB" 156 if (isNotebookInTheDataBase(notebookID)) { 157 String sql = "SELECT "+notebooksAnnotationsTableNameAnnotation_id+" FROM "+notebooksAnnotationsTableName+" where "+notebook_id+" = ?"; 158 return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString()); 159 } else { 160 return null; 161 } 162 } 163 164 private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() { 153 StringBuilder sql = new StringBuilder("SELECT DISTINCT "); 154 sql.append(notebooksAnnotationsTableNameAnnotation_id).append(" FROM ").append(notebooksAnnotationsTableName).append(" where ").append(notebook_id).append(" = ?"); 155 return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID.toString()); 156 } 157 private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() { 165 158 @Override 166 159 public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException { … … 169 162 } 170 163 }; 171 172 ////////////////////////////////////////////////// 173 174 /** 175 * 164 165 ////////////////////////////////////////////////// 166 /** 167 * 176 168 * @param notebookID 177 169 * @return the list of annotation-infos of the annotations from notebookID; 178 * if notebook not in the DB or null returns null 179 * if the notebook contains no annotations returns an empty list 180 * 181 182 @Override 183 public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) { 184 return jdbcAnnotationDao.getAnnotationInfos(getAnnotationIDs(notebookID)); 185 }*/ 186 187 188 ////////////////////////////////////////////// 189 /** 190 * 191 * @param notebookID 192 * @return the list of annotation References from the notebookID 193 * returns null if notebookID == null or it does not exists in the DB 194 */ 195 196 @Override 197 public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) { 198 return jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID)); 199 } 200 170 * if notebook not in the DB or null returns null if the notebook contains 171 * no annotations returns an empty list 172 * 173 * 174 * @Override public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number 175 * notebookID) { return 176 * jdbcAnnotationDao.getAnnotationInfos(getAnnotationIDs(notebookID)); } 177 */ 178 ////////////////////////////////////////////// 179 /** 180 * 181 * @param notebookID 182 * @return the list of annotation References from the notebookID returns 183 * null if notebookID == null or it does not exists in the DB 184 */ 185 @Override 186 public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) { 187 return jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID)); 188 } 189 201 190 //////////////////////////////////////////////////////////////////////////// 202 191 /** 203 * 204 * @param notebookID 205 * @return the Annotations (as a list of references) from the notebookID * 206 * returns null if notebookID == null, or it does not exists in th DB, or the list of annotations is empty, 207 * or something wrong happened when extracting annotations from the notebook 208 * (according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!) 209 * 210 */ 211 192 * 193 * @param notebookID 194 * @return the Annotations (as a list of references) from the notebookID * 195 * returns null if notebookID == null, or it does not exists in th DB, or 196 * the list of annotations is empty, or something wrong happened when 197 * extracting annotations from the notebook (according to dasish.xsd if an 198 * Annotation is created then its list of annotations must contain at least 199 * one element!) 200 * 201 */ 212 202 @Override 213 203 public Annotations getAnnotations(Number notebookID) { 214 215 204 if (notebookID == null) { 216 205 return null; 217 206 } 218 219 220 // TODO remove "isNoteBookInTheDB" 221 if (isNotebookInTheDataBase(notebookID)) { 222 Annotations result = new Annotations(); 223 List<ResourceREF> annotREFs = result.getAnnotation(); 224 // TODO: what of annotREFS is null???? 225 boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID)); 226 return (test ? result : null); 227 } else { 228 return null; 229 } 230 231 } 232 207 Annotations result = new Annotations(); 208 List<ResourceREF> annotREFs = result.getAnnotation(); 209 boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID)); 210 return (test ? result : null); 211 212 } 213 233 214 /////////////////////////////////////////////////// 234 215 // REUSES notebookInfoRowMapper … … 238 219 return null; 239 220 } 240 String sql = "SELECT " +notebookExternal_id+","+ notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ?";221 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ?"; 241 222 List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString()); 242 223 if (result == null) { … … 248 229 return result.get(0); 249 230 } 250 231 251 232 ////////////////////////////////////////////////// 252 233 @Override … … 255 236 return null; 256 237 } 257 258 String sql = "SELECT "+notebookNotebook_id+" FROM "+notebookTableName+" WHERE "+notebookExternal_id+" = ?"; 259 List<Number> result= getSimpleJdbcTemplate().query(sql, notebookIdRowMapper, externalId.toString()); 260 if (result == null) { 261 return null; 262 } 263 if (result.isEmpty()) { 264 return null; 265 } 266 267 return result.get(0); 268 } 269 270 private final RowMapper<Number> notebookIdRowMapper = new RowMapper<Number>() { 238 239 String sql = "SELECT " + notebookNotebook_id + " FROM " + notebookTableName + " WHERE " + notebookExternal_id + " = ?"; 240 List<Number> result = getSimpleJdbcTemplate().query(sql, notebookIdRowMapper, externalId.toString()); 241 if (result == null) { 242 return null; 243 } 244 if (result.isEmpty()) { 245 return null; 246 } 247 248 return result.get(0); 249 } 250 private final RowMapper<Number> notebookIdRowMapper = new RowMapper<Number>() { 271 251 @Override 272 252 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 273 Number result = rs.getInt(notebook_id); 274 return result; 275 } 276 }; 277 278 253 Number result = rs.getInt(notebook_id); 254 return result; 255 } 256 }; 257 279 258 ////////////////////////////////////////////////////////////////// 280 259 @Override 281 public List<AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifier notebookId){282 List<Number> internalIds = getAnnotationIDs(getNotebookID(notebookId)); 260 public List<AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifier notebookId) { 261 List<Number> internalIds = getAnnotationIDs(getNotebookID(notebookId)); 283 262 if (internalIds == null) { 284 263 return null; 285 264 } 286 List<AnnotationIdentifier> annotationIds 265 List<AnnotationIdentifier> annotationIds = new ArrayList<AnnotationIdentifier>(); 287 266 for (Number internalId : internalIds) { 288 267 annotationIds.add(jdbcAnnotationDao.getExternalID(internalId)); … … 290 269 return annotationIds; 291 270 } 292 271 293 272 //////////////////////////////////////////////////////////// 294 273 @Override 295 public int removeAnnotation(Number annotationID) {296 String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " +annotation_id + " = ?";274 public int removeAnnotation(Number annotationID) { 275 String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?"; 297 276 int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationID); 298 277 return affectedNotebooks; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3370 r3373 182 182 }; 183 183 184 ////////////////////////////////////////// 185 /** 186 * 187 * @param notebookID 188 * @return false if notebookID == null or the notebook with notebookID is not in the DB; 189 * @return true if the notebook with notebookID in the DB 190 */ 191 @Override 192 public boolean isNotebookInTheDataBase(Number notebookID){ 193 194 if (notebookID == null) { 195 return false; 196 } 197 String sql = "SELECT "+notebookNotebook_id+" FROM notebook where "+notebook_id+" = ? LIMIT 1"; 198 List<Number> result=getSimpleJdbcTemplate().query(sql, isNotebookInTheDataBaseRowMapper, notebookID.toString()); 199 if (result == null) { 200 return false; 201 } 202 if (result.isEmpty()) { 203 return false; 204 } 205 return true; 206 } 207 208 private final RowMapper<Number> isNotebookInTheDataBaseRowMapper = new RowMapper<Number>() { 209 @Override 210 public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException { 211 Integer notebookId = rs.getInt(notebook_id); 212 return notebookId; 213 } 214 }; 184 215 185 216 186
Note: See TracChangeset
for help on using the changeset viewer.