Although you can modify the handler class directly in the implementation class, in some situations it is more convenient to edit the handler class by itself.
With the Create Handler Classes for Interface wizard, you can separate handler classes from the implementation classes in which the workbench generated them. The workbench creates those handler classes in new files. The workbench also adds @Handler annotations to the interfaces.
To create a handler classes from an implementation class and place it in a separate file:
@Select(sql = "SELECT PRODUCT_NUMBER, BASE_PRODUCT_NUMBER, INTRODUCTION_DATE," + " DISCONTINUED_DATE, PRODUCT_TYPE_CODE, PRODUCT_COLOR_CODE, PRODUCT_SIZE_CODE," + " PRODUCT_BRAND_CODE, PRODUCTION_COST, GROSS_MARGIN, PRODUCT_IMAGE" + " FROM GOSALES.PRODUCT") Iterator<Product> getProducts();
The implementation class for the interface contains an @generated tag and the following handler class for this method:
public static class GetProductsRowHandler extends BaseRowHandler<Product> { public Product handle (java.sql.ResultSet rs, Product returnObject) throws java.sql.SQLException { returnObject = new Product (); returnObject.setProduct_number(getInt (rs, 1)); returnObject.setBase_product_number(getInt (rs, 2)); returnObject.setIntroduction_date(getTimestamp (rs, 3)); returnObject.setDiscontinued_date(getTimestamp (rs, 4)); returnObject.setProduct_type_code(getInt (rs, 5)); returnObject.setProduct_color_code(getInt (rs, 6)); returnObject.setProduct_size_code(getInt (rs, 7)); returnObject.setProduct_brand_code(getInt (rs, 8)); returnObject.setProduction_cost(getBigDecimal (rs, 9)); returnObject.setGross_margin(getDouble (rs, 10)); returnObject.setProduct_image(getString (rs, 11)); return returnObject; } }
After you use the Create Handler Classes for Interface wizard, the workbench creates the file GetProductsRowHandler.java to contain the handler class. The workbench also regenerates the implementation class without the handler class. You can edit the handler class directly, without having to open the implementation class for editing.
In the interface, the method now has an @Handler annotation.
@Handler(rowHandler=aforementioned.GetProductsRowHandler.class) @Select(sql = "SELECT PRODUCT_NUMBER, BASE_PRODUCT_NUMBER, INTRODUCTION_DATE," + " DISCONTINUED_DATE, PRODUCT_TYPE_CODE, PRODUCT_COLOR_CODE, PRODUCT_SIZE_CODE," + " PRODUCT_BRAND_CODE, PRODUCTION_COST, GROSS_MARGIN, PRODUCT_IMAGE" + " FROM GOSALES.PRODUCT") Iterator<Product> getProducts();