Hello my friend. See your query result below:

<%@ page import="java.io.ByteArrayInputStream, java.util.Collections, java.util.GregorianCalendar, java.util.Iterator, java.util.Map, java.util.ServiceLoader, javax.jcr.Node, javax.jcr.Repository" %> <%@ page import="javax.jcr.RepositoryFactory, javax.jcr.Session, javax.jcr.query.*, javax.servlet.ServletException" %> <%@ page import="javax.jcr.observation.ObservationManager" %> <%@ page import="javax.jcr.observation.EventListener" %> <%@ page import="javax.jcr.observation.EventIterator" %> <%@ page import="org.modeshape.jcr.api.observation.Event" %> <%@ page import="java.util.concurrent.CountDownLatch" %> <%@ page import="java.util.concurrent.TimeUnit" %> <% // due diligence to request parameters // if (request.getParameter("repo") == null) { // throw new ServletException("you need to set a query parameter 'repo' so this test app works."); // } // if (!request.getParameter("repo").matches("^[-0-9a-zA-Z_.]+$")) { // throw new ServletException( // "only english letters, digits, dash, underline and dot are supported in repository name"); // } %> <% // the jndi URL is defined in the modeshape rest/webdav war web.xml // String configUrl = "jndi:jcr/local?repositoryName=" + request.getParameter( // "repo"); // URL that points to your configuration file String configUrl = getClass().getClassLoader().getResource("repository-config.json").toString(); Map parameters = Collections.singletonMap("org.modeshape.jcr.URL", configUrl); Repository repository = null; for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) { repository = factory.getRepository(parameters); if (repository != null) { break; } } if (repository == null) { throw new ServletException("cannot obtain repository " + configUrl + ". Is that deployed?"); } %>

<%= "We've got '" + configUrl + "'." %>

<% Session jcrSession = repository.login(); if (jcrSession == null) { throw new ServletException("cannot obtain session to repository '" + configUrl + "'"); } Node rn = jcrSession.getRootNode(); if (rn == null) { throw new ServletException("cannot obtain root node"); } %>

<%= "We've got a session in workspace '" + jcrSession.getWorkspace().getName() + "'." %>

   <%
       String fileName = "myfile.csv";
       String fileData = "SYMBOL,FULLNAME,PRICE\nBA,Boeing Company,58.11\nORCL,Oracle Corporation,147.12";
       //String fileMime = "application/octet-stream";
       GregorianCalendar lastModified = new GregorianCalendar(2011, 01, 13, 21, 59);

       // clean up directory files/ first
       try {
           rn.getNode("files").removeShare();
           if (jcrSession.hasPendingChanges()) {
               out.println("we have pending changes, saving..");
           }
           jcrSession.save();
           if (!jcrSession.hasPendingChanges()) {
               out.print("   now changes are saved");
           }
       } catch (javax.jcr.PathNotFoundException pnfe) {
           //ignore
       }
   %>

       <%
           Node dirNode = rn.addNode("files", "nt:folder");
           Node fileNode = rn.addNode("files/" + fileName, "nt:file");
           Node resNode = fileNode.addNode("jcr:content", "nt:resource");
           //resNode.setProperty("jcr:mimeType", fileMime);
           //resNode.setProperty("jcr:encoding", "");
           resNode.setProperty("jcr:data", jcrSession.getValueFactory().createValue(new ByteArrayInputStream(
                   fileData.getBytes())));
           resNode.setProperty("jcr:lastModified", lastModified);

           if (jcrSession.hasPendingChanges()) {
               out.println("we have pending changes, saving..");
           }

           //Before the session save, register a listener that will be notified when the sequencer finishes
           final JspWriter writer = out;
           final CountDownLatch sequencingLatch = new CountDownLatch(1);
           final long sequencingStart = System.currentTimeMillis();
           ObservationManager observationManager = jcrSession.getWorkspace().getObservationManager();
           observationManager.addEventListener(new EventListener() {
               @Override
               public void onEvent( EventIterator events ) {
                   try {
                       long sequecingDurationMillis = System.currentTimeMillis() - sequencingStart;
                       writer.println("Sequencing duration: " + sequecingDurationMillis + " milliseconds");
                   } catch (Exception e) {
                       throw new RuntimeException(e);
                   } finally {
                       sequencingLatch.countDown();
                   }
               }
           }, Event.Sequencing.NODE_SEQUENCED, null, true, null, null, false);


           jcrSession.save();
           if (!jcrSession.hasPendingChanges()) {
               out.print("   now changes are saved");
           }

           //block and wait max 5 seconds for the sequencing to finish
           out.println();
           out.println("Waiting for sequencing to finish...");
           if (!sequencingLatch.await(5, TimeUnit.SECONDS)) {
               out.println("Sequencing never finished...something went wrong");
           }
       %>
   
       
