This article describes how to develop a plugin that integrates the HSQLDB pure Java relational database server into Eclipse Workbench. Although it is not as strong as DB2, it is worse than Mysql popular, but HSQLDB (supersonic SQL database) can meet the needs of Java applications, because it has scalability, and is not high on memory / processor.
The supersonic SQL database is later officially renamed HSQLDB, which is a type of pure Java composed embedded relational database server, you can use it in single-machine mode (using direct file access) or client / server mode, it supports a large number of concurrency user. Although it is not as strong as DB2, it is worse than Mysql popular, but HSQLDB (supersonic SQL database) can meet the needs of Java applications, because it has scalability, and is not high on memory / processor.
HSQLDB is a class of easy Java development databases because it supports Structured Query Language (SQL) rich subsets, and Java programmers do not need to install severely consumption, memory and disk space on their development workstations. server. It is an ideal tool that integrates into the Eclipse IDE, which can provide useful tools for newcomers to provide experienced developers.
This article and the same series of subsequent articles will show you how to build a group of Eclipse plugins to embed HSQLDB into the Eclipse Workbench. You will see an example in a real world that explains how to develop such plugins in consideration of the API and User Interface (UI), and how to evaluate alternative methods to bring the required features to users. . This article assumes that you are using the Eclipse SDK distribution, not Platform Runtime-binary plus JDT. But if it is just to develop a regular Java application, the latter is more suitable.
In this series, we will use the three steps to create and extend the plugin group using three steps in this article (see the links given in the reference) of this article).
Run an existing tool in Eclipse to easily access the required pre-existing tools from the Workbench menu. Explore how to use other features of Eclipse to add values to pre-existing tool sets to improve the productivity of Java developers. Use SWT to override the tool to achieve seamless integration with Eclipse Workbench.
Learn about HSQLDB You can download HSQLDB from SourceForge (HSQLDB.SourceForge.net; see the links given in the reference) Download HSQLDB, including source code and documentation. Be careful not to be confused with the original SourceForge project that has been frozen (hsql.sourceforge.net).
The binary distribution is a standard ZIP file, and what you have to do is extracting this ZIP file into a place on your hard drive. All HSQLDB Components - Database Engine, Server Process, JDBC Drivers, Documents, and Some Utilities - All in a separate JAR package, this package is installed in lib / hsqldb.jar, with a size of about 260 kB. Running the database engine requires only 170 kB of RAM, which is even if the PDA (such as the Zaurus produced by Sharp) can also be met, including the entire download file, including the source file and document, is small to a standard 1.44 MB floppy disk. .
You can start the database server and utility from the command line, the specific method is to call the convenient class like org.hsqldb.server and org.hsqldb.util.DatabaseManager, these two classes can accept a group of orders Row option, such as "-url", "- Database" (for direct file access) and "-user". Another "-?" Option can also be accepted, and its role is to provide help with respect to the valid command line syntax. The key factor that causes HSQLDB simplicity is the sequentialization of SQL statement execution. That is, although many concurrent users can connect to the database (when the database is running in server mode), all SQL statements are put in a queue, and then execute one time. Therefore, there is no need to achieve complex locking and synchronous algorithms. Despite this, HSQLB also implements Acid (Atomicity, Constency, ISOLATION, AND DURABILITY, NEO, NEO, NEO, consistency, isolation, and persistence) semantics. In other words, it is a transactional database, but only is in a read uncommitted level, and does not have a transaction isolation function. HSQLDB is actually created for embedded applications instead of a common data center.
If you want to use triggers, aggregate functions, external join, views, and other SQL features, HSQLB can meet your needs (most of the lightweight relationship databases cannot do this). You can implement a stored procedure by adding your Java class to the HSQLB classpath. Then you have a CREATE FUNCTION statement to tell. In fact, many standard SQL functions such as SQRT and ABS are implemented as direct mappings of standard Java classes (such as java.lang.math).
HSQLDB's Run mode The HSQLDB engine can run in a variety of modes to adapt to different applications:
All database tables and indexes in memory mode are placed in memory, and will never be saved on disk. Before you send questions that you want to use the database that will be lost when the application is lost, consider you can use a standard SQL statement to query, sort, group, and updated database data with a local cache.
The stand-alone mode application creates a database connection with JDBC, and the HSQLDB engine is running in the application, and the database file is allowed to access directly. There is no concurrent user (the application exclusively access the database file), but there is no additional thread and TCP connection overhead. Single-machine mode is the preferred mode of many embedded applications.
Server Mode This is a standard client / server database configuration similar to other relational databases that allows concurrent connections to use TCP sockets. Most developers like this mode because it allows any JDBC client to connect and query / update the table in the case where the primary application is still running.
Web server mode HSQLDB can be used as a web server, can accept SQL queries via HTTP; can also be run as a servlet in any standard web container, can pass through the firewall or installed on a web host service without involving provider support group (And expensive database host options). Since HTTP is stateless, there is no transaction in this mode.
HSQLDB Database File Structure HSQLDB places all tables and index data in memory, saving all SQL statements to a file called Database.script, which also acts as the role of the transaction log. After the initialization engine, the file is read, then all SQL statements are run, thereby completing the reconstruction of the entire database. During the downtime, the HSQLDB engine will generate a new Database.script file, which contains only the least statement, with the purpose to make the database quickly start. In addition to the table defaults in memory, HSQLDB also supports the Cache table and Text table. The data of all cached tables is placed in a file called Database.Data, and the data of the text table is placed in any separated text file (like the CSV file) named by the SET TABLE source non-standard SQL statement. The cache table supports the data set than available RAM, and the text table can be used as a convenient means of importing data.
In addition to Database.Script and Database.Data files, any HSQLDB database may also contain a Database.properties file, and the administrator can set a number of parameters that affect the ANSI SQL compatibility in this file. All database files (except text table data files) must be placed in the same directory.
There is no explicit method for creating a HSQLDB database. If you ask the engine to open a database file currently existing database files (using the servers -Database option or the JDBC URL of the stand-alone mode), the file and its directory are created. So, if you affirms that there is data in the empty database, check if there is an entered error.
Let us start developing plugins!
Creating a HSQLDB Eclipse plugin group puts existing applications to eclipse so powerful tools are not an easy task. Fortunately, HSQLDB and Eclipse have reduced the difficulty of the above tasks, because the HSQLDB itself can embed other applications, and Eclipse provides clear and easy-to-understand plug-in infrastructure and a robust development environment for creating new plugins. PDE. Even if you have never been exposed to the Eclipse plugin development, PDE can make it easy. See the article describing the Eclipse basic knowledge in the Reference section of this article.
These guidance contents assume that you are using the Eclipse SDK distribution instead of Platform Runtime-binary plus JDT. But if you just want to develop regular Java applications, the latter is more suitable. You can use your favorite operating system because we will only use Java code, and you will not use this unit code at all.
In order to create a useful plug-in group and write code as little as possible, we will start from the least work. Later, in the next part of this series, we will see how to use the Eclipse feature to provide value-added for HSQLDB.
In this article, we will focus on the following features of our code:
Start the HSQLDB engine in the server mode, so that the user application and the SQL console (like the HSQLDB's own DatabaseManager utility) can run the SQL statement. Stop HSQLDB servers completely. Call the DatabaseManager utility so that the developer can enter the SQL statement interactively from Workbench. Run the SQL script file using the HSQLDB ScriptTool utility. Over the years, in order to create database tables and insert test data, I have already put a lot of * .sql files in my project folder, and I have long wish to have an easy way to run them. Configure HSQLDB connection properties, such as TCP ports and administrator passwords. How can these functions can be used for Workbench? The easiest way to complete the first three steps is to provide an ActionSet, which is added to the new top-level menu and can be accessed from its own toolbar. The operation running the SQL script file must only be bound to a file named "* .sql", so this will be an ObjectContribut, which is added to the pop-up menu on any view of these files. Finally, the connection parameters should be well compliant with the plug-in parameter selection page, and you can access this page from the Workbench Window menu.
Figure 1 shows a new menu and toolbar, while Figure 2 shows new items in the pop-up menu of the Navigator view, Figure 3 shows the property page, so you can see the first version of our plugin group. What looks like.
Figure 1.HSQLDB menu and related toolbar
Figure 2. Pop-up menu item added to the * .sql file
Figure 3. HSQLDB connection properties
Turn HSQLDB into an Eclipse plugin to build our plug-in group to pack HSQLDB itself into an Eclipse plugin. This plugin will only contain the necessary PLUGIN.XML files required by HSQLDB. Jar and Workbench. If you have already viewed the standard Eclipse plug-in directory, you may have discovered that JUnit, Xerces, Tomcat, and other common Java packages were isolated in their respective plugins, and all Eclipse details were packaged in other Insert. This type of division makes these third-party tools easy to update, and does not necessarily change the Eclipse itself. Another benefit is that it is easy to share these common libraries with many plugins.
Open your Eclipse SDK installation and create a new plugin item; name HSQLDB.CORE (I know that the name recommended is org.hsqldb.core, but I don't want to pretend to use the HSQLDB name space. Perhaps HSQLDB development The readers will end with this idea and recommend it to "formally" Eclipse integrated plugins; this name is very likely to be changed). Make sure the "EMPTY PLUGIN" option is checked, not any plug-in template; otherwise you will get a top-level plugin class where you have use, if you want to delete it, it can be safely removed. Copy hsqldb.jar from your HSQLDB to the project directory and add it to the project's runtime. You can do this using PDE PLUGIN Manifest Editor or simply copying the content in Qingda 1.
Listing 1. Plugin.xml manifest file for HSQLDB.Core plugins
XML Version = "1.0" encoding = "UTF-8"?>
ID = "hsqldb.core" name = "HSQLDB Core Plug-in" Version = "0.0.1" Provider-name = "Fernando Lozano (www.lozano.geti.br)> library> runtime> plugin> Add Workbench Extension Next, create a second plugin item named HSQLDB.UI. This project will include all Eclipse extensions for the first revision of the plug-in group: an operation set of three operations, an object effect related to the * .sql file, and a property page. Name its main class (Plugin class) Pluginui, and accept the default name HSQLDB.UI of the package. Use the Plugin Manifest Editor to open the plugin.xml file and select the Extensions tab. Change the assigned menu to HSQLDB and change the demonstration operation to display the tag "Runs HSQLDB Database Manager". Add additional operations to the same ActionSet with the label "Stops HSQLDB Database Server" and "Starts HSQLDB Database Server" and provide the unique operation ID and implementation of each operation. Note that the above operation will appear in the menu and toolbar in the order in which the creation is reversed. Click the Add button to add two new extensions using the Extension template, pop-up menu, and property pages. The pop-up menu should be associated with the * .sql file mode, but the property page field should be set by programming. Figure 4 shows the final appearance of the Plugin Manifest Editor and shows all plug-in extensions; Figure 5 shows the properties allocated by the object (note the filter for * .sql file), and Figure 6 shows the file resource pop-up menu The properties of the "Run SQL Script" operation. The icon is given in the source code in this article (see Resources), but I will definitely know that there is a better graphic expert than this! Figure 4. HSQLDB operation on the list editor Figure 5. HSQLDB object assignment on the list editor Figure 6. Run SQL SCRIPT operation on the list editor Before you add code to our operation, we need to distinguish this UI plugin with the corresponding core plugin, otherwise it will not access the HSQLDB class. Go to the "DependenCIES" page on the Plugin Manifest Editor and add a plugin dependence, as shown in Figure 7. Some dependencies, like "Eclipse.UI", automatically configured by PDE, while other dependence, like "org.eclipse.debug.core, add when the operation is encoded. If you are willing to edit the XML code directly, Listing 2 shows the full plugin.xml file for the HSQLDB.UI plugin. To complete the installation of the plugin, add a new class to the HSQLDB.UI package and name it HSQLDBUTIL. This class will contain all the code directly handled the HSQLDB and keep the allocated extension code simple. Figure 7. HSQLDB.UI plugin dependence Listing 2. HSQLDB.UI plugin PLUGIN.XML inventory file XML Version = "1.0" encoding = "UTF-8"?> ID = "hsqldb.ui" Name = "HSQLDB UI Plug-in" Version = "0.0.1" Provider-name = "Fernando Lozano (www.lozano.geti.br)" Class = "hsqldb.ui.pluginui"> runtime> requires> Point = "org.eclipse.ui.actionsets"> Label = "HSQLDB" Visible = "True" ID = "HSQLDB.UI.ActionSet">