org.oddjob.hsql
Class HsqldbJob

java.lang.Object
  extended by org.oddjob.hsql.HsqldbJob

public class HsqldbJob
extends Object

Description

Start an instance of the HSQL Database engine. For more information on the properties please see http://hsqldb.org

Example

Using an HSQL Server and an HSQL connection to run lots of SQL.
<oddjob id="this">
    <job>
        <sequential id="top" name="Run in Sequence">
            <jobs>
                <hsql:hsqldb name="Hsqldb Server" xmlns:hsql="http://rgordon.co.uk/oddjob/hsql">
                    <database>
                        <value key="mydb" value="${work.dir}/mydb"/>
                    </database>
                    <properties>
                        <properties>
                            <values>
                                <value key="server.port" value="11001"/>
                                <value key="server.silent" value="false"/>
                            </values>
                        </properties>
                    </properties>
                </hsql:hsqldb>
                <variables id="vars">
                    <connection>
                        <hsql:connection url="jdbc:hsqldb:hsql://localhost:11001/mydb" username="sa" xmlns:hsql="http://rgordon.co.uk/oddjob/hsql"/>
                    </connection>
                </variables>
                <folder name="Setup Sql">
                    <jobs>
                        <sequential id="setup" name="All">
                            <jobs>
                                <sql name="Create table">
                                    <connection>
                                        <value value="${vars.connection}"/>
                                    </connection>
                                    <input>
                                        <buffer>create table greetings  (
style varchar(20), greeting varchar(30),constraint greetings_pk primary key (style))</buffer>
                                    </input>
                                </sql>
                                <sql name="Insert1">
                                    <connection>
                                        <value value="${vars.connection}"/>
                                    </connection>
                                    <input>
                                        <buffer>insert into greetings values ('nice', 'hello')</buffer>
                                    </input>
                                </sql>
                                <sql name="Insert1">
                                    <connection>
                                        <value value="${vars.connection}"/>
                                    </connection>
                                    <input>
                                        <buffer>insert into greetings values ('grumpy', 'bah humbug')</buffer>
                                    </input>
                                </sql>
                            </jobs>
                        </sequential>
                    </jobs>
                </folder>
                <folder name="Query Sql">
                    <jobs>
                        <sequential id="single-query" name="All">
                            <jobs>
                                <sql id="query" name="Query">
                                    <connection>
                                        <value value="${vars.connection}"/>
                                    </connection>
                                    <input>
                                        <buffer>select greeting from greetings where style='nice'</buffer>
                                    </input>
                                    <results>
                                        <sql-results-bean/>
                                    </results>
                                </sql>
                                <echo id="result">${query.results.row.GREETING}</echo>
                                <echo id="resultindexed">${query.results.rows[0].GREETING}</echo>
                            </jobs>
                        </sequential>
                    </jobs>
                </folder>
                <folder name="Query All">
                    <jobs>
                        <sequential id="all-query" name="All">
                            <jobs>
                                <sql id="queryall" name="Query">
                                    <connection>
                                        <value value="${vars.connection}"/>
                                    </connection>
                                    <input>
                                        <buffer>select style, greeting from greetings</buffer>
                                    </input>
                                    <results>
                                        <sql-results-bean/>
                                    </results>
                                </sql>
                                <foreach id="for">
                                    <values>
                                        <value value="${queryall.results.rows}"/>
                                    </values>
                                        <configuration>
                                            <xml>
                                                <foreach id="for">
                                                    <job>
                                                        <echo>${for.current.STYLE} is ${for.current.GREETING}</echo>
                                                    </job>
                                                </foreach>
                                            </xml>
                                        </configuration>
                                </foreach>
                            </jobs>
                        </sequential>
                    </jobs>
                </folder>
                <folder name="Cleanup Sql">
                    <jobs>
                        <sql id="clean-up" name="Sql Job">
                            <connection>
                                <value value="${vars.connection}"/>
                            </connection>
                            <input>
                                <buffer>drop table greetings</buffer>
                            </input>
                        </sql>
                    </jobs>
                </folder>
            </jobs>
        </sequential>
    </job>
</oddjob>

