[transfer-dev] Re: Unable to discard cached object, neither discard() nor discardByClassAndKey()

2009-01-28 Thread Jamie Krug

Also, my cache configuration looks like this:

objectCache
scopes
server key=transfer_myapp /
/scopes
defaultcache
scope type=server /
/defaultcache
/objectCache

Thanks,
Jamie

On Jan 28, 2:53 pm, Jamie Krug jamiek...@gmail.com wrote:
 Hi, all,

 I hope I'm missing something obvious, but I just can't peg it. I was
 purposely changing the key property of a Transfer object in a unit
 test object so I could test my validate() method (in my TO decorator).
 Suddenly a bunch of assertions that were successful started failing. I
 realized that I'm getting the cached version with the altered key
 field.

 For simplicity, assume I have a usstate table with a PK column named
 abbreviation-char(2) and column named statename-varchar(20). I have
 the 'abbreviation' column aliased as 'stateCode' as you can see in
 this transfer.xml snippet:

 package name=location
         object name=UsState table=usstate
 decorator=model.location.UsState
                 id name=stateCode type=string column=abbreviation /
                 property name=stateName type=string column=statename /
         /object
 /package

 When I get a state object with key 'NY' and change that key to
 '' (empty string), I can't seem to then discard this cached dirty
 object and access a fresh one from the database (unless I use the
 discardAll() method). I've tried discard() and I've tried
 discardByClassAndKey() with both the persisted key ('NY') and the
 dirty/changed one (''). Another get() for that object continues to
 return the dirty one, until I call discardAll() or restart the CF
 service.

 Here's my test code, with comments stating the output I'm seeing...

 transfer.discardAll();

 stateNY = transfer.get('location.UsState', 'NY');
 writeOutput(stateNY.getStateCode()  'br /'); //output is NY
 writeOutput(stateNY.getIsDirty()  'br /'); //output is false

 stateNY.setStateCode('');
 writeOutput(stateNY.getStateCode()  'br /'); //output is 
 writeOutput(stateNY.getIsDirty()  'br /'); //output is true

 transfer.discard(stateNY);
 writeOutput(stateNY.getStateCode()  'br /'); //output is 
 writeOutput(stateNY.getIsDirty()  'br /'); //output is true

 transfer.discardByClassAndKey('location.UsState', 'NY');
 writeOutput(stateNY.getStateCode()  'br /'); //output is 
 writeOutput(stateNY.getIsDirty()  'br /'); //output is true

 transfer.discardByClassAndKey('location.UsState', '');
 writeOutput(stateNY.getStateCode()  'br /'); //output is 
 writeOutput(stateNY.getIsDirty()  'br /'); //output is true

 Any thoughts would be much appreciated!

 Thanks!
 Jamie
--~--~-~--~~~---~--~~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer

You received this message because you are subscribed to the Google Groups 
transfer-dev group.
To post to this group, send email to transfer-dev@googlegroups.com
To unsubscribe from this group, send email to 
transfer-dev-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/transfer-dev?hl=en
-~--~~~~--~~--~--~---



[transfer-dev] Re: Unable to discard cached object, neither discard() nor discardByClassAndKey()

2009-01-28 Thread Jamie Krug

Bob,

