jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From herbert <i...@gmx.de>
Subject Removing a set of nodes via NodeIterator fails
Date Thu, 17 Sep 2009 14:44:50 GMT

Hi!

I'm quite new to Jackrabbit and have a problem deleting nodes in my
repository with jackrabbit 1.6.0.

Here's the problem-point in my code:

NodeIterator itTestNodes = result.getNodes();
while (itTestNodes.hasNext()) {
  Node testNode = itTestNodes.nextNode();
  System.out.println("Deleting Node " +testNode.getName());
  testNode.remove();	
}
session.save();

I iterate over a collection of nodes. After the first iteration has
completed, testNode references to the second node in NodeIterator and I get
an InvalidItemStateException "the item does not exist anymore" when
testNode.getName() is executed.

Where is my error? (full code and exception appended.)

Herbert


*********************************************************************

The full code:

Context context = new InitialContext();
ClientAdapterFactory adapter = new ClientAdapterFactory();
RemoteRepository rr = (RemoteRepository)
context.lookup("jnp://localhost:1099/jcrServer");
Repository repository = adapter.getRepository(rr);
Session session = repository.login(new SimpleCredentials("user",
"password".toCharArray()), "default");

QueryManager qm = session.getWorkspace().getQueryManager();
Query query = qm.createQuery("//*", Query.XPATH);
QueryResult result = query.execute();

NodeIterator itTestNodes = result.getNodes();
while (itTestNodes.hasNext()) {

  Node testNode = itTestNodes.nextNode();
  System.out.println("Examining Node " +testNode.getName());
  if (testNode.getName().startsWith("TEST")) {
	System.out.println("Deleting Node " +testNode.getName());
	testNode.remove();	
  }
}

session.save();
session.logout();

*********************************************************************

The exception:

javax.jcr.InvalidItemStateException: 7ccb179d-8830-48ad-91d8-cb6726a29b2e:
the item does not exist anymore
	at
org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException(ServerObject.java:104)
	at org.apache.jackrabbit.rmi.server.ServerItem.getName(ServerItem.java:71)
	at sun.reflect.GeneratedMethodAccessor332.invoke(Unknown Source)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
	at sun.rmi.transport.Transport$1.run(Transport.java:153)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
	at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
	at java.lang.Thread.run(Thread.java:595)
	at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
	at
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
	at org.apache.jackrabbit.rmi.server.ServerNode_Stub.getName(Unknown Source)
	at org.apache.jackrabbit.rmi.client.ClientItem.getName(ClientItem.java:85)
	at de.firma.deleteTestNodes2(TestMeta.java:96)
	at de.firma.tearDown(TestMeta.java:74)
	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:585)
	at org.junit.internal.runners.ClassRoadie.runAfters(ClassRoadie.java:65)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:40)
	at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


*********************************************************************
-- 
View this message in context: http://www.nabble.com/Removing-a-set-of-nodes-via-NodeIterator-fails-tp25491923p25491923.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message