for (...) {
UserList userList = (UserList) Component.getInstance(UserList.class, ScopeType.METHOD);
userList.getUserByEmailAddress(emailId);
}
There are different ScopeTypes which are supported by Seam (e.g. METHOD, PAGE, EVENT, APPLICATION). We currently use the METHOD scope to retrieve User object by email id. The above code is present in a for loop (i.e. for a collection of user email addresses we retrieve the user object). Is this the right ScopeType or would it be preferable to move the UserList declaration above the for loop
We have observed in certain scope types that the userList object gets reused, can someone clarify on how it really works. Are there any tools within seam which will help you understand how these objects get reused (We turned on some trace logging, but there were too many calls which were being made and it was not quite clear)
ScopeType.METHOD says
Much of the functionality of Seam is implemented as a set of built-in Seam interceptors. Here goes a piece of code of MethodContextInterceptor (built-in Seam interceptor) which API says
MethodContextInterceptor.java See comments bellow and compare with The highlighted Text above
As you can see, i do not see any special behavior provided by ScopeType.METHOD. I Think Gavin King, founder of Seam project, has created The ScopeType.METHOD as an additional scope which could be used posteriorly. Even Seam in Action book does not cover ScopeType.METHOD scope.
So each Time you call getUserByEmailAddress, The routine above is performed. About context, Seam in Action book is clear
So your desired scope should draw your business requiment.
About EntityQuery ??? Here goes what Seam in Action book says
By default, some Query methods avoid redundant database queries by caching the results in a private property on the class. But it can be overrided since you change
The last item is useful when you update some @Entity and you need To refresh The stored result set. You can accomplish it by using a Seam event. But if you always want a fresh result set, set up your EntityQuery as ScopeType.EVENT and use it before for loop instead
Here goes a side by side comparison between Seam and Spring scope
Notice ScopeType.CONVERSATION is not equal To Spring web flow. Seam ScopeType.CONVERSATION goes beyond web layer. Even an persistence context can be included in conversation context. Keep in mind ScopeType.PAGE makes sense when you have a server-side based component model framework such as JSF, Wicket and so on… Usually, ScopeType.STATELESS is used when you have an fully Java EE environment and ScopeType.APPLICATION when you use plain POJOs instead of EJB.