Thanks for the quick reply! While your suggestion is absolutely
correct, it does not correct the problem I'm having. In fact, in my
actual unit test, I was indeed calling get() again after discard() (I
was calling get() in my setUp() method and discard() in my tearDown()
method, if you're familiar with MXUnit or similar) -- when I
translated this into a static test, for the sake of this post, I made
the mistake that you've picked up on. That said, after correcting it,
I'm still seeing unexpected results.

That said, your correction did allow me to try out another hunch, with
different results this time. When I use similar code, but change a non-
primary-key property, both discard() and discardByClassAndKey() work
exactly as expected! I guess if you change the value of any Transfer
object's ID (primary key) you can't discard the object from cache
without using discardAll(). Stranger still is the fact that I can call
get() with the ID value that's in the database, but then calling getID
() on that object returns a different value -- the dirty value!?!

I guess it's rather unusual to be calling a setter on your ID property
-- maybe wouldn't even occur in a production app, but just in my test
case scenario. So, would this be considered a bug or expected
behavior?

Here's some updated test code to demonstrate:

transfer.discardAll();

stateNY = transfer.get('location.UsState', 'NY');

writeOutput(stateNY.getStateName()  'br /'); //output is New
York (expected)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
false (expected)

stateNY.setStateName('');
writeOutput(stateNY.getStateName()  'br /'); //output is
 (expected)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
true (expected)

transfer.discard(stateNY);
stateNY = transfer.get('location.UsState', 'NY');
writeOutput(stateNY.getStateName()  'br /'); //output is New
York (expected)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
false (expected)

stateNY.setStateName('');
writeOutput(stateNY.getStateName()  'br /'); //output is
 (expected)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
true (expected)

transfer.discardByClassAndKey('location.UsState', 'NY');
stateNY = transfer.get('location.UsState', 'NY');
writeOutput(stateNY.getStateName()  'br /'); //output is New
York (expected)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
false (expected)

writeOutput(stateNY.getStateCode()  'br /'); //output is
NY (expected)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
false (expected)

stateNY.setStateCode('');
writeOutput(stateNY.getStateCode()  'br /'); //output is
 (expected)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
true (expected)

transfer.discard(stateNY);
stateNY = transfer.get('location.UsState', 'NY');
writeOutput(stateNY.getStateCode()  'br /'); //output is  (EXPECT
NY !?!)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
true (EXPECT false !?!)

transfer.discardByClassAndKey('location.UsState', 'NY');
stateNY = transfer.get('location.UsState', 'NY');
writeOutput(stateNY.getStateCode()  'br /'); //output is  (EXPECT
NY !?!)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
true (EXPECT false !?!)

transfer.discardByClassAndKey('location.UsState', '');
stateNY = transfer.get('location.UsState', 'NY');
writeOutput(stateNY.getStateCode()  'br /'); //output is  (EXPECT
NY !?!)
writeOutput(stateNY.getIsDirty()  'br /'); //output is
true (EXPECT false !?!)
/cfscript

Best,
Jamie

On Jan 28, 3:14 pm, Bob Silverberg bob.silverb...@gmail.com wrote:
 It looks like you're calling Transfer.discard(stateNY)  but then
 trying to use the stateNY object again, without issuing another get().
  So stateNY is still pointing at the same object, even though it isn't
 currently in the Transfer cache.

 If you think of it that way you'll see that your test results make
 perfect sense.

 I think perhaps what you want to do is call stateNY =
 transfer.get('location.UsState', 'NY'); again, after your discard, and
 then check the values of the object.

 Bob



 On Wed, Jan 28, 2009 at 2:53 PM, Jamie Krug jamiek...@gmail.com wrote:

  Hi, all,

  I hope I'm missing something obvious, but I just can't peg it. I was
  purposely changing the key property of a Transfer object in a unit
  test object so I could test my validate() method (in my TO decorator).
  Suddenly a bunch of assertions that were successful started failing. I
  realized that I'm getting the cached version with the altered key
  field.

  For simplicity, assume I have a usstate table with a PK column named
  abbreviation-char(2) and column named statename-varchar(20). I have
  the 'abbreviation' column aliased as 'stateCode' as you can see in
  this transfer.xml snippet:

  package name=location
         object name=UsState table=usstate
  decorator=model.location.UsState
                 id name=stateCode type=string column=abbreviation /
                 property name=stateName type=string column=statename 
  /
         /object
  /package

 

[transfer-dev] Re: Unable to discard cached object, neither discard() nor discardByClassAndKey()

2009-01-28 Thread Jamie Krug

Sounds fair! Thanks Mark, and Bob!

