1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.stats.dao.impl; |
18 | |
|
19 | |
import java.sql.Connection; |
20 | |
import java.sql.PreparedStatement; |
21 | |
import java.sql.ResultSet; |
22 | |
import java.sql.SQLException; |
23 | |
import java.sql.Timestamp; |
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Calendar; |
26 | |
import java.util.Date; |
27 | |
import java.util.List; |
28 | |
|
29 | |
import org.apache.ojb.broker.PersistenceBroker; |
30 | |
import org.apache.ojb.broker.accesslayer.LookupException; |
31 | |
import org.kuali.rice.kew.stats.Stats; |
32 | |
import org.kuali.rice.kew.stats.dao.StatsDAO; |
33 | |
import org.kuali.rice.kew.util.KEWConstants; |
34 | |
import org.kuali.rice.kew.web.KeyValue; |
35 | |
import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; |
36 | |
|
37 | |
|
38 | 0 | public class StatsDAOOjbImpl extends PersistenceBrokerDaoSupport implements StatsDAO { |
39 | |
|
40 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(StatsDAOOjbImpl.class); |
41 | |
|
42 | |
public static final String SQL_NUM_ACTIVE_ITEMS = "select count(*) from krew_actn_itm_t"; |
43 | |
public static final String SQL_NUM_DOC_TYPES_REPORT = "select count(*) as num from krew_doc_typ_t where cur_ind = 1"; |
44 | |
public static final String SQL_DOCUMENTS_ROUTED = "select count(*) as count, krew_doc_hdr_t.doc_hdr_stat_cd from krew_doc_hdr_t where krew_doc_hdr_t.crte_dt between ? and ? group by doc_hdr_stat_cd"; |
45 | |
public static final String SQL_NUM_USERS = "select count(distinct prncpl_id) as prsn_count from KREW_USR_OPTN_T"; |
46 | |
public static final String SQL_NUM_DOCS_INITIATED = "select count(*), krew_doc_typ_t.doc_typ_nm from krew_doc_hdr_t, krew_doc_typ_t where krew_doc_hdr_t.crte_dt > ? and krew_doc_hdr_t.doc_typ_id = krew_doc_typ_t.doc_typ_id group by krew_doc_typ_t.doc_typ_nm"; |
47 | |
|
48 | |
public void NumActiveItemsReport(Stats stats) throws SQLException, LookupException { |
49 | |
|
50 | 0 | LOG.debug("NumActiveItemsReport()"); |
51 | 0 | PersistenceBroker broker = this.getPersistenceBroker(false); |
52 | 0 | Connection conn = broker.serviceConnectionManager().getConnection(); |
53 | 0 | PreparedStatement ps = conn.prepareStatement(StatsDAOOjbImpl.SQL_NUM_ACTIVE_ITEMS); |
54 | 0 | ResultSet rs = ps.executeQuery(); |
55 | |
|
56 | 0 | while (rs.next()) { |
57 | 0 | stats.setNumActionItems(new Integer(rs.getInt(1)).toString()); |
58 | |
} |
59 | |
|
60 | 0 | closeDatabaseObjects(rs, ps, conn); |
61 | 0 | } |
62 | |
|
63 | |
public void NumberOfDocTypesReport(Stats stats) throws SQLException, LookupException { |
64 | |
|
65 | 0 | LOG.debug("NumberOfDocTypesReport()"); |
66 | 0 | PersistenceBroker broker = this.getPersistenceBroker(false); |
67 | 0 | Connection conn = broker.serviceConnectionManager().getConnection(); |
68 | 0 | PreparedStatement ps = conn.prepareStatement(StatsDAOOjbImpl.SQL_NUM_DOC_TYPES_REPORT); |
69 | 0 | ResultSet rs = ps.executeQuery(); |
70 | |
|
71 | 0 | while (rs.next()) { |
72 | 0 | stats.setNumDocTypes(new Integer(rs.getInt(1)).toString()); |
73 | |
} |
74 | |
|
75 | 0 | closeDatabaseObjects(rs, ps, conn); |
76 | 0 | } |
77 | |
|
78 | |
public void DocumentsRoutedReport(Stats stats, Date begDate, Date endDate) throws SQLException, LookupException { |
79 | |
|
80 | 0 | LOG.debug("DocumentsRoutedReport()"); |
81 | 0 | PersistenceBroker broker = this.getPersistenceBroker(false); |
82 | 0 | Connection conn = broker.serviceConnectionManager().getConnection(); |
83 | 0 | PreparedStatement ps = conn.prepareStatement(StatsDAOOjbImpl.SQL_DOCUMENTS_ROUTED); |
84 | 0 | ps.setTimestamp(1, new Timestamp(begDate.getTime())); |
85 | 0 | ps.setTimestamp(2, new Timestamp(endDate.getTime())); |
86 | 0 | ResultSet rs = ps.executeQuery(); |
87 | |
|
88 | 0 | while (rs.next()) { |
89 | |
|
90 | 0 | String actionType = rs.getString(2); |
91 | 0 | String number = new Integer(rs.getInt(1)).toString(); |
92 | 0 | if (actionType.equals(KEWConstants.ROUTE_HEADER_APPROVED_CD)) { |
93 | 0 | stats.setApprovedNumber(number); |
94 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_CANCEL_CD)) { |
95 | 0 | stats.setCanceledNumber(number); |
96 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_DISAPPROVED_CD)) { |
97 | 0 | stats.setDisapprovedNumber(number); |
98 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_ENROUTE_CD)) { |
99 | 0 | stats.setEnrouteNumber(number); |
100 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_EXCEPTION_CD)) { |
101 | 0 | stats.setExceptionNumber(number); |
102 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_FINAL_CD)) { |
103 | 0 | stats.setFinalNumber(number); |
104 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_INITIATED_CD)) { |
105 | 0 | stats.setInitiatedNumber(number); |
106 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_PROCESSED_CD)) { |
107 | 0 | stats.setProcessedNumber(number); |
108 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_SAVED_CD)) { |
109 | 0 | stats.setSavedNumber(number); |
110 | |
} |
111 | 0 | } |
112 | |
|
113 | 0 | closeDatabaseObjects(rs, ps, conn); |
114 | 0 | } |
115 | |
|
116 | |
public void NumUsersReport(Stats stats) throws SQLException, LookupException { |
117 | |
|
118 | 0 | LOG.debug("NumUsersReport()"); |
119 | 0 | PersistenceBroker broker = this.getPersistenceBroker(false); |
120 | 0 | Connection conn = broker.serviceConnectionManager().getConnection(); |
121 | 0 | PreparedStatement ps = conn.prepareStatement(StatsDAOOjbImpl.SQL_NUM_USERS); |
122 | 0 | ResultSet rs = ps.executeQuery(); |
123 | |
|
124 | 0 | while (rs.next()) { |
125 | 0 | stats.setNumUsers(new Integer(rs.getInt("prsn_count")).toString()); |
126 | |
} |
127 | |
|
128 | 0 | closeDatabaseObjects(rs, ps, conn); |
129 | 0 | } |
130 | |
|
131 | |
public void NumInitiatedDocsByDocTypeReport(Stats stats) throws SQLException, LookupException { |
132 | |
|
133 | 0 | LOG.debug("NumInitiatedDocsByDocType()"); |
134 | 0 | PersistenceBroker broker = this.getPersistenceBroker(false); |
135 | 0 | Connection conn = broker.serviceConnectionManager().getConnection(); |
136 | 0 | PreparedStatement ps = conn.prepareStatement(StatsDAOOjbImpl.SQL_NUM_DOCS_INITIATED); |
137 | 0 | Calendar calendar = Calendar.getInstance(); |
138 | 0 | calendar.add(Calendar.DAY_OF_YEAR, -29); |
139 | 0 | calendar.set(Calendar.HOUR_OF_DAY, 0); |
140 | 0 | calendar.set(Calendar.MINUTE, 0); |
141 | 0 | calendar.set(Calendar.SECOND, 0); |
142 | 0 | calendar.set(Calendar.MILLISECOND, 0); |
143 | 0 | ps.setTimestamp(1, new Timestamp(calendar.getTime().getTime())); |
144 | 0 | ResultSet rs = ps.executeQuery(); |
145 | |
|
146 | 0 | List numDocs = new ArrayList(); |
147 | |
|
148 | 0 | while (rs.next()) { |
149 | 0 | numDocs.add(new KeyValue(rs.getString(2), new Integer(rs.getInt(1)).toString())); |
150 | |
} |
151 | 0 | stats.setNumInitiatedDocsByDocType(numDocs); |
152 | |
|
153 | 0 | closeDatabaseObjects(rs, ps, conn); |
154 | |
|
155 | 0 | } |
156 | |
|
157 | |
private void closeDatabaseObjects(ResultSet rs, PreparedStatement ps, Connection conn) { |
158 | |
|
159 | |
try { |
160 | 0 | rs.close(); |
161 | 0 | } catch (SQLException ex) { |
162 | 0 | LOG.warn("Failed to close ResultSet.", ex); |
163 | 0 | } |
164 | |
|
165 | |
try { |
166 | 0 | ps.close(); |
167 | 0 | } catch (SQLException ex) { |
168 | 0 | LOG.warn("Failed to close PreparedStatement.", ex); |
169 | 0 | } |
170 | |
|
171 | |
try { |
172 | 0 | conn.close(); |
173 | 0 | } catch (SQLException ex) { |
174 | 0 | LOG.warn("Failed to close Connection.", ex); |
175 | 0 | } |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | 0 | } |
184 | |
|
185 | |
} |