JCR 重新开放连接

发布于 2024-10-16 14:36:29 字数 4169 浏览 9 评论 0原文

我正在使用 JCR 1.0,在关闭 JCR 连接后重新打开它们时遇到问题。

以下是我的两个辅助方法:

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;
}

我有两个名为 addProperty() 和 getProperty() 的方法,它们都需要连接到 JCR 存储库。我将 openConnection() 和 closeConnection() 方法放在 add 和 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.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 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.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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

复古式 2024-10-23 14:36:29

看起来您尝试在会话关闭后添加节点。我可以使用以下测试用例重现该异常:

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");

使用最新版本的 Jackrabbit(我使用 Jackrabbit trunk),您将获得会话关闭位置的堆栈跟踪:

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文