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