<%
       //ByteArrayOutputStream wsAsXml = new ByteArrayOutputStream();
       //jcrSession.exportSystemView("/" + fileName + "/", wsAsXml, false, false);
       //wsAsXml.close();
       //out.println(wsAsXml.toString());

       String sqlExpression = "SELECT * FROM [nt:file] where name() like '" + fileName + "')";
       QueryManager qm = jcrSession.getWorkspace().getQueryManager();
       Query query = qm.createQuery(sqlExpression, Query.JCR_SQL2);
       QueryResult qr = query.execute();

       out.println("Below see our file(s) in the workspace:");
       // you may also use NodeIterator
       Iterator it = qr.getNodes();

       // wait up to 15 seconds for indexes to get synced, for
       // rationale see http://issues.jboss.org/browse/MODE-1063
       long checkStart = System.currentTimeMillis();
       for (int i = 0; ; i++) {
           if (it.hasNext()) {
               out.println("INFO: waited for index sync " + (System.currentTimeMillis() - checkStart) + " milliseconds");
               break;
           }
           if (i == 30) {
               throw new ServletException("15 seconds not enough to get query indexes in sync");
           }
           Thread.sleep(5000);
           qr = query.execute();
           it = qr.getNodes();
       }

       while (it.hasNext()) {
           out.print("* ");
           Node n = it.next();

           out.println(n.getName() + ":" + n.getIdentifier());
           String content = n.getNode("jcr:content").getProperty("jcr:data").getString();
           out.println(content);

           if (!content.matches(fileData)) {
               out.println("!!! file content and what we see in repo does not match !!!");
           }
       }
   %>

       <%
           String ftsExpression = "SELECT * FROM [nt:base] WHERE CONTAINS( [nt:base].*, 'Boeing' )";
           Query ftsQuery = qm.createQuery(ftsExpression, Query.JCR_SQL2);
           QueryResult ftsResult = ftsQuery.execute();
           // Iterator ir = null;
           Iterator ir = qr.getNodes();
           out.println("Full text search query result below:");

           // wait for data to be sequenced
           checkStart = System.currentTimeMillis();
           for (int i = 0; ; i++) {

               //   ir = ftsResult.getRows();
               // out.println("iteration: " + i);
               if (ir.hasNext()) {
                   out.println(
                           "INFO: waited for sequencing and persisting " + (System.currentTimeMillis() - checkStart) + " miliseconds");
                   break;
               }
               if (i == 100) {
                   throw new ServletException("10 seconds not enough to sequence the file and persist the additional nodes");
               }
               Thread.sleep(100);
               ftsResult = ftsQuery.execute();
               ir = qr.getNodes();
           }

           while (ir.hasNext()) {
               Node n = ir.next();
               out.println("name:" + n.getName() + ", id:" + n.getIdentifier());
           }
       %>
   
           <%
               out.println("deleting our file(s)..");
               it = qr.getNodes();
               while (it.hasNext()) {
                   Node n = it.next();
                   n.remove();
               }

               checkStart = System.currentTimeMillis();

               dirNode.removeShare(); // remove the directory node also

               jcrSession.save();

               // lets make sure file(s) gone
               it = query.execute().getNodes();
               if (it.hasNext()) {
                   out.println("file(s) not deleted!?");
               } else {
                   out.println("file(s) gone");
               }

               // lets make sure sequenced data is gone
               for (int i = 0; ; i++) {
                   ir = ftsQuery.execute().getRows();
                   if (!ir.hasNext()) {
                       out.println("sequenced data gone in " + (System.currentTimeMillis() - checkStart) + " milliseconds");
                       break;
                   }
                   if (i == 100) {
                       out.println("sequenced data not deleted after 10 seconds!?");
                       break;
                   }
               }
           %>