1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.wiki.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.annotation.BeanReference;
27  import com.liferay.portal.kernel.cache.CacheRegistry;
28  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderPath;
32  import com.liferay.portal.kernel.dao.orm.Query;
33  import com.liferay.portal.kernel.dao.orm.QueryPos;
34  import com.liferay.portal.kernel.dao.orm.QueryUtil;
35  import com.liferay.portal.kernel.dao.orm.Session;
36  import com.liferay.portal.kernel.log.Log;
37  import com.liferay.portal.kernel.log.LogFactoryUtil;
38  import com.liferay.portal.kernel.util.GetterUtil;
39  import com.liferay.portal.kernel.util.OrderByComparator;
40  import com.liferay.portal.kernel.util.StringPool;
41  import com.liferay.portal.kernel.util.StringUtil;
42  import com.liferay.portal.kernel.util.Validator;
43  import com.liferay.portal.model.ModelListener;
44  import com.liferay.portal.service.persistence.BatchSessionUtil;
45  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
46  
47  import com.liferay.portlet.wiki.NoSuchPageResourceException;
48  import com.liferay.portlet.wiki.model.WikiPageResource;
49  import com.liferay.portlet.wiki.model.impl.WikiPageResourceImpl;
50  import com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl;
51  
52  import java.util.ArrayList;
53  import java.util.Collections;
54  import java.util.List;
55  
56  /**
57   * <a href="WikiPageResourcePersistenceImpl.java.html"><b><i>View Source</i></b></a>
58   *
59   * <p>
60   * ServiceBuilder generated this class. Modifications in this class will be
61   * overwritten the next time is generated.
62   * </p>
63   *
64   * @author    Brian Wing Shun Chan
65   * @see       WikiPageResourcePersistence
66   * @see       WikiPageResourceUtil
67   * @generated
68   */
69  public class WikiPageResourcePersistenceImpl extends BasePersistenceImpl
70      implements WikiPageResourcePersistence {
71      public static final String FINDER_CLASS_NAME_ENTITY = WikiPageResourceImpl.class.getName();
72      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
73          ".List";
74      public static final FinderPath FINDER_PATH_FETCH_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
75              WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
76              FINDER_CLASS_NAME_ENTITY, "fetchByN_T",
77              new String[] { Long.class.getName(), String.class.getName() });
78      public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
79              WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
80              FINDER_CLASS_NAME_LIST, "countByN_T",
81              new String[] { Long.class.getName(), String.class.getName() });
82      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
83              WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
84              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
85      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
86              WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
87              FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
88  
89      public void cacheResult(WikiPageResource wikiPageResource) {
90          EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
91              WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
92              wikiPageResource);
93  
94          FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
95              new Object[] {
96                  new Long(wikiPageResource.getNodeId()),
97                  
98              wikiPageResource.getTitle()
99              }, wikiPageResource);
100     }
101 
102     public void cacheResult(List<WikiPageResource> wikiPageResources) {
103         for (WikiPageResource wikiPageResource : wikiPageResources) {
104             if (EntityCacheUtil.getResult(
105                         WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
106                         WikiPageResourceImpl.class,
107                         wikiPageResource.getPrimaryKey(), this) == null) {
108                 cacheResult(wikiPageResource);
109             }
110         }
111     }
112 
113     public void clearCache() {
114         CacheRegistry.clear(WikiPageResourceImpl.class.getName());
115         EntityCacheUtil.clearCache(WikiPageResourceImpl.class.getName());
116         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
117         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
118     }
119 
120     public WikiPageResource create(long resourcePrimKey) {
121         WikiPageResource wikiPageResource = new WikiPageResourceImpl();
122 
123         wikiPageResource.setNew(true);
124         wikiPageResource.setPrimaryKey(resourcePrimKey);
125 
126         return wikiPageResource;
127     }
128 
129     public WikiPageResource remove(long resourcePrimKey)
130         throws NoSuchPageResourceException, SystemException {
131         Session session = null;
132 
133         try {
134             session = openSession();
135 
136             WikiPageResource wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
137                     new Long(resourcePrimKey));
138 
139             if (wikiPageResource == null) {
140                 if (_log.isWarnEnabled()) {
141                     _log.warn(
142                         "No WikiPageResource exists with the primary key " +
143                         resourcePrimKey);
144                 }
145 
146                 throw new NoSuchPageResourceException(
147                     "No WikiPageResource exists with the primary key " +
148                     resourcePrimKey);
149             }
150 
151             return remove(wikiPageResource);
152         }
153         catch (NoSuchPageResourceException nsee) {
154             throw nsee;
155         }
156         catch (Exception e) {
157             throw processException(e);
158         }
159         finally {
160             closeSession(session);
161         }
162     }
163 
164     public WikiPageResource remove(WikiPageResource wikiPageResource)
165         throws SystemException {
166         for (ModelListener<WikiPageResource> listener : listeners) {
167             listener.onBeforeRemove(wikiPageResource);
168         }
169 
170         wikiPageResource = removeImpl(wikiPageResource);
171 
172         for (ModelListener<WikiPageResource> listener : listeners) {
173             listener.onAfterRemove(wikiPageResource);
174         }
175 
176         return wikiPageResource;
177     }
178 
179     protected WikiPageResource removeImpl(WikiPageResource wikiPageResource)
180         throws SystemException {
181         wikiPageResource = toUnwrappedModel(wikiPageResource);
182 
183         Session session = null;
184 
185         try {
186             session = openSession();
187 
188             if (wikiPageResource.isCachedModel() ||
189                     BatchSessionUtil.isEnabled()) {
190                 Object staleObject = session.get(WikiPageResourceImpl.class,
191                         wikiPageResource.getPrimaryKeyObj());
192 
193                 if (staleObject != null) {
194                     session.evict(staleObject);
195                 }
196             }
197 
198             session.delete(wikiPageResource);
199 
200             session.flush();
201         }
202         catch (Exception e) {
203             throw processException(e);
204         }
205         finally {
206             closeSession(session);
207         }
208 
209         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
210 
211         WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
212 
213         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
214             new Object[] {
215                 new Long(wikiPageResourceModelImpl.getOriginalNodeId()),
216                 
217             wikiPageResourceModelImpl.getOriginalTitle()
218             });
219 
220         EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
221             WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
222 
223         return wikiPageResource;
224     }
225 
226     /**
227      * @deprecated Use {@link #update(WikiPageResource, boolean merge)}.
228      */
229     public WikiPageResource update(WikiPageResource wikiPageResource)
230         throws SystemException {
231         if (_log.isWarnEnabled()) {
232             _log.warn(
233                 "Using the deprecated update(WikiPageResource wikiPageResource) method. Use update(WikiPageResource wikiPageResource, boolean merge) instead.");
234         }
235 
236         return update(wikiPageResource, false);
237     }
238 
239     /**
240      * Add, update, or merge, the entity. This method also calls the model
241      * listeners to trigger the proper events associated with adding, deleting,
242      * or updating an entity.
243      *
244      * @param  wikiPageResource the entity to add, update, or merge
245      * @param  merge boolean value for whether to merge the entity. The default
246      *         value is false. Setting merge to true is more expensive and
247      *         should only be true when wikiPageResource is transient. See
248      *         LEP-5473 for a detailed discussion of this method.
249      * @return the entity that was added, updated, or merged
250      */
251     public WikiPageResource update(WikiPageResource wikiPageResource,
252         boolean merge) throws SystemException {
253         boolean isNew = wikiPageResource.isNew();
254 
255         for (ModelListener<WikiPageResource> listener : listeners) {
256             if (isNew) {
257                 listener.onBeforeCreate(wikiPageResource);
258             }
259             else {
260                 listener.onBeforeUpdate(wikiPageResource);
261             }
262         }
263 
264         wikiPageResource = updateImpl(wikiPageResource, merge);
265 
266         for (ModelListener<WikiPageResource> listener : listeners) {
267             if (isNew) {
268                 listener.onAfterCreate(wikiPageResource);
269             }
270             else {
271                 listener.onAfterUpdate(wikiPageResource);
272             }
273         }
274 
275         return wikiPageResource;
276     }
277 
278     public WikiPageResource updateImpl(
279         com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource,
280         boolean merge) throws SystemException {
281         wikiPageResource = toUnwrappedModel(wikiPageResource);
282 
283         boolean isNew = wikiPageResource.isNew();
284 
285         WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
286 
287         Session session = null;
288 
289         try {
290             session = openSession();
291 
292             BatchSessionUtil.update(session, wikiPageResource, merge);
293 
294             wikiPageResource.setNew(false);
295         }
296         catch (Exception e) {
297             throw processException(e);
298         }
299         finally {
300             closeSession(session);
301         }
302 
303         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
304 
305         EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
306             WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
307             wikiPageResource);
308 
309         if (!isNew &&
310                 ((wikiPageResource.getNodeId() != wikiPageResourceModelImpl.getOriginalNodeId()) ||
311                 !Validator.equals(wikiPageResource.getTitle(),
312                     wikiPageResourceModelImpl.getOriginalTitle()))) {
313             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
314                 new Object[] {
315                     new Long(wikiPageResourceModelImpl.getOriginalNodeId()),
316                     
317                 wikiPageResourceModelImpl.getOriginalTitle()
318                 });
319         }
320 
321         if (isNew ||
322                 ((wikiPageResource.getNodeId() != wikiPageResourceModelImpl.getOriginalNodeId()) ||
323                 !Validator.equals(wikiPageResource.getTitle(),
324                     wikiPageResourceModelImpl.getOriginalTitle()))) {
325             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
326                 new Object[] {
327                     new Long(wikiPageResource.getNodeId()),
328                     
329                 wikiPageResource.getTitle()
330                 }, wikiPageResource);
331         }
332 
333         return wikiPageResource;
334     }
335 
336     protected WikiPageResource toUnwrappedModel(
337         WikiPageResource wikiPageResource) {
338         if (wikiPageResource instanceof WikiPageResourceImpl) {
339             return wikiPageResource;
340         }
341 
342         WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
343 
344         wikiPageResourceImpl.setNew(wikiPageResource.isNew());
345         wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
346 
347         wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
348         wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
349         wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
350 
351         return wikiPageResourceImpl;
352     }
353 
354     public WikiPageResource findByPrimaryKey(long resourcePrimKey)
355         throws NoSuchPageResourceException, SystemException {
356         WikiPageResource wikiPageResource = fetchByPrimaryKey(resourcePrimKey);
357 
358         if (wikiPageResource == null) {
359             if (_log.isWarnEnabled()) {
360                 _log.warn("No WikiPageResource exists with the primary key " +
361                     resourcePrimKey);
362             }
363 
364             throw new NoSuchPageResourceException(
365                 "No WikiPageResource exists with the primary key " +
366                 resourcePrimKey);
367         }
368 
369         return wikiPageResource;
370     }
371 
372     public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
373         throws SystemException {
374         WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
375                 WikiPageResourceImpl.class, resourcePrimKey, this);
376 
377         if (wikiPageResource == null) {
378             Session session = null;
379 
380             try {
381                 session = openSession();
382 
383                 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
384                         new Long(resourcePrimKey));
385             }
386             catch (Exception e) {
387                 throw processException(e);
388             }
389             finally {
390                 if (wikiPageResource != null) {
391                     cacheResult(wikiPageResource);
392                 }
393 
394                 closeSession(session);
395             }
396         }
397 
398         return wikiPageResource;
399     }
400 
401     public WikiPageResource findByN_T(long nodeId, String title)
402         throws NoSuchPageResourceException, SystemException {
403         WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
404 
405         if (wikiPageResource == null) {
406             StringBuilder msg = new StringBuilder();
407 
408             msg.append("No WikiPageResource exists with the key {");
409 
410             msg.append("nodeId=" + nodeId);
411 
412             msg.append(", ");
413             msg.append("title=" + title);
414 
415             msg.append(StringPool.CLOSE_CURLY_BRACE);
416 
417             if (_log.isWarnEnabled()) {
418                 _log.warn(msg.toString());
419             }
420 
421             throw new NoSuchPageResourceException(msg.toString());
422         }
423 
424         return wikiPageResource;
425     }
426 
427     public WikiPageResource fetchByN_T(long nodeId, String title)
428         throws SystemException {
429         return fetchByN_T(nodeId, title, true);
430     }
431 
432     public WikiPageResource fetchByN_T(long nodeId, String title,
433         boolean retrieveFromCache) throws SystemException {
434         Object[] finderArgs = new Object[] { new Long(nodeId), title };
435 
436         Object result = null;
437 
438         if (retrieveFromCache) {
439             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
440                     finderArgs, this);
441         }
442 
443         if (result == null) {
444             Session session = null;
445 
446             try {
447                 session = openSession();
448 
449                 StringBuilder query = new StringBuilder();
450 
451                 query.append(
452                     "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ");
453 
454                 query.append("wikiPageResource.nodeId = ?");
455 
456                 query.append(" AND ");
457 
458                 if (title == null) {
459                     query.append("wikiPageResource.title IS NULL");
460                 }
461                 else {
462                     query.append("wikiPageResource.title = ?");
463                 }
464 
465                 query.append(" ");
466 
467                 Query q = session.createQuery(query.toString());
468 
469                 QueryPos qPos = QueryPos.getInstance(q);
470 
471                 qPos.add(nodeId);
472 
473                 if (title != null) {
474                     qPos.add(title);
475                 }
476 
477                 List<WikiPageResource> list = q.list();
478 
479                 result = list;
480 
481                 WikiPageResource wikiPageResource = null;
482 
483                 if (list.isEmpty()) {
484                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
485                         finderArgs, list);
486                 }
487                 else {
488                     wikiPageResource = list.get(0);
489 
490                     cacheResult(wikiPageResource);
491 
492                     if ((wikiPageResource.getNodeId() != nodeId) ||
493                             (wikiPageResource.getTitle() == null) ||
494                             !wikiPageResource.getTitle().equals(title)) {
495                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
496                             finderArgs, wikiPageResource);
497                     }
498                 }
499 
500                 return wikiPageResource;
501             }
502             catch (Exception e) {
503                 throw processException(e);
504             }
505             finally {
506                 if (result == null) {
507                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
508                         finderArgs, new ArrayList<WikiPageResource>());
509                 }
510 
511                 closeSession(session);
512             }
513         }
514         else {
515             if (result instanceof List<?>) {
516                 return null;
517             }
518             else {
519                 return (WikiPageResource)result;
520             }
521         }
522     }
523 
524     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
525         throws SystemException {
526         Session session = null;
527 
528         try {
529             session = openSession();
530 
531             dynamicQuery.compile(session);
532 
533             return dynamicQuery.list();
534         }
535         catch (Exception e) {
536             throw processException(e);
537         }
538         finally {
539             closeSession(session);
540         }
541     }
542 
543     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
544         int start, int end) throws SystemException {
545         Session session = null;
546 
547         try {
548             session = openSession();
549 
550             dynamicQuery.setLimit(start, end);
551 
552             dynamicQuery.compile(session);
553 
554             return dynamicQuery.list();
555         }
556         catch (Exception e) {
557             throw processException(e);
558         }
559         finally {
560             closeSession(session);
561         }
562     }
563 
564     public List<WikiPageResource> findAll() throws SystemException {
565         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
566     }
567 
568     public List<WikiPageResource> findAll(int start, int end)
569         throws SystemException {
570         return findAll(start, end, null);
571     }
572 
573     public List<WikiPageResource> findAll(int start, int end,
574         OrderByComparator obc) throws SystemException {
575         Object[] finderArgs = new Object[] {
576                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
577             };
578 
579         List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
580                 finderArgs, this);
581 
582         if (list == null) {
583             Session session = null;
584 
585             try {
586                 session = openSession();
587 
588                 StringBuilder query = new StringBuilder();
589 
590                 query.append(
591                     "SELECT wikiPageResource FROM WikiPageResource wikiPageResource ");
592 
593                 if (obc != null) {
594                     query.append("ORDER BY ");
595 
596                     String[] orderByFields = obc.getOrderByFields();
597 
598                     for (int i = 0; i < orderByFields.length; i++) {
599                         query.append("wikiPageResource.");
600                         query.append(orderByFields[i]);
601 
602                         if (obc.isAscending()) {
603                             query.append(" ASC");
604                         }
605                         else {
606                             query.append(" DESC");
607                         }
608 
609                         if ((i + 1) < orderByFields.length) {
610                             query.append(", ");
611                         }
612                     }
613                 }
614 
615                 Query q = session.createQuery(query.toString());
616 
617                 if (obc == null) {
618                     list = (List<WikiPageResource>)QueryUtil.list(q,
619                             getDialect(), start, end, false);
620 
621                     Collections.sort(list);
622                 }
623                 else {
624                     list = (List<WikiPageResource>)QueryUtil.list(q,
625                             getDialect(), start, end);
626                 }
627             }
628             catch (Exception e) {
629                 throw processException(e);
630             }
631             finally {
632                 if (list == null) {
633                     list = new ArrayList<WikiPageResource>();
634                 }
635 
636                 cacheResult(list);
637 
638                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
639 
640                 closeSession(session);
641             }
642         }
643 
644         return list;
645     }
646 
647     public void removeByN_T(long nodeId, String title)
648         throws NoSuchPageResourceException, SystemException {
649         WikiPageResource wikiPageResource = findByN_T(nodeId, title);
650 
651         remove(wikiPageResource);
652     }
653 
654     public void removeAll() throws SystemException {
655         for (WikiPageResource wikiPageResource : findAll()) {
656             remove(wikiPageResource);
657         }
658     }
659 
660     public int countByN_T(long nodeId, String title) throws SystemException {
661         Object[] finderArgs = new Object[] { new Long(nodeId), title };
662 
663         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T,
664                 finderArgs, this);
665 
666         if (count == null) {
667             Session session = null;
668 
669             try {
670                 session = openSession();
671 
672                 StringBuilder query = new StringBuilder();
673 
674                 query.append("SELECT COUNT(wikiPageResource) ");
675                 query.append("FROM WikiPageResource wikiPageResource WHERE ");
676 
677                 query.append("wikiPageResource.nodeId = ?");
678 
679                 query.append(" AND ");
680 
681                 if (title == null) {
682                     query.append("wikiPageResource.title IS NULL");
683                 }
684                 else {
685                     query.append("wikiPageResource.title = ?");
686                 }
687 
688                 query.append(" ");
689 
690                 Query q = session.createQuery(query.toString());
691 
692                 QueryPos qPos = QueryPos.getInstance(q);
693 
694                 qPos.add(nodeId);
695 
696                 if (title != null) {
697                     qPos.add(title);
698                 }
699 
700                 count = (Long)q.uniqueResult();
701             }
702             catch (Exception e) {
703                 throw processException(e);
704             }
705             finally {
706                 if (count == null) {
707                     count = Long.valueOf(0);
708                 }
709 
710                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, finderArgs,
711                     count);
712 
713                 closeSession(session);
714             }
715         }
716 
717         return count.intValue();
718     }
719 
720     public int countAll() throws SystemException {
721         Object[] finderArgs = new Object[0];
722 
723         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
724                 finderArgs, this);
725 
726         if (count == null) {
727             Session session = null;
728 
729             try {
730                 session = openSession();
731 
732                 Query q = session.createQuery(
733                         "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource");
734 
735                 count = (Long)q.uniqueResult();
736             }
737             catch (Exception e) {
738                 throw processException(e);
739             }
740             finally {
741                 if (count == null) {
742                     count = Long.valueOf(0);
743                 }
744 
745                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
746                     count);
747 
748                 closeSession(session);
749             }
750         }
751 
752         return count.intValue();
753     }
754 
755     public void afterPropertiesSet() {
756         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
757                     com.liferay.portal.util.PropsUtil.get(
758                         "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
759 
760         if (listenerClassNames.length > 0) {
761             try {
762                 List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
763 
764                 for (String listenerClassName : listenerClassNames) {
765                     listenersList.add((ModelListener<WikiPageResource>)Class.forName(
766                             listenerClassName).newInstance());
767                 }
768 
769                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
770             }
771             catch (Exception e) {
772                 _log.error(e);
773             }
774         }
775     }
776 
777     @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiNodePersistence.impl")
778     protected com.liferay.portlet.wiki.service.persistence.WikiNodePersistence wikiNodePersistence;
779     @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPagePersistence.impl")
780     protected com.liferay.portlet.wiki.service.persistence.WikiPagePersistence wikiPagePersistence;
781     @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence.impl")
782     protected com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence wikiPageResourcePersistence;
783     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
784     protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
785     @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
786     protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
787     private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
788 }