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