01: package com.knowgate.jdc;
02:
03: import java.util.ArrayList;
04: import java.sql.DriverManager;
05: import java.sql.Connection;
06: import java.sql.SQLException;
07: import java.sql.Statement;
08: import java.sql.ResultSet;
09:
10: /**
11: * @author Sergio Montoro Ten
12: * @version 3.0
13: */
14: public class JDCActivityInfo {
15:
16: private JDCProcessInfo[] aProcessInfo = null;
17:
18: private void pgSqlActivity(Connection oConn) throws SQLException {
19: Statement oStmt;
20: ResultSet oRSet;
21: ArrayList aStats = new ArrayList();
22: oStmt = oConn.createStatement();
23: oRSet = oStmt
24: .executeQuery("SELECT datid,datname,procpid,usesysid,usename,current_query,query_start FROM pg_stat_activity");
25: while (oRSet.next()) {
26: aStats.add(new JDCProcessInfo(oRSet.getString(1), oRSet
27: .getString(2), oRSet.getString(3), oRSet
28: .getString(4), oRSet.getString(5), oRSet
29: .getString(6), oRSet.getDate(7)));
30: } // wend
31: oRSet.close();
32: oStmt.close();
33: final int nProcs = aStats.size();
34: if (nProcs > 0) {
35: aProcessInfo = new JDCProcessInfo[nProcs];
36: for (int p = 0; p < nProcs; p++) {
37: aProcessInfo[p] = (JDCProcessInfo) aStats.get(p);
38: } // next
39: } // fi
40: }
41:
42: public JDCActivityInfo(JDCConnection oConn) throws SQLException {
43: if (oConn.getDataBaseProduct() == JDCConnection.DBMS_POSTGRESQL) {
44: pgSqlActivity(oConn);
45: } // fi
46: }
47:
48: public JDCActivityInfo(JDCConnectionPool oPool)
49: throws SQLException, ClassNotFoundException {
50: //Class.forName("org.postgresql.Driver");
51: //Connection oConn = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/econtainers2r","sa","laifee3B");
52: JDCConnection oConn = oPool.getConnection("activity_info");
53: if (oConn.getDataBaseProduct() == JDCConnection.DBMS_POSTGRESQL) {
54: pgSqlActivity(oConn);
55: } // fi
56: oConn.close();
57: }
58:
59: public JDCProcessInfo[] processesInfo() {
60: return aProcessInfo;
61: }
62:
63: }
|