good point.<div>Naming was not my focus here though, it was just a quick example.</div><div><br><div class="gmail_quote">On Tue, Sep 27, 2011 at 1:55 PM, Max Rydahl Andersen <span dir="ltr"><<a href="mailto:max.andersen@redhat.com">max.andersen@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">don't use save or saveOrUpdate - those are old Hibernate API methods which doesn't do the same as what update/persist does.<br>
<br>
The semantics are similar but different enough to not overload the words since it requires a different usage of the API.<br>
<br>
My 2 cents ;)<br>
<font color="#888888"><br>
/max<br>
</font><div><div></div><div class="h5"><br>
On Sep 27, 2011, at 17:57, Jason Porter wrote:<br>
<br>
> I prefer the idea that there's a class that manages one instance and that's all it does, and another object (or objects) to handle collections of those objects. I think separating them out makes for better reusability. If we'd like to have a save method I'm okay with that, but don't really see the need.<br>
><br>
> Sent from my iPhone<br>
><br>
> On Sep 27, 2011, at 7:32, José Rodolfo Freitas <<a href="mailto:joserodolfo.freitas@gmail.com">joserodolfo.freitas@gmail.com</a>> wrote:<br>
><br>
>> Sorry for not being able to post my gist. After writting some "sketches", I realized that I don't have it very clear in my mind yet.<br>
>><br>
>> just to move from zero I posted something:<br>
>><br>
>> <a href="https://gist.github.com/1245041" target="_blank">https://gist.github.com/1245041</a><br>
>><br>
>> It's a really simple example on how we could avoid inheritance, but it's not contemplating a lot of needed features,<br>
>> so I'm not even near to be convinced with that gist.<br>
>><br>
>> btw, the @AutoHome approach seems very nice.<br>
>><br>
>><br>
>> On Thu, Sep 22, 2011 at 2:12 PM, Dan Allen <<a href="mailto:dan.j.allen@gmail.com">dan.j.allen@gmail.com</a>> wrote:<br>
>> Exactly. flush() has a specific purpose and really doesn't belong in boilerplate code.<br>
>><br>
>> - Dan Allen<br>
>><br>
>> Sent from my Android-powered phone:<br>
>> An open platform for carriers, consumers and developers<br>
>><br>
>> On Sep 22, 2011 11:19 AM, "Max Rydahl Andersen" <<a href="mailto:max.andersen@redhat.com">max.andersen@redhat.com</a>> wrote:<br>
>> > just one comment:<br>
>> ><br>
>> > Calling .flush() on every alteration really should not be promoted as a good practice.<br>
>> ><br>
>> > /max<br>
>> ><br>
>> > On Sep 22, 2011, at 24:22, Dan Allen wrote:<br>
>> ><br>
>> >> Here's some additional feedback I received from a community member a while back...to merge it into this thread.<br>
>> >><br>
>> >> (begin feedback)<br>
>> >><br>
>> >> ...from being burned from 3 seam based customers with apps and maintenance. The "Home" or any other name should be just be put into a grave and slowly cast away to sea ;). It is too heavy and complicated and just about anything inherited (extends) truly causes heartache[Favor Composition over inheritance: Effective Java]. The current seam home has a few super classes above the home and when you try to unit test it (the standard definition of unit-testing including isolation) you get the "No Active Application Context Found (if I remember it right). That happens because it is tightly coupled with the application. But not to be hard on Home, I do realize the history of the home object and know it was developed when EL had no parameters. So I have learned a lot since then and I here are some things that I can impart to Seam 3.<br>
>> >><br>
>> >> 1. My "Home" now is a "ServiceBean", and I have one for each "Major" entity, see below. I have really stewed over this over months and months, and the "Home" of "ServiceBean" should be kept small, focused, reusable, tested and untouched. It's only task is to update, persist, possibly remove, or some other functions that are required. In my example below I have custom close action. Notice also that although these beans are stateful that doesn't mean everything should be, so in these methods I have the parameter of what is being needed to be updated, and not a field. In other words I don't have @In private Job job, I opted for public boolean update(job). Mostly because, again, I want to make this service bean reusable so whether I have a #{newJob}, #{copyOfAJob}, or #{managedJob} or whatever component of job I need to work on I only need one jobServiceBean to cater to all my jobs, in whatever conversation I am using. I also fire events from here if I need to do that. !<br>
>> > After this is tested, and what I need I usually don't touch it anymore. If I need to enhance I either use a decorator pattern around it, or enhance it in an @Observer. I'll email about that later.<br>
>> >><br>
>> >> @Name("jobServiceBean")<br>
>> >> @Scope(ScopeType.CONVERSATION)<br>
>> >> public class JobServiceBean implements JobService {<br>
>> >> private EntityManager entityManager;<br>
>> >> private StatusMessages statusMessages;<br>
>> >><br>
>> >> @In<br>
>> >> public void setEntityManager(EntityManager entityManager) {<br>
>> >> this.entityManager = entityManager;<br>
>> >> }<br>
>> >><br>
>> >> @In<br>
>> >> public void setStatusMessages(StatusMessages statusMessages) {<br>
>> >> this.statusMessages = statusMessages;<br>
>> >> }<br>
>> >><br>
>> >> public boolean update(Job job) {<br>
>> >> this.entityManager.flush();<br>
>> >> this.statusMessages.add(<a href="http://StatusMessage.Severity.INFO" target="_blank">StatusMessage.Severity.INFO</a>, "Successfully updated job {0}", job.getName());<br>
>> >> return true;<br>
>> >> }<br>
>> >><br>
>> >> public boolean close(Job job) {<br>
>> >> job.setJobStatus(JobStatus.CLOSED);<br>
>> >> this.entityManager.flush();<br>
>> >> this.statusMessages.add(<a href="http://StatusMessage.Severity.INFO" target="_blank">StatusMessage.Severity.INFO</a>, "Successfully closed job {0}", job.getName());<br>
>> >> return true;<br>
>> >> }<br>
>> >> }<br>
>> >><br>
>> >> 2. One thing you may have noticed from above that there is no 'instance' field with corresponding getters or setters like the old 'Home'. So the ServiceBean in my case is not a full crud, but CUD + your own business methods. That's because that too should be decoupled because we never know the source of the object is. Is the object created from a factory? from a copy? is it a mapped component, a managed component? Creation of objects or loading of objects, or the manufacturing of objects from factories should be separate from the "home" or in my case the "ServiceBean".<br>
>> >><br>
>> >> (end feedback)<br>
>> >><br>
>> >> --<br>
>> >> Dan Allen<br>
>> >> Principal Software Engineer, Red Hat | Author of Seam in Action<br>
>> >> Registered Linux User #231597<br>
>> >><br>
>> >> <a href="http://www.google.com/profiles/dan.j.allen#about" target="_blank">http://www.google.com/profiles/dan.j.allen#about</a><br>
>> >> <a href="http://mojavelinux.com" target="_blank">http://mojavelinux.com</a><br>
>> >> <a href="http://mojavelinux.com/seaminaction" target="_blank">http://mojavelinux.com/seaminaction</a><br>
>> >><br>
>> >> _______________________________________________<br>
>> >> forge-dev mailing list<br>
>> >> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
>> >> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
>> ><br>
>> > /max<br>
>> > <a href="http://about.me/maxandersen" target="_blank">http://about.me/maxandersen</a><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > forge-dev mailing list<br>
>> > <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
>> > <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
>><br>
>> _______________________________________________<br>
>> seam-dev mailing list<br>
>> <a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>
>> <a href="https://lists.jboss.org/mailman/listinfo/seam-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-dev</a><br>
>><br>
>><br>
>> _______________________________________________<br>
>> seam-dev mailing list<br>
>> <a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>
>> <a href="https://lists.jboss.org/mailman/listinfo/seam-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-dev</a><br>
> _______________________________________________<br>
> forge-dev mailing list<br>
> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
<br>
/max<br>
<a href="http://about.me/maxandersen" target="_blank">http://about.me/maxandersen</a><br>
<br>
<br>
<br>
</div></div></blockquote></div><br></div>