- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
See also in Java
See also PDF417 Generator In Java Using Barcode generator for Java Control to generate, create PDF-417 2d barcode image in Java applications. www.OnBarcode.comPDF-417 2d Barcode Scanner In Java Using Barcode scanner for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.com2.1 Generating home, remote, local, and local home interfaces 2.2 Adding and customizing the JNDI name for the home interface 2.5 Generating a primary key class Generating QR Code ISO/IEC18004 In Java Using Barcode generation for Java Control to generate, create Denso QR Bar Code image in Java applications. www.OnBarcode.comDataMatrix Creation In Java Using Barcode creator for Java Control to generate, create Data Matrix image in Java applications. www.OnBarcode.comGenerating a primary key class
Creating PDF 417 In Java Using Barcode generation for Java Control to generate, create PDF417 image in Java applications. www.OnBarcode.comEncoding EAN-13 In Java Using Barcode creation for Java Control to generate, create EAN 13 image in Java applications. www.OnBarcode.com2.5 Generating a primary key class
Encoding GS1 DataBar-14 In Java Using Barcode printer for Java Control to generate, create GS1 RSS image in Java applications. www.OnBarcode.comMSI Plessey Generator In Java Using Barcode creator for Java Control to generate, create MSI Plessey image in Java applications. www.OnBarcode.comProblem
Encoding PDF-417 2d Barcode In .NET Using Barcode drawer for Reporting Service Control to generate, create PDF-417 2d barcode image in Reporting Service applications. www.OnBarcode.comPainting PDF-417 2d Barcode In Java Using Barcode generation for Android Control to generate, create PDF-417 2d barcode image in Android applications. www.OnBarcode.comYou want to generate a primary key class for your entity beans during development.
Drawing Quick Response Code In Objective-C Using Barcode generation for iPad Control to generate, create QR-Code image in iPad applications. www.OnBarcode.comQR Code ISO/IEC18004 Generation In Visual C# Using Barcode printer for .NET Control to generate, create QR Code 2d barcode image in VS .NET applications. www.OnBarcode.comBackground
Read Code-39 In Visual Basic .NET Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comCode128 Generator In C# Using Barcode maker for VS .NET Control to generate, create Code 128 Code Set A image in VS .NET applications. www.OnBarcode.comAs you develop more and more entity beans, you find yourself also having to create the primary key class. As we emphasized in this chapter, having to code one more class just adds to the time it takes to develop a bean and increases your chances for having source files out of synch. Generating GTIN - 128 In Objective-C Using Barcode generation for iPad Control to generate, create EAN / UCC - 14 image in iPad applications. www.OnBarcode.comUPC-A Supplement 2 Drawer In None Using Barcode generation for Office Word Control to generate, create Universal Product Code version A image in Office Word applications. www.OnBarcode.comRecipe
Barcode Maker In VS .NET Using Barcode generation for ASP.NET Control to generate, create Barcode image in ASP.NET applications. www.OnBarcode.comBarcode Printer In .NET Framework Using Barcode maker for .NET Control to generate, create Barcode image in .NET applications. www.OnBarcode.comTo have XDoclet generate a primary key class, use the @ejb.pk tag in your bean source file, use the @ejb.pk-field tag to denote an accessor for the primary key, and modify your <ejbdoclet/> task to include the <entitypk/> subtask. For instance, examine the ItemBean class shown in listing 2.10. The XDoclet tags applicable to this recipe are shown in bold; the others can be found in earlier recipes. Data Matrix Scanner In VB.NET Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET applications. www.OnBarcode.comDecode EAN128 In C#.NET Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comListing 2.10 ItemBean.java
package ch2; import javax.ejb.*; /** * @ejb.bean type="CMP" * name="ItemBean" * jndi-name="ejb/ItemBean" Identifies the * view-type="both" primary key field * primkey-field="ID"; * @ejb.pk Adds the primary key tag */ public abstract class ItemBean implements EntityBean { public void setEntityContext( EntityContext context) {} public void unsetEntityContext( ) {} public public public public public void void void void void ejbRemove() {} ejbLoad() {} ejbStore() {} ejbActivate() {} ejbPassivate() {} /** * @ejb.create-method */ Code generation with XDoclet
public void ejbCreate( String id ) { setID( id ); } /** * @ejb.interface-method Identifies the primary * @ejb.persistence key getter method * @ejb.pk-field */ public abstract String getID(); } Notice in addition to the placement of the specified tags that we included the primkey-field attribute in the @ejb.bean tag at the class declaration level. Note that you must also use the @ejb.persistence tag in combination with the @ejb.pk-field tag. Discussion
The result of using these tags is a source file named ItemBeanPK.java (containing the ItemBeanPK class). Listing 2.11 shows the generated code for this class. Listing 2.11 ItemBeanPK.java
/* * Generated by XDoclet - Do not edit! */ package ch2; /** * Primary key for ItemBean. */ public class ItemBeanPK extends java.lang.Object implements java.io.Serializable { private int _hashCode = Integer.MIN_VALUE; private StringBuffer _toStringValue = null; public java.lang.String iD; public ItemBeanPK() { } public ItemBeanPK( java.lang.String iD ) { this.iD = iD; } Generating a primary key class
public java.lang.String getID() { return iD; } public void setID(java.lang.String iD) { this.iD = iD; _hashCode = Integer.MIN_VALUE; } public int hashCode() { if( _hashCode == Integer.MIN_VALUE ) { if (this.iD != null) _hashCode += this.iD.hashCode(); } return _hashCode; } public boolean equals(Object obj) { if( !(obj instanceof ch2.ItemBeanPK) ) return false; ch2.ItemBeanPK pk = (ch2.ItemBeanPK)obj; boolean eq = true; if( obj == null ) { eq = false; } else { if( this.iD == null && ((ch2.ItemBeanPK)obj).getID() == null ) { eq = true; } else { if( this.iD == null || ((ch2.ItemBeanPK)obj).getID() == null ) { eq = false; } else { eq = eq && this.iD.equals( pk.iD ); } } } Code generation with XDoclet
return eq; } /** @return String representation of this pk in the form of [.field1.field2.field3]. */ public String toString() { if( _toStringValue == null ) { _toStringValue = new StringBuffer("[."); _toStringValue.append(this.iD).append('.'); _toStringValue.append(']'); } return _toStringValue.toString(); } } The generated primary key class contains a default constructor, an initialization constructor that accepts a String ID parameter, a getter method, a setter method, hashcode() and equals() methods, and a toString() method. If you use the @ejb.pk tag without using the @ejb.pk-field tag, you generate a primary key file without the getter, setter, and initialization constructor. See also
2.1 Generating home, remote, local, and local home interfaces
2.6 Avoiding hardcoded XDoclet tag values
Problem
You would like to centralize values in one place and not have to modify source files in order to update the values. Background
XDoclet is a great tool for generating necessary EJB files. In addition, it lets you specify values for the XML deployment descriptor and JNDI names for your beans. Using XDoclet with your development lets you automate and generate almost everything you need. However, as you add more XDoclet JavaDoc tags to your source files, you are specifying more values in code for things like JNDI names and bean names. Now you have many values spread out across many bean source files.
|
|