Changeset 3222


Ignore:
Timestamp:
08/02/13 14:30:50 (11 years ago)
Author:
olhsha
Message:

adding getters for Version and CachedRepresentation? DAO's. Not finished and not tested

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/CachedRepresentationDao.java

    r3221 r3222  
    1919
    2020import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
     21import eu.dasish.annotation.schema.CachedRepresentationInfo;
     22import eu.dasish.annotation.schema.CachedRepresentations;
     23import java.util.List;
    2124
    2225/**
     
    2629public interface CachedRepresentationDao {
    2730   
     31    /**
     32     *
     33     * @param internalID
     34     * @return extrnalID identifier of the resource with internalID
     35     */
    2836    public CachedRepresentationIdentifier getExternalId(Number internalID);
     37   
     38    /**
     39     *
     40     * @param externalID
     41     * @return internal identifier of the resource with externalID
     42     */
     43    public  Number getExternalId(CachedRepresentationIdentifier externalID);
     44   
     45    /**
     46     *
     47     * @param internalID
     48     * @return the object which fields have the corresponding column values of the row internalID
     49     */
     50    public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID);
     51   
     52    /**
     53     *
     54     * @param versionID
     55     * @return List of cached_representation_id-s of all the cached representations of the version with versionID
     56     */
     57    public List<Number> retrieveCachedRepresentationList(Number versionID);
     58   
     59    /**
     60     *
     61     * @param versionID
     62     * @return List of cached_representation_id-s of all the cached representations of the version with versionID
     63     */
     64    public CachedRepresentations retrieveCachedRepresentations(Number versionID);
     65   
     66   
    2967}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java

    r3221 r3222  
    1919
    2020import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
     21import eu.dasish.annotation.schema.Version;
    2122
    2223/**
     
    2627public interface VersionDao {
    2728   
     29      /**
     30     *
     31     * @param internalID
     32     * @return extrnalID identifier of the resource with internalID
     33     */
     34   
    2835    public VersionIdentifier getExternalId(Number internalID);
     36   
     37    /**
     38     *
     39     * @param externalID
     40     * @return internal identifier of the resource with externalID
     41     */
     42    public  Number getExternalId(VersionIdentifier externalID);
     43   
     44   
     45    /**
     46     *
     47     * @param internalID
     48     * @return the object which fields have the corresponding column values of the row internalID
     49     */
     50    public Version getVersion(Number internalID);
     51   
    2952}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3221 r3222  
    2020import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
    2121import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
    22 import eu.dasish.annotation.schema.Annotation;
    23 import eu.dasish.annotation.schema.NewOrExistingSourceInfos;
     22import eu.dasish.annotation.schema.CachedRepresentationInfo;
     23import eu.dasish.annotation.schema.CachedRepresentations;
    2424import eu.dasish.annotation.schema.ResourceREF;
    25 import eu.dasish.annotation.schema.SourceInfo;
    2625import java.sql.ResultSet;
    2726import java.sql.SQLException;
     27import java.util.ArrayList;
    2828import java.util.List;
    2929import javax.sql.DataSource;
     
    4040    }
    4141     
    42  //////////////////////////////////////////////////////////////////////////////////////////////////////   
     42   //////////////////////////////////////////////////////////////////////////////////////////////////////
     43     @Override
    4344     public CachedRepresentationIdentifier getExternalId(Number internalID){
    4445       if (internalID == null) {
     
    6566        }
    6667     }; 
     68     
     69      //////////////////////////////////////////////////////////////////////////////////////////////////////
     70     @Override
     71     public Number getExternalId(CachedRepresentationIdentifier externalID){
     72       if (externalID == null) {
     73            return null;
     74        }
     75       String sql = "SELECT "+cached_representation_id+" FROM "+cachedRepresentationTableName+" WHERE "+external_id  +"= ?";
     76       List<Number> sqlResult= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalID);
     77       
     78       if (sqlResult == null) {
     79           return null;
     80       }
     81       if (sqlResult.isEmpty()) {
     82           return null;
     83       }
     84       
     85        Number result  = sqlResult.get(0);
     86        return result;
     87    } 
     88     
     89     private final RowMapper<Number> internalIDRowMapper = new RowMapper<Number>() {       
     90        @Override
     91        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     92            return(rs.getInt(cached_representation_id));
     93        }
     94     };
     95     
     96     ///////////////////////////////////////////////////////////////
     97     @Override
     98     public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID){
     99         
     100       String sql = "SELECT "+cachedRepresentationStar+" FROM "+cachedRepresentationTableName+" WHERE "+cached_representation_id  +"= ?";
     101       List<CachedRepresentationInfo> result= getSimpleJdbcTemplate().query(sql, cachedRepresentationRowMapper, internalID);
     102       
     103       if (result == null) {
     104           return null;
     105       }
     106       if (result.isEmpty()) {
     107           return null;
     108       }
     109       return result.get(0);
     110     }
     111     
     112     private final RowMapper<CachedRepresentationInfo> cachedRepresentationRowMapper = new RowMapper<CachedRepresentationInfo>() {       
     113        @Override
     114        public CachedRepresentationInfo mapRow(ResultSet rs, int rowNumber) throws SQLException {
     115            CachedRepresentationInfo result = new CachedRepresentationInfo();
     116            //external_id, mime_type, tool, type_, where_is_the_file
     117            result.setMimeType(rs.getString(mime_type));
     118            result.setRef(rs.getString(external_id));
     119            result.setTool(rs.getString(tool));
     120            result.setType(rs.getString(type_));
     121            // TODO add where is the file when the schem is updated!!!!s
     122            return result;
     123        }
     124     };
     125     
     126     
     127     ////////////////////////////////////////////////////////////////////////////
     128      @Override
     129      public List<Number> retrieveCachedRepresentationList(Number versionID){
     130       String sql = "SELECT "+cached_representation_id+" FROM "+versionsCachedRepresentationsTableName+" WHERE "+version_id  +"= ?";
     131       List<Number> result= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, versionID);
     132       
     133       if (result == null) {
     134           return null;
     135       }
     136       if (result.isEmpty()) {
     137           return null;
     138       }
     139       return result;
     140      };
     141     
     142     
     143      /////////////////////////////////////////////////////
     144     
     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     
    67162}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3221 r3222  
    8989    final static protected String principalExternal_id = principalTableName+"."+external_id;
    9090   
     91   
     92    final static protected String cachedRepresentationStar = cachedRepresentationTableName+".*";
     93   
     94    final static protected String versionStar = versionTableName+".*";
     95   
    9196    //////////////////////////////////////////
    9297    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java

    r3221 r3222  
    1919
    2020import eu.dasish.annotation.backend.dao.VersionDao;
    21 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
    2221import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
     22import eu.dasish.annotation.schema.CachedRepresentationInfo;
     23import eu.dasish.annotation.schema.Version;
    2324import java.sql.ResultSet;
    2425import java.sql.SQLException;
     
    6263            return(rs.getString(external_id));
    6364        }
    64      }; 
     65     };
     66     
     67      //////////////////////////////////////////////////////////////////////////////////////////////////////
     68     @Override
     69     public Number getExternalId(VersionIdentifier externalID){
     70       if (externalID == null) {
     71            return null;
     72        }
     73       String sql = "SELECT "+version_id+" FROM "+versionTableName+" WHERE "+external_id  +"= ?";
     74       List<Number> sqlResult= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalID);
     75       
     76       if (sqlResult == null) {
     77           return null;
     78       }
     79       if (sqlResult.isEmpty()) {
     80           return null;
     81       }
     82       
     83        Number result  = sqlResult.get(0);
     84        return result;
     85    } 
     86     
     87     private final RowMapper<Number> internalIDRowMapper = new RowMapper<Number>() {       
     88        @Override
     89        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     90            return(rs.getInt(version_id));
     91        }
     92     };
     93     
     94     
     95      ///////////////////////////////////////////////////////////////
     96     @Override
     97     public Version getVersion(Number internalID){
     98         
     99       String sql = "SELECT "+versionStar+" FROM "+versionTableName+" WHERE "+version_id  +"= ?";
     100       List<Version> result= getSimpleJdbcTemplate().query(sql, versionRowMapper, internalID);
     101       
     102       if (result == null) {
     103           return null;
     104       }
     105       if (result.isEmpty()) {
     106           return null;
     107       }
     108       return result.get(0);
     109     }
     110     
     111     private final RowMapper<Version> versionRowMapper = new RowMapper<Version>() {       
     112        @Override
     113        public Version mapRow(ResultSet rs, int rowNumber) throws SQLException {
     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
     121            return result;
     122        }
     123     };
     124     
    65125}
Note: See TracChangeset for help on using the changeset viewer.