Wrox Programmer Forums
|
BOOK: Beginning Spring Framework 2 ISBN: 978-0-470-10161-2
This is the forum to discuss the Wrox book Beginning Spring Framework 2 by Thomas Van de Velde, Bruce Snyder, Christian Dupuis, Sing Li, Anne Horton, Naveen Balani; ISBN: 9780470101612
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Spring Framework 2 ISBN: 978-0-470-10161-2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2009, 09:25 AM
tok tok is offline
Registered User
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error in Chapter 12, AOP code?

I can't get the idea of the AOP example code in page 367.

Code:
public PixUser lookup(ProceedingJoinPoint call, String userName) {
  log.debug(“Advising method: ‚“ +   call.getSignature().toShortString());
  PixUser user = (PixUser) cache.get(userName);
  if (user != null) {
    user = call.proceed();
  }
  cache.put(user.getUserName());
  return user;
}
I presume the idea is first look the cache for the user object by userName and if not found there, fetch user with the target method and put it in the cache. To me it seem this code does the opposite: if the user IS FOUND in the cache (user != null) then the target method is called (call.procees()) and user is fetched from the database. And regardless of the user was in the cache or not, it is put there again.

Instead, shouldn't it be like this

Code:
  PixUser user = (PixUser) cache.get(userName);
  if (user == null) {
    user = call.proceed();
    cache.put(user.getUserName());
  }
  return user;
Or did I understand it all wrong?





Similar Threads
Thread Thread Starter Forum Replies Last Post
aop source code missing ccp2p BOOK: Beginning Spring Framework 2 ISBN: 978-0-470-10161-2 0 March 7th, 2008 11:50 AM
Chapter 12 Code Behind Problem locknload7 BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 March 30th, 2005 10:34 AM
Chapter 12 code error rsteph7 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 34 August 18th, 2004 01:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.