001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.messageboards.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.util.PortalUtil;
020    import com.liferay.portlet.messageboards.model.MBDiscussion;
021    import com.liferay.portlet.messageboards.service.base.MBDiscussionLocalServiceBaseImpl;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class MBDiscussionLocalServiceImpl
027            extends MBDiscussionLocalServiceBaseImpl {
028    
029            @Override
030            public MBDiscussion addDiscussion(
031                            long classNameId, long classPK, long threadId)
032                    throws SystemException {
033    
034                    long discussionId = counterLocalService.increment();
035    
036                    MBDiscussion discussion = mbDiscussionPersistence.create(discussionId);
037    
038                    discussion.setClassNameId(classNameId);
039                    discussion.setClassPK(classPK);
040                    discussion.setThreadId(threadId);
041    
042                    mbDiscussionPersistence.update(discussion, false);
043    
044                    return discussion;
045            }
046    
047            @Override
048            public MBDiscussion getDiscussion(long discussionId)
049                    throws PortalException, SystemException {
050    
051                    return mbDiscussionPersistence.findByPrimaryKey(discussionId);
052            }
053    
054            @Override
055            public MBDiscussion getDiscussion(String className, long classPK)
056                    throws PortalException, SystemException {
057    
058                    long classNameId = PortalUtil.getClassNameId(className);
059    
060                    return mbDiscussionPersistence.findByC_C(classNameId, classPK);
061            }
062    
063            @Override
064            public MBDiscussion getThreadDiscussion(long threadId)
065                    throws PortalException, SystemException {
066    
067                    return mbDiscussionPersistence.findByThreadId(threadId);
068            }
069    
070    }