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