3 import java.awt.BorderLayout;
4 import java.awt.FlowLayout;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
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;
15 import com.db4o.ObjectServer;
16 import com.db4o.cs.Db4oClientServer;
17 import com.db4o.cs.config.ServerConfiguration;
19 import configuration.ConfigXML;
20 import domain.Account;
21 import domain.Booking;
24 import domain.RuralHouse;
26 public class DB4oServerManager extends JDialog {
31 private static final long serialVersionUID = 1L;
32 private final JPanel contentPanel = new JPanel();
35 private ServerConfiguration configurationCS;
38 * Launch the application.
40 public static void main(String[] args) {
42 DB4oServerManager dialog = new DB4oServerManager ();
43 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
44 dialog.setVisible(true);
45 } catch (Exception e) {
53 public DB4oServerManager () {
54 setTitle("DB4oManagerServer: running the database server");
55 setBounds(100, 100, 486, 180);
56 getContentPane().setLayout(new BorderLayout());
57 contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
58 getContentPane().add(contentPanel, BorderLayout.CENTER);
59 contentPanel.setLayout(new BorderLayout(0, 0));
61 textArea = new JTextArea();
62 contentPanel.add(textArea);
65 JPanel buttonPane = new JPanel();
66 buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
67 getContentPane().add(buttonPane, BorderLayout.SOUTH);
69 JButton okButton = new JButton("OK");
70 okButton.addActionListener(new ActionListener() {
71 public void actionPerformed(ActionEvent e) {
72 textArea.append("\n\n\nClosing the database... ");
75 } catch (Exception e1) {
80 okButton.setActionCommand("OK");
81 buttonPane.add(okButton);
82 getRootPane().setDefaultButton(okButton);
85 JButton cancelButton = new JButton("Cancel");
86 cancelButton.setActionCommand("Cancel");
87 buttonPane.add(cancelButton);
91 ConfigXML c=ConfigXML.getInstance();
96 if (c.getDataBaseOpenMode().equals("initialize")) new File(c.getDb4oFilename()).delete();
98 configurationCS = Db4oClientServer.newServerConfiguration();
99 configurationCS.common().activationDepth(c.getActivationDepth());
100 configurationCS.common().updateDepth(c.getUpdateDepth());
101 configurationCS.common().objectClass(Owner.class).cascadeOnDelete(true);
102 configurationCS.common().objectClass(Booking.class).cascadeOnUpdate(true);
103 configurationCS.common().objectClass(RuralHouse.class)
104 .cascadeOnUpdate(true);
105 configurationCS.common().objectClass(Account.class).cascadeOnUpdate(true);
106 configurationCS.common().objectClass(Offer.class).cascadeOnUpdate(true);
107 configurationCS.common().objectClass(Account.class).cascadeOnUpdate(true);
109 server = Db4oClientServer.openServer(configurationCS,
110 c.getDb4oFilename(),c.getDatabasePort());
112 textArea.append("\nConnection to the database '"+c.getDb4oFilename()+"' opened in port "+c.getDatabasePort());
114 server.grantAccess(c.getUser(),c.getPassword());
116 textArea.append("\nAccess granted to: "+c.getUser());
120 textArea.append("\nPress button to exit this database server... ");
122 } catch (Exception e) {
123 textArea.append("Something has happened in DB4oManagerServer: "+e.toString());