Changeset 3292


Ignore:
Timestamp:
08/06/13 16:15:13 (11 years ago)
Author:
olhsha
Message:

added signatures for SourceDao? toolkit: getting externalId, get Source, retrieve (given an annotationId), add, delete, purge. Implementing getSource, retrieve the list of all SourceId?'s

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  
    3737    public SourceIdentifier getExternalID(Number internalID);
    3838   
    39    
     39    /**
     40     *
     41     * @param annotationID
     42     * @return the list of the source's internal IDs of all the target sources of annotationID
     43     */
    4044    public List<Number> retrieveSourceIDs(Number annotationID);
    4145   
     46    /**
     47     *
     48     * @param inernalID
     49     * @return the object containing the source with the intrenal Id "internalId"
     50     */
     51    public Source getSource(Number internalID);
    4252   
    43     public Source getSource(Number inernalID);
    44    
    45    
     53    /**
     54     *
     55     * @param internalID
     56     * @return delete the source with the internal ID "internalID"
     57     */
    4658    public int deleteSource(Number internalID);
    4759   
    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     */
    4966    public Source addSource(Source freshSource);
    5067   
    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     */
    5274    public int purge(Number internalId);
    5375   
    54    
     76    /**
     77     *
     78     * @return the list of all internal sourceIDs
     79     */
    5580    public List<Number> sourceIDs();
    5681   
    57    
     82    /**
     83     * removes  all the sources from the DAb which are  not target sources of some annotations
     84     * @return
     85     */
    5886    public int purgeAll();
    5987   
    60    
     88    //////////////////////////////////////////////
    6189   
    6290    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3272 r3292  
    9999    }
    100100
    101     ;
     101   
    102102     
    103103      ////////////////////////////////////////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3272 r3292  
    6060    final static protected String time_stamp = "time_stamp";
    6161    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";
    6363    final static protected String link = "link";
    6464    final static protected String version = "version";
     
    9090   
    9191   
    92     final static protected String cachedRepresentationStar = cachedRepresentationTableName+".*";
    93    
     92    final static protected String cachedRepresentationStar = cachedRepresentationTableName+".*";   
    9493    final static protected String versionStar = versionTableName+".*";
     94    final static protected String sourceStar = sourceTableName+".*";
    9595   
    9696    ///////////////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java

    r3279 r3292  
    2020import eu.dasish.annotation.backend.dao.SourceDao;
    2121import eu.dasish.annotation.backend.identifiers.SourceIdentifier;
    22 import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
    2322import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    2423import eu.dasish.annotation.schema.NewOrExistingSourceInfos;
     
    3029import java.util.List;
    3130import javax.sql.DataSource;
     31import javax.xml.datatype.DatatypeConfigurationException;
     32import javax.xml.datatype.DatatypeFactory;
     33import javax.xml.datatype.XMLGregorianCalendar;
    3234import org.springframework.jdbc.core.RowMapper;
    3335
     
    5153   
    5254 
     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     };
    5376   
    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);
    5681    }
    5782   
    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    };
    6297   
    6398   
    6499    public int deleteSource(Number internalID){
    65         return -1;
     100        String sql = "DELETE FROM " + sourceTableName + " where " + source_id + " = ?";
     101        return (getSimpleJdbcTemplate().update(sql, internalID));
    66102    }
    67103   
     
    89125   
    90126    public List<SourceInfo> getSourceInfos(Number annotationID){
    91        String sourceIDs = makeListOfValues(getSourceInternalIdentifiers(annotationID));
     127       String sourceIDs = makeListOfValues(retrieveSourceIDs(annotationID));
    92128       String sql = "SELECT "+external_id+","+ link +"," + version+"FROM "+sourcesTableName+" WHERE "+source_id  +" IN "+sourceIDs;
    93129       List<SourceInfo> result= getSimpleJdbcTemplate().query(sql, SourceInfoRowMapper);       
     
    121157    //////// HELPERS //////////////////////
    122158   
    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 
    138160    ////////////////////////////////////////////////////////
    139161    private SourceInfo constructSourceInfo(SourceIdentifier sourceIdentifier, String link, String version){
     
    144166        return sourceInfo;
    145167    }
     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    }
    146178}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDaoTest.java

    r3211 r3292  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
    20 import eu.dasish.annotation.backend.TestBackendConstants;
    2120import java.io.File;
    2221import java.io.FileNotFoundException;
     
    2928import org.springframework.dao.DataAccessException;
    3029import org.springframework.jdbc.core.JdbcTemplate;
    31 import static org.junit.Assert.assertEquals;
    3230/**
    3331 *
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3255 r3292  
    6868INSERT INTO version (external_id, version) VALUES ('00000000-0000-0000-0000-000000000044', 'Art Nuveau wiki -version 2013'); --4
    6969INSERT 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  note used
     70INSERT INTO version (external_id, version) VALUES ('00000000-0000-0000-0000-000000000046', 'Art Nuveau wiki -version 2011'); --6  not used
    7171
    7272-- CREATE TABLE target_source (
Note: See TracChangeset for help on using the changeset viewer.