001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }