Thaw Hsqldb Integration
Homepage
Plugins using Hsqldb
To access to the Hsql database of Thaw from a plugin, you need to pass by the Hsqldb plugin. Here is a basic example for a plugin using hsqldb in thaw:
package thaw.plugins;
import java.sql.*;
import thaw.core.*;
public class PluginUsingHsqldb implements Plugin {
private Core core;
private Hsqldb hsqldb;
public PluginUsingHsqldb() {
/* never called */
}
public boolean run(Core core) {
this.core = core;
/* If Hsqldb plugin is not already loaded, then we need to load it */
if(core.getPluginManager().getPlugin("thaw.plugins.Hsqldb") == null) {
Logger.info(this, "Loading Hsqldb plugin");
if(!core.getPluginManager().loadPlugin("thaw.plugins.Hsqldb")
|| !core.getPluginManager().runPlugin("thaw.plugins.Hsqldb")) { /* Hsqldb.run() do almost nothing, see Hsqldb.registerChild() */
Logger.error(this, "Unable to load thaw.plugins.Hsqldb !");
return false;
}
}
hsqldb = (Hsqldb)core.getPluginManager().getPlugin("thaw.plugins.Hsqldb");
/* We need to register: Like this, Hsqldb plugin can know how many child plugins
it has. When this number reach 0, then it can disconnect from the database.
*/
hsqldb.registerChild(this);
/* ADD YOUR CODE HERE */
return true;
}
public boolean stop() {
hsqldb.unregisterChild(this);
return true;
}
public String getNameForUser() {
return I18n.getMessage("thaw.plugin.PluginUsingHsqldb");
}
}
import java.sql.*;
import thaw.core.*;
public class PluginUsingHsqldb implements Plugin {
private Core core;
private Hsqldb hsqldb;
public PluginUsingHsqldb() {
/* never called */
}
public boolean run(Core core) {
this.core = core;
/* If Hsqldb plugin is not already loaded, then we need to load it */
if(core.getPluginManager().getPlugin("thaw.plugins.Hsqldb") == null) {
Logger.info(this, "Loading Hsqldb plugin");
if(!core.getPluginManager().loadPlugin("thaw.plugins.Hsqldb")
|| !core.getPluginManager().runPlugin("thaw.plugins.Hsqldb")) { /* Hsqldb.run() do almost nothing, see Hsqldb.registerChild() */
Logger.error(this, "Unable to load thaw.plugins.Hsqldb !");
return false;
}
}
hsqldb = (Hsqldb)core.getPluginManager().getPlugin("thaw.plugins.Hsqldb");
/* We need to register: Like this, Hsqldb plugin can know how many child plugins
it has. When this number reach 0, then it can disconnect from the database.
*/
hsqldb.registerChild(this);
/* ADD YOUR CODE HERE */
return true;
}
public boolean stop() {
hsqldb.unregisterChild(this);
return true;
}
public String getNameForUser() {
return I18n.getMessage("thaw.plugin.PluginUsingHsqldb");
}
}
When you have a reference to the Hsqldb plugin, then you can use getConnection() or executeQuery() or execute() to send query to the database (but be careful about the SQL Exception).
From this point, everything works as usual with Jdbc.
Regarding the methods registerChild() and unregisterChild(), you can look at the thaw.core.LibraryPlugin javadoc for more details.
SQL Console
You can access yourself to the database by using the Thaw SQL Console:
Put Thaw in advanced mode, and load the plugin "thaw.plugins.SqlConsole".
The SQL used is, of course, the Hsqldb one :)
Shortcut available:
- "list_tables" => "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES"
- "drop_tables" => Drop all the tables used for the indexations.