Db4o-NetBeans-Plugin

kaputmaltwormSoftware and s/w Development

Aug 15, 2012 (5 years and 4 months ago)

667 views

Db4o-NetBeans-Plugin
Version 0.6


Author: Gerd Klevesaat.(Gerd.Klevesaat@googlemail.com
)

2
Inhalt

Introduction..................................................................................................................3

Creating and accessing a db4o database....................................................................4

Re-Opening a db4o database file type.........................................................................8

Closing a db4o database file........................................................................................8

Starting a db4o database file as a server.....................................................................9

Queries.......................................................................................................................10

Adding Queries.......................................................................................................10

Executing Queries..................................................................................................11

Editing........................................................................................................................13

Adding Objects.......................................................................................................13

Adding Objects using Class Node......................................................................13

Adding Objects using Database Node................................................................15

Removing Objects..................................................................................................17

Committing Changes..............................................................................................17

Options dialog............................................................................................................18

Output Window Support.............................................................................................19

Updating db4o-netbeans plug in................................................................................19

Important Notes..........................................................................................................20

Credits........................................................................................................................21



Abbildungen

Figure 1: Creating a db4o Database Connection File – Wizard Step 1.......................4
Figure 2: Creating a db4o Database Connection File – Wizard Step 2.......................5
Figure 3: Creating a db4o Database Connection File – Wizard Step 3.......................5
Figure 4: Open a db4o Database Connection..............................................................6
Figure 5: Loading more objects on demand.................................................................7
Figure 6: Displaying of properties in the TableView Window.......................................8
Figure 7: Menu Item - Open Data Editor......................................................................8
Figure 8: Starting an Embedded Server.......................................................................9
Figure 9: Specifying server connection details.............................................................9
Figure 10: Icon for a Running Server...........................................................................9
Figure 11: Adding a Query.........................................................................................10
Figure 12: Dialog for Adding a Query.........................................................................10
Figure 13: Query Node...............................................................................................11
Figure 14: Editing an SQL Query...............................................................................11
Figure 15: Executing a Query....................................................................................12
Figure 16: Query Results in a separate Editor...........................................................12
Figure 17: Adding an Object Using the Class Node...................................................13
Figure 18: New Object Added with default values.....................................................14
Figure 19: Changing Properties.................................................................................14
Figure 20: Updated Properties of an Object...............................................................14
Figure 21: Adding an Object Using the Database Node............................................15
Figure 22: Select A Type............................................................................................16
Figure 23: Object Added............................................................................................16
Figure 24: Adding Multiple Objects............................................................................17
Figure 25: Adding Multiple Objects Dialog.................................................................17
Figure 26: Remove an Object....................................................................................18
Figure 27: Option Dialog............................................................................................19
Figure 28: Output Window Support............................................................................19
Figure 29: Update Center Support.............................................................................20

3
Introduction

