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