01: package xui.samples.carousel.database;
02:
03: import javax.swing.SwingUtilities;
04: import net.xoetrope.optional.data.sql.DataConnection;
05: import net.xoetrope.optional.data.sql.DatabaseTableModel;
06: import net.xoetrope.xui.XPage;
07: import net.xoetrope.xui.XProject;
08: import xui.samples.carousel.database.PreparationTask;
09: import xui.samples.carousel.database.Prepared;
10:
11: /**
12: * A class that is kicked off in the background when the application loads. The
13: * class prepares the database for use.
14: * <p>Copyright Xoetrope Ltd. (c) 2001-2005</p>
15: * $Revision: 1.2 $
16: */
17: public class DatabasePreparationTask implements PreparationTask {
18: private boolean prepared;
19:
20: /*
21: * Creates a new instance of DatabasePreparationTask
22: */
23: public DatabasePreparationTask() {
24: // The PL17 tables use NULLs deliberately
25: DatabaseTableModel.setAllowNull(true);
26: prepared = false;
27: }
28:
29: /**
30: * Prepare the database
31: */
32: public synchronized void prepare(Prepared owner, XProject project) {
33: final Prepared ownerPage = owner;
34: final XProject ownerProject = project;
35:
36: new Thread() {
37: public void run() {
38: if (!prepared) {
39: DataConnection connection = new DataConnection(
40: ownerProject, "default");
41: final DataConnection theConnection = connection;
42: try {
43: // connection.executeQuery( "DELETE FROM COMPRESSOR_SEARCH" );
44: // DatabaseTableModel dtm = DatabaseTableModel.getTable( "COMPRESSOR_SEARCH" );
45: // dtm.retrieve();
46: } catch (Exception ex) {
47: ex.printStackTrace();
48: }
49:
50: while (!prepared) {
51: if (((XPage) ownerPage).getStatus() == XPage.ACTIVATED) {
52: SwingUtilities.invokeLater(new Runnable() {
53: public void run() {
54: ownerPage.prepared(theConnection);
55: }
56: });
57: prepared = true;
58: } else {
59: try {
60: Thread.currentThread().sleep(1000);
61: } catch (Exception e) {
62: }
63: }
64: }
65: }
66: }
67: }.start();
68: }
69: }
|