adding all of botlist, initial add
[botlist.git] / openbotlist / src / org / spirit / apps / jdbc / GenericRuntimeJDBCDao.java
blobfc9c7562ea08064976205e9dc05fb57bafbe398e
1 /*
2 * GenericRuntimeJDBCDaoI.java
3 * Apr 12, 2008
4 */
5 package org.spirit.apps.jdbc;
7 import java.sql.ResultSet;
8 import java.sql.SQLException;
9 import java.util.ArrayList;
10 import java.util.Collection;
12 import javax.sql.DataSource;
14 import org.spirit.apps.system.SystemFeedItemsType;
15 import org.springframework.jdbc.core.JdbcTemplate;
16 import org.springframework.jdbc.core.RowMapper;
18 /**
19 * Use the generic jdbc dao class to access the botlist application with spring jdbc template calls.
20 * References:
21 * [1] http://static.springframework.org/spring/docs/2.0.x/reference/jdbc.html
22 * @author bbrown
24 public class GenericRuntimeJDBCDao implements IGenericRuntimeJDBCDao {
26 private JdbcTemplate jdbcTemplate;
28 public void setDataSource(DataSource dataSource) {
29 this.jdbcTemplate = new JdbcTemplate(dataSource);
32 /**
33 * Perform an insert or update jdbc SQL query.
35 * <code>
36 * Example SQL:
37 * "insert into t_actor (first_name, surname) values (?, ?)"
38 * </code>
39 * @param update_sql
40 * @param parm_values
42 public int jdbcUpdateInsert(final String update_sql, final Object[] parm_values) {
43 if (this.jdbcTemplate == null) {
44 return -1;
46 return this.jdbcTemplate.update(update_sql, parm_values);
49 /**
50 * id
51 * main_url
52 * url_title
53 * url_description
54 * url_source
55 * process_count
56 * created_on
57 * hostname
58 * enum_proc_type
60 * @param update_sql
61 * @param feed_items
62 * @return
64 public int jdbcInsertFeedItems(final String update_sql, final SystemFeedItemsType feed_items) {
65 if (this.jdbcTemplate == null) {
66 return -1;
68 final Object [] data = new Object[6];
69 data[0] = feed_items.getMainUrl();
70 data[1] = feed_items.getUrlTitle();
71 data[2] = feed_items.getUrlDescription();
72 data[3] = feed_items.getUrlSource();
73 data[4] = feed_items.getCreatedOn();
74 data[5] = feed_items.getHostname();
76 return this.jdbcTemplate.update(update_sql, data);
79 /**
80 * Perform an insert or update jdbc SQL query.
82 * <code>
83 * Example SQL:
84 * select count(0) from t_accrual
85 * </code>
87 public int jdbcQueryForInt(final String count_sql) {
88 if (this.jdbcTemplate == null) {
89 return -1;
91 int rowCount = this.jdbcTemplate.queryForInt(count_sql);
92 return rowCount;
95 /**
96 * select first_name, surname from t_actor"
98 * @param count_sql
99 * @return
101 public Collection jdbcQuerySystemFeedItems(final String sql) {
102 if (this.jdbcTemplate == null) {
103 return new ArrayList();
105 Collection feed_items = this.jdbcTemplate.query(
106 sql,
107 new RowMapper() {
108 public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
109 SystemFeedItemsType feed_item = new SystemFeedItemsType();
110 feed_item.setId(new Long(rs.getLong("id")));
111 feed_item.setMainUrl(rs.getString("main_url"));
112 return feed_item;
115 return feed_items;