O O D B Design And Implementation - O D B Server with O D B Service -

Joe

Thành viên VIP
21/1/13
2,701
1,246
113
Hi

(cont. of ODManager and ODMS)

In this last section I talk generally about some ODB features, the examples and the ODB installation.

The ODB Essentials
First, for your memory: Object-Oriented data (OOD) are different from Relational data (RD). OOD is always a part of an object, the soul if you so will. An Object, says Dog, includes all attributes that constitute the object to a distinct object. A dog is certainly no cat, nor whatever animal -except "dog". And that is the most important characteristic of OOD.

Second, OOD can only exist with a physical class like the soul in a body. JAVA class is the body of JAVA OOD. In a RD model data are ACID. The Atomization of data makes them to the anonymous and that requires some toilsome reassembling of the data as we witness with RDB data. We get a list of ACID data (the tables) and we have to separate them, to categorize them and finally to give them the "identity". No so with OOD. We get a list of objects and each object is itself an entity with its own identity. The example "ThePeople" or "TheZOO" highlights the distinction between OOD and RD. Object "Trump" has its own attributes which belong only to object Trump -no separation, no categorization, nothing.

Third, OOD always go in sync with their class. And each class can have its own actions (i.e. methods) and environment (i.e. private part). In the example "TheZOO" you will see that class "Animal" has 4 complex methods:
  • public Process browse(). This method starts its own "browser" to access the "big data" hidden under the link that leads to WIKI data vault.
  • public boolean show( ). This method is the ersatz (alternative) of the previous method. Show() will be activated if the first method failed and returned a null.
  • public boolean getImage( ). As the name says, it returns an ImageIcon from the given link (or file).
  • public boolean playSound( ). This method renders the noise made by the specified animal. Dog with its barking, tiger with the growl, etc.

JAVA Object must be an implementation of JAVA Interface Serialization. The serialized object has two parts:

  • Data or OOD which could be any type: int, double, string or JAVA class. Only data are physically "serialized" and saved.
  • Codes or the methods. This part won't be part of the saving process. The reason is obvious: it exists already as JAVA class.

From this viewpoint OO Database (ODB or OODB) is the DB of the OOD parts. And their corresponding classes are preconditioned to be present in the CLASSPATH so that OOD could be "vivified" -like the soul expects a live body. Therefore ODB applications always precondition the JAVA classes on the site where they are executed (as a separate JAR file or embedded in a JAR file of the applications). It's wrong to assume that ODB is generic and covers "everything" from OOD to Object classes. Maybe one day Google with its IT Might (like IBM in the 70s/80s) would set a standard so that we, the little men, could work on the setting standard base like "Android" in the Smartphone world.

OOD as I explained in previous sections are only physically saved (permanent) when they are committed. There are different ways to implement the "Committing Phase" like in the RDB world. The 2PC or Two Phase Commit-Protocol is for example one of the most popular (and implemented) way to safeguard the consistency of data (more about 2PC: click HERE).



It's the question of integrity, importantness and the expense of the data. I have implemented the Commit process as following:
  • as long as the client doesn't explicitly commit the transaction the data stay locked and inaccessible for the others.
  • if the client unlocks the transaction (represented by the key) the data are temporarily available for everyone. They can be "relocked" and rollbacked at any time,
  • if the client issues a Commit the data are permanent and cannot be rollbacked.

It isn't the RDB-2PC. But I believe that it would work fine -without having to "acknowledge to and fro". It's the question of priority: time versus expense. In some sense the LOCK-TRANSACTION-COMMIT (or LOCK-TRANSACTION-UNLOCK) is a variant of 2PC.


ODB Package

The ODB is in two different packages:
- Full: CongDongJava, represented by the Admins (quydtkt, macarong35 and Tranhuyvc), and a trusted member Thanhpv. The package contains all the sources (Core, Server, examples + the MVC package). Those who want to access to the sources have to contact them for the fee which is set by them themselves.
- Runtime: this package contains 4 JAR files (clientODB.jar, joodb.jar, JODBServer.jar and joemvc.jar), the sources of all examples (eDict, People, DataMing and ZOO)

The FULL package:

ODBCore directory:
  • EnDecrypt.java (dummy)
  • ODBBroadcaster.java
  • ODBClientListener.java (Client)
  • ODBCluster.java
  • ODBConnect.java (Client)
  • ODBEvent.java (Client)
  • ODBEventListener.java
  • ODBInputStream.java (Client)
  • ODBOutputStream.java (Client)
  • ODBMining.java (Client)
  • ODBParms.java
  • ODBResult.java (Client)
  • ODBService.java
  • ODBTools.java (Client)
  • ODBWorker.java
  • ODManager.java
  • ODMS.java

The notes with (Client) are the required classes for applications on Client site (clientODB.jar). The EnDecrypt.java is a dummy file (see HERE) and you need to implement it with your own algorithm.

