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