You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by J Kuijpers <ja...@hotmail.com> on 2006/08/28 14:26:46 UTC

problem retrieving nodes from different workspaces

Hello I am having a problem retrieving nodes from different workspaces. I
have supplied a runnable example class.

In this class I am creating two workspaces and add some nodes to them. When
I retrieve the nodes without first shutting down the repository I am getting
a result as expected: 

workspace1Node1
workspace1Node2
workspace1Node3

But when I am shutting down the repository before retrieving the nodes
(passing true in the call to runTest(boolean)), I am getting unexpected
results:

workspace1Node3

This only happens with the DerbyPersistenceManager. Changing to
FileSystemPersistenceManager gives no problems.

Supplied repository.xml and runnable MultipleWorkspaceTest.java 
http://www.nabble.com/user-files/235783/repository.xml repository.xml  
http://www.nabble.com/user-files/235784/MultipleWorkspaceTest.java
MultipleWorkspaceTest.java 
-- 
View this message in context: http://www.nabble.com/problem-retrieving-nodes-from-different-workspaces-tf2177041.html#a6019261
Sent from the Jackrabbit - Dev forum at Nabble.com.


Re: problem retrieving nodes from different workspaces

Posted by J Kuijpers <ja...@hotmail.com>.
Ok hmm strange... This toppic involves the same problem as the toppic of my
collegue quipere (ItemNotFoundException while switching between different
workspaces). The reason why I am not getting an ItemNotFoundException but
only the wrong nodes, I think is because the code I am using is not using a
NodeType which is orderable. The orginal code does use such a nodetype. When
creating the test class I couldn't use our custom nodetypes. That's the main
difference.    

Will supply the class inline:

package nl.src;

import java.util.Hashtable;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.query.Query;
import javax.jcr.query.QueryResult;
import javax.naming.Context;
import javax.naming.InitialContext;

import org.apache.jackrabbit.core.RepositoryImpl;
import org.apache.jackrabbit.core.WorkspaceImpl;
import org.apache.jackrabbit.core.jndi.RegistryHelper;

/**
 * @author jukuijpe
 *
 */
public class MultipleWorkspaceTest {
	
	private static Repository repos = null;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		runTest(true);		
	}
	
	public static void runTest(boolean repositoryShutdown) {
		Session session = null;
		Session session1 = null;
		Session session2 = null;
		
		try {
			Repository repos = getRepository();
			session = repos.login(new SimpleCredentials("user",
"password".toCharArray()));
			((WorkspaceImpl)
session.getWorkspace()).createWorkspace("testWorkspace1");
			((WorkspaceImpl)
session.getWorkspace()).createWorkspace("testWorkspace2");
			session.logout();
			
			session1 = repos.login(new SimpleCredentials("user",
"password".toCharArray()), "testWorkspace1");
			session2 = repos.login(new SimpleCredentials("user",
"password".toCharArray()), "testWorkspace2");
			
			Node startNodeW1 = null;
			Node startNodeW2 = null;			
			
			if (session1.getRootNode().hasNode("testNodes")) {
				startNodeW1 = session1.getRootNode().getNode("testNodes");				
			} else {
				startNodeW1 = session1.getRootNode().addNode("testNodes");
			}
			if (session2.getRootNode().hasNode("testNodes")) {
				startNodeW2 = session2.getRootNode().getNode("testNodes");
			} else {
				startNodeW2 = session2.getRootNode().addNode("testNodes");
			}
			
			startNodeW1.addNode("workspace1Node1");
			startNodeW2.addNode("workspace2Node1");
			startNodeW1.addNode("workspace1Node2");
			startNodeW2.addNode("workspace2Node2");
			startNodeW1.addNode("workspace1Node3");
			startNodeW2.addNode("workspace2Node3");
			
			session1.save();
			session2.save();
			
			RepositoryImpl jackRabbitRepos = ((RepositoryImpl)
session2.getRepository());
			
			session1.logout();
			session2.logout();
			
			if (repositoryShutdown) {
				jackRabbitRepos.shutdown();
				MultipleWorkspaceTest.repos = null;
			}			
			listNodes();						
		} catch(Exception e) {
			e.printStackTrace();
		}finally {
			if (session != null) {
				session.logout();
			}
			if (session1 != null) {
				session1.logout();
			}
			if (session2 != null) {
				session2.logout();
			}
		}
	}

	
    /**
     * Creates a Repository instance to be used by the example class.
     *
     * @return repository instance
     * @throws Exception on errors
     */
    private static Repository getRepository() throws Exception {
    	if (repos == null) {
	        String configFile = "c:/repotest/repository.xml";
	        String repHomeDir = "c:/repotest";
	
	        Hashtable env = new Hashtable();
	        env.put(Context.INITIAL_CONTEXT_FACTORY,
	               
"org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
	        env.put(Context.PROVIDER_URL, "localhost");
	        InitialContext ctx = new InitialContext(env);
	
	        RegistryHelper.registerRepository(ctx, "repo", configFile,
repHomeDir, true);
	        repos = (Repository) ctx.lookup("repo");
    	}
    	return repos;
    }
    
    private static void listNodes() {
		Session session = null;
		try{
		Repository reposNew = getRepository();
		session = reposNew.login(new SimpleCredentials("user",
"password".toCharArray()), "testWorkspace1");
		Query repositoryQuery =
session.getWorkspace().getQueryManager().createQuery("testNodes/*",
Query.XPATH);
		QueryResult result = repositoryQuery.execute();
		NodeIterator it = result.getNodes();
		while (it.hasNext()) {
			Node node = it.nextNode();
			System.out.println(node.getName());
		}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (session != null) {
				session.logout();
			}
		}
    }
}
 



