01: package dinamica;
02:
03: import java.sql.*;
04:
05: /**
06: * Collect JRE info and test default database connection defined in web.xml,
07: * publish recordset with id "sysinfo" containing collected information.
08: * <br><br>
09: * Last update: 2007-07-16
10: * @author Martin Cordova (martin.cordova@gmail.com)
11: **/
12: public class SysInfo extends GenericTransaction {
13:
14: /* (non-Javadoc)
15: * @see dinamica.GenericTransaction#service(dinamica.Recordset)
16: */
17: @SuppressWarnings("unchecked")
18: public int service(Recordset inputParams) throws Throwable {
19:
20: int rc = 0; //sucess
21:
22: /* define recordset structure */
23: Recordset x = new Recordset();
24: x.append("datasource", java.sql.Types.VARCHAR);
25: x.append("dbname", java.sql.Types.VARCHAR);
26: x.append("dbversion", java.sql.Types.VARCHAR);
27: x.append("driver-version", java.sql.Types.VARCHAR);
28: x.append("java-version", java.sql.Types.VARCHAR);
29: x.append("java-home", java.sql.Types.VARCHAR);
30: x.append("os-version", java.sql.Types.VARCHAR);
31: x.append("server-engine", java.sql.Types.VARCHAR);
32: x.append("jvmmaxram", java.sql.Types.DOUBLE);
33: x.append("jvmfreeram", java.sql.Types.DOUBLE);
34: x.append("encoding", java.sql.Types.VARCHAR);
35: x.append("country", java.sql.Types.VARCHAR);
36: x.append("language", java.sql.Types.VARCHAR);
37: x.addNew();
38:
39: /* get database metadata and system info */
40: Connection conn = getConnection();
41: DatabaseMetaData md = conn.getMetaData();
42: x.setValue("datasource", getContext().getInitParameter(
43: "def-datasource"));
44: x.setValue("dbname", md.getDatabaseProductName());
45: x.setValue("dbversion", md.getDatabaseProductVersion());
46: x.setValue("driver-version", md.getDriverName() + " "
47: + md.getDriverVersion());
48: x.setValue("os-version", System.getProperty("os.name") + " "
49: + System.getProperty("os.version"));
50: x.setValue("java-version", System.getProperty("java.vm.name")
51: + " " + System.getProperty("java.vm.version") + " ("
52: + System.getProperty("java.vm.vendor") + ")");
53: x.setValue("java-home", System.getProperty("java.home"));
54: x.setValue("server-engine", getContext().getServerInfo());
55: x.setValue("jvmmaxram", new Double((Runtime.getRuntime()
56: .totalMemory() / 1024) / 1024));
57: x.setValue("jvmfreeram", new Double((Runtime.getRuntime()
58: .freeMemory() / 1024) / 1024));
59: x.setValue("encoding", System.getProperty("file.encoding"));
60: x.setValue("country", System.getProperty("user.country"));
61: x.setValue("language", System.getProperty("user.language"));
62:
63: /* publish recordset to be consumed by output module */
64: publish("sysinfo", x);
65:
66: return rc;
67:
68: }
69:
70: }
|