W R I T E A N D D E P L O Y J 2 E E A P P L I C A T I O N S
adapter, datasource or other data access layer to access the persistence layer. Whenever you
retrieve these objects through JNDI it is recommended to specify their name as environment
variable in the EJB DD (ejb jar.xml). The XDoclet tag would look like this:
* @ejb:env entry name="DataSourceName"
* value="java:/PostgreSQL"
And is then used here:
private DataSource getDataSource()
{
try {
Context lContext = new InitialContext();
String lDataSourceName = (String) lContext.lookup(
"java:comp/env/DataSourceName"
);
return (DataSource) lContext.lookup( lDataSourceName );
}
catch ( NamingException ne ) {
throw new EJBException( "Naming lookup failure: " + ne.getMessage() );
}
}
This enables the deployer to adjust there is another JNDI name used for the data source.
The only vendor specific settings for BMPs is to set them as read only bean and then the
ejbStore() method is never called. Of course, you can still save or change data in another
method but this is considered erroneous coding.
Depending on your commit options and other settings it is possible that the Entity Beans
container invokes the ejbStore() method too often. To avoid these calls there is an option
method isModified() and if it returns false the ejbStore() is not called. XDoclet normally
generates the method and the call to set it dirty or clear already. In your Bean class you
have the chance to specify the methods makeDirty() and makeClean() as abstract
methods and then you can set this flag in other, not generated methods.
/**
* Mark the Entity as changed that needs to be saved
**/
protected abstract void makeDirty();
/**
* Mark the Entity as synchronized with the DB and does
* not need to be saved
**/
protected abstract void makeClean();
As example in the TestBMPEntityBean the ejbLoad() method sets the values with the
setter methods but in turn the set the dirty flag to true which obviously false. With the
method call of makeClean() it is fixed.
public void ejbLoad()
45
footer
Our partners:
PHP: Hypertext Preprocessor Cheap Web Hosting
JSP Web Hosting
Ontario Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Java Hosting
Cheapest Hosting
Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved