|
|
|
Last
revision of this document: |
As
opening a connection to a database-systems takes pretty long
(compared to processing other Java-code), a the class
JSBS_DB_ConnectionManager
is implemented.
This class establishes and maintains connections
to a database.
If the connection to the database is no longer
used by a Business Object (BO), then the ConnectionManager does not
close the connection but marks it as unused and keeps it open for a
later reuse.
Preface:To
code this class is only necessary if you decided to code the
base-classes by yourself (see JS_FC01ca –
Create a project for the base-classes).
If
you decided to use the library with the JavaScout base-classes (see
JS_FC01cb – Download the jar-file
for the base-classes) you can skip this step.
Credits:Too
numerous to mention; the idea is available in dozens of versions –
I refined a lot of ideas into my system.
JS_FC01f - Base-Class for reading a file with XML-structure completed - and its prerequisites too.
Recommended:
* Structure
of the xml-file with the parameters for database- and JAS-connection
(Connections.xml in directory CONNECTIONS)
read.
This introduces the parameters that are needed to
incorporate the access to a database in a JAVA-application.
* For
more explanations using a database-system in a JAVA-application,
please browse through JS_Base02d,
Step3 – Read parameters for the connection to the database
and JS_Base02e,
Step 4 – Connect to the database
– if you not already made this exercise.
Implement
the ConnectionManager:This
step has only to be done, if you decided to code the base-classes;
i.e. you did step JS_FC01ca –
Create a project for the base-classes.
If
you decided for JS_FC01cb –
Download the jar-file for the base-classes, you may skip to
Construct the
ConnectionManager-class and verify if the connection was successful.
Right
click onto the project 'JS_Base' and select
>New>Class
Enter
the Package (js_base.xml),
the (Class-)Name (JSBS_XML_Connections)
select
(o) public,
do not check any boxes,
enter the
Superclass (JSBS_XML_Base)
and
click the [ Finish ] button.
Eclipse
has already generated a template and the individual code can be
entered.
For a listing of the code please refer to Code
for JSBS_XML_Connections.
The
just coded base-class is not directly used in an apllication; it is a
base for the ConnectionManager which establishes and manages
connections to the database.
To code the ConnectionManager-class
do the following:
Right
click onto the project 'JS_Base' and select
>New>Class
Enter
the Package (js_base.connections),
the (Class-)Name (JSBS_DB_ConnectionManager)
select
(o) public,
do not check any boxes,
leave the default
Superclass (java.lang.Object)
and
click the [ Finish ] button.
Eclipse
has already generated a template and the individual code can be
entered.
For a listing of the code please refer to Code
for JSBS_DB_ConnectionManager.
top.
Next
Steps:I
f you are impatient and are greedy to test the implementation, you
can make a sidestep to
JS_FC01p
– Create the database-table 'Project' and establish the
connection | Construct the ConnectionManager and verify if the
connection was successful.
The
regular continuation is
JS_FC01o
– Develop the Server-Side Class for the Business Objject
'Project'.