001
014
015 package com.liferay.portlet.wiki.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041 import com.liferay.portal.service.persistence.BatchSessionUtil;
042 import com.liferay.portal.service.persistence.GroupPersistence;
043 import com.liferay.portal.service.persistence.ResourcePersistence;
044 import com.liferay.portal.service.persistence.SubscriptionPersistence;
045 import com.liferay.portal.service.persistence.UserPersistence;
046 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047
048 import com.liferay.portlet.wiki.NoSuchNodeException;
049 import com.liferay.portlet.wiki.model.WikiNode;
050 import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
051 import com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl;
052
053 import java.io.Serializable;
054
055 import java.util.ArrayList;
056 import java.util.Collections;
057 import java.util.List;
058
059
065 public class WikiNodePersistenceImpl extends BasePersistenceImpl<WikiNode>
066 implements WikiNodePersistence {
067 public static final String FINDER_CLASS_NAME_ENTITY = WikiNodeImpl.class.getName();
068 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069 ".List";
070 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
071 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
072 "findByUuid",
073 new String[] {
074 String.class.getName(),
075
076 "java.lang.Integer", "java.lang.Integer",
077 "com.liferay.portal.kernel.util.OrderByComparator"
078 });
079 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
080 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081 "countByUuid", new String[] { String.class.getName() });
082 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
083 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
084 "fetchByUUID_G",
085 new String[] { String.class.getName(), Long.class.getName() });
086 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
087 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088 "countByUUID_G",
089 new String[] { String.class.getName(), Long.class.getName() });
090 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
091 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
092 "findByGroupId",
093 new String[] {
094 Long.class.getName(),
095
096 "java.lang.Integer", "java.lang.Integer",
097 "com.liferay.portal.kernel.util.OrderByComparator"
098 });
099 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
100 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101 "countByGroupId", new String[] { Long.class.getName() });
102 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
103 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "findByCompanyId",
105 new String[] {
106 Long.class.getName(),
107
108 "java.lang.Integer", "java.lang.Integer",
109 "com.liferay.portal.kernel.util.OrderByComparator"
110 });
111 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
112 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113 "countByCompanyId", new String[] { Long.class.getName() });
114 public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
115 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
116 "fetchByG_N",
117 new String[] { Long.class.getName(), String.class.getName() });
118 public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
119 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
120 "countByG_N",
121 new String[] { Long.class.getName(), String.class.getName() });
122 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
123 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124 "findAll", new String[0]);
125 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
126 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
127 "countAll", new String[0]);
128
129 public void cacheResult(WikiNode wikiNode) {
130 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
131 WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
132
133 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
134 new Object[] { wikiNode.getUuid(), new Long(wikiNode.getGroupId()) },
135 wikiNode);
136
137 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
138 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
139 wikiNode);
140 }
141
142 public void cacheResult(List<WikiNode> wikiNodes) {
143 for (WikiNode wikiNode : wikiNodes) {
144 if (EntityCacheUtil.getResult(
145 WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
146 WikiNodeImpl.class, wikiNode.getPrimaryKey(), this) == null) {
147 cacheResult(wikiNode);
148 }
149 }
150 }
151
152 public void clearCache() {
153 CacheRegistryUtil.clear(WikiNodeImpl.class.getName());
154 EntityCacheUtil.clearCache(WikiNodeImpl.class.getName());
155 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
156 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
157 }
158
159 public void clearCache(WikiNode wikiNode) {
160 EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
161 WikiNodeImpl.class, wikiNode.getPrimaryKey());
162
163 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
164 new Object[] { wikiNode.getUuid(), new Long(wikiNode.getGroupId()) });
165
166 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
167 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() });
168 }
169
170 public WikiNode create(long nodeId) {
171 WikiNode wikiNode = new WikiNodeImpl();
172
173 wikiNode.setNew(true);
174 wikiNode.setPrimaryKey(nodeId);
175
176 String uuid = PortalUUIDUtil.generate();
177
178 wikiNode.setUuid(uuid);
179
180 return wikiNode;
181 }
182
183 public WikiNode remove(Serializable primaryKey)
184 throws NoSuchModelException, SystemException {
185 return remove(((Long)primaryKey).longValue());
186 }
187
188 public WikiNode remove(long nodeId)
189 throws NoSuchNodeException, SystemException {
190 Session session = null;
191
192 try {
193 session = openSession();
194
195 WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
196 new Long(nodeId));
197
198 if (wikiNode == null) {
199 if (_log.isWarnEnabled()) {
200 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
201 }
202
203 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
204 nodeId);
205 }
206
207 return remove(wikiNode);
208 }
209 catch (NoSuchNodeException nsee) {
210 throw nsee;
211 }
212 catch (Exception e) {
213 throw processException(e);
214 }
215 finally {
216 closeSession(session);
217 }
218 }
219
220 protected WikiNode removeImpl(WikiNode wikiNode) throws SystemException {
221 wikiNode = toUnwrappedModel(wikiNode);
222
223 Session session = null;
224
225 try {
226 session = openSession();
227
228 if (wikiNode.isCachedModel() || BatchSessionUtil.isEnabled()) {
229 Object staleObject = session.get(WikiNodeImpl.class,
230 wikiNode.getPrimaryKeyObj());
231
232 if (staleObject != null) {
233 session.evict(staleObject);
234 }
235 }
236
237 session.delete(wikiNode);
238
239 session.flush();
240 }
241 catch (Exception e) {
242 throw processException(e);
243 }
244 finally {
245 closeSession(session);
246 }
247
248 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
249
250 WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
251
252 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
253 new Object[] {
254 wikiNodeModelImpl.getOriginalUuid(),
255 new Long(wikiNodeModelImpl.getOriginalGroupId())
256 });
257
258 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
259 new Object[] {
260 new Long(wikiNodeModelImpl.getOriginalGroupId()),
261
262 wikiNodeModelImpl.getOriginalName()
263 });
264
265 EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
266 WikiNodeImpl.class, wikiNode.getPrimaryKey());
267
268 return wikiNode;
269 }
270
271 public WikiNode updateImpl(
272 com.liferay.portlet.wiki.model.WikiNode wikiNode, boolean merge)
273 throws SystemException {
274 wikiNode = toUnwrappedModel(wikiNode);
275
276 boolean isNew = wikiNode.isNew();
277
278 WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
279
280 if (Validator.isNull(wikiNode.getUuid())) {
281 String uuid = PortalUUIDUtil.generate();
282
283 wikiNode.setUuid(uuid);
284 }
285
286 Session session = null;
287
288 try {
289 session = openSession();
290
291 BatchSessionUtil.update(session, wikiNode, merge);
292
293 wikiNode.setNew(false);
294 }
295 catch (Exception e) {
296 throw processException(e);
297 }
298 finally {
299 closeSession(session);
300 }
301
302 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
303
304 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
305 WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
306
307 if (!isNew &&
308 (!Validator.equals(wikiNode.getUuid(),
309 wikiNodeModelImpl.getOriginalUuid()) ||
310 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
311 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
312 new Object[] {
313 wikiNodeModelImpl.getOriginalUuid(),
314 new Long(wikiNodeModelImpl.getOriginalGroupId())
315 });
316 }
317
318 if (isNew ||
319 (!Validator.equals(wikiNode.getUuid(),
320 wikiNodeModelImpl.getOriginalUuid()) ||
321 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
322 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
323 new Object[] { wikiNode.getUuid(), new Long(
324 wikiNode.getGroupId()) }, wikiNode);
325 }
326
327 if (!isNew &&
328 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
329 !Validator.equals(wikiNode.getName(),
330 wikiNodeModelImpl.getOriginalName()))) {
331 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
332 new Object[] {
333 new Long(wikiNodeModelImpl.getOriginalGroupId()),
334
335 wikiNodeModelImpl.getOriginalName()
336 });
337 }
338
339 if (isNew ||
340 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
341 !Validator.equals(wikiNode.getName(),
342 wikiNodeModelImpl.getOriginalName()))) {
343 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
344 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
345 wikiNode);
346 }
347
348 return wikiNode;
349 }
350
351 protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
352 if (wikiNode instanceof WikiNodeImpl) {
353 return wikiNode;
354 }
355
356 WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
357
358 wikiNodeImpl.setNew(wikiNode.isNew());
359 wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
360
361 wikiNodeImpl.setUuid(wikiNode.getUuid());
362 wikiNodeImpl.setNodeId(wikiNode.getNodeId());
363 wikiNodeImpl.setGroupId(wikiNode.getGroupId());
364 wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
365 wikiNodeImpl.setUserId(wikiNode.getUserId());
366 wikiNodeImpl.setUserName(wikiNode.getUserName());
367 wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
368 wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
369 wikiNodeImpl.setName(wikiNode.getName());
370 wikiNodeImpl.setDescription(wikiNode.getDescription());
371 wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
372
373 return wikiNodeImpl;
374 }
375
376 public WikiNode findByPrimaryKey(Serializable primaryKey)
377 throws NoSuchModelException, SystemException {
378 return findByPrimaryKey(((Long)primaryKey).longValue());
379 }
380
381 public WikiNode findByPrimaryKey(long nodeId)
382 throws NoSuchNodeException, SystemException {
383 WikiNode wikiNode = fetchByPrimaryKey(nodeId);
384
385 if (wikiNode == null) {
386 if (_log.isWarnEnabled()) {
387 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
388 }
389
390 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
391 nodeId);
392 }
393
394 return wikiNode;
395 }
396
397 public WikiNode fetchByPrimaryKey(Serializable primaryKey)
398 throws SystemException {
399 return fetchByPrimaryKey(((Long)primaryKey).longValue());
400 }
401
402 public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
403 WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
404 WikiNodeImpl.class, nodeId, this);
405
406 if (wikiNode == null) {
407 Session session = null;
408
409 try {
410 session = openSession();
411
412 wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
413 new Long(nodeId));
414 }
415 catch (Exception e) {
416 throw processException(e);
417 }
418 finally {
419 if (wikiNode != null) {
420 cacheResult(wikiNode);
421 }
422
423 closeSession(session);
424 }
425 }
426
427 return wikiNode;
428 }
429
430 public List<WikiNode> findByUuid(String uuid) throws SystemException {
431 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
432 }
433
434 public List<WikiNode> findByUuid(String uuid, int start, int end)
435 throws SystemException {
436 return findByUuid(uuid, start, end, null);
437 }
438
439 public List<WikiNode> findByUuid(String uuid, int start, int end,
440 OrderByComparator orderByComparator) throws SystemException {
441 Object[] finderArgs = new Object[] {
442 uuid,
443
444 String.valueOf(start), String.valueOf(end),
445 String.valueOf(orderByComparator)
446 };
447
448 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
449 finderArgs, this);
450
451 if (list == null) {
452 Session session = null;
453
454 try {
455 session = openSession();
456
457 StringBundler query = null;
458
459 if (orderByComparator != null) {
460 query = new StringBundler(3 +
461 (orderByComparator.getOrderByFields().length * 3));
462 }
463 else {
464 query = new StringBundler(3);
465 }
466
467 query.append(_SQL_SELECT_WIKINODE_WHERE);
468
469 if (uuid == null) {
470 query.append(_FINDER_COLUMN_UUID_UUID_1);
471 }
472 else {
473 if (uuid.equals(StringPool.BLANK)) {
474 query.append(_FINDER_COLUMN_UUID_UUID_3);
475 }
476 else {
477 query.append(_FINDER_COLUMN_UUID_UUID_2);
478 }
479 }
480
481 if (orderByComparator != null) {
482 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
483 orderByComparator);
484 }
485
486 else {
487 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
488 }
489
490 String sql = query.toString();
491
492 Query q = session.createQuery(sql);
493
494 QueryPos qPos = QueryPos.getInstance(q);
495
496 if (uuid != null) {
497 qPos.add(uuid);
498 }
499
500 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
501 end);
502 }
503 catch (Exception e) {
504 throw processException(e);
505 }
506 finally {
507 if (list == null) {
508 list = new ArrayList<WikiNode>();
509 }
510
511 cacheResult(list);
512
513 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
514 list);
515
516 closeSession(session);
517 }
518 }
519
520 return list;
521 }
522
523 public WikiNode findByUuid_First(String uuid,
524 OrderByComparator orderByComparator)
525 throws NoSuchNodeException, SystemException {
526 List<WikiNode> list = findByUuid(uuid, 0, 1, orderByComparator);
527
528 if (list.isEmpty()) {
529 StringBundler msg = new StringBundler(4);
530
531 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
532
533 msg.append("uuid=");
534 msg.append(uuid);
535
536 msg.append(StringPool.CLOSE_CURLY_BRACE);
537
538 throw new NoSuchNodeException(msg.toString());
539 }
540 else {
541 return list.get(0);
542 }
543 }
544
545 public WikiNode findByUuid_Last(String uuid,
546 OrderByComparator orderByComparator)
547 throws NoSuchNodeException, SystemException {
548 int count = countByUuid(uuid);
549
550 List<WikiNode> list = findByUuid(uuid, count - 1, count,
551 orderByComparator);
552
553 if (list.isEmpty()) {
554 StringBundler msg = new StringBundler(4);
555
556 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
557
558 msg.append("uuid=");
559 msg.append(uuid);
560
561 msg.append(StringPool.CLOSE_CURLY_BRACE);
562
563 throw new NoSuchNodeException(msg.toString());
564 }
565 else {
566 return list.get(0);
567 }
568 }
569
570 public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
571 OrderByComparator orderByComparator)
572 throws NoSuchNodeException, SystemException {
573 WikiNode wikiNode = findByPrimaryKey(nodeId);
574
575 Session session = null;
576
577 try {
578 session = openSession();
579
580 WikiNode[] array = new WikiNodeImpl[3];
581
582 array[0] = getByUuid_PrevAndNext(session, wikiNode, uuid,
583 orderByComparator, true);
584
585 array[1] = wikiNode;
586
587 array[2] = getByUuid_PrevAndNext(session, wikiNode, uuid,
588 orderByComparator, false);
589
590 return array;
591 }
592 catch (Exception e) {
593 throw processException(e);
594 }
595 finally {
596 closeSession(session);
597 }
598 }
599
600 protected WikiNode getByUuid_PrevAndNext(Session session,
601 WikiNode wikiNode, String uuid, OrderByComparator orderByComparator,
602 boolean previous) {
603 StringBundler query = null;
604
605 if (orderByComparator != null) {
606 query = new StringBundler(6 +
607 (orderByComparator.getOrderByFields().length * 6));
608 }
609 else {
610 query = new StringBundler(3);
611 }
612
613 query.append(_SQL_SELECT_WIKINODE_WHERE);
614
615 if (uuid == null) {
616 query.append(_FINDER_COLUMN_UUID_UUID_1);
617 }
618 else {
619 if (uuid.equals(StringPool.BLANK)) {
620 query.append(_FINDER_COLUMN_UUID_UUID_3);
621 }
622 else {
623 query.append(_FINDER_COLUMN_UUID_UUID_2);
624 }
625 }
626
627 if (orderByComparator != null) {
628 String[] orderByFields = orderByComparator.getOrderByFields();
629
630 if (orderByFields.length > 0) {
631 query.append(WHERE_AND);
632 }
633
634 for (int i = 0; i < orderByFields.length; i++) {
635 query.append(_ORDER_BY_ENTITY_ALIAS);
636 query.append(orderByFields[i]);
637
638 if ((i + 1) < orderByFields.length) {
639 if (orderByComparator.isAscending() ^ previous) {
640 query.append(WHERE_GREATER_THAN_HAS_NEXT);
641 }
642 else {
643 query.append(WHERE_LESSER_THAN_HAS_NEXT);
644 }
645 }
646 else {
647 if (orderByComparator.isAscending() ^ previous) {
648 query.append(WHERE_GREATER_THAN);
649 }
650 else {
651 query.append(WHERE_LESSER_THAN);
652 }
653 }
654 }
655
656 query.append(ORDER_BY_CLAUSE);
657
658 for (int i = 0; i < orderByFields.length; i++) {
659 query.append(_ORDER_BY_ENTITY_ALIAS);
660 query.append(orderByFields[i]);
661
662 if ((i + 1) < orderByFields.length) {
663 if (orderByComparator.isAscending() ^ previous) {
664 query.append(ORDER_BY_ASC_HAS_NEXT);
665 }
666 else {
667 query.append(ORDER_BY_DESC_HAS_NEXT);
668 }
669 }
670 else {
671 if (orderByComparator.isAscending() ^ previous) {
672 query.append(ORDER_BY_ASC);
673 }
674 else {
675 query.append(ORDER_BY_DESC);
676 }
677 }
678 }
679 }
680
681 else {
682 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
683 }
684
685 String sql = query.toString();
686
687 Query q = session.createQuery(sql);
688
689 q.setFirstResult(0);
690 q.setMaxResults(2);
691
692 QueryPos qPos = QueryPos.getInstance(q);
693
694 if (uuid != null) {
695 qPos.add(uuid);
696 }
697
698 if (orderByComparator != null) {
699 Object[] values = orderByComparator.getOrderByValues(wikiNode);
700
701 for (Object value : values) {
702 qPos.add(value);
703 }
704 }
705
706 List<WikiNode> list = q.list();
707
708 if (list.size() == 2) {
709 return list.get(1);
710 }
711 else {
712 return null;
713 }
714 }
715
716 public WikiNode findByUUID_G(String uuid, long groupId)
717 throws NoSuchNodeException, SystemException {
718 WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
719
720 if (wikiNode == null) {
721 StringBundler msg = new StringBundler(6);
722
723 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
724
725 msg.append("uuid=");
726 msg.append(uuid);
727
728 msg.append(", groupId=");
729 msg.append(groupId);
730
731 msg.append(StringPool.CLOSE_CURLY_BRACE);
732
733 if (_log.isWarnEnabled()) {
734 _log.warn(msg.toString());
735 }
736
737 throw new NoSuchNodeException(msg.toString());
738 }
739
740 return wikiNode;
741 }
742
743 public WikiNode fetchByUUID_G(String uuid, long groupId)
744 throws SystemException {
745 return fetchByUUID_G(uuid, groupId, true);
746 }
747
748 public WikiNode fetchByUUID_G(String uuid, long groupId,
749 boolean retrieveFromCache) throws SystemException {
750 Object[] finderArgs = new Object[] { uuid, groupId };
751
752 Object result = null;
753
754 if (retrieveFromCache) {
755 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
756 finderArgs, this);
757 }
758
759 if (result == null) {
760 Session session = null;
761
762 try {
763 session = openSession();
764
765 StringBundler query = new StringBundler(4);
766
767 query.append(_SQL_SELECT_WIKINODE_WHERE);
768
769 if (uuid == null) {
770 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
771 }
772 else {
773 if (uuid.equals(StringPool.BLANK)) {
774 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
775 }
776 else {
777 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
778 }
779 }
780
781 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
782
783 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
784
785 String sql = query.toString();
786
787 Query q = session.createQuery(sql);
788
789 QueryPos qPos = QueryPos.getInstance(q);
790
791 if (uuid != null) {
792 qPos.add(uuid);
793 }
794
795 qPos.add(groupId);
796
797 List<WikiNode> list = q.list();
798
799 result = list;
800
801 WikiNode wikiNode = null;
802
803 if (list.isEmpty()) {
804 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
805 finderArgs, list);
806 }
807 else {
808 wikiNode = list.get(0);
809
810 cacheResult(wikiNode);
811
812 if ((wikiNode.getUuid() == null) ||
813 !wikiNode.getUuid().equals(uuid) ||
814 (wikiNode.getGroupId() != groupId)) {
815 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
816 finderArgs, wikiNode);
817 }
818 }
819
820 return wikiNode;
821 }
822 catch (Exception e) {
823 throw processException(e);
824 }
825 finally {
826 if (result == null) {
827 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
828 finderArgs, new ArrayList<WikiNode>());
829 }
830
831 closeSession(session);
832 }
833 }
834 else {
835 if (result instanceof List<?>) {
836 return null;
837 }
838 else {
839 return (WikiNode)result;
840 }
841 }
842 }
843
844 public List<WikiNode> findByGroupId(long groupId) throws SystemException {
845 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
846 }
847
848 public List<WikiNode> findByGroupId(long groupId, int start, int end)
849 throws SystemException {
850 return findByGroupId(groupId, start, end, null);
851 }
852
853 public List<WikiNode> findByGroupId(long groupId, int start, int end,
854 OrderByComparator orderByComparator) throws SystemException {
855 Object[] finderArgs = new Object[] {
856 groupId,
857
858 String.valueOf(start), String.valueOf(end),
859 String.valueOf(orderByComparator)
860 };
861
862 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
863 finderArgs, this);
864
865 if (list == null) {
866 Session session = null;
867
868 try {
869 session = openSession();
870
871 StringBundler query = null;
872
873 if (orderByComparator != null) {
874 query = new StringBundler(3 +
875 (orderByComparator.getOrderByFields().length * 3));
876 }
877 else {
878 query = new StringBundler(3);
879 }
880
881 query.append(_SQL_SELECT_WIKINODE_WHERE);
882
883 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
884
885 if (orderByComparator != null) {
886 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
887 orderByComparator);
888 }
889
890 else {
891 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
892 }
893
894 String sql = query.toString();
895
896 Query q = session.createQuery(sql);
897
898 QueryPos qPos = QueryPos.getInstance(q);
899
900 qPos.add(groupId);
901
902 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
903 end);
904 }
905 catch (Exception e) {
906 throw processException(e);
907 }
908 finally {
909 if (list == null) {
910 list = new ArrayList<WikiNode>();
911 }
912
913 cacheResult(list);
914
915 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
916 finderArgs, list);
917
918 closeSession(session);
919 }
920 }
921
922 return list;
923 }
924
925 public WikiNode findByGroupId_First(long groupId,
926 OrderByComparator orderByComparator)
927 throws NoSuchNodeException, SystemException {
928 List<WikiNode> list = findByGroupId(groupId, 0, 1, orderByComparator);
929
930 if (list.isEmpty()) {
931 StringBundler msg = new StringBundler(4);
932
933 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
934
935 msg.append("groupId=");
936 msg.append(groupId);
937
938 msg.append(StringPool.CLOSE_CURLY_BRACE);
939
940 throw new NoSuchNodeException(msg.toString());
941 }
942 else {
943 return list.get(0);
944 }
945 }
946
947 public WikiNode findByGroupId_Last(long groupId,
948 OrderByComparator orderByComparator)
949 throws NoSuchNodeException, SystemException {
950 int count = countByGroupId(groupId);
951
952 List<WikiNode> list = findByGroupId(groupId, count - 1, count,
953 orderByComparator);
954
955 if (list.isEmpty()) {
956 StringBundler msg = new StringBundler(4);
957
958 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
959
960 msg.append("groupId=");
961 msg.append(groupId);
962
963 msg.append(StringPool.CLOSE_CURLY_BRACE);
964
965 throw new NoSuchNodeException(msg.toString());
966 }
967 else {
968 return list.get(0);
969 }
970 }
971
972 public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
973 OrderByComparator orderByComparator)
974 throws NoSuchNodeException, SystemException {
975 WikiNode wikiNode = findByPrimaryKey(nodeId);
976
977 Session session = null;
978
979 try {
980 session = openSession();
981
982 WikiNode[] array = new WikiNodeImpl[3];
983
984 array[0] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
985 orderByComparator, true);
986
987 array[1] = wikiNode;
988
989 array[2] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
990 orderByComparator, false);
991
992 return array;
993 }
994 catch (Exception e) {
995 throw processException(e);
996 }
997 finally {
998 closeSession(session);
999 }
1000 }
1001
1002 protected WikiNode getByGroupId_PrevAndNext(Session session,
1003 WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1004 boolean previous) {
1005 StringBundler query = null;
1006
1007 if (orderByComparator != null) {
1008 query = new StringBundler(6 +
1009 (orderByComparator.getOrderByFields().length * 6));
1010 }
1011 else {
1012 query = new StringBundler(3);
1013 }
1014
1015 query.append(_SQL_SELECT_WIKINODE_WHERE);
1016
1017 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1018
1019 if (orderByComparator != null) {
1020 String[] orderByFields = orderByComparator.getOrderByFields();
1021
1022 if (orderByFields.length > 0) {
1023 query.append(WHERE_AND);
1024 }
1025
1026 for (int i = 0; i < orderByFields.length; i++) {
1027 query.append(_ORDER_BY_ENTITY_ALIAS);
1028 query.append(orderByFields[i]);
1029
1030 if ((i + 1) < orderByFields.length) {
1031 if (orderByComparator.isAscending() ^ previous) {
1032 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1033 }
1034 else {
1035 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1036 }
1037 }
1038 else {
1039 if (orderByComparator.isAscending() ^ previous) {
1040 query.append(WHERE_GREATER_THAN);
1041 }
1042 else {
1043 query.append(WHERE_LESSER_THAN);
1044 }
1045 }
1046 }
1047
1048 query.append(ORDER_BY_CLAUSE);
1049
1050 for (int i = 0; i < orderByFields.length; i++) {
1051 query.append(_ORDER_BY_ENTITY_ALIAS);
1052 query.append(orderByFields[i]);
1053
1054 if ((i + 1) < orderByFields.length) {
1055 if (orderByComparator.isAscending() ^ previous) {
1056 query.append(ORDER_BY_ASC_HAS_NEXT);
1057 }
1058 else {
1059 query.append(ORDER_BY_DESC_HAS_NEXT);
1060 }
1061 }
1062 else {
1063 if (orderByComparator.isAscending() ^ previous) {
1064 query.append(ORDER_BY_ASC);
1065 }
1066 else {
1067 query.append(ORDER_BY_DESC);
1068 }
1069 }
1070 }
1071 }
1072
1073 else {
1074 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1075 }
1076
1077 String sql = query.toString();
1078
1079 Query q = session.createQuery(sql);
1080
1081 q.setFirstResult(0);
1082 q.setMaxResults(2);
1083
1084 QueryPos qPos = QueryPos.getInstance(q);
1085
1086 qPos.add(groupId);
1087
1088 if (orderByComparator != null) {
1089 Object[] values = orderByComparator.getOrderByValues(wikiNode);
1090
1091 for (Object value : values) {
1092 qPos.add(value);
1093 }
1094 }
1095
1096 List<WikiNode> list = q.list();
1097
1098 if (list.size() == 2) {
1099 return list.get(1);
1100 }
1101 else {
1102 return null;
1103 }
1104 }
1105
1106 public List<WikiNode> filterFindByGroupId(long groupId)
1107 throws SystemException {
1108 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1109 QueryUtil.ALL_POS, null);
1110 }
1111
1112 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end)
1113 throws SystemException {
1114 return filterFindByGroupId(groupId, start, end, null);
1115 }
1116
1117 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end,
1118 OrderByComparator orderByComparator) throws SystemException {
1119 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1120 return findByGroupId(groupId, start, end, orderByComparator);
1121 }
1122
1123 Session session = null;
1124
1125 try {
1126 session = openSession();
1127
1128 StringBundler query = null;
1129
1130 if (orderByComparator != null) {
1131 query = new StringBundler(3 +
1132 (orderByComparator.getOrderByFields().length * 3));
1133 }
1134 else {
1135 query = new StringBundler(3);
1136 }
1137
1138 query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1139
1140 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1141
1142 if (orderByComparator != null) {
1143 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1144 orderByComparator);
1145 }
1146
1147 else {
1148 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1149 }
1150
1151 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1152 WikiNode.class.getName(), _FILTER_COLUMN_PK,
1153 _FILTER_COLUMN_USERID, groupId);
1154
1155 SQLQuery q = session.createSQLQuery(sql);
1156
1157 q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1158
1159 QueryPos qPos = QueryPos.getInstance(q);
1160
1161 qPos.add(groupId);
1162
1163 return (List<WikiNode>)QueryUtil.list(q, getDialect(), start, end);
1164 }
1165 catch (Exception e) {
1166 throw processException(e);
1167 }
1168 finally {
1169 closeSession(session);
1170 }
1171 }
1172
1173 public List<WikiNode> findByCompanyId(long companyId)
1174 throws SystemException {
1175 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1176 null);
1177 }
1178
1179 public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1180 throws SystemException {
1181 return findByCompanyId(companyId, start, end, null);
1182 }
1183
1184 public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1185 OrderByComparator orderByComparator) throws SystemException {
1186 Object[] finderArgs = new Object[] {
1187 companyId,
1188
1189 String.valueOf(start), String.valueOf(end),
1190 String.valueOf(orderByComparator)
1191 };
1192
1193 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1194 finderArgs, this);
1195
1196 if (list == null) {
1197 Session session = null;
1198
1199 try {
1200 session = openSession();
1201
1202 StringBundler query = null;
1203
1204 if (orderByComparator != null) {
1205 query = new StringBundler(3 +
1206 (orderByComparator.getOrderByFields().length * 3));
1207 }
1208 else {
1209 query = new StringBundler(3);
1210 }
1211
1212 query.append(_SQL_SELECT_WIKINODE_WHERE);
1213
1214 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1215
1216 if (orderByComparator != null) {
1217 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1218 orderByComparator);
1219 }
1220
1221 else {
1222 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1223 }
1224
1225 String sql = query.toString();
1226
1227 Query q = session.createQuery(sql);
1228
1229 QueryPos qPos = QueryPos.getInstance(q);
1230
1231 qPos.add(companyId);
1232
1233 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1234 end);
1235 }
1236 catch (Exception e) {
1237 throw processException(e);
1238 }
1239 finally {
1240 if (list == null) {
1241 list = new ArrayList<WikiNode>();
1242 }
1243
1244 cacheResult(list);
1245
1246 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1247 finderArgs, list);
1248
1249 closeSession(session);
1250 }
1251 }
1252
1253 return list;
1254 }
1255
1256 public WikiNode findByCompanyId_First(long companyId,
1257 OrderByComparator orderByComparator)
1258 throws NoSuchNodeException, SystemException {
1259 List<WikiNode> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1260
1261 if (list.isEmpty()) {
1262 StringBundler msg = new StringBundler(4);
1263
1264 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1265
1266 msg.append("companyId=");
1267 msg.append(companyId);
1268
1269 msg.append(StringPool.CLOSE_CURLY_BRACE);
1270
1271 throw new NoSuchNodeException(msg.toString());
1272 }
1273 else {
1274 return list.get(0);
1275 }
1276 }
1277
1278 public WikiNode findByCompanyId_Last(long companyId,
1279 OrderByComparator orderByComparator)
1280 throws NoSuchNodeException, SystemException {
1281 int count = countByCompanyId(companyId);
1282
1283 List<WikiNode> list = findByCompanyId(companyId, count - 1, count,
1284 orderByComparator);
1285
1286 if (list.isEmpty()) {
1287 StringBundler msg = new StringBundler(4);
1288
1289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1290
1291 msg.append("companyId=");
1292 msg.append(companyId);
1293
1294 msg.append(StringPool.CLOSE_CURLY_BRACE);
1295
1296 throw new NoSuchNodeException(msg.toString());
1297 }
1298 else {
1299 return list.get(0);
1300 }
1301 }
1302
1303 public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
1304 OrderByComparator orderByComparator)
1305 throws NoSuchNodeException, SystemException {
1306 WikiNode wikiNode = findByPrimaryKey(nodeId);
1307
1308 Session session = null;
1309
1310 try {
1311 session = openSession();
1312
1313 WikiNode[] array = new WikiNodeImpl[3];
1314
1315 array[0] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
1316 orderByComparator, true);
1317
1318 array[1] = wikiNode;
1319
1320 array[2] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
1321 orderByComparator, false);
1322
1323 return array;
1324 }
1325 catch (Exception e) {
1326 throw processException(e);
1327 }
1328 finally {
1329 closeSession(session);
1330 }
1331 }
1332
1333 protected WikiNode getByCompanyId_PrevAndNext(Session session,
1334 WikiNode wikiNode, long companyId, OrderByComparator orderByComparator,
1335 boolean previous) {
1336 StringBundler query = null;
1337
1338 if (orderByComparator != null) {
1339 query = new StringBundler(6 +
1340 (orderByComparator.getOrderByFields().length * 6));
1341 }
1342 else {
1343 query = new StringBundler(3);
1344 }
1345
1346 query.append(_SQL_SELECT_WIKINODE_WHERE);
1347
1348 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1349
1350 if (orderByComparator != null) {
1351 String[] orderByFields = orderByComparator.getOrderByFields();
1352
1353 if (orderByFields.length > 0) {
1354 query.append(WHERE_AND);
1355 }
1356
1357 for (int i = 0; i < orderByFields.length; i++) {
1358 query.append(_ORDER_BY_ENTITY_ALIAS);
1359 query.append(orderByFields[i]);
1360
1361 if ((i + 1) < orderByFields.length) {
1362 if (orderByComparator.isAscending() ^ previous) {
1363 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1364 }
1365 else {
1366 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1367 }
1368 }
1369 else {
1370 if (orderByComparator.isAscending() ^ previous) {
1371 query.append(WHERE_GREATER_THAN);
1372 }
1373 else {
1374 query.append(WHERE_LESSER_THAN);
1375 }
1376 }
1377 }
1378
1379 query.append(ORDER_BY_CLAUSE);
1380
1381 for (int i = 0; i < orderByFields.length; i++) {
1382 query.append(_ORDER_BY_ENTITY_ALIAS);
1383 query.append(orderByFields[i]);
1384
1385 if ((i + 1) < orderByFields.length) {
1386 if (orderByComparator.isAscending() ^ previous) {
1387 query.append(ORDER_BY_ASC_HAS_NEXT);
1388 }
1389 else {
1390 query.append(ORDER_BY_DESC_HAS_NEXT);
1391 }
1392 }
1393 else {
1394 if (orderByComparator.isAscending() ^ previous) {
1395 query.append(ORDER_BY_ASC);
1396 }
1397 else {
1398 query.append(ORDER_BY_DESC);
1399 }
1400 }
1401 }
1402 }
1403
1404 else {
1405 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1406 }
1407
1408 String sql = query.toString();
1409
1410 Query q = session.createQuery(sql);
1411
1412 q.setFirstResult(0);
1413 q.setMaxResults(2);
1414
1415 QueryPos qPos = QueryPos.getInstance(q);
1416
1417 qPos.add(companyId);
1418
1419 if (orderByComparator != null) {
1420 Object[] values = orderByComparator.getOrderByValues(wikiNode);
1421
1422 for (Object value : values) {
1423 qPos.add(value);
1424 }
1425 }
1426
1427 List<WikiNode> list = q.list();
1428
1429 if (list.size() == 2) {
1430 return list.get(1);
1431 }
1432 else {
1433 return null;
1434 }
1435 }
1436
1437 public WikiNode findByG_N(long groupId, String name)
1438 throws NoSuchNodeException, SystemException {
1439 WikiNode wikiNode = fetchByG_N(groupId, name);
1440
1441 if (wikiNode == null) {
1442 StringBundler msg = new StringBundler(6);
1443
1444 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1445
1446 msg.append("groupId=");
1447 msg.append(groupId);
1448
1449 msg.append(", name=");
1450 msg.append(name);
1451
1452 msg.append(StringPool.CLOSE_CURLY_BRACE);
1453
1454 if (_log.isWarnEnabled()) {
1455 _log.warn(msg.toString());
1456 }
1457
1458 throw new NoSuchNodeException(msg.toString());
1459 }
1460
1461 return wikiNode;
1462 }
1463
1464 public WikiNode fetchByG_N(long groupId, String name)
1465 throws SystemException {
1466 return fetchByG_N(groupId, name, true);
1467 }
1468
1469 public WikiNode fetchByG_N(long groupId, String name,
1470 boolean retrieveFromCache) throws SystemException {
1471 Object[] finderArgs = new Object[] { groupId, name };
1472
1473 Object result = null;
1474
1475 if (retrieveFromCache) {
1476 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1477 finderArgs, this);
1478 }
1479
1480 if (result == null) {
1481 Session session = null;
1482
1483 try {
1484 session = openSession();
1485
1486 StringBundler query = new StringBundler(4);
1487
1488 query.append(_SQL_SELECT_WIKINODE_WHERE);
1489
1490 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1491
1492 if (name == null) {
1493 query.append(_FINDER_COLUMN_G_N_NAME_1);
1494 }
1495 else {
1496 if (name.equals(StringPool.BLANK)) {
1497 query.append(_FINDER_COLUMN_G_N_NAME_3);
1498 }
1499 else {
1500 query.append(_FINDER_COLUMN_G_N_NAME_2);
1501 }
1502 }
1503
1504 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1505
1506 String sql = query.toString();
1507
1508 Query q = session.createQuery(sql);
1509
1510 QueryPos qPos = QueryPos.getInstance(q);
1511
1512 qPos.add(groupId);
1513
1514 if (name != null) {
1515 qPos.add(name);
1516 }
1517
1518 List<WikiNode> list = q.list();
1519
1520 result = list;
1521
1522 WikiNode wikiNode = null;
1523
1524 if (list.isEmpty()) {
1525 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1526 finderArgs, list);
1527 }
1528 else {
1529 wikiNode = list.get(0);
1530
1531 cacheResult(wikiNode);
1532
1533 if ((wikiNode.getGroupId() != groupId) ||
1534 (wikiNode.getName() == null) ||
1535 !wikiNode.getName().equals(name)) {
1536 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1537 finderArgs, wikiNode);
1538 }
1539 }
1540
1541 return wikiNode;
1542 }
1543 catch (Exception e) {
1544 throw processException(e);
1545 }
1546 finally {
1547 if (result == null) {
1548 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1549 finderArgs, new ArrayList<WikiNode>());
1550 }
1551
1552 closeSession(session);
1553 }
1554 }
1555 else {
1556 if (result instanceof List<?>) {
1557 return null;
1558 }
1559 else {
1560 return (WikiNode)result;
1561 }
1562 }
1563 }
1564
1565 public List<WikiNode> findAll() throws SystemException {
1566 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1567 }
1568
1569 public List<WikiNode> findAll(int start, int end) throws SystemException {
1570 return findAll(start, end, null);
1571 }
1572
1573 public List<WikiNode> findAll(int start, int end,
1574 OrderByComparator orderByComparator) throws SystemException {
1575 Object[] finderArgs = new Object[] {
1576 String.valueOf(start), String.valueOf(end),
1577 String.valueOf(orderByComparator)
1578 };
1579
1580 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1581 finderArgs, this);
1582
1583 if (list == null) {
1584 Session session = null;
1585
1586 try {
1587 session = openSession();
1588
1589 StringBundler query = null;
1590 String sql = null;
1591
1592 if (orderByComparator != null) {
1593 query = new StringBundler(2 +
1594 (orderByComparator.getOrderByFields().length * 3));
1595
1596 query.append(_SQL_SELECT_WIKINODE);
1597
1598 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1599 orderByComparator);
1600
1601 sql = query.toString();
1602 }
1603 else {
1604 sql = _SQL_SELECT_WIKINODE.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
1605 }
1606
1607 Query q = session.createQuery(sql);
1608
1609 if (orderByComparator == null) {
1610 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1611 start, end, false);
1612
1613 Collections.sort(list);
1614 }
1615 else {
1616 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1617 start, end);
1618 }
1619 }
1620 catch (Exception e) {
1621 throw processException(e);
1622 }
1623 finally {
1624 if (list == null) {
1625 list = new ArrayList<WikiNode>();
1626 }
1627
1628 cacheResult(list);
1629
1630 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1631
1632 closeSession(session);
1633 }
1634 }
1635
1636 return list;
1637 }
1638
1639 public void removeByUuid(String uuid) throws SystemException {
1640 for (WikiNode wikiNode : findByUuid(uuid)) {
1641 remove(wikiNode);
1642 }
1643 }
1644
1645 public void removeByUUID_G(String uuid, long groupId)
1646 throws NoSuchNodeException, SystemException {
1647 WikiNode wikiNode = findByUUID_G(uuid, groupId);
1648
1649 remove(wikiNode);
1650 }
1651
1652 public void removeByGroupId(long groupId) throws SystemException {
1653 for (WikiNode wikiNode : findByGroupId(groupId)) {
1654 remove(wikiNode);
1655 }
1656 }
1657
1658 public void removeByCompanyId(long companyId) throws SystemException {
1659 for (WikiNode wikiNode : findByCompanyId(companyId)) {
1660 remove(wikiNode);
1661 }
1662 }
1663
1664 public void removeByG_N(long groupId, String name)
1665 throws NoSuchNodeException, SystemException {
1666 WikiNode wikiNode = findByG_N(groupId, name);
1667
1668 remove(wikiNode);
1669 }
1670
1671 public void removeAll() throws SystemException {
1672 for (WikiNode wikiNode : findAll()) {
1673 remove(wikiNode);
1674 }
1675 }
1676
1677 public int countByUuid(String uuid) throws SystemException {
1678 Object[] finderArgs = new Object[] { uuid };
1679
1680 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1681 finderArgs, this);
1682
1683 if (count == null) {
1684 Session session = null;
1685
1686 try {
1687 session = openSession();
1688
1689 StringBundler query = new StringBundler(2);
1690
1691 query.append(_SQL_COUNT_WIKINODE_WHERE);
1692
1693 if (uuid == null) {
1694 query.append(_FINDER_COLUMN_UUID_UUID_1);
1695 }
1696 else {
1697 if (uuid.equals(StringPool.BLANK)) {
1698 query.append(_FINDER_COLUMN_UUID_UUID_3);
1699 }
1700 else {
1701 query.append(_FINDER_COLUMN_UUID_UUID_2);
1702 }
1703 }
1704
1705 String sql = query.toString();
1706
1707 Query q = session.createQuery(sql);
1708
1709 QueryPos qPos = QueryPos.getInstance(q);
1710
1711 if (uuid != null) {
1712 qPos.add(uuid);
1713 }
1714
1715 count = (Long)q.uniqueResult();
1716 }
1717 catch (Exception e) {
1718 throw processException(e);
1719 }
1720 finally {
1721 if (count == null) {
1722 count = Long.valueOf(0);
1723 }
1724
1725 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1726 finderArgs, count);
1727
1728 closeSession(session);
1729 }
1730 }
1731
1732 return count.intValue();
1733 }
1734
1735 public int countByUUID_G(String uuid, long groupId)
1736 throws SystemException {
1737 Object[] finderArgs = new Object[] { uuid, groupId };
1738
1739 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1740 finderArgs, this);
1741
1742 if (count == null) {
1743 Session session = null;
1744
1745 try {
1746 session = openSession();
1747
1748 StringBundler query = new StringBundler(3);
1749
1750 query.append(_SQL_COUNT_WIKINODE_WHERE);
1751
1752 if (uuid == null) {
1753 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1754 }
1755 else {
1756 if (uuid.equals(StringPool.BLANK)) {
1757 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1758 }
1759 else {
1760 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1761 }
1762 }
1763
1764 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1765
1766 String sql = query.toString();
1767
1768 Query q = session.createQuery(sql);
1769
1770 QueryPos qPos = QueryPos.getInstance(q);
1771
1772 if (uuid != null) {
1773 qPos.add(uuid);
1774 }
1775
1776 qPos.add(groupId);
1777
1778 count = (Long)q.uniqueResult();
1779 }
1780 catch (Exception e) {
1781 throw processException(e);
1782 }
1783 finally {
1784 if (count == null) {
1785 count = Long.valueOf(0);
1786 }
1787
1788 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1789 finderArgs, count);
1790
1791 closeSession(session);
1792 }
1793 }
1794
1795 return count.intValue();
1796 }
1797
1798 public int countByGroupId(long groupId) throws SystemException {
1799 Object[] finderArgs = new Object[] { groupId };
1800
1801 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1802 finderArgs, this);
1803
1804 if (count == null) {
1805 Session session = null;
1806
1807 try {
1808 session = openSession();
1809
1810 StringBundler query = new StringBundler(2);
1811
1812 query.append(_SQL_COUNT_WIKINODE_WHERE);
1813
1814 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1815
1816 String sql = query.toString();
1817
1818 Query q = session.createQuery(sql);
1819
1820 QueryPos qPos = QueryPos.getInstance(q);
1821
1822 qPos.add(groupId);
1823
1824 count = (Long)q.uniqueResult();
1825 }
1826 catch (Exception e) {
1827 throw processException(e);
1828 }
1829 finally {
1830 if (count == null) {
1831 count = Long.valueOf(0);
1832 }
1833
1834 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1835 finderArgs, count);
1836
1837 closeSession(session);
1838 }
1839 }
1840
1841 return count.intValue();
1842 }
1843
1844 public int filterCountByGroupId(long groupId) throws SystemException {
1845 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1846 return countByGroupId(groupId);
1847 }
1848
1849 Session session = null;
1850
1851 try {
1852 session = openSession();
1853
1854 StringBundler query = new StringBundler(2);
1855
1856 query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
1857
1858 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1859
1860 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1861 WikiNode.class.getName(), _FILTER_COLUMN_PK,
1862 _FILTER_COLUMN_USERID, groupId);
1863
1864 SQLQuery q = session.createSQLQuery(sql);
1865
1866 q.addScalar(COUNT_COLUMN_NAME,
1867 com.liferay.portal.kernel.dao.orm.Type.LONG);
1868
1869 QueryPos qPos = QueryPos.getInstance(q);
1870
1871 qPos.add(groupId);
1872
1873 Long count = (Long)q.uniqueResult();
1874
1875 return count.intValue();
1876 }
1877 catch (Exception e) {
1878 throw processException(e);
1879 }
1880 finally {
1881 closeSession(session);
1882 }
1883 }
1884
1885 public int countByCompanyId(long companyId) throws SystemException {
1886 Object[] finderArgs = new Object[] { companyId };
1887
1888 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1889 finderArgs, this);
1890
1891 if (count == null) {
1892 Session session = null;
1893
1894 try {
1895 session = openSession();
1896
1897 StringBundler query = new StringBundler(2);
1898
1899 query.append(_SQL_COUNT_WIKINODE_WHERE);
1900
1901 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1902
1903 String sql = query.toString();
1904
1905 Query q = session.createQuery(sql);
1906
1907 QueryPos qPos = QueryPos.getInstance(q);
1908
1909 qPos.add(companyId);
1910
1911 count = (Long)q.uniqueResult();
1912 }
1913 catch (Exception e) {
1914 throw processException(e);
1915 }
1916 finally {
1917 if (count == null) {
1918 count = Long.valueOf(0);
1919 }
1920
1921 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1922 finderArgs, count);
1923
1924 closeSession(session);
1925 }
1926 }
1927
1928 return count.intValue();
1929 }
1930
1931 public int countByG_N(long groupId, String name) throws SystemException {
1932 Object[] finderArgs = new Object[] { groupId, name };
1933
1934 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1935 finderArgs, this);
1936
1937 if (count == null) {
1938 Session session = null;
1939
1940 try {
1941 session = openSession();
1942
1943 StringBundler query = new StringBundler(3);
1944
1945 query.append(_SQL_COUNT_WIKINODE_WHERE);
1946
1947 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1948
1949 if (name == null) {
1950 query.append(_FINDER_COLUMN_G_N_NAME_1);
1951 }
1952 else {
1953 if (name.equals(StringPool.BLANK)) {
1954 query.append(_FINDER_COLUMN_G_N_NAME_3);
1955 }
1956 else {
1957 query.append(_FINDER_COLUMN_G_N_NAME_2);
1958 }
1959 }
1960
1961 String sql = query.toString();
1962
1963 Query q = session.createQuery(sql);
1964
1965 QueryPos qPos = QueryPos.getInstance(q);
1966
1967 qPos.add(groupId);
1968
1969 if (name != null) {
1970 qPos.add(name);
1971 }
1972
1973 count = (Long)q.uniqueResult();
1974 }
1975 catch (Exception e) {
1976 throw processException(e);
1977 }
1978 finally {
1979 if (count == null) {
1980 count = Long.valueOf(0);
1981 }
1982
1983 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1984 count);
1985
1986 closeSession(session);
1987 }
1988 }
1989
1990 return count.intValue();
1991 }
1992
1993 public int filterCountByG_N(long groupId, String name)
1994 throws SystemException {
1995 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1996 return countByG_N(groupId, name);
1997 }
1998
1999 Session session = null;
2000
2001 try {
2002 session = openSession();
2003
2004 StringBundler query = new StringBundler(3);
2005
2006 query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2007
2008 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2009
2010 if (name == null) {
2011 query.append(_FINDER_COLUMN_G_N_NAME_1);
2012 }
2013 else {
2014 if (name.equals(StringPool.BLANK)) {
2015 query.append(_FINDER_COLUMN_G_N_NAME_3);
2016 }
2017 else {
2018 query.append(_FINDER_COLUMN_G_N_NAME_2);
2019 }
2020 }
2021
2022 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2023 WikiNode.class.getName(), _FILTER_COLUMN_PK,
2024 _FILTER_COLUMN_USERID, groupId);
2025
2026 SQLQuery q = session.createSQLQuery(sql);
2027
2028 q.addScalar(COUNT_COLUMN_NAME,
2029 com.liferay.portal.kernel.dao.orm.Type.LONG);
2030
2031 QueryPos qPos = QueryPos.getInstance(q);
2032
2033 qPos.add(groupId);
2034
2035 if (name != null) {
2036 qPos.add(name);
2037 }
2038
2039 Long count = (Long)q.uniqueResult();
2040
2041 return count.intValue();
2042 }
2043 catch (Exception e) {
2044 throw processException(e);
2045 }
2046 finally {
2047 closeSession(session);
2048 }
2049 }
2050
2051 public int countAll() throws SystemException {
2052 Object[] finderArgs = new Object[0];
2053
2054 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2055 finderArgs, this);
2056
2057 if (count == null) {
2058 Session session = null;
2059
2060 try {
2061 session = openSession();
2062
2063 Query q = session.createQuery(_SQL_COUNT_WIKINODE);
2064
2065 count = (Long)q.uniqueResult();
2066 }
2067 catch (Exception e) {
2068 throw processException(e);
2069 }
2070 finally {
2071 if (count == null) {
2072 count = Long.valueOf(0);
2073 }
2074
2075 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2076 count);
2077
2078 closeSession(session);
2079 }
2080 }
2081
2082 return count.intValue();
2083 }
2084
2085 public void afterPropertiesSet() {
2086 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2087 com.liferay.portal.util.PropsUtil.get(
2088 "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
2089
2090 if (listenerClassNames.length > 0) {
2091 try {
2092 List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
2093
2094 for (String listenerClassName : listenerClassNames) {
2095 listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
2096 listenerClassName));
2097 }
2098
2099 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2100 }
2101 catch (Exception e) {
2102 _log.error(e);
2103 }
2104 }
2105 }
2106
2107 @BeanReference(type = WikiNodePersistence.class)
2108 protected WikiNodePersistence wikiNodePersistence;
2109 @BeanReference(type = WikiPagePersistence.class)
2110 protected WikiPagePersistence wikiPagePersistence;
2111 @BeanReference(type = WikiPageResourcePersistence.class)
2112 protected WikiPageResourcePersistence wikiPageResourcePersistence;
2113 @BeanReference(type = GroupPersistence.class)
2114 protected GroupPersistence groupPersistence;
2115 @BeanReference(type = ResourcePersistence.class)
2116 protected ResourcePersistence resourcePersistence;
2117 @BeanReference(type = SubscriptionPersistence.class)
2118 protected SubscriptionPersistence subscriptionPersistence;
2119 @BeanReference(type = UserPersistence.class)
2120 protected UserPersistence userPersistence;
2121 private static final String _SQL_SELECT_WIKINODE = "SELECT wikiNode FROM WikiNode wikiNode";
2122 private static final String _SQL_SELECT_WIKINODE_WHERE = "SELECT wikiNode FROM WikiNode wikiNode WHERE ";
2123 private static final String _SQL_COUNT_WIKINODE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode";
2124 private static final String _SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode WHERE ";
2125 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiNode.uuid IS NULL";
2126 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiNode.uuid = ?";
2127 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?)";
2128 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiNode.uuid IS NULL AND ";
2129 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiNode.uuid = ? AND ";
2130 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?) AND ";
2131 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiNode.groupId = ?";
2132 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "wikiNode.groupId = ?";
2133 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "wikiNode.companyId = ?";
2134 private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "wikiNode.groupId = ? AND ";
2135 private static final String _FINDER_COLUMN_G_N_NAME_1 = "wikiNode.name IS NULL";
2136 private static final String _FINDER_COLUMN_G_N_NAME_2 = "wikiNode.name = ?";
2137 private static final String _FINDER_COLUMN_G_N_NAME_3 = "(wikiNode.name IS NULL OR wikiNode.name = ?)";
2138 private static final String _FILTER_SQL_SELECT_WIKINODE_WHERE = "SELECT DISTINCT {wikiNode.*} FROM WikiNode wikiNode WHERE ";
2139 private static final String _FILTER_SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(DISTINCT wikiNode.nodeId) AS COUNT_VALUE FROM WikiNode wikiNode WHERE ";
2140 private static final String _FILTER_COLUMN_PK = "wikiNode.nodeId";
2141 private static final String _FILTER_COLUMN_USERID = "wikiNode.userId";
2142 private static final String _FILTER_ENTITY_ALIAS = "wikiNode";
2143 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
2144 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
2145 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
2146 private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
2147 }