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.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.VirtualHost;
020    import com.liferay.portal.service.base.VirtualHostLocalServiceBaseImpl;
021    
022    /**
023     * @author Alexander Chow
024     */
025    public class VirtualHostLocalServiceImpl
026            extends VirtualHostLocalServiceBaseImpl {
027    
028            public VirtualHost fetchVirtualHost(long companyId, long layoutSetId)
029                    throws SystemException {
030    
031                    return virtualHostPersistence.fetchByC_L(companyId, layoutSetId);
032            }
033    
034            public VirtualHost fetchVirtualHost(String hostname)
035                    throws SystemException {
036    
037                    return virtualHostPersistence.fetchByHostname(hostname);
038            }
039    
040            public VirtualHost getVirtualHost(long companyId, long layoutSetId)
041                    throws PortalException, SystemException {
042    
043                    return virtualHostPersistence.findByC_L(companyId, layoutSetId);
044            }
045    
046            public VirtualHost getVirtualHost(String hostname)
047                    throws PortalException, SystemException {
048    
049                    return virtualHostPersistence.findByHostname(hostname);
050            }
051    
052            public VirtualHost updateVirtualHost(
053                            long companyId, long layoutSetId, String hostname)
054                    throws SystemException {
055    
056                    VirtualHost virtualHost = virtualHostPersistence.fetchByC_L(
057                            companyId, layoutSetId);
058    
059                    if (virtualHost == null) {
060                            long virtualHostId = counterLocalService.increment();
061    
062                            virtualHost = virtualHostPersistence.create(virtualHostId);
063    
064                            virtualHost.setCompanyId(companyId);
065                            virtualHost.setLayoutSetId(layoutSetId);
066                    }
067    
068                    virtualHost.setHostname(hostname);
069    
070                    virtualHostPersistence.update(virtualHost, false);
071    
072                    return virtualHost;
073            }
074    
075    }