The ShipBean
The
ShipBean
defined for this chapter uses JDBC to
synchronize the bean’s state to the database. In reality, an
entity bean this simple could easily be deployed as a CMP bean. The
purpose of this chapter, however, is to illustrate exactly where the
resource-access code goes for BMP and how to implement it. When
learning about bean-managed persistence, you should focus on when and
where the resource is accessed in order to synchronize the bean with
the database. The fact that we are using JDBC and synchronizing the
bean state against a relational database is not important. The bean
could just as easily be persisted to some legacy system, to an ERP
application, or to some other resource that is not supported by your
vendor’s version of CMP, such as LDAP or a hierarchical
database.
Here is the complete definition of the ShipBean
:
package com.titan.ship; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.ejb.EntityContext; import java.rmi.RemoteException; import java.sql.SQLException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.DriverManager; import java.sql.ResultSet; import javax.sql.DataSource; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.FinderException; import javax.ejb.ObjectNotFoundException; import java.util.Collection; import java.util.Properties; import java.util.Vector; import java.util.Collection; public class ShipBean implements ...
Get Enterprise JavaBeans, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.