01: package simpleorm.simplewebapp.eg.database;
02:
03: import simpleorm.simplewebapp.eg.dbute.WCreateDB;
04: import simpleorm.simplewebapp.eg.hibernatetest.WHibernateMain;
05: import simpleorm.simplewebapp.eg.simple.WTestDatabase;
06: import simpleorm.simplewebapp.core.WPage;
07: import simpleorm.simplewebapp.core.WPagelet;
08: import simpleorm.simplewebapp.core.WButton;
09: import simpleorm.simplewebapp.core.WFieldGroup;
10: import simpleorm.simplewebapp.scalarFields.WFieldBoolean;
11: import simpleorm.core.*;
12:
13: /** The scratch init form that creates the database. */
14: public class WInitPage extends WPage implements SConstants {
15:
16: public final WInitPagelet pagelet = new WInitPagelet(this );
17:
18: static public boolean initialized;
19:
20: public static class WInitPagelet extends WPagelet {
21: public WButton init = addNewButton("Initialize");
22:
23: WFieldGroup group = addGroup(this , new WFieldGroup(
24: "Configuration"));
25: final WFieldBoolean useHibernate = addField(group,
26: new WFieldBoolean("UseHibernate"));
27:
28: public WInitPagelet(WInitPage page) {
29: super (page, "crud");
30: }
31:
32: protected void onNotSubmitted() throws Exception {
33: useHibernate.setValue("Hibernate/HSQL"
34: .equals(WTestDatabase.db.getDatabaseName()));
35: }
36:
37: protected void onWasSubmitted() throws Exception {
38:
39: if (useHibernate.getValue()) {
40: getPage().getLogger().info(
41: "=== Initializing HibernateDB...");
42: WHibernateMain.setHibernate();
43: getPage().getLogger().info(
44: "--- Initialized HibernateDB.");
45: } else {
46: WTestDatabase.db = new WTestDatabase.WMockDatabase()
47: .addTestRows();
48: }
49:
50: WCreateDB.dbConnect();
51: WCreateDB.doDbInit(getPage());
52: initialized = true;
53: }
54:
55: protected void onFinalize() throws Exception {
56: SConnection.detachAndClose();
57: }
58:
59: }
60:
61: public static boolean isInitialized() {
62: return initialized;
63: }
64: }
|