Re: Inline scripted transactions
Karl Wettin <[email protected]>
| Newsgroups | gmane.comp.java.prevayler |
|---|---|
| Message-ID | <[email protected]> |
17 jul 2010 kl. 04.22 skrev Justin T. Sampson: > On Fri, Jul 16, 2010 at 1:00 AM, Karl Wettin <[email protected]> > wrote: > I find this very neat and think it's safe since transactions are > "useless" after taking a snapshot. > > I'm not sure what you mean by "useless". That a journal is "depricated" after taking a snapshot. > Something else I might be missing that makes this a bad idea? > > Well, I suppose journals will be larger because they contain code > snippets rather than just class names. I wouldn't worry about that > unless it actually becomes a problem. > > You also, of course, lose compile-time checking of the syntax and > typesafety of the code. Presumably you have unit tests that will > exercise the scripts, though. It also turns out to be rather slow when executing the journal. Perhaps 10-15 times slower. But I'm OK with that. My system almost never crash *knock on wood* and I take snapshots realatively frequent. Here is some example code: > > EntityTransactionScriptWithQuery<Advertisement> script = new > EntityTransactionScriptWithQuery<Advertisement>(advertisement); > script.invoke("source = entity.getSource(" + > script.get(advertisementSource.getURI()) + ");"); > script.invoke("source.setLastSeen(executionTime);"); > > Boolean sold = harvester.isSold(searchResult, > advertisementDocument); > if (sold != null) { > if (!sold && advertisementSource.getClosed() != null) { > // mark as still for sale > script.invoke("source.setClosed(null);"); > > } else if (sold && advertisementSource.getClosed() == null) { > // mark as sold > script.invoke("source.setClosed(executionTime);"); > > } > } > > Hydda.getInstance().executeTransaction(script); Notice the first invokation that use "script.get(...". This will serialize any class to bean shell script using reflection. In this case it's just a string but it could be a complete object graph. (In the case of prevayler transactions this should of course be an isolated graph.) I do enjoy the inline transactions. Makes for fast coding and easy to read code compared to decoupled transaction classes. I haven't pushed the scripted transaction classes to github yet, but I will. In case anyone want it now just let me know. Here is the Bsh helper though: http://github.com/karlwettin/kodapan-common/blob/master/src/main/java/se/kodapan/bsh/BshScriptBuilder.java karl ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion _______________________________________________ "Databases in Memoriam" -- http://www.prevayler.org