001    /**
002     * Copyright (c) 2000-2013 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;
016    
017    import com.liferay.portal.NoSuchClusterGroupException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringUtil;
033    import com.liferay.portal.kernel.util.UnmodifiableList;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.model.ClusterGroup;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.model.impl.ClusterGroupImpl;
038    import com.liferay.portal.model.impl.ClusterGroupModelImpl;
039    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040    
041    import java.io.Serializable;
042    
043    import java.util.ArrayList;
044    import java.util.Collections;
045    import java.util.List;
046    
047    /**
048     * The persistence implementation for the cluster group service.
049     *
050     * <p>
051     * Caching information and settings can be found in <code>portal.properties</code>
052     * </p>
053     *
054     * @author Brian Wing Shun Chan
055     * @see ClusterGroupPersistence
056     * @see ClusterGroupUtil
057     * @generated
058     */
059    public class ClusterGroupPersistenceImpl extends BasePersistenceImpl<ClusterGroup>
060            implements ClusterGroupPersistence {
061            /*
062             * NOTE FOR DEVELOPERS:
063             *
064             * 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.
065             */
066            public static final String FINDER_CLASS_NAME_ENTITY = ClusterGroupImpl.class.getName();
067            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
068                    ".List1";
069            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070                    ".List2";
071            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
072                            ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
073                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
074            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
075                            ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
076                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
077            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
078                            ClusterGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
079                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
080    
081            public ClusterGroupPersistenceImpl() {
082                    setModelClass(ClusterGroup.class);
083            }
084    
085            /**
086             * Caches the cluster group in the entity cache if it is enabled.
087             *
088             * @param clusterGroup the cluster group
089             */
090            @Override
091            public void cacheResult(ClusterGroup clusterGroup) {
092                    EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
093                            ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
094    
095                    clusterGroup.resetOriginalValues();
096            }
097    
098            /**
099             * Caches the cluster groups in the entity cache if it is enabled.
100             *
101             * @param clusterGroups the cluster groups
102             */
103            @Override
104            public void cacheResult(List<ClusterGroup> clusterGroups) {
105                    for (ClusterGroup clusterGroup : clusterGroups) {
106                            if (EntityCacheUtil.getResult(
107                                                    ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
108                                                    ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
109                                    cacheResult(clusterGroup);
110                            }
111                            else {
112                                    clusterGroup.resetOriginalValues();
113                            }
114                    }
115            }
116    
117            /**
118             * Clears the cache for all cluster groups.
119             *
120             * <p>
121             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
122             * </p>
123             */
124            @Override
125            public void clearCache() {
126                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
127                            CacheRegistryUtil.clear(ClusterGroupImpl.class.getName());
128                    }
129    
130                    EntityCacheUtil.clearCache(ClusterGroupImpl.class.getName());
131    
132                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
133                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
134                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
135            }
136    
137            /**
138             * Clears the cache for the cluster group.
139             *
140             * <p>
141             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
142             * </p>
143             */
144            @Override
145            public void clearCache(ClusterGroup clusterGroup) {
146                    EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
147                            ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
148    
149                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
150                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
151            }
152    
153            @Override
154            public void clearCache(List<ClusterGroup> clusterGroups) {
155                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
156                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
157    
158                    for (ClusterGroup clusterGroup : clusterGroups) {
159                            EntityCacheUtil.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 com.liferay.portal.NoSuchClusterGroupException if a cluster group with the primary key could not be found
186             * @throws SystemException if a system exception occurred
187             */
188            @Override
189            public ClusterGroup remove(long clusterGroupId)
190                    throws NoSuchClusterGroupException, SystemException {
191                    return remove((Serializable)clusterGroupId);
192            }
193    
194            /**
195             * Removes the cluster group with the primary key from the database. Also notifies the appropriate model listeners.
196             *
197             * @param primaryKey the primary key of the cluster group
198             * @return the cluster group that was removed
199             * @throws com.liferay.portal.NoSuchClusterGroupException if a cluster group with the primary key could not be found
200             * @throws SystemException if a system exception occurred
201             */
202            @Override
203            public ClusterGroup remove(Serializable primaryKey)
204                    throws NoSuchClusterGroupException, SystemException {
205                    Session session = null;
206    
207                    try {
208                            session = openSession();
209    
210                            ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
211                                            primaryKey);
212    
213                            if (clusterGroup == null) {
214                                    if (_log.isWarnEnabled()) {
215                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
216                                    }
217    
218                                    throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
219                                            primaryKey);
220                            }
221    
222                            return remove(clusterGroup);
223                    }
224                    catch (NoSuchClusterGroupException nsee) {
225                            throw nsee;
226                    }
227                    catch (Exception e) {
228                            throw processException(e);
229                    }
230                    finally {
231                            closeSession(session);
232                    }
233            }
234    
235            @Override
236            protected ClusterGroup removeImpl(ClusterGroup clusterGroup)
237                    throws SystemException {
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                    throws SystemException {
272                    clusterGroup = toUnwrappedModel(clusterGroup);
273    
274                    boolean isNew = clusterGroup.isNew();
275    
276                    Session session = null;
277    
278                    try {
279                            session = openSession();
280    
281                            if (clusterGroup.isNew()) {
282                                    session.save(clusterGroup);
283    
284                                    clusterGroup.setNew(false);
285                            }
286                            else {
287                                    session.merge(clusterGroup);
288                            }
289                    }
290                    catch (Exception e) {
291                            throw processException(e);
292                    }
293                    finally {
294                            closeSession(session);
295                    }
296    
297                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
298    
299                    if (isNew) {
300                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
301                    }
302    
303                    EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
304                            ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
305    
306                    return clusterGroup;
307            }
308    
309            protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
310                    if (clusterGroup instanceof ClusterGroupImpl) {
311                            return clusterGroup;
312                    }
313    
314                    ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
315    
316                    clusterGroupImpl.setNew(clusterGroup.isNew());
317                    clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
318    
319                    clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
320                    clusterGroupImpl.setName(clusterGroup.getName());
321                    clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
322                    clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
323    
324                    return clusterGroupImpl;
325            }
326    
327            /**
328             * Returns the cluster group with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
329             *
330             * @param primaryKey the primary key of the cluster group
331             * @return the cluster group
332             * @throws com.liferay.portal.NoSuchClusterGroupException if a cluster group with the primary key could not be found
333             * @throws SystemException if a system exception occurred
334             */
335            @Override
336            public ClusterGroup findByPrimaryKey(Serializable primaryKey)
337                    throws NoSuchClusterGroupException, SystemException {
338                    ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
339    
340                    if (clusterGroup == null) {
341                            if (_log.isWarnEnabled()) {
342                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
343                            }
344    
345                            throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
346                                    primaryKey);
347                    }
348    
349                    return clusterGroup;
350            }
351    
352            /**
353             * Returns the cluster group with the primary key or throws a {@link com.liferay.portal.NoSuchClusterGroupException} if it could not be found.
354             *
355             * @param clusterGroupId the primary key of the cluster group
356             * @return the cluster group
357             * @throws com.liferay.portal.NoSuchClusterGroupException if a cluster group with the primary key could not be found
358             * @throws SystemException if a system exception occurred
359             */
360            @Override
361            public ClusterGroup findByPrimaryKey(long clusterGroupId)
362                    throws NoSuchClusterGroupException, SystemException {
363                    return findByPrimaryKey((Serializable)clusterGroupId);
364            }
365    
366            /**
367             * Returns the cluster group with the primary key or returns <code>null</code> if it could not be found.
368             *
369             * @param primaryKey the primary key of the cluster group
370             * @return the cluster group, or <code>null</code> if a cluster group with the primary key could not be found
371             * @throws SystemException if a system exception occurred
372             */
373            @Override
374            public ClusterGroup fetchByPrimaryKey(Serializable primaryKey)
375                    throws SystemException {
376                    ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
377                                    ClusterGroupImpl.class, primaryKey);
378    
379                    if (clusterGroup == _nullClusterGroup) {
380                            return null;
381                    }
382    
383                    if (clusterGroup == null) {
384                            Session session = null;
385    
386                            try {
387                                    session = openSession();
388    
389                                    clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
390                                                    primaryKey);
391    
392                                    if (clusterGroup != null) {
393                                            cacheResult(clusterGroup);
394                                    }
395                                    else {
396                                            EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
397                                                    ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
398                                    }
399                            }
400                            catch (Exception e) {
401                                    EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
402                                            ClusterGroupImpl.class, primaryKey);
403    
404                                    throw processException(e);
405                            }
406                            finally {
407                                    closeSession(session);
408                            }
409                    }
410    
411                    return clusterGroup;
412            }
413    
414            /**
415             * Returns the cluster group with the primary key or returns <code>null</code> if it could not be found.
416             *
417             * @param clusterGroupId the primary key of the cluster group
418             * @return the cluster group, or <code>null</code> if a cluster group with the primary key could not be found
419             * @throws SystemException if a system exception occurred
420             */
421            @Override
422            public ClusterGroup fetchByPrimaryKey(long clusterGroupId)
423                    throws SystemException {
424                    return fetchByPrimaryKey((Serializable)clusterGroupId);
425            }
426    
427            /**
428             * Returns all the cluster groups.
429             *
430             * @return the cluster groups
431             * @throws SystemException if a system exception occurred
432             */
433            @Override
434            public List<ClusterGroup> findAll() throws SystemException {
435                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
436            }
437    
438            /**
439             * Returns a range of all the cluster groups.
440             *
441             * <p>
442             * 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.
443             * </p>
444             *
445             * @param start the lower bound of the range of cluster groups
446             * @param end the upper bound of the range of cluster groups (not inclusive)
447             * @return the range of cluster groups
448             * @throws SystemException if a system exception occurred
449             */
450            @Override
451            public List<ClusterGroup> findAll(int start, int end)
452                    throws SystemException {
453                    return findAll(start, end, null);
454            }
455    
456            /**
457             * Returns an ordered range of all the cluster groups.
458             *
459             * <p>
460             * 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.
461             * </p>
462             *
463             * @param start the lower bound of the range of cluster groups
464             * @param end the upper bound of the range of cluster groups (not inclusive)
465             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
466             * @return the ordered range of cluster groups
467             * @throws SystemException if a system exception occurred
468             */
469            @Override
470            public List<ClusterGroup> findAll(int start, int end,
471                    OrderByComparator orderByComparator) throws SystemException {
472                    boolean pagination = true;
473                    FinderPath finderPath = null;
474                    Object[] finderArgs = null;
475    
476                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
477                                    (orderByComparator == null)) {
478                            pagination = false;
479                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
480                            finderArgs = FINDER_ARGS_EMPTY;
481                    }
482                    else {
483                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
484                            finderArgs = new Object[] { start, end, orderByComparator };
485                    }
486    
487                    List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(finderPath,
488                                    finderArgs, this);
489    
490                    if (list == null) {
491                            StringBundler query = null;
492                            String sql = null;
493    
494                            if (orderByComparator != null) {
495                                    query = new StringBundler(2 +
496                                                    (orderByComparator.getOrderByFields().length * 3));
497    
498                                    query.append(_SQL_SELECT_CLUSTERGROUP);
499    
500                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
501                                            orderByComparator);
502    
503                                    sql = query.toString();
504                            }
505                            else {
506                                    sql = _SQL_SELECT_CLUSTERGROUP;
507    
508                                    if (pagination) {
509                                            sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
510                                    }
511                            }
512    
513                            Session session = null;
514    
515                            try {
516                                    session = openSession();
517    
518                                    Query q = session.createQuery(sql);
519    
520                                    if (!pagination) {
521                                            list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
522                                                            start, end, false);
523    
524                                            Collections.sort(list);
525    
526                                            list = new UnmodifiableList<ClusterGroup>(list);
527                                    }
528                                    else {
529                                            list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
530                                                            start, end);
531                                    }
532    
533                                    cacheResult(list);
534    
535                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
536                            }
537                            catch (Exception e) {
538                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
539    
540                                    throw processException(e);
541                            }
542                            finally {
543                                    closeSession(session);
544                            }
545                    }
546    
547                    return list;
548            }
549    
550            /**
551             * Removes all the cluster groups from the database.
552             *
553             * @throws SystemException if a system exception occurred
554             */
555            @Override
556            public void removeAll() throws SystemException {
557                    for (ClusterGroup clusterGroup : findAll()) {
558                            remove(clusterGroup);
559                    }
560            }
561    
562            /**
563             * Returns the number of cluster groups.
564             *
565             * @return the number of cluster groups
566             * @throws SystemException if a system exception occurred
567             */
568            @Override
569            public int countAll() throws SystemException {
570                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
571                                    FINDER_ARGS_EMPTY, this);
572    
573                    if (count == null) {
574                            Session session = null;
575    
576                            try {
577                                    session = openSession();
578    
579                                    Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
580    
581                                    count = (Long)q.uniqueResult();
582    
583                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
584                                            FINDER_ARGS_EMPTY, count);
585                            }
586                            catch (Exception e) {
587                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
588                                            FINDER_ARGS_EMPTY);
589    
590                                    throw processException(e);
591                            }
592                            finally {
593                                    closeSession(session);
594                            }
595                    }
596    
597                    return count.intValue();
598            }
599    
600            /**
601             * Initializes the cluster group persistence.
602             */
603            public void afterPropertiesSet() {
604                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
605                                            com.liferay.portal.util.PropsUtil.get(
606                                                    "value.object.listener.com.liferay.portal.model.ClusterGroup")));
607    
608                    if (listenerClassNames.length > 0) {
609                            try {
610                                    List<ModelListener<ClusterGroup>> listenersList = new ArrayList<ModelListener<ClusterGroup>>();
611    
612                                    for (String listenerClassName : listenerClassNames) {
613                                            listenersList.add((ModelListener<ClusterGroup>)InstanceFactory.newInstance(
614                                                            getClassLoader(), listenerClassName));
615                                    }
616    
617                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
618                            }
619                            catch (Exception e) {
620                                    _log.error(e);
621                            }
622                    }
623            }
624    
625            public void destroy() {
626                    EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
627                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
628                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
629                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
630            }
631    
632            private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
633            private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
634            private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
635            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
636            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
637            private static Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
638            private static ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
639                            @Override
640                            public Object clone() {
641                                    return this;
642                            }
643    
644                            @Override
645                            public CacheModel<ClusterGroup> toCacheModel() {
646                                    return _nullClusterGroupCacheModel;
647                            }
648                    };
649    
650            private static CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new CacheModel<ClusterGroup>() {
651                            @Override
652                            public ClusterGroup toEntityModel() {
653                                    return _nullClusterGroup;
654                            }
655                    };
656    }