Jukka Zitting-3 wrote:
> 
> Hi,
> 
> On 8/28/06, J Kuijpers <ja...@hotmail.com> wrote:
>> Supplied repository.xml and runnable MultipleWorkspaceTest.java
>> http://www.nabble.com/user-files/235783/repository.xml repository.xml
>> http://www.nabble.com/user-files/235784/MultipleWorkspaceTest.java
>> MultipleWorkspaceTest.java
> 
> The MultipleWorkspaceTest.java file appears to be empty. Could you
> resend it, inline if necessary?
> 
> BR,
> 
> Jukka Zitting
> 
> -- 
> Yukatan - http://yukatan.fi/ - info@yukatan.fi
> Software craftsmanship, JCR consulting, and Java development
> 
> 

-- 
View this message in context: http://www.nabble.com/problem-retrieving-nodes-from-different-workspaces-tf2177041.html#a6019752
Sent from the Jackrabbit - Dev forum at Nabble.com.


Re: problem retrieving nodes from different workspaces

Posted by J Kuijpers <ja...@hotmail.com>.
You're right, that I didn't find that myself. Thanks for spotting it :)


Marcel Reutegger-3 wrote:
> 
> Your repository.xml file is broken.
> 
> You have:
> 
> <PersistenceManager
>    class="org.apache.jackrabbit.core.state.db.DerbyPersistenceManager">
>      <param name="url" 
> value="jdbc:derby:${rep.home}/version/db;create=true"/>
>      <param name="schemaObjectPrefix" value="version_"/>
> </PersistenceManager>
> 
> 
> A fixed value for the parameter 'schemaObjectPrefix' will cause 
> Jackrabbit to write content of multiple workspaces into the same 
> table, thus possibly overwriting content.
> 
> You must use a value that includes the workspace name as a variable.
> 
> E.g. the sample configuration uses this:
> 
> <param name="schemaObjectPrefix" value="${wsp.name}_"/>
> 
> See also:
> https://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit/src/main/config/repository.xml
> 
> Using the sample repository.xml the test works fine even with a 
> shutdown in between.
> 
> regards
>   marcel
> 
> 
> 
> J Kuijpers wrote:
>> Were you able to reproduce our problem?
>> 
>> 
>> Jukka Zitting-3 wrote:
>>> Hi,
>>>
>>> On 8/28/06, J Kuijpers <ja...@hotmail.com> wrote:
>>>> Supplied repository.xml and runnable MultipleWorkspaceTest.java
>>>> http://www.nabble.com/user-files/235783/repository.xml repository.xml
>>>> http://www.nabble.com/user-files/235784/MultipleWorkspaceTest.java
>>>> MultipleWorkspaceTest.java
>>> The MultipleWorkspaceTest.java file appears to be empty. Could you
>>> resend it, inline if necessary?
>>>
>>> BR,
>>>
>>> Jukka Zitting
>>>
>>> -- 
>>> Yukatan - http://yukatan.fi/ - info@yukatan.fi
>>> Software craftsmanship, JCR consulting, and Java development
>>>
>>>
>> 
> 
> 
> -- 
> Marcel Reutegger
> Day Management AG
> Barfuesserplatz 6, 4001 Basel Switzerland
> 
> marcel.reutegger@day.com
> www.day.com
> 
> T 41 61 226 98 98
> F 41 61 226 98 97
> 
> This message is a private communication. If you are
> not the intended recipient, please do not read, copy,
> or use it, and do not disclose it to others. Please
> notify the sender of the delivery error by replying to
> this message, and then delete it from your system.
> Thank you. The sender does not assume any liability
> for timely, trouble-free, complete, virus free, secure,
> error free or uninterrupted arrival of this e-mail. For
> verification please request a hard copy version.
> 
> 

