Book.java
01 /**
02  *Copyright (c) 2006 by BEA Systems, Inc. All Rights Reserved.
03  */
04 
05 package examples.ejb.ejb30.domain;
06 
07 import javax.persistence.*;
08 
09 /** 
10  *  Book is a kind of Item. 
11  *  The target table for Book is decided by the inheritance strategey 
12  *  specified in its {@link examples.ejb.ejb30.domain.Item superclass}. In this 
13  *  case, <code>SINGLE_TABLE</code>
14  *  inheritance is used -- that stores all subclasses of Item including
15  *  Book to a single table. <BR>
16  *  Hence it is required to discriminate the records of Book from records
17  *  of other types. The <code>@DiscriminatorValue</code> annotation specifies 
18  *  that
19  *  all records of Book will carry the value <code>"BOOK"</code> in the
20  *  <code>@DiscriminatorColumn</code> specified with the 
21  *  {@link Item inheritance strategy}
22  */
23 
24 @Entity
25 @DiscriminatorValue(value = "BOOK")
26 public class Book
27   extends Item
28 {
29   @Column(name = "PAGE_COUNT")
30   private int pageCount;
31 
32   /** A no-arg constructor is required for enhancement.
33    
34    *
35    */
36   public Book ()
37   {
38     super ();
39   }
40 
41   /** The public constructor constructs with a title.
42    
43    @param title the title of the book.
44    */
45   public Book (String title)
46   {
47     super (title);
48   }
49 
50   /** 
51    * A single additional value to designate the number of pages in this
52    * book.
53    
54    @return the page count of the book.
55    */
56   public int getPageCount ()
57   {
58     return pageCount;
59   }
60 
61   /**
62    * Sets the page count of this receiver.
63    
64    @param d a non-negative number of pages.
65    */
66   public void setPageCount (int d)
67   {
68     if (d < 0)
69       throw new IllegalArgumentException ("Invalid page count " + d
70           " for " this);
71 
72     pageCount = d;
73   }
74 
75 }