001    /**
002     * Copyright (c) 2000-2011 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.dynamicdatamapping.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLink;
021    import com.liferay.portlet.dynamicdatamapping.service.base.DDMStructureLinkLocalServiceBaseImpl;
022    
023    import java.util.List;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     * @author Bruno Basto
028     */
029    public class DDMStructureLinkLocalServiceImpl
030            extends DDMStructureLinkLocalServiceBaseImpl {
031    
032            public DDMStructureLink addStructureLink(
033                            long classNameId, long classPK, long structureId,
034                            ServiceContext serviceContext)
035                    throws SystemException {
036    
037                    long structureLinkId = counterLocalService.increment();
038    
039                    DDMStructureLink structureLink =
040                            ddmStructureLinkPersistence.create(structureLinkId);
041    
042                    structureLink.setClassNameId(classNameId);
043                    structureLink.setClassPK(classPK);
044                    structureLink.setStructureId(structureId);
045    
046                    ddmStructureLinkPersistence.update(structureLink, false);
047    
048                    return structureLink;
049            }
050    
051            public void deleteClassStructureLink(long classPK)
052                    throws PortalException, SystemException {
053    
054                    DDMStructureLink structureLink =
055                            ddmStructureLinkPersistence.findByClassPK(classPK);
056    
057                    deleteStructureLink(structureLink);
058            }
059    
060            public void deleteStructureLink(DDMStructureLink structureLink)
061                    throws SystemException {
062    
063                    ddmStructureLinkPersistence.remove(structureLink);
064            }
065    
066            public void deleteStructureLink(long structureLinkId)
067                    throws PortalException, SystemException {
068    
069                    DDMStructureLink structureLink =
070                            ddmStructureLinkPersistence.findByPrimaryKey(structureLinkId);
071    
072                    deleteStructureLink(structureLink);
073            }
074    
075            public void deleteStructureStructureLinks(long structureId)
076                    throws SystemException {
077    
078                    List<DDMStructureLink> structureLinks =
079                            ddmStructureLinkPersistence.findByStructureId(structureId);
080    
081                    for (DDMStructureLink structureLink : structureLinks) {
082                            deleteStructureLink(structureLink);
083                    }
084            }
085    
086            public DDMStructureLink getClassStructureLink(long classPK)
087                    throws PortalException, SystemException {
088    
089                    return ddmStructureLinkPersistence.findByClassPK(classPK);
090            }
091    
092            public List<DDMStructureLink> getClassStructureLinks(long classNameId)
093                    throws SystemException {
094    
095                    return ddmStructureLinkPersistence.findByStructureId(classNameId);
096            }
097    
098            public DDMStructureLink getStructureLink(long structureLinkId)
099                    throws PortalException, SystemException {
100    
101                    return ddmStructureLinkPersistence.findByPrimaryKey(structureLinkId);
102            }
103    
104            public List<DDMStructureLink> getStructureLinks(
105                            long structureId, int start, int end)
106                    throws SystemException {
107    
108                    return ddmStructureLinkPersistence.findByStructureId(
109                            structureId, start, end);
110            }
111    
112            public DDMStructureLink updateStructureLink(
113                            long structureLinkId, long classNameId, long classPK,
114                            long structureId)
115                    throws PortalException, SystemException {
116    
117                    DDMStructureLink structureLink =
118                            ddmStructureLinkPersistence.findByPrimaryKey(structureLinkId);
119    
120                    structureLink.setClassNameId(classNameId);
121                    structureLink.setClassPK(classPK);
122                    structureLink.setStructureId(structureId);
123    
124                    ddmStructureLinkPersistence.update(structureLink, false);
125    
126                    return structureLink;
127            }
128    
129    }