read.setDataObjectModel(helper.getType(DataGraphRoot.class));
read.setParameterValue("PURCHASELOTNUMBER", purchaseLotNumber);// autoboxing :-)
DataGraphRoot root = (DataGraphRoot) read.executeQuery();
List stocks = root.getStockSummaries();
if (null != stocks && !stocks.isEmpty()) {
StockSummary stock = (StockSummary) stocks.get(0);
int newQuatity = Math.max(stock.getQuantity() - quantity, 0);
if (newQuatity < 1) {
Command delete = Command.FACTORY.createCommand("DELETE FROM STOCKS WHERE PURCHASELOTNUMBER = ?");
delete.setParameterValue(1, purchaseLotNumber);
delete.setConnection(getConnection());
delete.execute();
} else {
Command update = commandGroup.getCommand("stockbylot");
update.setParameterValue("QUANTITY", newQuatity);
update.setParameterValue("PURCHASELOTNUMBER", purchaseLotNumber);
update.execute();
stock.setQuantity(newQuatity);
}
}
return null;