2 * GenericRuntimeJDBCDaoI.java
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
;
19 * Use the generic jdbc dao class to access the botlist application with spring jdbc template calls.
21 * [1] http://static.springframework.org/spring/docs/2.0.x/reference/jdbc.html
24 public class GenericRuntimeJDBCDao
implements IGenericRuntimeJDBCDao
{
26 private JdbcTemplate jdbcTemplate
;
28 public void setDataSource(DataSource dataSource
) {
29 this.jdbcTemplate
= new JdbcTemplate(dataSource
);
33 * Perform an insert or update jdbc SQL query.
37 * "insert into t_actor (first_name, surname) values (?, ?)"
42 public int jdbcUpdateInsert(final String update_sql
, final Object
[] parm_values
) {
43 if (this.jdbcTemplate
== null) {
46 return this.jdbcTemplate
.update(update_sql
, parm_values
);
64 public int jdbcInsertFeedItems(final String update_sql
, final SystemFeedItemsType feed_items
) {
65 if (this.jdbcTemplate
== null) {
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
);
80 * Perform an insert or update jdbc SQL query.
84 * select count(0) from t_accrual
87 public int jdbcQueryForInt(final String count_sql
) {
88 if (this.jdbcTemplate
== null) {
91 int rowCount
= this.jdbcTemplate
.queryForInt(count_sql
);
96 * select first_name, surname from t_actor"
101 public Collection
jdbcQuerySystemFeedItems(final String sql
) {
102 if (this.jdbcTemplate
== null) {
103 return new ArrayList();
105 Collection feed_items
= this.jdbcTemplate
.query(
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"));