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;
22 public class DB4oManagerServer extends JDialog {
27 private static final long serialVersionUID = 1L;
28 private final JPanel contentPanel = new JPanel();
31 private ServerConfiguration configurationCS;
34 * Launch the application.
36 public static void main(String[] args) {
38 DB4oManagerServer dialog = new DB4oManagerServer();
39 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
40 dialog.setVisible(true);
41 } catch (Exception e) {
49 public DB4oManagerServer() {
50 setTitle("DB4oManagerServer: running the database server");
51 setBounds(100, 100, 486, 180);
52 getContentPane().setLayout(new BorderLayout());
53 contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
54 getContentPane().add(contentPanel, BorderLayout.CENTER);
55 contentPanel.setLayout(new BorderLayout(0, 0));
57 textArea = new JTextArea();
58 contentPanel.add(textArea);
61 JPanel buttonPane = new JPanel();
62 buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
63 getContentPane().add(buttonPane, BorderLayout.SOUTH);
65 JButton okButton = new JButton("OK");
66 okButton.addActionListener(new ActionListener() {
67 public void actionPerformed(ActionEvent e) {
68 textArea.append("\n\n\nClosing the database... ");
71 } catch (Exception e1) {
76 okButton.setActionCommand("OK");
77 buttonPane.add(okButton);
78 getRootPane().setDefaultButton(okButton);
81 JButton cancelButton = new JButton("Cancel");
82 cancelButton.setActionCommand("Cancel");
83 buttonPane.add(cancelButton);
87 ConfigXML c=ConfigXML.getInstance();
92 if (c.getDataBaseOpenMode().equals("initialize")) new File(c.getDb4oFilename()).delete();
94 configurationCS = Db4oClientServer.newServerConfiguration();
95 configurationCS.common().activationDepth(c.getActivationDepth());
96 configurationCS.common().updateDepth(c.getUpdateDepth());
97 configurationCS.common().objectClass(Owner.class).cascadeOnDelete(true);
99 server = Db4oClientServer.openServer(configurationCS,
100 c.getDb4oFilename(),c.getDatabasePort());
102 textArea.append("\nConnection to the database '"+c.getDb4oFilename()+"' opened in port "+c.getDatabasePort());
104 server.grantAccess(c.getUser(),c.getPassword());
106 textArea.append("\nAccess granted to: "+c.getUser());
110 textArea.append("\nPress button to exit this database server... ");
112 } catch (Exception e) {
113 textArea.append("Something has happened in DB4oManagerServer: "+e.toString());