001    /****************************************************************
002     * Licensed to the Apache Software Foundation (ASF) under one   *
003     * or more contributor license agreements.  See the NOTICE file *
004     * distributed with this work for additional information        *
005     * regarding copyright ownership.  The ASF licenses this file   *
006     * to you under the Apache License, Version 2.0 (the            *
007     * "License"); you may not use this file except in compliance   *
008     * with the License.  You may obtain a copy of the License at   *
009     *                                                              *
010     *   http://www.apache.org/licenses/LICENSE-2.0                 *
011     *                                                              *
012     * Unless required by applicable law or agreed to in writing,   *
013     * software distributed under the License is distributed on an  *
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015     * KIND, either express or implied.  See the License for the    *
016     * specific language governing permissions and limitations      *
017     * under the License.                                           *
018     ****************************************************************/
019    
020    package org.apache.james.mailbox.jpa.openjpa;
021    
022    
023    import org.apache.james.mailbox.MailboxPathLocker;
024    import org.apache.james.mailbox.MailboxSession;
025    import org.apache.james.mailbox.acl.GroupMembershipResolver;
026    import org.apache.james.mailbox.acl.MailboxACLResolver;
027    import org.apache.james.mailbox.exception.MailboxException;
028    import org.apache.james.mailbox.jpa.JPAMailboxManager;
029    import org.apache.james.mailbox.jpa.JPAMailboxSessionMapperFactory;
030    import org.apache.james.mailbox.jpa.mail.model.openjpa.EncryptDecryptHelper;
031    import org.apache.james.mailbox.jpa.openjpa.OpenJPAMessageManager.AdvancedFeature;
032    import org.apache.james.mailbox.store.Authenticator;
033    import org.apache.james.mailbox.store.JVMMailboxPathLocker;
034    import org.apache.james.mailbox.store.StoreMessageManager;
035    import org.apache.james.mailbox.store.mail.model.Mailbox;
036    
037    /**
038     * OpenJPA implementation of MailboxManager
039     *
040     */
041    public class OpenJPAMailboxManager extends JPAMailboxManager {
042    
043        private AdvancedFeature feature;
044    
045        public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker, boolean useStreaming, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
046            super(mapperFactory, authenticator,  locker, aclResolver, groupMembershipResolver);
047            if (useStreaming) {
048                feature = AdvancedFeature.Streaming;
049            } else {
050                feature = AdvancedFeature.None;
051            }
052        }
053    
054        public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker,  String encryptPass, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
055            super(mapperFactory, authenticator,  locker, aclResolver, groupMembershipResolver);
056            if (encryptPass != null) {
057                EncryptDecryptHelper.init(encryptPass);
058                feature = AdvancedFeature.Encryption;
059            } else {
060                feature = AdvancedFeature.None;
061            }
062        }
063        
064        public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
065            this(mapperFactory, authenticator, new JVMMailboxPathLocker(), false, aclResolver, groupMembershipResolver);
066        }
067    
068        @Override
069        protected StoreMessageManager<Long> createMessageManager(Mailbox<Long> mailboxRow, MailboxSession session) throws MailboxException {
070            StoreMessageManager<Long> result =  new OpenJPAMessageManager(getMapperFactory(), getMessageSearchIndex(), getEventDispatcher(), getLocker(), mailboxRow, feature, getAclResolver(), getGroupMembershipResolver());
071            return result;
072        }
073    }