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
075 public class WikiNodePersistenceImpl extends BasePersistenceImpl<WikiNode>
076 implements WikiNodePersistence {
077 public static final String FINDER_CLASS_NAME_ENTITY = WikiNodeImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
079 ".List";
080 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
081 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082 "findByUuid",
083 new String[] {
084 String.class.getName(),
085
086 "java.lang.Integer", "java.lang.Integer",
087 "com.liferay.portal.kernel.util.OrderByComparator"
088 });
089 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
090 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
091 "countByUuid", new String[] { String.class.getName() });
092 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
093 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
094 "fetchByUUID_G",
095 new String[] { String.class.getName(), Long.class.getName() });
096 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
097 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
098 "countByUUID_G",
099 new String[] { String.class.getName(), Long.class.getName() });
100 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
101 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102 "findByGroupId",
103 new String[] {
104 Long.class.getName(),
105
106 "java.lang.Integer", "java.lang.Integer",
107 "com.liferay.portal.kernel.util.OrderByComparator"
108 });
109 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
110 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111 "countByGroupId", new String[] { Long.class.getName() });
112 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
113 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114 "findByCompanyId",
115 new String[] {
116 Long.class.getName(),
117
118 "java.lang.Integer", "java.lang.Integer",
119 "com.liferay.portal.kernel.util.OrderByComparator"
120 });
121 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
122 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123 "countByCompanyId", new String[] { Long.class.getName() });
124 public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
125 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
126 "fetchByG_N",
127 new String[] { Long.class.getName(), String.class.getName() });
128 public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
129 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130 "countByG_N",
131 new String[] { Long.class.getName(), String.class.getName() });
132 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
133 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134 "findAll", new String[0]);
135 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
136 WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137 "countAll", new String[0]);
138
139
144 public void cacheResult(WikiNode wikiNode) {
145 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
146 WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
147
148 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
149 new Object[] { wikiNode.getUuid(), new Long(wikiNode.getGroupId()) },
150 wikiNode);
151
152 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
153 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
154 wikiNode);
155 }
156
157
162 public void cacheResult(List<WikiNode> wikiNodes) {
163 for (WikiNode wikiNode : wikiNodes) {
164 if (EntityCacheUtil.getResult(
165 WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
166 WikiNodeImpl.class, wikiNode.getPrimaryKey(), this) == null) {
167 cacheResult(wikiNode);
168 }
169 }
170 }
171
172
179 public void clearCache() {
180 CacheRegistryUtil.clear(WikiNodeImpl.class.getName());
181 EntityCacheUtil.clearCache(WikiNodeImpl.class.getName());
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
184 }
185
186
193 public void clearCache(WikiNode wikiNode) {
194 EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
195 WikiNodeImpl.class, wikiNode.getPrimaryKey());
196
197 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
198 new Object[] { wikiNode.getUuid(), new Long(wikiNode.getGroupId()) });
199
200 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
201 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() });
202 }
203
204
210 public WikiNode create(long nodeId) {
211 WikiNode wikiNode = new WikiNodeImpl();
212
213 wikiNode.setNew(true);
214 wikiNode.setPrimaryKey(nodeId);
215
216 String uuid = PortalUUIDUtil.generate();
217
218 wikiNode.setUuid(uuid);
219
220 return wikiNode;
221 }
222
223
231 public WikiNode remove(Serializable primaryKey)
232 throws NoSuchModelException, SystemException {
233 return remove(((Long)primaryKey).longValue());
234 }
235
236
244 public WikiNode remove(long nodeId)
245 throws NoSuchNodeException, SystemException {
246 Session session = null;
247
248 try {
249 session = openSession();
250
251 WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
252 new Long(nodeId));
253
254 if (wikiNode == null) {
255 if (_log.isWarnEnabled()) {
256 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
257 }
258
259 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
260 nodeId);
261 }
262
263 return remove(wikiNode);
264 }
265 catch (NoSuchNodeException nsee) {
266 throw nsee;
267 }
268 catch (Exception e) {
269 throw processException(e);
270 }
271 finally {
272 closeSession(session);
273 }
274 }
275
276 protected WikiNode removeImpl(WikiNode wikiNode) throws SystemException {
277 wikiNode = toUnwrappedModel(wikiNode);
278
279 Session session = null;
280
281 try {
282 session = openSession();
283
284 BatchSessionUtil.delete(session, wikiNode);
285 }
286 catch (Exception e) {
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292
293 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
294
295 WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
296
297 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
298 new Object[] {
299 wikiNodeModelImpl.getOriginalUuid(),
300 new Long(wikiNodeModelImpl.getOriginalGroupId())
301 });
302
303 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
304 new Object[] {
305 new Long(wikiNodeModelImpl.getOriginalGroupId()),
306
307 wikiNodeModelImpl.getOriginalName()
308 });
309
310 EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
311 WikiNodeImpl.class, wikiNode.getPrimaryKey());
312
313 return wikiNode;
314 }
315
316 public WikiNode updateImpl(
317 com.liferay.portlet.wiki.model.WikiNode wikiNode, boolean merge)
318 throws SystemException {
319 wikiNode = toUnwrappedModel(wikiNode);
320
321 boolean isNew = wikiNode.isNew();
322
323 WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
324
325 if (Validator.isNull(wikiNode.getUuid())) {
326 String uuid = PortalUUIDUtil.generate();
327
328 wikiNode.setUuid(uuid);
329 }
330
331 Session session = null;
332
333 try {
334 session = openSession();
335
336 BatchSessionUtil.update(session, wikiNode, merge);
337
338 wikiNode.setNew(false);
339 }
340 catch (Exception e) {
341 throw processException(e);
342 }
343 finally {
344 closeSession(session);
345 }
346
347 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
348
349 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
350 WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
351
352 if (!isNew &&
353 (!Validator.equals(wikiNode.getUuid(),
354 wikiNodeModelImpl.getOriginalUuid()) ||
355 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
356 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
357 new Object[] {
358 wikiNodeModelImpl.getOriginalUuid(),
359 new Long(wikiNodeModelImpl.getOriginalGroupId())
360 });
361 }
362
363 if (isNew ||
364 (!Validator.equals(wikiNode.getUuid(),
365 wikiNodeModelImpl.getOriginalUuid()) ||
366 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
367 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
368 new Object[] { wikiNode.getUuid(), new Long(
369 wikiNode.getGroupId()) }, wikiNode);
370 }
371
372 if (!isNew &&
373 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
374 !Validator.equals(wikiNode.getName(),
375 wikiNodeModelImpl.getOriginalName()))) {
376 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
377 new Object[] {
378 new Long(wikiNodeModelImpl.getOriginalGroupId()),
379
380 wikiNodeModelImpl.getOriginalName()
381 });
382 }
383
384 if (isNew ||
385 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
386 !Validator.equals(wikiNode.getName(),
387 wikiNodeModelImpl.getOriginalName()))) {
388 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
389 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
390 wikiNode);
391 }
392
393 return wikiNode;
394 }
395
396 protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
397 if (wikiNode instanceof WikiNodeImpl) {
398 return wikiNode;
399 }
400
401 WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
402
403 wikiNodeImpl.setNew(wikiNode.isNew());
404 wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
405
406 wikiNodeImpl.setUuid(wikiNode.getUuid());
407 wikiNodeImpl.setNodeId(wikiNode.getNodeId());
408 wikiNodeImpl.setGroupId(wikiNode.getGroupId());
409 wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
410 wikiNodeImpl.setUserId(wikiNode.getUserId());
411 wikiNodeImpl.setUserName(wikiNode.getUserName());
412 wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
413 wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
414 wikiNodeImpl.setName(wikiNode.getName());
415 wikiNodeImpl.setDescription(wikiNode.getDescription());
416 wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
417
418 return wikiNodeImpl;
419 }
420
421
429 public WikiNode findByPrimaryKey(Serializable primaryKey)
430 throws NoSuchModelException, SystemException {
431 return findByPrimaryKey(((Long)primaryKey).longValue());
432 }
433
434
442 public WikiNode findByPrimaryKey(long nodeId)
443 throws NoSuchNodeException, SystemException {
444 WikiNode wikiNode = fetchByPrimaryKey(nodeId);
445
446 if (wikiNode == null) {
447 if (_log.isWarnEnabled()) {
448 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
449 }
450
451 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
452 nodeId);
453 }
454
455 return wikiNode;
456 }
457
458
465 public WikiNode fetchByPrimaryKey(Serializable primaryKey)
466 throws SystemException {
467 return fetchByPrimaryKey(((Long)primaryKey).longValue());
468 }
469
470
477 public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
478 WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
479 WikiNodeImpl.class, nodeId, this);
480
481 if (wikiNode == null) {
482 Session session = null;
483
484 try {
485 session = openSession();
486
487 wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
488 new Long(nodeId));
489 }
490 catch (Exception e) {
491 throw processException(e);
492 }
493 finally {
494 if (wikiNode != null) {
495 cacheResult(wikiNode);
496 }
497
498 closeSession(session);
499 }
500 }
501
502 return wikiNode;
503 }
504
505
512 public List<WikiNode> findByUuid(String uuid) throws SystemException {
513 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
514 }
515
516
529 public List<WikiNode> findByUuid(String uuid, int start, int end)
530 throws SystemException {
531 return findByUuid(uuid, start, end, null);
532 }
533
534
548 public List<WikiNode> findByUuid(String uuid, int start, int end,
549 OrderByComparator orderByComparator) throws SystemException {
550 Object[] finderArgs = new Object[] {
551 uuid,
552
553 String.valueOf(start), String.valueOf(end),
554 String.valueOf(orderByComparator)
555 };
556
557 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
558 finderArgs, this);
559
560 if (list == null) {
561 Session session = null;
562
563 try {
564 session = openSession();
565
566 StringBundler query = null;
567
568 if (orderByComparator != null) {
569 query = new StringBundler(3 +
570 (orderByComparator.getOrderByFields().length * 3));
571 }
572 else {
573 query = new StringBundler(3);
574 }
575
576 query.append(_SQL_SELECT_WIKINODE_WHERE);
577
578 if (uuid == null) {
579 query.append(_FINDER_COLUMN_UUID_UUID_1);
580 }
581 else {
582 if (uuid.equals(StringPool.BLANK)) {
583 query.append(_FINDER_COLUMN_UUID_UUID_3);
584 }
585 else {
586 query.append(_FINDER_COLUMN_UUID_UUID_2);
587 }
588 }
589
590 if (orderByComparator != null) {
591 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
592 orderByComparator);
593 }
594
595 else {
596 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
597 }
598
599 String sql = query.toString();
600
601 Query q = session.createQuery(sql);
602
603 QueryPos qPos = QueryPos.getInstance(q);
604
605 if (uuid != null) {
606 qPos.add(uuid);
607 }
608
609 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
610 end);
611 }
612 catch (Exception e) {
613 throw processException(e);
614 }
615 finally {
616 if (list == null) {
617 list = new ArrayList<WikiNode>();
618 }
619
620 cacheResult(list);
621
622 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
623 list);
624
625 closeSession(session);
626 }
627 }
628
629 return list;
630 }
631
632
645 public WikiNode findByUuid_First(String uuid,
646 OrderByComparator orderByComparator)
647 throws NoSuchNodeException, SystemException {
648 List<WikiNode> list = findByUuid(uuid, 0, 1, orderByComparator);
649
650 if (list.isEmpty()) {
651 StringBundler msg = new StringBundler(4);
652
653 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
654
655 msg.append("uuid=");
656 msg.append(uuid);
657
658 msg.append(StringPool.CLOSE_CURLY_BRACE);
659
660 throw new NoSuchNodeException(msg.toString());
661 }
662 else {
663 return list.get(0);
664 }
665 }
666
667
680 public WikiNode findByUuid_Last(String uuid,
681 OrderByComparator orderByComparator)
682 throws NoSuchNodeException, SystemException {
683 int count = countByUuid(uuid);
684
685 List<WikiNode> list = findByUuid(uuid, count - 1, count,
686 orderByComparator);
687
688 if (list.isEmpty()) {
689 StringBundler msg = new StringBundler(4);
690
691 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
692
693 msg.append("uuid=");
694 msg.append(uuid);
695
696 msg.append(StringPool.CLOSE_CURLY_BRACE);
697
698 throw new NoSuchNodeException(msg.toString());
699 }
700 else {
701 return list.get(0);
702 }
703 }
704
705
719 public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
720 OrderByComparator orderByComparator)
721 throws NoSuchNodeException, SystemException {
722 WikiNode wikiNode = findByPrimaryKey(nodeId);
723
724 Session session = null;
725
726 try {
727 session = openSession();
728
729 WikiNode[] array = new WikiNodeImpl[3];
730
731 array[0] = getByUuid_PrevAndNext(session, wikiNode, uuid,
732 orderByComparator, true);
733
734 array[1] = wikiNode;
735
736 array[2] = getByUuid_PrevAndNext(session, wikiNode, uuid,
737 orderByComparator, false);
738
739 return array;
740 }
741 catch (Exception e) {
742 throw processException(e);
743 }
744 finally {
745 closeSession(session);
746 }
747 }
748
749 protected WikiNode getByUuid_PrevAndNext(Session session,
750 WikiNode wikiNode, String uuid, OrderByComparator orderByComparator,
751 boolean previous) {
752 StringBundler query = null;
753
754 if (orderByComparator != null) {
755 query = new StringBundler(6 +
756 (orderByComparator.getOrderByFields().length * 6));
757 }
758 else {
759 query = new StringBundler(3);
760 }
761
762 query.append(_SQL_SELECT_WIKINODE_WHERE);
763
764 if (uuid == null) {
765 query.append(_FINDER_COLUMN_UUID_UUID_1);
766 }
767 else {
768 if (uuid.equals(StringPool.BLANK)) {
769 query.append(_FINDER_COLUMN_UUID_UUID_3);
770 }
771 else {
772 query.append(_FINDER_COLUMN_UUID_UUID_2);
773 }
774 }
775
776 if (orderByComparator != null) {
777 String[] orderByFields = orderByComparator.getOrderByFields();
778
779 if (orderByFields.length > 0) {
780 query.append(WHERE_AND);
781 }
782
783 for (int i = 0; i < orderByFields.length; i++) {
784 query.append(_ORDER_BY_ENTITY_ALIAS);
785 query.append(orderByFields[i]);
786
787 if ((i + 1) < orderByFields.length) {
788 if (orderByComparator.isAscending() ^ previous) {
789 query.append(WHERE_GREATER_THAN_HAS_NEXT);
790 }
791 else {
792 query.append(WHERE_LESSER_THAN_HAS_NEXT);
793 }
794 }
795 else {
796 if (orderByComparator.isAscending() ^ previous) {
797 query.append(WHERE_GREATER_THAN);
798 }
799 else {
800 query.append(WHERE_LESSER_THAN);
801 }
802 }
803 }
804
805 query.append(ORDER_BY_CLAUSE);
806
807 for (int i = 0; i < orderByFields.length; i++) {
808 query.append(_ORDER_BY_ENTITY_ALIAS);
809 query.append(orderByFields[i]);
810
811 if ((i + 1) < orderByFields.length) {
812 if (orderByComparator.isAscending() ^ previous) {
813 query.append(ORDER_BY_ASC_HAS_NEXT);
814 }
815 else {
816 query.append(ORDER_BY_DESC_HAS_NEXT);
817 }
818 }
819 else {
820 if (orderByComparator.isAscending() ^ previous) {
821 query.append(ORDER_BY_ASC);
822 }
823 else {
824 query.append(ORDER_BY_DESC);
825 }
826 }
827 }
828 }
829
830 else {
831 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
832 }
833
834 String sql = query.toString();
835
836 Query q = session.createQuery(sql);
837
838 q.setFirstResult(0);
839 q.setMaxResults(2);
840
841 QueryPos qPos = QueryPos.getInstance(q);
842
843 if (uuid != null) {
844 qPos.add(uuid);
845 }
846
847 if (orderByComparator != null) {
848 Object[] values = orderByComparator.getOrderByValues(wikiNode);
849
850 for (Object value : values) {
851 qPos.add(value);
852 }
853 }
854
855 List<WikiNode> list = q.list();
856
857 if (list.size() == 2) {
858 return list.get(1);
859 }
860 else {
861 return null;
862 }
863 }
864
865
874 public WikiNode findByUUID_G(String uuid, long groupId)
875 throws NoSuchNodeException, SystemException {
876 WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
877
878 if (wikiNode == null) {
879 StringBundler msg = new StringBundler(6);
880
881 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
882
883 msg.append("uuid=");
884 msg.append(uuid);
885
886 msg.append(", groupId=");
887 msg.append(groupId);
888
889 msg.append(StringPool.CLOSE_CURLY_BRACE);
890
891 if (_log.isWarnEnabled()) {
892 _log.warn(msg.toString());
893 }
894
895 throw new NoSuchNodeException(msg.toString());
896 }
897
898 return wikiNode;
899 }
900
901
909 public WikiNode fetchByUUID_G(String uuid, long groupId)
910 throws SystemException {
911 return fetchByUUID_G(uuid, groupId, true);
912 }
913
914
922 public WikiNode fetchByUUID_G(String uuid, long groupId,
923 boolean retrieveFromCache) throws SystemException {
924 Object[] finderArgs = new Object[] { uuid, groupId };
925
926 Object result = null;
927
928 if (retrieveFromCache) {
929 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
930 finderArgs, this);
931 }
932
933 if (result == null) {
934 Session session = null;
935
936 try {
937 session = openSession();
938
939 StringBundler query = new StringBundler(4);
940
941 query.append(_SQL_SELECT_WIKINODE_WHERE);
942
943 if (uuid == null) {
944 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
945 }
946 else {
947 if (uuid.equals(StringPool.BLANK)) {
948 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
949 }
950 else {
951 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
952 }
953 }
954
955 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
956
957 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
958
959 String sql = query.toString();
960
961 Query q = session.createQuery(sql);
962
963 QueryPos qPos = QueryPos.getInstance(q);
964
965 if (uuid != null) {
966 qPos.add(uuid);
967 }
968
969 qPos.add(groupId);
970
971 List<WikiNode> list = q.list();
972
973 result = list;
974
975 WikiNode wikiNode = null;
976
977 if (list.isEmpty()) {
978 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
979 finderArgs, list);
980 }
981 else {
982 wikiNode = list.get(0);
983
984 cacheResult(wikiNode);
985
986 if ((wikiNode.getUuid() == null) ||
987 !wikiNode.getUuid().equals(uuid) ||
988 (wikiNode.getGroupId() != groupId)) {
989 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
990 finderArgs, wikiNode);
991 }
992 }
993
994 return wikiNode;
995 }
996 catch (Exception e) {
997 throw processException(e);
998 }
999 finally {
1000 if (result == null) {
1001 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1002 finderArgs, new ArrayList<WikiNode>());
1003 }
1004
1005 closeSession(session);
1006 }
1007 }
1008 else {
1009 if (result instanceof List<?>) {
1010 return null;
1011 }
1012 else {
1013 return (WikiNode)result;
1014 }
1015 }
1016 }
1017
1018
1025 public List<WikiNode> findByGroupId(long groupId) throws SystemException {
1026 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1027 }
1028
1029
1042 public List<WikiNode> findByGroupId(long groupId, int start, int end)
1043 throws SystemException {
1044 return findByGroupId(groupId, start, end, null);
1045 }
1046
1047
1061 public List<WikiNode> findByGroupId(long groupId, int start, int end,
1062 OrderByComparator orderByComparator) throws SystemException {
1063 Object[] finderArgs = new Object[] {
1064 groupId,
1065
1066 String.valueOf(start), String.valueOf(end),
1067 String.valueOf(orderByComparator)
1068 };
1069
1070 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1071 finderArgs, this);
1072
1073 if (list == null) {
1074 Session session = null;
1075
1076 try {
1077 session = openSession();
1078
1079 StringBundler query = null;
1080
1081 if (orderByComparator != null) {
1082 query = new StringBundler(3 +
1083 (orderByComparator.getOrderByFields().length * 3));
1084 }
1085 else {
1086 query = new StringBundler(3);
1087 }
1088
1089 query.append(_SQL_SELECT_WIKINODE_WHERE);
1090
1091 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1092
1093 if (orderByComparator != null) {
1094 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1095 orderByComparator);
1096 }
1097
1098 else {
1099 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1100 }
1101
1102 String sql = query.toString();
1103
1104 Query q = session.createQuery(sql);
1105
1106 QueryPos qPos = QueryPos.getInstance(q);
1107
1108 qPos.add(groupId);
1109
1110 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1111 end);
1112 }
1113 catch (Exception e) {
1114 throw processException(e);
1115 }
1116 finally {
1117 if (list == null) {
1118 list = new ArrayList<WikiNode>();
1119 }
1120
1121 cacheResult(list);
1122
1123 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1124 finderArgs, list);
1125
1126 closeSession(session);
1127 }
1128 }
1129
1130 return list;
1131 }
1132
1133
1146 public WikiNode findByGroupId_First(long groupId,
1147 OrderByComparator orderByComparator)
1148 throws NoSuchNodeException, SystemException {
1149 List<WikiNode> list = findByGroupId(groupId, 0, 1, orderByComparator);
1150
1151 if (list.isEmpty()) {
1152 StringBundler msg = new StringBundler(4);
1153
1154 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1155
1156 msg.append("groupId=");
1157 msg.append(groupId);
1158
1159 msg.append(StringPool.CLOSE_CURLY_BRACE);
1160
1161 throw new NoSuchNodeException(msg.toString());
1162 }
1163 else {
1164 return list.get(0);
1165 }
1166 }
1167
1168
1181 public WikiNode findByGroupId_Last(long groupId,
1182 OrderByComparator orderByComparator)
1183 throws NoSuchNodeException, SystemException {
1184 int count = countByGroupId(groupId);
1185
1186 List<WikiNode> list = findByGroupId(groupId, count - 1, count,
1187 orderByComparator);
1188
1189 if (list.isEmpty()) {
1190 StringBundler msg = new StringBundler(4);
1191
1192 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1193
1194 msg.append("groupId=");
1195 msg.append(groupId);
1196
1197 msg.append(StringPool.CLOSE_CURLY_BRACE);
1198
1199 throw new NoSuchNodeException(msg.toString());
1200 }
1201 else {
1202 return list.get(0);
1203 }
1204 }
1205
1206
1220 public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
1221 OrderByComparator orderByComparator)
1222 throws NoSuchNodeException, SystemException {
1223 WikiNode wikiNode = findByPrimaryKey(nodeId);
1224
1225 Session session = null;
1226
1227 try {
1228 session = openSession();
1229
1230 WikiNode[] array = new WikiNodeImpl[3];
1231
1232 array[0] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1233 orderByComparator, true);
1234
1235 array[1] = wikiNode;
1236
1237 array[2] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1238 orderByComparator, false);
1239
1240 return array;
1241 }
1242 catch (Exception e) {
1243 throw processException(e);
1244 }
1245 finally {
1246 closeSession(session);
1247 }
1248 }
1249
1250 protected WikiNode getByGroupId_PrevAndNext(Session session,
1251 WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1252 boolean previous) {
1253 StringBundler query = null;
1254
1255 if (orderByComparator != null) {
1256 query = new StringBundler(6 +
1257 (orderByComparator.getOrderByFields().length * 6));
1258 }
1259 else {
1260 query = new StringBundler(3);
1261 }
1262
1263 query.append(_SQL_SELECT_WIKINODE_WHERE);
1264
1265 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1266
1267 if (orderByComparator != null) {
1268 String[] orderByFields = orderByComparator.getOrderByFields();
1269
1270 if (orderByFields.length > 0) {
1271 query.append(WHERE_AND);
1272 }
1273
1274 for (int i = 0; i < orderByFields.length; i++) {
1275 query.append(_ORDER_BY_ENTITY_ALIAS);
1276 query.append(orderByFields[i]);
1277
1278 if ((i + 1) < orderByFields.length) {
1279 if (orderByComparator.isAscending() ^ previous) {
1280 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1281 }
1282 else {
1283 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1284 }
1285 }
1286 else {
1287 if (orderByComparator.isAscending() ^ previous) {
1288 query.append(WHERE_GREATER_THAN);
1289 }
1290 else {
1291 query.append(WHERE_LESSER_THAN);
1292 }
1293 }
1294 }
1295
1296 query.append(ORDER_BY_CLAUSE);
1297
1298 for (int i = 0; i < orderByFields.length; i++) {
1299 query.append(_ORDER_BY_ENTITY_ALIAS);
1300 query.append(orderByFields[i]);
1301
1302 if ((i + 1) < orderByFields.length) {
1303 if (orderByComparator.isAscending() ^ previous) {
1304 query.append(ORDER_BY_ASC_HAS_NEXT);
1305 }
1306 else {
1307 query.append(ORDER_BY_DESC_HAS_NEXT);
1308 }
1309 }
1310 else {
1311 if (orderByComparator.isAscending() ^ previous) {
1312 query.append(ORDER_BY_ASC);
1313 }
1314 else {
1315 query.append(ORDER_BY_DESC);
1316 }
1317 }
1318 }
1319 }
1320
1321 else {
1322 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1323 }
1324
1325 String sql = query.toString();
1326
1327 Query q = session.createQuery(sql);
1328
1329 q.setFirstResult(0);
1330 q.setMaxResults(2);
1331
1332 QueryPos qPos = QueryPos.getInstance(q);
1333
1334 qPos.add(groupId);
1335
1336 if (orderByComparator != null) {
1337 Object[] values = orderByComparator.getOrderByValues(wikiNode);
1338
1339 for (Object value : values) {
1340 qPos.add(value);
1341 }
1342 }
1343
1344 List<WikiNode> list = q.list();
1345
1346 if (list.size() == 2) {
1347 return list.get(1);
1348 }
1349 else {
1350 return null;
1351 }
1352 }
1353
1354
1361 public List<WikiNode> filterFindByGroupId(long groupId)
1362 throws SystemException {
1363 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1364 QueryUtil.ALL_POS, null);
1365 }
1366
1367
1380 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end)
1381 throws SystemException {
1382 return filterFindByGroupId(groupId, start, end, null);
1383 }
1384
1385
1399 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end,
1400 OrderByComparator orderByComparator) throws SystemException {
1401 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1402 return findByGroupId(groupId, start, end, orderByComparator);
1403 }
1404
1405 Session session = null;
1406
1407 try {
1408 session = openSession();
1409
1410 StringBundler query = null;
1411
1412 if (orderByComparator != null) {
1413 query = new StringBundler(3 +
1414 (orderByComparator.getOrderByFields().length * 3));
1415 }
1416 else {
1417 query = new StringBundler(3);
1418 }
1419
1420 if (getDB().isSupportsInlineDistinct()) {
1421 query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1422 }
1423 else {
1424 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE);
1425 }
1426
1427 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1428
1429 if (orderByComparator != null) {
1430 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1431 orderByComparator);
1432 }
1433
1434 else {
1435 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1436 }
1437
1438 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1439 WikiNode.class.getName(), _FILTER_COLUMN_PK,
1440 _FILTER_COLUMN_USERID, groupId);
1441
1442 SQLQuery q = session.createSQLQuery(sql);
1443
1444 q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1445
1446 QueryPos qPos = QueryPos.getInstance(q);
1447
1448 qPos.add(groupId);
1449
1450 return (List<WikiNode>)QueryUtil.list(q, getDialect(), start, end);
1451 }
1452 catch (Exception e) {
1453 throw processException(e);
1454 }
1455 finally {
1456 closeSession(session);
1457 }
1458 }
1459
1460
1467 public List<WikiNode> findByCompanyId(long companyId)
1468 throws SystemException {
1469 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1470 null);
1471 }
1472
1473
1486 public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1487 throws SystemException {
1488 return findByCompanyId(companyId, start, end, null);
1489 }
1490
1491
1505 public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1506 OrderByComparator orderByComparator) throws SystemException {
1507 Object[] finderArgs = new Object[] {
1508 companyId,
1509
1510 String.valueOf(start), String.valueOf(end),
1511 String.valueOf(orderByComparator)
1512 };
1513
1514 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1515 finderArgs, this);
1516
1517 if (list == null) {
1518 Session session = null;
1519
1520 try {
1521 session = openSession();
1522
1523 StringBundler query = null;
1524
1525 if (orderByComparator != null) {
1526 query = new StringBundler(3 +
1527 (orderByComparator.getOrderByFields().length * 3));
1528 }
1529 else {
1530 query = new StringBundler(3);
1531 }
1532
1533 query.append(_SQL_SELECT_WIKINODE_WHERE);
1534
1535 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1536
1537 if (orderByComparator != null) {
1538 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1539 orderByComparator);
1540 }
1541
1542 else {
1543 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1544 }
1545
1546 String sql = query.toString();
1547
1548 Query q = session.createQuery(sql);
1549
1550 QueryPos qPos = QueryPos.getInstance(q);
1551
1552 qPos.add(companyId);
1553
1554 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1555 end);
1556 }
1557 catch (Exception e) {
1558 throw processException(e);
1559 }
1560 finally {
1561 if (list == null) {
1562 list = new ArrayList<WikiNode>();
1563 }
1564
1565 cacheResult(list);
1566
1567 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1568 finderArgs, list);
1569
1570 closeSession(session);
1571 }
1572 }
1573
1574 return list;
1575 }
1576
1577
1590 public WikiNode findByCompanyId_First(long companyId,
1591 OrderByComparator orderByComparator)
1592 throws NoSuchNodeException, SystemException {
1593 List<WikiNode> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1594
1595 if (list.isEmpty()) {
1596 StringBundler msg = new StringBundler(4);
1597
1598 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1599
1600 msg.append("companyId=");
1601 msg.append(companyId);
1602
1603 msg.append(StringPool.CLOSE_CURLY_BRACE);
1604
1605 throw new NoSuchNodeException(msg.toString());
1606 }
1607 else {
1608 return list.get(0);
1609 }
1610 }
1611
1612
1625 public WikiNode findByCompanyId_Last(long companyId,
1626 OrderByComparator orderByComparator)
1627 throws NoSuchNodeException, SystemException {
1628 int count = countByCompanyId(companyId);
1629
1630 List<WikiNode> list = findByCompanyId(companyId, count - 1, count,
1631 orderByComparator);
1632
1633 if (list.isEmpty()) {
1634 StringBundler msg = new StringBundler(4);
1635
1636 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1637
1638 msg.append("companyId=");
1639 msg.append(companyId);
1640
1641 msg.append(StringPool.CLOSE_CURLY_BRACE);
1642
1643 throw new NoSuchNodeException(msg.toString());
1644 }
1645 else {
1646 return list.get(0);
1647 }
1648 }
1649
1650
1664 public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
1665 OrderByComparator orderByComparator)
1666 throws NoSuchNodeException, SystemException {
1667 WikiNode wikiNode = findByPrimaryKey(nodeId);
1668
1669 Session session = null;
1670
1671 try {
1672 session = openSession();
1673
1674 WikiNode[] array = new WikiNodeImpl[3];
1675
1676 array[0] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
1677 orderByComparator, true);
1678
1679 array[1] = wikiNode;
1680
1681 array[2] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
1682 orderByComparator, false);
1683
1684 return array;
1685 }
1686 catch (Exception e) {
1687 throw processException(e);
1688 }
1689 finally {
1690 closeSession(session);
1691 }
1692 }
1693
1694 protected WikiNode getByCompanyId_PrevAndNext(Session session,
1695 WikiNode wikiNode, long companyId, OrderByComparator orderByComparator,
1696 boolean previous) {
1697 StringBundler query = null;
1698
1699 if (orderByComparator != null) {
1700 query = new StringBundler(6 +
1701 (orderByComparator.getOrderByFields().length * 6));
1702 }
1703 else {
1704 query = new StringBundler(3);
1705 }
1706
1707 query.append(_SQL_SELECT_WIKINODE_WHERE);
1708
1709 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1710
1711 if (orderByComparator != null) {
1712 String[] orderByFields = orderByComparator.getOrderByFields();
1713
1714 if (orderByFields.length > 0) {
1715 query.append(WHERE_AND);
1716 }
1717
1718 for (int i = 0; i < orderByFields.length; i++) {
1719 query.append(_ORDER_BY_ENTITY_ALIAS);
1720 query.append(orderByFields[i]);
1721
1722 if ((i + 1) < orderByFields.length) {
1723 if (orderByComparator.isAscending() ^ previous) {
1724 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1725 }
1726 else {
1727 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1728 }
1729 }
1730 else {
1731 if (orderByComparator.isAscending() ^ previous) {
1732 query.append(WHERE_GREATER_THAN);
1733 }
1734 else {
1735 query.append(WHERE_LESSER_THAN);
1736 }
1737 }
1738 }
1739
1740 query.append(ORDER_BY_CLAUSE);
1741
1742 for (int i = 0; i < orderByFields.length; i++) {
1743 query.append(_ORDER_BY_ENTITY_ALIAS);
1744 query.append(orderByFields[i]);
1745
1746 if ((i + 1) < orderByFields.length) {
1747 if (orderByComparator.isAscending() ^ previous) {
1748 query.append(ORDER_BY_ASC_HAS_NEXT);
1749 }
1750 else {
1751 query.append(ORDER_BY_DESC_HAS_NEXT);
1752 }
1753 }
1754 else {
1755 if (orderByComparator.isAscending() ^ previous) {
1756 query.append(ORDER_BY_ASC);
1757 }
1758 else {
1759 query.append(ORDER_BY_DESC);
1760 }
1761 }
1762 }
1763 }
1764
1765 else {
1766 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1767 }
1768
1769 String sql = query.toString();
1770
1771 Query q = session.createQuery(sql);
1772
1773 q.setFirstResult(0);
1774 q.setMaxResults(2);
1775
1776 QueryPos qPos = QueryPos.getInstance(q);
1777
1778 qPos.add(companyId);
1779
1780 if (orderByComparator != null) {
1781 Object[] values = orderByComparator.getOrderByValues(wikiNode);
1782
1783 for (Object value : values) {
1784 qPos.add(value);
1785 }
1786 }
1787
1788 List<WikiNode> list = q.list();
1789
1790 if (list.size() == 2) {
1791 return list.get(1);
1792 }
1793 else {
1794 return null;
1795 }
1796 }
1797
1798
1807 public WikiNode findByG_N(long groupId, String name)
1808 throws NoSuchNodeException, SystemException {
1809 WikiNode wikiNode = fetchByG_N(groupId, name);
1810
1811 if (wikiNode == null) {
1812 StringBundler msg = new StringBundler(6);
1813
1814 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1815
1816 msg.append("groupId=");
1817 msg.append(groupId);
1818
1819 msg.append(", name=");
1820 msg.append(name);
1821
1822 msg.append(StringPool.CLOSE_CURLY_BRACE);
1823
1824 if (_log.isWarnEnabled()) {
1825 _log.warn(msg.toString());
1826 }
1827
1828 throw new NoSuchNodeException(msg.toString());
1829 }
1830
1831 return wikiNode;
1832 }
1833
1834
1842 public WikiNode fetchByG_N(long groupId, String name)
1843 throws SystemException {
1844 return fetchByG_N(groupId, name, true);
1845 }
1846
1847
1855 public WikiNode fetchByG_N(long groupId, String name,
1856 boolean retrieveFromCache) throws SystemException {
1857 Object[] finderArgs = new Object[] { groupId, name };
1858
1859 Object result = null;
1860
1861 if (retrieveFromCache) {
1862 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1863 finderArgs, this);
1864 }
1865
1866 if (result == null) {
1867 Session session = null;
1868
1869 try {
1870 session = openSession();
1871
1872 StringBundler query = new StringBundler(4);
1873
1874 query.append(_SQL_SELECT_WIKINODE_WHERE);
1875
1876 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1877
1878 if (name == null) {
1879 query.append(_FINDER_COLUMN_G_N_NAME_1);
1880 }
1881 else {
1882 if (name.equals(StringPool.BLANK)) {
1883 query.append(_FINDER_COLUMN_G_N_NAME_3);
1884 }
1885 else {
1886 query.append(_FINDER_COLUMN_G_N_NAME_2);
1887 }
1888 }
1889
1890 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1891
1892 String sql = query.toString();
1893
1894 Query q = session.createQuery(sql);
1895
1896 QueryPos qPos = QueryPos.getInstance(q);
1897
1898 qPos.add(groupId);
1899
1900 if (name != null) {
1901 qPos.add(name);
1902 }
1903
1904 List<WikiNode> list = q.list();
1905
1906 result = list;
1907
1908 WikiNode wikiNode = null;
1909
1910 if (list.isEmpty()) {
1911 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1912 finderArgs, list);
1913 }
1914 else {
1915 wikiNode = list.get(0);
1916
1917 cacheResult(wikiNode);
1918
1919 if ((wikiNode.getGroupId() != groupId) ||
1920 (wikiNode.getName() == null) ||
1921 !wikiNode.getName().equals(name)) {
1922 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1923 finderArgs, wikiNode);
1924 }
1925 }
1926
1927 return wikiNode;
1928 }
1929 catch (Exception e) {
1930 throw processException(e);
1931 }
1932 finally {
1933 if (result == null) {
1934 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1935 finderArgs, new ArrayList<WikiNode>());
1936 }
1937
1938 closeSession(session);
1939 }
1940 }
1941 else {
1942 if (result instanceof List<?>) {
1943 return null;
1944 }
1945 else {
1946 return (WikiNode)result;
1947 }
1948 }
1949 }
1950
1951
1957 public List<WikiNode> findAll() throws SystemException {
1958 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1959 }
1960
1961
1973 public List<WikiNode> findAll(int start, int end) throws SystemException {
1974 return findAll(start, end, null);
1975 }
1976
1977
1990 public List<WikiNode> findAll(int start, int end,
1991 OrderByComparator orderByComparator) throws SystemException {
1992 Object[] finderArgs = new Object[] {
1993 String.valueOf(start), String.valueOf(end),
1994 String.valueOf(orderByComparator)
1995 };
1996
1997 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1998 finderArgs, this);
1999
2000 if (list == null) {
2001 Session session = null;
2002
2003 try {
2004 session = openSession();
2005
2006 StringBundler query = null;
2007 String sql = null;
2008
2009 if (orderByComparator != null) {
2010 query = new StringBundler(2 +
2011 (orderByComparator.getOrderByFields().length * 3));
2012
2013 query.append(_SQL_SELECT_WIKINODE);
2014
2015 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2016 orderByComparator);
2017
2018 sql = query.toString();
2019 }
2020 else {
2021 sql = _SQL_SELECT_WIKINODE.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
2022 }
2023
2024 Query q = session.createQuery(sql);
2025
2026 if (orderByComparator == null) {
2027 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2028 start, end, false);
2029
2030 Collections.sort(list);
2031 }
2032 else {
2033 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2034 start, end);
2035 }
2036 }
2037 catch (Exception e) {
2038 throw processException(e);
2039 }
2040 finally {
2041 if (list == null) {
2042 list = new ArrayList<WikiNode>();
2043 }
2044
2045 cacheResult(list);
2046
2047 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2048
2049 closeSession(session);
2050 }
2051 }
2052
2053 return list;
2054 }
2055
2056
2062 public void removeByUuid(String uuid) throws SystemException {
2063 for (WikiNode wikiNode : findByUuid(uuid)) {
2064 remove(wikiNode);
2065 }
2066 }
2067
2068
2075 public void removeByUUID_G(String uuid, long groupId)
2076 throws NoSuchNodeException, SystemException {
2077 WikiNode wikiNode = findByUUID_G(uuid, groupId);
2078
2079 remove(wikiNode);
2080 }
2081
2082
2088 public void removeByGroupId(long groupId) throws SystemException {
2089 for (WikiNode wikiNode : findByGroupId(groupId)) {
2090 remove(wikiNode);
2091 }
2092 }
2093
2094
2100 public void removeByCompanyId(long companyId) throws SystemException {
2101 for (WikiNode wikiNode : findByCompanyId(companyId)) {
2102 remove(wikiNode);
2103 }
2104 }
2105
2106
2113 public void removeByG_N(long groupId, String name)
2114 throws NoSuchNodeException, SystemException {
2115 WikiNode wikiNode = findByG_N(groupId, name);
2116
2117 remove(wikiNode);
2118 }
2119
2120
2125 public void removeAll() throws SystemException {
2126 for (WikiNode wikiNode : findAll()) {
2127 remove(wikiNode);
2128 }
2129 }
2130
2131
2138 public int countByUuid(String uuid) throws SystemException {
2139 Object[] finderArgs = new Object[] { uuid };
2140
2141 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2142 finderArgs, this);
2143
2144 if (count == null) {
2145 Session session = null;
2146
2147 try {
2148 session = openSession();
2149
2150 StringBundler query = new StringBundler(2);
2151
2152 query.append(_SQL_COUNT_WIKINODE_WHERE);
2153
2154 if (uuid == null) {
2155 query.append(_FINDER_COLUMN_UUID_UUID_1);
2156 }
2157 else {
2158 if (uuid.equals(StringPool.BLANK)) {
2159 query.append(_FINDER_COLUMN_UUID_UUID_3);
2160 }
2161 else {
2162 query.append(_FINDER_COLUMN_UUID_UUID_2);
2163 }
2164 }
2165
2166 String sql = query.toString();
2167
2168 Query q = session.createQuery(sql);
2169
2170 QueryPos qPos = QueryPos.getInstance(q);
2171
2172 if (uuid != null) {
2173 qPos.add(uuid);
2174 }
2175
2176 count = (Long)q.uniqueResult();
2177 }
2178 catch (Exception e) {
2179 throw processException(e);
2180 }
2181 finally {
2182 if (count == null) {
2183 count = Long.valueOf(0);
2184 }
2185
2186 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2187 finderArgs, count);
2188
2189 closeSession(session);
2190 }
2191 }
2192
2193 return count.intValue();
2194 }
2195
2196
2204 public int countByUUID_G(String uuid, long groupId)
2205 throws SystemException {
2206 Object[] finderArgs = new Object[] { uuid, groupId };
2207
2208 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2209 finderArgs, this);
2210
2211 if (count == null) {
2212 Session session = null;
2213
2214 try {
2215 session = openSession();
2216
2217 StringBundler query = new StringBundler(3);
2218
2219 query.append(_SQL_COUNT_WIKINODE_WHERE);
2220
2221 if (uuid == null) {
2222 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2223 }
2224 else {
2225 if (uuid.equals(StringPool.BLANK)) {
2226 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2227 }
2228 else {
2229 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2230 }
2231 }
2232
2233 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2234
2235 String sql = query.toString();
2236
2237 Query q = session.createQuery(sql);
2238
2239 QueryPos qPos = QueryPos.getInstance(q);
2240
2241 if (uuid != null) {
2242 qPos.add(uuid);
2243 }
2244
2245 qPos.add(groupId);
2246
2247 count = (Long)q.uniqueResult();
2248 }
2249 catch (Exception e) {
2250 throw processException(e);
2251 }
2252 finally {
2253 if (count == null) {
2254 count = Long.valueOf(0);
2255 }
2256
2257 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2258 finderArgs, count);
2259
2260 closeSession(session);
2261 }
2262 }
2263
2264 return count.intValue();
2265 }
2266
2267
2274 public int countByGroupId(long groupId) throws SystemException {
2275 Object[] finderArgs = new Object[] { groupId };
2276
2277 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2278 finderArgs, this);
2279
2280 if (count == null) {
2281 Session session = null;
2282
2283 try {
2284 session = openSession();
2285
2286 StringBundler query = new StringBundler(2);
2287
2288 query.append(_SQL_COUNT_WIKINODE_WHERE);
2289
2290 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2291
2292 String sql = query.toString();
2293
2294 Query q = session.createQuery(sql);
2295
2296 QueryPos qPos = QueryPos.getInstance(q);
2297
2298 qPos.add(groupId);
2299
2300 count = (Long)q.uniqueResult();
2301 }
2302 catch (Exception e) {
2303 throw processException(e);
2304 }
2305 finally {
2306 if (count == null) {
2307 count = Long.valueOf(0);
2308 }
2309
2310 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2311 finderArgs, count);
2312
2313 closeSession(session);
2314 }
2315 }
2316
2317 return count.intValue();
2318 }
2319
2320
2327 public int filterCountByGroupId(long groupId) throws SystemException {
2328 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2329 return countByGroupId(groupId);
2330 }
2331
2332 Session session = null;
2333
2334 try {
2335 session = openSession();
2336
2337 StringBundler query = new StringBundler(2);
2338
2339 query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2340
2341 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2342
2343 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2344 WikiNode.class.getName(), _FILTER_COLUMN_PK,
2345 _FILTER_COLUMN_USERID, groupId);
2346
2347 SQLQuery q = session.createSQLQuery(sql);
2348
2349 q.addScalar(COUNT_COLUMN_NAME,
2350 com.liferay.portal.kernel.dao.orm.Type.LONG);
2351
2352 QueryPos qPos = QueryPos.getInstance(q);
2353
2354 qPos.add(groupId);
2355
2356 Long count = (Long)q.uniqueResult();
2357
2358 return count.intValue();
2359 }
2360 catch (Exception e) {
2361 throw processException(e);
2362 }
2363 finally {
2364 closeSession(session);
2365 }
2366 }
2367
2368
2375 public int countByCompanyId(long companyId) throws SystemException {
2376 Object[] finderArgs = new Object[] { companyId };
2377
2378 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2379 finderArgs, this);
2380
2381 if (count == null) {
2382 Session session = null;
2383
2384 try {
2385 session = openSession();
2386
2387 StringBundler query = new StringBundler(2);
2388
2389 query.append(_SQL_COUNT_WIKINODE_WHERE);
2390
2391 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2392
2393 String sql = query.toString();
2394
2395 Query q = session.createQuery(sql);
2396
2397 QueryPos qPos = QueryPos.getInstance(q);
2398
2399 qPos.add(companyId);
2400
2401 count = (Long)q.uniqueResult();
2402 }
2403 catch (Exception e) {
2404 throw processException(e);
2405 }
2406 finally {
2407 if (count == null) {
2408 count = Long.valueOf(0);
2409 }
2410
2411 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2412 finderArgs, count);
2413
2414 closeSession(session);
2415 }
2416 }
2417
2418 return count.intValue();
2419 }
2420
2421
2429 public int countByG_N(long groupId, String name) throws SystemException {
2430 Object[] finderArgs = new Object[] { groupId, name };
2431
2432 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
2433 finderArgs, this);
2434
2435 if (count == null) {
2436 Session session = null;
2437
2438 try {
2439 session = openSession();
2440
2441 StringBundler query = new StringBundler(3);
2442
2443 query.append(_SQL_COUNT_WIKINODE_WHERE);
2444
2445 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2446
2447 if (name == null) {
2448 query.append(_FINDER_COLUMN_G_N_NAME_1);
2449 }
2450 else {
2451 if (name.equals(StringPool.BLANK)) {
2452 query.append(_FINDER_COLUMN_G_N_NAME_3);
2453 }
2454 else {
2455 query.append(_FINDER_COLUMN_G_N_NAME_2);
2456 }
2457 }
2458
2459 String sql = query.toString();
2460
2461 Query q = session.createQuery(sql);
2462
2463 QueryPos qPos = QueryPos.getInstance(q);
2464
2465 qPos.add(groupId);
2466
2467 if (name != null) {
2468 qPos.add(name);
2469 }
2470
2471 count = (Long)q.uniqueResult();
2472 }
2473 catch (Exception e) {
2474 throw processException(e);
2475 }
2476 finally {
2477 if (count == null) {
2478 count = Long.valueOf(0);
2479 }
2480
2481 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
2482 count);
2483
2484 closeSession(session);
2485 }
2486 }
2487
2488 return count.intValue();
2489 }
2490
2491
2499 public int filterCountByG_N(long groupId, String name)
2500 throws SystemException {
2501 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2502 return countByG_N(groupId, name);
2503 }
2504
2505 Session session = null;
2506
2507 try {
2508 session = openSession();
2509
2510 StringBundler query = new StringBundler(3);
2511
2512 query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2513
2514 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2515
2516 if (name == null) {
2517 query.append(_FINDER_COLUMN_G_N_NAME_1);
2518 }
2519 else {
2520 if (name.equals(StringPool.BLANK)) {
2521 query.append(_FINDER_COLUMN_G_N_NAME_3);
2522 }
2523 else {
2524 query.append(_FINDER_COLUMN_G_N_NAME_2);
2525 }
2526 }
2527
2528 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2529 WikiNode.class.getName(), _FILTER_COLUMN_PK,
2530 _FILTER_COLUMN_USERID, groupId);
2531
2532 SQLQuery q = session.createSQLQuery(sql);
2533
2534 q.addScalar(COUNT_COLUMN_NAME,
2535 com.liferay.portal.kernel.dao.orm.Type.LONG);
2536
2537 QueryPos qPos = QueryPos.getInstance(q);
2538
2539 qPos.add(groupId);
2540
2541 if (name != null) {
2542 qPos.add(name);
2543 }
2544
2545 Long count = (Long)q.uniqueResult();
2546
2547 return count.intValue();
2548 }
2549 catch (Exception e) {
2550 throw processException(e);
2551 }
2552 finally {
2553 closeSession(session);
2554 }
2555 }
2556
2557
2563 public int countAll() throws SystemException {
2564 Object[] finderArgs = new Object[0];
2565
2566 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2567 finderArgs, this);
2568
2569 if (count == null) {
2570 Session session = null;
2571
2572 try {
2573 session = openSession();
2574
2575 Query q = session.createQuery(_SQL_COUNT_WIKINODE);
2576
2577 count = (Long)q.uniqueResult();
2578 }
2579 catch (Exception e) {
2580 throw processException(e);
2581 }
2582 finally {
2583 if (count == null) {
2584 count = Long.valueOf(0);
2585 }
2586
2587 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2588 count);
2589
2590 closeSession(session);
2591 }
2592 }
2593
2594 return count.intValue();
2595 }
2596
2597
2600 public void afterPropertiesSet() {
2601 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2602 com.liferay.portal.util.PropsUtil.get(
2603 "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
2604
2605 if (listenerClassNames.length > 0) {
2606 try {
2607 List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
2608
2609 for (String listenerClassName : listenerClassNames) {
2610 listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
2611 listenerClassName));
2612 }
2613
2614 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2615 }
2616 catch (Exception e) {
2617 _log.error(e);
2618 }
2619 }
2620 }
2621
2622 public void destroy() {
2623 EntityCacheUtil.removeCache(WikiNodeImpl.class.getName());
2624 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2625 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2626 }
2627
2628 @BeanReference(type = WikiNodePersistence.class)
2629 protected WikiNodePersistence wikiNodePersistence;
2630 @BeanReference(type = WikiPagePersistence.class)
2631 protected WikiPagePersistence wikiPagePersistence;
2632 @BeanReference(type = WikiPageResourcePersistence.class)
2633 protected WikiPageResourcePersistence wikiPageResourcePersistence;
2634 @BeanReference(type = GroupPersistence.class)
2635 protected GroupPersistence groupPersistence;
2636 @BeanReference(type = ResourcePersistence.class)
2637 protected ResourcePersistence resourcePersistence;
2638 @BeanReference(type = SubscriptionPersistence.class)
2639 protected SubscriptionPersistence subscriptionPersistence;
2640 @BeanReference(type = UserPersistence.class)
2641 protected UserPersistence userPersistence;
2642 private static final String _SQL_SELECT_WIKINODE = "SELECT wikiNode FROM WikiNode wikiNode";
2643 private static final String _SQL_SELECT_WIKINODE_WHERE = "SELECT wikiNode FROM WikiNode wikiNode WHERE ";
2644 private static final String _SQL_COUNT_WIKINODE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode";
2645 private static final String _SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode WHERE ";
2646 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiNode.uuid IS NULL";
2647 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiNode.uuid = ?";
2648 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?)";
2649 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiNode.uuid IS NULL AND ";
2650 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiNode.uuid = ? AND ";
2651 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?) AND ";
2652 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiNode.groupId = ?";
2653 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "wikiNode.groupId = ?";
2654 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "wikiNode.companyId = ?";
2655 private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "wikiNode.groupId = ? AND ";
2656 private static final String _FINDER_COLUMN_G_N_NAME_1 = "wikiNode.name IS NULL";
2657 private static final String _FINDER_COLUMN_G_N_NAME_2 = "wikiNode.name = ?";
2658 private static final String _FINDER_COLUMN_G_N_NAME_3 = "(wikiNode.name IS NULL OR wikiNode.name = ?)";
2659 private static final String _FILTER_SQL_SELECT_WIKINODE_WHERE = "SELECT DISTINCT {wikiNode.*} FROM WikiNode wikiNode WHERE ";
2660 private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE =
2661 "SELECT {wikiNode.*} FROM (SELECT DISTINCT nodeId FROM WikiNode) wikiNode2 INNER JOIN WikiNode wikiNode ON (wikiNode2.nodeId = wikiNode.nodeId) WHERE ";
2662 private static final String _FILTER_SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(DISTINCT wikiNode.nodeId) AS COUNT_VALUE FROM WikiNode wikiNode WHERE ";
2663 private static final String _FILTER_COLUMN_PK = "wikiNode.nodeId";
2664 private static final String _FILTER_COLUMN_USERID = "wikiNode.userId";
2665 private static final String _FILTER_ENTITY_ALIAS = "wikiNode";
2666 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
2667 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
2668 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
2669 private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
2670 }