001    /**
002     * Copyright (c) 2000-2010 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            public MBDiscussion addDiscussion(
030                            long classNameId, long classPK, long threadId)
031                    throws SystemException {
032    
033                    long discussionId = counterLocalService.increment();
034    
035                    MBDiscussion discussion = mbDiscussionPersistence.create(discussionId);
036    
037                    discussion.setClassNameId(classNameId);
038                    discussion.setClassPK(classPK);
039                    discussion.setThreadId(threadId);
040    
041                    mbDiscussionPersistence.update(discussion, false);
042    
043                    return discussion;
044            }
045    
046            public MBDiscussion getDiscussion(long discussionId)
047                    throws PortalException, SystemException {
048    
049                    return mbDiscussionPersistence.findByPrimaryKey(discussionId);
050            }
051    
052            public MBDiscussion getDiscussion(String className, long classPK)
053                    throws PortalException, SystemException {
054    
055                    long classNameId = PortalUtil.getClassNameId(className);
056    
057                    return mbDiscussionPersistence.findByC_C(classNameId, classPK);
058            }
059    
060            public MBDiscussion getThreadDiscussion(long threadId)
061                    throws PortalException, SystemException {
062    
063                    return mbDiscussionPersistence.findByThreadId(threadId);
064            }
065    
066    }