Re: about Business Object and System Object design?
Jon Tirsén <[email protected]> Tue, 29 Apr 2003 16:30:30 +0200 (CEST)
| Newsgroups | gmane.comp.java.nanning.devel |
|---|---|
| Message-ID | <[email protected]> |
Any objects that are transactional/persisten/business objects needs to be created with a factory method, that is by using: Aspects.getCurrentAspectFactory().newInstance(MyObject.class) So it would not be correct to do: new MyObjectImpl(); The reason for this is that Nanning creates a special class that wraps the MyObjectImpl. Nanning does this in order to invoke interceptors when methods are called. More on this can be read here: http://nanning.snipsnap.org/space/Dynamic+Proxy For Nanning to intercept method-calls that are performed *within* an object you need to use Aspects.getThis(). This will return you the proxy of the currently executing object. You need to cast it to the type of the interface in order to use it. Future versions of Nanning may remove this necessity in many situations. (There's a little trick I'm working on.) Also it is currently not supported (if you're using 0.3) to create objects and return them within methods that are marked with @transaction. So remove @transaction from createMyObject-method. This has nothing specifically to do with Nanning but with the special feature of Prevayler 2.0 that Nanning uses. I have now included an assert in the latest commit (you need to build from CVS) that will inform you when you are doing this error. Always run Nanning with assertions enabled when you're developing, there are a lot of helpful error-messages that will help you if you're doing something wrong. Assertions can be turned of in production because they will hur performance a lot. Hope this helps you, and if there's any other questions don't hesitate to ask. --- yiming wang <[email protected]> skrev: > hi jon, > > In nanning's testcase, > I guess that MyObject.java is normal Business Object > > and MySystem.java is to hold all Business Objects. > > I add following code in MyObject.java: > /** > * @transaction > */ > void createNewMyObject(); > > /** > * @transaction > */ > void removeNewMyObject(); > > MyObject getNewMyObject(); > > also MyObjectImpl.java: > > MyObject newMyObject; > > public void createNewMyObject() { > newMyObject = new MyObjectImpl(); > //should be (MyObject) > //Aspects.getCurrentAspectFactory().newInstance(MyObject.class) > //? > > newMyObject.setValue("abc"); > } > > public void removeNewMyObject() { > newMyObject = null; // to remove > //newMyObject from the system, right? > } > > public MyObject getNewMyObject() { > return newMyObject; > } > > then i test it, all is fine. > but in method public void createNewObject(): > newMyObject = new MyObjectImpl(); > is it a right design? > should it be writed as following? > newMyObject = (MyObject) > Aspects.getCurrentAspectFactory().newInstance(MyObject.class); > > if i am not missing, i guess there is only one big > xxxSystem.java in system which > hold all "top level" Business Objects, the "top > level" > Business Object > (like MyObject.java, it is wraped as Aspect object) > can hold other business objects(they may not Aspect > object, > so we can do like that "newMyObject = new > MyObjectImpl()") > > that's all my thought, just about to persistent > framework. > i hope that you can know my said and guide me to the > right way. > > thanks! > > wang yiming > 2003.4.29 > > __________________________________ > Do you Yahoo!? > The New Yahoo! Search - Faster. Easier. Bingo. > http://search.yahoo.com > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Nanning-developer mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/nanning-developer _____________________________________________________ Gå före i kön och få din sajt värderad på nolltid med Yahoo! Express Se mer på: http://se.docs.yahoo.com/info/express/help/index.html ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf