Changeset 3370
- Timestamp:
- 08/13/13 14:03:21 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 4 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
r3369 r3370 71 71 @Override 72 72 public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) { 73 74 73 75 String table; 76 74 StringBuilder sql = new StringBuilder("SELECT DISTINCT "); 75 sql.append(annotation_id).append(" FROM ").append(annotationTableName).append(" WHERE TRUE "); 76 Map<String, Object> params = new HashMap<String, Object>(); 77 77 78 if (link != null) { 78 79 List<Number> sourceIDs = jdbcSourceDao.getSourcesForLink(link); … … 80 81 if (!annotationIDs.isEmpty()) { 81 82 String values = makeListOfValues(annotationIDs); 82 table = "( SELECT DISTINCT "+annotationStar + "WHERE "+ annotation_id +"IN " + values + ") ";83 sql.append(" AND ").append(annotation_id).append(" IN ").append(values); 83 84 } 84 85 else{ … … 86 87 } 87 88 } 88 else{89 table = annotationTableName;90 }91 89 92 93 StringBuilder sql = new StringBuilder("SELECT ");94 sql.append(annotation_id).append(" FROM ").append(table).append(" WHERE TRUE ");95 96 Map<String, Object> params = new HashMap<String, Object>();97 //TODO: optimizie String builder98 99 90 100 91 if (owner != null) { 101 sql.append(" AND ").append(principal_id).append(" = :owner "); 102 params.put("owner", owner.toString()); 92 Number ownerID = jdbcUserDao.getInternalID(owner); 93 sql.append(" AND ").append(owner_id).append(" = :owner "); 94 params.put("owner", ownerID); 103 95 } 104 96 … … 114 106 115 107 if (text != null) { 116 sql .append(" AND ").append(body_xml).append(" LIKE '% :text%'");117 params.put("text", text);118 }108 sql.append(" AND ").append(body_xml).append(" LIKE '%").append(text).append("%'"); 109 } 110 119 111 120 112 List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params); … … 174 166 * from the input list if the input list is null or empty (zero elements) 175 167 * returns an empty list 168 * there may be annotationIDs which are not in the DB (so that's why we need this method). 176 169 */ 170 177 171 @Override 178 172 public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3361 r3370 106 106 return null; 107 107 } 108 String sql = "SELECT "+internalIdName+" FROM "+resourceTableName+" WHERE "+external_id +"= ? ";108 String sql = "SELECT "+internalIdName+" FROM "+resourceTableName+" WHERE "+external_id +"= ? LIMIT 1"; 109 109 List<Number> sqlResult= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalId.toString()); 110 110 … … 137 137 return null; 138 138 } 139 String sql = "SELECT " + external_id + " FROM " + resourceTableName + " WHERE " + internalIdName + "= ? ";139 String sql = "SELECT " + external_id + " FROM " + resourceTableName + " WHERE " + internalIdName + "= ? LIMIT 1"; 140 140 List<String> sqlResult = getSimpleJdbcTemplate().query(sql, externalIDRowMapper, internalId); 141 141 … … 162 162 ///////////////////////////////////////////////////// 163 163 protected XMLGregorianCalendar retrieveTimeStamp(Number internalID) { 164 String sqlTime = "SELECT " + time_stamp + " FROM " + resourceTableName + " WHERE " + internalIdName + "= ? ";164 String sqlTime = "SELECT " + time_stamp + " FROM " + resourceTableName + " WHERE " + internalIdName + "= ? LIMIT 1"; 165 165 List<XMLGregorianCalendar> timeStamp = getSimpleJdbcTemplate().query(sqlTime, timeStampRowMapper, internalID); 166 166 if (timeStamp.isEmpty()) { … … 195 195 return false; 196 196 } 197 String sql = "SELECT "+notebookNotebook_id+" FROM notebook where "+notebook_id+" = ? ";197 String sql = "SELECT "+notebookNotebook_id+" FROM notebook where "+notebook_id+" = ? LIMIT 1"; 198 198 List<Number> result=getSimpleJdbcTemplate().query(sql, isNotebookInTheDataBaseRowMapper, notebookID.toString()); 199 199 if (result == null) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java
r3309 r3370 20 20 import eu.dasish.annotation.backend.dao.UserDao; 21 21 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 22 import java.sql.ResultSet;23 import java.sql.SQLException;24 import java.util.List;25 22 import javax.sql.DataSource; 26 import org.springframework.jdbc.core.RowMapper;27 23 28 24 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3369 r3370 23 23 import eu.dasish.annotation.backend.dao.PermissionsDao; 24 24 import eu.dasish.annotation.backend.dao.SourceDao; 25 import eu.dasish.annotation.backend.dao.UserDao; 25 26 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 26 27 import eu.dasish.annotation.backend.identifiers.SourceIdentifier; 28 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 27 29 import eu.dasish.annotation.schema.Annotation; 28 30 import eu.dasish.annotation.schema.AnnotationInfo; … … 33 35 import eu.dasish.annotation.schema.SourceInfo; 34 36 import java.sql.SQLException; 37 import java.sql.Timestamp; 35 38 import java.util.ArrayList; 36 39 import java.util.HashMap; … … 40 43 import org.jmock.Mockery; 41 44 import static org.junit.Assert.*; 42 import org.junit.Ignore;43 45 import org.junit.Test; 44 46 import org.junit.runner.RunWith; … … 64 66 @Autowired 65 67 private SourceDao sourceDao; 68 @Autowired 69 private UserDao userDao; 66 70 @Autowired 67 71 private Mockery mockery; … … 376 380 List<Number> result = jdbcAnnotationDao.getAnnotationIDsForSources(sources); 377 381 assertEquals (2, result.size()); 378 //assertEquals(2, result.get(0));379 //assertEquals(3, result.get(1));382 assertEquals(2, result.get(0)); 383 assertEquals(3, result.get(1)); 380 384 } 381 385 382 386 @Test 383 387 public void testGetExternalID() { 384 System.out.println("get AnnotationID");388 System.out.println("getExternalID"); 385 389 386 390 final AnnotationIdentifier externalId = jdbcAnnotationDao.getExternalID(2); … … 392 396 393 397 } 398 399 400 /** test 401 * public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) { 402 **/ 403 404 @Test 405 public void testGetFilteredAnnotationIDs(){ 406 System.out.println(" test getFilteredAnnotationIDs"); 407 408 409 ////////////////////////////////////////// 410 // TEST 1 411 final String link = "nl.wikipedia.org"; 412 final List<Number> sourceIDs = new ArrayList<Number>(); 413 sourceIDs.add(1); 414 sourceIDs.add(2); 415 416 417 mockery.checking(new Expectations() { 418 { 419 oneOf(sourceDao).getSourcesForLink(link); 420 will(returnValue(sourceIDs)); 421 } 422 }); 423 List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(link, null, null, null, null, null, null); 424 assertEquals(2, result_1.size()); 425 assertEquals(2, result_1.get(0)); 426 assertEquals(3, result_1.get(1)); 427 428 /////////////////////////////////////////////// 429 // TEST 2 430 mockery.checking(new Expectations() { 431 { 432 oneOf(sourceDao).getSourcesForLink(link); 433 will(returnValue(sourceIDs)); 434 } 435 }); 436 List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(link, "some html", null, null, null, null, null); 437 assertEquals(2, result_2.size()); 438 assertEquals(2, result_2.get(0)); 439 assertEquals(3, result_2.get(1)); 440 441 /////////////////////////////////////////////// 442 // TEST 3 443 final UserIdentifier owner = new UserIdentifier("00000000-0000-0000-0000-000000000111"); 444 445 446 mockery.checking(new Expectations() { 447 { 448 oneOf(sourceDao).getSourcesForLink(link); 449 will(returnValue(sourceIDs)); 450 451 oneOf(userDao).getInternalID(owner); 452 will(returnValue(3)); 453 } 454 }); 455 456 List<Number> result_3 = jdbcAnnotationDao.getFilteredAnnotationIDs(link, "some html", null, null, owner, null, null); 457 assertEquals(1, result_3.size()); 458 assertEquals(2, result_3.get(0)); 459 460 /////////////////////////////////////////////// 461 // TEST 4 462 463 mockery.checking(new Expectations() { 464 { 465 oneOf(sourceDao).getSourcesForLink(link); 466 will(returnValue(sourceIDs)); 467 468 oneOf(userDao).getInternalID(owner); 469 will(returnValue(3)); 470 } 471 }); 472 Timestamp after = new Timestamp(0); 473 Timestamp before = new Timestamp(System.currentTimeMillis()); 474 List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(link, "some html", null, null, owner, after, before); 475 assertEquals(1, result_4.size()); 476 assertEquals(2, result_4.get(0)); 477 478 /////////////////////////////////////////////// 479 // TEST 5 480 481 mockery.checking(new Expectations() { 482 { 483 oneOf(sourceDao).getSourcesForLink(link); 484 will(returnValue(sourceIDs)); 485 486 oneOf(userDao).getInternalID(owner); 487 will(returnValue(3)); 488 } 489 }); 490 Timestamp after_1 = new Timestamp(System.currentTimeMillis()); 491 List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(link, "some html", null, null, owner, after_1, null); 492 assertEquals(0, result_5.size()); 493 494 495 } 496 394 497 //////////// helpers ////////////////////// 395 498 }
Note: See TracChangeset
for help on using the changeset viewer.