01 package com.bea.medrec.admin;
02
03 import com.bea.medrec.BaseMBean;
04 import java.sql.Connection;
05 import java.sql.ResultSet;
06 import java.sql.SQLException;
07 import java.sql.Statement;
08 import javax.naming.Context;
09 import javax.naming.InitialContext;
10 import javax.sql.DataSource;
11
12 /**
13 * This custom mbean returns the number of patients who awaiting to have their
14 * accounts approved.
15 *
16 * @author Copyright (c) 2006 by BEA Systems, Inc. All Rights Reserved.
17 */
18 public class AdminReport extends BaseMBean implements AdminReportMBean {
19 // private static Logger logger = MedRecLog4jFactory.getLogger(AdminReport.class.getName());
20
21 /**
22 * Returns number of patients with a status of NEW
23 *
24 * @return int
25 */
26 public int getNewUserCount() {
27 //logger.debug("Get new user count");
28 int result = 0;
29 try {
30
31 ResultSet rs = null;
32
33 Context ctx = new InitialContext();
34 // REVIEWME - let's make this dynamic
35 DataSource ds = (DataSource) ctx.lookup("jdbc/MedRecGlobalDataSource");
36 Connection conn = ds.getConnection();
37
38 Statement stmt = conn.createStatement();
39
40 try {
41 rs = stmt.executeQuery("SELECT COUNT(*) as rowcount FROM medrec_user WHERE status = 'NEW'");
42 rs.next();
43 result = rs.getInt("rowcount");
44 } catch (SQLException ex) {
45 ex.printStackTrace();
46 } finally {
47 try {
48 if (rs != null) rs.close();
49 if (stmt != null) stmt.close();
50 if (conn != null) conn.close();
51 } catch (Exception ex) {
52 ex.printStackTrace();
53 }
54 }
55 } catch (Exception ex) {
56 ex.printStackTrace();
57 }
58 return result;
59 }
60 }
|