The modular design of ODBConnect/ODBCluster, ODBWorker and ODManager/ODMS give you the possibilities to enhance or to extend the functional concept:
  • The communication protocol between ODBConnect (client) or ODBCluster (Cluster Intercommunication) and ODBWorker lets you expand in more functionalities (currently: 0...99 or 100 commands whereas only roughly 30 commands are in used and the rest is free).
  • The cooperation between ODBWorker and ODManager can be easily extended. For example: Load sharing. The same for ODBService and ODManager.
  • The interchange between ODManager and ODMS still has a lot of room to improve. For example: ODB Shadowing.

I have already implemented the Load-Sharing between ODBConnect and ODBWorker. Normally Client computer is more in idle state than in processing work (e.g. user types something, presses ENTER and waits for the response) while the server has busily to serve numerous clients. Why should the Client computer won't share the processing burden? The check for the valid operational privilege (READ/WRITE/DELETE) is, for example, can be done on the Client computer and that makes more sense. Or the validation of ODB whether it is connected or not. A reject (i.e exception) from the server site is not only time-consuming, but also very risky (due to loss, latency, high load, etc.)

ODBCluster is an Agent (with privilege 2) spawned by ODManager on behalf of remote ODB accessing. Due to the Load-Sharing ODBCluster should work"lithely" without having to check burdensome redundancies (e.g. Privilege or ODB existence) as ODBConnect has to do. The "ODB Creation" is the privilege of Client whose privilege is 2 (more: O O D B Design And Implementation - Part 3 -). If you extend this Creation-function to ODBCluster you should be aware about the consensus complexity about the maintenance between the admins sitting on different nodes. It could be very thorny.

Nodes directory:
  • log_Node1: subdirectory contains the log.txt of Node_1
  • log_Node2: subdirectory contains the log.txt of Node_2
  • oodb_Node1: subdirectory contains the local ODBs of Node_1 (eDict, Member, OODBmix, people, stock, userlist and zoo)
  • oodb_Node2: subdirectory contains the local ODBs of Node_2 (eDict, OODBmix, people, stock)
  • JOODBServer.java and ServerController.java. The ODBServer SWING MVC-Application (see HERE)
  • classes: subdirectory contains the view-models (_JoodbServer_.txt, _tab1_.txt, _tab2_.txt, _tab_3.txt and the manifest.mf -used for jar. See section Installation)

Examples directory:
  • DataMining subdirectory with the sources: Animal.java (OOD of ODB OODBmix), Concurrency.java (works with ODB Stock), CopyAndPast.java (a API tool), DataMining,java (works with ODB Member), Items.java (OOD of ODB Stock), Member.java (OOD of ODB Member), MultipleUsers.java (works with OODBmix), OODBMember.java (the generator to create the big ODB Member), OODBmix.java (the generator to create the ODB ODBmix), Stock.java (generator for ODB Stock)
  • eDict subdirectory with the JavaFX sources: eDict.java, eDialog.java, eOpenDict.java (works with ODBConnect), eParms.java and the directory classes with the files: find.png, jfyStyle.css, save.png, style1.css, style2.css and the manifest.mf.
  • People subdirectory with the sources: InputPane.java (API tool), People.java (the OOD), PeopleController.java (works with ODBConnect) and ThePeople.java (SWING MVC). The classes subdirectory: the view model _People_.txt and the manifest.mf
  • zoo subdirectory with the sources: Animal.java (OOD), Browser.java (SWING-JavaFX WebBrowser), browserConfig.txt (the configuration for Browser), CopyPasteListener.java (API tool), Intro.java (with intro.txt), ZOO.java (main), ZooAnimal.java (works with ODBMining), ZooButtonListener.java, ZooButtonRenderer.java, ZooDialog.java, ZooTableModel.java. The sounds subdirectory contains: Bear.mp3, Boar.mp3, Buzzard.mp3, Cheeta.mp3, Hawk.mp3, hippo.mp3, Kookaburra.mp3, MouseLemur.mp3, Pheasant.mp3, Rhinoceros.mp3, Tasier.mp3, TigerGrowl.mp3.

If you want to run the examples you have to compile the sources. It's because I believe you rather work with an IDE (netbeans, eclipse, etc.) than to do the bare-bones work as I always do it. All the needed files are included in the examples directory. The "sounds" for the ZOO, JFX files for eDict, etc.

And if you intend to work with the JODBServer in the Nodes directory you have to include the SWING-MVC "joemvc.jar" to your local/global CLASSPATH and all the View models in your working PATH. An example in bare-bones work:

1) open a Command-Window and move to the Nodes directory
2) create a subdirectory "classes"
3) run "notepad" and create a "build.bat" file as following:
Code:
@echo off
javac -g:none -d ./classes *.java
cd .\classes
jar -cvfme ../JODBServer.jar manifest.mf JOODBServer *.class *.txt > ../log.txt
cd ..\
4) set CLASSPATH=./classes;./joemvc.jar;./joodb.jar;%CLASSPATH%
5) run the "build.bat"

(On Linux you could do the same steps. The shell script instead of build.bat and the setting CLASSPATH are very similar).


ODB Installation

