Revision 39076
Added by Antonis Lempesis over 8 years ago
HelpDAO.java | ||
---|---|---|
16 | 16 |
*/ |
17 | 17 |
public class HelpDAO { |
18 | 18 |
|
19 |
@Autowired
|
|
20 |
private DataSource dataSource;
|
|
19 |
@Autowired
|
|
20 |
private DataSource dataSource;
|
|
21 | 21 |
|
22 |
private final static String UPDATE_HELP = "update help set name=?, text=? where id=?";
|
|
23 |
private final static String INSERT_HELP = "insert into help (name, text, id) values (?, ?, ?)";
|
|
24 |
private final static String GET_BY_ID = "select id, name, text from help where id = ?";
|
|
25 |
private final static String GET_ALL = "select id, name, text from help";
|
|
26 |
private final static String DELETE = "delete from help where id = ?";
|
|
22 |
private final static String UPDATE_HELP = "update help set name=?, text=? where id=?";
|
|
23 |
private final static String INSERT_HELP = "insert into help (name, text, id) values (?, ?, ?)";
|
|
24 |
private final static String GET_BY_ID = "select id, name, text from help where id = ?";
|
|
25 |
private final static String GET_ALL = "select id, name, text from help";
|
|
26 |
private final static String DELETE = "delete from help where id = ?";
|
|
27 | 27 |
|
28 | 28 |
|
29 |
private RowMapper<Help> helpRowMapper = new RowMapper<Help>() {
|
|
30 |
@Override
|
|
31 |
public Help mapRow(ResultSet rs, int i) throws SQLException {
|
|
32 |
return new Help(rs.getString("id"), rs.getString("name"), rs.getString("text"));
|
|
33 |
}
|
|
34 |
};
|
|
29 |
private RowMapper<Help> helpRowMapper = new RowMapper<Help>() {
|
|
30 |
@Override
|
|
31 |
public Help mapRow(ResultSet rs, int i) throws SQLException {
|
|
32 |
return new Help(rs.getString("id"), rs.getString("name"), rs.getString("text"));
|
|
33 |
}
|
|
34 |
};
|
|
35 | 35 |
|
36 |
public Help saveHelp(Help help) {
|
|
37 |
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
36 |
public Help saveHelp(Help help) {
|
|
37 |
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
38 | 38 |
|
39 |
if (jdbcTemplate.update(UPDATE_HELP, new String[] {help.getName(), help.getText(), help.getId()}, new int[] {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}) == 0)
|
|
40 |
jdbcTemplate.update(INSERT_HELP, new String[] {help.getName(), help.getText(), help.getId()}, new int[] {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
|
|
39 |
if (jdbcTemplate.update(UPDATE_HELP, new String[]{help.getName(), help.getText(), help.getId()}, new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}) == 0)
|
|
40 |
jdbcTemplate.update(INSERT_HELP, new String[]{help.getName(), help.getText(), help.getId()}, new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
|
|
41 | 41 |
|
42 |
return help;
|
|
43 |
}
|
|
42 |
return help;
|
|
43 |
}
|
|
44 | 44 |
|
45 |
public Help getById(String id) {
|
|
46 |
return new JdbcTemplate(dataSource).queryForObject(GET_BY_ID, new String[] {id}, new int[] {Types.VARCHAR}, helpRowMapper);
|
|
47 |
}
|
|
45 |
public Help getById(String id) {
|
|
46 |
return new JdbcTemplate(dataSource).queryForObject(GET_BY_ID, new String[]{id}, new int[]{Types.VARCHAR}, helpRowMapper);
|
|
47 |
}
|
|
48 | 48 |
|
49 |
public List<Help> getAll() {
|
|
50 |
return new JdbcTemplate(dataSource).query(GET_ALL, helpRowMapper);
|
|
51 |
}
|
|
49 |
public List<Help> getAll() {
|
|
50 |
return new JdbcTemplate(dataSource).query(GET_ALL, helpRowMapper);
|
|
51 |
}
|
|
52 | 52 |
|
53 |
public void delete(String helpId) {
|
|
54 |
new JdbcTemplate(dataSource).update(DELETE, new String[] {helpId}, new int[] {Types.VARCHAR});
|
|
55 |
}
|
|
53 |
public void delete(String helpId) {
|
|
54 |
new JdbcTemplate(dataSource).update(DELETE, new String[]{helpId}, new int[]{Types.VARCHAR});
|
|
55 |
}
|
|
56 | 56 |
} |
Also available in: Unified diff
reformatted code