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.NoSuchClusterGroupException;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.model.CacheModel;
034    import com.liferay.portal.model.ClusterGroup;
035    import com.liferay.portal.model.MVCCModel;
036    import com.liferay.portal.model.impl.ClusterGroupImpl;
037    import com.liferay.portal.model.impl.ClusterGroupModelImpl;
038    import com.liferay.portal.service.persistence.ClusterGroupPersistence;
039    
040    import java.io.Serializable;
041    
042    import java.util.Collections;
043    import java.util.HashMap;
044    import java.util.HashSet;
045    import java.util.Iterator;
046    import java.util.List;
047    import java.util.Map;
048    import java.util.Set;
049    
050    /**
051     * The persistence implementation for the cluster group service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see ClusterGroupPersistence
059     * @see com.liferay.portal.service.persistence.ClusterGroupUtil
060     * @generated
061     */
062    @ProviderType
063    public class ClusterGroupPersistenceImpl extends BasePersistenceImpl<ClusterGroup>
064            implements ClusterGroupPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link ClusterGroupUtil} to access the cluster group persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = ClusterGroupImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
076                            ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
079                            ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
082                            ClusterGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084    
085            public ClusterGroupPersistenceImpl() {
086                    setModelClass(ClusterGroup.class);
087            }
088    
089            /**
090             * Caches the cluster group in the entity cache if it is enabled.
091             *
092             * @param clusterGroup the cluster group
093             */
094            @Override
095            public void cacheResult(ClusterGroup clusterGroup) {
096                    entityCache.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
097                            ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
098    
099                    clusterGroup.resetOriginalValues();
100            }
101    
102            /**
103             * Caches the cluster groups in the entity cache if it is enabled.
104             *
105             * @param clusterGroups the cluster groups
106             */
107            @Override
108            public void cacheResult(List<ClusterGroup> clusterGroups) {
109                    for (ClusterGroup clusterGroup : clusterGroups) {
110                            if (entityCache.getResult(
111                                                    ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
112                                                    ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
113                                    cacheResult(clusterGroup);
114                            }
115                            else {
116                                    clusterGroup.resetOriginalValues();
117                            }
118                    }
119            }
120    
121            /**
122             * Clears the cache for all cluster groups.
123             *
124             * <p>
125             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
126             * </p>
127             */
128            @Override
129            public void clearCache() {
130                    entityCache.clearCache(ClusterGroupImpl.class);
131    
132                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
133                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
134                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
135            }
136    
137            /**
138             * Clears the cache for the cluster group.
139             *
140             * <p>
141             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
142             * </p>
143             */
144            @Override
145            public void clearCache(ClusterGroup clusterGroup) {
146                    entityCache.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
147                            ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
148    
149                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
150                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
151            }
152    
153            @Override
154            public void clearCache(List<ClusterGroup> clusterGroups) {
155                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
156                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
157    
158                    for (ClusterGroup clusterGroup : clusterGroups) {
159                            entityCache.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
160                                    ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
161                    }
162            }
163    
164            /**
165             * Creates a new cluster group with the primary key. Does not add the cluster group to the database.
166             *
167             * @param clusterGroupId the primary key for the new cluster group
168             * @return the new cluster group
169             */
170            @Override
171            public ClusterGroup create(long clusterGroupId) {
172                    ClusterGroup clusterGroup = new ClusterGroupImpl();
173    
174                    clusterGroup.setNew(true);
175                    clusterGroup.setPrimaryKey(clusterGroupId);
176    
177                    return clusterGroup;
178            }
179    
180            /**
181             * Removes the cluster group with the primary key from the database. Also notifies the appropriate model listeners.
182             *
183             * @param clusterGroupId the primary key of the cluster group
184             * @return the cluster group that was removed
185             * @throws NoSuchClusterGroupException if a cluster group with the primary key could not be found
186             */
187            @Override
188            public ClusterGroup remove(long clusterGroupId)
189                    throws NoSuchClusterGroupException {
190                    return remove((Serializable)clusterGroupId);
191            }
192    
193            /**
194             * Removes the cluster group with the primary key from the database. Also notifies the appropriate model listeners.
195             *
196             * @param primaryKey the primary key of the cluster group
197             * @return the cluster group that was removed
198             * @throws NoSuchClusterGroupException if a cluster group with the primary key could not be found
199             */
200            @Override
201            public ClusterGroup remove(Serializable primaryKey)
202                    throws NoSuchClusterGroupException {
203                    Session session = null;
204    
205                    try {
206                            session = openSession();
207    
208                            ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
209                                            primaryKey);
210    
211                            if (clusterGroup == null) {
212                                    if (_log.isWarnEnabled()) {
213                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
214                                    }
215    
216                                    throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
217                                            primaryKey);
218                            }
219    
220                            return remove(clusterGroup);
221                    }
222                    catch (NoSuchClusterGroupException nsee) {
223                            throw nsee;
224                    }
225                    catch (Exception e) {
226                            throw processException(e);
227                    }
228                    finally {
229                            closeSession(session);
230                    }
231            }
232    
233            @Override
234            protected ClusterGroup removeImpl(ClusterGroup clusterGroup) {
235                    clusterGroup = toUnwrappedModel(clusterGroup);
236    
237                    Session session = null;
238    
239                    try {
240                            session = openSession();
241    
242                            if (!session.contains(clusterGroup)) {
243                                    clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
244                                                    clusterGroup.getPrimaryKeyObj());
245                            }
246    
247                            if (clusterGroup != null) {
248                                    session.delete(clusterGroup);
249                            }
250                    }
251                    catch (Exception e) {
252                            throw processException(e);
253                    }
254                    finally {
255                            closeSession(session);
256                    }
257    
258                    if (clusterGroup != null) {
259                            clearCache(clusterGroup);
260                    }
261    
262                    return clusterGroup;
263            }
264    
265            @Override
266            public ClusterGroup updateImpl(ClusterGroup clusterGroup) {
267                    clusterGroup = toUnwrappedModel(clusterGroup);
268    
269                    boolean isNew = clusterGroup.isNew();
270    
271                    Session session = null;
272    
273                    try {
274                            session = openSession();
275    
276                            if (clusterGroup.isNew()) {
277                                    session.save(clusterGroup);
278    
279                                    clusterGroup.setNew(false);
280                            }
281                            else {
282                                    clusterGroup = (ClusterGroup)session.merge(clusterGroup);
283                            }
284                    }
285                    catch (Exception e) {
286                            throw processException(e);
287                    }
288                    finally {
289                            closeSession(session);
290                    }
291    
292                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
293    
294                    if (isNew) {
295                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
296                    }
297    
298                    entityCache.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
299                            ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup,
300                            false);
301    
302                    clusterGroup.resetOriginalValues();
303    
304                    return clusterGroup;
305            }
306    
307            protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
308                    if (clusterGroup instanceof ClusterGroupImpl) {
309                            return clusterGroup;
310                    }
311    
312                    ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
313    
314                    clusterGroupImpl.setNew(clusterGroup.isNew());
315                    clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
316    
317                    clusterGroupImpl.setMvccVersion(clusterGroup.getMvccVersion());
318                    clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
319                    clusterGroupImpl.setName(clusterGroup.getName());
320                    clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
321                    clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
322    
323                    return clusterGroupImpl;
324            }
325    
326            /**
327             * Returns the cluster group with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
328             *
329             * @param primaryKey the primary key of the cluster group
330             * @return the cluster group
331             * @throws NoSuchClusterGroupException if a cluster group with the primary key could not be found
332             */
333            @Override
334            public ClusterGroup findByPrimaryKey(Serializable primaryKey)
335                    throws NoSuchClusterGroupException {
336                    ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
337    
338                    if (clusterGroup == null) {
339                            if (_log.isWarnEnabled()) {
340                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
341                            }
342    
343                            throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
344                                    primaryKey);
345                    }
346    
347                    return clusterGroup;
348            }
349    
350            /**
351             * Returns the cluster group with the primary key or throws a {@link NoSuchClusterGroupException} if it could not be found.
352             *
353             * @param clusterGroupId the primary key of the cluster group
354             * @return the cluster group
355             * @throws NoSuchClusterGroupException if a cluster group with the primary key could not be found
356             */
357            @Override
358            public ClusterGroup findByPrimaryKey(long clusterGroupId)
359                    throws NoSuchClusterGroupException {
360                    return findByPrimaryKey((Serializable)clusterGroupId);
361            }
362    
363            /**
364             * Returns the cluster group with the primary key or returns <code>null</code> if it could not be found.
365             *
366             * @param primaryKey the primary key of the cluster group
367             * @return the cluster group, or <code>null</code> if a cluster group with the primary key could not be found
368             */
369            @Override
370            public ClusterGroup fetchByPrimaryKey(Serializable primaryKey) {
371                    ClusterGroup clusterGroup = (ClusterGroup)entityCache.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
372                                    ClusterGroupImpl.class, primaryKey);
373    
374                    if (clusterGroup == _nullClusterGroup) {
375                            return null;
376                    }
377    
378                    if (clusterGroup == null) {
379                            Session session = null;
380    
381                            try {
382                                    session = openSession();
383    
384                                    clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
385                                                    primaryKey);
386    
387                                    if (clusterGroup != null) {
388                                            cacheResult(clusterGroup);
389                                    }
390                                    else {
391                                            entityCache.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
392                                                    ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
393                                    }
394                            }
395                            catch (Exception e) {
396                                    entityCache.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
397                                            ClusterGroupImpl.class, primaryKey);
398    
399                                    throw processException(e);
400                            }
401                            finally {
402                                    closeSession(session);
403                            }
404                    }
405    
406                    return clusterGroup;
407            }
408    
409            /**
410             * Returns the cluster group with the primary key or returns <code>null</code> if it could not be found.
411             *
412             * @param clusterGroupId the primary key of the cluster group
413             * @return the cluster group, or <code>null</code> if a cluster group with the primary key could not be found
414             */
415            @Override
416            public ClusterGroup fetchByPrimaryKey(long clusterGroupId) {
417                    return fetchByPrimaryKey((Serializable)clusterGroupId);
418            }
419    
420            @Override
421            public Map<Serializable, ClusterGroup> fetchByPrimaryKeys(
422                    Set<Serializable> primaryKeys) {
423                    if (primaryKeys.isEmpty()) {
424                            return Collections.emptyMap();
425                    }
426    
427                    Map<Serializable, ClusterGroup> map = new HashMap<Serializable, ClusterGroup>();
428    
429                    if (primaryKeys.size() == 1) {
430                            Iterator<Serializable> iterator = primaryKeys.iterator();
431    
432                            Serializable primaryKey = iterator.next();
433    
434                            ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
435    
436                            if (clusterGroup != null) {
437                                    map.put(primaryKey, clusterGroup);
438                            }
439    
440                            return map;
441                    }
442    
443                    Set<Serializable> uncachedPrimaryKeys = null;
444    
445                    for (Serializable primaryKey : primaryKeys) {
446                            ClusterGroup clusterGroup = (ClusterGroup)entityCache.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
447                                            ClusterGroupImpl.class, primaryKey);
448    
449                            if (clusterGroup == null) {
450                                    if (uncachedPrimaryKeys == null) {
451                                            uncachedPrimaryKeys = new HashSet<Serializable>();
452                                    }
453    
454                                    uncachedPrimaryKeys.add(primaryKey);
455                            }
456                            else {
457                                    map.put(primaryKey, clusterGroup);
458                            }
459                    }
460    
461                    if (uncachedPrimaryKeys == null) {
462                            return map;
463                    }
464    
465                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
466                                    1);
467    
468                    query.append(_SQL_SELECT_CLUSTERGROUP_WHERE_PKS_IN);
469    
470                    for (Serializable primaryKey : uncachedPrimaryKeys) {
471                            query.append(String.valueOf(primaryKey));
472    
473                            query.append(StringPool.COMMA);
474                    }
475    
476                    query.setIndex(query.index() - 1);
477    
478                    query.append(StringPool.CLOSE_PARENTHESIS);
479    
480                    String sql = query.toString();
481    
482                    Session session = null;
483    
484                    try {
485                            session = openSession();
486    
487                            Query q = session.createQuery(sql);
488    
489                            for (ClusterGroup clusterGroup : (List<ClusterGroup>)q.list()) {
490                                    map.put(clusterGroup.getPrimaryKeyObj(), clusterGroup);
491    
492                                    cacheResult(clusterGroup);
493    
494                                    uncachedPrimaryKeys.remove(clusterGroup.getPrimaryKeyObj());
495                            }
496    
497                            for (Serializable primaryKey : uncachedPrimaryKeys) {
498                                    entityCache.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
499                                            ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
500                            }
501                    }
502                    catch (Exception e) {
503                            throw processException(e);
504                    }
505                    finally {
506                            closeSession(session);
507                    }
508    
509                    return map;
510            }
511    
512            /**
513             * Returns all the cluster groups.
514             *
515             * @return the cluster groups
516             */
517            @Override
518            public List<ClusterGroup> findAll() {
519                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
520            }
521    
522            /**
523             * Returns a range of all the cluster groups.
524             *
525             * <p>
526             * 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 ClusterGroupModelImpl}. 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.
527             * </p>
528             *
529             * @param start the lower bound of the range of cluster groups
530             * @param end the upper bound of the range of cluster groups (not inclusive)
531             * @return the range of cluster groups
532             */
533            @Override
534            public List<ClusterGroup> findAll(int start, int end) {
535                    return findAll(start, end, null);
536            }
537    
538            /**
539             * Returns an ordered range of all the cluster groups.
540             *
541             * <p>
542             * 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 ClusterGroupModelImpl}. 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.
543             * </p>
544             *
545             * @param start the lower bound of the range of cluster groups
546             * @param end the upper bound of the range of cluster groups (not inclusive)
547             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
548             * @return the ordered range of cluster groups
549             */
550            @Override
551            public List<ClusterGroup> findAll(int start, int end,
552                    OrderByComparator<ClusterGroup> orderByComparator) {
553                    return findAll(start, end, orderByComparator, true);
554            }
555    
556            /**
557             * Returns an ordered range of all the cluster groups.
558             *
559             * <p>
560             * 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 ClusterGroupModelImpl}. 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.
561             * </p>
562             *
563             * @param start the lower bound of the range of cluster groups
564             * @param end the upper bound of the range of cluster groups (not inclusive)
565             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
566             * @param retrieveFromCache whether to retrieve from the finder cache
567             * @return the ordered range of cluster groups
568             */
569            @Override
570            public List<ClusterGroup> findAll(int start, int end,
571                    OrderByComparator<ClusterGroup> orderByComparator,
572                    boolean retrieveFromCache) {
573                    boolean pagination = true;
574                    FinderPath finderPath = null;
575                    Object[] finderArgs = null;
576    
577                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
578                                    (orderByComparator == null)) {
579                            pagination = false;
580                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
581                            finderArgs = FINDER_ARGS_EMPTY;
582                    }
583                    else {
584                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
585                            finderArgs = new Object[] { start, end, orderByComparator };
586                    }
587    
588                    List<ClusterGroup> list = null;
589    
590                    if (retrieveFromCache) {
591                            list = (List<ClusterGroup>)finderCache.getResult(finderPath,
592                                            finderArgs, this);
593                    }
594    
595                    if (list == null) {
596                            StringBundler query = null;
597                            String sql = null;
598    
599                            if (orderByComparator != null) {
600                                    query = new StringBundler(2 +
601                                                    (orderByComparator.getOrderByFields().length * 3));
602    
603                                    query.append(_SQL_SELECT_CLUSTERGROUP);
604    
605                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
606                                            orderByComparator);
607    
608                                    sql = query.toString();
609                            }
610                            else {
611                                    sql = _SQL_SELECT_CLUSTERGROUP;
612    
613                                    if (pagination) {
614                                            sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
615                                    }
616                            }
617    
618                            Session session = null;
619    
620                            try {
621                                    session = openSession();
622    
623                                    Query q = session.createQuery(sql);
624    
625                                    if (!pagination) {
626                                            list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
627                                                            start, end, false);
628    
629                                            Collections.sort(list);
630    
631                                            list = Collections.unmodifiableList(list);
632                                    }
633                                    else {
634                                            list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
635                                                            start, end);
636                                    }
637    
638                                    cacheResult(list);
639    
640                                    finderCache.putResult(finderPath, finderArgs, list);
641                            }
642                            catch (Exception e) {
643                                    finderCache.removeResult(finderPath, finderArgs);
644    
645                                    throw processException(e);
646                            }
647                            finally {
648                                    closeSession(session);
649                            }
650                    }
651    
652                    return list;
653            }
654    
655            /**
656             * Removes all the cluster groups from the database.
657             *
658             */
659            @Override
660            public void removeAll() {
661                    for (ClusterGroup clusterGroup : findAll()) {
662                            remove(clusterGroup);
663                    }
664            }
665    
666            /**
667             * Returns the number of cluster groups.
668             *
669             * @return the number of cluster groups
670             */
671            @Override
672            public int countAll() {
673                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
674                                    FINDER_ARGS_EMPTY, this);
675    
676                    if (count == null) {
677                            Session session = null;
678    
679                            try {
680                                    session = openSession();
681    
682                                    Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
683    
684                                    count = (Long)q.uniqueResult();
685    
686                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
687                                            count);
688                            }
689                            catch (Exception e) {
690                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
691                                            FINDER_ARGS_EMPTY);
692    
693                                    throw processException(e);
694                            }
695                            finally {
696                                    closeSession(session);
697                            }
698                    }
699    
700                    return count.intValue();
701            }
702    
703            @Override
704            protected Map<String, Integer> getTableColumnsMap() {
705                    return ClusterGroupModelImpl.TABLE_COLUMNS_MAP;
706            }
707    
708            /**
709             * Initializes the cluster group persistence.
710             */
711            public void afterPropertiesSet() {
712            }
713    
714            public void destroy() {
715                    entityCache.removeCache(ClusterGroupImpl.class.getName());
716                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
717                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
718                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
719            }
720    
721            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
722            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
723            private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
724            private static final String _SQL_SELECT_CLUSTERGROUP_WHERE_PKS_IN = "SELECT clusterGroup FROM ClusterGroup clusterGroup WHERE clusterGroupId IN (";
725            private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
726            private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
727            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
728            private static final Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
729            private static final ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
730                            @Override
731                            public Object clone() {
732                                    return this;
733                            }
734    
735                            @Override
736                            public CacheModel<ClusterGroup> toCacheModel() {
737                                    return _nullClusterGroupCacheModel;
738                            }
739                    };
740    
741            private static final CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new NullCacheModel();
742    
743            private static class NullCacheModel implements CacheModel<ClusterGroup>,
744                    MVCCModel {
745                    @Override
746                    public long getMvccVersion() {
747                            return -1;
748                    }
749    
750                    @Override
751                    public void setMvccVersion(long mvccVersion) {
752                    }
753    
754                    @Override
755                    public ClusterGroup toEntityModel() {
756                            return _nullClusterGroup;
757                    }
758            }
759    }