JCR 重新开放连接
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您尝试在会话关闭后添加节点。我可以使用以下测试用例重现该异常:
使用最新版本的 Jackrabbit(我使用 Jackrabbit trunk),您将获得会话关闭位置的堆栈跟踪:
It looks like you try to add a node after the session was closed. I can reproduce the exception using the following test case:
With a recent version of Jackrabbit (I used Jackrabbit trunk) you will get the stack trace of where the session was closed: