return query.getResultList();
}
public QuoteDataBean updateQuotePriceVolume(String symbol, BigDecimal changeFactor, double sharesTraded) throws Exception {
if (!TradeConfig.getUpdateQuotePrices()) {
return new QuoteDataBeanImpl();
}
if (Log.doTrace())
Log.trace("TradeJpaCm:updateQuote", symbol, changeFactor);
/*
* Add logic to determine JPA layer, because JBoss5' Hibernate 3.3.1GA
* DB2Dialect and MySQL5Dialect do not work with annotated query
* "quoteejb.quoteForUpdate" defined in QuoteDataBeanImpl
*/
QuoteDataBeanImpl quote = null;
if (TradeConfig.jpaLayer == TradeConfig.HIBERNATE) {
quote = entityManager.find(QuoteDataBeanImpl.class, symbol);
} else if (TradeConfig.jpaLayer == TradeConfig.OPENJPA) {
Query q = entityManager.createNamedQuery("quoteejb.quoteForUpdate");
q.setParameter(1, symbol);
quote = (QuoteDataBeanImpl) q.getSingleResult();
}
BigDecimal oldPrice = quote.getPrice();
if (quote.getPrice().equals(TradeConfig.PENNY_STOCK_PRICE)) {
changeFactor = TradeConfig.PENNY_STOCK_RECOVERY_MIRACLE_MULTIPLIER;
}
BigDecimal newPrice = changeFactor.multiply(oldPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
quote.setPrice(newPrice);
quote.setVolume(quote.getVolume() + sharesTraded);
quote.setChange((newPrice.subtract(quote.getOpen()).doubleValue()));
if (newPrice.compareTo(quote.getHigh()) == 1) quote.setHigh(newPrice);
else if (newPrice.compareTo(quote.getLow()) == -1) quote.setLow(newPrice);
entityManager.merge(quote);
this.publishQuotePriceChange(quote, oldPrice, changeFactor, sharesTraded);