printMessage("-------------------- MyQueryTest---------------------");
String descOrder = "SELECT [nt:file].[jcr:created] FROM [nt:file] INNER JOIN [nt:base] AS content ON ISCHILDNODE(content,[nt:file]) WHERE ([nt:file].[jcr:mixinTypes] = 'mix:simpleVersionable' AND NAME([nt:file]) LIKE 'f%') ORDER BY content.[jcr:lastModified] DESC";
String ascOrder = "SELECT [nt:file].[jcr:created] FROM [nt:file] INNER JOIN [nt:base] AS content ON ISCHILDNODE(content,[nt:file]) WHERE ([nt:file].[jcr:mixinTypes] = 'mix:simpleVersionable' AND NAME([nt:file]) LIKE 'f%') ORDER BY content.[jcr:lastModified] ASC";
QueryManager queryManager = session.getWorkspace().getQueryManager();
Query query = queryManager.createQuery(descOrder, Query.JCR_SQL2);
QueryResult result = query.execute();
// checking first query
RowIterator it = result.getRows();
assertEquals(2, it.getSize());
Node n1 = it.nextRow().getNode();
Node n2 = it.nextRow().getNode();
assertEquals("f2", n1.getName());
assertEquals("f1", n2.getName());
// the same request with other order
query = queryManager.createQuery(ascOrder, Query.JCR_SQL2);
result = query.execute();
// checking second query
it = result.getRows();
assertEquals(2, it.getSize());
n1 = it.nextRow().getNode();
n2 = it.nextRow().getNode();
assertEquals("f1", n1.getName());
assertEquals("f2", n2.getName());
// Try the XPath query ...
String descOrderX = "/jcr:root//element(*,nt:file)[(@jcr:mixinTypes = 'mix:simpleVersionable')] order by jcr:content/@jcr:lastModified descending";
String ascOrderX = "/jcr:root//element(*,nt:file)[(@jcr:mixinTypes = 'mix:simpleVersionable')] order by jcr:content/@jcr:lastModified ascending";
query = queryManager.createQuery(descOrderX, Query.XPATH);
result = query.execute();
// checking first query
it = result.getRows();
assertEquals(2, it.getSize());
n1 = it.nextRow().getNode();
n2 = it.nextRow().getNode();
assertEquals("f2", n1.getName());
assertEquals("f1", n2.getName());
// the same request with other order
query = queryManager.createQuery(ascOrderX, Query.XPATH);
result = query.execute();
// checking second query
it = result.getRows();
assertEquals(2, it.getSize());