imports leaned
[RRRRHHHH_Code] / ruralHouses / src / dataAccess / DB4oManagerServer.java
1 package dataAccess;
2
3 import java.awt.BorderLayout;
4 import java.awt.FlowLayout;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.io.File;
8
9 import javax.swing.JButton;
10 import javax.swing.JDialog;
11 import javax.swing.JPanel;
12 import javax.swing.JTextArea;
13 import javax.swing.border.EmptyBorder;
14
15 import com.db4o.ObjectServer;
16 import com.db4o.cs.Db4oClientServer;
17 import com.db4o.cs.config.ServerConfiguration;
18
19 import configuration.ConfigXML;
20 import domain.Owner;
21
22 public class DB4oManagerServer extends JDialog {
23
24         private final JPanel contentPanel = new JPanel();
25         JTextArea textArea;
26         ObjectServer server;
27         private ServerConfiguration configurationCS;
28
29         /**
30          * Launch the application.
31          */
32         public static void main(String[] args) {
33                 try {
34                         DB4oManagerServer dialog = new DB4oManagerServer();
35                         dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
36                         dialog.setVisible(true);
37                 } catch (Exception e) {
38                         e.printStackTrace();
39                 }
40         }
41
42         /**
43          * Create the dialog.
44          */
45         public DB4oManagerServer() {
46                 setTitle("DB4oManagerServer: running the database server");
47                 setBounds(100, 100, 486, 180);
48                 getContentPane().setLayout(new BorderLayout());
49                 contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
50                 getContentPane().add(contentPanel, BorderLayout.CENTER);
51                 contentPanel.setLayout(new BorderLayout(0, 0));
52                 {
53                         textArea = new JTextArea();
54                         contentPanel.add(textArea);
55                 }
56                 {
57                         JPanel buttonPane = new JPanel();
58                         buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
59                         getContentPane().add(buttonPane, BorderLayout.SOUTH);
60                         {
61                                 JButton okButton = new JButton("OK");
62                                 okButton.addActionListener(new ActionListener() {
63                                         public void actionPerformed(ActionEvent e) {
64                                                 textArea.append("\n\n\nClosing the database... ");
65                                             try {
66                                                         server.close();
67                                                 } catch (Exception e1) {
68                                                 }
69                                                 System.exit(1);
70                                         }
71                                 });
72                                 okButton.setActionCommand("OK");
73                                 buttonPane.add(okButton);
74                                 getRootPane().setDefaultButton(okButton);
75                         }
76                         {
77                                 JButton cancelButton = new JButton("Cancel");
78                                 cancelButton.setActionCommand("Cancel");
79                                 buttonPane.add(cancelButton);
80                         }
81                 }
82                 
83                 ConfigXML c=ConfigXML.getInstance();
84                 
85                 
86                 try{
87
88                         if (c.getDataBaseOpenMode().equals("initialize")) new File(c.getDb4oFilename()).delete();
89                         
90                         configurationCS = Db4oClientServer.newServerConfiguration();
91                         configurationCS.common().activationDepth(c.getActivationDepth());
92                         configurationCS.common().updateDepth(c.getUpdateDepth());
93                         configurationCS.common().objectClass(Owner.class).cascadeOnDelete(true);
94
95                         server = Db4oClientServer.openServer(configurationCS,
96                                                                                                  c.getDb4oFilename(),c.getDatabasePort());
97                         
98                         textArea.append("\nConnection to the database '"+c.getDb4oFilename()+"' opened in port "+c.getDatabasePort());
99         
100                     server.grantAccess(c.getUser(),c.getPassword());
101
102                     textArea.append("\nAccess granted to: "+c.getUser());
103
104
105
106                         textArea.append("\nPress button to exit this database server... ");
107                         
108                 } catch (Exception e) {
109                         textArea.append("Something has happened in DB4oManagerServer: "+e.toString());
110
111                 }
112         }
113 }
114