< 前へ

演習 2: 生成された Bean InventoryLevels を調べる

InventoryLevels Bean は、INVENTORY_LEVELS 表にアクセスするために他のアプリケーションでも使用できる再使用可能な Java オブジェクトです。
この演習では、pureQuery 固有の要素を含む Bean のセクションについて説明します。

InventoryLevels Bean を表示するには、以下のようにします。

  1. 中ほどのペインにある InventoryLevels.java タブに移動します。
  2. Bean のセクションを表示します。 Bean には以下のセクションがあります。
    標準 Java セクション
    最初のセクションは、Java クラスの標準のセクションです。 このセクションは、クラスが所属する Java パッケージを宣言し、クラスについて説明するコメントを含み、他のパッケージからクラスをインポートし、クラスの開始を宣言します。しかし、以下に示す 3 つの import ステートメントがあることに注意してください。
    import com.ibm.pdq.annotation.Table;
    import com.ibm.pdq.annotation.Id;
    import com.ibm.pdq.annotation.Column;
    @Table、@Id、および @Column は pureQuery がこの Bean で使用するアノテーションです。Bean の後のセクションで、さらに詳しく説明します。
    @Table アノテーション
    pureQuery は次に @Table アノテーションを使用して、Bean が表す表を示します。pureQuery は生成した Bean でのみこのアノテーションを使用します。独自の Bean を書くときには、@Table を使用する必要はありません。
    @Table(name = "INVENTORY_LEVELS", schema = "GOSALES")
    public class InventoryLevels {
    フィールドの宣言
    フィールドはすべて protected 有効範囲で宣言されます。これは「表からの pureQuery コードの生成」ウィザードで指定した結果です。
    	// Class variables
    	protected short inventoryYear;
    	protected short inventoryMonth;
    	protected int warehouseBranchCode;
    	protected int productNumber;
    	protected int openingInventory;
    	protected int quantityShipped;
    	protected int additions;
    	protected BigDecimal unitCost;
    	protected int closingInventory;
    	protected BigDecimal averageUnitCost;
    コンストラクターの宣言
    Bean のフィールドを宣言した後、コードでは 2 つのコンストラクターが宣言されます。最初のコンストラクターは、空の Bean を作成するためのものです。2 番目のコンストラクターは、フィールドの値が設定された Bean を作成するためのものです。
    	/**
    	 * Constructor for InventoryLevels.
    	 */
    	public InventoryLevels() {
    		super();
    	}
    
    	/**
    	 * Constructor for InventoryLevels that sets all fields.
    	 */
    	public InventoryLevels(short inventoryYear, short inventoryMonth,
    			int warehouseBranchCode, int productNumber, int openingInventory,
    			int quantityShipped, int additions, BigDecimal unitCost,
    			int closingInventory, BigDecimal averageUnitCost) {
    		super();
    		this.inventoryYear = inventoryYear;
    		this.inventoryMonth = inventoryMonth;
    		this.warehouseBranchCode = warehouseBranchCode;
    		this.productNumber = productNumber;
    		this.openingInventory = openingInventory;
    		this.quantityShipped = quantityShipped;
    		this.additions = additions;
    		this.unitCost = unitCost;
    		this.closingInventory = closingInventory;
    		this.averageUnitCost = averageUnitCost;
    	}
    それぞれのフィールドの get() メソッドおよび set() メソッド
    pureQuery は @Id アノテーションを使用して表の主キー列にマップするそれぞれのフィールドを指定します。ただし、pureQuery は生成した Bean でのみこのアノテーションを使用します。独自の Bean を書くときには、@Id を使用する必要はありません。
    フィールド名はキャメル・ケースで下線は使用されていないので、pureQuery は @Column アノテーションを get() メソッドで使用してそれぞれの表列の名前を対応するフィールドにマップします。@Column アノテーションを使用する状況については「Bean のアノテーション」をご覧ください。そこでは使用できる他のアノテーションについても説明されています。また、pureQuery の Javadoc の「@Column」も参照してください。
    	/**
    	 * Get inventoryYear.
    	 * 
    	 * @return return inventoryYear
    	 */
    	@Id
    	@Column(name = "INVENTORY_YEAR")
    	public short getInventoryYear() {
    		return inventoryYear;
    	}
    
    	/**
    	 * Set inventoryYear.
    	 * 
    	 * @param short inventoryYear
    	 */
    	@Id
    	public void setInventoryYear(short inventoryYear) {
    		this.inventoryYear = inventoryYear;
    	}
< 前へ

フィードバック