< Previous

Lesson 2: Examining the generated bean InventoryLevels

The InventoryLevels bean is a reusable Java object that different applications can use for accessing the INVENTORY_LEVELS table.
This lesson shows you the sections of the bean that contain elements that are specific to pureQuery.

To view the InventoryLevels bean:

  1. Go to the InventoryLevels.java tab in the middle pane.
  2. View the sections of the bean. The bean has the following sections:
    Standard Java Section
    The first section is standard for a Java class. It declares the Java package that the class belongs to, contains a comment that describes the class, imports classes from other packages, and declares that start of the class. However, notice these three import statements:
    import com.ibm.pdq.annotation.Table;
    import com.ibm.pdq.annotation.Id;
    import com.ibm.pdq.annotation.Column;
    @Table, @Id, and @Column are annotations that pureQuery uses in this bean. You will see how in a later section of the bean.
    @Table annotation
    pureQuery next uses the @Table annotation to identify the table that the bean represents. pureQuery uses this annotation only in generated beans. When you write your own beans, you do not need to use @Table.
    @Table(name = "INVENTORY_LEVELS", schema = "GOSALES")
    public class InventoryLevels {
    Declaration of the fields
    The fields are all declared with protected scope, which you specified in the Generate pureQuery Code from a Table wizard.
    	// 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;
    Declaration of the constructors
    After declaring the fields of the bean, the code declares two constructors. The first constructor is for creating empty beans. The second constructor is for creating beans with values for the fields.
    	/**
    	 * 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() and set() methods for each field
    pureQuery uses an @Id annotation to identify each field that maps to a primary key column in the table. However, pureQuery uses this annotation only in generated beans. When you write your own beans, you do not need to use @Id.
    Because the field names are in camel case and do not use underscores, pureQuery uses an @Column annotation on get() methods to map the name of each table column to its corresponding field. For documentation about when to use the @Column annotation, see Annotations in beans, which also describes other annotations that you can use. You can also refer to @Column in the pureQuery Javadoc.
    	/**
    	 * 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;
    	}
< Previous

Feedback