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