Example

Using an HSQL Server to provide a SQLPersisterService.
<oddjob>
    <job>
        <sequential name="Sql Persister Example">
            <jobs>
                <hsql:hsqldb name="Database Server" xmlns:hsql="http://rgordon.co.uk/oddjob/hsql">
                    <database>
                        <value key="ojdb" value="${work.dir}/ojdb"/>
                    </database>
                    <properties>
                        <properties>
                            <values>
                                <value key="server.port" value="11002"/>
                                <value key="server.silent" value="false"/>
                            </values>
                        </properties>
                    </properties>
                </hsql:hsqldb>
                <variables id="vars">
                    <persisterConnection>
                        <hsql:connection url="jdbc:hsqldb:hsql://localhost:11002/ojdb" username="sa" xmlns:hsql="http://rgordon.co.uk/oddjob/hsql"/>
                    </persisterConnection>
                </variables>
                <sql name="Create table">
                    <connection>
                        <value value="${vars.persisterConnection}"/>
                    </connection>
                    <input>
                        <buffer>CREATE TABLE oddjob( path VARCHAR(32),
id VARCHAR(32), job BLOB,
CONSTRAINT oddjob_pk PRIMARY KEY (path, id))</buffer>
                    </input>
                </sql>
                <sql-persister-service id="persister-service">
                    <connection>
                        <value value="${vars.persisterConnection}"/>
                    </connection>
                </sql-persister-service>
                <oddjob id="database-persist-example" name="A Database Persisted Oddjob">
                    <configuration>
                        <arooa:configuration resource="org/oddjob/hsql/OddjobToPersist.xml" xmlns:arooa="http://rgordon.co.uk/oddjob/arooa"/>
                    </configuration>
                    <persister>
                        <value value="${persister-service.persister(example)}"/>
                    </persister>
                </oddjob>
                <folder name="Cleanup Sql">
                    <jobs>
                        <sql id="clean-up" name="Sql Job">
                            <connection>
                                <value value="${vars.persisterConnection}"/>
                            </connection>
                            <input>
                                <buffer>drop table oddjob</buffer>
                            </input>
                        </sql>
                    </jobs>
                </folder>
            </jobs>
        </sequential>
    </job>
</oddjob>
Author:
Rob Gordon.

Constructor Summary
HsqldbJob()
           
 
Method Summary
 String getDatabase(String name)
          Get the database path for a give name.
 String getName()
          Get the name.
 Properties getProperties()
          Getter for properties.
 Integer getServerState()
           
 void setDatabase(String name, String path)
          Set the database name.
 void setName(String name)
          Set the name.
 void setProperties(Properties properties)
          Setter for server properties.
 void start()
          Start the server.
 void stop()
          Stop the server.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HsqldbJob

public HsqldbJob()
Method Detail

getName

public String getName()
Get the name.

Returns:
The name.

setName

public void setName(String name)
Set the name.

Parameters:
name - The name.

getDatabase

public String getDatabase(String name)
Get the database path for a give name.

Parameters:
name - The database path.
Returns:
The database path.

setDatabase

public void setDatabase(String name,
                        String path)
Set the database name.

Parameters:
name - The database name.

setProperties

public void setProperties(Properties properties)
Setter for server properties.

Parameters:
properties - The property name.
value - The property value.

getProperties

public Properties getProperties()
Getter for properties.

Parameters:
name - The property name.

start

public void start()
           throws IOException,
                  org.hsqldb.server.ServerAcl.AclFormatException
Start the server.

Throws:
org.hsqldb.server.ServerAcl.AclFormatException
IOException

stop

public void stop()
Stop the server.


getServerState

public Integer getServerState()

Property: serverState

Description: The current state of this server in numerically coded form.

Typically, this will be one of:

  1. ServerProperties.SERVER_STATE_ONLINE (1).
  2. ServerProperties.SERVER_STATE_OPENING (4).
  3. ServerProperties.SERVER_STATE_CLOSING (8).
  4. ServerProperties.SERVER_STATE_SHUTDOWN (16).

Required: Read Only.

Returns:

toString

public String toString()
Overrides:
toString in class Object