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