001    /**
002     * Copyright (c) 2000-2012 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.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.DDMStorageLink;
021    import com.liferay.portlet.dynamicdatamapping.service.base.DDMStorageLinkLocalServiceBaseImpl;
022    
023    import java.util.List;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     * @author Eduardo Lundgren
028     */
029    public class DDMStorageLinkLocalServiceImpl
030            extends DDMStorageLinkLocalServiceBaseImpl {
031    
032            public DDMStorageLink addStorageLink(
033                            long classNameId, long classPK, long structureId,
034                            ServiceContext serviceContext)
035                    throws SystemException {
036    
037                    long storageLinkId = counterLocalService.increment();
038    
039                    DDMStorageLink storageLink = ddmStorageLinkPersistence.create(
040                            storageLinkId);
041    
042                    storageLink.setClassNameId(classNameId);
043                    storageLink.setClassPK(classPK);
044                    storageLink.setStructureId(structureId);
045    
046                    ddmStorageLinkPersistence.update(storageLink, false);
047    
048                    return storageLink;
049            }
050    
051            public void deleteClassStorageLink(long classPK)
052                    throws PortalException, SystemException {
053    
054                    DDMStorageLink storageLink = ddmStorageLinkPersistence.findByClassPK(
055                            classPK);
056    
057                    deleteStorageLink(storageLink);
058            }
059    
060            public void deleteStorageLink(DDMStorageLink storageLink)
061                    throws SystemException {
062    
063                    ddmStorageLinkPersistence.remove(storageLink);
064            }
065    
066            public void deleteStorageLink(long storageLinkId)
067                    throws PortalException, SystemException {
068    
069                    DDMStorageLink storageLink = ddmStorageLinkPersistence.findByPrimaryKey(
070                            storageLinkId);
071    
072                    deleteStorageLink(storageLink);
073            }
074    
075            public void deleteStructureStorageLinks(long structureId)
076                    throws SystemException {
077    
078                    List<DDMStorageLink> storageLinks =
079                            ddmStorageLinkPersistence.findByStructureId(structureId);
080    
081                    for (DDMStorageLink storageLink : storageLinks) {
082                            deleteStorageLink(storageLink);
083                    }
084            }
085    
086            public DDMStorageLink getClassStorageLink(long classPK)
087                    throws PortalException, SystemException {
088    
089                    return ddmStorageLinkPersistence.findByClassPK(classPK);
090            }
091    
092            public DDMStorageLink getStorageLink(long storageLinkId)
093                    throws PortalException, SystemException {
094    
095                    return ddmStorageLinkPersistence.findByPrimaryKey(storageLinkId);
096            }
097    
098            public List<DDMStorageLink> getStructureStorageLinks(long structureId)
099                    throws SystemException {
100    
101                    return ddmStorageLinkPersistence.findByStructureId(structureId);
102            }
103    
104            public DDMStorageLink updateStorageLink(
105                            long storageLinkId, long classNameId, long classPK)
106                    throws PortalException, SystemException {
107    
108                    DDMStorageLink storageLink = ddmStorageLinkPersistence.findByPrimaryKey(
109                            storageLinkId);
110    
111                    storageLink.setClassNameId(classNameId);
112                    storageLink.setClassPK(classPK);
113    
114                    ddmStorageLinkPersistence.update(storageLink, false);
115    
116                    return storageLink;
117            }
118    
119    }