Changeset 3455 for DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
- Timestamp:
- 08/22/13 12:17:19 (11 years ago)
- 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 20 20 import eu.dasish.annotation.backend.dao.AnnotationDao; 21 21 import 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;25 22 import eu.dasish.annotation.schema.Annotations; 26 23 import eu.dasish.annotation.schema.Notebook; … … 34 31 import java.util.List; 35 32 import java.util.Map; 33 import java.util.UUID; 36 34 import javax.sql.DataSource; 37 35 import org.springframework.jdbc.core.RowMapper; … … 54 52 55 53 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) { 61 61 String sql = "SELECT " + notebookTitle + ", " + notebookExternal_id + " FROM " + notebookTableName + ", " + principalTableName + " where " + principalPrincipal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?"; 62 62 return getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, userID.toString()); … … 64 64 65 65 @Override 66 public List<Notebook> getUsersNotebooks(U serIdentifieruserID) {66 public List<Notebook> getUsersNotebooks(UUID userID) { 67 67 String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + owner_id + " and " + principalExternal_id + " = ?"; 68 68 return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString()); … … 70 70 71 71 @Override 72 public NotebookIdentifier addNotebook(UserIdentifieruserID, String title) {72 public UUID addNotebook(UUID userID, String title) { 73 73 try { 74 final NotebookIdentifier notebookIdentifier = new NotebookIdentifier();74 final UUID externalIdentifier = UUID.randomUUID(); 75 75 String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + owner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))"; 76 76 Map<String, Object> params = new HashMap<String, Object>(); 77 params.put("notebookId", notebookIdentifier.getUUID().toString());77 params.put("notebookId", externalIdentifier.toString()); 78 78 params.put("userID", userID.toString()); 79 79 params.put("title", title); 80 80 final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params); 81 return notebookIdentifier;81 return externalIdentifier; 82 82 } catch (DataAccessException exception) { 83 83 throw exception; … … 116 116 // returns the number of affected annotations 117 117 @Override 118 public int deleteNotebook( NotebookIdentifiernotebookId) {118 public int deleteNotebook(UUID notebookId) { 119 119 String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)"; 120 120 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()); 123 123 return affectedAnnotations; 124 124 } 125 125 126 126 @Override 127 public int addAnnotation( NotebookIdentifier notebookId, AnnotationIdentifierannotationId) {127 public int addAnnotation(UUID notebookId, UUID annotationId) { 128 128 try { 129 129 SimpleJdbcInsert notebookInsert = new SimpleJdbcInsert(getDataSource()).withTableName(notebooksAnnotationsTableName); … … 148 148 @Override 149 149 public List<Number> getAnnotationIDs(Number notebookID) { 150 if (notebookID == null) {151 return null;152 }153 150 StringBuilder sql = new StringBuilder("SELECT DISTINCT "); 154 151 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); 156 153 } 157 154 private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() { … … 230 227 } 231 228 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 258 230 ////////////////////////////////////////////////////////////////// 259 231 @Override 260 public List< AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifiernotebookId) {261 List<Number> internalIds = getAnnotationIDs(get NotebookID(notebookId));232 public List<UUID> getAnnotationExternalIDs(UUID notebookId) { 233 List<Number> internalIds = getAnnotationIDs(getInternalID(notebookId)); 262 234 if (internalIds == null) { 263 235 return null; 264 236 } 265 List< AnnotationIdentifier> annotationIds = new ArrayList<AnnotationIdentifier>();237 List<UUID> annotationIds = new ArrayList<UUID>(); 266 238 for (Number internalId : internalIds) { 267 239 annotationIds.add(jdbcAnnotationDao.getExternalID(internalId));
Note: See TracChangeset
for help on using the changeset viewer.