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.
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 javax.ejb.EntityBean { public Integer ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access