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 {
24 private final JPanel contentPanel = new JPanel();
27 private ServerConfiguration configurationCS;
30 * Launch the application.
32 public static void main(String[] args) {
34 DB4oManagerServer dialog = new DB4oManagerServer();
35 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
36 dialog.setVisible(true);
37 } catch (Exception e) {
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));
53 textArea = new JTextArea();
54 contentPanel.add(textArea);
57 JPanel buttonPane = new JPanel();
58 buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
59 getContentPane().add(buttonPane, BorderLayout.SOUTH);
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... ");
67 } catch (Exception e1) {
72 okButton.setActionCommand("OK");
73 buttonPane.add(okButton);
74 getRootPane().setDefaultButton(okButton);
77 JButton cancelButton = new JButton("Cancel");
78 cancelButton.setActionCommand("Cancel");
79 buttonPane.add(cancelButton);
83 ConfigXML c=ConfigXML.getInstance();
88 if (c.getDataBaseOpenMode().equals("initialize")) new File(c.getDb4oFilename()).delete();
90 configurationCS = Db4oClientServer.newServerConfiguration();
91 configurationCS.common().activationDepth(c.getActivationDepth());
92 configurationCS.common().updateDepth(c.getUpdateDepth());
93 configurationCS.common().objectClass(Owner.class).cascadeOnDelete(true);
95 server = Db4oClientServer.openServer(configurationCS,
96 c.getDb4oFilename(),c.getDatabasePort());
98 textArea.append("\nConnection to the database '"+c.getDb4oFilename()+"' opened in port "+c.getDatabasePort());
100 server.grantAccess(c.getUser(),c.getPassword());
102 textArea.append("\nAccess granted to: "+c.getUser());
106 textArea.append("\nPress button to exit this database server... ");
108 } catch (Exception e) {
109 textArea.append("Something has happened in DB4oManagerServer: "+e.toString());