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                 (!wikiNode.getUuid().equals(wikiNodeModelImpl.getOriginalUuid()) ||
360                 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
361             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
362                 new Object[] {
363                     wikiNodeModelImpl.getOriginalUuid(),
364                     new Long(wikiNodeModelImpl.getOriginalGroupId())
365                 });
366         }
367 
368         if (isNew ||
369                 (!wikiNode.getUuid().equals(wikiNodeModelImpl.getOriginalUuid()) ||
370                 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
371             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
372                 new Object[] { wikiNode.getUuid(), new Long(
373                         wikiNode.getGroupId()) }, wikiNode);
374         }
375 
376         if (!isNew &&
377                 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
378                 !wikiNode.getName().equals(wikiNodeModelImpl.getOriginalName()))) {
379             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
380                 new Object[] {
381                     new Long(wikiNodeModelImpl.getOriginalGroupId()),
382                     
383                 wikiNodeModelImpl.getOriginalName()
384                 });
385         }
386 
387         if (isNew ||
388                 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
389                 !wikiNode.getName().equals(wikiNodeModelImpl.getOriginalName()))) {
390             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
391                 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
392                 wikiNode);
393         }
394 
395         return wikiNode;
396     }
397 
398     public WikiNode findByPrimaryKey(long nodeId)
399         throws NoSuchNodeException, SystemException {
400         WikiNode wikiNode = fetchByPrimaryKey(nodeId);
401 
402         if (wikiNode == null) {
403             if (_log.isWarnEnabled()) {
404                 _log.warn("No WikiNode exists with the primary key " + nodeId);
405             }
406 
407             throw new NoSuchNodeException(
408                 "No WikiNode exists with the primary key " + nodeId);
409         }
410 
411         return wikiNode;
412     }
413 
414     public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
415         WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
416                 WikiNodeImpl.class, nodeId, this);
417 
418         if (wikiNode == null) {
419             Session session = null;
420 
421             try {
422                 session = openSession();
423 
424                 wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
425                         new Long(nodeId));
426             }
427             catch (Exception e) {
428                 throw processException(e);
429             }
430             finally {
431                 if (wikiNode != null) {
432                     cacheResult(wikiNode);
433                 }
434 
435                 closeSession(session);
436             }
437         }
438 
439         return wikiNode;
440     }
441 
442     public List<WikiNode> findByUuid(String uuid) throws SystemException {
443         Object[] finderArgs = new Object[] { uuid };
444 
445         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
446                 finderArgs, this);
447 
448         if (list == null) {
449             Session session = null;
450 
451             try {
452                 session = openSession();
453 
454                 StringBuilder query = new StringBuilder();
455 
456                 query.append(
457                     "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
458 
459                 if (uuid == null) {
460                     query.append("uuid_ IS NULL");
461                 }
462                 else {
463                     query.append("uuid_ = ?");
464                 }
465 
466                 query.append(" ");
467 
468                 query.append("ORDER BY ");
469 
470                 query.append("name ASC");
471 
472                 Query q = session.createQuery(query.toString());
473 
474                 QueryPos qPos = QueryPos.getInstance(q);
475 
476                 if (uuid != null) {
477                     qPos.add(uuid);
478                 }
479 
480                 list = q.list();
481             }
482             catch (Exception e) {
483                 throw processException(e);
484             }
485             finally {
486                 if (list == null) {
487                     list = new ArrayList<WikiNode>();
488                 }
489 
490                 cacheResult(list);
491 
492                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
493                     list);
494 
495                 closeSession(session);
496             }
497         }
498 
499         return list;
500     }
501 
502     public List<WikiNode> findByUuid(String uuid, int start, int end)
503         throws SystemException {
504         return findByUuid(uuid, start, end, null);
505     }
506 
507     public List<WikiNode> findByUuid(String uuid, int start, int end,
508         OrderByComparator obc) throws SystemException {
509         Object[] finderArgs = new Object[] {
510                 uuid,
511                 
512                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
513             };
514 
515         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
516                 finderArgs, this);
517 
518         if (list == null) {
519             Session session = null;
520 
521             try {
522                 session = openSession();
523 
524                 StringBuilder query = new StringBuilder();
525 
526                 query.append(
527                     "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
528 
529                 if (uuid == null) {
530                     query.append("uuid_ IS NULL");
531                 }
532                 else {
533                     query.append("uuid_ = ?");
534                 }
535 
536                 query.append(" ");
537 
538                 if (obc != null) {
539                     query.append("ORDER BY ");
540                     query.append(obc.getOrderBy());
541                 }
542 
543                 else {
544                     query.append("ORDER BY ");
545 
546                     query.append("name ASC");
547                 }
548 
549                 Query q = session.createQuery(query.toString());
550 
551                 QueryPos qPos = QueryPos.getInstance(q);
552 
553                 if (uuid != null) {
554                     qPos.add(uuid);
555                 }
556 
557                 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
558                         end);
559             }
560             catch (Exception e) {
561                 throw processException(e);
562             }
563             finally {
564                 if (list == null) {
565                     list = new ArrayList<WikiNode>();
566                 }
567 
568                 cacheResult(list);
569 
570                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
571                     finderArgs, list);
572 
573                 closeSession(session);
574             }
575         }
576 
577         return list;
578     }
579 
580     public WikiNode findByUuid_First(String uuid, OrderByComparator obc)
581         throws NoSuchNodeException, SystemException {
582         List<WikiNode> list = findByUuid(uuid, 0, 1, obc);
583 
584         if (list.isEmpty()) {
585             StringBuilder msg = new StringBuilder();
586 
587             msg.append("No WikiNode exists with the key {");
588 
589             msg.append("uuid=" + uuid);
590 
591             msg.append(StringPool.CLOSE_CURLY_BRACE);
592 
593             throw new NoSuchNodeException(msg.toString());
594         }
595         else {
596             return list.get(0);
597         }
598     }
599 
600     public WikiNode findByUuid_Last(String uuid, OrderByComparator obc)
601         throws NoSuchNodeException, SystemException {
602         int count = countByUuid(uuid);
603 
604         List<WikiNode> list = findByUuid(uuid, count - 1, count, 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_PrevAndNext(long nodeId, String uuid,
623         OrderByComparator obc) throws NoSuchNodeException, SystemException {
624         WikiNode wikiNode = findByPrimaryKey(nodeId);
625 
626         int count = countByUuid(uuid);
627 
628         Session session = null;
629 
630         try {
631             session = openSession();
632 
633             StringBuilder query = new StringBuilder();
634 
635             query.append("FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
636 
637             if (uuid == null) {
638                 query.append("uuid_ IS NULL");
639             }
640             else {
641                 query.append("uuid_ = ?");
642             }
643 
644             query.append(" ");
645 
646             if (obc != null) {
647                 query.append("ORDER BY ");
648                 query.append(obc.getOrderBy());
649             }
650 
651             else {
652                 query.append("ORDER BY ");
653 
654                 query.append("name ASC");
655             }
656 
657             Query q = session.createQuery(query.toString());
658 
659             QueryPos qPos = QueryPos.getInstance(q);
660 
661             if (uuid != null) {
662                 qPos.add(uuid);
663             }
664 
665             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, wikiNode);
666 
667             WikiNode[] array = new WikiNodeImpl[3];
668 
669             array[0] = (WikiNode)objArray[0];
670             array[1] = (WikiNode)objArray[1];
671             array[2] = (WikiNode)objArray[2];
672 
673             return array;
674         }
675         catch (Exception e) {
676             throw processException(e);
677         }
678         finally {
679             closeSession(session);
680         }
681     }
682 
683     public WikiNode findByUUID_G(String uuid, long groupId)
684         throws NoSuchNodeException, SystemException {
685         WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
686 
687         if (wikiNode == null) {
688             StringBuilder msg = new StringBuilder();
689 
690             msg.append("No WikiNode exists with the key {");
691 
692             msg.append("uuid=" + uuid);
693 
694             msg.append(", ");
695             msg.append("groupId=" + groupId);
696 
697             msg.append(StringPool.CLOSE_CURLY_BRACE);
698 
699             if (_log.isWarnEnabled()) {
700                 _log.warn(msg.toString());
701             }
702 
703             throw new NoSuchNodeException(msg.toString());
704         }
705 
706         return wikiNode;
707     }
708 
709     public WikiNode fetchByUUID_G(String uuid, long groupId)
710         throws SystemException {
711         return fetchByUUID_G(uuid, groupId, true);
712     }
713 
714     public WikiNode fetchByUUID_G(String uuid, long groupId,
715         boolean retrieveFromCache) throws SystemException {
716         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
717 
718         Object result = null;
719 
720         if (retrieveFromCache) {
721             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
722                     finderArgs, this);
723         }
724 
725         if (result == null) {
726             Session session = null;
727 
728             try {
729                 session = openSession();
730 
731                 StringBuilder query = new StringBuilder();
732 
733                 query.append(
734                     "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
735 
736                 if (uuid == null) {
737                     query.append("uuid_ IS NULL");
738                 }
739                 else {
740                     query.append("uuid_ = ?");
741                 }
742 
743                 query.append(" AND ");
744 
745                 query.append("groupId = ?");
746 
747                 query.append(" ");
748 
749                 query.append("ORDER BY ");
750 
751                 query.append("name ASC");
752 
753                 Query q = session.createQuery(query.toString());
754 
755                 QueryPos qPos = QueryPos.getInstance(q);
756 
757                 if (uuid != null) {
758                     qPos.add(uuid);
759                 }
760 
761                 qPos.add(groupId);
762 
763                 List<WikiNode> list = q.list();
764 
765                 result = list;
766 
767                 WikiNode wikiNode = null;
768 
769                 if (list.isEmpty()) {
770                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
771                         finderArgs, list);
772                 }
773                 else {
774                     wikiNode = list.get(0);
775 
776                     cacheResult(wikiNode);
777 
778                     if ((wikiNode.getUuid() == null) ||
779                             !wikiNode.getUuid().equals(uuid) ||
780                             (wikiNode.getGroupId() != groupId)) {
781                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
782                             finderArgs, list);
783                     }
784                 }
785 
786                 return wikiNode;
787             }
788             catch (Exception e) {
789                 throw processException(e);
790             }
791             finally {
792                 if (result == null) {
793                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
794                         finderArgs, new ArrayList<WikiNode>());
795                 }
796 
797                 closeSession(session);
798             }
799         }
800         else {
801             if (result instanceof List) {
802                 return null;
803             }
804             else {
805                 return (WikiNode)result;
806             }
807         }
808     }
809 
810     public List<WikiNode> findByGroupId(long groupId) throws SystemException {
811         Object[] finderArgs = new Object[] { new Long(groupId) };
812 
813         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
814                 finderArgs, this);
815 
816         if (list == null) {
817             Session session = null;
818 
819             try {
820                 session = openSession();
821 
822                 StringBuilder query = new StringBuilder();
823 
824                 query.append(
825                     "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
826 
827                 query.append("groupId = ?");
828 
829                 query.append(" ");
830 
831                 query.append("ORDER BY ");
832 
833                 query.append("name ASC");
834 
835                 Query q = session.createQuery(query.toString());
836 
837                 QueryPos qPos = QueryPos.getInstance(q);
838 
839                 qPos.add(groupId);
840 
841                 list = q.list();
842             }
843             catch (Exception e) {
844                 throw processException(e);
845             }
846             finally {
847                 if (list == null) {
848                     list = new ArrayList<WikiNode>();
849                 }
850 
851                 cacheResult(list);
852 
853                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
854                     finderArgs, list);
855 
856                 closeSession(session);
857             }
858         }
859 
860         return list;
861     }
862 
863     public List<WikiNode> findByGroupId(long groupId, int start, int end)
864         throws SystemException {
865         return findByGroupId(groupId, start, end, null);
866     }
867 
868     public List<WikiNode> findByGroupId(long groupId, int start, int end,
869         OrderByComparator obc) throws SystemException {
870         Object[] finderArgs = new Object[] {
871                 new Long(groupId),
872                 
873                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
874             };
875 
876         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
877                 finderArgs, this);
878 
879         if (list == null) {
880             Session session = null;
881 
882             try {
883                 session = openSession();
884 
885                 StringBuilder query = new StringBuilder();
886 
887                 query.append(
888                     "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
889 
890                 query.append("groupId = ?");
891 
892                 query.append(" ");
893 
894                 if (obc != null) {
895                     query.append("ORDER BY ");
896                     query.append(obc.getOrderBy());
897                 }
898 
899                 else {
900                     query.append("ORDER BY ");
901 
902                     query.append("name ASC");
903                 }
904 
905                 Query q = session.createQuery(query.toString());
906 
907                 QueryPos qPos = QueryPos.getInstance(q);
908 
909                 qPos.add(groupId);
910 
911                 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
912                         end);
913             }
914             catch (Exception e) {
915                 throw processException(e);
916             }
917             finally {
918                 if (list == null) {
919                     list = new ArrayList<WikiNode>();
920                 }
921 
922                 cacheResult(list);
923 
924                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
925                     finderArgs, list);
926 
927                 closeSession(session);
928             }
929         }
930 
931         return list;
932     }
933 
934     public WikiNode findByGroupId_First(long groupId, OrderByComparator obc)
935         throws NoSuchNodeException, SystemException {
936         List<WikiNode> list = findByGroupId(groupId, 0, 1, obc);
937 
938         if (list.isEmpty()) {
939             StringBuilder msg = new StringBuilder();
940 
941             msg.append("No WikiNode exists with the key {");
942 
943             msg.append("groupId=" + groupId);
944 
945             msg.append(StringPool.CLOSE_CURLY_BRACE);
946 
947             throw new NoSuchNodeException(msg.toString());
948         }
949         else {
950             return list.get(0);
951         }
952     }
953 
954     public WikiNode findByGroupId_Last(long groupId, OrderByComparator obc)
955         throws NoSuchNodeException, SystemException {
956         int count = countByGroupId(groupId);
957 
958         List<WikiNode> list = findByGroupId(groupId, count - 1, count, obc);
959 
960         if (list.isEmpty()) {
961             StringBuilder msg = new StringBuilder();
962 
963             msg.append("No WikiNode exists with the key {");
964 
965             msg.append("groupId=" + groupId);
966 
967             msg.append(StringPool.CLOSE_CURLY_BRACE);
968 
969             throw new NoSuchNodeException(msg.toString());
970         }
971         else {
972             return list.get(0);
973         }
974     }
975 
976     public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
977         OrderByComparator obc) throws NoSuchNodeException, SystemException {
978         WikiNode wikiNode = findByPrimaryKey(nodeId);
979 
980         int count = countByGroupId(groupId);
981 
982         Session session = null;
983 
984         try {
985             session = openSession();
986 
987             StringBuilder query = new StringBuilder();
988 
989             query.append("FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
990 
991             query.append("groupId = ?");
992 
993             query.append(" ");
994 
995             if (obc != null) {
996                 query.append("ORDER BY ");
997                 query.append(obc.getOrderBy());
998             }
999 
1000            else {
1001                query.append("ORDER BY ");
1002
1003                query.append("name ASC");
1004            }
1005
1006            Query q = session.createQuery(query.toString());
1007
1008            QueryPos qPos = QueryPos.getInstance(q);
1009
1010            qPos.add(groupId);
1011
1012            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, wikiNode);
1013
1014            WikiNode[] array = new WikiNodeImpl[3];
1015
1016            array[0] = (WikiNode)objArray[0];
1017            array[1] = (WikiNode)objArray[1];
1018            array[2] = (WikiNode)objArray[2];
1019
1020            return array;
1021        }
1022        catch (Exception e) {
1023            throw processException(e);
1024        }
1025        finally {
1026            closeSession(session);
1027        }
1028    }
1029
1030    public List<WikiNode> findByCompanyId(long companyId)
1031        throws SystemException {
1032        Object[] finderArgs = new Object[] { new Long(companyId) };
1033
1034        List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1035                finderArgs, this);
1036
1037        if (list == null) {
1038            Session session = null;
1039
1040            try {
1041                session = openSession();
1042
1043                StringBuilder query = new StringBuilder();
1044
1045                query.append(
1046                    "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1047
1048                query.append("companyId = ?");
1049
1050                query.append(" ");
1051
1052                query.append("ORDER BY ");
1053
1054                query.append("name ASC");
1055
1056                Query q = session.createQuery(query.toString());
1057
1058                QueryPos qPos = QueryPos.getInstance(q);
1059
1060                qPos.add(companyId);
1061
1062                list = q.list();
1063            }
1064            catch (Exception e) {
1065                throw processException(e);
1066            }
1067            finally {
1068                if (list == null) {
1069                    list = new ArrayList<WikiNode>();
1070                }
1071
1072                cacheResult(list);
1073
1074                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1075                    finderArgs, list);
1076
1077                closeSession(session);
1078            }
1079        }
1080
1081        return list;
1082    }
1083
1084    public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1085        throws SystemException {
1086        return findByCompanyId(companyId, start, end, null);
1087    }
1088
1089    public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1090        OrderByComparator obc) throws SystemException {
1091        Object[] finderArgs = new Object[] {
1092                new Long(companyId),
1093                
1094                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1095            };
1096
1097        List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1098                finderArgs, this);
1099
1100        if (list == null) {
1101            Session session = null;
1102
1103            try {
1104                session = openSession();
1105
1106                StringBuilder query = new StringBuilder();
1107
1108                query.append(
1109                    "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1110
1111                query.append("companyId = ?");
1112
1113                query.append(" ");
1114
1115                if (obc != null) {
1116                    query.append("ORDER BY ");
1117                    query.append(obc.getOrderBy());
1118                }
1119
1120                else {
1121                    query.append("ORDER BY ");
1122
1123                    query.append("name ASC");
1124                }
1125
1126                Query q = session.createQuery(query.toString());
1127
1128                QueryPos qPos = QueryPos.getInstance(q);
1129
1130                qPos.add(companyId);
1131
1132                list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1133                        end);
1134            }
1135            catch (Exception e) {
1136                throw processException(e);
1137            }
1138            finally {
1139                if (list == null) {
1140                    list = new ArrayList<WikiNode>();
1141                }
1142
1143                cacheResult(list);
1144
1145                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1146                    finderArgs, list);
1147
1148                closeSession(session);
1149            }
1150        }
1151
1152        return list;
1153    }
1154
1155    public WikiNode findByCompanyId_First(long companyId, OrderByComparator obc)
1156        throws NoSuchNodeException, SystemException {
1157        List<WikiNode> list = findByCompanyId(companyId, 0, 1, obc);
1158
1159        if (list.isEmpty()) {
1160            StringBuilder msg = new StringBuilder();
1161
1162            msg.append("No WikiNode exists with the key {");
1163
1164            msg.append("companyId=" + companyId);
1165
1166            msg.append(StringPool.CLOSE_CURLY_BRACE);
1167
1168            throw new NoSuchNodeException(msg.toString());
1169        }
1170        else {
1171            return list.get(0);
1172        }
1173    }
1174
1175    public WikiNode findByCompanyId_Last(long companyId, OrderByComparator obc)
1176        throws NoSuchNodeException, SystemException {
1177        int count = countByCompanyId(companyId);
1178
1179        List<WikiNode> list = findByCompanyId(companyId, count - 1, count, obc);
1180
1181        if (list.isEmpty()) {
1182            StringBuilder msg = new StringBuilder();
1183
1184            msg.append("No WikiNode exists with the key {");
1185
1186            msg.append("companyId=" + companyId);
1187
1188            msg.append(StringPool.CLOSE_CURLY_BRACE);
1189
1190            throw new NoSuchNodeException(msg.toString());
1191        }
1192        else {
1193            return list.get(0);
1194        }
1195    }
1196
1197    public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
1198        OrderByComparator obc) throws NoSuchNodeException, SystemException {
1199        WikiNode wikiNode = findByPrimaryKey(nodeId);
1200
1201        int count = countByCompanyId(companyId);
1202
1203        Session session = null;
1204
1205        try {
1206            session = openSession();
1207
1208            StringBuilder query = new StringBuilder();
1209
1210            query.append("FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1211
1212            query.append("companyId = ?");
1213
1214            query.append(" ");
1215
1216            if (obc != null) {
1217                query.append("ORDER BY ");
1218                query.append(obc.getOrderBy());
1219            }
1220
1221            else {
1222                query.append("ORDER BY ");
1223
1224                query.append("name ASC");
1225            }
1226
1227            Query q = session.createQuery(query.toString());
1228
1229            QueryPos qPos = QueryPos.getInstance(q);
1230
1231            qPos.add(companyId);
1232
1233            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, wikiNode);
1234
1235            WikiNode[] array = new WikiNodeImpl[3];
1236
1237            array[0] = (WikiNode)objArray[0];
1238            array[1] = (WikiNode)objArray[1];
1239            array[2] = (WikiNode)objArray[2];
1240
1241            return array;
1242        }
1243        catch (Exception e) {
1244            throw processException(e);
1245        }
1246        finally {
1247            closeSession(session);
1248        }
1249    }
1250
1251    public WikiNode findByG_N(long groupId, String name)
1252        throws NoSuchNodeException, SystemException {
1253        WikiNode wikiNode = fetchByG_N(groupId, name);
1254
1255        if (wikiNode == null) {
1256            StringBuilder msg = new StringBuilder();
1257
1258            msg.append("No WikiNode exists with the key {");
1259
1260            msg.append("groupId=" + groupId);
1261
1262            msg.append(", ");
1263            msg.append("name=" + name);
1264
1265            msg.append(StringPool.CLOSE_CURLY_BRACE);
1266
1267            if (_log.isWarnEnabled()) {
1268                _log.warn(msg.toString());
1269            }
1270
1271            throw new NoSuchNodeException(msg.toString());
1272        }
1273
1274        return wikiNode;
1275    }
1276
1277    public WikiNode fetchByG_N(long groupId, String name)
1278        throws SystemException {
1279        return fetchByG_N(groupId, name, true);
1280    }
1281
1282    public WikiNode fetchByG_N(long groupId, String name,
1283        boolean retrieveFromCache) throws SystemException {
1284        Object[] finderArgs = new Object[] { new Long(groupId), name };
1285
1286        Object result = null;
1287
1288        if (retrieveFromCache) {
1289            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1290                    finderArgs, this);
1291        }
1292
1293        if (result == null) {
1294            Session session = null;
1295
1296            try {
1297                session = openSession();
1298
1299                StringBuilder query = new StringBuilder();
1300
1301                query.append(
1302                    "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1303
1304                query.append("groupId = ?");
1305
1306                query.append(" AND ");
1307
1308                if (name == null) {
1309                    query.append("name IS NULL");
1310                }
1311                else {
1312                    query.append("name = ?");
1313                }
1314
1315                query.append(" ");
1316
1317                query.append("ORDER BY ");
1318
1319                query.append("name ASC");
1320
1321                Query q = session.createQuery(query.toString());
1322
1323                QueryPos qPos = QueryPos.getInstance(q);
1324
1325                qPos.add(groupId);
1326
1327                if (name != null) {
1328                    qPos.add(name);
1329                }
1330
1331                List<WikiNode> list = q.list();
1332
1333                result = list;
1334
1335                WikiNode wikiNode = null;
1336
1337                if (list.isEmpty()) {
1338                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1339                        finderArgs, list);
1340                }
1341                else {
1342                    wikiNode = list.get(0);
1343
1344                    cacheResult(wikiNode);
1345
1346                    if ((wikiNode.getGroupId() != groupId) ||
1347                            (wikiNode.getName() == null) ||
1348                            !wikiNode.getName().equals(name)) {
1349                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1350                            finderArgs, list);
1351                    }
1352                }
1353
1354                return wikiNode;
1355            }
1356            catch (Exception e) {
1357                throw processException(e);
1358            }
1359            finally {
1360                if (result == null) {
1361                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1362                        finderArgs, new ArrayList<WikiNode>());
1363                }
1364
1365                closeSession(session);
1366            }
1367        }
1368        else {
1369            if (result instanceof List) {
1370                return null;
1371            }
1372            else {
1373                return (WikiNode)result;
1374            }
1375        }
1376    }
1377
1378    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1379        throws SystemException {
1380        Session session = null;
1381
1382        try {
1383            session = openSession();
1384
1385            dynamicQuery.compile(session);
1386
1387            return dynamicQuery.list();
1388        }
1389        catch (Exception e) {
1390            throw processException(e);
1391        }
1392        finally {
1393            closeSession(session);
1394        }
1395    }
1396
1397    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1398        int start, int end) throws SystemException {
1399        Session session = null;
1400
1401        try {
1402            session = openSession();
1403
1404            dynamicQuery.setLimit(start, end);
1405
1406            dynamicQuery.compile(session);
1407
1408            return dynamicQuery.list();
1409        }
1410        catch (Exception e) {
1411            throw processException(e);
1412        }
1413        finally {
1414            closeSession(session);
1415        }
1416    }
1417
1418    public List<WikiNode> findAll() throws SystemException {
1419        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1420    }
1421
1422    public List<WikiNode> findAll(int start, int end) throws SystemException {
1423        return findAll(start, end, null);
1424    }
1425
1426    public List<WikiNode> findAll(int start, int end, OrderByComparator obc)
1427        throws SystemException {
1428        Object[] finderArgs = new Object[] {
1429                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1430            };
1431
1432        List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1433                finderArgs, this);
1434
1435        if (list == null) {
1436            Session session = null;
1437
1438            try {
1439                session = openSession();
1440
1441                StringBuilder query = new StringBuilder();
1442
1443                query.append("FROM com.liferay.portlet.wiki.model.WikiNode ");
1444
1445                if (obc != null) {
1446                    query.append("ORDER BY ");
1447                    query.append(obc.getOrderBy());
1448                }
1449
1450                else {
1451                    query.append("ORDER BY ");
1452
1453                    query.append("name ASC");
1454                }
1455
1456                Query q = session.createQuery(query.toString());
1457
1458                if (obc == null) {
1459                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1460                            start, end, false);
1461
1462                    Collections.sort(list);
1463                }
1464                else {
1465                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1466                            start, end);
1467                }
1468            }
1469            catch (Exception e) {
1470                throw processException(e);
1471            }
1472            finally {
1473                if (list == null) {
1474                    list = new ArrayList<WikiNode>();
1475                }
1476
1477                cacheResult(list);
1478
1479                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1480
1481                closeSession(session);
1482            }
1483        }
1484
1485        return list;
1486    }
1487
1488    public void removeByUuid(String uuid) throws SystemException {
1489        for (WikiNode wikiNode : findByUuid(uuid)) {
1490            remove(wikiNode);
1491        }
1492    }
1493
1494    public void removeByUUID_G(String uuid, long groupId)
1495        throws NoSuchNodeException, SystemException {
1496        WikiNode wikiNode = findByUUID_G(uuid, groupId);
1497
1498        remove(wikiNode);
1499    }
1500
1501    public void removeByGroupId(long groupId) throws SystemException {
1502        for (WikiNode wikiNode : findByGroupId(groupId)) {
1503            remove(wikiNode);
1504        }
1505    }
1506
1507    public void removeByCompanyId(long companyId) throws SystemException {
1508        for (WikiNode wikiNode : findByCompanyId(companyId)) {
1509            remove(wikiNode);
1510        }
1511    }
1512
1513    public void removeByG_N(long groupId, String name)
1514        throws NoSuchNodeException, SystemException {
1515        WikiNode wikiNode = findByG_N(groupId, name);
1516
1517        remove(wikiNode);
1518    }
1519
1520    public void removeAll() throws SystemException {
1521        for (WikiNode wikiNode : findAll()) {
1522            remove(wikiNode);
1523        }
1524    }
1525
1526    public int countByUuid(String uuid) throws SystemException {
1527        Object[] finderArgs = new Object[] { uuid };
1528
1529        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1530                finderArgs, this);
1531
1532        if (count == null) {
1533            Session session = null;
1534
1535            try {
1536                session = openSession();
1537
1538                StringBuilder query = new StringBuilder();
1539
1540                query.append("SELECT COUNT(*) ");
1541                query.append(
1542                    "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1543
1544                if (uuid == null) {
1545                    query.append("uuid_ IS NULL");
1546                }
1547                else {
1548                    query.append("uuid_ = ?");
1549                }
1550
1551                query.append(" ");
1552
1553                Query q = session.createQuery(query.toString());
1554
1555                QueryPos qPos = QueryPos.getInstance(q);
1556
1557                if (uuid != null) {
1558                    qPos.add(uuid);
1559                }
1560
1561                count = (Long)q.uniqueResult();
1562            }
1563            catch (Exception e) {
1564                throw processException(e);
1565            }
1566            finally {
1567                if (count == null) {
1568                    count = Long.valueOf(0);
1569                }
1570
1571                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1572                    finderArgs, count);
1573
1574                closeSession(session);
1575            }
1576        }
1577
1578        return count.intValue();
1579    }
1580
1581    public int countByUUID_G(String uuid, long groupId)
1582        throws SystemException {
1583        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1584
1585        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1586                finderArgs, this);
1587
1588        if (count == null) {
1589            Session session = null;
1590
1591            try {
1592                session = openSession();
1593
1594                StringBuilder query = new StringBuilder();
1595
1596                query.append("SELECT COUNT(*) ");
1597                query.append(
1598                    "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1599
1600                if (uuid == null) {
1601                    query.append("uuid_ IS NULL");
1602                }
1603                else {
1604                    query.append("uuid_ = ?");
1605                }
1606
1607                query.append(" AND ");
1608
1609                query.append("groupId = ?");
1610
1611                query.append(" ");
1612
1613                Query q = session.createQuery(query.toString());
1614
1615                QueryPos qPos = QueryPos.getInstance(q);
1616
1617                if (uuid != null) {
1618                    qPos.add(uuid);
1619                }
1620
1621                qPos.add(groupId);
1622
1623                count = (Long)q.uniqueResult();
1624            }
1625            catch (Exception e) {
1626                throw processException(e);
1627            }
1628            finally {
1629                if (count == null) {
1630                    count = Long.valueOf(0);
1631                }
1632
1633                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1634                    finderArgs, count);
1635
1636                closeSession(session);
1637            }
1638        }
1639
1640        return count.intValue();
1641    }
1642
1643    public int countByGroupId(long groupId) throws SystemException {
1644        Object[] finderArgs = new Object[] { new Long(groupId) };
1645
1646        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1647                finderArgs, this);
1648
1649        if (count == null) {
1650            Session session = null;
1651
1652            try {
1653                session = openSession();
1654
1655                StringBuilder query = new StringBuilder();
1656
1657                query.append("SELECT COUNT(*) ");
1658                query.append(
1659                    "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1660
1661                query.append("groupId = ?");
1662
1663                query.append(" ");
1664
1665                Query q = session.createQuery(query.toString());
1666
1667                QueryPos qPos = QueryPos.getInstance(q);
1668
1669                qPos.add(groupId);
1670
1671                count = (Long)q.uniqueResult();
1672            }
1673            catch (Exception e) {
1674                throw processException(e);
1675            }
1676            finally {
1677                if (count == null) {
1678                    count = Long.valueOf(0);
1679                }
1680
1681                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1682                    finderArgs, count);
1683
1684                closeSession(session);
1685            }
1686        }
1687
1688        return count.intValue();
1689    }
1690
1691    public int countByCompanyId(long companyId) throws SystemException {
1692        Object[] finderArgs = new Object[] { new Long(companyId) };
1693
1694        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1695                finderArgs, this);
1696
1697        if (count == null) {
1698            Session session = null;
1699
1700            try {
1701                session = openSession();
1702
1703                StringBuilder query = new StringBuilder();
1704
1705                query.append("SELECT COUNT(*) ");
1706                query.append(
1707                    "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1708
1709                query.append("companyId = ?");
1710
1711                query.append(" ");
1712
1713                Query q = session.createQuery(query.toString());
1714
1715                QueryPos qPos = QueryPos.getInstance(q);
1716
1717                qPos.add(companyId);
1718
1719                count = (Long)q.uniqueResult();
1720            }
1721            catch (Exception e) {
1722                throw processException(e);
1723            }
1724            finally {
1725                if (count == null) {
1726                    count = Long.valueOf(0);
1727                }
1728
1729                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1730                    finderArgs, count);
1731
1732                closeSession(session);
1733            }
1734        }
1735
1736        return count.intValue();
1737    }
1738
1739    public int countByG_N(long groupId, String name) throws SystemException {
1740        Object[] finderArgs = new Object[] { new Long(groupId), name };
1741
1742        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1743                finderArgs, this);
1744
1745        if (count == null) {
1746            Session session = null;
1747
1748            try {
1749                session = openSession();
1750
1751                StringBuilder query = new StringBuilder();
1752
1753                query.append("SELECT COUNT(*) ");
1754                query.append(
1755                    "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
1756
1757                query.append("groupId = ?");
1758
1759                query.append(" AND ");
1760
1761                if (name == null) {
1762                    query.append("name IS NULL");
1763                }
1764                else {
1765                    query.append("name = ?");
1766                }
1767
1768                query.append(" ");
1769
1770                Query q = session.createQuery(query.toString());
1771
1772                QueryPos qPos = QueryPos.getInstance(q);
1773
1774                qPos.add(groupId);
1775
1776                if (name != null) {
1777                    qPos.add(name);
1778                }
1779
1780                count = (Long)q.uniqueResult();
1781            }
1782            catch (Exception e) {
1783                throw processException(e);
1784            }
1785            finally {
1786                if (count == null) {
1787                    count = Long.valueOf(0);
1788                }
1789
1790                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1791                    count);
1792
1793                closeSession(session);
1794            }
1795        }
1796
1797        return count.intValue();
1798    }
1799
1800    public int countAll() throws SystemException {
1801        Object[] finderArgs = new Object[0];
1802
1803        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1804                finderArgs, this);
1805
1806        if (count == null) {
1807            Session session = null;
1808
1809            try {
1810                session = openSession();
1811
1812                Query q = session.createQuery(
1813                        "SELECT COUNT(*) FROM com.liferay.portlet.wiki.model.WikiNode");
1814
1815                count = (Long)q.uniqueResult();
1816            }
1817            catch (Exception e) {
1818                throw processException(e);
1819            }
1820            finally {
1821                if (count == null) {
1822                    count = Long.valueOf(0);
1823                }
1824
1825                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1826                    count);
1827
1828                closeSession(session);
1829            }
1830        }
1831
1832        return count.intValue();
1833    }
1834
1835    public void afterPropertiesSet() {
1836        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1837                    com.liferay.portal.util.PropsUtil.get(
1838                        "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
1839
1840        if (listenerClassNames.length > 0) {
1841            try {
1842                List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
1843
1844                for (String listenerClassName : listenerClassNames) {
1845                    listenersList.add((ModelListener<WikiNode>)Class.forName(
1846                            listenerClassName).newInstance());
1847                }
1848
1849                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1850            }
1851            catch (Exception e) {
1852                _log.error(e);
1853            }
1854        }
1855    }
1856
1857    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiNodePersistence.impl")
1858    protected com.liferay.portlet.wiki.service.persistence.WikiNodePersistence wikiNodePersistence;
1859    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPagePersistence.impl")
1860    protected com.liferay.portlet.wiki.service.persistence.WikiPagePersistence wikiPagePersistence;
1861    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence.impl")
1862    protected com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence wikiPageResourcePersistence;
1863    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1864    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1865    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1866    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1867    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1868    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1869    private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
1870}