JavaDB integration JavaEE SDK

Derby and glassfish

1. Introduction.

The objective of this blog is to explain in detail the following.
    - how javadb is closely integrated with Java EE 5.0 SDK.
    - how javadb is configured for better out-of-the box experience.
    - overview of  how javadb is used internally by SDK.

This blog is written using Java EE 5 SDK, the latest version can be downloaded from
Java EE 5 SDK all-in-one bundle was used to run through the examples used here.

2. Contents.

Javadb integration
Start/Stop javadb through application server commands
Javadb and EJBTimer
Javadb database and callflow
Using javadb tools
Further readings

3. Javadb integration.

    3.1 Installation.

Javadb binaries are always installed directly under Installation root directory/javadb.  The binaries include the javadb core jar files,
useful javadb utilities(dblook, sysinfo and ij) and a few a native scripts to perform functions like start, stop database. The functionality
of start and stop scripts are also available through application server command line interfaces.

   3.2 Application Server domain and javadb database.

 Every application server domain created out of the default installer as well as the ones explicitly created using 'asadmin create-domain'
 command will contain the following.

    3.2.1. A javadb database to be used by EJBTimer Service.

  The name of this database is 'ejbtimer' used to store information about EJB timers and is to be used by Timer Service that is part of
  this SDK. This database is owned by the user owning the domain. The differences compared to J2EE 1.4 SDK are
    a). Pointbase database was used for storing EJBTimer information.
    b). The ejbtimer pointbase database is owned by the user who initially performed the installation, not by the owner of application server domain.
  This database gets created under <domainroot>/<domainname>/lib/databases/ejbtimer, where <domainroot> by default will be <SDKInstalllRoot>/domains.
  A default domain by name domain1 is automatically created by SDK installer, 'ejbtimer' database is configured to run in "embedded mode"  inside application
  server's JVM.

  3.2.2. A JDBC connection pool by name "__TimerPool" is configured to point to 'ejbtimer' database. This pool is used by EJBTimer service.    

  3.2.3. A JDBC Resource with the jndi name of "jdbc/__TimerPool" that is configured to use __TimerPool.

  3.2.4. A JDBC connection pool by name "__CallFlowPool" is configured to point to 'sun-callflow' database. This pool is used by CallFlow module.      

  3.2.5. A JDBC Resource with the jndi name of "jdbc/__CallFlowPool" that is configured to use __CallFlowPool.

Entries 3.2.2 through and 3.2.5 can be viewed from SDK's powerful administration console. From your browser, go to http://localhost:<admin port>
to start the Administration Console, where <admin port> by default will have 4848 unless changed during SDK installation process.

Log in with the administrator user name and password. After logging in on the left hand side of the console, click to open
"Resources" to view the entries. (Timer related entries are circled in the following image).

Alternatively, run 'asadmin list-jdbc-connection-pools' to view the list of JDBC connection pools and 'asadmin list-jdbc-resources' to view the list of of JDBC
resources that have been created.

NOTE: None of these above components should be deleted.  Doing so will result in undesirable product behavior.

4. Start/Stop javadb through Application Server.

      Java EE 5 SDK's command line interface 'asadmin' supports starting and stopping network server through 'asadmin start-database' and 'asadmin stop-database' commands.

      Prior to understanding what these commands do, it is important to differentiate the two modes of javadb database serverEmbedded and Network mode.
      Refer to this link that has a very good explanation of them.

    4.1 Starting javadb.

 'asadmin start-database' command starts javadb network server in shared mode  to enable connections from other hosts in network. By default javadb network server(engine)
will only requests from clients local to the machine.
Syntax: asadmin start-database [--dbhost] [--dbport 1527]  [--dbhome install_dir/javadb]

--dbhome specifies the root directory of the database to be created if one is not specified, default is the current directory.

    4.2 Stopping javadb.

'asadmin stop-database' [--dbhost] [--dbport 1527]

--dbhost is the host name or ip address of the javadb database. The default is the IP address, which listens on all interfaces.
--dbport can be used to start the javadb server process on a port other than 1527.

