You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2008/12/29 16:17:46 UTC

svn commit: r729915 - in /james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa: JPAMailbox.java om/MailboxMapper.java om/MailboxRow.java om/MessageMapper.java

Author: rdonkin
Date: Mon Dec 29 07:17:46 2008
New Revision: 729915

URL: http://svn.apache.org/viewvc?rev=729915&view=rev
Log:
Moved queries from POJOs to mapper

Modified:
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxRow.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MessageMapper.java

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java?rev=729915&r1=729914&r2=729915&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java Mon Dec 29 07:17:46 2008
@@ -104,7 +104,7 @@
             try {
                 checkAccess();
                 try {
-                    return getMailboxRow().countMessages();
+                    return messageMapper.countMessages(getMailboxRow().getMailboxId());
                 } catch (Exception e) {
                     throw new MailboxManagerException(e);
                 }
@@ -237,7 +237,7 @@
         final MailboxRow myMailboxRow;
         try {
             lock.writeLock().acquire();
-            myMailboxRow = getMailboxRow().consumeNextUid();
+            myMailboxRow = messageMapper.consumeNextUid(getMailboxRow().getMailboxId());
         } catch (TorqueException e) {
             throw new MailboxManagerException(e);
         } catch (SQLException e) {
@@ -332,7 +332,7 @@
                 }
 
                 if (reset) {
-                    mailboxRow.resetRecent();
+                    messageMapper.resetRecent(mailboxRow.getMailboxId());
                 }
                 return results;
             } catch (TorqueException e) {
@@ -389,8 +389,8 @@
             try {
                 checkAccess();
                 try {
-                    final int count = getMailboxRow().countMessages(
-                            new Flags(Flags.Flag.SEEN), false);
+                    final int count = messageMapper.countMessages(
+                            new Flags(Flags.Flag.SEEN), false, getMailboxRow().getMailboxId());
                     return count;
                 } catch (TorqueException e) {
                     throw new MailboxManagerException(e);

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java?rev=729915&r1=729914&r2=729915&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java Mon Dec 29 07:17:46 2008
@@ -21,12 +21,17 @@
 
 import java.util.List;
 
+import javax.mail.Flags;
+
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageRange;
 import org.apache.torque.TorqueException;
 import org.apache.torque.util.CountHelper;
 import org.apache.torque.util.Criteria;
 
+import com.workingdogs.village.DataSetException;
+import com.workingdogs.village.Record;
+
 /**
  * Data access management for mailbox.
  */
@@ -35,7 +40,7 @@
     public void save(MailboxRow mailbox) throws TorqueException {
         mailbox.save();
     }
-    
+
     /**
      * Finds a mailbox by name.
      * @param name not null
@@ -90,7 +95,7 @@
         List rows = MessageMapper.doSelectJoinMessageFlags(c);
         return rows;
     }
-    
+
     public List findMarkedForDeletionInMailbox(final MessageRange set, final MailboxRow mailboxRow) throws TorqueException, MailboxManagerException {
         final Criteria c = criteriaForMessageSet(set);
         c.addJoin(MessageRowPeer.MAILBOX_ID, MessageFlagsPeer.MAILBOX_ID);
@@ -101,7 +106,7 @@
         final List messageRows = mailboxRow.getMessageRows(c);
         return messageRows;
     }
-    
+
     private Criteria criteriaForMessageSet(MessageRange set) throws MailboxManagerException {
         Criteria criteria = new Criteria();
         criteria.addAscendingOrderByColumn(MessageRowPeer.UID);

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxRow.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxRow.java?rev=729915&r1=729914&r2=729915&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxRow.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxRow.java Mon Dec 29 07:17:46 2008
@@ -18,19 +18,7 @@
  ****************************************************************/
 package org.apache.james.imap.jpa.om;
 
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.List;
-
-import javax.mail.Flags;
-
-import org.apache.torque.TorqueException;
 import org.apache.torque.om.Persistent;
-import org.apache.torque.util.Criteria;
-import org.apache.torque.util.Transaction;
-
-import com.workingdogs.village.DataSetException;
-import com.workingdogs.village.Record;
 
 /**
  * The skeleton for this class was autogenerated by Torque on:
@@ -46,66 +34,8 @@
         Persistent {
 
     private static final long serialVersionUID = -8207690877715465485L;
-
-    public MailboxRow(String string, long uidValidity) {
-        this();
-        setName(string);
-        setUidValidity(uidValidity);
-    }
-
+    
     public MailboxRow() {
         super();
     }
-
-    public MailboxRow consumeNextUid() throws SQLException, TorqueException {
-        Connection c = Transaction.begin(MailboxRowPeer.DATABASE_NAME);
-        int ti = c.getTransactionIsolation();
-        boolean ac = c.getAutoCommit();
-        c.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
-        c.setAutoCommit(false);
-        try {
-            String sql = "UPDATE " + MailboxRowPeer.TABLE_NAME + " set "
-                    + MailboxRowPeer.LAST_UID + " = " + MailboxRowPeer.LAST_UID
-                    + "+1 WHERE " + MailboxRowPeer.MAILBOX_ID + " = "
-                    + getMailboxId();
-            MailboxRowPeer.executeStatement(sql, c);
-            MailboxRow mr = MailboxRowPeer.retrieveByPK(getMailboxId(), c);
-            Transaction.commit(c);
-            return mr;
-        } catch (TorqueException e) {
-            Transaction.safeRollback(c);
-            throw e;
-        } finally {
-            try {
-                c.setTransactionIsolation(ti);
-                c.setAutoCommit(ac);
-            } catch (Exception e) {
-            }
-        }
-
-    }
-
-    public int countMessages() throws TorqueException, DataSetException {
-        return countMessages(new Flags(), true);
-    }
-
-    public int countMessages(Flags flags, boolean value)
-            throws TorqueException, DataSetException {
-        Criteria criteria = new Criteria();
-        criteria.addSelectColumn(" COUNT(" + MessageFlagsPeer.UID + ") ");
-        criteria.add(MessageFlagsPeer.MAILBOX_ID, getMailboxId());
-        MessageMapper.addFlagsToCriteria(flags, value, criteria);
-        List result = MessageFlagsPeer.doSelectVillageRecords(criteria);
-        Record record = (Record) result.get(0);
-        int numberOfRecords = record.getValue(1).asInt();
-        return numberOfRecords;
-    }
-
-    public void resetRecent() throws TorqueException {
-        String sql = "UPDATE " + MessageFlagsPeer.TABLE_NAME + " set "
-                + MessageFlagsPeer.RECENT + " = 0 WHERE "
-                + MessageFlagsPeer.MAILBOX_ID + " = " + getMailboxId()
-                + " AND " + MessageFlagsPeer.RECENT + " = 1 ";
-        MessageFlagsPeer.executeStatement(sql);
-    }
 }

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MessageMapper.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MessageMapper.java?rev=729915&r1=729914&r2=729915&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MessageMapper.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MessageMapper.java Mon Dec 29 07:17:46 2008
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.imap.jpa.om;
 
+import java.sql.Connection;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -29,11 +31,64 @@
 import org.apache.torque.TorqueException;
 import org.apache.torque.util.BasePeer;
 import org.apache.torque.util.Criteria;
+import org.apache.torque.util.Transaction;
 
+import com.workingdogs.village.DataSetException;
 import com.workingdogs.village.Record;
 
 public class MessageMapper {
     
+    public MailboxRow consumeNextUid(long mailboxId) throws SQLException, TorqueException {
+        Connection c = Transaction.begin(MailboxRowPeer.DATABASE_NAME);
+        int ti = c.getTransactionIsolation();
+        boolean ac = c.getAutoCommit();
+        c.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
+        c.setAutoCommit(false);
+        try {
+            String sql = "UPDATE " + MailboxRowPeer.TABLE_NAME + " set "
+                    + MailboxRowPeer.LAST_UID + " = " + MailboxRowPeer.LAST_UID
+                    + "+1 WHERE " + MailboxRowPeer.MAILBOX_ID + " = "
+                    + mailboxId;
+            MailboxRowPeer.executeStatement(sql, c);
+            MailboxRow mr = MailboxRowPeer.retrieveByPK(mailboxId, c);
+            Transaction.commit(c);
+            return mr;
+        } catch (TorqueException e) {
+            Transaction.safeRollback(c);
+            throw e;
+        } finally {
+            try {
+                c.setTransactionIsolation(ti);
+                c.setAutoCommit(ac);
+            } catch (Exception e) {
+                // TODO: Log?
+            }
+        }
+    }
+
+    public void resetRecent(long mailboxId) throws TorqueException {
+        String sql = "UPDATE " + MessageFlagsPeer.TABLE_NAME + " set "
+                + MessageFlagsPeer.RECENT + " = 0 WHERE "
+                + MessageFlagsPeer.MAILBOX_ID + " = " + mailboxId
+                + " AND " + MessageFlagsPeer.RECENT + " = 1 ";
+        MessageFlagsPeer.executeStatement(sql);
+    }
+    
+    public int countMessages(long mailboxId) throws TorqueException, DataSetException {
+        return countMessages(new Flags(), true, mailboxId);
+    }
+    
+    public int countMessages(Flags flags, boolean value, long mailboxId)
+            throws TorqueException, DataSetException {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(" COUNT(" + MessageFlagsPeer.UID + ") ");
+        criteria.add(MessageFlagsPeer.MAILBOX_ID, mailboxId);
+        MessageMapper.addFlagsToCriteria(flags, value, criteria);
+        List result = MessageFlagsPeer.doSelectVillageRecords(criteria);
+        Record record = (Record) result.get(0);
+        int numberOfRecords = record.getValue(1).asInt();
+        return numberOfRecords;
+    }
 
     public List find(SearchQuery query) throws TorqueException {
         final Criteria criterion = preSelect(query);



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