Project

General

Profile

Actions

Sample-DB-worker-node » History » Revision 5

« Previous | Revision 5/19 (diff) | Next »
Udo Offermann, 03.04.2013 16:06


Sample DB Worker Node

This sample illustrates the usage of the DB_Worker_Node_Add-on and thereby how easy it is to setup a all-in-one-system comprising the z2 environment and the database. The sample web-application has a very simple database schema containing one table with a primary key and a varchar column while the UI provides just the basic CRUD actions.

The sample is provided via the repository z2-samples-dbworker.

Prerequisites

All you need is a JDK 6 distribution as described in Step_2_-_Install_and_run_in_5_minutes.

Setting up the sample

There is no further pre-requisite to running this sample, and you may proceed as described in How to run a sample. Here's the really fast version:

mkdir install
cd install 
git clone -b master http://git.z2-environment.net/z2-base.core
git clone -b master http://git.z2-environment.net/z2-samples.dbworker

# on Linux / Mac OS:
cd z2-base.core/run/bin
./gui.sh

# on Windows:
cd z2-base.core\run\bin
gui.bat

The first time you launch the sample will take a while. Watch the log output and keep an eye out for the following lines:

4/03 15:50:52 [33]...ment/h2Worker@0.2 [800]: 04/03 15:50:52 [1]...2DatabaseLauncher [800]: H2 TCP Server running at tcp://192.168.178.28:9092 (only local connections allowed)
04/03 15:50:52 [32]...ment/h2Worker@0.1 [800]: SQLState(90028) vendor code(90028)
04/03 15:50:52 [33]...ment/h2Worker@0.2 [800]: 04/03 15:50:52 [1]...2DatabaseLauncher [800]: H2 Console Server running at http://192.168.178.28:8082 (only local connections allowed)
04/03 15:50:52 [33]...ment/h2Worker@0.2 [800]: 04/03 15:50:52 [1]...stemStateResource [800]: Attained system state: com.zfabrik.db.environment/h2WorkerUp
04/03 15:50:52 [33]...ment/h2Worker@0.2 [800]: 04/03 15:50:52 [1]...worker.WorkerSoul [800]: Completed worker process initialization

If you want to inspect the code using Eclipse, please create a workspace in install (i.e. install/workspace) and import the Git repositories and the following projects into your workspace: core from z2-base.core, environemnt and com.zfabrik.samples.dbworker.webapp from z2-samples.dbworker (see also First steps).

Run the sample app

run http://localhost:8080/dbworker_sample and play around with the UI. You can create new entries, modify and update existing entries by clicking inside the name column and delete entries. The sample application itself is not that tricky. It uses the JDBC API in order to create the schema on demand as well as to implement the CRUD operations. A single jsp file provides the UI.

How to use the DB Worker Add-on for own projects?

The environment project of the sample contains the important pieces: The z2 repository component dbWorkerAddon.properties makes the DB Worker Node Add-on available to the z2-Environment. Furthermore the home layout defined in home.properties launches the database worker in addition to the web worker:

com.zfabrik.component.type=com.zfabrik.homeLayout
home.workers = com.zfabrik.db.environment/h2Worker, environment/webWorker

Note that com.zfabrik.db.environment/h2Worker precedes environment/webWorker so that the DB is up and running when before the web applications are started.

Updated by Udo Offermann over 11 years ago · 5 revisions