Question

I'm using Modeshape and modeshape-connector-jdbc-metadata. I want to get all nodes representing tables in the storage. That nodes have [mj:catalog] mixin type.

I'm querying storage using next code:

    public List getDatabases() throws RepositoryException {
        // Obtain the query manager for the session ...
        QueryManager queryManager = dbSession.getWorkspace().getQueryManager();

        // Create a query object ...
        Query query = queryManager.createQuery("SELECT * FROM [mj:table]"
                , Query.JCR_SQL2);
        // Execute the query and get the results ...
        QueryResult result = query.execute();

        // Iterate over the nodes in the results ...
        NodeIterator nodeIter = result.getNodes();

        List stringResult = new ArrayList();
        while (nodeIter.hasNext()) {
            stringResult.add(nodeIter.nextNode().getName());
        }

        return stringResult;
    }

But it always returns empty list.

I also tried to query using next queries:

SELECT unst.*, tbl.* FROM [nt:unstructured] AS unst 
    JOIN [mj:table] AS tbl ON ISSAMENODE(unst,tbl)
SELECT * FROM [nt:unstructured] WHERE [jcr:mixinTypes] = [mj:table]

But result remains the same. What I'm doing wrong?

Thank you for any help.

Was it helpful?

Solution

There is a known issue that the database metadata nodes are not indexed automatically. A simple workaround is to cast the JCR Session's getWorkspace() instance to org.modeshape.jcr.api.Workspace (the public API for ModeShape's workspace) and call the reindex(String path) method and passing in the path to the database catalog node (or an ancestor if desired).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top