Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Java Tools for Extreme programming mastering open source tools including - Hightower R.

Hightower R. Java Tools for Extreme programming mastering open source tools including - Wiley publishing , 2002. - 417 p.
ISBN: 0-471-20708
Download (direct link): javatoolsforextremeprog2002.pdf
Previous << 1 .. 17 18 19 20 21 22 < 23 > 24 25 26 27 28 29 .. 159 >> Next

Notice from the DDL in the createTables target that there are primary key constraints; thus the tables must be dropped in the order specified here.
Complete Listings
The complete code for the pet store case study can be downloaded from www.wiley.com/compbooks/hightower.
Model Package Complete Listings
The model (Listings 3.4 through 3.8) is the business interface for the system. It is the fa3ade covering the rest of the systems. Most of the tests can be run against the model classes.
Listing 3.4: CategorySystem.
package xptoolkit.petstore.model;
public class CategorySystem { private Category currentCategory; private Subcategory currentSubcategory; private Product currentProduct;
public CategorySystem() throws Exception { currentCategory = Category.getCategory(); currentCategory.setId(777);
46
}
public Category getCurrentCategory() { return currentCategory;
}
public Subcategory getCurrentSubcategory() { return currentSubcategory;
}
public Product getCurrentProduct() { return currentProduct;
}
public Subcategory getSubcategory(int id) throws Exception { currentSubcategory = currentCategory.getSubcategory(id); return currentSubcategory;
}
public Product getProduct(int id) throws Exception { currentProduct = currentSubcategory.getProduct(id); return currentProduct;
}
}
Listing 3.5: Category.
package xptoolkit.petstore.model;
import java.util.*;
public abstract class Category extends Catalogltem {
47
protected Subcategory[] subcategories;
public static Category getCategory() throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
String className = System.getProperty("xptoolkit.petstore.category.class", "xptoolkit.petstore.dbmodel.CategoryDB");
Class categoryClass = Class.forName(className); return (Category)categoryClass.newInstance();
}
public Subcategory[] getSubcategories() throws Exception { return subcategories;
}
public abstract Subcategory getSubcategory(int id) throws Exception;
public String toString() { return "Category [ " + super.toString() +
"]";
}
}
Listing 3.6: CatalogItem.
package xptoolkit.petstore.model;
public abstract class CatalogItem {
48
protected int id;
protected String name;
protected String description;
public int getld() { return id;
}
public void setld(int id) throws Exception { this.id = id;
}
public String getName() { return name;
}
public void setName(String name) { this.name = name;
}
public String getDescription() { return description;
}
public void setDescription(String description) { this.description = description;
}
public String toString() { return "" + id + ", " + name + ", " + description;
}
}
49
Listing 3.7: Subcategory.
package xptoolkit.petstore.model;
public abstract class Subcategory extends Catalogltem {
protected int fkCategoryld;
protected Product[] products;
public int getFkCategoryId() throws Exception { return fkCategoryld;
}
public void setFkCategoryld(int fkCategoryld) { this.fkCategoryld = fkCategoryld;;
}
public Product[] getProducts() throws Exception { return products;
}
public abstract Product getProduct(int id) throws Exception;
public String toString() { return "Subcategory [ " + super.toString() + ", " + fkCategoryld +
"]";
}
}
Listing 3.8: Product.
50
package xptoolkit.petstore.model;
public abstract class Product extends CatalogItem {
protected int price;
protected int qty;
protected int fkSubcategoryId;
public int getPrice() { return price;
}
public void setPrice(int price) { this.price = price;
}
public int getQty() { return qty;
}
public void setQty(int qty) { this.qty = qty;
}
public int getFkSubcategoryId() { return fkSubcategoryId;
}
public void setFkSubcategoryId(int fkSubcategoryId) { this.fkSubcategoryId = fkSubcategoryId;
}
51
public String toString() { return "Product [ " + super.toString() + ", " + price + ", " + qty + ", " + fkSubcategoryId +
"]";
}
}
dbmodel Package Complete Listings
The dbmodel package (Listings 3.9 through 3.12) is the implementation of the model. It uses JDBC to get rows out of the database and converts them to Java objects that can be manipulated by the JSPs.
Listing 3.9: CategoryDB.
package xptoolkit.petstore.dbmodel;
import xptoolkit.petstore.model.Category; import xptoolkit.petstore.model.Subcategory; import xptoolkit.petstore.model.Product; import java.sql.*; import java.util.ArrayList; import java.util.HashMap; import java.util.Map;
public class CategoryDB extends Category implements Entity {
public static final String COLUMNS = "ID, NAME, DESCRIPTION";
private static Connection connCategory; private static Connection connSubcategory; private static PreparedStatement prepLoadCategory; private static PreparedStatement prepLoadSubcategories;
52
boolean loaded = false;
static
{
try {
String load = "select " + COLUMNS + " from CATEGORY where ID = ? "; connCategory = InitPackage.getConnection(); prepLoadCategory = connCategory.prepareStatement(load);
load = "select " + SubcategoryDB.COLUMNS + " from SUBCATEGORY where FK_CATEGORY_ID = ?"; connSubcategory = InitPackage.getConnection(); prepLoadSubcategories =
Previous << 1 .. 17 18 19 20 21 22 < 23 > 24 25 26 27 28 29 .. 159 >> Next