0

I've read through the reference guide and the forums looking for a way to get to the data stored in a delimited (CSV) file using JCR and haven't found a solution yet. I've read that it's possible to access the underlying data as well as the metadata, I just don't know how.

I've looked at the "beginner's guide" on the Modeshape forums and modified the configuration to also use a delimited text sequencer. Then I added the csv file to the repo using identical code to what's in the forum.

When I query the repo using select * from [nt:file] I don't get any content, only nt:file metadata. I get the same when I query for [jcr:content] and [jcr:data].

So my question is, how do I query for the data in the CSV file once it's in the repository?

max
  • 2,346
  • 4
  • 26
  • 34

1 Answers1

1

Assuming the sequencing was successful, the structure of the output should be similar to what's defined here.

To query this content, one possibility is to build & execute a JCR_SQL2 query, like so:

String expr = "SELECT * FROM [text:column] WHERE [text:data] LIKE 'somestring'";
Query query = session.getWorkspace().getQueryManager().createQuery(expr, Query.JCR_SQL2);    
QueryResult result = query.execute(); 
RowIterator iter = result.getRows();
while (iter.hasNext()) {
     //your code
}

The query can be anything you need. Take a look at ModeShape's documentation for more information.

Note: This answer was originally posted as a response to the same question on ModeShape's forum.

Randall Hauch
  • 7,069
  • 31
  • 28