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