InitialContext ctx = new InitialContext();
t = (UserTransaction) ctx.lookup("UserTransaction");
t.begin();
EntityManager em = (EntityManager) Component.getInstance("entityManager", true);
List<Auction> auctions = em.createQuery("select a from Auction a").getResultList();
Calendar cal = new GregorianCalendar();
Random r = new Random(System.currentTimeMillis());
for (Auction auction : auctions)
{
cal.setTime(auction.getEndDate());
cal.add(Calendar.DATE, r.nextInt(7));
cal.add(Calendar.MINUTE, 30 + r.nextInt(1410));
auction.setEndDate(cal.getTime());
auction.setStatus(Auction.STATUS_COMPLETED);
em.merge(auction);
AuctionEndAction auctionEnd = (AuctionEndAction) Component.getInstance(AuctionEndAction.class, true);
auctionEnd.endAuction(auction.getAuctionId(), auction.getEndDate());
}