Db4oNetBeans is a plug-in for the NetBeans IDE to explore and query the db4o
database content (http://www.db4o.com)).
It is possible to open a custom number of db4o databases and explore and change
the content in a db4o database editor window.

Feature list for version 0.6:
• Create/Open/Close a db4o database file
• Browse the objects stored in the database
• Change properties of stored objects
• Add/Remove objects
• Add/Remove queries
• Executing queries
• Displaying query results in a separate editor window
• Auto-Update functionality
• Host a db4o database file in an embedded server
• Sending text messages to a db4o database server

Changes in version 0.6:
• Adding multiple objects to an initially empty db4o database.
• Sending text messages to a db4o database server
• Password field also enabled for db4o database fields
• Output Window Support
• Bug fixes



4
Creating and accessing a db4o database

db4o databases are created or accessed by simply creating a custom file type
choosing New File on the File menu and adding it to the opened java project.

On page one of the New File wizard select the category Db4o. This category offers
one new file template type called db4oTemplate.db4o. Select it and press Next.


Figure 1: Creating a db4o Database Connection File – Wizard Step 1


The second step appears. Enter a name for the new db4o file and adjust settings for
the location of the file.


5

Figure 2: Creating a db4o Database Connection File – Wizard Step 2


After entering the name, you can specify the connection details on the third page.


Figure 3: Creating a db4o Database Connection File – Wizard Step 3

There are two connection types to select.
• File connection type

6
• Server connection type

A file connection type connects directly to db4o database file.
A server connection type connects using the client/server model. It requires that a
db4o database server is running.

Depending on the type of db4o database connection:
• Enter or select a db4o database file. If the db4o database file does not exist, it
will be created.
• Enter db4o object server connection parameters.

After pressing OK, the db4o file will be added to the selected package as new sub
node and the database will be opened in the db4o database editor.




Figure 4: Open a db4o Database Connection

Any number of db4o databases may be added to a java project.

The db4o database editor will be used to display object data, add or remove objects
and to define queries.

The opened db4o database is displayed in a tree with the reference to the database
as a root. It has two child objects. One displays the database content structure. The
other is the root for the queries that may be defined on the database.

The database content structure displays the stored classes and its instances.

7
Note, that only a limited number of objects of each class are displayed. More can be
loaded on demand.

Figure 5: Loading more objects on demand

The number of objects loaded on each request is a parameter in the options dialog.

Editing data is based on the standard properties window provided by NetBeans.
Note, that it (in version 0.2) the properties window is not visible when the db4o
database editor is opened the first time. You can activate it by selecting it from the
windows menu.

Depending on the node selected in the db4o database editor, you can display its data
in a table view. Open the window menu and select the Table View Window. By
default, it will be displayed docked at the bottom of the application window as
illustrated in the picture below.


8

Figure 6: Displaying of properties in the TableView Window



Re-Opening a db4o database file type

This is simply done by selecting the menu item Open Data Editor from the context
menu of the db4o database file type in the navigator window.


Figure 7: Menu Item - Open Data Editor

Closing a db4o database file

A db4o database file is closed by closing the editors.



9
Starting a db4o database file as a server

A db4o database file can be started as a server. That means, a server instance is
started that hosts the database file.

A db4o database file is started as a server by using the menu item Start As Server
from the context menu as shown below.


Figure 8: Starting an Embedded Server

A db4o database file is stopped again by selecting the corresponding menu item
Stop Server.

The connection details used by the server embedded into the plug in are available in
the options dialog and can be modified there.


Figure 9: Specifying server connection details

Default settings are: Port = 4488, User/Password = db4o.
The host is always set to localhost.
However, the current limitation is that only one server can be started in the plug in.
This is subject to change.

Connection is indicated by a small triangle as an overlay image to the database icon.


Figure 10: Icon for a Running Server



10
Queries

Adding Queries

Queries are added by selecting the Add Query… from the context menu of the
Queries sub node.


Figure 11: Adding a Query

The Add Query dialog opens where you can add a name for the query and the type
of the objects to query for.
Additionally, the type of query can be selected from a combo box. Two query types
are supported by now: SQL and SODA.


Figure 12: Dialog for Adding a Query

When pressing OK and a new query sub node labeled with the given name is added
to the Queries node.


11

Figure 13: Query Node

For a SQL query, the expression can now be entered using the properties window.
Either enter the expression directly into the one-line edit field or open a multi-line text
field by pressing the …-button on the right.


Figure 14: Editing an SQL Query


Pressing OK assigns the expression to the query.


Executing Queries

Queries can be executing by selecting the menu item Execute… from the context
menu of the query.


12

Figure 15: Executing a Query

After execution of the query, the result is displayed in another editor window.


Figure 16: Query Results in a separate Editor

The count of objects affected by the query is displayed both in the properties window
and in the title of the editor window.



13
Editing

Object properties are edited using the properties window. Select the node of an
object and edit its properties in the edit fields of the properties window.
(Future version may come up add customize editors)

Objects can be added or removed.

Adding Objects

Adding objects can be done either on the database content node or on the class
node.
Adding objects on the database node is useful if you a have created a new database
file. In this case, you can add objects by specifying the type of the object to insert into
the database.


Adding Objects using Class Node

Select a class node to add objects for and open its context menu.


Figure 17: Adding an Object Using the Class Node

A new empty object node is appended to the class node.


14

Figure 18: New Object Added with default values

Now the properties can be changed using the properties window.


Figure 19: Changing Properties

The properties sub nodes of the object node are updated accordingly.


Figure 20: Updated Properties of an Object


15

Adding Objects using Database Node

If the database is empty, you don’t have a class node to select for adding objects.
But you can also add objects on the database node.
In this case, you can specify the type of object to add to the database.

Select the menu item Add object… on the context menu of the database node.


Figure 21: Adding an Object Using the Database Node

A dialog to specify the class opens. It provides all classes known to the plugin in a
tree. They come from three sources:
• The dialog scans the database for classes (in case of an empty database it
won’t find any)
• The dialog scans the CLASSPATH setting
• The dialog uses the classpath settings defined using the options dialog of the
plugin.



16

Figure 22: Select A Type

Selecting a type and pressing OK creates an instance of the selected type and adds
it to the db4o database.

If you cannot find the class that should be added to the database, you can add it the
plugin classpath settings by pressing the New… button.

The object and its classes are added to the database, as shown in the figure below.


Figure 23: Object Added


The object is added with its default parameters.

Note: Objects have to have a default constructor without arguments defined.

17

Adding Multiple Objects

A menu item has been added in 0.6 to allow adding multiple objects with their default
values to the database.


Figure 24: Adding Multiple Objects


Selecting Add Multiple Objects… on the context menu opens a dialog to specify the
type and count of instances to add.


Figure 25: Adding Multiple Objects Dialog


Removing Objects

Objects can be removed by selecting Remove on the context menu of the object
node. Currently it is single selection only, which may be changed in the future.

Committing Changes

Changes to the db4o database can be committed explicitly by selecting a
corresponding context menu item on the root in the db4o database editor.


18

Figure 26: Remove an Object

Options dialog

Some settings may be modified by the user using the standard options dialog.
However, the options dialog will be revised in next versions.

• Threshold: Number of objects to load on each request.
• Suppress: comma separated list of package names to suppress when
displaying the database structure.
• Delete on defragmentation: If checked, objects may be deleted on
defragmentation,
• Classpath Settings.
• Embedded Server Settings: Port, User name and password used for the
server that is capable to host a configured db4o database file.



19

Figure 27: Option Dialog


Output Window Support

With version 0.6 support has been added that sends information (such as connecting
or disconnecting to a database) to the Output window.


Figure 28: Output Window Support

Updating db4o-netbeans plug in


20
Auto-update functionality has been added to the plug in. On installation, the plug-in
adds a Update Center to NetBeans which is able to download and update the plug-in
if a new version is available.

Open the Update Center by selecting the menu item Update Center from the Extras
menu. The Update Center wizard opens.


Figure 29: Update Center Support

Check mark the Update Center called Db4o Net Beans Update Center and press
next. Net Beans will check for an updated version of the plug in. If it can find one, it is
downloaded and installed after confirmation.




Important Notes

A db4o object container is opened when a db4o database editor is opened. It is
closed again if the db4o database editor is closed again.
More precisely, it is closed if the last open editor referencing that object container is
closed. This is valid for opened editor windows displaying query results: Even if the
db4o database editor displaying the database content and queries is closed, the
object container may remain opened if there is a editor window open displaying query
results for that object container.




21
Credits

The Db4o-NetBeans plugin is using the Db4o-sql extension
by Travis Reeder.