On Jan 28, 4:05 pm, Mark Mandel mark.man...@gmail.com wrote:
 Considering the primary key value is the unique identifier for the
 object... it is expected behaviour.

 Mark



 On Thu, Jan 29, 2009 at 7:56 AM, Jamie Krug jamiek...@gmail.com wrote:

  Bob,

  Thanks for the quick reply! While your suggestion is absolutely
  correct, it does not correct the problem I'm having. In fact, in my
  actual unit test, I was indeed calling get() again after discard() (I
  was calling get() in my setUp() method and discard() in my tearDown()
  method, if you're familiar with MXUnit or similar) -- when I
  translated this into a static test, for the sake of this post, I made
  the mistake that you've picked up on. That said, after correcting it,
  I'm still seeing unexpected results.

  That said, your correction did allow me to try out another hunch, with
  different results this time. When I use similar code, but change a non-
  primary-key property, both discard() and discardByClassAndKey() work
  exactly as expected! I guess if you change the value of any Transfer
  object's ID (primary key) you can't discard the object from cache
  without using discardAll(). Stranger still is the fact that I can call
  get() with the ID value that's in the database, but then calling getID
  () on that object returns a different value -- the dirty value!?!

  I guess it's rather unusual to be calling a setter on your ID property
  -- maybe wouldn't even occur in a production app, but just in my test
  case scenario. So, would this be considered a bug or expected
  behavior?

  Here's some updated test code to demonstrate:

  transfer.discardAll();

  stateNY = transfer.get('location.UsState', 'NY');

  writeOutput(stateNY.getStateName()  'br /'); //output is New
  York (expected)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  false (expected)

  stateNY.setStateName('');
  writeOutput(stateNY.getStateName()  'br /'); //output is
   (expected)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  true (expected)

  transfer.discard(stateNY);
  stateNY = transfer.get('location.UsState', 'NY');
  writeOutput(stateNY.getStateName()  'br /'); //output is New
  York (expected)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  false (expected)

  stateNY.setStateName('');
  writeOutput(stateNY.getStateName()  'br /'); //output is
   (expected)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  true (expected)

  transfer.discardByClassAndKey('location.UsState', 'NY');
  stateNY = transfer.get('location.UsState', 'NY');
  writeOutput(stateNY.getStateName()  'br /'); //output is New
  York (expected)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  false (expected)

  writeOutput(stateNY.getStateCode()  'br /'); //output is
  NY (expected)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  false (expected)

  stateNY.setStateCode('');
  writeOutput(stateNY.getStateCode()  'br /'); //output is
   (expected)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  true (expected)

  transfer.discard(stateNY);
  stateNY = transfer.get('location.UsState', 'NY');
  writeOutput(stateNY.getStateCode()  'br /'); //output is  (EXPECT
  NY !?!)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  true (EXPECT false !?!)

  transfer.discardByClassAndKey('location.UsState', 'NY');
  stateNY = transfer.get('location.UsState', 'NY');
  writeOutput(stateNY.getStateCode()  'br /'); //output is  (EXPECT
  NY !?!)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  true (EXPECT false !?!)

  transfer.discardByClassAndKey('location.UsState', '');
  stateNY = transfer.get('location.UsState', 'NY');
  writeOutput(stateNY.getStateCode()  'br /'); //output is  (EXPECT
  NY !?!)
  writeOutput(stateNY.getIsDirty()  'br /'); //output is
  true (EXPECT false !?!)
  /cfscript

  Best,
  Jamie

  On Jan 28, 3:14 pm, Bob Silverberg bob.silverb...@gmail.com wrote:
  It looks like you're calling Transfer.discard(stateNY)  but then
  trying to use the stateNY object again, without issuing another get().
   So stateNY is still pointing at the same object, even though it isn't
  currently in the Transfer cache.

  If you think of it that way you'll see that your test results make
  perfect sense.

  I think perhaps what you want to do is call stateNY =
  transfer.get('location.UsState', 'NY'); again, after your discard, and
  then check the values of the object.

  Bob

  On Wed, Jan 28, 2009 at 2:53 PM, Jamie Krug jamiek...@gmail.com wrote:

   Hi, all,

   I hope I'm missing something obvious, but I just can't peg it. I was
   purposely changing the key property of a Transfer object in a unit
   test object so I could test my validate() method (in my TO decorator).
   Suddenly a bunch of assertions that were successful started failing. I
   realized that I'm getting the cached version with the altered key
   field.

   For simplicity, assume I have a usstate table