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