Changeset 3373


Ignore:
Timestamp:
08/13/13 16:03:31 (11 years ago)
Author:
olhsha
Message:

removing a redundant method "if Notebook Is in the DB"

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

Legend:

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

    r3272 r3373  
    4040     */
    4141   
    42     // TODO: remoev this after notebooks are corrected so they do not use it!!
    43     public boolean isNotebookInTheDataBase(Number notebookID);
    44    
    4542   
    4643}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r3241 r3373  
    5252    @Autowired
    5353    private AnnotationDao jdbcAnnotationDao;
    54    
    5554
    5655    public JdbcNotebookDao(DataSource dataSource) {
     
    6059    @Override
    6160    public List<NotebookInfo> getNotebookInfos(UserIdentifier userID) {
    62         String sql = "SELECT "+notebookTitle+", "+notebookExternal_id+" FROM "+notebookTableName+", "+principalTableName+" where "+principalPrincipal_id+" = "+notebookOwner_id+" and "+principalExternal_id+" = ?";
     61        String sql = "SELECT " + notebookTitle + ", " + notebookExternal_id + " FROM " + notebookTableName + ", " + principalTableName + " where " + principalPrincipal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?";
    6362        return getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, userID.toString());
    6463    }
     
    6665    @Override
    6766    public List<Notebook> getUsersNotebooks(UserIdentifier userID) {
    68         String sql = "SELECT "+notebookStar+" FROM "+notebookTableName+", "+principalTableName+" where "+principal_id+" = "+owner_id+" and "+principalExternal_id+" = ?";
     67        String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + owner_id + " and " + principalExternal_id + " = ?";
    6968        return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString());
    7069    }
     
    7473        try {
    7574            final NotebookIdentifier notebookIdentifier = new NotebookIdentifier();
    76             String sql = "INSERT INTO "+notebookTableName+" ("+external_id+", "+this.title+","+ owner_id+") VALUES (:notebookId, :title, (SELECT "+principal_id+" FROM "+principalTableName+" WHERE "+principalExternal_id+" = :userID))";
     75            String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + owner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))";
    7776            Map<String, Object> params = new HashMap<String, Object>();
    7877            params.put("notebookId", notebookIdentifier.getUUID().toString());
     
    118117    @Override
    119118    public int deleteNotebook(NotebookIdentifier notebookId) {
    120         String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where "+notebook_id +"= (SELECT "+notebook_id+" FROM "+notebookTableName+" WHERE "+external_id+" = ?)";
     119        String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)";
    121120        String sql2 = "DELETE FROM notebook where external_id = ?";
    122121        int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.getUUID().toString());
     
    138137        }
    139138    }
    140    
    141      ////////////////////////////////////////////////////////////////////////
    142     /**
    143      * 
    144      * @param notebookID
    145      * @return the list of annotation-ids belonging to the notebook with notebookId
    146      * returns null if notebookId is null or is not in the DB
    147      * TODO: do we need to return null here? using an additional check.
    148      */
    149      @Override           
     139
     140    ////////////////////////////////////////////////////////////////////////
     141    /**
     142     *
     143     * @param notebookID
     144     * @return the list of annotation-ids belonging to the notebook with
     145     * notebookId returns null if notebookId is null or is not in the DB TODO:
     146     * do we need to return null here? using an additional check.
     147     */
     148    @Override
    150149    public List<Number> getAnnotationIDs(Number notebookID) {
    151150        if (notebookID == null) {
    152151            return null;
    153152        }
    154 
    155         // TODO remove "isNoteBookInTheDB"
    156         if (isNotebookInTheDataBase(notebookID)) {
    157             String sql = "SELECT "+notebooksAnnotationsTableNameAnnotation_id+"  FROM "+notebooksAnnotationsTableName+" where "+notebook_id+" = ?";
    158             return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString());
    159         } else {
    160             return null;
    161         }
    162     }
    163    
    164     private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {       
     153        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
     154        sql.append(notebooksAnnotationsTableNameAnnotation_id).append("  FROM ").append(notebooksAnnotationsTableName).append(" where ").append(notebook_id).append(" = ?");
     155        return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID.toString());
     156    }
     157    private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {
    165158        @Override
    166159        public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    169162        }
    170163    };
    171    
    172      //////////////////////////////////////////////////
    173    
    174     /**
    175      *
     164
     165    //////////////////////////////////////////////////
     166    /**
     167     *
    176168     * @param notebookID
    177169     * @return the list of annotation-infos of the annotations from notebookID;
    178      * if notebook not in the DB or null returns null
    179      * if the notebook contains no annotations returns an empty list
    180      *
    181    
    182     @Override
    183     public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) {   
    184         return jdbcAnnotationDao.getAnnotationInfos(getAnnotationIDs(notebookID));
    185     }*/
    186    
    187    
    188      //////////////////////////////////////////////
    189     /**
    190      *
    191      * @param notebookID
    192      * @return the list of annotation References from the notebookID
    193      * returns null if notebookID == null or it does not exists in the DB
    194      */
    195    
    196     @Override
    197     public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) {   
    198         return jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID));
    199     }
    200    
     170     * if notebook not in the DB or null returns null if the notebook contains
     171     * no annotations returns an empty list
     172     *
     173     *
     174     * @Override public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number
     175     * notebookID) { return
     176     * jdbcAnnotationDao.getAnnotationInfos(getAnnotationIDs(notebookID)); }
     177     */
     178    //////////////////////////////////////////////
     179    /**
     180     *
     181     * @param notebookID
     182     * @return the list of annotation References from the notebookID returns
     183     * null if notebookID == null or it does not exists in the DB
     184     */
     185    @Override
     186    public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) {
     187        return jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID));
     188    }
     189
    201190    ////////////////////////////////////////////////////////////////////////////
    202191    /**
    203      *
    204      * @param notebookID
    205      * @return the Annotations (as a list of references) from the notebookID     *
    206      * returns null if notebookID == null, or it does not exists in th DB, or the list of annotations is empty,
    207      * or something wrong happened when extracting annotations from the notebook
    208      * (according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!)
    209      *
    210      */
    211 
     192     *
     193     * @param notebookID
     194     * @return the Annotations (as a list of references) from the notebookID *
     195     * returns null if notebookID == null, or it does not exists in th DB, or
     196     * the list of annotations is empty, or something wrong happened when
     197     * extracting annotations from the notebook (according to dasish.xsd if an
     198     * Annotation is created then its list of annotations must contain at least
     199     * one element!)
     200     *
     201     */
    212202    @Override
    213203    public Annotations getAnnotations(Number notebookID) {
    214 
    215204        if (notebookID == null) {
    216205            return null;
    217206        }
    218 
    219        
    220         // TODO remove "isNoteBookInTheDB"
    221         if (isNotebookInTheDataBase(notebookID)) {
    222             Annotations result = new Annotations();
    223             List<ResourceREF> annotREFs = result.getAnnotation();
    224             // TODO: what of annotREFS is null????
    225             boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID));
    226             return (test ? result : null);
    227         } else {
    228             return null;
    229         }
    230 
    231     }
    232    
     207        Annotations result = new Annotations();
     208        List<ResourceREF> annotREFs = result.getAnnotation();
     209        boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID));
     210        return (test ? result : null);
     211
     212    }
     213
    233214    ///////////////////////////////////////////////////
    234215    // REUSES notebookInfoRowMapper
     
    238219            return null;
    239220        }
    240         String sql = "SELECT  "+notebookExternal_id+","+ notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ?";
     221        String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ?";
    241222        List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString());
    242223        if (result == null) {
     
    248229        return result.get(0);
    249230    }
    250    
     231
    251232    //////////////////////////////////////////////////
    252233    @Override
     
    255236            return null;
    256237        }
    257        
    258        String sql = "SELECT "+notebookNotebook_id+" FROM "+notebookTableName+" WHERE "+notebookExternal_id+"  = ?";
    259        List<Number> result= getSimpleJdbcTemplate().query(sql, notebookIdRowMapper, externalId.toString());
    260        if (result == null) {
    261            return null;
    262        }
    263        if (result.isEmpty()) {
    264            return null;
    265        }
    266        
    267        return result.get(0);
    268    }
    269      
    270       private final RowMapper<Number> notebookIdRowMapper = new RowMapper<Number>() {       
     238
     239        String sql = "SELECT " + notebookNotebook_id + " FROM " + notebookTableName + " WHERE " + notebookExternal_id + "  = ?";
     240        List<Number> result = getSimpleJdbcTemplate().query(sql, notebookIdRowMapper, externalId.toString());
     241        if (result == null) {
     242            return null;
     243        }
     244        if (result.isEmpty()) {
     245            return null;
     246        }
     247
     248        return result.get(0);
     249    }
     250    private final RowMapper<Number> notebookIdRowMapper = new RowMapper<Number>() {
    271251        @Override
    272252        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    273            Number result = rs.getInt(notebook_id);
    274            return result;
    275         }
    276     };
    277      
    278      
     253            Number result = rs.getInt(notebook_id);
     254            return result;
     255        }
     256    };
     257
    279258    //////////////////////////////////////////////////////////////////
    280259    @Override
    281     public  List<AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifier notebookId){
    282         List<Number> internalIds = getAnnotationIDs(getNotebookID(notebookId)); 
     260    public List<AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifier notebookId) {
     261        List<Number> internalIds = getAnnotationIDs(getNotebookID(notebookId));
    283262        if (internalIds == null) {
    284263            return null;
    285264        }
    286         List<AnnotationIdentifier> annotationIds  = new ArrayList<AnnotationIdentifier>();
     265        List<AnnotationIdentifier> annotationIds = new ArrayList<AnnotationIdentifier>();
    287266        for (Number internalId : internalIds) {
    288267            annotationIds.add(jdbcAnnotationDao.getExternalID(internalId));
     
    290269        return annotationIds;
    291270    }
    292    
     271
    293272    ////////////////////////////////////////////////////////////
    294273    @Override
    295     public int removeAnnotation(Number annotationID){       
    296         String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where "+annotation_id + " = ?";
     274    public int removeAnnotation(Number annotationID) {
     275        String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?";
    297276        int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationID);
    298277        return affectedNotebooks;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3370 r3373  
    182182    };
    183183   
    184     //////////////////////////////////////////
    185     /**
    186      *
    187      * @param notebookID
    188      * @return false if notebookID == null or the notebook with notebookID is not in the DB;
    189      * @return true if the notebook with notebookID in the DB
    190      */
    191     @Override
    192     public boolean isNotebookInTheDataBase(Number notebookID){
    193        
    194         if (notebookID == null) {
    195            return false;
    196        }
    197        String sql = "SELECT "+notebookNotebook_id+"  FROM notebook where "+notebook_id+" = ? LIMIT 1";
    198        List<Number> result=getSimpleJdbcTemplate().query(sql, isNotebookInTheDataBaseRowMapper, notebookID.toString());
    199        if (result == null) {
    200            return false;
    201        }
    202        if (result.isEmpty()) {
    203            return false;
    204        }
    205        return true;
    206     }
    207    
    208     private final RowMapper<Number> isNotebookInTheDataBaseRowMapper = new RowMapper<Number>() {       
    209         @Override
    210         public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException {
    211             Integer notebookId = rs.getInt(notebook_id);
    212             return notebookId;
    213         }
    214     };
     184   
    215185   
    216186   
Note: See TracChangeset for help on using the changeset viewer.