First: I am never a fan of any IDE (netbeans or whatever) and never use one of them. So, what I show you hereunder is the bare-bones development of a true developer. Then because the ODB Core is in itself NOT a runnable application, but a package of APIs there's NO such a kind of ODB Installation. However, I show you how to build a "workable" JAR file for the ODB APIs. Because my UBUNTU PC was crashed and broken since months I show you here the way to build the JAR files on Windows (with joemvc.jar if you work with SWING-MVC ODBServer). Before you start to build your own ODBCore you have to create the EnDecrypt.java or copy the EnDecrypt.class to your created subdirectory classes (see step 1)

1) Open a Command-Window and Create a subdirectory classes (mkdir classes) in the ODBCore directory
2) run the command: set CLASSPATH=./classes;joemvc.jar;%CLASSPATH%
3) run notepad and create the build.bat file for the ODB Core directory:
Code:
@echo off
javac -g:none -d ./classes *.java
cd classes
jar -cvf ../joodb.jar ./joodb/*.class > ../log.txt
jar -cvf ../clientODB.jar ./joodb/ODBConnect*.class ./joodb/ODBMining.class ./joodb/ODBResult.class ./joodb/ODBTools.class ./joodb/ODB*Stream.*  ./joodb/ODBEvent.* ./joodb/*Client*.class ./joodb/*Decrypt.class > ../logC.txt
cd ..
4) verify the results with "dir *.jar" (2 JAR files must be present: joodb.jar and clientODB.jar). In the subdirectory classes you see all the compiled classes of ODB Core

With the joodb.jar and clientODB.jar you are now able to build your own apps and ODB server. First of all you need to put the joodb.jar in your global CLASSPATH. Or set it locally when you work with ODB (see, for example, "set CLASSPATH=....". The same for clientODB.jar on the Client site)

Assume that you have set joemvc.jar and joodb.jar correctly in your CLASSPATH you could move to the Nodes directory and do the similar things on the Command-Window:

1) create a subdirectory classes and put all the view-models in this classes directory
2) create a build.bat for this directory
Code:
@echo off
javac -g:none -d ./classes *.java
cd classes
jar -cvfme ../JODBServer.jar manifest.mf JOODBServer *.class *.txt > ../log.txt
cd ..
3) verify for the existence of JODBServer.jar with "dir *.jar"
4) amend the odbConfig_Node1, 2, etc, according to your needs (port number, path, etc.)
5) run "java -jar JODBServer.jar odbConfig.txt" and see how it comes up.

If you run your own EnDecrypt algorithm you have to delete the ODB userlist in the Nodes/oodb_Node1 directory and run your newly-created JODBServer with the default superuser: ID is "admin", password is "system". Otherwise the delivered userlist contains the following users:

Code:
+----------------+--------------+-------------+
| user           |     ID       | Password    |
+----------------+--------------+-------------+
| quydtkt        ! quydtkt      | quydtkt     |
+----------------+--------------+-------------+
| thanhpv        | thanhpv      | thanhpv     |
+----------------+--------------+-------------+
| test           | test         | tester      |
+----------------+--------------+-------------+
Please change/delete them according to your own references.

Similar to ODBServer you move to the subdirectories DataMining, eDict, People and zoo and create the classes directory, the build.bat file and play with them.

- ThePeople gives you a glim about the famous people (except me : Joe).
- ZOO shows you how to build a sophisticated app using the vast big data of the Web (WIKI, the sounds and the images).

Liabilities, Documentation and Support

The author Joe T. Nartca
and CongdongJava represented by the persons I mentioned above are NOT responsible for the loss or damages of data on your environment. It's a freeware. However if you use ODB for any kind of commercial purposes you have to mention the sources and the author + CongdongJava and donate some voluntary fee to CongdongJava. Via this way you support the CDJ people who spend their time and money to keep this site alive for YOU.
Copyright (c) 2020, CongdongJava.com - Joe T. Nartca
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
There is NO explicit documentation, except the written series posted here on CongdongJava.com and the included JAVA-Styled Documents in API format (JDoc directory).

Bugs and/or suggestions can be openly reported or made here on the Forum board and if I was free I could care about the correction or enhancement. But I am NOT obliged to amend, nor to correct them.

It's obvious that none of the software in the world is bug-free. And I am aware about that, too. Even I have tried hard to reduce the bugs, but there still are some. ODBCore and all the examples might contain some hidden bugs. If you possess the ODBCore sources and discover some bugs and you could amend them OR you have enhanced some functionalities of the Core then please inform CongdongJava community about your work. Thank you in advance. It's the one-to-many-and-many-to-one benefit.

The Examples

- eDict:



- ThePeople


- DataMing




- ZOO: Note: Only JavaFX provides you the facility to play mp3 sound. For SWING app you need to download this JavaZOOM.


....and when you click at the (image) "Bear" you'll hear it growling (method playSound) in background, or the WIKI button to learn its habitats (method browse), etc. Have fun with the "virtual" ZOO.

That's all, folks! Thanks for following my series...

Note: due to size restriction I have to divided the package into 4 small one RT_1...RT_4.zp
The jlayerme01.zip is for the MP3 used by "the ZOO"
 

Attachments

Sửa lần cuối: