Changeset 1895
- Timestamp:
- 04/20/12 12:59:56 (12 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/CommentsDao.java
r1697 r1895 59 59 * @throws DataAccessException 60 60 */ 61 public Comment getById( Stringid) throws DataAccessException {61 public Comment getById(Number id) throws DataAccessException { 62 62 return getFirstOrNull(SELECT_BASE + " WHERE " + COLUMN_ID + " = ?", id); 63 63 } … … 202 202 } 203 203 204 /**205 * Retrieve comment Id From a comment206 * @param cmdId207 * @return query for database access to id208 */209 public Number getDbId(String cmdId) {210 StringBuilder query = new StringBuilder("SELECT " + COLUMN_ID + " FROM ").append(getTableName());211 query.append(" WHERE ").append(COLUMN_ID).append(" = ?");212 return getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId);213 }214 215 204 private Timestamp extractTimestamp(Comment comment) { 216 205 if (comment.getCommentDate() != null) { -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r1892 r1895 653 653 ComponentRegistryException, UserUnauthorizedException, DeleteFailedException { 654 654 try { 655 Comment comment = commentsDao.getById( commentId);655 Comment comment = commentsDao.getById(Integer.parseInt(commentId)); 656 656 if (comment != null 657 657 // Comment must have an existing (in this registry) componentId or profileId … … 666 666 } catch (DataAccessException ex) { 667 667 throw new DeleteFailedException("Database access error while trying to delete component", ex); 668 } catch (NumberFormatException ex) { 669 throw new DeleteFailedException("Illegal comment ID, cannot parse integer", ex); 668 670 } 669 671 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/CommentsDaoTest.java
r1697 r1895 78 78 assertEquals(TEST_COMMENT_USER_NAME, comments.get(0).getUserName()); 79 79 assertEquals(Integer.toString(TEST_COMMENT_USER_ID), comments.get(0).getUserId()); 80 } 81 82 @Test 83 public void testGetById() { 84 Comment comment1 = createTestComment(); 85 comment1.setProfileDescriptionId(TEST_COMMENT_PROFILE_ID); 86 Number commentId = commentsDao.insertComment(comment1, TEST_COMMENT_USER_ID); 87 Comment commentById = commentsDao.getById(commentId); 88 assertEquals(TEST_COMMENT_PROFILE_ID, commentById.getProfileDescriptionId()); 89 assertEquals(TEST_COMMENT_NAME, commentById.getComment()); 80 90 } 81 91
Note: See TracChangeset
for help on using the changeset viewer.