jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Wehrens (JIRA)" <j...@apache.org>
Subject [jira] Commented: (JCR-392) Accessing element by number does not work
Date Wed, 12 Apr 2006 08:58:23 GMT
    [ http://issues.apache.org/jira/browse/JCR-392?page=comments#action_12374156 ] 

Oliver Wehrens commented on JCR-392:
------------------------------------

The full code for this example is:

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

import javax.jcr.*;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;

public class JackrabbitBug {


    public static void main(String[] args) {
        String configFile = "repository.xml";
        String repHomeDir = "repository";

        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 = null;
        try {

            ctx = new InitialContext(env);

            RegistryHelper.registerRepository(ctx,
                    "repo",
                    configFile,
                    repHomeDir,
                    true);

            Repository r = (Repository) ctx.lookup("repo");

            SimpleCredentials cred = new SimpleCredentials("userid", "".toCharArray());

            Session session = r.login(cred, null);
            Workspace ws = session.getWorkspace();
            Node rn = session.getRootNode();

            Query q;
            QueryManager qm = ws.getQueryManager();
            QueryResult qr;

            for (int i=0;i<6;i++) {
               Node child = rn.addNode("entry");
               child.setProperty("title", "title "+i);
               child.setProperty("content", "content "+i);
               session.save();
           }

            // try both position()=last() and entry[5] both do not work as expected
            System.out.println("Now it should display the last (or this 5th entry with //entry[5])");
            q = qm.createQuery("//entry[position()=last()]", Query.XPATH);
            qr = q.execute();
            NodeIterator it = qr.getNodes();
            while (it.hasNext()) {
                Node n = it.nextNode();
                System.out.println(n.getProperty("content").getValue().getString());
            }

        } catch (NamingException e) {
            e.printStackTrace();
        } catch (RepositoryException e) {
            e.printStackTrace();
        }
    }
}

> Accessing element by number does not work
> -----------------------------------------
>
>          Key: JCR-392
>          URL: http://issues.apache.org/jira/browse/JCR-392
>      Project: Jackrabbit
>         Type: Bug

>   Components: query
>  Environment: svn version 393179M
>     Reporter: Oliver Wehrens

>
> I have a bunch of wiki:entries stored in my workspace. If I create the following code:
>             q = qm.createQuery("//wiki:entry[5]", Query.XPATH);
>             qr = q.execute();
>             NodeIterator it = qr.getNodes();
> The Nodeiterator reports all entries back, bot just the 5th.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message