001    /**
002     * Copyright (c) 2000-present 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.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.exception.NoSuchVirtualHostException;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.model.CacheModel;
033    import com.liferay.portal.kernel.model.MVCCModel;
034    import com.liferay.portal.kernel.model.VirtualHost;
035    import com.liferay.portal.kernel.service.persistence.CompanyProvider;
036    import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
037    import com.liferay.portal.kernel.service.persistence.VirtualHostPersistence;
038    import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.model.impl.VirtualHostImpl;
043    import com.liferay.portal.model.impl.VirtualHostModelImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.Collections;
048    import java.util.HashMap;
049    import java.util.HashSet;
050    import java.util.Iterator;
051    import java.util.List;
052    import java.util.Map;
053    import java.util.Objects;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the virtual host service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see VirtualHostPersistence
065     * @see com.liferay.portal.kernel.service.persistence.VirtualHostUtil
066     * @generated
067     */
068    @ProviderType
069    public class VirtualHostPersistenceImpl extends BasePersistenceImpl<VirtualHost>
070            implements VirtualHostPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link VirtualHostUtil} to access the virtual host persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = VirtualHostImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
082                            VirtualHostModelImpl.FINDER_CACHE_ENABLED, VirtualHostImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
085                            VirtualHostModelImpl.FINDER_CACHE_ENABLED, VirtualHostImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
088                            VirtualHostModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_FETCH_BY_HOSTNAME = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
091                            VirtualHostModelImpl.FINDER_CACHE_ENABLED, VirtualHostImpl.class,
092                            FINDER_CLASS_NAME_ENTITY, "fetchByHostname",
093                            new String[] { String.class.getName() },
094                            VirtualHostModelImpl.HOSTNAME_COLUMN_BITMASK);
095            public static final FinderPath FINDER_PATH_COUNT_BY_HOSTNAME = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
096                            VirtualHostModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByHostname",
098                            new String[] { String.class.getName() });
099    
100            /**
101             * Returns the virtual host where hostname = &#63; or throws a {@link NoSuchVirtualHostException} if it could not be found.
102             *
103             * @param hostname the hostname
104             * @return the matching virtual host
105             * @throws NoSuchVirtualHostException if a matching virtual host could not be found
106             */
107            @Override
108            public VirtualHost findByHostname(String hostname)
109                    throws NoSuchVirtualHostException {
110                    VirtualHost virtualHost = fetchByHostname(hostname);
111    
112                    if (virtualHost == null) {
113                            StringBundler msg = new StringBundler(4);
114    
115                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
116    
117                            msg.append("hostname=");
118                            msg.append(hostname);
119    
120                            msg.append(StringPool.CLOSE_CURLY_BRACE);
121    
122                            if (_log.isDebugEnabled()) {
123                                    _log.debug(msg.toString());
124                            }
125    
126                            throw new NoSuchVirtualHostException(msg.toString());
127                    }
128    
129                    return virtualHost;
130            }
131    
132            /**
133             * Returns the virtual host where hostname = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
134             *
135             * @param hostname the hostname
136             * @return the matching virtual host, or <code>null</code> if a matching virtual host could not be found
137             */
138            @Override
139            public VirtualHost fetchByHostname(String hostname) {
140                    return fetchByHostname(hostname, true);
141            }
142    
143            /**
144             * Returns the virtual host where hostname = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
145             *
146             * @param hostname the hostname
147             * @param retrieveFromCache whether to retrieve from the finder cache
148             * @return the matching virtual host, or <code>null</code> if a matching virtual host could not be found
149             */
150            @Override
151            public VirtualHost fetchByHostname(String hostname,
152                    boolean retrieveFromCache) {
153                    Object[] finderArgs = new Object[] { hostname };
154    
155                    Object result = null;
156    
157                    if (retrieveFromCache) {
158                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_HOSTNAME,
159                                            finderArgs, this);
160                    }
161    
162                    if (result instanceof VirtualHost) {
163                            VirtualHost virtualHost = (VirtualHost)result;
164    
165                            if (!Objects.equals(hostname, virtualHost.getHostname())) {
166                                    result = null;
167                            }
168                    }
169    
170                    if (result == null) {
171                            StringBundler query = new StringBundler(3);
172    
173                            query.append(_SQL_SELECT_VIRTUALHOST_WHERE);
174    
175                            boolean bindHostname = false;
176    
177                            if (hostname == null) {
178                                    query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_1);
179                            }
180                            else if (hostname.equals(StringPool.BLANK)) {
181                                    query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_3);
182                            }
183                            else {
184                                    bindHostname = true;
185    
186                                    query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_2);
187                            }
188    
189                            String sql = query.toString();
190    
191                            Session session = null;
192    
193                            try {
194                                    session = openSession();
195    
196                                    Query q = session.createQuery(sql);
197    
198                                    QueryPos qPos = QueryPos.getInstance(q);
199    
200                                    if (bindHostname) {
201                                            qPos.add(hostname);
202                                    }
203    
204                                    List<VirtualHost> list = q.list();
205    
206                                    if (list.isEmpty()) {
207                                            finderCache.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
208                                                    finderArgs, list);
209                                    }
210                                    else {
211                                            VirtualHost virtualHost = list.get(0);
212    
213                                            result = virtualHost;
214    
215                                            cacheResult(virtualHost);
216    
217                                            if ((virtualHost.getHostname() == null) ||
218                                                            !virtualHost.getHostname().equals(hostname)) {
219                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
220                                                            finderArgs, virtualHost);
221                                            }
222                                    }
223                            }
224                            catch (Exception e) {
225                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME,
226                                            finderArgs);
227    
228                                    throw processException(e);
229                            }
230                            finally {
231                                    closeSession(session);
232                            }
233                    }
234    
235                    if (result instanceof List<?>) {
236                            return null;
237                    }
238                    else {
239                            return (VirtualHost)result;
240                    }
241            }
242    
243            /**
244             * Removes the virtual host where hostname = &#63; from the database.
245             *
246             * @param hostname the hostname
247             * @return the virtual host that was removed
248             */
249            @Override
250            public VirtualHost removeByHostname(String hostname)
251                    throws NoSuchVirtualHostException {
252                    VirtualHost virtualHost = findByHostname(hostname);
253    
254                    return remove(virtualHost);
255            }
256    
257            /**
258             * Returns the number of virtual hosts where hostname = &#63;.
259             *
260             * @param hostname the hostname
261             * @return the number of matching virtual hosts
262             */
263            @Override
264            public int countByHostname(String hostname) {
265                    FinderPath finderPath = FINDER_PATH_COUNT_BY_HOSTNAME;
266    
267                    Object[] finderArgs = new Object[] { hostname };
268    
269                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
270    
271                    if (count == null) {
272                            StringBundler query = new StringBundler(2);
273    
274                            query.append(_SQL_COUNT_VIRTUALHOST_WHERE);
275    
276                            boolean bindHostname = false;
277    
278                            if (hostname == null) {
279                                    query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_1);
280                            }
281                            else if (hostname.equals(StringPool.BLANK)) {
282                                    query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_3);
283                            }
284                            else {
285                                    bindHostname = true;
286    
287                                    query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_2);
288                            }
289    
290                            String sql = query.toString();
291    
292                            Session session = null;
293    
294                            try {
295                                    session = openSession();
296    
297                                    Query q = session.createQuery(sql);
298    
299                                    QueryPos qPos = QueryPos.getInstance(q);
300    
301                                    if (bindHostname) {
302                                            qPos.add(hostname);
303                                    }
304    
305                                    count = (Long)q.uniqueResult();
306    
307                                    finderCache.putResult(finderPath, finderArgs, count);
308                            }
309                            catch (Exception e) {
310                                    finderCache.removeResult(finderPath, finderArgs);
311    
312                                    throw processException(e);
313                            }
314                            finally {
315                                    closeSession(session);
316                            }
317                    }
318    
319                    return count.intValue();
320            }
321    
322            private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_1 = "virtualHost.hostname IS NULL";
323            private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_2 = "virtualHost.hostname = ?";
324            private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_3 = "(virtualHost.hostname IS NULL OR virtualHost.hostname = '')";
325            public static final FinderPath FINDER_PATH_FETCH_BY_C_L = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
326                            VirtualHostModelImpl.FINDER_CACHE_ENABLED, VirtualHostImpl.class,
327                            FINDER_CLASS_NAME_ENTITY, "fetchByC_L",
328                            new String[] { Long.class.getName(), Long.class.getName() },
329                            VirtualHostModelImpl.COMPANYID_COLUMN_BITMASK |
330                            VirtualHostModelImpl.LAYOUTSETID_COLUMN_BITMASK);
331            public static final FinderPath FINDER_PATH_COUNT_BY_C_L = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
332                            VirtualHostModelImpl.FINDER_CACHE_ENABLED, Long.class,
333                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_L",
334                            new String[] { Long.class.getName(), Long.class.getName() });
335    
336            /**
337             * Returns the virtual host where companyId = &#63; and layoutSetId = &#63; or throws a {@link NoSuchVirtualHostException} if it could not be found.
338             *
339             * @param companyId the company ID
340             * @param layoutSetId the layout set ID
341             * @return the matching virtual host
342             * @throws NoSuchVirtualHostException if a matching virtual host could not be found
343             */
344            @Override
345            public VirtualHost findByC_L(long companyId, long layoutSetId)
346                    throws NoSuchVirtualHostException {
347                    VirtualHost virtualHost = fetchByC_L(companyId, layoutSetId);
348    
349                    if (virtualHost == null) {
350                            StringBundler msg = new StringBundler(6);
351    
352                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
353    
354                            msg.append("companyId=");
355                            msg.append(companyId);
356    
357                            msg.append(", layoutSetId=");
358                            msg.append(layoutSetId);
359    
360                            msg.append(StringPool.CLOSE_CURLY_BRACE);
361    
362                            if (_log.isDebugEnabled()) {
363                                    _log.debug(msg.toString());
364                            }
365    
366                            throw new NoSuchVirtualHostException(msg.toString());
367                    }
368    
369                    return virtualHost;
370            }
371    
372            /**
373             * Returns the virtual host where companyId = &#63; and layoutSetId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
374             *
375             * @param companyId the company ID
376             * @param layoutSetId the layout set ID
377             * @return the matching virtual host, or <code>null</code> if a matching virtual host could not be found
378             */
379            @Override
380            public VirtualHost fetchByC_L(long companyId, long layoutSetId) {
381                    return fetchByC_L(companyId, layoutSetId, true);
382            }
383    
384            /**
385             * Returns the virtual host where companyId = &#63; and layoutSetId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
386             *
387             * @param companyId the company ID
388             * @param layoutSetId the layout set ID
389             * @param retrieveFromCache whether to retrieve from the finder cache
390             * @return the matching virtual host, or <code>null</code> if a matching virtual host could not be found
391             */
392            @Override
393            public VirtualHost fetchByC_L(long companyId, long layoutSetId,
394                    boolean retrieveFromCache) {
395                    Object[] finderArgs = new Object[] { companyId, layoutSetId };
396    
397                    Object result = null;
398    
399                    if (retrieveFromCache) {
400                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_L,
401                                            finderArgs, this);
402                    }
403    
404                    if (result instanceof VirtualHost) {
405                            VirtualHost virtualHost = (VirtualHost)result;
406    
407                            if ((companyId != virtualHost.getCompanyId()) ||
408                                            (layoutSetId != virtualHost.getLayoutSetId())) {
409                                    result = null;
410                            }
411                    }
412    
413                    if (result == null) {
414                            StringBundler query = new StringBundler(4);
415    
416                            query.append(_SQL_SELECT_VIRTUALHOST_WHERE);
417    
418                            query.append(_FINDER_COLUMN_C_L_COMPANYID_2);
419    
420                            query.append(_FINDER_COLUMN_C_L_LAYOUTSETID_2);
421    
422                            String sql = query.toString();
423    
424                            Session session = null;
425    
426                            try {
427                                    session = openSession();
428    
429                                    Query q = session.createQuery(sql);
430    
431                                    QueryPos qPos = QueryPos.getInstance(q);
432    
433                                    qPos.add(companyId);
434    
435                                    qPos.add(layoutSetId);
436    
437                                    List<VirtualHost> list = q.list();
438    
439                                    if (list.isEmpty()) {
440                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_L, finderArgs,
441                                                    list);
442                                    }
443                                    else {
444                                            VirtualHost virtualHost = list.get(0);
445    
446                                            result = virtualHost;
447    
448                                            cacheResult(virtualHost);
449    
450                                            if ((virtualHost.getCompanyId() != companyId) ||
451                                                            (virtualHost.getLayoutSetId() != layoutSetId)) {
452                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_L,
453                                                            finderArgs, virtualHost);
454                                            }
455                                    }
456                            }
457                            catch (Exception e) {
458                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_L, finderArgs);
459    
460                                    throw processException(e);
461                            }
462                            finally {
463                                    closeSession(session);
464                            }
465                    }
466    
467                    if (result instanceof List<?>) {
468                            return null;
469                    }
470                    else {
471                            return (VirtualHost)result;
472                    }
473            }
474    
475            /**
476             * Removes the virtual host where companyId = &#63; and layoutSetId = &#63; from the database.
477             *
478             * @param companyId the company ID
479             * @param layoutSetId the layout set ID
480             * @return the virtual host that was removed
481             */
482            @Override
483            public VirtualHost removeByC_L(long companyId, long layoutSetId)
484                    throws NoSuchVirtualHostException {
485                    VirtualHost virtualHost = findByC_L(companyId, layoutSetId);
486    
487                    return remove(virtualHost);
488            }
489    
490            /**
491             * Returns the number of virtual hosts where companyId = &#63; and layoutSetId = &#63;.
492             *
493             * @param companyId the company ID
494             * @param layoutSetId the layout set ID
495             * @return the number of matching virtual hosts
496             */
497            @Override
498            public int countByC_L(long companyId, long layoutSetId) {
499                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_L;
500    
501                    Object[] finderArgs = new Object[] { companyId, layoutSetId };
502    
503                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
504    
505                    if (count == null) {
506                            StringBundler query = new StringBundler(3);
507    
508                            query.append(_SQL_COUNT_VIRTUALHOST_WHERE);
509    
510                            query.append(_FINDER_COLUMN_C_L_COMPANYID_2);
511    
512                            query.append(_FINDER_COLUMN_C_L_LAYOUTSETID_2);
513    
514                            String sql = query.toString();
515    
516                            Session session = null;
517    
518                            try {
519                                    session = openSession();
520    
521                                    Query q = session.createQuery(sql);
522    
523                                    QueryPos qPos = QueryPos.getInstance(q);
524    
525                                    qPos.add(companyId);
526    
527                                    qPos.add(layoutSetId);
528    
529                                    count = (Long)q.uniqueResult();
530    
531                                    finderCache.putResult(finderPath, finderArgs, count);
532                            }
533                            catch (Exception e) {
534                                    finderCache.removeResult(finderPath, finderArgs);
535    
536                                    throw processException(e);
537                            }
538                            finally {
539                                    closeSession(session);
540                            }
541                    }
542    
543                    return count.intValue();
544            }
545    
546            private static final String _FINDER_COLUMN_C_L_COMPANYID_2 = "virtualHost.companyId = ? AND ";
547            private static final String _FINDER_COLUMN_C_L_LAYOUTSETID_2 = "virtualHost.layoutSetId = ?";
548    
549            public VirtualHostPersistenceImpl() {
550                    setModelClass(VirtualHost.class);
551            }
552    
553            /**
554             * Caches the virtual host in the entity cache if it is enabled.
555             *
556             * @param virtualHost the virtual host
557             */
558            @Override
559            public void cacheResult(VirtualHost virtualHost) {
560                    entityCache.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
561                            VirtualHostImpl.class, virtualHost.getPrimaryKey(), virtualHost);
562    
563                    finderCache.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
564                            new Object[] { virtualHost.getHostname() }, virtualHost);
565    
566                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_L,
567                            new Object[] {
568                                    virtualHost.getCompanyId(), virtualHost.getLayoutSetId()
569                            }, virtualHost);
570    
571                    virtualHost.resetOriginalValues();
572            }
573    
574            /**
575             * Caches the virtual hosts in the entity cache if it is enabled.
576             *
577             * @param virtualHosts the virtual hosts
578             */
579            @Override
580            public void cacheResult(List<VirtualHost> virtualHosts) {
581                    for (VirtualHost virtualHost : virtualHosts) {
582                            if (entityCache.getResult(
583                                                    VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
584                                                    VirtualHostImpl.class, virtualHost.getPrimaryKey()) == null) {
585                                    cacheResult(virtualHost);
586                            }
587                            else {
588                                    virtualHost.resetOriginalValues();
589                            }
590                    }
591            }
592    
593            /**
594             * Clears the cache for all virtual hosts.
595             *
596             * <p>
597             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
598             * </p>
599             */
600            @Override
601            public void clearCache() {
602                    entityCache.clearCache(VirtualHostImpl.class);
603    
604                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
605                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
606                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
607            }
608    
609            /**
610             * Clears the cache for the virtual host.
611             *
612             * <p>
613             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
614             * </p>
615             */
616            @Override
617            public void clearCache(VirtualHost virtualHost) {
618                    entityCache.removeResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
619                            VirtualHostImpl.class, virtualHost.getPrimaryKey());
620    
621                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
622                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
623    
624                    clearUniqueFindersCache((VirtualHostModelImpl)virtualHost);
625            }
626    
627            @Override
628            public void clearCache(List<VirtualHost> virtualHosts) {
629                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
630                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
631    
632                    for (VirtualHost virtualHost : virtualHosts) {
633                            entityCache.removeResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
634                                    VirtualHostImpl.class, virtualHost.getPrimaryKey());
635    
636                            clearUniqueFindersCache((VirtualHostModelImpl)virtualHost);
637                    }
638            }
639    
640            protected void cacheUniqueFindersCache(
641                    VirtualHostModelImpl virtualHostModelImpl, boolean isNew) {
642                    if (isNew) {
643                            Object[] args = new Object[] { virtualHostModelImpl.getHostname() };
644    
645                            finderCache.putResult(FINDER_PATH_COUNT_BY_HOSTNAME, args,
646                                    Long.valueOf(1));
647                            finderCache.putResult(FINDER_PATH_FETCH_BY_HOSTNAME, args,
648                                    virtualHostModelImpl);
649    
650                            args = new Object[] {
651                                            virtualHostModelImpl.getCompanyId(),
652                                            virtualHostModelImpl.getLayoutSetId()
653                                    };
654    
655                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_L, args,
656                                    Long.valueOf(1));
657                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_L, args,
658                                    virtualHostModelImpl);
659                    }
660                    else {
661                            if ((virtualHostModelImpl.getColumnBitmask() &
662                                            FINDER_PATH_FETCH_BY_HOSTNAME.getColumnBitmask()) != 0) {
663                                    Object[] args = new Object[] { virtualHostModelImpl.getHostname() };
664    
665                                    finderCache.putResult(FINDER_PATH_COUNT_BY_HOSTNAME, args,
666                                            Long.valueOf(1));
667                                    finderCache.putResult(FINDER_PATH_FETCH_BY_HOSTNAME, args,
668                                            virtualHostModelImpl);
669                            }
670    
671                            if ((virtualHostModelImpl.getColumnBitmask() &
672                                            FINDER_PATH_FETCH_BY_C_L.getColumnBitmask()) != 0) {
673                                    Object[] args = new Object[] {
674                                                    virtualHostModelImpl.getCompanyId(),
675                                                    virtualHostModelImpl.getLayoutSetId()
676                                            };
677    
678                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_L, args,
679                                            Long.valueOf(1));
680                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_L, args,
681                                            virtualHostModelImpl);
682                            }
683                    }
684            }
685    
686            protected void clearUniqueFindersCache(
687                    VirtualHostModelImpl virtualHostModelImpl) {
688                    Object[] args = new Object[] { virtualHostModelImpl.getHostname() };
689    
690                    finderCache.removeResult(FINDER_PATH_COUNT_BY_HOSTNAME, args);
691                    finderCache.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME, args);
692    
693                    if ((virtualHostModelImpl.getColumnBitmask() &
694                                    FINDER_PATH_FETCH_BY_HOSTNAME.getColumnBitmask()) != 0) {
695                            args = new Object[] { virtualHostModelImpl.getOriginalHostname() };
696    
697                            finderCache.removeResult(FINDER_PATH_COUNT_BY_HOSTNAME, args);
698                            finderCache.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME, args);
699                    }
700    
701                    args = new Object[] {
702                                    virtualHostModelImpl.getCompanyId(),
703                                    virtualHostModelImpl.getLayoutSetId()
704                            };
705    
706                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_L, args);
707                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_L, args);
708    
709                    if ((virtualHostModelImpl.getColumnBitmask() &
710                                    FINDER_PATH_FETCH_BY_C_L.getColumnBitmask()) != 0) {
711                            args = new Object[] {
712                                            virtualHostModelImpl.getOriginalCompanyId(),
713                                            virtualHostModelImpl.getOriginalLayoutSetId()
714                                    };
715    
716                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_L, args);
717                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_L, args);
718                    }
719            }
720    
721            /**
722             * Creates a new virtual host with the primary key. Does not add the virtual host to the database.
723             *
724             * @param virtualHostId the primary key for the new virtual host
725             * @return the new virtual host
726             */
727            @Override
728            public VirtualHost create(long virtualHostId) {
729                    VirtualHost virtualHost = new VirtualHostImpl();
730    
731                    virtualHost.setNew(true);
732                    virtualHost.setPrimaryKey(virtualHostId);
733    
734                    virtualHost.setCompanyId(companyProvider.getCompanyId());
735    
736                    return virtualHost;
737            }
738    
739            /**
740             * Removes the virtual host with the primary key from the database. Also notifies the appropriate model listeners.
741             *
742             * @param virtualHostId the primary key of the virtual host
743             * @return the virtual host that was removed
744             * @throws NoSuchVirtualHostException if a virtual host with the primary key could not be found
745             */
746            @Override
747            public VirtualHost remove(long virtualHostId)
748                    throws NoSuchVirtualHostException {
749                    return remove((Serializable)virtualHostId);
750            }
751    
752            /**
753             * Removes the virtual host with the primary key from the database. Also notifies the appropriate model listeners.
754             *
755             * @param primaryKey the primary key of the virtual host
756             * @return the virtual host that was removed
757             * @throws NoSuchVirtualHostException if a virtual host with the primary key could not be found
758             */
759            @Override
760            public VirtualHost remove(Serializable primaryKey)
761                    throws NoSuchVirtualHostException {
762                    Session session = null;
763    
764                    try {
765                            session = openSession();
766    
767                            VirtualHost virtualHost = (VirtualHost)session.get(VirtualHostImpl.class,
768                                            primaryKey);
769    
770                            if (virtualHost == null) {
771                                    if (_log.isDebugEnabled()) {
772                                            _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
773                                    }
774    
775                                    throw new NoSuchVirtualHostException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
776                                            primaryKey);
777                            }
778    
779                            return remove(virtualHost);
780                    }
781                    catch (NoSuchVirtualHostException nsee) {
782                            throw nsee;
783                    }
784                    catch (Exception e) {
785                            throw processException(e);
786                    }
787                    finally {
788                            closeSession(session);
789                    }
790            }
791    
792            @Override
793            protected VirtualHost removeImpl(VirtualHost virtualHost) {
794                    virtualHost = toUnwrappedModel(virtualHost);
795    
796                    Session session = null;
797    
798                    try {
799                            session = openSession();
800    
801                            if (!session.contains(virtualHost)) {
802                                    virtualHost = (VirtualHost)session.get(VirtualHostImpl.class,
803                                                    virtualHost.getPrimaryKeyObj());
804                            }
805    
806                            if (virtualHost != null) {
807                                    session.delete(virtualHost);
808                            }
809                    }
810                    catch (Exception e) {
811                            throw processException(e);
812                    }
813                    finally {
814                            closeSession(session);
815                    }
816    
817                    if (virtualHost != null) {
818                            clearCache(virtualHost);
819                    }
820    
821                    return virtualHost;
822            }
823    
824            @Override
825            public VirtualHost updateImpl(VirtualHost virtualHost) {
826                    virtualHost = toUnwrappedModel(virtualHost);
827    
828                    boolean isNew = virtualHost.isNew();
829    
830                    VirtualHostModelImpl virtualHostModelImpl = (VirtualHostModelImpl)virtualHost;
831    
832                    Session session = null;
833    
834                    try {
835                            session = openSession();
836    
837                            if (virtualHost.isNew()) {
838                                    session.save(virtualHost);
839    
840                                    virtualHost.setNew(false);
841                            }
842                            else {
843                                    virtualHost = (VirtualHost)session.merge(virtualHost);
844                            }
845                    }
846                    catch (Exception e) {
847                            throw processException(e);
848                    }
849                    finally {
850                            closeSession(session);
851                    }
852    
853                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
854    
855                    if (isNew || !VirtualHostModelImpl.COLUMN_BITMASK_ENABLED) {
856                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
857                    }
858    
859                    entityCache.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
860                            VirtualHostImpl.class, virtualHost.getPrimaryKey(), virtualHost,
861                            false);
862    
863                    clearUniqueFindersCache(virtualHostModelImpl);
864                    cacheUniqueFindersCache(virtualHostModelImpl, isNew);
865    
866                    virtualHost.resetOriginalValues();
867    
868                    return virtualHost;
869            }
870    
871            protected VirtualHost toUnwrappedModel(VirtualHost virtualHost) {
872                    if (virtualHost instanceof VirtualHostImpl) {
873                            return virtualHost;
874                    }
875    
876                    VirtualHostImpl virtualHostImpl = new VirtualHostImpl();
877    
878                    virtualHostImpl.setNew(virtualHost.isNew());
879                    virtualHostImpl.setPrimaryKey(virtualHost.getPrimaryKey());
880    
881                    virtualHostImpl.setMvccVersion(virtualHost.getMvccVersion());
882                    virtualHostImpl.setVirtualHostId(virtualHost.getVirtualHostId());
883                    virtualHostImpl.setCompanyId(virtualHost.getCompanyId());
884                    virtualHostImpl.setLayoutSetId(virtualHost.getLayoutSetId());
885                    virtualHostImpl.setHostname(virtualHost.getHostname());
886    
887                    return virtualHostImpl;
888            }
889    
890            /**
891             * Returns the virtual host with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
892             *
893             * @param primaryKey the primary key of the virtual host
894             * @return the virtual host
895             * @throws NoSuchVirtualHostException if a virtual host with the primary key could not be found
896             */
897            @Override
898            public VirtualHost findByPrimaryKey(Serializable primaryKey)
899                    throws NoSuchVirtualHostException {
900                    VirtualHost virtualHost = fetchByPrimaryKey(primaryKey);
901    
902                    if (virtualHost == null) {
903                            if (_log.isDebugEnabled()) {
904                                    _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
905                            }
906    
907                            throw new NoSuchVirtualHostException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
908                                    primaryKey);
909                    }
910    
911                    return virtualHost;
912            }
913    
914            /**
915             * Returns the virtual host with the primary key or throws a {@link NoSuchVirtualHostException} if it could not be found.
916             *
917             * @param virtualHostId the primary key of the virtual host
918             * @return the virtual host
919             * @throws NoSuchVirtualHostException if a virtual host with the primary key could not be found
920             */
921            @Override
922            public VirtualHost findByPrimaryKey(long virtualHostId)
923                    throws NoSuchVirtualHostException {
924                    return findByPrimaryKey((Serializable)virtualHostId);
925            }
926    
927            /**
928             * Returns the virtual host with the primary key or returns <code>null</code> if it could not be found.
929             *
930             * @param primaryKey the primary key of the virtual host
931             * @return the virtual host, or <code>null</code> if a virtual host with the primary key could not be found
932             */
933            @Override
934            public VirtualHost fetchByPrimaryKey(Serializable primaryKey) {
935                    VirtualHost virtualHost = (VirtualHost)entityCache.getResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
936                                    VirtualHostImpl.class, primaryKey);
937    
938                    if (virtualHost == _nullVirtualHost) {
939                            return null;
940                    }
941    
942                    if (virtualHost == null) {
943                            Session session = null;
944    
945                            try {
946                                    session = openSession();
947    
948                                    virtualHost = (VirtualHost)session.get(VirtualHostImpl.class,
949                                                    primaryKey);
950    
951                                    if (virtualHost != null) {
952                                            cacheResult(virtualHost);
953                                    }
954                                    else {
955                                            entityCache.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
956                                                    VirtualHostImpl.class, primaryKey, _nullVirtualHost);
957                                    }
958                            }
959                            catch (Exception e) {
960                                    entityCache.removeResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
961                                            VirtualHostImpl.class, primaryKey);
962    
963                                    throw processException(e);
964                            }
965                            finally {
966                                    closeSession(session);
967                            }
968                    }
969    
970                    return virtualHost;
971            }
972    
973            /**
974             * Returns the virtual host with the primary key or returns <code>null</code> if it could not be found.
975             *
976             * @param virtualHostId the primary key of the virtual host
977             * @return the virtual host, or <code>null</code> if a virtual host with the primary key could not be found
978             */
979            @Override
980            public VirtualHost fetchByPrimaryKey(long virtualHostId) {
981                    return fetchByPrimaryKey((Serializable)virtualHostId);
982            }
983    
984            @Override
985            public Map<Serializable, VirtualHost> fetchByPrimaryKeys(
986                    Set<Serializable> primaryKeys) {
987                    if (primaryKeys.isEmpty()) {
988                            return Collections.emptyMap();
989                    }
990    
991                    Map<Serializable, VirtualHost> map = new HashMap<Serializable, VirtualHost>();
992    
993                    if (primaryKeys.size() == 1) {
994                            Iterator<Serializable> iterator = primaryKeys.iterator();
995    
996                            Serializable primaryKey = iterator.next();
997    
998                            VirtualHost virtualHost = fetchByPrimaryKey(primaryKey);
999    
1000                            if (virtualHost != null) {
1001                                    map.put(primaryKey, virtualHost);
1002                            }
1003    
1004                            return map;
1005                    }
1006    
1007                    Set<Serializable> uncachedPrimaryKeys = null;
1008    
1009                    for (Serializable primaryKey : primaryKeys) {
1010                            VirtualHost virtualHost = (VirtualHost)entityCache.getResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
1011                                            VirtualHostImpl.class, primaryKey);
1012    
1013                            if (virtualHost == null) {
1014                                    if (uncachedPrimaryKeys == null) {
1015                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1016                                    }
1017    
1018                                    uncachedPrimaryKeys.add(primaryKey);
1019                            }
1020                            else {
1021                                    map.put(primaryKey, virtualHost);
1022                            }
1023                    }
1024    
1025                    if (uncachedPrimaryKeys == null) {
1026                            return map;
1027                    }
1028    
1029                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1030                                    1);
1031    
1032                    query.append(_SQL_SELECT_VIRTUALHOST_WHERE_PKS_IN);
1033    
1034                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1035                            query.append(String.valueOf(primaryKey));
1036    
1037                            query.append(StringPool.COMMA);
1038                    }
1039    
1040                    query.setIndex(query.index() - 1);
1041    
1042                    query.append(StringPool.CLOSE_PARENTHESIS);
1043    
1044                    String sql = query.toString();
1045    
1046                    Session session = null;
1047    
1048                    try {
1049                            session = openSession();
1050    
1051                            Query q = session.createQuery(sql);
1052    
1053                            for (VirtualHost virtualHost : (List<VirtualHost>)q.list()) {
1054                                    map.put(virtualHost.getPrimaryKeyObj(), virtualHost);
1055    
1056                                    cacheResult(virtualHost);
1057    
1058                                    uncachedPrimaryKeys.remove(virtualHost.getPrimaryKeyObj());
1059                            }
1060    
1061                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1062                                    entityCache.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
1063                                            VirtualHostImpl.class, primaryKey, _nullVirtualHost);
1064                            }
1065                    }
1066                    catch (Exception e) {
1067                            throw processException(e);
1068                    }
1069                    finally {
1070                            closeSession(session);
1071                    }
1072    
1073                    return map;
1074            }
1075    
1076            /**
1077             * Returns all the virtual hosts.
1078             *
1079             * @return the virtual hosts
1080             */
1081            @Override
1082            public List<VirtualHost> findAll() {
1083                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1084            }
1085    
1086            /**
1087             * Returns a range of all the virtual hosts.
1088             *
1089             * <p>
1090             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link VirtualHostModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1091             * </p>
1092             *
1093             * @param start the lower bound of the range of virtual hosts
1094             * @param end the upper bound of the range of virtual hosts (not inclusive)
1095             * @return the range of virtual hosts
1096             */
1097            @Override
1098            public List<VirtualHost> findAll(int start, int end) {
1099                    return findAll(start, end, null);
1100            }
1101    
1102            /**
1103             * Returns an ordered range of all the virtual hosts.
1104             *
1105             * <p>
1106             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link VirtualHostModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1107             * </p>
1108             *
1109             * @param start the lower bound of the range of virtual hosts
1110             * @param end the upper bound of the range of virtual hosts (not inclusive)
1111             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1112             * @return the ordered range of virtual hosts
1113             */
1114            @Override
1115            public List<VirtualHost> findAll(int start, int end,
1116                    OrderByComparator<VirtualHost> orderByComparator) {
1117                    return findAll(start, end, orderByComparator, true);
1118            }
1119    
1120            /**
1121             * Returns an ordered range of all the virtual hosts.
1122             *
1123             * <p>
1124             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link VirtualHostModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1125             * </p>
1126             *
1127             * @param start the lower bound of the range of virtual hosts
1128             * @param end the upper bound of the range of virtual hosts (not inclusive)
1129             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1130             * @param retrieveFromCache whether to retrieve from the finder cache
1131             * @return the ordered range of virtual hosts
1132             */
1133            @Override
1134            public List<VirtualHost> findAll(int start, int end,
1135                    OrderByComparator<VirtualHost> orderByComparator,
1136                    boolean retrieveFromCache) {
1137                    boolean pagination = true;
1138                    FinderPath finderPath = null;
1139                    Object[] finderArgs = null;
1140    
1141                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1142                                    (orderByComparator == null)) {
1143                            pagination = false;
1144                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1145                            finderArgs = FINDER_ARGS_EMPTY;
1146                    }
1147                    else {
1148                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1149                            finderArgs = new Object[] { start, end, orderByComparator };
1150                    }
1151    
1152                    List<VirtualHost> list = null;
1153    
1154                    if (retrieveFromCache) {
1155                            list = (List<VirtualHost>)finderCache.getResult(finderPath,
1156                                            finderArgs, this);
1157                    }
1158    
1159                    if (list == null) {
1160                            StringBundler query = null;
1161                            String sql = null;
1162    
1163                            if (orderByComparator != null) {
1164                                    query = new StringBundler(2 +
1165                                                    (orderByComparator.getOrderByFields().length * 2));
1166    
1167                                    query.append(_SQL_SELECT_VIRTUALHOST);
1168    
1169                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1170                                            orderByComparator);
1171    
1172                                    sql = query.toString();
1173                            }
1174                            else {
1175                                    sql = _SQL_SELECT_VIRTUALHOST;
1176    
1177                                    if (pagination) {
1178                                            sql = sql.concat(VirtualHostModelImpl.ORDER_BY_JPQL);
1179                                    }
1180                            }
1181    
1182                            Session session = null;
1183    
1184                            try {
1185                                    session = openSession();
1186    
1187                                    Query q = session.createQuery(sql);
1188    
1189                                    if (!pagination) {
1190                                            list = (List<VirtualHost>)QueryUtil.list(q, getDialect(),
1191                                                            start, end, false);
1192    
1193                                            Collections.sort(list);
1194    
1195                                            list = Collections.unmodifiableList(list);
1196                                    }
1197                                    else {
1198                                            list = (List<VirtualHost>)QueryUtil.list(q, getDialect(),
1199                                                            start, end);
1200                                    }
1201    
1202                                    cacheResult(list);
1203    
1204                                    finderCache.putResult(finderPath, finderArgs, list);
1205                            }
1206                            catch (Exception e) {
1207                                    finderCache.removeResult(finderPath, finderArgs);
1208    
1209                                    throw processException(e);
1210                            }
1211                            finally {
1212                                    closeSession(session);
1213                            }
1214                    }
1215    
1216                    return list;
1217            }
1218    
1219            /**
1220             * Removes all the virtual hosts from the database.
1221             *
1222             */
1223            @Override
1224            public void removeAll() {
1225                    for (VirtualHost virtualHost : findAll()) {
1226                            remove(virtualHost);
1227                    }
1228            }
1229    
1230            /**
1231             * Returns the number of virtual hosts.
1232             *
1233             * @return the number of virtual hosts
1234             */
1235            @Override
1236            public int countAll() {
1237                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1238                                    FINDER_ARGS_EMPTY, this);
1239    
1240                    if (count == null) {
1241                            Session session = null;
1242    
1243                            try {
1244                                    session = openSession();
1245    
1246                                    Query q = session.createQuery(_SQL_COUNT_VIRTUALHOST);
1247    
1248                                    count = (Long)q.uniqueResult();
1249    
1250                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1251                                            count);
1252                            }
1253                            catch (Exception e) {
1254                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1255                                            FINDER_ARGS_EMPTY);
1256    
1257                                    throw processException(e);
1258                            }
1259                            finally {
1260                                    closeSession(session);
1261                            }
1262                    }
1263    
1264                    return count.intValue();
1265            }
1266    
1267            @Override
1268            protected Map<String, Integer> getTableColumnsMap() {
1269                    return VirtualHostModelImpl.TABLE_COLUMNS_MAP;
1270            }
1271    
1272            /**
1273             * Initializes the virtual host persistence.
1274             */
1275            public void afterPropertiesSet() {
1276            }
1277    
1278            public void destroy() {
1279                    entityCache.removeCache(VirtualHostImpl.class.getName());
1280                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1281                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1282                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1283            }
1284    
1285            @BeanReference(type = CompanyProviderWrapper.class)
1286            protected CompanyProvider companyProvider;
1287            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1288            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1289            private static final String _SQL_SELECT_VIRTUALHOST = "SELECT virtualHost FROM VirtualHost virtualHost";
1290            private static final String _SQL_SELECT_VIRTUALHOST_WHERE_PKS_IN = "SELECT virtualHost FROM VirtualHost virtualHost WHERE virtualHostId IN (";
1291            private static final String _SQL_SELECT_VIRTUALHOST_WHERE = "SELECT virtualHost FROM VirtualHost virtualHost WHERE ";
1292            private static final String _SQL_COUNT_VIRTUALHOST = "SELECT COUNT(virtualHost) FROM VirtualHost virtualHost";
1293            private static final String _SQL_COUNT_VIRTUALHOST_WHERE = "SELECT COUNT(virtualHost) FROM VirtualHost virtualHost WHERE ";
1294            private static final String _ORDER_BY_ENTITY_ALIAS = "virtualHost.";
1295            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No VirtualHost exists with the primary key ";
1296            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No VirtualHost exists with the key {";
1297            private static final Log _log = LogFactoryUtil.getLog(VirtualHostPersistenceImpl.class);
1298            private static final VirtualHost _nullVirtualHost = new VirtualHostImpl() {
1299                            @Override
1300                            public Object clone() {
1301                                    return this;
1302                            }
1303    
1304                            @Override
1305                            public CacheModel<VirtualHost> toCacheModel() {
1306                                    return _nullVirtualHostCacheModel;
1307                            }
1308                    };
1309    
1310            private static final CacheModel<VirtualHost> _nullVirtualHostCacheModel = new NullCacheModel();
1311    
1312            private static class NullCacheModel implements CacheModel<VirtualHost>,
1313                    MVCCModel {
1314                    @Override
1315                    public long getMvccVersion() {
1316                            return -1;
1317                    }
1318    
1319                    @Override
1320                    public void setMvccVersion(long mvccVersion) {
1321                    }
1322    
1323                    @Override
1324                    public VirtualHost toEntityModel() {
1325                            return _nullVirtualHost;
1326                    }
1327            }
1328    }