<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: return last object in a folder from a query? in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261337#M214467</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good call on using the OperationContext to save network traffic.&amp;nbsp; Don't know if the CMIS server-side will translate that into a better-performing query (like adding a LIMIT to the end of the select), but it certainly will help on the network side.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When you start to scale to hundreds-of-thousands or millions of objects, passing those "hints" back to the underlying DB engine is a huge win.&amp;nbsp; Of course, in this case you really can't "translate" the per-page request into a LIMIT, as it's a little different.&amp;nbsp; We need a way to pass something like that back though…whether it's in an OC setMaxItems (total), or allowing the query to be extended with optimization hints like LIMIT.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AJ&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Jun 2012 16:09:19 GMT</pubDate>
    <dc:creator>aweber1nj</dc:creator>
    <dc:date>2012-06-29T16:09:19Z</dc:date>
    <item>
      <title>return last object in a folder from a query?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261333#M214463</link>
      <description>So, from my early-learnings of CMIS and query-language, the lack of functions and joins is a bit of a drag…In order to return the last/latest object in a folder, I know I can use the in_folder( ) expression, but I don't have a way to choose max( ) on a column, right?&amp;nbsp; (As an aside, I would have like</description>
      <pubDate>Fri, 29 Jun 2012 15:09:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261333#M214463</guid>
      <dc:creator>aweber1nj</dc:creator>
      <dc:date>2012-06-29T15:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: return last object in a folder from a query?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261334#M214464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Probably the easiest thing to do is to order by cmis:lastModificationDate descending. And you can make it more efficient by setting maxItems to 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&amp;gt;&amp;gt;&amp;gt; query = "select cmis:objectId, cmis:name from cmis:document where cmis:name like 'test-plain%' order by cmis:lastModificationDate desc"&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; rs = repo.query(query, maxItems="1")&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; rs[0].name&lt;BR /&gt;u'test-plain-3.txt'&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;SPAN&gt;That file, test-plain-3.txt, is the most recently modified file matching the query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need to get the most recently modified doc in a folder, use the in_folder(folderId) clause, like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&amp;gt;&amp;gt;&amp;gt; folder = repo.getObjectByPath('/Sites/test-site-1/documentLibrary')&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; query = "select cmis:objectId, cmis:name from cmis:document where in_folder('%s') order by cmis:lastModificationDate desc" % folder.id&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; query&lt;BR /&gt;"select cmis:objectId, cmis:name from cmis:document where in_folder('workspace://SpacesStore/388e0fed-9104-4507-a702-30c4768e119b') order by cmis:lastModificationDate desc"&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; rs = repo.query(query, maxItems="1")&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; rs[0].name&lt;BR /&gt;u'test-plain-3.txt'&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;SPAN&gt;Yes, it sucks that I have to retrieve the folder first to get its ID just to build the in_folder clause.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 15:24:17 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261334#M214464</guid>
      <dc:creator>jpotts</dc:creator>
      <dc:date>2012-06-29T15:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: return last object in a folder from a query?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261335#M214465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Probably the easiest thing to do is to order by cmis:lastModificationDate descending. And you can make it more efficient by setting maxItems to 1.&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&amp;gt;&amp;gt;&amp;gt; query = "select cmis:objectId, cmis:name from cmis:document where cmis:name like 'test-plain%' order by cmis:lastModificationDate desc"&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; rs = repo.query(query, maxItems="1")&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; rs[0].name&lt;BR /&gt;u'test-plain-3.txt'&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Does that capability to set maxItems exist with OpenCMIS/Chemistry java classes?&amp;nbsp; I don't see a session.query( ) overload that would necessarily work like that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Yes, it sucks that I have to retrieve the folder first to get its ID just to build the in_folder clause.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Remember you mentioning this in your webinar.&amp;nbsp; Agree with your assessment. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://connect.hyland.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AJ&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 15:32:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261335#M214465</guid>
      <dc:creator>aweber1nj</dc:creator>
      <dc:date>2012-06-29T15:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: return last object in a folder from a query?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261336#M214466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry, I was trying to lay my &lt;/SPAN&gt;&lt;A href="http://xkcd.com/353/" rel="nofollow noopener noreferrer"&gt;Python trip&lt;/A&gt;&lt;SPAN&gt; on you, man. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://connect.hyland.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you look at the &lt;/SPAN&gt;&lt;A href="http://chemistry.apache.org/java/0.7.0/maven/apidocs/" rel="nofollow noopener noreferrer"&gt;JavaDoc for OpenCMIS&lt;/A&gt;&lt;SPAN&gt; you'll see that there is a version of the query method that takes an OperationContext. OperationContext has a method called setMaxItemsPerPage.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;String query = "select * from cmis:document";&lt;BR /&gt;OperationContext oc = new OperationContextImpl();&lt;BR /&gt;oc.setMaxItemsPerPage(5);&lt;BR /&gt;ItemIterable&amp;lt;QueryResult&amp;gt; q = getSession().query(query, false, oc);&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;SPAN&gt;So grab an OperationContext, call that method, then pass it in when you do the query. Voila. Now you're down with the OC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 16:01:14 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261336#M214466</guid>
      <dc:creator>jpotts</dc:creator>
      <dc:date>2012-06-29T16:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: return last object in a folder from a query?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261337#M214467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good call on using the OperationContext to save network traffic.&amp;nbsp; Don't know if the CMIS server-side will translate that into a better-performing query (like adding a LIMIT to the end of the select), but it certainly will help on the network side.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When you start to scale to hundreds-of-thousands or millions of objects, passing those "hints" back to the underlying DB engine is a huge win.&amp;nbsp; Of course, in this case you really can't "translate" the per-page request into a LIMIT, as it's a little different.&amp;nbsp; We need a way to pass something like that back though…whether it's in an OC setMaxItems (total), or allowing the query to be extended with optimization hints like LIMIT.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AJ&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 16:09:19 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/return-last-object-in-a-folder-from-a-query/m-p/261337#M214467</guid>
      <dc:creator>aweber1nj</dc:creator>
      <dc:date>2012-06-29T16:09:19Z</dc:date>
    </item>
  </channel>
</rss>

