We can use the FileSystemRepositoryIntegrationTest.java to illustrate the issue, let us add some folders ie:folder1 & folder2 into the repository before running the unit tests.
@Override
public void beforeEach() throws Exception {
FileUtil.delete("target/fsRepoWithProps");
new File("target/fsRepoWithProps/root").mkdirs();
new File("target/fsRepoWithProps/root/defaultWorkspace/folder1").mkdirs();
new File("target/fsRepoWithProps/root/defaultWorkspace/folder2").mkdirs();
super.beforeEach();
}
Let us create a new unit @Test TestQueryingExistingContent() as below:
@Test
public void TestQueryingExistingContent() throws Exception {
startEngineUsing("config/configRepositoryForFileSystemWithExtraProperties.xml");
Session session = session();
session.getRootNode().addNode("NewFolder", "nt:folder");
session.save();
String sql = "SELECT * FROM [nt:base]";
Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
QueryResult result = query.execute();
System.out.println(result.toString());
logout();
}
The result of @Test TestQueryingExistingContent() :-
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.modeshape.test.integration.filesystem.FileSystemRepositoryIntegrationTest
+---+-----------------+------------+-----------+-----------+----------------+------------+------------------------------------------------------------------------------------+----------------+
| # | jcr:primaryType | jcr:path | jcr:name | jcr:score | mode:localName | mode:depth | Location(nt:base) | Score(nt:base) |
+---+-----------------+------------+-----------+-----------+----------------+------------+------------------------------------------------------------------------------------+----------------+
| 1 | mode:root | / | | 1.0 | | 0 | </ && [{http:| 2 | nt:folder | /NewFolder | NewFolder | 1.0 | NewFolder | 1 | /{}NewFolder | 1.0 |
+---+-----------------+------------+-----------+-----------+----------------+------------+------------------------------------------------------------------------------------+----------------+
As shown above, only the Root node and the newly created "NewFolder" node are returned by the Query. The Query won't address the existing "folder1" or "folder2", we can even put some text file into "folder1" or "folder2", it won't show either. So, all existing nodes (except Root node) before session start won't be addressed by the Query. Putting Thread.sleep(3000) before Query.execute() won't help either.
*Pls noted that for @Test shouldFindAllNodesWhenQueryingContent(), it doesn't address any existing nodes inside the Repository, all its print out via printQuery("SELECT * FROM [nt:base]", 5L, Collections.<String, String>emptyMap()); only return Root node and its newly created nodes after session started (Total 5 rows). However, this @Test still PASS, but by right, it should FAIL because we are expecting 7 rows returned due to the existing "folder1" & "folder2" and is not match with "5L". But of course, if we change the printQuery() -> "5L" to "7L", then this @Test will FAIL with Error:"Expected different number of rows from 'SELECT * FROM [nt:base]".