1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.kernel.uuid.PortalUUIDUtil;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.service.persistence.BatchSessionUtil;
46  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
47  
48  import com.liferay.portlet.wiki.NoSuchNodeException;
49  import com.liferay.portlet.wiki.model.WikiNode;
50  import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
51  import com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.List;
56  
57  /**
58   * <a href="WikiNodePersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * @author Brian Wing Shun Chan
61   *
62   */
63  public class WikiNodePersistenceImpl extends BasePersistenceImpl
64      implements WikiNodePersistence {
65      public static final String FINDER_CLASS_NAME_ENTITY = WikiNodeImpl.class.getName();
66      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67          ".List";
68      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
69              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
70              "findByUuid", new String[] { String.class.getName() });
71      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
72              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73              "findByUuid",
74              new String[] {
75                  String.class.getName(),
76                  
77              "java.lang.Integer", "java.lang.Integer",
78                  "com.liferay.portal.kernel.util.OrderByComparator"
79              });
80      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
81              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
82              "countByUuid", new String[] { String.class.getName() });
83      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
84              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
85              "fetchByUUID_G",
86              new String[] { String.class.getName(), Long.class.getName() });
87      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
88              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89              "countByUUID_G",
90              new String[] { String.class.getName(), Long.class.getName() });
91      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
92              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93              "findByGroupId", new String[] { Long.class.getName() });
94      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
95              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96              "findByGroupId",
97              new String[] {
98                  Long.class.getName(),
99                  
100             "java.lang.Integer", "java.lang.Integer",
101                 "com.liferay.portal.kernel.util.OrderByComparator"
102             });
103     public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
104             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105             "countByGroupId", new String[] { Long.class.getName() });
106     public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
107             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108             "findByCompanyId", new String[] { Long.class.getName() });
109     public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
110             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111             "findByCompanyId",
112             new String[] {
113                 Long.class.getName(),
114                 
115             "java.lang.Integer", "java.lang.Integer",
116                 "com.liferay.portal.kernel.util.OrderByComparator"
117             });
118     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
119             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
120             "countByCompanyId", new String[] { Long.class.getName() });
121     public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
122             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
123             "fetchByG_N",
124             new String[] { Long.class.getName(), String.class.getName() });
125     public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
126             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
127             "countByG_N",
128             new String[] { Long.class.getName(), String.class.getName() });
129     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
130             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
131             "findAll", new String[0]);
132     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
133             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134             "countAll", new String[0]);
135 
136     public void cacheResult(WikiNode wikiNode) {
137         EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
138             WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
139 
140         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
141             new Object[] { wikiNode.getUuid(), new Long(wikiNode.getGroupId()) },
142             wikiNode);
143 
144         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
145             new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
146             wikiNode);
147     }
148 
149     public void cacheResult(List<WikiNode> wikiNodes) {
150         for (WikiNode wikiNode : wikiNodes) {
151             if (EntityCacheUtil.getResult(
152                         WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
153                         WikiNodeImpl.class, wikiNode.getPrimaryKey(), this) == null) {
154                 cacheResult(wikiNode);
155             }
156         }
157     }
158 
159     public void clearCache() {
160         CacheRegistry.clear(WikiNodeImpl.class.getName());
161         EntityCacheUtil.clearCache(WikiNodeImpl.class.getName());
162         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
163         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
164     }
165 
166     public WikiNode create(long nodeId) {
167         WikiNode wikiNode = new WikiNodeImpl();
168 
169         wikiNode.setNew(true);
170         wikiNode.setPrimaryKey(nodeId);
171 
172         String uuid = PortalUUIDUtil.generate();
173 
174         wikiNode.setUuid(uuid);
175 
176         return wikiNode;
177     }
178 
179     public WikiNode remove(long nodeId)
180         throws NoSuchNodeException, SystemException {
181         Session session = null;
182 
183         try {
184             session = openSession();
185 
186             WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
187                     new Long(nodeId));
188 
189             if (wikiNode == null) {
190                 if (_log.isWarnEnabled()) {
191                     _log.warn("No WikiNode exists with the primary key " +
192                         nodeId);
193                 }
194 
195                 throw new NoSuchNodeException(
196                     "No WikiNode exists with the primary key " + nodeId);
197             }
198 
199             return remove(wikiNode);
200         }
201         catch (NoSuchNodeException nsee) {
202             throw nsee;
203         }
204         catch (Exception e) {
205             throw processException(e);
206         }
207         finally {
208             closeSession(session);
209         }
210     }
211 
212     public WikiNode remove(WikiNode wikiNode) throws SystemException {
213         for (ModelListener<WikiNode> listener : listeners) {
214             listener.onBeforeRemove(wikiNode);
215         }
216 
217         wikiNode = removeImpl(wikiNode);
218 
219         for (ModelListener<WikiNode> listener : listeners) {
220             listener.onAfterRemove(wikiNode);
221         }
222 
223         return wikiNode;
224     }
225 
226     protected WikiNode removeImpl(WikiNode wikiNode) throws SystemException {
227         Session session = null;
228 
229         try {
230             session = openSession();
231 
232             if (wikiNode.isCachedModel() || BatchSessionUtil.isEnabled()) {
233                 Object staleObject = session.get(WikiNodeImpl.class,
234                         wikiNode.getPrimaryKeyObj());
235 
236                 if (staleObject != null) {
237                     session.evict(staleObject);
238                 }
239             }
240 
241             session.delete(wikiNode);
242 
243             session.flush();
244         }
245         catch (Exception e) {
246             throw processException(e);
247         }
248         finally {
249             closeSession(session);
250         }
251 
252         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
253 
254         WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
255 
256         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
257             new Object[] {
258                 wikiNodeModelImpl.getOriginalUuid(),
259                 new Long(wikiNodeModelImpl.getOriginalGroupId())
260             });
261 
262         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
263             new Object[] {
264                 new Long(wikiNodeModelImpl.getOriginalGroupId()),
265                 
266             wikiNodeModelImpl.getOriginalName()
267             });
268 
269         EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
270             WikiNodeImpl.class, wikiNode.getPrimaryKey());
271 
272         return wikiNode;
273     }
274 
275     /**
276      * @deprecated Use <code>update(WikiNode wikiNode, boolean merge)</code>.
277      */
278     public WikiNode update(WikiNode wikiNode) throws SystemException {
279         if (_log.isWarnEnabled()) {
280             _log.warn(
281                 "Using the deprecated update(WikiNode wikiNode) method. Use update(WikiNode wikiNode, boolean merge) instead.");
282         }
283 
284         return update(wikiNode, false);
285     }
286 
287     /**
288      * Add, update, or merge, the entity. This method also calls the model
289      * listeners to trigger the proper events associated with adding, deleting,
290      * or updating an entity.
291      *
292      * @param        wikiNode the entity to add, update, or merge
293      * @param        merge boolean value for whether to merge the entity. The
294      *                default value is false. Setting merge to true is more
295      *                expensive and should only be true when wikiNode is
296      *                transient. See LEP-5473 for a detailed discussion of this
297      *                method.
298      * @return        true if the portlet can be displayed via Ajax
299      */
300     public WikiNode update(WikiNode wikiNode, boolean merge)
301         throws SystemException {
302         boolean isNew = wikiNode.isNew();
303 
304         for (ModelListener<WikiNode> listener : listeners) {
305             if (isNew) {
306                 listener.onBeforeCreate(wikiNode);
307             }
308             else {
309                 listener.onBeforeUpdate(wikiNode);
310             }
311         }
312 
313         wikiNode = updateImpl(wikiNode, merge);
314 
315         for (ModelListener<WikiNode> listener : listeners) {
316             if (isNew) {
317                 listener.onAfterCreate(wikiNode);
318             }
319             else {
320                 listener.onAfterUpdate(wikiNode);
321             }
322         }
323 
324         return wikiNode;
325     }
326 
327     public WikiNode updateImpl(
328         com.liferay.portlet.wiki.model.WikiNode wikiNode, boolean merge)
329         throws SystemException {
330         boolean isNew = wikiNode.isNew();
331 
332         WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
333 
334         if (Validator.isNull(wikiNode.getUuid())) {
335             String uuid = PortalUUIDUtil.generate();
336 
337             wikiNode.setUuid(uuid);
338         }
339 
340         Session session = null;
341 
342         try {
343             session = openSession();
344 
345             BatchSessionUtil.update(session, wikiNode, merge);
346 
347             wikiNode.setNew(false);
348         }
349         catch (Exception e) {
350             throw processException(e);
351         }
352         finally {
353             closeSession(session);
354         }
355 
356         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
357 
358         EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
359             WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
360 
361         if (!isNew &&
362                 (!Validator.equals(wikiNode.getUuid(),
363                     wikiNodeModelImpl.getOriginalUuid()) ||
364                 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
365             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
366                 new Object[] {
367                     wikiNodeModelImpl.getOriginalUuid(),
368                     new Long(wikiNodeModelImpl.getOriginalGroupId())
369                 });
370         }
371 
372         if (isNew ||
373                 (!Validator.equals(wikiNode.getUuid(),
374                     wikiNodeModelImpl.getOriginalUuid()) ||
375                 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
376             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
377                 new Object[] { wikiNode.getUuid(), new Long(
378                         wikiNode.getGroupId()) }, wikiNode);
379         }
380 
381         if (!isNew &&
382                 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
383                 !Validator.equals(wikiNode.getName(),
384                     wikiNodeModelImpl.getOriginalName()))) {
385             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
386                 new Object[] {
387                     new Long(wikiNodeModelImpl.getOriginalGroupId()),
388                     
389                 wikiNodeModelImpl.getOriginalName()
390                 });
391         }
392 
393         if (isNew ||
394                 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
395                 !Validator.equals(wikiNode.getName(),
396                     wikiNodeModelImpl.getOriginalName()))) {
397             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
398                 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
399                 wikiNode);
400         }
401 
402         return wikiNode;
403     }
404 
405     public WikiNode findByPrimaryKey(long nodeId)
406         throws NoSuchNodeException, SystemException {
407         WikiNode wikiNode = fetchByPrimaryKey(nodeId);
408 
409         if (wikiNode == null) {
410             if (_log.isWarnEnabled()) {
411                 _log.warn("No WikiNode exists with the primary key " + nodeId);
412             }
413 
414             throw new NoSuchNodeException(
415                 "No WikiNode exists with the primary key " + nodeId);
416         }
417 
418         return wikiNode;
419     }
420 
421     public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
422         WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
423                 WikiNodeImpl.class, nodeId, this);
424 
425         if (wikiNode == null) {
426             Session session = null;
427 
428             try {
429                 session = openSession();
430 
431                 wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
432                         new Long(nodeId));
433             }
434             catch (Exception e) {
435                 throw processException(e);
436             }
437             finally {
438                 if (wikiNode != null) {
439                     cacheResult(wikiNode);
440                 }
441 
442                 closeSession(session);
443             }
444         }
445 
446         return wikiNode;
447     }
448 
449     public List<WikiNode> findByUuid(String uuid) throws SystemException {
450         Object[] finderArgs = new Object[] { uuid };
451 
452         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
453                 finderArgs, this);
454 
455         if (list == null) {
456             Session session = null;
457 
458             try {
459                 session = openSession();
460 
461                 StringBuilder query = new StringBuilder();
462 
463                 query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
464 
465                 if (uuid == null) {
466                     query.append("wikiNode.uuid IS NULL");
467                 }
468                 else {
469                     query.append("wikiNode.uuid = ?");
470                 }
471 
472                 query.append(" ");
473 
474                 query.append("ORDER BY ");
475 
476                 query.append("wikiNode.name ASC");
477 
478                 Query q = session.createQuery(query.toString());
479 
480                 QueryPos qPos = QueryPos.getInstance(q);
481 
482                 if (uuid != null) {
483                     qPos.add(uuid);
484                 }
485 
486                 list = q.list();
487             }
488             catch (Exception e) {
489                 throw processException(e);
490             }
491             finally {
492                 if (list == null) {
493                     list = new ArrayList<WikiNode>();
494                 }
495 
496                 cacheResult(list);
497 
498                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
499                     list);
500 
501                 closeSession(session);
502             }
503         }
504 
505         return list;
506     }
507 
508     public List<WikiNode> findByUuid(String uuid, int start, int end)
509         throws SystemException {
510         return findByUuid(uuid, start, end, null);
511     }
512 
513     public List<WikiNode> findByUuid(String uuid, int start, int end,
514         OrderByComparator obc) throws SystemException {
515         Object[] finderArgs = new Object[] {
516                 uuid,
517                 
518                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
519             };
520 
521         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
522                 finderArgs, this);
523 
524         if (list == null) {
525             Session session = null;
526 
527             try {
528                 session = openSession();
529 
530                 StringBuilder query = new StringBuilder();
531 
532                 query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
533 
534                 if (uuid == null) {
535                     query.append("wikiNode.uuid IS NULL");
536                 }
537                 else {
538                     query.append("wikiNode.uuid = ?");
539                 }
540 
541                 query.append(" ");
542 
543                 if (obc != null) {
544                     query.append("ORDER BY ");
545 
546                     String[] orderByFields = obc.getOrderByFields();
547 
548                     for (int i = 0; i < orderByFields.length; i++) {
549                         query.append("wikiNode.");
550                         query.append(orderByFields[i]);
551 
552                         if (obc.isAscending()) {
553                             query.append(" ASC");
554                         }
555                         else {
556                             query.append(" DESC");
557                         }
558 
559                         if ((i + 1) < orderByFields.length) {
560                             query.append(", ");
561                         }
562                     }
563                 }
564 
565                 else {
566                     query.append("ORDER BY ");
567 
568                     query.append("wikiNode.name ASC");
569                 }
570 
571                 Query q = session.createQuery(query.toString());
572 
573                 QueryPos qPos = QueryPos.getInstance(q);
574 
575                 if (uuid != null) {
576                     qPos.add(uuid);
577                 }
578 
579                 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
580                         end);
581             }
582             catch (Exception e) {
583                 throw processException(e);
584             }
585             finally {
586                 if (list == null) {
587                     list = new ArrayList<WikiNode>();
588                 }
589 
590                 cacheResult(list);
591 
592                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
593                     finderArgs, list);
594 
595                 closeSession(session);
596             }
597         }
598 
599         return list;
600     }
601 
602     public WikiNode findByUuid_First(String uuid, OrderByComparator obc)
603         throws NoSuchNodeException, SystemException {
604         List<WikiNode> list = findByUuid(uuid, 0, 1, obc);
605 
606         if (list.isEmpty()) {
607             StringBuilder msg = new StringBuilder();
608 
609             msg.append("No WikiNode exists with the key {");
610 
611             msg.append("uuid=" + uuid);
612 
613             msg.append(StringPool.CLOSE_CURLY_BRACE);
614 
615             throw new NoSuchNodeException(msg.toString());
616         }
617         else {
618             return list.get(0);
619         }
620     }
621 
622     public WikiNode findByUuid_Last(String uuid, OrderByComparator obc)
623         throws NoSuchNodeException, SystemException {
624         int count = countByUuid(uuid);
625 
626         List<WikiNode> list = findByUuid(uuid, count - 1, count, obc);
627 
628         if (list.isEmpty()) {
629             StringBuilder msg = new StringBuilder();
630 
631             msg.append("No WikiNode exists with the key {");
632 
633             msg.append("uuid=" + uuid);
634 
635             msg.append(StringPool.CLOSE_CURLY_BRACE);
636 
637             throw new NoSuchNodeException(msg.toString());
638         }
639         else {
640             return list.get(0);
641         }
642     }
643 
644     public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
645         OrderByComparator obc) throws NoSuchNodeException, SystemException {
646         WikiNode wikiNode = findByPrimaryKey(nodeId);
647 
648         int count = countByUuid(uuid);
649 
650         Session session = null;
651 
652         try {
653             session = openSession();
654 
655             StringBuilder query = new StringBuilder();
656 
657             query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
658 
659             if (uuid == null) {
660                 query.append("wikiNode.uuid IS NULL");
661             }
662             else {
663                 query.append("wikiNode.uuid = ?");
664             }
665 
666             query.append(" ");
667 
668             if (obc != null) {
669                 query.append("ORDER BY ");
670 
671                 String[] orderByFields = obc.getOrderByFields();
672 
673                 for (int i = 0; i < orderByFields.length; i++) {
674                     query.append("wikiNode.");
675                     query.append(orderByFields[i]);
676 
677                     if (obc.isAscending()) {
678                         query.append(" ASC");
679                     }
680                     else {
681                         query.append(" DESC");
682                     }
683 
684                     if ((i + 1) < orderByFields.length) {
685                         query.append(", ");
686                     }
687                 }
688             }
689 
690             else {
691                 query.append("ORDER BY ");
692 
693                 query.append("wikiNode.name ASC");
694             }
695 
696             Query q = session.createQuery(query.toString());
697 
698             QueryPos qPos = QueryPos.getInstance(q);
699 
700             if (uuid != null) {
701                 qPos.add(uuid);
702             }
703 
704             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, wikiNode);
705 
706             WikiNode[] array = new WikiNodeImpl[3];
707 
708             array[0] = (WikiNode)objArray[0];
709             array[1] = (WikiNode)objArray[1];
710             array[2] = (WikiNode)objArray[2];
711 
712             return array;
713         }
714         catch (Exception e) {
715             throw processException(e);
716         }
717         finally {
718             closeSession(session);
719         }
720     }
721 
722     public WikiNode findByUUID_G(String uuid, long groupId)
723         throws NoSuchNodeException, SystemException {
724         WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
725 
726         if (wikiNode == null) {
727             StringBuilder msg = new StringBuilder();
728 
729             msg.append("No WikiNode exists with the key {");
730 
731             msg.append("uuid=" + uuid);
732 
733             msg.append(", ");
734             msg.append("groupId=" + groupId);
735 
736             msg.append(StringPool.CLOSE_CURLY_BRACE);
737 
738             if (_log.isWarnEnabled()) {
739                 _log.warn(msg.toString());
740             }
741 
742             throw new NoSuchNodeException(msg.toString());
743         }
744 
745         return wikiNode;
746     }
747 
748     public WikiNode fetchByUUID_G(String uuid, long groupId)
749         throws SystemException {
750         return fetchByUUID_G(uuid, groupId, true);
751     }
752 
753     public WikiNode fetchByUUID_G(String uuid, long groupId,
754         boolean retrieveFromCache) throws SystemException {
755         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
756 
757         Object result = null;
758 
759         if (retrieveFromCache) {
760             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
761                     finderArgs, this);
762         }
763 
764         if (result == null) {
765             Session session = null;
766 
767             try {
768                 session = openSession();
769 
770                 StringBuilder query = new StringBuilder();
771 
772                 query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
773 
774                 if (uuid == null) {
775                     query.append("wikiNode.uuid IS NULL");
776                 }
777                 else {
778                     query.append("wikiNode.uuid = ?");
779                 }
780 
781                 query.append(" AND ");
782 
783                 query.append("wikiNode.groupId = ?");
784 
785                 query.append(" ");
786 
787                 query.append("ORDER BY ");
788 
789                 query.append("wikiNode.name ASC");
790 
791                 Query q = session.createQuery(query.toString());
792 
793                 QueryPos qPos = QueryPos.getInstance(q);
794 
795                 if (uuid != null) {
796                     qPos.add(uuid);
797                 }
798 
799                 qPos.add(groupId);
800 
801                 List<WikiNode> list = q.list();
802 
803                 result = list;
804 
805                 WikiNode wikiNode = null;
806 
807                 if (list.isEmpty()) {
808                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
809                         finderArgs, list);
810                 }
811                 else {
812                     wikiNode = list.get(0);
813 
814                     cacheResult(wikiNode);
815 
816                     if ((wikiNode.getUuid() == null) ||
817                             !wikiNode.getUuid().equals(uuid) ||
818                             (wikiNode.getGroupId() != groupId)) {
819                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
820                             finderArgs, wikiNode);
821                     }
822                 }
823 
824                 return wikiNode;
825             }
826             catch (Exception e) {
827                 throw processException(e);
828             }
829             finally {
830                 if (result == null) {
831                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
832                         finderArgs, new ArrayList<WikiNode>());
833                 }
834 
835                 closeSession(session);
836             }
837         }
838         else {
839             if (result instanceof List) {
840                 return null;
841             }
842             else {
843                 return (WikiNode)result;
844             }
845         }
846     }
847 
848     public List<WikiNode> findByGroupId(long groupId) throws SystemException {
849         Object[] finderArgs = new Object[] { new Long(groupId) };
850 
851         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
852                 finderArgs, this);
853 
854         if (list == null) {
855             Session session = null;
856 
857             try {
858                 session = openSession();
859 
860                 StringBuilder query = new StringBuilder();
861 
862                 query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
863 
864                 query.append("wikiNode.groupId = ?");
865 
866                 query.append(" ");
867 
868                 query.append("ORDER BY ");
869 
870                 query.append("wikiNode.name ASC");
871 
872                 Query q = session.createQuery(query.toString());
873 
874                 QueryPos qPos = QueryPos.getInstance(q);
875 
876                 qPos.add(groupId);
877 
878                 list = q.list();
879             }
880             catch (Exception e) {
881                 throw processException(e);
882             }
883             finally {
884                 if (list == null) {
885                     list = new ArrayList<WikiNode>();
886                 }
887 
888                 cacheResult(list);
889 
890                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
891                     finderArgs, list);
892 
893                 closeSession(session);
894             }
895         }
896 
897         return list;
898     }
899 
900     public List<WikiNode> findByGroupId(long groupId, int start, int end)
901         throws SystemException {
902         return findByGroupId(groupId, start, end, null);
903     }
904 
905     public List<WikiNode> findByGroupId(long groupId, int start, int end,
906         OrderByComparator obc) throws SystemException {
907         Object[] finderArgs = new Object[] {
908                 new Long(groupId),
909                 
910                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
911             };
912 
913         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
914                 finderArgs, this);
915 
916         if (list == null) {
917             Session session = null;
918 
919             try {
920                 session = openSession();
921 
922                 StringBuilder query = new StringBuilder();
923 
924                 query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
925 
926                 query.append("wikiNode.groupId = ?");
927 
928                 query.append(" ");
929 
930                 if (obc != null) {
931                     query.append("ORDER BY ");
932 
933                     String[] orderByFields = obc.getOrderByFields();
934 
935                     for (int i = 0; i < orderByFields.length; i++) {
936                         query.append("wikiNode.");
937                         query.append(orderByFields[i]);
938 
939                         if (obc.isAscending()) {
940                             query.append(" ASC");
941                         }
942                         else {
943                             query.append(" DESC");
944                         }
945 
946                         if ((i + 1) < orderByFields.length) {
947                             query.append(", ");
948                         }
949                     }
950                 }
951 
952                 else {
953                     query.append("ORDER BY ");
954 
955                     query.append("wikiNode.name ASC");
956                 }
957 
958                 Query q = session.createQuery(query.toString());
959 
960                 QueryPos qPos = QueryPos.getInstance(q);
961 
962                 qPos.add(groupId);
963 
964                 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
965                         end);
966             }
967             catch (Exception e) {
968                 throw processException(e);
969             }
970             finally {
971                 if (list == null) {
972                     list = new ArrayList<WikiNode>();
973                 }
974 
975                 cacheResult(list);
976 
977                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
978                     finderArgs, list);
979 
980                 closeSession(session);
981             }
982         }
983 
984         return list;
985     }
986 
987     public WikiNode findByGroupId_First(long groupId, OrderByComparator obc)
988         throws NoSuchNodeException, SystemException {
989         List<WikiNode> list = findByGroupId(groupId, 0, 1, obc);
990 
991         if (list.isEmpty()) {
992             StringBuilder msg = new StringBuilder();
993 
994             msg.append("No WikiNode exists with the key {");
995 
996             msg.append("groupId=" + groupId);
997 
998             msg.append(StringPool.CLOSE_CURLY_BRACE);
999 
1000            throw new NoSuchNodeException(msg.toString());
1001        }
1002        else {
1003            return list.get(0);
1004        }
1005    }
1006
1007    public WikiNode findByGroupId_Last(long groupId, OrderByComparator obc)
1008        throws NoSuchNodeException, SystemException {
1009        int count = countByGroupId(groupId);
1010
1011        List<WikiNode> list = findByGroupId(groupId, count - 1, count, obc);
1012
1013        if (list.isEmpty()) {
1014            StringBuilder msg = new StringBuilder();
1015
1016            msg.append("No WikiNode exists with the key {");
1017
1018            msg.append("groupId=" + groupId);
1019
1020            msg.append(StringPool.CLOSE_CURLY_BRACE);
1021
1022            throw new NoSuchNodeException(msg.toString());
1023        }
1024        else {
1025            return list.get(0);
1026        }
1027    }
1028
1029    public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
1030        OrderByComparator obc) throws NoSuchNodeException, SystemException {
1031        WikiNode wikiNode = findByPrimaryKey(nodeId);
1032
1033        int count = countByGroupId(groupId);
1034
1035        Session session = null;
1036
1037        try {
1038            session = openSession();
1039
1040            StringBuilder query = new StringBuilder();
1041
1042            query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
1043
1044            query.append("wikiNode.groupId = ?");
1045
1046            query.append(" ");
1047
1048            if (obc != null) {
1049                query.append("ORDER BY ");
1050
1051                String[] orderByFields = obc.getOrderByFields();
1052
1053                for (int i = 0; i < orderByFields.length; i++) {
1054                    query.append("wikiNode.");
1055                    query.append(orderByFields[i]);
1056
1057                    if (obc.isAscending()) {
1058                        query.append(" ASC");
1059                    }
1060                    else {
1061                        query.append(" DESC");
1062                    }
1063
1064                    if ((i + 1) < orderByFields.length) {
1065                        query.append(", ");
1066                    }
1067                }
1068            }
1069
1070            else {
1071                query.append("ORDER BY ");
1072
1073                query.append("wikiNode.name ASC");
1074            }
1075
1076            Query q = session.createQuery(query.toString());
1077
1078            QueryPos qPos = QueryPos.getInstance(q);
1079
1080            qPos.add(groupId);
1081
1082            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, wikiNode);
1083
1084            WikiNode[] array = new WikiNodeImpl[3];
1085
1086            array[0] = (WikiNode)objArray[0];
1087            array[1] = (WikiNode)objArray[1];
1088            array[2] = (WikiNode)objArray[2];
1089
1090            return array;
1091        }
1092        catch (Exception e) {
1093            throw processException(e);
1094        }
1095        finally {
1096            closeSession(session);
1097        }
1098    }
1099
1100    public List<WikiNode> findByCompanyId(long companyId)
1101        throws SystemException {
1102        Object[] finderArgs = new Object[] { new Long(companyId) };
1103
1104        List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1105                finderArgs, this);
1106
1107        if (list == null) {
1108            Session session = null;
1109
1110            try {
1111                session = openSession();
1112
1113                StringBuilder query = new StringBuilder();
1114
1115                query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
1116
1117                query.append("wikiNode.companyId = ?");
1118
1119                query.append(" ");
1120
1121                query.append("ORDER BY ");
1122
1123                query.append("wikiNode.name ASC");
1124
1125                Query q = session.createQuery(query.toString());
1126
1127                QueryPos qPos = QueryPos.getInstance(q);
1128
1129                qPos.add(companyId);
1130
1131                list = q.list();
1132            }
1133            catch (Exception e) {
1134                throw processException(e);
1135            }
1136            finally {
1137                if (list == null) {
1138                    list = new ArrayList<WikiNode>();
1139                }
1140
1141                cacheResult(list);
1142
1143                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1144                    finderArgs, list);
1145
1146                closeSession(session);
1147            }
1148        }
1149
1150        return list;
1151    }
1152
1153    public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1154        throws SystemException {
1155        return findByCompanyId(companyId, start, end, null);
1156    }
1157
1158    public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1159        OrderByComparator obc) throws SystemException {
1160        Object[] finderArgs = new Object[] {
1161                new Long(companyId),
1162                
1163                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1164            };
1165
1166        List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1167                finderArgs, this);
1168
1169        if (list == null) {
1170            Session session = null;
1171
1172            try {
1173                session = openSession();
1174
1175                StringBuilder query = new StringBuilder();
1176
1177                query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
1178
1179                query.append("wikiNode.companyId = ?");
1180
1181                query.append(" ");
1182
1183                if (obc != null) {
1184                    query.append("ORDER BY ");
1185
1186                    String[] orderByFields = obc.getOrderByFields();
1187
1188                    for (int i = 0; i < orderByFields.length; i++) {
1189                        query.append("wikiNode.");
1190                        query.append(orderByFields[i]);
1191
1192                        if (obc.isAscending()) {
1193                            query.append(" ASC");
1194                        }
1195                        else {
1196                            query.append(" DESC");
1197                        }
1198
1199                        if ((i + 1) < orderByFields.length) {
1200                            query.append(", ");
1201                        }
1202                    }
1203                }
1204
1205                else {
1206                    query.append("ORDER BY ");
1207
1208                    query.append("wikiNode.name ASC");
1209                }
1210
1211                Query q = session.createQuery(query.toString());
1212
1213                QueryPos qPos = QueryPos.getInstance(q);
1214
1215                qPos.add(companyId);
1216
1217                list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1218                        end);
1219            }
1220            catch (Exception e) {
1221                throw processException(e);
1222            }
1223            finally {
1224                if (list == null) {
1225                    list = new ArrayList<WikiNode>();
1226                }
1227
1228                cacheResult(list);
1229
1230                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1231                    finderArgs, list);
1232
1233                closeSession(session);
1234            }
1235        }
1236
1237        return list;
1238    }
1239
1240    public WikiNode findByCompanyId_First(long companyId, OrderByComparator obc)
1241        throws NoSuchNodeException, SystemException {
1242        List<WikiNode> list = findByCompanyId(companyId, 0, 1, obc);
1243
1244        if (list.isEmpty()) {
1245            StringBuilder msg = new StringBuilder();
1246
1247            msg.append("No WikiNode exists with the key {");
1248
1249            msg.append("companyId=" + companyId);
1250
1251            msg.append(StringPool.CLOSE_CURLY_BRACE);
1252
1253            throw new NoSuchNodeException(msg.toString());
1254        }
1255        else {
1256            return list.get(0);
1257        }
1258    }
1259
1260    public WikiNode findByCompanyId_Last(long companyId, OrderByComparator obc)
1261        throws NoSuchNodeException, SystemException {
1262        int count = countByCompanyId(companyId);
1263
1264        List<WikiNode> list = findByCompanyId(companyId, count - 1, count, obc);
1265
1266        if (list.isEmpty()) {
1267            StringBuilder msg = new StringBuilder();
1268
1269            msg.append("No WikiNode exists with the key {");
1270
1271            msg.append("companyId=" + companyId);
1272
1273            msg.append(StringPool.CLOSE_CURLY_BRACE);
1274
1275            throw new NoSuchNodeException(msg.toString());
1276        }
1277        else {
1278            return list.get(0);
1279        }
1280    }
1281
1282    public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
1283        OrderByComparator obc) throws NoSuchNodeException, SystemException {
1284        WikiNode wikiNode = findByPrimaryKey(nodeId);
1285
1286        int count = countByCompanyId(companyId);
1287
1288        Session session = null;
1289
1290        try {
1291            session = openSession();
1292
1293            StringBuilder query = new StringBuilder();
1294
1295            query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
1296
1297            query.append("wikiNode.companyId = ?");
1298
1299            query.append(" ");
1300
1301            if (obc != null) {
1302                query.append("ORDER BY ");
1303
1304                String[] orderByFields = obc.getOrderByFields();
1305
1306                for (int i = 0; i < orderByFields.length; i++) {
1307                    query.append("wikiNode.");
1308                    query.append(orderByFields[i]);
1309
1310                    if (obc.isAscending()) {
1311                        query.append(" ASC");
1312                    }
1313                    else {
1314                        query.append(" DESC");
1315                    }
1316
1317                    if ((i + 1) < orderByFields.length) {
1318                        query.append(", ");
1319                    }
1320                }
1321            }
1322
1323            else {
1324                query.append("ORDER BY ");
1325
1326                query.append("wikiNode.name ASC");
1327            }
1328
1329            Query q = session.createQuery(query.toString());
1330
1331            QueryPos qPos = QueryPos.getInstance(q);
1332
1333            qPos.add(companyId);
1334
1335            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, wikiNode);
1336
1337            WikiNode[] array = new WikiNodeImpl[3];
1338
1339            array[0] = (WikiNode)objArray[0];
1340            array[1] = (WikiNode)objArray[1];
1341            array[2] = (WikiNode)objArray[2];
1342
1343            return array;
1344        }
1345        catch (Exception e) {
1346            throw processException(e);
1347        }
1348        finally {
1349            closeSession(session);
1350        }
1351    }
1352
1353    public WikiNode findByG_N(long groupId, String name)
1354        throws NoSuchNodeException, SystemException {
1355        WikiNode wikiNode = fetchByG_N(groupId, name);
1356
1357        if (wikiNode == null) {
1358            StringBuilder msg = new StringBuilder();
1359
1360            msg.append("No WikiNode exists with the key {");
1361
1362            msg.append("groupId=" + groupId);
1363
1364            msg.append(", ");
1365            msg.append("name=" + name);
1366
1367            msg.append(StringPool.CLOSE_CURLY_BRACE);
1368
1369            if (_log.isWarnEnabled()) {
1370                _log.warn(msg.toString());
1371            }
1372
1373            throw new NoSuchNodeException(msg.toString());
1374        }
1375
1376        return wikiNode;
1377    }
1378
1379    public WikiNode fetchByG_N(long groupId, String name)
1380        throws SystemException {
1381        return fetchByG_N(groupId, name, true);
1382    }
1383
1384    public WikiNode fetchByG_N(long groupId, String name,
1385        boolean retrieveFromCache) throws SystemException {
1386        Object[] finderArgs = new Object[] { new Long(groupId), name };
1387
1388        Object result = null;
1389
1390        if (retrieveFromCache) {
1391            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1392                    finderArgs, this);
1393        }
1394
1395        if (result == null) {
1396            Session session = null;
1397
1398            try {
1399                session = openSession();
1400
1401                StringBuilder query = new StringBuilder();
1402
1403                query.append("SELECT wikiNode FROM WikiNode wikiNode WHERE ");
1404
1405                query.append("wikiNode.groupId = ?");
1406
1407                query.append(" AND ");
1408
1409                if (name == null) {
1410                    query.append("wikiNode.name IS NULL");
1411                }
1412                else {
1413                    query.append("wikiNode.name = ?");
1414                }
1415
1416                query.append(" ");
1417
1418                query.append("ORDER BY ");
1419
1420                query.append("wikiNode.name ASC");
1421
1422                Query q = session.createQuery(query.toString());
1423
1424                QueryPos qPos = QueryPos.getInstance(q);
1425
1426                qPos.add(groupId);
1427
1428                if (name != null) {
1429                    qPos.add(name);
1430                }
1431
1432                List<WikiNode> list = q.list();
1433
1434                result = list;
1435
1436                WikiNode wikiNode = null;
1437
1438                if (list.isEmpty()) {
1439                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1440                        finderArgs, list);
1441                }
1442                else {
1443                    wikiNode = list.get(0);
1444
1445                    cacheResult(wikiNode);
1446
1447                    if ((wikiNode.getGroupId() != groupId) ||
1448                            (wikiNode.getName() == null) ||
1449                            !wikiNode.getName().equals(name)) {
1450                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1451                            finderArgs, wikiNode);
1452                    }
1453                }
1454
1455                return wikiNode;
1456            }
1457            catch (Exception e) {
1458                throw processException(e);
1459            }
1460            finally {
1461                if (result == null) {
1462                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1463                        finderArgs, new ArrayList<WikiNode>());
1464                }
1465
1466                closeSession(session);
1467            }
1468        }
1469        else {
1470            if (result instanceof List) {
1471                return null;
1472            }
1473            else {
1474                return (WikiNode)result;
1475            }
1476        }
1477    }
1478
1479    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1480        throws SystemException {
1481        Session session = null;
1482
1483        try {
1484            session = openSession();
1485
1486            dynamicQuery.compile(session);
1487
1488            return dynamicQuery.list();
1489        }
1490        catch (Exception e) {
1491            throw processException(e);
1492        }
1493        finally {
1494            closeSession(session);
1495        }
1496    }
1497
1498    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1499        int start, int end) throws SystemException {
1500        Session session = null;
1501
1502        try {
1503            session = openSession();
1504
1505            dynamicQuery.setLimit(start, end);
1506
1507            dynamicQuery.compile(session);
1508
1509            return dynamicQuery.list();
1510        }
1511        catch (Exception e) {
1512            throw processException(e);
1513        }
1514        finally {
1515            closeSession(session);
1516        }
1517    }
1518
1519    public List<WikiNode> findAll() throws SystemException {
1520        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1521    }
1522
1523    public List<WikiNode> findAll(int start, int end) throws SystemException {
1524        return findAll(start, end, null);
1525    }
1526
1527    public List<WikiNode> findAll(int start, int end, OrderByComparator obc)
1528        throws SystemException {
1529        Object[] finderArgs = new Object[] {
1530                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1531            };
1532
1533        List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1534                finderArgs, this);
1535
1536        if (list == null) {
1537            Session session = null;
1538
1539            try {
1540                session = openSession();
1541
1542                StringBuilder query = new StringBuilder();
1543
1544                query.append("SELECT wikiNode FROM WikiNode wikiNode ");
1545
1546                if (obc != null) {
1547                    query.append("ORDER BY ");
1548
1549                    String[] orderByFields = obc.getOrderByFields();
1550
1551                    for (int i = 0; i < orderByFields.length; i++) {
1552                        query.append("wikiNode.");
1553                        query.append(orderByFields[i]);
1554
1555                        if (obc.isAscending()) {
1556                            query.append(" ASC");
1557                        }
1558                        else {
1559                            query.append(" DESC");
1560                        }
1561
1562                        if ((i + 1) < orderByFields.length) {
1563                            query.append(", ");
1564                        }
1565                    }
1566                }
1567
1568                else {
1569                    query.append("ORDER BY ");
1570
1571                    query.append("wikiNode.name ASC");
1572                }
1573
1574                Query q = session.createQuery(query.toString());
1575
1576                if (obc == null) {
1577                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1578                            start, end, false);
1579
1580                    Collections.sort(list);
1581                }
1582                else {
1583                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1584                            start, end);
1585                }
1586            }
1587            catch (Exception e) {
1588                throw processException(e);
1589            }
1590            finally {
1591                if (list == null) {
1592                    list = new ArrayList<WikiNode>();
1593                }
1594
1595                cacheResult(list);
1596
1597                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1598
1599                closeSession(session);
1600            }
1601        }
1602
1603        return list;
1604    }
1605
1606    public void removeByUuid(String uuid) throws SystemException {
1607        for (WikiNode wikiNode : findByUuid(uuid)) {
1608            remove(wikiNode);
1609        }
1610    }
1611
1612    public void removeByUUID_G(String uuid, long groupId)
1613        throws NoSuchNodeException, SystemException {
1614        WikiNode wikiNode = findByUUID_G(uuid, groupId);
1615
1616        remove(wikiNode);
1617    }
1618
1619    public void removeByGroupId(long groupId) throws SystemException {
1620        for (WikiNode wikiNode : findByGroupId(groupId)) {
1621            remove(wikiNode);
1622        }
1623    }
1624
1625    public void removeByCompanyId(long companyId) throws SystemException {
1626        for (WikiNode wikiNode : findByCompanyId(companyId)) {
1627            remove(wikiNode);
1628        }
1629    }
1630
1631    public void removeByG_N(long groupId, String name)
1632        throws NoSuchNodeException, SystemException {
1633        WikiNode wikiNode = findByG_N(groupId, name);
1634
1635        remove(wikiNode);
1636    }
1637
1638    public void removeAll() throws SystemException {
1639        for (WikiNode wikiNode : findAll()) {
1640            remove(wikiNode);
1641        }
1642    }
1643
1644    public int countByUuid(String uuid) throws SystemException {
1645        Object[] finderArgs = new Object[] { uuid };
1646
1647        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1648                finderArgs, this);
1649
1650        if (count == null) {
1651            Session session = null;
1652
1653            try {
1654                session = openSession();
1655
1656                StringBuilder query = new StringBuilder();
1657
1658                query.append("SELECT COUNT(wikiNode) ");
1659                query.append("FROM WikiNode wikiNode WHERE ");
1660
1661                if (uuid == null) {
1662                    query.append("wikiNode.uuid IS NULL");
1663                }
1664                else {
1665                    query.append("wikiNode.uuid = ?");
1666                }
1667
1668                query.append(" ");
1669
1670                Query q = session.createQuery(query.toString());
1671
1672                QueryPos qPos = QueryPos.getInstance(q);
1673
1674                if (uuid != null) {
1675                    qPos.add(uuid);
1676                }
1677
1678                count = (Long)q.uniqueResult();
1679            }
1680            catch (Exception e) {
1681                throw processException(e);
1682            }
1683            finally {
1684                if (count == null) {
1685                    count = Long.valueOf(0);
1686                }
1687
1688                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1689                    finderArgs, count);
1690
1691                closeSession(session);
1692            }
1693        }
1694
1695        return count.intValue();
1696    }
1697
1698    public int countByUUID_G(String uuid, long groupId)
1699        throws SystemException {
1700        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1701
1702        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1703                finderArgs, this);
1704
1705        if (count == null) {
1706            Session session = null;
1707
1708            try {
1709                session = openSession();
1710
1711                StringBuilder query = new StringBuilder();
1712
1713                query.append("SELECT COUNT(wikiNode) ");
1714                query.append("FROM WikiNode wikiNode WHERE ");
1715
1716                if (uuid == null) {
1717                    query.append("wikiNode.uuid IS NULL");
1718                }
1719                else {
1720                    query.append("wikiNode.uuid = ?");
1721                }
1722
1723                query.append(" AND ");
1724
1725                query.append("wikiNode.groupId = ?");
1726
1727                query.append(" ");
1728
1729                Query q = session.createQuery(query.toString());
1730
1731                QueryPos qPos = QueryPos.getInstance(q);
1732
1733                if (uuid != null) {
1734                    qPos.add(uuid);
1735                }
1736
1737                qPos.add(groupId);
1738
1739                count = (Long)q.uniqueResult();
1740            }
1741            catch (Exception e) {
1742                throw processException(e);
1743            }
1744            finally {
1745                if (count == null) {
1746                    count = Long.valueOf(0);
1747                }
1748
1749                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1750                    finderArgs, count);
1751
1752                closeSession(session);
1753            }
1754        }
1755
1756        return count.intValue();
1757    }
1758
1759    public int countByGroupId(long groupId) throws SystemException {
1760        Object[] finderArgs = new Object[] { new Long(groupId) };
1761
1762        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1763                finderArgs, this);
1764
1765        if (count == null) {
1766            Session session = null;
1767
1768            try {
1769                session = openSession();
1770
1771                StringBuilder query = new StringBuilder();
1772
1773                query.append("SELECT COUNT(wikiNode) ");
1774                query.append("FROM WikiNode wikiNode WHERE ");
1775
1776                query.append("wikiNode.groupId = ?");
1777
1778                query.append(" ");
1779
1780                Query q = session.createQuery(query.toString());
1781
1782                QueryPos qPos = QueryPos.getInstance(q);
1783
1784                qPos.add(groupId);
1785
1786                count = (Long)q.uniqueResult();
1787            }
1788            catch (Exception e) {
1789                throw processException(e);
1790            }
1791            finally {
1792                if (count == null) {
1793                    count = Long.valueOf(0);
1794                }
1795
1796                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1797                    finderArgs, count);
1798
1799                closeSession(session);
1800            }
1801        }
1802
1803        return count.intValue();
1804    }
1805
1806    public int countByCompanyId(long companyId) throws SystemException {
1807        Object[] finderArgs = new Object[] { new Long(companyId) };
1808
1809        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1810                finderArgs, this);
1811
1812        if (count == null) {
1813            Session session = null;
1814
1815            try {
1816                session = openSession();
1817
1818                StringBuilder query = new StringBuilder();
1819
1820                query.append("SELECT COUNT(wikiNode) ");
1821                query.append("FROM WikiNode wikiNode WHERE ");
1822
1823                query.append("wikiNode.companyId = ?");
1824
1825                query.append(" ");
1826
1827                Query q = session.createQuery(query.toString());
1828
1829                QueryPos qPos = QueryPos.getInstance(q);
1830
1831                qPos.add(companyId);
1832
1833                count = (Long)q.uniqueResult();
1834            }
1835            catch (Exception e) {
1836                throw processException(e);
1837            }
1838            finally {
1839                if (count == null) {
1840                    count = Long.valueOf(0);
1841                }
1842
1843                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1844                    finderArgs, count);
1845
1846                closeSession(session);
1847            }
1848        }
1849
1850        return count.intValue();
1851    }
1852
1853    public int countByG_N(long groupId, String name) throws SystemException {
1854        Object[] finderArgs = new Object[] { new Long(groupId), name };
1855
1856        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1857                finderArgs, this);
1858
1859        if (count == null) {
1860            Session session = null;
1861
1862            try {
1863                session = openSession();
1864
1865                StringBuilder query = new StringBuilder();
1866
1867                query.append("SELECT COUNT(wikiNode) ");
1868                query.append("FROM WikiNode wikiNode WHERE ");
1869
1870                query.append("wikiNode.groupId = ?");
1871
1872                query.append(" AND ");
1873
1874                if (name == null) {
1875                    query.append("wikiNode.name IS NULL");
1876                }
1877                else {
1878                    query.append("wikiNode.name = ?");
1879                }
1880
1881                query.append(" ");
1882
1883                Query q = session.createQuery(query.toString());
1884
1885                QueryPos qPos = QueryPos.getInstance(q);
1886
1887                qPos.add(groupId);
1888
1889                if (name != null) {
1890                    qPos.add(name);
1891                }
1892
1893                count = (Long)q.uniqueResult();
1894            }
1895            catch (Exception e) {
1896                throw processException(e);
1897            }
1898            finally {
1899                if (count == null) {
1900                    count = Long.valueOf(0);
1901                }
1902
1903                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1904                    count);
1905
1906                closeSession(session);
1907            }
1908        }
1909
1910        return count.intValue();
1911    }
1912
1913    public int countAll() throws SystemException {
1914        Object[] finderArgs = new Object[0];
1915
1916        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1917                finderArgs, this);
1918
1919        if (count == null) {
1920            Session session = null;
1921
1922            try {
1923                session = openSession();
1924
1925                Query q = session.createQuery(
1926                        "SELECT COUNT(wikiNode) FROM WikiNode wikiNode");
1927
1928                count = (Long)q.uniqueResult();
1929            }
1930            catch (Exception e) {
1931                throw processException(e);
1932            }
1933            finally {
1934                if (count == null) {
1935                    count = Long.valueOf(0);
1936                }
1937
1938                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1939                    count);
1940
1941                closeSession(session);
1942            }
1943        }
1944
1945        return count.intValue();
1946    }
1947
1948    public void afterPropertiesSet() {
1949        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1950                    com.liferay.portal.util.PropsUtil.get(
1951                        "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
1952
1953        if (listenerClassNames.length > 0) {
1954            try {
1955                List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
1956
1957                for (String listenerClassName : listenerClassNames) {
1958                    listenersList.add((ModelListener<WikiNode>)Class.forName(
1959                            listenerClassName).newInstance());
1960                }
1961
1962                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1963            }
1964            catch (Exception e) {
1965                _log.error(e);
1966            }
1967        }
1968    }
1969
1970    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiNodePersistence.impl")
1971    protected com.liferay.portlet.wiki.service.persistence.WikiNodePersistence wikiNodePersistence;
1972    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPagePersistence.impl")
1973    protected com.liferay.portlet.wiki.service.persistence.WikiPagePersistence wikiPagePersistence;
1974    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence.impl")
1975    protected com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence wikiPageResourcePersistence;
1976    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1977    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1978    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1979    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1980    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1981    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1982    private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
1983}