james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1049933 - /james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRCachingUidProvider.java
Date Thu, 16 Dec 2010 11:18:11 GMT
Author: norman
Date: Thu Dec 16 11:18:10 2010
New Revision: 1049933

URL: http://svn.apache.org/viewvc?rev=1049933&view=rev
Log:
Fix query for last uid and make sure we close the Session

Modified:
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRCachingUidProvider.java

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRCachingUidProvider.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRCachingUidProvider.java?rev=1049933&r1=1049932&r2=1049933&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRCachingUidProvider.java
(original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRCachingUidProvider.java
Thu Dec 16 11:18:10 2010
@@ -53,10 +53,11 @@ public class JCRCachingUidProvider exten
      * @see org.apache.james.mailbox.store.CachingUidProvider#getLastUid(org.apache.james.mailbox.MailboxSession,
org.apache.james.mailbox.store.mail.model.Mailbox)
      */
     protected long getLastUid(MailboxSession session, Mailbox<String> mailbox) throws
MailboxException {
+        Session s = null;
         try {
-            Session s = repos.login(session);
+            s = repos.login(session);
             // we use order by because without it count will always be 0 in jackrabbit
-            String queryString = "/jcr:root/" + ISO9075.encodePath(s.getNodeByIdentifier(mailbox.getMailboxId()).getPath())
+ "//element(*,jamesMailbox:message) order by @" + JCRMessage.UID_PROPERTY + " desc";
+            String queryString = "/jcr:root/" + ISO9075.encodePath(s.getNodeByIdentifier(mailbox.getMailboxId()).getPath())
+ "//element(*,jamesMailbox:message) order by @" + JCRMessage.UID_PROPERTY + " descending";
             QueryManager manager = s.getWorkspace().getQueryManager();
             Query q = manager.createQuery(queryString, Query.XPATH);
             q.setLimit(1);
@@ -64,11 +65,14 @@ public class JCRCachingUidProvider exten
             NodeIterator nodes = result.getNodes();
             if (nodes.hasNext()) {
                 return nodes.nextNode().getProperty(JCRMessage.UID_PROPERTY).getLong();
-            } else {
-                return 0;
             }
+            return 0;
         } catch (RepositoryException e) {
             throw new MailboxException("Unable to count unseen messages in mailbox " + mailbox,
e);
+        } finally {
+            if (s != null) {
+                repos.logout(session);
+            }
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message