Project

General

Profile

Sample-DB-worker-node » History » Version 2

Udo Offermann, 02.04.2013 14:56

1 1 Udo Offermann
h1. Sample DBWorker Node
2 2 Udo Offermann
3
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.
4
5
The sample is provided via the repository "z2-samples-dbworker":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-dbworker.
6
7
h2. Prerequisites
8
9
All you need is a JDK 6 distribution as described in [[Step_2_-_Install_and_run_in_5_minutes]]. 
10
11
h2. Setting up the sample
12
13
This sample is run like all samples, that is, following [[How to run a sample]].
14
15
Assuming everything (including the z2 core and dbworker sample) is under *install* and your workspace is in *install/workspace* please import the following  projects into your workspace: _core_ from z2-base.core, _environemnt_ and _com.zfabrik.samples.dbworker.webapp_ from z2-samples.dbworker. 
16
17
*Note:* if the h2 driver jar is not found, please switch the core to branch _master_.
18
19
h2. Running the sample
20
21
h3. Starting Z2. 
22
23
Use the Eclipse launcher or start from the command line. The first time this will take a short moment. Watch the log output and keep an eye out for the following lines:
24
<pre>
25
04/02 14:43:22 [51]...ment/dbWorker@0.1 [800]: Listening for transport dt_socket at address: 5100
26
04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]...stemStateResource [800]: Attained system state: com.zfabrik.boot.main/bootrepo_up
27
04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]...stemStateResource [800]: Attained system state: com.zfabrik.boot.main/sysrepo_up
28
04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]...stemStateResource [800]: Attained system state: com.zfabrik.boot.main/process_up
29
04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]...stemStateResource [800]: Attained system state: com.zfabrik.boot.main/worker_up
30
04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]....db.h2.H2Database [800]: Starting H2 server...
31
04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]....db.h2.H2Database [800]: H2 Console Server running at http://192.168.178.28:8082 (only local connections allowed)
32
</pre>
33
34
h3. Run the sample app
35
36
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. 
37
38
h2. How can I use by myself?
39
40
The *environment* module of the "dbworker sample":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-dbworker/revisions/master/show/environment contains the important pieces. [[DB_Worker_Node_Add-on]] lists all environment components that you have to change or add in order to configure the DB worker node feature.