How a region type affects the way an EntityQuery object is reused

for (...) {
    UserList userList = (UserList) Component.getInstance(UserList.class, ScopeType.METHOD);
    userList.getUserByEmailAddress(emailId);
}

There are various ScopeTypes that are supported by Seam (e.g. METHOD, PAGE, EVENT, APPLICATION). We are currently using the METHOD scope to retrieve the User object by email id. The above code is present in the for loop (i.e., to retrieve user email addresses, we retrieve the user object). Is this a valid ScopeType or would it be preferable to move the UserList declaration over the for loop.

We observe in certain types of areas that the userList object is reused, someone can clarify how it works. Are there any tools in the seam that will help you understand how these objects will be reused (we included some trace logs, but there were too many calls that were made, and this was not entirely clear)

+3
source share
1 answer

ScopeType.METHOD says

Each call to a bean session or JavaBean component places a new method context on the stack of method contexts associated with the current thread . The context is destroyed when the method returns.

Seam Seam. MethodContextInterceptor ( Seam), API

METHOD SFSB

MethodContextInterceptor.java .

@AroundInvoke
public Object aroundInvoke(InvocationContext ctx) throws Exception {
    Component comp = getComponent();

    String name = comp.getName();
    Object target = ctx.getTarget();
    Method method = ctx.getMethod();
    Object[] parameters = ctx.getParameters();

    /**
      * beginMethod
      *
      * Takes care of putting a NEW method context onto the stack of method contexts
      */
    Context outerMethodContext = Lifecycle.beginMethod();

    try {
        Contexts.getMethodContext().set(name, target);
        Contexts.getMethodContext().set("org.jboss.seam.this", target);
        Contexts.getMethodContext().set("org.jboss.seam.method", method);
        Contexts.getMethodContext().set("org.jboss.seam.parameters", parameters);
        Contexts.getMethodContext().set("org.jboss.seam.component", comp);

        /**
          * And after method return 
          */ 
        return ctx.proceed();
    } finally {
        /**
          * endMethod Takes care of destroying The previous added method context
          */       
        Lifecycle.endMethod(outerMethodContext);
    }
}

, , ScopeType.METHOD. , , Seam, The ScopeType.METHOD , . Seam in Action ScopeType.METHOD.

, , getUserByEmailAddress, . , " " .

,

, .

EntityQuery??? , Seam in Action

, , . , , , , , .

, . ,

  • refresh()

@Entity, . , Seam. , EntityQuery ScopeType.EVENT

UserList userList = (UserList) Component.getInstance(UserList.class, ScopeType.EVENT);
for (...) {
    userList.getUserByEmailAddress(emailId);
}

Seam Spring scope

Seam                               Spring            Suited for
ScopeType.STATELESS                singleton         Service, repositories, Thread-safe components
ScopeType.APPLICATION              singleton         Service, repositories, Thread-safe components
ScopeType.SESSION                  session           User login
ScopeType.CONVERSATION             -                 Page flow
ScopeType.PAGE                     -                 Server-side based component model
ScopeType.EVENT                    request           Non Thread-safe components

ScopeType.CONVERSATION Spring -. Seam ScopeType.CONVERSATION -. . , ScopeType.PAGE , , JSF, Wicket ..... ScopeType.STATELESS , Java EE ScopeType.APPLICATION, POJO EJB.

+1

Source: https://habr.com/ru/post/1752940/


All Articles