Changeset 1318


Ignore:
Timestamp:
05/16/11 13:05:02 (13 years ago)
Author:
twagoo
Message:

InsertDescription? method with parameters for userId and isPublic

Location:
ComponentRegistry/trunk/ComponentRegistry/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDao.java

    r1316 r1318  
    6363     * @return Id of newly inserted description
    6464     */
    65     public Number insertComponent(final AbstractDescription description,
    66             final String content) {
     65    public Number insertDescription(AbstractDescription description, String content, boolean isPublic, Number userId) {
    6766        SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).
    6867                withTableName(TABLE_XML_CONTENT).usingGeneratedKeyColumns(
     
    7675        Map<String, Object> params = new HashMap<String, Object>();
    7776        params.put("content_id", contentId);
    78         params.put("is_public", Boolean.TRUE);
     77        params.put("userId", userId);
     78        params.put("is_public", isPublic);
    7979        params.put("is_deleted", Boolean.FALSE);
    8080        params.put(getCMDIdColumn(), description.getId());
     
    128128     */
    129129    public void setDeleted(String id) {
    130         String delete = "UPDATE " + getTableName() + " SET is_deleted = true WHERE " + getCMDIdColumn() + " = :id";
    131         getSimpleJdbcTemplate().update(delete, Collections.singletonMap("id", id));
    132     }
    133 
     130        String update = "UPDATE " + getTableName() + " SET is_deleted = true WHERE " + getCMDIdColumn() + " = :id";
     131        getSimpleJdbcTemplate().update(update, Collections.singletonMap("id", id));
     132    }
     133
     134    public void setPublished(String id, boolean published) {
     135        final String update = "UPDATE " + getTableName() + " SET is_published = :published WHERE " + getCMDIdColumn() + " = :id";
     136        final Map<String, Object> args = new HashMap<String, Object>();
     137        args.put("id", id);
     138        args.put("published", published);
     139
     140        getSimpleJdbcTemplate().update(update, Collections.singletonMap("id", id));
     141    }
    134142    /*
    135143     * DAO HELPER METHODS (may well be moved to some other place in class hierarchy at a later time)
    136144     */
     145
    137146    private T getFirstOrNull(StringBuilder selectQuery, Object... args) {
    138147        return getFirstOrNull(selectQuery.toString(), args);
     
    153162
    154163    private List<T> getList(String selectQuery, Object... args) {
    155         return getSimpleJdbcTemplate().query(selectQuery, rowMapper, args);
     164        return getSimpleJdbcTemplate().query(selectQuery, getRowMapper(), args);
    156165    }
    157166
     
    176185        return "name, description, " + getCMDIdColumn();
    177186    }
     187   
    178188    private final ParameterizedRowMapper<T> rowMapper = new ParameterizedRowMapper<T>() {
    179189
     
    195205        }
    196206    };
     207
     208    /**
     209     * @return the rowMapper
     210     */
     211    protected ParameterizedRowMapper<T> getRowMapper() {
     212        return rowMapper;
     213    }
    197214}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1316 r1318  
    119119            String xml = os.toString();
    120120            if (description.isProfile()) {
    121                 profileDescriptionDao.insertComponent(description, xml);
     121                profileDescriptionDao.insertDescription(description, xml, isPublic(), userId);
    122122            } else {
    123                 componentDescriptionDao.insertComponent(description, xml);
     123                componentDescriptionDao.insertDescription(description, xml, isPublic(), userId);
    124124            }
    125125            return 0;
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDaoTest.java

    r1316 r1318  
    4141
    4242        String testComponent = RegistryTestHelper.getComponentTestContentString();
    43         Number newId = getDao().insertComponent(description, testComponent);
     43        Number newId = getDao().insertDescription(description, testComponent, true, null);
    4444        assertNotNull(newId);
    4545        assertNotNull(getDao().getById(newId));
     
    6767        int count = getDao().getPublicDescriptions().size();
    6868        // insert
    69         getDao().insertComponent(description, testComponent);
     69        getDao().insertDescription(description, testComponent, true, null);
    7070        assertEquals(count+1, getDao().getPublicDescriptions().size());
    7171
Note: See TracChangeset for help on using the changeset viewer.