BMP EJB Classes
The current release includes a beta release of the bean managed persistence
EJB generator.
Overview
Bean Managed Persistence enterprise java beans can require a lot of coding.
The JDBC Wizard can use database tables or views. In order to generate
BMP EJB's a few steps must be taken using the wizard:
- Create the bean
- Select the columns you would like to select, insert and update
- Create finders, if any. The wizard automatically generates
findByPrimaryKey(). For additional finder methods (eg findAll(),
findByRegion(String theRegion)) the Wizard must be used to specify part of
the SQL, and any parameters the finders need.
- Select the create() methods to generate. And if the remove() method should
delete a database record, or just thorw an exception.
Primary Keys
If the database object does not have a primary key defined, please
follow these steps:
- Select the column object which is to be a primary key, or part of a
composite primary key
- Check the Primary Key checkbox
- Press Save
Creating A BMP EJB
By drilling down the treeview control, we can reach the "BMP EJB
Classes" node below the database table or view of our choice. See below.
- The EJB Name is used as the name for the bean's remote interface.
- The package is the java package of all the bean's support java
files.
- The manifest name is the name given to the bean in the xml manifest
file. The bean name should be unique within the Wizard project file. When
generating EJB's the wizzard generates one manifest with descriptions of all
the EJB's generated.
When the create button is pressed, the user is navigated to the next set of
dialogs.
Configuring BMP EJB's
The BMP EJB Classes tab (shown below), displays java class and manifest
information the wizard will generate.
- The remote interface is used by the client to represent an instance
of a bean. The interface includes methods to get and set bean properties.
The remote interface extends EJBObject, and so also has methods to get the
primary key, get the handle, and remove to the bean.
- The bean package is the name of the java package all generated files
should use.
- The implementation class is the EJB class. Contained within are all
the methods necessary to implement the EJB.
- The home interface (or bean factory), is used by the client to create
and find bean instances. This interface extends EJBHome, and so also has methods
to remove a bean instance.
- The key class is used to hold a bean's primary key valur. The key class
is a java type for simple keys. The wizard generates classes to represent
a composite key's values.
- Key class is the class used to represent the primary key. This is
usually a Java type. Should the key be composite, the wizard generates an
appropriate primary key class.
- DAO key class is used by the implementation class. This class is
the data access object for the bean's key. This class contains JDBC code to
find primary keys behind the scenes.
- DAO data class is used to hold all of a bean's property values.
- DAO class contains JDBC code to manage one bean instance: findByPrimaryKey,
store, create, remove.
- The name in manifest, is the name used for the bean in the generated
manifest file. The name should be unique within a JDBC Wizard project.
- Javadoc for each class can be edited
or created . If no comments
are present, default comments are generated when the code is generated.
Configuring Columns
The columns tab is used to configure the bean's individual columns, and how
they map to the underlying database. The bean must have select and insert access
to the primary key column(s).
The columns property editor pops up when an entry in the table is double
clicked.
- The column name is the database table, or view, column name.
- The property name is the name of the bean property which represents
this column.
- The transaction to use on the get and set methods is set here.
- The access combo is used to determine what the bean can do to the
database: insert and/or update and/or select the column value.
- The property type is the java type the property should have.
- The get/set op. controls the JDBC Resultset and PreparedStatement
get and set methods to use for this column.
- The set NULL JDBC type controls what constant to use when calling
setNull() on a PreparedStatement object.
Configuring Finders
The finders tab allows bean finders to be created, edited and removed.
To create a new finder, press the new button.
Below is a sample EJB finder parameter dialog:
- Parameter Name is used to name the parameter in the finder method
call.
- Set Fields From quickly sets this dialog's controls to the values
of one of the columns previously configured.
- Precision is the total number of digits for numbers and
characters for strings.
- Scale is only useful for decimal numbers. It specifies how many
decimal digits the number can have.
- Java Type is the java type of the parameter.
- Get/Set Op. is the PreparedStatement get and set method call to
use.
- Set NULL JDBC Type controls what constant to use when calling
setNull() on a PreparedStatement object.
Configuring Create Methods
The wizard allows two types of ejb create methods to be generated. For
example:
public Person create(PersonDAOData thePersonDAOData)
public Person create(String theEmail, String theFirstName, String theLastName, String theTitle)
The PersonDAOData class is also generated by the wizard. It is used to hold a
bean instance's values.
public class PersonDAOData implements java.io.Serializable
{
protected Date myDateAdded;
protected String myEmail;
protected String myFirstName;
protected String myLastName;
protected String myTitle;
public PersonDAOData()
public PersonDAOData(PersonDAOData theToCopy)
public void clearProperties()
public Date getDateAdded()
public String getEmail()
public String getFirstName()
public String getLastName()
public String getTitle()
public void setDateAdded(Date theDateAdded)
public void setEmail(String theEmail) throws NullPointerException
public void setFirstName(String theFirstName)
public void setLastName(String theLastName)
public void setTitle(String theTitle)
}
The tab (shown above) has the following settings:
- Generate create(DAO Data Class) is used to generate a create method
which uses a DAO data class to hold the bean values.
- Generate create(Bean Property1, 2, ...) is used to generate a method
which uses one parameter per database column.
Configuring The Remove Method
- Remove can be made to delete a record from the database, or to throw
and exception if remove is called.
Generating Java Code
The wizard can generate java code, when one or more beans have been created
in the wizard.
More information on generating and using the EJB source code can be found here.