Changeset 3292
- Timestamp:
- 08/06/13 16:15:13 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java
r3279 r3292 37 37 public SourceIdentifier getExternalID(Number internalID); 38 38 39 39 /** 40 * 41 * @param annotationID 42 * @return the list of the source's internal IDs of all the target sources of annotationID 43 */ 40 44 public List<Number> retrieveSourceIDs(Number annotationID); 41 45 46 /** 47 * 48 * @param inernalID 49 * @return the object containing the source with the intrenal Id "internalId" 50 */ 51 public Source getSource(Number internalID); 42 52 43 public Source getSource(Number inernalID); 44 45 53 /** 54 * 55 * @param internalID 56 * @return delete the source with the internal ID "internalID" 57 */ 46 58 public int deleteSource(Number internalID); 47 59 48 60 /** 61 * 62 * @param freshSource 63 * adds freshSource to the DB and assigns the fresh external Identifier to it 64 * @return the copy of freshSource with the assigned external identifier 65 */ 49 66 public Source addSource(Source freshSource); 50 67 51 68 /** 69 * 70 * @param internalId 71 * removes the source with the ID "internalId" from the DB, if it is not a target source of some annotation 72 * @return the amount of affected rows in the "source" table 73 */ 52 74 public int purge(Number internalId); 53 75 54 76 /** 77 * 78 * @return the list of all internal sourceIDs 79 */ 55 80 public List<Number> sourceIDs(); 56 81 57 82 /** 83 * removes all the sources from the DAb which are not target sources of some annotations 84 * @return 85 */ 58 86 public int purgeAll(); 59 87 60 88 ////////////////////////////////////////////// 61 89 62 90 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r3272 r3292 99 99 } 100 100 101 ;101 102 102 103 103 //////////////////////////////////////////////////////////////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3272 r3292 60 60 final static protected String time_stamp = "time_stamp"; 61 61 final static protected String permission = "permission_"; 62 final static protected String target_source_id = "target_source_id";62 //final static protected String target_source_id = "target_source_id"; 63 63 final static protected String link = "link"; 64 64 final static protected String version = "version"; … … 90 90 91 91 92 final static protected String cachedRepresentationStar = cachedRepresentationTableName+".*"; 93 92 final static protected String cachedRepresentationStar = cachedRepresentationTableName+".*"; 94 93 final static protected String versionStar = versionTableName+".*"; 94 final static protected String sourceStar = sourceTableName+".*"; 95 95 96 96 /////////////////////////////////////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3279 r3292 20 20 import eu.dasish.annotation.backend.dao.SourceDao; 21 21 import eu.dasish.annotation.backend.identifiers.SourceIdentifier; 22 import eu.dasish.annotation.backend.identifiers.VersionIdentifier;23 22 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 24 23 import eu.dasish.annotation.schema.NewOrExistingSourceInfos; … … 30 29 import java.util.List; 31 30 import javax.sql.DataSource; 31 import javax.xml.datatype.DatatypeConfigurationException; 32 import javax.xml.datatype.DatatypeFactory; 33 import javax.xml.datatype.XMLGregorianCalendar; 32 34 import org.springframework.jdbc.core.RowMapper; 33 35 … … 51 53 52 54 55 @Override 56 public List<Number> retrieveSourceIDs(Number annotationID){ 57 String sql = "SELECT "+source_id+" FROM "+annotationsSourcesTableName+" WHERE "+annotation_id +"= ?"; 58 List<Number> result= getSimpleJdbcTemplate().query(sql, annotationSourceRowMapper, annotationID); 59 60 if (result == null) { 61 return null; 62 } 63 if (result.isEmpty()) { 64 return null; 65 } 66 return result; 67 } 68 69 private final RowMapper<Number> annotationSourceRowMapper = new RowMapper<Number>() { 70 @Override 71 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 72 Number result = rs.getInt(source_id); 73 return result; 74 } 75 }; 53 76 54 public List<Number> retrieveSourceIDs(Number annotationID){ 55 return null; 77 public Source getSource(Number internalID) { 78 String sql = "SELECT "+sourceStar+"FROM "+sourcesTableName+" WHERE "+source_id +" = ?"; 79 List<Source> result= getSimpleJdbcTemplate().query(sql, SourceRowMapper, internalID); 80 return result.get(0); 56 81 } 57 82 58 59 public Source getSource(Number inernalID) { 60 return null; 61 } 83 private final RowMapper<Source> SourceRowMapper = new RowMapper<Source>() { 84 @Override 85 public Source mapRow(ResultSet rs, int rowNumber) throws SQLException { 86 try { 87 Source result = constructSource(new SourceIdentifier(rs.getString(external_id)), rs.getString(link), rs.getString(version), rs.getString(time_stamp)); 88 return result; 89 } 90 catch (DatatypeConfigurationException e) { 91 // TODO: what logger are we going to use 92 System.out.println("Cannot construct time stam: probably worng date/time format"); 93 return null; 94 } 95 } 96 }; 62 97 63 98 64 99 public int deleteSource(Number internalID){ 65 return -1; 100 String sql = "DELETE FROM " + sourceTableName + " where " + source_id + " = ?"; 101 return (getSimpleJdbcTemplate().update(sql, internalID)); 66 102 } 67 103 … … 89 125 90 126 public List<SourceInfo> getSourceInfos(Number annotationID){ 91 String sourceIDs = makeListOfValues( getSourceInternalIdentifiers(annotationID));127 String sourceIDs = makeListOfValues(retrieveSourceIDs(annotationID)); 92 128 String sql = "SELECT "+external_id+","+ link +"," + version+"FROM "+sourcesTableName+" WHERE "+source_id +" IN "+sourceIDs; 93 129 List<SourceInfo> result= getSimpleJdbcTemplate().query(sql, SourceInfoRowMapper); … … 121 157 //////// HELPERS ////////////////////// 122 158 123 124 private List<Number> getSourceInternalIdentifiers(Number annotationID){ 125 String sql = "SELECT "+target_source_id+" FROM "+annotationsSourcesTableName+" WHERE "+annotationAnnotation_id +"= ?"; 126 List<Number> result = getSimpleJdbcTemplate().query(sql, SourceIDRowMapper, annotationID); 127 return result; 128 } 129 130 private final RowMapper<Number> SourceIDRowMapper = new RowMapper<Number>() { 131 @Override 132 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 133 return rs.getInt(target_source_id); 134 } 135 }; 136 137 159 138 160 //////////////////////////////////////////////////////// 139 161 private SourceInfo constructSourceInfo(SourceIdentifier sourceIdentifier, String link, String version){ … … 144 166 return sourceInfo; 145 167 } 168 169 private Source constructSource(SourceIdentifier sourceIdentifier, String link, String version, String timeStamp) throws DatatypeConfigurationException{ 170 Source source = new Source(); 171 XMLGregorianCalendar xmlTimeStamp = DatatypeFactory.newInstance().newXMLGregorianCalendar(timeStamp); 172 source.setURI(sourceIdentifier.toString()); 173 source.setTimeSatmp(xmlTimeStamp); 174 source.setLink(link); 175 source.setVersion(version); 176 return source; 177 } 146 178 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDaoTest.java
r3211 r3292 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.TestBackendConstants;21 20 import java.io.File; 22 21 import java.io.FileNotFoundException; … … 29 28 import org.springframework.dao.DataAccessException; 30 29 import org.springframework.jdbc.core.JdbcTemplate; 31 import static org.junit.Assert.assertEquals;32 30 /** 33 31 * -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r3255 r3292 68 68 INSERT INTO version (external_id, version) VALUES ('00000000-0000-0000-0000-000000000044', 'Art Nuveau wiki -version 2013'); --4 69 69 INSERT INTO version (external_id, version) VALUES ('00000000-0000-0000-0000-000000000045', 'Art Nuveau wiki -version 2012'); --5 not used 70 INSERT INTO version (external_id, version) VALUES ('00000000-0000-0000-0000-000000000046', 'Art Nuveau wiki -version 2011'); --6 not eused70 INSERT INTO version (external_id, version) VALUES ('00000000-0000-0000-0000-000000000046', 'Art Nuveau wiki -version 2011'); --6 not used 71 71 72 72 -- CREATE TABLE target_source (
Note: See TracChangeset
for help on using the changeset viewer.