Changeset 3236
- Timestamp:
- 08/05/13 13:32:17 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/CachedRepresentationDao.java
r3222 r3236 41 41 * @return internal identifier of the resource with externalID 42 42 */ 43 public Number get ExternalId(CachedRepresentationIdentifier externalID);43 public Number getInternalId(CachedRepresentationIdentifier externalID); 44 44 45 45 /** 46 46 * 47 47 * @param internalID 48 * @return the object which fields have the corresponding column values of the row internalID48 * @return the object "cached representation info" with the internal id "internalID" 49 49 */ 50 50 public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID); … … 53 53 * 54 54 * @param versionID 55 * @return List of cached_representation_id-s of all the cached representations of the version with versionID55 * @return The list list of cached representation internal id-s of all the cached representations of the version with versionID 56 56 */ 57 57 public List<Number> retrieveCachedRepresentationList(Number versionID); … … 59 59 /** 60 60 * 61 * @param versionID 62 * @return List of cached_representation_id-s of all the cached representations of the version with versionID 61 * @param internalID 62 * @return the amount of rows affected by removing from the DB the cached representation with the id "intenalID" 63 * should be "1" (or 0 with a non-existing id on the input) 63 64 */ 64 public CachedRepresentations retrieveCachedRepresentations(Number versionID);65 public int deleteCachedRepresentationInfo(Number internalID); 65 66 67 /** 68 * 69 * @param cached 70 * @return copy of "cached" after "cached" is added to the DB; the internal id is set in the return copy 71 */ 72 public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached); 66 73 67 74 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3221 r3236 333 333 334 334 335 336 337 //TODO: update when target sources and permissions are added 335 ////////////////////////////////////////// 336 338 337 private Annotation makeFreshCopy(Annotation annotation){ 339 338 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r3222 r3236 21 21 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier; 22 22 import eu.dasish.annotation.schema.CachedRepresentationInfo; 23 import eu.dasish.annotation.schema.CachedRepresentations;24 import eu.dasish.annotation.schema.ResourceREF;25 23 import java.sql.ResultSet; 26 24 import java.sql.SQLException; 27 import java.util. ArrayList;25 import java.util.HashMap; 28 26 import java.util.List; 27 import java.util.Map; 29 28 import javax.sql.DataSource; 30 29 import org.springframework.jdbc.core.RowMapper; … … 69 68 ////////////////////////////////////////////////////////////////////////////////////////////////////// 70 69 @Override 71 public Number get ExternalId(CachedRepresentationIdentifier externalID){70 public Number getInternalId(CachedRepresentationIdentifier externalID){ 72 71 if (externalID == null) { 73 72 return null; 74 73 } 75 74 String sql = "SELECT "+cached_representation_id+" FROM "+cachedRepresentationTableName+" WHERE "+external_id +"= ?"; 76 List<Number> sqlResult= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalID );75 List<Number> sqlResult= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalID.toString()); 77 76 78 77 if (sqlResult == null) { … … 90 89 @Override 91 90 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 92 return(rs.getInt(cached_representation_id)); 91 int result = rs.getInt(cached_representation_id); 92 Number resultNumber = result; 93 return resultNumber; 93 94 } 94 95 }; … … 140 141 }; 141 142 143 //////////////////////////////////////////////////////////////////////////// 144 @Override 145 public int deleteCachedRepresentationInfo(Number internalID){ 146 String sql = "DELETE FROM " + cachedRepresentationTableName + " where "+cached_representation_id + " = ?"; 147 String sqlVersionsCachedRepresentations = "DELETE FROM " + versionsCachedRepresentationsTableName + " where "+cached_representation_id + " = ?"; 148 getSimpleJdbcTemplate().update(sqlVersionsCachedRepresentations, internalID); 149 return (getSimpleJdbcTemplate().update(sql, internalID)); 150 }; 151 152 //////////////////////////////////////////////////////////////////////////// 153 @Override 154 public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached){ 155 156 CachedRepresentationIdentifier externalIdentifier = new CachedRepresentationIdentifier(); 157 158 Map<String, Object> params = new HashMap<String, Object>(); 159 params.put("externalId", externalIdentifier.toString()); 160 params.put("mime_type", cached.getMimeType()); 161 params.put("tool", cached.getTool()); 162 params.put("type", cached.getType()); 163 String sql = "INSERT INTO "+cachedRepresentationTableName + "("+external_id+","+ mime_type+"," + tool+","+type_+" ) VALUES (:externalId, :mime_type, :tool, :type)"; 164 final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 165 CachedRepresentationInfo cachedNew = makeFreshCopy(cached); 166 return cachedNew; 167 } 142 168 143 ////////// ///////////////////////////////////////////169 ////////// Helpers /////////////////// 144 170 145 @Override 146 public CachedRepresentations retrieveCachedRepresentations(Number versionID){ 147 CachedRepresentations result = new CachedRepresentations(); 148 149 List<Number> cachedRepresenationIDs = retrieveCachedRepresentationList(versionID); 150 List<ResourceREF> cachedRepresenationIdentifierList = new ArrayList<ResourceREF>(); 151 152 for (Number cachedRepresentationID : cachedRepresenationIDs){ 153 ResourceREF resourceREF = new ResourceREF(); 154 resourceREF.setRef(getExternalId(cachedRepresentationID).toString()); 155 cachedRepresenationIdentifierList.add(resourceREF); 156 } 157 158 result.getCachedRepresentation().addAll(cachedRepresenationIdentifierList); 159 return result; 160 }; 161 171 private CachedRepresentationInfo makeFreshCopy(CachedRepresentationInfo cached){ 172 CachedRepresentationInfo result = new CachedRepresentationInfo(); 173 result.setMimeType(cached.getMimeType()); 174 result.setRef(cached.getRef()); 175 result.setTool(cached.getTool()); 176 result.setType(cached.getType()); 177 return result; 178 } 162 179 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3222 r3236 45 45 final static protected String permissionsTableName = "annotations_principals_permissions"; 46 46 final static protected String annotationsSourcesTableName = "annotations_target_sources"; 47 final static protected String versionsCachedRepresentationsTableName = "versions +cached_representations";47 final static protected String versionsCachedRepresentationsTableName = "versions_cached_representations"; 48 48 49 49 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java
r3222 r3236 113 113 public Version mapRow(ResultSet rs, int rowNumber) throws SQLException { 114 114 Version result = new Version(); 115 //external_id, mime_type, tool, type_, where_is_the_file 116 // result.setCachedRepresentations((rs.get) 117 // result.setRef(rs.getString(external_id)); 118 // result.setTool(rs.getString(tool)); 119 // result.setType(rs.getString(type_)); 120 // TODO add where is the file when the schem is updated!!!!s 115 // TODO: clarify situation with the attribute cached representation 116 //result.setCachedRepresentations!!! The same situation as with permissions lists: we cannot refer from a filed to a list of smth, we have a separate joint table 117 // TODO: attribute URI (external-id is missing) 118 result.setVersion(rs.getString("external_id")); 121 119 return result; 122 120 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r3220 r3236 81 81 public static final int _TEST_SOURCE_1_VERSION_ID = 1; 82 82 public static final int _TEST_SOURCE_2_VERSION_ID = 3; 83 84 public static final String _TEST_CACHED_REPRESENTATION_1_EXT_ID_ = "00000000-0000-0000-0000-000000000051"; 85 // INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000051', 'text/html', 'latex', 'text', 'corpus1'); --1 86 public static final String _TEST_CACHED_REPRESENTATION_1_MIME_TYPE_ = "text/html"; 87 public static final String _TEST_CACHED_REPRESENTATION_1_TOOL_ = "latex"; 88 public static final String _TEST_CACHED_REPRESENTATION_1_TYPE_ = "text"; 89 90 83 91 } 84 92 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java
r3220 r3236 66 66 67 67 // so far tests only adding annot with existing sources!!! 68 // TOD : add non-existing sources68 // TODO: add non-existing sources 69 69 private Annotation makeAnnotation(String bodyTxt, String headline, int ownerId){ 70 70 Annotation result = new Annotation(); … … 91 91 return _annotationToAdd; 92 92 } 93 94 93 95 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r3217 r3236 123 123 INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000053', 'image/png', 'screenshooter', 'image', 'corpus1'); -- 3 124 124 INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000054', 'text/html', 'oxygen', 'text', 'corpus1'); --4 125 INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000055', 'image/jpg', 'photomaster', 'image', 'TLAscratch'); --5 125 126 126 127 -------------------------------------------------------------- … … 138 139 INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (3, 2); 139 140 INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (4, 4); 140 141 INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (1, 5); 141 142 142 143 ---- PERMISSIONS --------------------------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.