Page 1 of 1

have I been created in this transaction

Posted: Mon Feb 24, 2014 8:56 am
by Lorcan
Hi everyone,
Wonder if anyone can solve this conundrum....(in Jade 6)...

for the below piece of code, can you tell me how to code for the method hasBeenCreatedWithinThisBlock

Cheers for the time .. :)

lorcan




beginTransaction
create otherObject persistant;
commitTransaction

beginTransaction
create newObject persistant;

if newObject.hasBeenCreatedWithinThisBlock then
/> //this is true;
else
/> // this is false;
endif;

if otherObject.t.hasBeenCreatedWithinThisBlock then
/> //this is false
else
/> // this is true
endif;

commitTransaction

Re: have I been created in this transaction

Posted: Mon Feb 24, 2014 10:31 am
by murray
What are you trying to achieve here?
1. You will need to define what "this block" actually means in a context that the proposed method will understand.
2. Also, you have explicitly coded to create these objects - why then do you need to check if you have just created them?

Re: have I been created in this transaction

Posted: Mon Feb 24, 2014 11:23 am
by allistar
This is extremely nasty, but it can be done by passing the object into a serverExecution method which returns "global.isValidObject" on the object. If the object has not been committed yet then this will return "false" on the server node. As I said this is nasty and will not be overly efficient.

A common pattern is to have a transient controller singleton which controls database transaction state handling as well as the execution of agents. This makes it easier to detect which objects have been created/modified/deleted in the current database transaction.