jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jaco Prinsloo <jacoli...@gmail.com>
Subject Re: Jackrabbit Session inside Stateless Session EJB
Date Thu, 15 Oct 2009 06:41:52 GMT
Thanks for clarifying.
Perhaps I can clarify the difference with two pseudo-ish code examples:

(1)
@Stateless
public class RepositoryEJB {
  @Resource private Repository repository;

  public String getMimeType(String path) {
    Session session = repository.login( .. );
    String mimeType =
(String)session.getRootNode().getNode(path).getProperties().get( .. );
    session.logout();
    return mimeType;
  }

  public Long getSize(String path) {
    Session session = repository.login( .. );
    Long size =
(Long)session.getRootNode().getNode(path).getProperties().get( .. );
    session.logout();
    return size;
  }
}

(2)
@Stateless
public class RepositoryEJB {
  @Resource private Repository repository;

  private Session session;

  @PostConstruct
  public void postConstruct() {
    Session session = repository.login( .. );
  }

  @PreDestroy
  public void preDestroy() {
    session.logout();
  }

  public String getMimeType(String path) {
    return (String)session.getRootNode().getNode(path).getProperties().get(
.. );
  }

  public Long getSize(String path) {
    return (Long)session.getRootNode().getNode(path).getProperties().get( ..
);
  }
}

Which one is better?

Thank you,
Jaco

On Wed, Oct 14, 2009 at 11:04 PM, Guo Du <mrduguo@gmail.com> wrote:

> On Wed, Oct 14, 2009 at 11:11 AM, Jaco Prinsloo <jacolists@gmail.com>
> wrote:
> > 1) Every request (method) opens a session, performs the work and then
> closes
> > the session again.
> In general, we have a session open to process the request, works like
> jdbc data source. It doesn't matter what environment you are using,
> servlet container, ejb or standalone application.
>
> > 2) There is one session per SLSB which is opened in PostConstruct and
> closed
> > in PreDestroy.
> This is how you actual implement the session management in EJB container.
>
> > Are there any advantages/disadvantages to these two approaches?
>
> I couldn't see the difference in your approaches.
>
> -Guo
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message