01: package simpleorm.simplewebapp.eg.token;
02:
03: import simpleorm.simplewebapp.core.*;
04: import simpleorm.simplewebapp.eg.dbute.WCreateDB;
05: import simpleorm.simplewebapp.eg.WTestGlobals;
06: import simpleorm.simplewebapp.scalarFields.WFieldString;
07:
08: import java.sql.Connection;
09: import java.sql.DatabaseMetaData;
10: import java.sql.ResultSet;
11: import java.sql.PreparedStatement;
12: import java.util.ArrayList;
13: import java.util.HashMap;
14:
15: public class WRowListPage extends WPage {
16:
17: public final WRowListPage.WRowListPagelet pagelet = new WRowListPage.WRowListPagelet(
18: this );
19: {
20: pagelet
21: .setListCrudItem(WTestGlobals.getGlobalMenus().token.rowCrud);
22: }
23:
24: Connection con;
25:
26: protected void onInitialize() throws Exception {
27: con = WCreateDB.openJdbc();
28: }
29:
30: protected void onFinalize() throws Exception {
31: if (con != null)
32: con.close();
33: }
34:
35: public static class WRowListPagelet extends WPageletList {
36:
37: String table_name = "RSA_USER";
38:
39: final WFieldString keyWord = addField(searchFields,
40: new WFieldString("keyWord"));
41:
42: public WRowListPagelet(WPage wpage) {
43: super (wpage, "list");
44: }
45:
46: Connection getCon() {
47: return ((WRowListPage) getPage()).con;
48: }
49:
50: ResultSet rs;
51:
52: public @Override
53: void onPostMaybeSubmitted() throws Exception {
54: /// Read meta data to define WFields dynamically
55: DatabaseMetaData dbmd = getCon().getMetaData();
56: ResultSet cols = dbmd.getColumns(null, // ### allTables.getString("TABLE_CAT"),
57: null, // ###allTables.getString("TABLE_SCHEM"),
58: table_name, null);
59: while (cols.next()) {
60: String colName = cols.getString("COLUMN_NAME");
61: addField(listFields, new WFieldString(colName)
62: .setNotRetrieved(true));
63: }
64: cols.close();
65:
66: /// Now read the actual data into an arrayList
67: ArrayList<HashMap> rows = new ArrayList();
68: PreparedStatement ps = getCon().prepareStatement(
69: "SELECT * FROM " + table_name);
70: rs = ps.executeQuery();
71: }
72:
73: protected @Override
74: boolean onListRow() throws Exception {
75: if (!rs.next())
76: return false;
77: for (WField wfield : getPage().getListFieldValues()) {
78: Object value = rs.getString(wfield.getDataName());
79: //if ( logger().isDebug() ) logger().debug("onNotSubmitted "+ sfield + " == " + value);
80: wfield.setValue(value);
81: }
82: return true;
83: }
84:
85: }
86: }
|