diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java index 6de70c6d8cf..0796fc0fd0d 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java @@ -67,7 +67,6 @@ import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder; import org.apache.openjpa.persistence.jdbc.ElementJoinColumn; import org.apache.openjpa.persistence.jdbc.ElementJoinColumns; -import org.apache.openjpa.persistence.jdbc.Index; import com.github.fge.lambdas.Throwing; import com.google.common.base.Objects; @@ -165,7 +164,6 @@ public boolean equals(Object obj) { private long uid; /** The value for the modSeq field */ - @Index @Column(name = "MAIL_MODSEQ") private long modSeq; @@ -182,7 +180,6 @@ public boolean equals(Object obj) { /** The value for the deleted field */ @Basic(optional = false) @Column(name = "MAIL_IS_DELETED", nullable = false) - @Index private boolean deleted = false; /** The value for the draft field */ @@ -198,13 +195,11 @@ public boolean equals(Object obj) { /** The value for the recent field */ @Basic(optional = false) @Column(name = "MAIL_IS_RECENT", nullable = false) - @Index private boolean recent = false; /** The value for the seen field */ @Basic(optional = false) @Column(name = "MAIL_IS_SEEN", nullable = false) - @Index private boolean seen = false; /** The first body octet */ diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java index 062017947ea..46bd18ac9d4 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java @@ -28,6 +28,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.Index; import javax.persistence.Lob; import javax.persistence.Table; @@ -45,11 +46,17 @@ import org.apache.openjpa.persistence.Factory; @Entity(name = "MailboxMessage") -@Table(name = "JAMES_MAIL") +@Table(name = "JAMES_MAIL", + indexes = { + @Index(name = "MAIL_IS_SEEN_INDEX", columnList = "MAILBOX_ID, MAIL_IS_SEEN"), + @Index(name = "MAIL_IS_RECENT_INDEX", columnList = "MAILBOX_ID, MAIL_IS_RECENT"), + @Index(name = "MAIL_IS_DELETED_INDEX", columnList = "MAILBOX_ID, MAIL_IS_DELETED"), + @Index(name = "MAIL_MODSEQ_INDEX", columnList = "MAILBOX_ID, MAIL_MODSEQ") + }) public class JPAEncryptedMailboxMessage extends AbstractJPAMailboxMessage { - /** The value for the body field. Lazy loaded */ - /** We use a max length to represent 1gb data. Thats prolly overkill, but who knows */ + /** The value for the body field. Lazy loaded + * We use a max length to represent 1gb data. Thats prolly overkill, but who knows */ @Basic(optional = false, fetch = FetchType.LAZY) @Column(name = "MAIL_BYTES", length = 1048576000, nullable = false) @Externalizer("EncryptDecryptHelper.getEncrypted") @@ -57,8 +64,8 @@ public class JPAEncryptedMailboxMessage extends AbstractJPAMailboxMessage { @Lob private byte[] body; - /** The value for the header field. Lazy loaded */ - /** We use a max length to represent 1gb data. Thats prolly overkill, but who knows */ + /** The value for the header field. Lazy loaded + * We use a max length to represent 1gb data. Thats prolly overkill, but who knows */ @Basic(optional = false, fetch = FetchType.LAZY) @Column(name = "HEADER_BYTES", length = 10485760, nullable = false) @Externalizer("EncryptDecryptHelper.getEncrypted") diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java index 2083b6a2374..858cad3a5ff 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java @@ -28,6 +28,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.Index; import javax.persistence.Lob; import javax.persistence.Table; @@ -45,20 +46,26 @@ import com.google.common.annotations.VisibleForTesting; @Entity(name = "MailboxMessage") -@Table(name = "JAMES_MAIL") +@Table(name = "JAMES_MAIL", +indexes = { + @Index(name = "MAIL_IS_SEEN_INDEX", columnList = "MAILBOX_ID, MAIL_IS_SEEN"), + @Index(name = "MAIL_IS_RECENT_INDEX", columnList = "MAILBOX_ID, MAIL_IS_RECENT"), + @Index(name = "MAIL_IS_DELETED_INDEX", columnList = "MAILBOX_ID, MAIL_IS_DELETED"), + @Index(name = "MAIL_MODSEQ_INDEX", columnList = "MAILBOX_ID, MAIL_MODSEQ") +}) public class JPAMailboxMessage extends AbstractJPAMailboxMessage { private static final byte[] EMPTY_BODY = new byte[] {}; - /** The value for the body field. Lazy loaded */ - /** We use a max length to represent 1gb data. Thats prolly overkill, but who knows */ + /** The value for the body field. Lazy loaded + * We use a max length to represent 1gb data. Thats prolly overkill, but who knows */ @Basic(optional = false, fetch = FetchType.LAZY) @Column(name = "MAIL_BYTES", length = 1048576000, nullable = false) @Lob private byte[] body; - /** The value for the header field. Lazy loaded */ - /** We use a max length to represent 10mb data. Thats prolly overkill, but who knows */ + /** The value for the header field. Lazy loaded + * We use a max length to represent 10mb data. Thats prolly overkill, but who knows */ @Basic(optional = false, fetch = FetchType.LAZY) @Column(name = "HEADER_BYTES", length = 10485760, nullable = false) @Lob private byte[] header; diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java index 8ffbd6090b3..b19956001bc 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java @@ -26,6 +26,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.Index; import javax.persistence.Table; import org.apache.commons.io.input.BoundedInputStream; @@ -50,7 +51,13 @@ * TODO: Fix me! */ @Entity(name = "MailboxMessage") -@Table(name = "JAMES_MAIL") +@Table(name = "JAMES_MAIL", + indexes = { + @Index(name = "MAIL_IS_SEEN_INDEX", columnList = "MAILBOX_ID, MAIL_IS_SEEN"), + @Index(name = "MAIL_IS_RECENT_INDEX", columnList = "MAILBOX_ID, MAIL_IS_RECENT"), + @Index(name = "MAIL_IS_DELETED_INDEX", columnList = "MAILBOX_ID, MAIL_IS_DELETED"), + @Index(name = "MAIL_MODSEQ_INDEX", columnList = "MAILBOX_ID, MAIL_MODSEQ") + }) public class JPAStreamingMailboxMessage extends AbstractJPAMailboxMessage { @Persistent(optional = false, fetch = FetchType.LAZY)