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.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            public VirtualHost fetchVirtualHost(long companyId, long layoutSetId)
031                    throws SystemException {
032    
033                    return virtualHostPersistence.fetchByC_L(companyId, layoutSetId);
034            }
035    
036            public VirtualHost fetchVirtualHost(String hostname)
037                    throws SystemException {
038    
039                    return virtualHostPersistence.fetchByHostname(hostname);
040            }
041    
042            public VirtualHost getVirtualHost(long companyId, long layoutSetId)
043                    throws PortalException, SystemException {
044    
045                    return virtualHostPersistence.findByC_L(companyId, layoutSetId);
046            }
047    
048            public VirtualHost getVirtualHost(String hostname)
049                    throws PortalException, SystemException {
050    
051                    return virtualHostPersistence.findByHostname(hostname);
052            }
053    
054            public VirtualHost updateVirtualHost(
055                            long companyId, long layoutSetId, String hostname)
056                    throws SystemException {
057    
058                    VirtualHost virtualHost = virtualHostPersistence.fetchByC_L(
059                            companyId, layoutSetId);
060    
061                    if (virtualHost == null) {
062                            long virtualHostId = counterLocalService.increment();
063    
064                            virtualHost = virtualHostPersistence.create(virtualHostId);
065    
066                            virtualHost.setCompanyId(companyId);
067                            virtualHost.setLayoutSetId(layoutSetId);
068                    }
069    
070                    virtualHost.setHostname(hostname);
071    
072                    virtualHostPersistence.update(virtualHost);
073    
074                    Company company = companyPersistence.fetchByPrimaryKey(companyId);
075    
076                    if (company != null) {
077                            companyPersistence.clearCache(company);
078                    }
079    
080                    LayoutSet layoutSet = layoutSetPersistence.fetchByPrimaryKey(
081                            layoutSetId);
082    
083                    if (layoutSet != null) {
084                            layoutSetPersistence.clearCache(layoutSet);
085                    }
086    
087                    return virtualHost;
088            }
089    
090    }