Java Reference
In-Depth Information
loaded, the existing one (from the maps) replaces the one that was just loaded
from the database.
Finally, after it has gotten the single instance of a particular account, manufac-
turer, or product, it adds them to the appropriate objects, as shown in listing 6.3.
Listing 6.3
A very powerful row handler
public class AMPRowHandler implements RowHandler {
private Map<Integer, AccountManufacturers> accountMap
= new HashMap<Integer, AccountManufacturers>();
private Map<Integer, Manufacturer> manufacturerMap
= new HashMap<Integer, Manufacturer>();
private Map<Integer, ProductAccounts> productMap
= new HashMap<Integer, ProductAccounts>();
private List<ProductAccounts> productAccountList
= new ArrayList<ProductAccounts>();
private List<AccountManufacturers> accountManufacturerList
= new ArrayList<AccountManufacturers>();
public void handleRow(Object valueObject) {
AccountManufacturerProduct amp;
amp = (AccountManufacturerProduct)valueObject;
Account currentAccount = amp.getAccount();
Manufacturer currentMfgr = amp.getManufacturer();
AccountManufacturers am;
ProductAccounts pa;
Product currentProduct = amp.getProduct();
if (null == accountMap.get(currentAccount.getAccountId())) {
// this is the first time we have seen this account
am = new AccountManufacturers();
am.setAccount(currentAccount);
accountMap.put(currentAccount.getAccountId(), am);
accountManufacturerList.add(am);
} else {
// Use the accoutn from the account map
am = accountMap.get(currentAccount.getAccountId());
currentAccount = am.getAccount();
}
// am is now the current account / manufacturerlist
Contains only
required method
B
duplicate accounts C
Checks for
if (null ==
manufacturerMap.get(currentMfgr.getManufacturerId())) {
// we have not seen this manufacturer yet
manufacturerMap.put(
currentMfgr.getManufacturerId(),
currentMfgr);
} else {
// we already have this manufacturer loaded, reuse it
currentMfgr = manufacturerMap.get(
Checks for duplicate
manufacturers D
Search WWH ::




Custom Search