-- 
View this message in context: http://www.nabble.com/problem-retrieving-nodes-from-different-workspaces-tf2177041.html#a6038987
Sent from the Jackrabbit - Dev forum at Nabble.com.


Re: problem retrieving nodes from different workspaces

Posted by Marcel Reutegger <ma...@day.com>.
Your repository.xml file is broken.

You have:

<PersistenceManager
   class="org.apache.jackrabbit.core.state.db.DerbyPersistenceManager">
     <param name="url" 
value="jdbc:derby:${rep.home}/version/db;create=true"/>
     <param name="schemaObjectPrefix" value="version_"/>
</PersistenceManager>


A fixed value for the parameter 'schemaObjectPrefix' will cause 
Jackrabbit to write content of multiple workspaces into the same 
table, thus possibly overwriting content.

You must use a value that includes the workspace name as a variable.

E.g. the sample configuration uses this:

<param name="schemaObjectPrefix" value="${wsp.name}_"/>

See also:
https://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit/src/main/config/repository.xml

Using the sample repository.xml the test works fine even with a 
shutdown in between.

regards
  marcel



J Kuijpers wrote:
> Were you able to reproduce our problem?
> 
> 
> Jukka Zitting-3 wrote:
>> Hi,
>>
>> On 8/28/06, J Kuijpers <ja...@hotmail.com> wrote:
>>> Supplied repository.xml and runnable MultipleWorkspaceTest.java
>>> http://www.nabble.com/user-files/235783/repository.xml repository.xml
>>> http://www.nabble.com/user-files/235784/MultipleWorkspaceTest.java
>>> MultipleWorkspaceTest.java
>> The MultipleWorkspaceTest.java file appears to be empty. Could you
>> resend it, inline if necessary?
>>
>> BR,
>>
>> Jukka Zitting
>>
>> -- 
>> Yukatan - http://yukatan.fi/ - info@yukatan.fi
>> Software craftsmanship, JCR consulting, and Java development
>>
>>
> 


-- 
Marcel Reutegger
Day Management AG
Barfuesserplatz 6, 4001 Basel Switzerland

marcel.reutegger@day.com
www.day.com

T 41 61 226 98 98
F 41 61 226 98 97

This message is a private communication. If you are
not the intended recipient, please do not read, copy,
or use it, and do not disclose it to others. Please
notify the sender of the delivery error by replying to
this message, and then delete it from your system.
Thank you. The sender does not assume any liability
for timely, trouble-free, complete, virus free, secure,
error free or uninterrupted arrival of this e-mail. For
verification please request a hard copy version.

Re: problem retrieving nodes from different workspaces

Posted by J Kuijpers <ja...@hotmail.com>.
Were you able to reproduce our problem?


Jukka Zitting-3 wrote:
> 
> Hi,
> 
> On 8/28/06, J Kuijpers <ja...@hotmail.com> wrote:
>> Supplied repository.xml and runnable MultipleWorkspaceTest.java
>> http://www.nabble.com/user-files/235783/repository.xml repository.xml
>> http://www.nabble.com/user-files/235784/MultipleWorkspaceTest.java
>> MultipleWorkspaceTest.java
> 
> The MultipleWorkspaceTest.java file appears to be empty. Could you
> resend it, inline if necessary?
> 
> BR,
> 
> Jukka Zitting
> 
> -- 
> Yukatan - http://yukatan.fi/ - info@yukatan.fi
> Software craftsmanship, JCR consulting, and Java development
> 
> 

-- 
View this message in context: http://www.nabble.com/problem-retrieving-nodes-from-different-workspaces-tf2177041.html#a6037018
Sent from the Jackrabbit - Dev forum at Nabble.com.


Re: problem retrieving nodes from different workspaces

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 8/28/06, J Kuijpers <ja...@hotmail.com> wrote:
> Supplied repository.xml and runnable MultipleWorkspaceTest.java
> http://www.nabble.com/user-files/235783/repository.xml repository.xml
> http://www.nabble.com/user-files/235784/MultipleWorkspaceTest.java
> MultipleWorkspaceTest.java

The MultipleWorkspaceTest.java file appears to be empty. Could you
resend it, inline if necessary?

BR,

Jukka Zitting

-- 
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development