Changeset 3298
- Timestamp:
- 08/07/13 12:56:03 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/CachedRepresentationDao.java
r3297 r3298 66 66 67 67 68 /** 69 * 70 * @return the list of all the internal id-s of the cached representations. 71 */ 72 public List<Number> cachedRepresentationIDs(); 73 68 74 69 75 70 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java
r3297 r3298 68 68 69 69 70 /** 71 * 72 * @return the list of all internal sourceIDs 73 */ 74 public List<Number> sourceIDs(); 75 76 /** 77 * removes all the sources from the DAb which are not target sources of some annotations 78 * @return 79 */ 80 public int purgeAll(); 81 70 82 71 ////////////////////////////////////////////// 83 72 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java
r3297 r3298 69 69 70 70 71 72 /** 73 * 74 * @return the list of all the internal-ids of all the versions 75 */ 76 public List<Number> versionIDs(); 71 77 72 78 73 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r3297 r3298 120 120 121 121 if (result.isEmpty()) { 122 // r emove the cached representation safely122 // rou can remove the cached representation 123 123 String sql = "DELETE FROM " + cachedRepresentationTableName + " where " + cached_representation_id + " = ?"; 124 124 return getSimpleJdbcTemplate().update(sql, internalID); … … 137 137 }; 138 138 139 ////////////////////////////////////////////////////////////////////////////////////////////// 140 @Override 141 public List<Number> cachedRepresentationIDs() { 142 String sqlCheck = "SELECT " + cached_representation_id + " FROM " + cachedRepresentationTableName; 143 List<Number> result = getSimpleJdbcTemplate().query(sqlCheck, cachedRepresentationRunnerRowMapper); 144 return result; 145 } 146 private final RowMapper<Number> cachedRepresentationRunnerRowMapper = new RowMapper<Number>() { 147 @Override 148 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 149 Number result = rs.getInt(cached_representation_id); 150 return result; 151 } 152 }; 153 139 154 140 155 141 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3297 r3298 59 59 final static protected String time_stamp = "time_stamp"; 60 60 final static protected String permission = "permission_"; 61 //final static protected String target_source_id = "target_source_id"; 62 final static protected String link = "link"; 61 final static protected String link_uri = "link_uri"; 63 62 final static protected String version = "version"; 64 63 final static protected String cached_representation_id = "cached_representation_id"; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3297 r3298 19 19 20 20 import eu.dasish.annotation.backend.dao.SourceDao; 21 import eu.dasish.annotation.backend.dao.VersionDao; 21 22 import eu.dasish.annotation.backend.identifiers.SourceIdentifier; 22 23 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; … … 27 28 import java.sql.SQLException; 28 29 import java.util.ArrayList; 30 import java.util.HashMap; 29 31 import java.util.List; 32 import java.util.Map; 30 33 import javax.sql.DataSource; 31 34 import javax.xml.datatype.DatatypeConfigurationException; 32 35 import javax.xml.datatype.DatatypeFactory; 33 36 import javax.xml.datatype.XMLGregorianCalendar; 37 import org.springframework.beans.factory.annotation.Autowired; 34 38 import org.springframework.jdbc.core.RowMapper; 35 39 … … 39 43 */ 40 44 public class JdbcSourceDao extends JdbcResourceDao implements SourceDao{ 45 46 @Autowired 47 VersionDao versionDao; 41 48 42 49 public JdbcSourceDao(DataSource dataSource) { … … 75 82 }; 76 83 84 /////////////////////////////////////////////////////////////////////////////// 85 @Override 77 86 public Source getSource(Number internalID) { 78 87 String sql = "SELECT "+sourceStar+"FROM "+sourceTableName+" WHERE "+source_id +" = ?"; … … 85 94 public Source mapRow(ResultSet rs, int rowNumber) throws SQLException { 86 95 try { 87 Source result = constructSource(new SourceIdentifier(rs.getString(external_id)), rs.getString(link ), rs.getString(version), rs.getString(time_stamp));96 Source result = constructSource(new SourceIdentifier(rs.getString(external_id)), rs.getString(link_uri), rs.getString(version), rs.getString(time_stamp)); 88 97 return result; 89 98 } … … 96 105 }; 97 106 98 107 /////////////////////////////////////////////////////////////////// 108 @Override 99 109 public int deleteSource(Number internalID){ 100 String sql = "DELETE FROM " + sourceTableName + " where " + source_id + " = ?"; 101 return (getSimpleJdbcTemplate().update(sql, internalID)); 102 } 103 104 110 111 // check if there are annotations referring to the source with "internalID", in the table "annotations_sources" 112 String sqlAnnotationsSources = "SELECT " + annotation_id + " FROM " + annotationsSourcesTableName + " WHERE " + source_id + "= ?"; 113 List<Number> resultAnnotationsSources = getSimpleJdbcTemplate().query(sqlAnnotationsSources, annotationsSourcesRowMapper, internalID); 114 115 if (resultAnnotationsSources.isEmpty()) { 116 117 // You can remove the source! 118 119 // retrieve the list of versions of the source to be deleted 120 List<Number> versions = versionDao.retrieveVersionList(internalID); 121 122 // remove all the pairs (internalID, version_id) from the joint table 123 String sqlSourcesVersions = "DELETE FROM " + sourcesVersionsTableName + " where " + source_id + " = ?"; 124 int affected_sources_versions_rows = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 125 126 // the main action: remove the source with internalID from "source" table 127 String sql = "DELETE FROM " + sourceTableName + " where " + source_id + " = ?"; 128 int affected_source_rows = getSimpleJdbcTemplate().update(sql, internalID); 129 130 // remove the versions of "versions" from the DB unless they are still mentioned in "sources_versions" 131 for (Number versionID : versions) { 132 versionDao.deleteVersion(versionID); 133 } 134 135 return (affected_source_rows); 136 } else { 137 // do not remove 138 return 0; 139 } 140 } 141 142 private final RowMapper<Number> annotationsSourcesRowMapper = new RowMapper<Number>() { 143 @Override 144 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 145 Number result = rs.getInt(annotation_id); 146 return result; 147 } 148 }; 149 150 151 /////////////////////////////////////////////////////////////////// 152 @Override 105 153 public Source addSource(Source freshSource){ 106 return null; 107 } 108 109 110 public List<Number> sourceIDs(){ 111 return null; 112 } 113 114 115 public int purgeAll(){ 116 return -1; 117 } 154 155 SourceIdentifier externalIdentifier = new SourceIdentifier(); 156 157 Map<String, Object> params = new HashMap<String, Object>(); 158 params.put("externalId", externalIdentifier.toString()); 159 params.put("linkUri", freshSource.getLink()); 160 params.put("versionId", freshSource.getVersion()); 161 String sql = "INSERT INTO " + sourceTableName + "(" + external_id + "," + link_uri + "," + version_id + " ) VALUES (:externalId, :linkUri, :versionId)"; 162 final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 163 164 Map<String, Object> paramsJoint = new HashMap<String, Object>(); 165 paramsJoint.put("sourceId", getInternalID(externalIdentifier)); 166 paramsJoint.put("versionId", freshSource.getVersion()); 167 String sqlSourceVersion = "INSERT INTO " + sourcesVersionsTableName + "(" + source_id + "," + version_id + " ) VALUES (:sourceId, :versionId)"; 168 int affectedRowsJoint = getSimpleJdbcTemplate().update(sqlSourceVersion, paramsJoint); 169 170 Source result = makeFreshCopy(freshSource); 171 result.setURI(externalIdentifier.toString()); 172 173 return result; 174 175 } 176 118 177 119 178 //////////////////////////////////////////////////////////////// 120 179 /////////////////////////////////////////////////////////////////// 180 @Override 121 181 public List<SourceInfo> getSourceInfos(Number annotationID){ 122 182 String sourceIDs = makeListOfValues(retrieveSourceIDs(annotationID)); 123 String sql = "SELECT "+external_id+","+ link +"," + version+"FROM "+sourceTableName+" WHERE "+source_id +" IN "+sourceIDs;183 String sql = "SELECT "+external_id+","+ link_uri +"," + version+"FROM "+sourceTableName+" WHERE "+source_id +" IN "+sourceIDs; 124 184 List<SourceInfo> result= getSimpleJdbcTemplate().query(sql, SourceInfoRowMapper); 125 185 return result; … … 129 189 @Override 130 190 public SourceInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 131 return constructSourceInfo(new SourceIdentifier(rs.getString(external_id)), rs.getString(link ), rs.getString(version));191 return constructSourceInfo(new SourceIdentifier(rs.getString(external_id)), rs.getString(link_uri), rs.getString(version)); 132 192 } 133 193 }; … … 171 231 return source; 172 232 } 233 234 private Source makeFreshCopy(Source source) { 235 Source result = new Source(); 236 result.setLink(source.getLink()); 237 result.setURI(source.getURI()); 238 result.setVersion(source.getVersion()); 239 result.setTimeSatmp(source.getTimeSatmp()); 240 //versions-siblings are mentioned in the table sources_versions 241 return result; 242 } 173 243 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java
r3297 r3298 174 174 175 175 176 //////////////////////////////////////////////////////177 @Override178 public List<Number> versionIDs() {179 String sqlCheck = "SELECT " + version_id + " FROM " + versionTableName;180 List<Number> result = getSimpleJdbcTemplate().query(sqlCheck, versionRunnerRowMapper);181 return result;182 }183 private final RowMapper<Number> versionRunnerRowMapper = new RowMapper<Number>() {184 @Override185 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {186 Number result = rs.getInt(version_id);187 return result;188 }189 };190 191 192 176 193 177 private Version makeFreshCopy(Version version) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java
r3297 r3298 160 160 161 161 162 /** 163 * test public List<Number> cachedRepresentationIDs() 164 * public List<Number> cachedRepresentationIDs() 165 */ 166 @Test 167 public void testCachedRepresentationIDs() { 168 System.out.println(" test cachedRepresentationIDs"); 169 List<Number> result = jdbcCachedRepresentationDao.cachedRepresentationIDs(); 170 assertEquals(7, result.size()); 171 assertEquals(1, result.get(0)); 172 assertEquals(2, result.get(1)); 173 assertEquals(3, result.get(2)); 174 assertEquals(4, result.get(3)); 175 assertEquals(5, result.get(4)); 176 assertEquals(6, result.get(5)); 177 assertEquals(7, result.get(6)); 178 } 179 162 180 163 181 164 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java
r3297 r3298 166 166 167 167 168 /** 169 * Test of versionIDs method, of class JdbcVersionDao. 170 */ 171 @Test 172 public void testVersionIDs() { 173 System.out.println("versionIDs"); 174 List result = jdbcVersionDao.versionIDs(); 175 assertEquals(6, result.size()); 176 assertEquals(1, result.get(0)); 177 assertEquals(2, result.get(1)); 178 assertEquals(3, result.get(2)); 179 assertEquals(4, result.get(3)); 180 assertEquals(5, result.get(4)); 181 assertEquals(6, result.get(5)); 182 } 183 168 184 169 185 170 }
Note: See TracChangeset
for help on using the changeset viewer.