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.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    }