开发者

JCR Re-opening Connections

I am using JCR 1.0 and I am having problems re-opening JCR connections after I close them.

Here are my two helper methods:

private void openConnection() throws Exception {
    loadDbProperties();

    repository = new TransientRepository(repositoryConfig,repositoryHome);
    session = repository.login(new SimpleCredentials("testUserName","testPassword".toCharArray()));

    ws = session.getWorkspace();

    rootNode = session.getRootNode();
}

private void closeConnection() throws Exception {
    session.save();
    session.logout();
    session = null;
    repository = null;
}

I have two methods called, addProperty() and getProperty(), both need a connection to the JCR repository. I placed the openConnection() and closeConnection() methods at the beginning of both add and get methods but it seems that whichever method runs second is not able to re-open an already closed connection.

This is the exception I get:

javax.faces.el.EvaluationException: javax.jcr.RepositoryException: this session has been closed
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.开发者_StackOverflow社区broadcastEvents(UIViewRoot.java:775)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:550)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:380)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Caused by: javax.jcr.RepositoryException: this session has been closed
    at org.apache.jackrabbit.core.SessionImpl.sanityCheck(SessionImpl.java:340)
    at org.apache.jackrabbit.core.ItemImpl.sanityCheck(ItemImpl.java:154)
    at org.apache.jackrabbit.core.NodeImpl.addNode(NodeImpl.java:1751)
    at pgts.trueMiner.core.dao.TenureDAOImpl.addTenure(TenureDAOImpl.java:63)
    at pgts.trueMiner.core.biz.TenureServiceImpl.addTenure(TenureServiceImpl.java:63)
    at pgts.trueMiner.core.ui.TenureForm.addTenure(TenureForm.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:98)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    ... 23 more

How do you re-open the same connection? I don't want to always keep the connection open because a lock will prevent other applications from using the repository.


It looks like you try to add a node after the session was closed. I can reproduce the exception using the following test case:

Repository repository = new TransientRepository();
Session session = repository.login(
        new SimpleCredentials("admin", "admin".toCharArray()));
session.getWorkspace();
Node rootNode = session.getRootNode();
session.save();
session.logout();
rootNode.addNode("test");

With a recent version of Jackrabbit (I used Jackrabbit trunk) you will get the stack trace of where the session was closed:

Exception in thread "main" javax.jcr.RepositoryException: This session has been closed. See the chained exception for a trace of where the session was closed.
  at org.apache.jackrabbit.core.session.SessionState.checkAlive(SessionState.java:121)
  at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:171)
  at org.apache.jackrabbit.core.ItemImpl.perform(ItemImpl.java:91)
  at org.apache.jackrabbit.core.NodeImpl.addNodeWithUuid(NodeImpl.java:1790)
  at org.apache.jackrabbit.core.NodeImpl.addNode(NodeImpl.java:1742)
  at org.apache.jackrabbit.api.Test.main(Test.java:21)
Caused by: java.lang.Exception: Stack trace of  where session-admin-4 was originally closed
  at org.apache.jackrabbit.core.session.SessionState.close(SessionState.java:246)
  at org.apache.jackrabbit.core.SessionImpl.logout(SessionImpl.java:888)
  at org.apache.jackrabbit.core.XASessionImpl.logout(XASessionImpl.java:389)
  at org.apache.jackrabbit.api.Test.main(Test.java:20)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