Simple O/R Mapping Tool Help
Main Screen
After running codegen.sh, you should see the main screen. Here you will
see a tree pane for the schema objects (tables and views) for the Oracle database
to which
you will connect to extract schema information and generate Java code for
a simple one-to-one object relational mapping. On the
right pane titled Code Generation
you have fields which are prepopulated and default code type to generate
as dao (Data Access Object).
Currently three types of Java classes can be generated
- Data Access Object (dao) - These objects form the data access
layer and they are responsible for CRUD (create, read update and delete)
operations on their corresponding table. Each DAO has a find method to which
you can pass a value object (vo) with some properties set using setter
methods and it will internally create the corresponding SQL and return the
results as a list of populated value objects. Each DAO also has an
insert(), delete() and update() method.
- Value Object (vo) - A value object is a Java bean used by
the corresponding DAO and different software layers to transfer coarse grained
data between layers. Code generator generates a value bean for each selected
schema object where the properties match the columns of the schema object.
- Primary Key Object (pk) - Current not used. A
primary key object maps to the primary key of its corresponding schema object.
Schema Extraction
The first step in code generation is schema extraction from an Oracle database.
First, select Load Schema Objects from File Menu.
The following dialog box will appear. Initially the fields in the dialog
box will be empty. However, the code generator saves the last setting after
each run.
Here you need to provide the database type (Oracle or Postgres), database
host, port, name and user/schema information for the schema
where your database tables /views reside. Then, press OK. After successful
schema extraction, the Generate and Select All buttons
in the Code Generation panel will be enabled. And you will see the tree
and schema object list box populated.
Now you can select the schema objects from the list, adjust the parameters
like code type and output directory and press Generate button.
Here, two data access objects are generated for NC_USERCLASS and NC_EXPSEGMENT
schema objects and saved to /tmp/clinical/server/dao directory. The Package
Name is the name of the package for the data access objects. Since data
access objects depend both on code generated (like value objects) and programmer
written Java code residing in clinical.exception and clinical.server.utils
packages, if you want to use a different package structure, you need to
move the dependencies in clinical.exception and clinical.server.utils
packages to your package structure and set the Package Name, Value Object
Package Name, Exception Package Name and Utilities Package Name fields accordingly.
Custom Code in Generated Java Code and Code Regeneration
During development, there may be cases where you need to customize some
of the generated code. If you don't want your custom code to disappear after
code regeneration,
you should put your custom code within delimeters like shown below.
/*+++ */
// Enter your code here
String myVar;
public String getMyVar() { return this.myVar; }
/*+++ */