source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDao.java @ 3048

Last change on this file since 3048 was 3048, checked in by twagoo, 11 years ago

added comment to switch to named parameter JDBC support when doing extensions

File size: 1.7 KB
Line 
1package clarin.cmdi.componentregistry.impl.database;
2
3import java.util.List;
4import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
5import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
6
7/**
8 * Logic and constants shared by the dao's of the DB implementation
9 *
10 * TODO: For future extensions we may want to use {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport}
11 *
12 * @author Twan Goosen <twan.goosen@mpi.nl>
13 * @param <T> Type the dao maps to
14 */
15public abstract class ComponentRegistryDao<T> extends SimpleJdbcDaoSupport {
16
17    public final static String TABLE_COMMENTS = "comments";
18    public final static String TABLE_COMPONENT_DESCRIPTION = "component_description";
19    public final static String TABLE_PROFILE_DESCRIPTION = "profile_description";
20    public final static String TABLE_XML_CONTENT = "xml_content";
21    public final static String TABLE_REGISTRY_USER = "registry_user";
22    public final static String COLUMN_ID = "id";
23
24    public ComponentRegistryDao() {
25    }
26
27    protected T getFirstOrNull(StringBuilder selectQuery, Object... args) {
28        return getFirstOrNull(selectQuery.toString(), args);
29    }
30
31    protected T getFirstOrNull(String selectQuery, Object... args) {
32        List<T> list = getList(selectQuery, args);
33        if (list.size() > 0) {
34            return list.get(0);
35        } else {
36            return null;
37        }
38    }
39
40    protected List<T> getList(StringBuilder selectQuery, Object... args) {
41        return getList(selectQuery.toString(), args);
42    }
43
44    protected List<T> getList(String selectQuery, Object... args) {
45        return getSimpleJdbcTemplate().query(selectQuery, getRowMapper(), args);
46    }
47
48    /**
49     * @return the rowMapper
50     */
51    protected abstract ParameterizedRowMapper<T> getRowMapper();
52}
Note: See TracBrowser for help on using the repository browser.