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