| Next >

Lesson 3: Examining the generated interface InventoryLevelsData

The InventoryLevelsData interface is a reusable Java object that different applications can use for querying and updating the INVENTORY_LEVELS table.
This lesson details the content of this interface.

To view the InventoryLevelsData interface that you generated:

  1. Go to the InventoryLevelsData.java tab in the middle pane
  2. View the sections of the class. The class 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. Notice these two import statements:
    import com.ibm.pdq.annotation.Select;
    import com.ibm.pdq.annotation.Update;
    @Select and @Update are two annotations that pureQuery uses in this interface. You'll see how shortly.
    Annotated methods
    When you completed the Generate pureQuery Code from a Table wizard in Lesson 1, you specified for pureQuery to generate all of the SQL statements that it could. Therefore the interface contains nine SQL statements and declares nine methods. Each method is annotated with either a SELECT, INSERT, UPDATE, or DELETE statement:
    Methods that are annotated with SELECT statements
    The following methods use @Select annotations.
    • The getInventoryLevelss() method
      The getInventoryLevelss() method returns an iterator of the Inventory Levels bean
      	// Select all GOSALES.INVENTORY_LEVELSs
      	@Select(sql = "SELECT INVENTORY_YEAR, INVENTORY_MONTH, WAREHOUSE_BRANCH_CODE,"
      	               + "  PRODUCT_NUMBER, OPENING_INVENTORY, QUANTITY_SHIPPED, ADDITIONS,"
      	               + "  UNIT_COST, CLOSING_INVENTORY, AVERAGE_UNIT_COST"
      	               + "  FROM GOSALES.INVENTORY_LEVELS")
      	Iterator<InventoryLevels> getInventoryLevelss();
      Notice that the annotation is named @Select and it contains an sql attribute. When you use a SELECT statement, put the statement in the sql attribute of this annotation.
      Tip: When naming the method, pureQuery prefixes the name of the bean with get. It also automatically adds an S because the method returns all of the possible InventoryLevels beans. So, the extra S in getInventoryLevelss() is not a typo. It indicates the plural of Inventory_level bean.
    • The getInventoryLevels() method takes individual fields for a WHERE clause in the SELECT statement
      	// Select GOSALES.INVENTORY_LEVELS by parameters
      	@Select(sql = "SELECT INVENTORY_YEAR, INVENTORY_MONTH, WAREHOUSE_BRANCH_CODE,"
      	               + "  PRODUCT_NUMBER, OPENING_INVENTORY, QUANTITY_SHIPPED, ADDITIONS,"
      	               + "  UNIT_COST, CLOSING_INVENTORY, AVERAGE_UNIT_COST"
      	               + "  FROM GOSALES.INVENTORY_LEVELS"
      	               + "  WHERE INVENTORY_YEAR = ? AND INVENTORY_MONTH = ? AND WAREHOUSE_BRANCH_CODE = ?"
      	               + "    AND PRODUCT_NUMBER = ?")
      	InventoryLevels getInventoryLevels(short inventoryYear,
      			short inventoryMonth, int warehouseBranchCode, int productNumber);
      This method lets you pass individual fields for each of the columns that comprise the primary key and are listed in the WHERE clause. It returns a single InventoryLevels bean with the results.
    • The getInventoryLevels() method takes an instance of the InventoryLevels bean as a parameter
      	// Select GOSALES.INVENTORY_LEVELS by InventoryLevels object
      	@Select(sql = "SELECT INVENTORY_YEAR, INVENTORY_MONTH, WAREHOUSE_BRANCH_CODE,"
      	               + "  PRODUCT_NUMBER, OPENING_INVENTORY, QUANTITY_SHIPPED, ADDITIONS,"
      	               + "  UNIT_COST, CLOSING_INVENTORY, AVERAGE_UNIT_COST"
      	               + "  FROM GOSALES.INVENTORY_LEVELS"
      	               + "  WHERE INVENTORY_YEAR = :inventoryYear AND INVENTORY_MONTH = :inventoryMonth"
      	               + "    AND WAREHOUSE_BRANCH_CODE = :warehouseBranchCode"
      	               + "    AND PRODUCT_NUMBER = :productNumber")
      	InventoryLevels getInventoryLevels(InventoryLevels i);
      This method lets you pass an InventoryLevels bean that contains the values of the primary key columns that are in the WHERE clause. It returns a single InventoryLevels bean with the results.
    Methods that are annotated with INSERT statements
    The following methods use @Update annotations.
    • The createInventoryLevels method takes individual fields
      	// Create GOSALES.INVENTORY_LEVELS by parameters
      	@Update(sql = "INSERT INTO GOSALES.INVENTORY_LEVELS (INVENTORY_YEAR, INVENTORY_MONTH,"
      	               + "  WAREHOUSE_BRANCH_CODE, PRODUCT_NUMBER, OPENING_INVENTORY, QUANTITY_SHIPPED,"
      	               + "  ADDITIONS, UNIT_COST, CLOSING_INVENTORY, AVERAGE_UNIT_COST)"
      	               + "  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
      	int createInventoryLevels(short inventoryYear, short inventoryMonth,
      			int warehouseBranchCode, int productNumber, int openingInventory,
      			int quantityShipped, int additions, BigDecimal unitCost,
      			int closingInventory, BigDecimal averageUnitCost);
      This method lets you pass individual fields for all of the columns in the row that you want to insert. It returns a value of 1 if the insert is successful or a value of 0 if the insert fails.
    • The createInventoryLevels() method takes an instance of the InventoryLevels bean
      	// Create GOSALES.INVENTORY_LEVELS by InventoryLevels Object
      	@Update(sql = "INSERT INTO GOSALES.INVENTORY_LEVELS (INVENTORY_YEAR, INVENTORY_MONTH,"
      	               + "  WAREHOUSE_BRANCH_CODE, PRODUCT_NUMBER, OPENING_INVENTORY, QUANTITY_SHIPPED,"
      	               + "  ADDITIONS, UNIT_COST, CLOSING_INVENTORY, AVERAGE_UNIT_COST)"
      	               + "  VALUES (:inventoryYear, :inventoryMonth, :warehouseBranchCode,"
      	               + "    :productNumber, :openingInventory, :quantityShipped, :additions,"
      	               + "    :unitCost, :closingInventory, :averageUnitCost)")
      	int createInventoryLevels(InventoryLevels i);
      This method lets you pass an InventoryLevels bean that contains the values of the columns that are in the row that you want to insert. It returns a value of 1 if the insert is successful or a value of 0 if the insert fails.
    Methods that are annotated with UPDATE statements
    The following methods use @Update annotations.
    • The updateInventoryLevels() method takes individual fields
      	// Update GOSALES.INVENTORY_LEVELS by parameters
      	@Update(sql = "UPDATE GOSALES.INVENTORY_LEVELS"
      	               + "  SET INVENTORY_YEAR = ?, INVENTORY_MONTH = ?, WAREHOUSE_BRANCH_CODE = ?,"
      	               + "      PRODUCT_NUMBER = ?, OPENING_INVENTORY = ?, QUANTITY_SHIPPED = ?,"
      	               + "      ADDITIONS = ?, UNIT_COST = ?, CLOSING_INVENTORY = ?, AVERAGE_UNIT_COST = ?"
      	               + "  WHERE INVENTORY_YEAR = ? AND INVENTORY_MONTH = ? AND WAREHOUSE_BRANCH_CODE = ?"
      	               + "    AND PRODUCT_NUMBER = ?")
      	int updateInventoryLevels(short inventoryYear, short inventoryMonth,
      			int warehouseBranchCode, int productNumber, int openingInventory,
      			int quantityShipped, int additions, BigDecimal unitCost,
      			int closingInventory, BigDecimal averageUnitCost,
      			short inventoryYear_K, short inventoryMonth_K,
      			int warehouseBranchCode_K, int productNumber_K);
      This method lets you pass individual fields for all of the columns in the row that you want to update. It returns a value of 1 if the update is successful or a value of 0 if the update fails.
    • The updateInventoryLevels() method takes an instance of the InventoryLevels bean
      	// Update one GOSALES.INVENTORY_LEVELS by InventoryLevels object
      	@Update(sql = "UPDATE GOSALES.INVENTORY_LEVELS"
      	               + "  SET OPENING_INVENTORY = :openingInventory, QUANTITY_SHIPPED = :quantityShipped,"
      	               + "      ADDITIONS = :additions, UNIT_COST = :unitCost, CLOSING_INVENTORY = :closingInventory,"
      	               + "      AVERAGE_UNIT_COST = :averageUnitCost"
      	               + "  WHERE INVENTORY_YEAR = :inventoryYear AND INVENTORY_MONTH = :inventoryMonth"
      	               + "    AND WAREHOUSE_BRANCH_CODE = :warehouseBranchCode"
      	               + "    AND PRODUCT_NUMBER = :productNumber")
      	int updateInventoryLevels(InventoryLevels i);
      This method lets you pass an InventoryLevels bean that contains the values of the columns that are in the row that you want to update. It returns a value of 1 if the update is successful or a value of 0 if the update fails.
    Methods that are annotated with DELETE statements
    The following methods use @Update annotations.
    • The deleteInventoryLevels() method takes individual fields
      	// Delete GOSALES.INVENTORY_LEVELS by parameters
      	@Update(sql = "DELETE FROM GOSALES.INVENTORY_LEVELS"
      	               + " WHERE INVENTORY_YEAR = ? AND INVENTORY_MONTH = ? AND WAREHOUSE_BRANCH_CODE = ?"
      	               + "    AND PRODUCT_NUMBER = ?")
      	int deleteInventoryLevels(short inventoryYear, short inventoryMonth,
      			int warehouseBranchCode, int productNumber);
      This method lets you pass individual fields for all of the primary key columns in the row that you want to delete. It returns a value of 1 if the delete is successful or a value of 0 if the delete fails.
    • The deleteInventoryLevels() method takes an instance of the InventoryLevels bean
      	// Delete one GOSALES.INVENTORY_LEVELS by InventoryLevels object
      	@Update(sql = "DELETE FROM GOSALES.INVENTORY_LEVELS"
      	               + " WHERE INVENTORY_YEAR = :inventoryYear AND INVENTORY_MONTH = :inventoryMonth"
      	               + "    AND WAREHOUSE_BRANCH_CODE = :warehouseBranchCode"
      	               + "    AND PRODUCT_NUMBER = :productNumber")
      	int deleteInventoryLevels(InventoryLevels i);
      This method lets you pass an InventoryLevels bean that contains the values of the primary key columns that are in the row that you want to delete. It returns a value of 1 if the delete is successful or a value of 0 if the delete fails.
You can edit the SQL statements and add or remove methods. In a later lesson, you will learn about features that make editing and testing SQL statements easy.
| Next >

Feedback