001    /**
002     * Copyright (c) 2000-2013 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            @Override
029            public VirtualHost fetchVirtualHost(long companyId, long layoutSetId)
030                    throws SystemException {
031    
032                    return virtualHostPersistence.fetchByC_L(companyId, layoutSetId);
033            }
034    
035            @Override
036            public VirtualHost fetchVirtualHost(String hostname)
037                    throws SystemException {
038    
039                    return virtualHostPersistence.fetchByHostname(hostname);
040            }
041    
042            @Override
043            public VirtualHost getVirtualHost(long companyId, long layoutSetId)
044                    throws PortalException, SystemException {
045    
046                    return virtualHostPersistence.findByC_L(companyId, layoutSetId);
047            }
048    
049            @Override
050            public VirtualHost getVirtualHost(String hostname)
051                    throws PortalException, SystemException {
052    
053                    return virtualHostPersistence.findByHostname(hostname);
054            }
055    
056            @Override
057            public VirtualHost updateVirtualHost(
058                            long companyId, long layoutSetId, String hostname)
059                    throws SystemException {
060    
061                    VirtualHost virtualHost = virtualHostPersistence.fetchByC_L(
062                            companyId, layoutSetId);
063    
064                    if (virtualHost == null) {
065                            long virtualHostId = counterLocalService.increment();
066    
067                            virtualHost = virtualHostPersistence.create(virtualHostId);
068    
069                            virtualHost.setCompanyId(companyId);
070                            virtualHost.setLayoutSetId(layoutSetId);
071                    }
072    
073                    virtualHost.setHostname(hostname);
074    
075                    virtualHostPersistence.update(virtualHost, false);
076    
077                    return virtualHost;
078            }
079    
080    }