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.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.Company;
020    import com.liferay.portal.model.LayoutSet;
021    import com.liferay.portal.model.VirtualHost;
022    import com.liferay.portal.service.base.VirtualHostLocalServiceBaseImpl;
023    
024    /**
025     * @author Alexander Chow
026     */
027    public class VirtualHostLocalServiceImpl
028            extends VirtualHostLocalServiceBaseImpl {
029    
030            @Override
031            public VirtualHost fetchVirtualHost(long companyId, long layoutSetId)
032                    throws SystemException {
033    
034                    return virtualHostPersistence.fetchByC_L(companyId, layoutSetId);
035            }
036    
037            @Override
038            public VirtualHost fetchVirtualHost(String hostname)
039                    throws SystemException {
040    
041                    return virtualHostPersistence.fetchByHostname(hostname);
042            }
043    
044            @Override
045            public VirtualHost getVirtualHost(long companyId, long layoutSetId)
046                    throws PortalException, SystemException {
047    
048                    return virtualHostPersistence.findByC_L(companyId, layoutSetId);
049            }
050    
051            @Override
052            public VirtualHost getVirtualHost(String hostname)
053                    throws PortalException, SystemException {
054    
055                    return virtualHostPersistence.findByHostname(hostname);
056            }
057    
058            @Override
059            public VirtualHost updateVirtualHost(
060                            long companyId, long layoutSetId, String hostname)
061                    throws SystemException {
062    
063                    VirtualHost virtualHost = virtualHostPersistence.fetchByC_L(
064                            companyId, layoutSetId);
065    
066                    if (virtualHost == null) {
067                            long virtualHostId = counterLocalService.increment();
068    
069                            virtualHost = virtualHostPersistence.create(virtualHostId);
070    
071                            virtualHost.setCompanyId(companyId);
072                            virtualHost.setLayoutSetId(layoutSetId);
073                    }
074    
075                    virtualHost.setHostname(hostname);
076    
077                    virtualHostPersistence.update(virtualHost);
078    
079                    Company company = companyPersistence.fetchByPrimaryKey(companyId);
080    
081                    if (company != null) {
082                            companyPersistence.clearCache(company);
083                    }
084    
085                    LayoutSet layoutSet = layoutSetPersistence.fetchByPrimaryKey(
086                            layoutSetId);
087    
088                    if (layoutSet != null) {
089                            layoutSetPersistence.clearCache(layoutSet);
090                    }
091    
092                    return virtualHost;
093            }
094    
095    }