Ignore:
Timestamp:
08/22/13 12:17:19 (11 years ago)
Author:
olhsha
Message:

replacing DaishIdentifier?-based classes with simply UUID. tested. Works, excpet that UUID seems not be be serailizable, see e.g. getAllAnnotations in NotebookResource? where I have to use Peter's workoaroun to put UUID in JAXBElement<UUID>

File:
1 edited

Legend:

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

    r3373 r3455  
    2020import eu.dasish.annotation.backend.dao.AnnotationDao;
    2121import eu.dasish.annotation.backend.dao.NotebookDao;
    22 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    23 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    24 import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2522import eu.dasish.annotation.schema.Annotations;
    2623import eu.dasish.annotation.schema.Notebook;
     
    3431import java.util.List;
    3532import java.util.Map;
     33import java.util.UUID;
    3634import javax.sql.DataSource;
    3735import org.springframework.jdbc.core.RowMapper;
     
    5452
    5553    public JdbcNotebookDao(DataSource dataSource) {
    56         setDataSource(dataSource);
    57     }
    58 
    59     @Override
    60     public List<NotebookInfo> getNotebookInfos(UserIdentifier userID) {
     54        setDataSource(dataSource);       
     55        internalIdName = notebook_id;
     56        resourceTableName = notebookTableName;
     57    }
     58
     59    @Override
     60    public List<NotebookInfo> getNotebookInfos(UUID  userID) {
    6161        String sql = "SELECT " + notebookTitle + ", " + notebookExternal_id + " FROM " + notebookTableName + ", " + principalTableName + " where " + principalPrincipal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?";
    6262        return getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, userID.toString());
     
    6464
    6565    @Override
    66     public List<Notebook> getUsersNotebooks(UserIdentifier userID) {
     66    public List<Notebook> getUsersNotebooks(UUID userID) {
    6767        String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + owner_id + " and " + principalExternal_id + " = ?";
    6868        return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString());
     
    7070
    7171    @Override
    72     public NotebookIdentifier addNotebook(UserIdentifier userID, String title) {
     72    public UUID addNotebook(UUID userID, String title) {
    7373        try {
    74             final NotebookIdentifier notebookIdentifier = new NotebookIdentifier();
     74            final UUID externalIdentifier = UUID.randomUUID();
    7575            String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + owner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))";
    7676            Map<String, Object> params = new HashMap<String, Object>();
    77             params.put("notebookId", notebookIdentifier.getUUID().toString());
     77            params.put("notebookId", externalIdentifier.toString());
    7878            params.put("userID", userID.toString());
    7979            params.put("title", title);
    8080            final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params);
    81             return notebookIdentifier;
     81            return externalIdentifier;
    8282        } catch (DataAccessException exception) {
    8383            throw exception;
     
    116116    // returns the number of affected annotations
    117117    @Override
    118     public int deleteNotebook(NotebookIdentifier notebookId) {
     118    public int deleteNotebook(UUID notebookId) {
    119119        String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)";
    120120        String sql2 = "DELETE FROM notebook where external_id = ?";
    121         int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.getUUID().toString());
    122         int affectedNotebooks = getSimpleJdbcTemplate().update(sql2, notebookId.getUUID().toString());
     121        int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.toString());
     122        int affectedNotebooks = getSimpleJdbcTemplate().update(sql2, notebookId.toString());
    123123        return affectedAnnotations;
    124124    }
    125125
    126126    @Override
    127     public int addAnnotation(NotebookIdentifier notebookId, AnnotationIdentifier annotationId) {
     127    public int addAnnotation(UUID notebookId, UUID annotationId) {
    128128        try {
    129129            SimpleJdbcInsert notebookInsert = new SimpleJdbcInsert(getDataSource()).withTableName(notebooksAnnotationsTableName);
     
    148148    @Override
    149149    public List<Number> getAnnotationIDs(Number notebookID) {
    150         if (notebookID == null) {
    151             return null;
    152         }
    153150        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    154151        sql.append(notebooksAnnotationsTableNameAnnotation_id).append("  FROM ").append(notebooksAnnotationsTableName).append(" where ").append(notebook_id).append(" = ?");
    155         return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID.toString());
     152        return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID);
    156153    }
    157154    private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {
     
    230227    }
    231228
    232     //////////////////////////////////////////////////
    233     @Override
    234     public Number getNotebookID(NotebookIdentifier externalId) {
    235         if (externalId == null) {
    236             return null;
    237         }
    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>() {
    251         @Override
    252         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    253             Number result = rs.getInt(notebook_id);
    254             return result;
    255         }
    256     };
    257 
     229   
    258230    //////////////////////////////////////////////////////////////////
    259231    @Override
    260     public List<AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifier notebookId) {
    261         List<Number> internalIds = getAnnotationIDs(getNotebookID(notebookId));
     232    public List<UUID> getAnnotationExternalIDs(UUID notebookId) {
     233        List<Number> internalIds = getAnnotationIDs(getInternalID(notebookId));
    262234        if (internalIds == null) {
    263235            return null;
    264236        }
    265         List<AnnotationIdentifier> annotationIds = new ArrayList<AnnotationIdentifier>();
     237        List<UUID> annotationIds = new ArrayList<UUID>();
    266238        for (Number internalId : internalIds) {
    267239            annotationIds.add(jdbcAnnotationDao.getExternalID(internalId));
Note: See TracChangeset for help on using the changeset viewer.