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