web server - Borland Technical Publications
web server - Borland Technical Publications web server - Borland Technical Publications
Implementing an entity bean ■ ■ ■ Security Roles: simple definitions of security roles used by the application. Any security role references you defined for your beans must also be defined here. Method Permissions: each method of each bean can have certain rules about their execution. These are set here. Container-Transactions: this specifies the transaction attributes as per the EJB 2.0 specification for each method participating in a transaction ■ Exclude List: methods to be uncalled by anyone All of these can be accessed through the Deployment Descriptor Editor. You should refer to the EJB 2.0 specification for DTD information and the proper use of the descriptor files. Entity Bean Primary Keys Each Entity Bean must have a unique primary key that used to identify the bean instance. The primary key can be represented by a Java class that must be a legal value type in RMI-IIOP. Therefore, it extends the java.io.Serializable interface. It must also provide an implementation of the Object.equals(Object other) and Object.hashCode() methods. Normally, the primary key fields of entity beans must be set in the ejbCreate() method. The fields are then used to insert a new record into the database. This can be a difficult procedure, however, bloating the method, and many databases now have built-in mechanisms for providing appropriate primary key values. A more elegant means of generating primary keys is for the user to implement a separate class that generates primary keys. This class can also implement database-specific programming logic for generating primary keys. Generating primary keys from a user class With enterprise beans, the primary key is represented by a Java class containing the unique data. This primary key class can be any class as long as that class is a legal value type in RMI-IIOP, meaning it extends the java.io.Serializable interface. It must also provide an implementation of the Object.equals(Object other) and Object.hashCode() methods, two methods which all Java classes inherit by definition. The primary key class can be specific to an particular entity bean class. That is, each entity bean can define its own primary key class. Or, multiple entity beans can share the same primary key class. The bank application uses two different entity beans to represent savings and checking accounts. Both types of accounts use the same field to uniquely identify a particular account record. In this case, they both use the same primary key class, AccountPK, to represent the unique identifier for either type of account. The following code shows the definition of the account primary key class: public class AccountPK implements java.io.Serializable { public String name; public AccountPK() {} public AccountPK(String name) { this.name = name; } } Chapter 14: Entity Beans and CMP 1.1 in Borland Enterprise Server 113
Implementing an entity bean Generating primary keys from a custom class To generate primary keys from a custom class, you must write a class that implements the com.borland.ejb.pm.PrimaryKeyGenerationListener interface. Support for composite keys Primary keys are not restricted to a single column. Sometimes, a primary key is composed of more than one column. In a more realistic example, a course is not identified merely by its name. Instead, the primary key for each course record can be the department in which the course is offered and the course number itself. The department code and the course number are separate columns in the Course table. A select statement that retrieves a particular course, or all courses in which a student is enrolled, must use the entire primary key; that is, it must consider both columns of the primary key. The Borland CMP engine supports composite primary keys. You can use keys with multiple columns in the where clause of a select statement. You can also select all fields of a compound key in the select clause portion of the statement. For the where clause, specify multiple field names in the same manner that you specify single field names. Use “and” to separate each field. The format is = :[ejb/] Note that the equal (=) sign is one of several possible notations. You could also specify greater than (>), less than (=), or less than or equal (
- Page 73 and 74: The Borland IIOP connector BES supp
- Page 75 and 76: Setting up your web container with
- Page 77 and 78: 66 BES Developer’s Guide
- Page 79 and 80: Web-enabling your CORBA server Impo
- Page 81 and 82: Configuring your Apache web server
- Page 83 and 84: Configuring your Apache web server
- Page 85 and 86: Web Services and Partitions ■ ■
- Page 87 and 88: Web Service providers Java:RPC prov
- Page 89 and 90: How Borland Web Services work
- Page 91 and 92: Packaging Web Service Application A
- Page 93 and 94: Tools Overview Java2WSDL tool Note
- Page 95 and 96: 84 BES Developer’s Guide
- Page 97 and 98: Client view of an enterprise bean L
- Page 99 and 100: Client view of an enterprise bean E
- Page 101 and 102: Managing transactions Managing tran
- Page 103 and 104: Support for JNDI Support for JNDI T
- Page 105 and 106: EJB to CORBA mapping A CORBA progra
- Page 107 and 108: 96 BES Developer’s Guide
- Page 109 and 110: Application Client architecture Pac
- Page 111 and 112: Document Type Definitions (DTDs) my
- Page 113 and 114: Support of references and links The
- Page 115 and 116: Use of Manifest files Use of Manife
- Page 117 and 118: 106 BES Developer’s Guide
- Page 119 and 120: Sessions in secondary storage If yo
- Page 121 and 122: 110 BES Developer’s Guide
- Page 123: Container-managed persistence and R
- Page 127 and 128: Container-Managed Persistence in Bo
- Page 129 and 130: Container-Managed Persistence in Bo
- Page 131 and 132: Setting Properties Setting Properti
- Page 133 and 134: Setting Properties into a BLOB. The
- Page 135 and 136: Setting Properties Automatic table
- Page 137 and 138: 126 BES Developer’s Guide
- Page 139 and 140: Container-managed persistence and R
- Page 141 and 142: Container-Managed Persistence in Bo
- Page 143 and 144: Container-Managed Persistence in Bo
- Page 145 and 146: Container-Managed Persistence in Bo
- Page 147 and 148: Container-Managed Persistence in Bo
- Page 149 and 150: Container-Managed Persistence in Bo
- Page 151 and 152: Container-Managed Persistence in Bo
- Page 153 and 154: 142 BES Developer’s Guide
- Page 155 and 156: Setting Properties J2EE 1.3 Entity
- Page 157 and 158: Setting Properties Figure 16.2 Edit
- Page 159 and 160: Setting Properties Table 16.1 ejb.m
- Page 161 and 162: Setting Properties Table 16.3 Table
- Page 163 and 164: Setting Properties Security Propert
- Page 165 and 166: Aggregate Functions in EJB-QL Selec
- Page 167 and 168: Support for ORDER BY Support for OR
- Page 169 and 170: Overriding SQL generated from EJB-Q
- Page 171 and 172: Container-managed data access suppo
- Page 173 and 174: 162 BES Developer’s Guide
Implementing an entity bean<br />
■<br />
■<br />
■<br />
Security Roles: simple definitions of security roles used by the application. Any<br />
security role references you defined for your beans must also be defined here.<br />
Method Permissions: each method of each bean can have certain rules about<br />
their execution. These are set here.<br />
Container-Transactions: this specifies the transaction attributes as per the EJB<br />
2.0 specification for each method participating in a transaction<br />
■<br />
Exclude List: methods to be uncalled by anyone<br />
All of these can be accessed through the Deployment Descriptor Editor. You should<br />
refer to the EJB 2.0 specification for DTD information and the proper use of the<br />
descriptor files.<br />
Entity Bean Primary Keys<br />
Each Entity Bean must have a unique primary key that used to identify the bean<br />
instance. The primary key can be represented by a Java class that must be a legal<br />
value type in RMI-IIOP. Therefore, it extends the java.io.Serializable interface. It<br />
must also provide an implementation of the Object.equals(Object other) and<br />
Object.hashCode() methods.<br />
Normally, the primary key fields of entity beans must be set in the ejbCreate() method.<br />
The fields are then used to insert a new record into the database. This can be a difficult<br />
procedure, however, bloating the method, and many databases now have built-in<br />
mechanisms for providing appropriate primary key values. A more elegant means of<br />
generating primary keys is for the user to implement a separate class that generates<br />
primary keys. This class can also implement database-specific programming logic for<br />
generating primary keys.<br />
Generating primary keys from a user class<br />
With enterprise beans, the primary key is represented by a Java class containing the<br />
unique data. This primary key class can be any class as long as that class is a legal<br />
value type in RMI-IIOP, meaning it extends the java.io.Serializable interface. It must<br />
also provide an implementation of the Object.equals(Object other) and<br />
Object.hashCode() methods, two methods which all Java classes inherit by definition.<br />
The primary key class can be specific to an particular entity bean class. That is, each<br />
entity bean can define its own primary key class. Or, multiple entity beans can share<br />
the same primary key class.<br />
The bank application uses two different entity beans to represent savings and checking<br />
accounts. Both types of accounts use the same field to uniquely identify a particular<br />
account record. In this case, they both use the same primary key class, AccountPK, to<br />
represent the unique identifier for either type of account. The following code shows the<br />
definition of the account primary key class:<br />
public class AccountPK implements java.io.Serializable {<br />
public String name;<br />
public AccountPK() {}<br />
public AccountPK(String name) {<br />
this.name = name;<br />
}<br />
}<br />
Chapter 14: Entity Beans and CMP 1.1 in <strong>Borland</strong> Enterprise Server 113