Introduction:
This article describes how to use the object relationship mapping bridge (OJB) through a simple example. Example programs contain righteous products
Directory database and some user features. The source code of the program is published along with the OJB source code, which is included in org.apache.
Ojb.Tutorial1 package.
The document demonstrates a small program that implements five user features through the object-related bridge API (PersistenceBroker)
The specific structure. Five functions include modifications, deletion, access, etc. of objects. How does the document also demonstrate?
A Product Access object is mapped to a table in the relational database.
Sample program:
This example is a program under the console that operates a product catalog database through different user input data, including
Five functions:
1. List All Products D - List All Products
2. ENTER A New Product D D- Create a new product in inventory
3. Edit An EXISTING PRODUCT RECORD D - a product in the inventory
4. DELETE A Product RECORD D D ㄉ D? 獯胬 桓 桓 桓?
5. Quit The Application D - For unity, we also use it as a function
The above five functions, only some of the basic concepts of the OJB. There is no implementation of 1: 1, 1 in the example:
N or M: N mapping, you want to know about these three D-advanced O / R.
Operation example:
In order to perform the program shown in the document, you must first prepare an example. No need to configure a database, example
The program has integrated HSQLDB database, and what you have to do is running sample programs with Ant.
Unzip the source code of the OJB to ensure that you are currently in the directory where the directory OJB is:
Under Windows 9x / NT / 2000 / XP:
Preparation Example: Perform bin / build.bat prepare-tutorials
Operation example: Execute bin / tutorial1.bat
Under UNIX / Linux:
Preparation Example: Perform bin / build.sh prepare-tutorials
Operation example: execution bin / tutorial1.sh
Structure of the sample program:
The structure of the entire program can be represented by the following class diagrams.
The program contains some usecases. The Usecase interface is implemented by an abstract base class AbstractUsecase, which
Provide some code for the specific class's implementation. There are four specific Usecase classes: uclistallproduc
TS, UcenterneWProduct, UcdeleteProduct, and UcquitApplication class. Product class is expressed
A product record in the Product database.
Application.run () method implements a loop, the program is in the Application.SelectUserCase () method
Wait for the user's input, once a feature is selected, the usecase.Apply () method will be called. Usecase is through
It is achieved by our familiar Command design model.
While (True)
{
Try
{
// select a use case and performance it
Usecase uc = selectusecase ();
Uc.apply ();
}
Catch (throwable t)
{
System.out.println (t.getMessage ());
}
}
The usecase method contains two methods: getDescription () method and Apply () method. Use.getDescription () method to display basic information of the function to the user, in the Application.SelectuseCase () method
A directory for all functions will be given. Usecase.Apply () method is a commercial logic implementation of different functions.
.
Here is the simplest function of the apply () method in the UcquitApplication class:
Public void apply ()
{
System.out.println ("Bye ...");
System.exit (0);
}