5. Javadb database and EJB Timer.

EJB Timer service provided by SDK is used to schedule a timed notification to happen at specific time, after a duration of time, or at timed
intervals. This service uses javadb database to persist EJB timer information. As mentioned in the previous section, a javadb database
created automatically as part of the application server domain 'ejbtimer' is used for data storage. SDK comes pre bundled with this sample
application to demonstrate how to schedule timed notification of enterprise beans.

    5.1 About the timer sample application.

TimerSessionEJB is a stateless session bean that shows how to set a timer. This application is installed under <SDKInstallDir>/samples/ejb/misc/apps/timersession.
For added convenience, this application similar to other sample applications is also available as a pre assembled app along with source code and the build environment.
The pre built ear file is used here rather than building the application. However it is highly recommend  to change the application source and descriptors if required to understand
timers better.

    5.2 Deploying timer sample app to SDK.

   -Change directory to <SDKInstall>/samples/ejb/misc/apps/timersession.
   -Include SDKInstall/bin to PATH,
   -Run 'asant deploy' will deploy the "timersession.ear" file to the default domain(domain1).
   -Run 'asadmin list-components' to verify the deployment.

    Alternatively the deployment can also be verified through "Administration Console"


    5.3 Running the timer sample.

To run the application client, set your current directory to <SDKInstallDir>/app_dir/samples/ejb/misc/apps/timersession. Then type the following command:
<SDKInstallDir>/bin/appclient -client timersessionClient.jar -xml install_dir/domains/domain1/config/sun-acc.xml.

The output from the timer client is sent to domain_root_dir/domain_name/server/logs/server.log.  After about 30 seconds, view
<SDKInstallDir>/domains/domain1/logs/server.log and you will see the following lines:

TimerSessionBean: setSessionContext
TimerSessionBean: ejbCreate
TimerSessionBean: start createTimer
TimerSessionBean: ejbTimeout

          For more info on this Sample, Refer to the bundled samples documentation available in the sample's Root directory.

6. Javadb database and callflow.

CallFlow enables monitoring of application(s) behaviour that are deployed in Application Server. When CallFlow is enabled(either through Administration console OR through
command line interfaces) a database by name 'sun-callflow' is created under '<domainroot>/<domainname>/lib/databases/ejbtimer, where <domainroot> by default will be
<SDKInstalllRoot>/domains. A default domain by name domain1 is automatically created by SDK installer.

'sun-callflow' database is configured to run in "embedded mode"  inside application server's JVM. All the runtime information about monitored applications(s)  are stored in this
database. This database if required can be cleared using Administration Console. For more information on CallFlow please refer to CallFlow home page.

7. Using javadb tools.

Javadb comes with a minimal set of tools and they are ij, dblook and sysinfo. SDK also includes several useful scripts that can help you use javadb.
The following scripts are available for use in the <appserver_install_dir>/javadb/frameworks/[NetworkServer/embedded]/bin directory:

startNetworkServer.ksh/bat — Script to start the network server

stopNetworkServer.ksh/bat — Script to stop the network server

ij.ksh/bat — interactive JDBC scripting tool

dblook.ksh/bat — Script to view all or part of the DDL for a database

sysinfo.ksh/bat — Script to display versioning info regarding the javadb environment

NetworkServerControl.ksh/bat — Script which provides a means of executing commands on the NetworkServerControl API

To Configure Your Environment to Run the javadb Utility Scripts, following should be done
-Set the javadb_INSTALL environment variable to the <appserver_install_dir>/javadb directory
-Unset your CLASSPATH environment variable.
-You can also optionally set the following properties:
            javadb_SERVER_HOST to the host on which the network server will listen. Can also be set to to enable all listeners.
            javadb_SERVER_PORT to the port number on which the network server will listen.

8. Some useful Links.




Good article. Can Javadb be installed on Linux (Ubuntu)?On What other operating systems does this work?

Posted by Balki on November 08, 2006 at 12:06 AM PST #


Posted by Farmacia on March 17, 2009 at 11:48 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed



« August 2016