1 | package clarin.cmdi.componentregistry.persistence.impl; |
---|
2 | |
---|
3 | import clarin.cmdi.componentregistry.model.AbstractDescription; |
---|
4 | import clarin.cmdi.componentregistry.model.ProfileDescription; |
---|
5 | import clarin.cmdi.componentregistry.persistence.ProfileDescriptionDao; |
---|
6 | |
---|
7 | import java.sql.ResultSet; |
---|
8 | import java.sql.SQLException; |
---|
9 | import java.util.Collections; |
---|
10 | import java.util.List; |
---|
11 | import java.util.Map; |
---|
12 | |
---|
13 | import org.apache.commons.collections.ListUtils; |
---|
14 | import org.springframework.stereotype.Repository; |
---|
15 | |
---|
16 | /** |
---|
17 | * |
---|
18 | * @author Twan Goosen <twan.goosen@mpi.nl> |
---|
19 | * @author George.Georgovassilis@mpi.nl |
---|
20 | */ |
---|
21 | @Repository |
---|
22 | public class ProfileDescriptionDaoImpl extends AbstractDescriptionDaoImpl<ProfileDescription> implements ProfileDescriptionDao{ |
---|
23 | |
---|
24 | public ProfileDescriptionDaoImpl() { |
---|
25 | super(ProfileDescription.class); |
---|
26 | } |
---|
27 | |
---|
28 | public List<ProfileDescription> getPublicProfileDescriptions() { |
---|
29 | return getPublicDescriptions(); |
---|
30 | } |
---|
31 | |
---|
32 | @Override |
---|
33 | protected String getTableName() { |
---|
34 | return TABLE_PROFILE_DESCRIPTION; |
---|
35 | } |
---|
36 | |
---|
37 | @Override |
---|
38 | protected String getCMDIdColumn() { |
---|
39 | return "profile_id"; |
---|
40 | } |
---|
41 | |
---|
42 | @Override |
---|
43 | protected String getCommentsForeignKeyColumn() { |
---|
44 | return "profile_description_id"; |
---|
45 | } |
---|
46 | |
---|
47 | @Override |
---|
48 | protected StringBuilder getDescriptionColumnList() { |
---|
49 | return super.getDescriptionColumnList().append(",show_in_editor"); |
---|
50 | } |
---|
51 | |
---|
52 | @Override |
---|
53 | protected void putInsertParameters(Map<String, Object> params, AbstractDescription description, Number contentId, Number userId, boolean isPublic) { |
---|
54 | super.putInsertParameters(params, description, contentId, userId, isPublic); |
---|
55 | params.put("show_in_editor", ((ProfileDescription) description).isShowInEditor()); |
---|
56 | } |
---|
57 | |
---|
58 | @Override |
---|
59 | protected void setDescriptionValuesFromResultSet(ResultSet rs, AbstractDescription newDescription) throws SQLException { |
---|
60 | super.setDescriptionValuesFromResultSet(rs, newDescription); |
---|
61 | ((ProfileDescription) newDescription).setShowInEditor(rs.getBoolean("show_in_editor")); |
---|
62 | } |
---|
63 | |
---|
64 | @Override |
---|
65 | protected void appendUpdateColumnsStatement(StringBuilder updateDescription) { |
---|
66 | super.appendUpdateColumnsStatement(updateDescription); |
---|
67 | updateDescription.append(" , show_in_editor=?"); |
---|
68 | } |
---|
69 | |
---|
70 | @Override |
---|
71 | protected List getUpdateParameterValues(AbstractDescription description) { |
---|
72 | return ListUtils.union( |
---|
73 | super.getUpdateParameterValues(description), |
---|
74 | // Add value for 'shown_in_editor' to abstract description |
---|
75 | Collections.singletonList(((ProfileDescription) description).isShowInEditor())); |
---|
76 | } |
---|
77 | } |
---|