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