source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ProfileDescriptionDao.java @ 1701

Last change on this file since 1701 was 1701, checked in by twagoo, 12 years ago

Added comments count to component/profile description model. Retrieved from database by doing a count on the comments table

File size: 2.2 KB
Line 
1package clarin.cmdi.componentregistry.impl.database;
2
3import clarin.cmdi.componentregistry.model.AbstractDescription;
4import clarin.cmdi.componentregistry.model.ProfileDescription;
5import java.sql.ResultSet;
6import java.sql.SQLException;
7import java.util.Collections;
8import java.util.List;
9import java.util.Map;
10import org.apache.commons.collections.ListUtils;
11
12/**
13 *
14 * @author Twan Goosen <twan.goosen@mpi.nl>
15 */
16public 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}
Note: See TracBrowser for help on using the repository browser.