public void invalidateFromCache()
{
}
public void ejbHomeInvalidateCompleteOrders(Collection/*<orderlocal>*/ orders) { Iterator iter = orders.iterator(); while(iter.hasNext()) { OrderLocal order = (OrderLocal)iter.next(); // this just adds the option A bean to this transaction so that when we rollback below // it gets discarded, i.e. removed from the cache. order.invalidateFromCache(); } myEntityCtx.setRollbackOnly(); }
BookLocal book = ivBookHome.findByPrimaryKey(ivOrder.getSymbol()); Collection/*<OrderKey>*/ completedOrders = book.acceptOrder(session, pub, ivOrder, cache); // invalidate all completed orders from the CMP option A cache. try { if(!completedOrders.isEmpty()) ivOrderHome.invalidateCompleteOrders(completedOrders); } catch(Exception e) { // ignore expected exception }
public Collection/*<OrderLocal>*/ acceptOrder(…) Collection completeOrders = new LinkedList(); OrderLocal buyer = ...; OrderLocal seller = ...; ... some business logic.... if(buyer.getIsComplete()) completeOrders.add(buyer); if(seller.getIsComplete()) completeOrders.add(seller); … return completedOrders; }
このコードは、キャッシュされたオブジェクトのうち処理が完了しているものを除去するアプリケーションの例を示しています。アプリケーションが除去を実行しないと、キャッシュには、役立つインスタンスと役に立たないインスタンスの両方が混在することになります。役立つインスタンスとは、まだアプリケーションで必要なレコード、あるいは保留中または未完了のレコードのことです。 完了済みレコードをキャッシュしておく必要はありません。アプリケーションは、このアプローチを使用して完了済みオブジェクトを除去することができます。
Related concepts
区画固有の CMP データ