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 if (wikiNode.isCachedModel() || BatchSessionUtil.isEnabled()) {
285 Object staleObject = session.get(WikiNodeImpl.class,
286 wikiNode.getPrimaryKeyObj());
287
288 if (staleObject != null) {
289 session.evict(staleObject);
290 }
291 }
292
293 session.delete(wikiNode);
294
295 session.flush();
296 }
297 catch (Exception e) {
298 throw processException(e);
299 }
300 finally {
301 closeSession(session);
302 }
303
304 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
305
306 WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
307
308 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
309 new Object[] {
310 wikiNodeModelImpl.getOriginalUuid(),
311 new Long(wikiNodeModelImpl.getOriginalGroupId())
312 });
313
314 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
315 new Object[] {
316 new Long(wikiNodeModelImpl.getOriginalGroupId()),
317
318 wikiNodeModelImpl.getOriginalName()
319 });
320
321 EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
322 WikiNodeImpl.class, wikiNode.getPrimaryKey());
323
324 return wikiNode;
325 }
326
327 public WikiNode updateImpl(
328 com.liferay.portlet.wiki.model.WikiNode wikiNode, boolean merge)
329 throws SystemException {
330 wikiNode = toUnwrappedModel(wikiNode);
331
332 boolean isNew = wikiNode.isNew();
333
334 WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
335
336 if (Validator.isNull(wikiNode.getUuid())) {
337 String uuid = PortalUUIDUtil.generate();
338
339 wikiNode.setUuid(uuid);
340 }
341
342 Session session = null;
343
344 try {
345 session = openSession();
346
347 BatchSessionUtil.update(session, wikiNode, merge);
348
349 wikiNode.setNew(false);
350 }
351 catch (Exception e) {
352 throw processException(e);
353 }
354 finally {
355 closeSession(session);
356 }
357
358 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
359
360 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
361 WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
362
363 if (!isNew &&
364 (!Validator.equals(wikiNode.getUuid(),
365 wikiNodeModelImpl.getOriginalUuid()) ||
366 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
367 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
368 new Object[] {
369 wikiNodeModelImpl.getOriginalUuid(),
370 new Long(wikiNodeModelImpl.getOriginalGroupId())
371 });
372 }
373
374 if (isNew ||
375 (!Validator.equals(wikiNode.getUuid(),
376 wikiNodeModelImpl.getOriginalUuid()) ||
377 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
378 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
379 new Object[] { wikiNode.getUuid(), new Long(
380 wikiNode.getGroupId()) }, wikiNode);
381 }
382
383 if (!isNew &&
384 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
385 !Validator.equals(wikiNode.getName(),
386 wikiNodeModelImpl.getOriginalName()))) {
387 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
388 new Object[] {
389 new Long(wikiNodeModelImpl.getOriginalGroupId()),
390
391 wikiNodeModelImpl.getOriginalName()
392 });
393 }
394
395 if (isNew ||
396 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
397 !Validator.equals(wikiNode.getName(),
398 wikiNodeModelImpl.getOriginalName()))) {
399 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
400 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
401 wikiNode);
402 }
403
404 return wikiNode;
405 }
406
407 protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
408 if (wikiNode instanceof WikiNodeImpl) {
409 return wikiNode;
410 }
411
412 WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
413
414 wikiNodeImpl.setNew(wikiNode.isNew());
415 wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
416
417 wikiNodeImpl.setUuid(wikiNode.getUuid());
418 wikiNodeImpl.setNodeId(wikiNode.getNodeId());
419 wikiNodeImpl.setGroupId(wikiNode.getGroupId());
420 wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
421 wikiNodeImpl.setUserId(wikiNode.getUserId());
422 wikiNodeImpl.setUserName(wikiNode.getUserName());
423 wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
424 wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
425 wikiNodeImpl.setName(wikiNode.getName());
426 wikiNodeImpl.setDescription(wikiNode.getDescription());
427 wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
428
429 return wikiNodeImpl;
430 }
431
432
440 public WikiNode findByPrimaryKey(Serializable primaryKey)
441 throws NoSuchModelException, SystemException {
442 return findByPrimaryKey(((Long)primaryKey).longValue());
443 }
444
445
453 public WikiNode findByPrimaryKey(long nodeId)
454 throws NoSuchNodeException, SystemException {
455 WikiNode wikiNode = fetchByPrimaryKey(nodeId);
456
457 if (wikiNode == null) {
458 if (_log.isWarnEnabled()) {
459 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
460 }
461
462 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
463 nodeId);
464 }
465
466 return wikiNode;
467 }
468
469
476 public WikiNode fetchByPrimaryKey(Serializable primaryKey)
477 throws SystemException {
478 return fetchByPrimaryKey(((Long)primaryKey).longValue());
479 }
480
481
488 public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
489 WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
490 WikiNodeImpl.class, nodeId, this);
491
492 if (wikiNode == null) {
493 Session session = null;
494
495 try {
496 session = openSession();
497
498 wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
499 new Long(nodeId));
500 }
501 catch (Exception e) {
502 throw processException(e);
503 }
504 finally {
505 if (wikiNode != null) {
506 cacheResult(wikiNode);
507 }
508
509 closeSession(session);
510 }
511 }
512
513 return wikiNode;
514 }
515
516
523 public List<WikiNode> findByUuid(String uuid) throws SystemException {
524 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
525 }
526
527
540 public List<WikiNode> findByUuid(String uuid, int start, int end)
541 throws SystemException {
542 return findByUuid(uuid, start, end, null);
543 }
544
545
559 public List<WikiNode> findByUuid(String uuid, int start, int end,
560 OrderByComparator orderByComparator) throws SystemException {
561 Object[] finderArgs = new Object[] {
562 uuid,
563
564 String.valueOf(start), String.valueOf(end),
565 String.valueOf(orderByComparator)
566 };
567
568 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
569 finderArgs, this);
570
571 if (list == null) {
572 Session session = null;
573
574 try {
575 session = openSession();
576
577 StringBundler query = null;
578
579 if (orderByComparator != null) {
580 query = new StringBundler(3 +
581 (orderByComparator.getOrderByFields().length * 3));
582 }
583 else {
584 query = new StringBundler(3);
585 }
586
587 query.append(_SQL_SELECT_WIKINODE_WHERE);
588
589 if (uuid == null) {
590 query.append(_FINDER_COLUMN_UUID_UUID_1);
591 }
592 else {
593 if (uuid.equals(StringPool.BLANK)) {
594 query.append(_FINDER_COLUMN_UUID_UUID_3);
595 }
596 else {
597 query.append(_FINDER_COLUMN_UUID_UUID_2);
598 }
599 }
600
601 if (orderByComparator != null) {
602 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
603 orderByComparator);
604 }
605
606 else {
607 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
608 }
609
610 String sql = query.toString();
611
612 Query q = session.createQuery(sql);
613
614 QueryPos qPos = QueryPos.getInstance(q);
615
616 if (uuid != null) {
617 qPos.add(uuid);
618 }
619
620 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
621 end);
622 }
623 catch (Exception e) {
624 throw processException(e);
625 }
626 finally {
627 if (list == null) {
628 list = new ArrayList<WikiNode>();
629 }
630
631 cacheResult(list);
632
633 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
634 list);
635
636 closeSession(session);
637 }
638 }
639
640 return list;
641 }
642
643
656 public WikiNode findByUuid_First(String uuid,
657 OrderByComparator orderByComparator)
658 throws NoSuchNodeException, SystemException {
659 List<WikiNode> list = findByUuid(uuid, 0, 1, orderByComparator);
660
661 if (list.isEmpty()) {
662 StringBundler msg = new StringBundler(4);
663
664 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
665
666 msg.append("uuid=");
667 msg.append(uuid);
668
669 msg.append(StringPool.CLOSE_CURLY_BRACE);
670
671 throw new NoSuchNodeException(msg.toString());
672 }
673 else {
674 return list.get(0);
675 }
676 }
677
678
691 public WikiNode findByUuid_Last(String uuid,
692 OrderByComparator orderByComparator)
693 throws NoSuchNodeException, SystemException {
694 int count = countByUuid(uuid);
695
696 List<WikiNode> list = findByUuid(uuid, count - 1, count,
697 orderByComparator);
698
699 if (list.isEmpty()) {
700 StringBundler msg = new StringBundler(4);
701
702 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
703
704 msg.append("uuid=");
705 msg.append(uuid);
706
707 msg.append(StringPool.CLOSE_CURLY_BRACE);
708
709 throw new NoSuchNodeException(msg.toString());
710 }
711 else {
712 return list.get(0);
713 }
714 }
715
716
730 public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
731 OrderByComparator orderByComparator)
732 throws NoSuchNodeException, SystemException {
733 WikiNode wikiNode = findByPrimaryKey(nodeId);
734
735 Session session = null;
736
737 try {
738 session = openSession();
739
740 WikiNode[] array = new WikiNodeImpl[3];
741
742 array[0] = getByUuid_PrevAndNext(session, wikiNode, uuid,
743 orderByComparator, true);
744
745 array[1] = wikiNode;
746
747 array[2] = getByUuid_PrevAndNext(session, wikiNode, uuid,
748 orderByComparator, false);
749
750 return array;
751 }
752 catch (Exception e) {
753 throw processException(e);
754 }
755 finally {
756 closeSession(session);
757 }
758 }
759
760 protected WikiNode getByUuid_PrevAndNext(Session session,
761 WikiNode wikiNode, String uuid, OrderByComparator orderByComparator,
762 boolean previous) {
763 StringBundler query = null;
764
765 if (orderByComparator != null) {
766 query = new StringBundler(6 +
767 (orderByComparator.getOrderByFields().length * 6));
768 }
769 else {
770 query = new StringBundler(3);
771 }
772
773 query.append(_SQL_SELECT_WIKINODE_WHERE);
774
775 if (uuid == null) {
776 query.append(_FINDER_COLUMN_UUID_UUID_1);
777 }
778 else {
779 if (uuid.equals(StringPool.BLANK)) {
780 query.append(_FINDER_COLUMN_UUID_UUID_3);
781 }
782 else {
783 query.append(_FINDER_COLUMN_UUID_UUID_2);
784 }
785 }
786
787 if (orderByComparator != null) {
788 String[] orderByFields = orderByComparator.getOrderByFields();
789
790 if (orderByFields.length > 0) {
791 query.append(WHERE_AND);
792 }
793
794 for (int i = 0; i < orderByFields.length; i++) {
795 query.append(_ORDER_BY_ENTITY_ALIAS);
796 query.append(orderByFields[i]);
797
798 if ((i + 1) < orderByFields.length) {
799 if (orderByComparator.isAscending() ^ previous) {
800 query.append(WHERE_GREATER_THAN_HAS_NEXT);
801 }
802 else {
803 query.append(WHERE_LESSER_THAN_HAS_NEXT);
804 }
805 }
806 else {
807 if (orderByComparator.isAscending() ^ previous) {
808 query.append(WHERE_GREATER_THAN);
809 }
810 else {
811 query.append(WHERE_LESSER_THAN);
812 }
813 }
814 }
815
816 query.append(ORDER_BY_CLAUSE);
817
818 for (int i = 0; i < orderByFields.length; i++) {
819 query.append(_ORDER_BY_ENTITY_ALIAS);
820 query.append(orderByFields[i]);
821
822 if ((i + 1) < orderByFields.length) {
823 if (orderByComparator.isAscending() ^ previous) {
824 query.append(ORDER_BY_ASC_HAS_NEXT);
825 }
826 else {
827 query.append(ORDER_BY_DESC_HAS_NEXT);
828 }
829 }
830 else {
831 if (orderByComparator.isAscending() ^ previous) {
832 query.append(ORDER_BY_ASC);
833 }
834 else {
835 query.append(ORDER_BY_DESC);
836 }
837 }
838 }
839 }
840
841 else {
842 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
843 }
844
845 String sql = query.toString();
846
847 Query q = session.createQuery(sql);
848
849 q.setFirstResult(0);
850 q.setMaxResults(2);
851
852 QueryPos qPos = QueryPos.getInstance(q);
853
854 if (uuid != null) {
855 qPos.add(uuid);
856 }
857
858 if (orderByComparator != null) {
859 Object[] values = orderByComparator.getOrderByValues(wikiNode);
860
861 for (Object value : values) {
862 qPos.add(value);
863 }
864 }
865
866 List<WikiNode> list = q.list();
867
868 if (list.size() == 2) {
869 return list.get(1);
870 }
871 else {
872 return null;
873 }
874 }
875
876
885 public WikiNode findByUUID_G(String uuid, long groupId)
886 throws NoSuchNodeException, SystemException {
887 WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
888
889 if (wikiNode == null) {
890 StringBundler msg = new StringBundler(6);
891
892 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
893
894 msg.append("uuid=");
895 msg.append(uuid);
896
897 msg.append(", groupId=");
898 msg.append(groupId);
899
900 msg.append(StringPool.CLOSE_CURLY_BRACE);
901
902 if (_log.isWarnEnabled()) {
903 _log.warn(msg.toString());
904 }
905
906 throw new NoSuchNodeException(msg.toString());
907 }
908
909 return wikiNode;
910 }
911
912
920 public WikiNode fetchByUUID_G(String uuid, long groupId)
921 throws SystemException {
922 return fetchByUUID_G(uuid, groupId, true);
923 }
924
925
933 public WikiNode fetchByUUID_G(String uuid, long groupId,
934 boolean retrieveFromCache) throws SystemException {
935 Object[] finderArgs = new Object[] { uuid, groupId };
936
937 Object result = null;
938
939 if (retrieveFromCache) {
940 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
941 finderArgs, this);
942 }
943
944 if (result == null) {
945 Session session = null;
946
947 try {
948 session = openSession();
949
950 StringBundler query = new StringBundler(4);
951
952 query.append(_SQL_SELECT_WIKINODE_WHERE);
953
954 if (uuid == null) {
955 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
956 }
957 else {
958 if (uuid.equals(StringPool.BLANK)) {
959 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
960 }
961 else {
962 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
963 }
964 }
965
966 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
967
968 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
969
970 String sql = query.toString();
971
972 Query q = session.createQuery(sql);
973
974 QueryPos qPos = QueryPos.getInstance(q);
975
976 if (uuid != null) {
977 qPos.add(uuid);
978 }
979
980 qPos.add(groupId);
981
982 List<WikiNode> list = q.list();
983
984 result = list;
985
986 WikiNode wikiNode = null;
987
988 if (list.isEmpty()) {
989 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
990 finderArgs, list);
991 }
992 else {
993 wikiNode = list.get(0);
994
995 cacheResult(wikiNode);
996
997 if ((wikiNode.getUuid() == null) ||
998 !wikiNode.getUuid().equals(uuid) ||
999 (wikiNode.getGroupId() != groupId)) {
1000 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1001 finderArgs, wikiNode);
1002 }
1003 }
1004
1005 return wikiNode;
1006 }
1007 catch (Exception e) {
1008 throw processException(e);
1009 }
1010 finally {
1011 if (result == null) {
1012 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1013 finderArgs, new ArrayList<WikiNode>());
1014 }
1015
1016 closeSession(session);
1017 }
1018 }
1019 else {
1020 if (result instanceof List<?>) {
1021 return null;
1022 }
1023 else {
1024 return (WikiNode)result;
1025 }
1026 }
1027 }
1028
1029
1036 public List<WikiNode> findByGroupId(long groupId) throws SystemException {
1037 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1038 }
1039
1040
1053 public List<WikiNode> findByGroupId(long groupId, int start, int end)
1054 throws SystemException {
1055 return findByGroupId(groupId, start, end, null);
1056 }
1057
1058
1072 public List<WikiNode> findByGroupId(long groupId, int start, int end,
1073 OrderByComparator orderByComparator) throws SystemException {
1074 Object[] finderArgs = new Object[] {
1075 groupId,
1076
1077 String.valueOf(start), String.valueOf(end),
1078 String.valueOf(orderByComparator)
1079 };
1080
1081 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1082 finderArgs, this);
1083
1084 if (list == null) {
1085 Session session = null;
1086
1087 try {
1088 session = openSession();
1089
1090 StringBundler query = null;
1091
1092 if (orderByComparator != null) {
1093 query = new StringBundler(3 +
1094 (orderByComparator.getOrderByFields().length * 3));
1095 }
1096 else {
1097 query = new StringBundler(3);
1098 }
1099
1100 query.append(_SQL_SELECT_WIKINODE_WHERE);
1101
1102 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1103
1104 if (orderByComparator != null) {
1105 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1106 orderByComparator);
1107 }
1108
1109 else {
1110 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1111 }
1112
1113 String sql = query.toString();
1114
1115 Query q = session.createQuery(sql);
1116
1117 QueryPos qPos = QueryPos.getInstance(q);
1118
1119 qPos.add(groupId);
1120
1121 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1122 end);
1123 }
1124 catch (Exception e) {
1125 throw processException(e);
1126 }
1127 finally {
1128 if (list == null) {
1129 list = new ArrayList<WikiNode>();
1130 }
1131
1132 cacheResult(list);
1133
1134 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1135 finderArgs, list);
1136
1137 closeSession(session);
1138 }
1139 }
1140
1141 return list;
1142 }
1143
1144
1157 public WikiNode findByGroupId_First(long groupId,
1158 OrderByComparator orderByComparator)
1159 throws NoSuchNodeException, SystemException {
1160 List<WikiNode> list = findByGroupId(groupId, 0, 1, orderByComparator);
1161
1162 if (list.isEmpty()) {
1163 StringBundler msg = new StringBundler(4);
1164
1165 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1166
1167 msg.append("groupId=");
1168 msg.append(groupId);
1169
1170 msg.append(StringPool.CLOSE_CURLY_BRACE);
1171
1172 throw new NoSuchNodeException(msg.toString());
1173 }
1174 else {
1175 return list.get(0);
1176 }
1177 }
1178
1179
1192 public WikiNode findByGroupId_Last(long groupId,
1193 OrderByComparator orderByComparator)
1194 throws NoSuchNodeException, SystemException {
1195 int count = countByGroupId(groupId);
1196
1197 List<WikiNode> list = findByGroupId(groupId, count - 1, count,
1198 orderByComparator);
1199
1200 if (list.isEmpty()) {
1201 StringBundler msg = new StringBundler(4);
1202
1203 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1204
1205 msg.append("groupId=");
1206 msg.append(groupId);
1207
1208 msg.append(StringPool.CLOSE_CURLY_BRACE);
1209
1210 throw new NoSuchNodeException(msg.toString());
1211 }
1212 else {
1213 return list.get(0);
1214 }
1215 }
1216
1217
1231 public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
1232 OrderByComparator orderByComparator)
1233 throws NoSuchNodeException, SystemException {
1234 WikiNode wikiNode = findByPrimaryKey(nodeId);
1235
1236 Session session = null;
1237
1238 try {
1239 session = openSession();
1240
1241 WikiNode[] array = new WikiNodeImpl[3];
1242
1243 array[0] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1244 orderByComparator, true);
1245
1246 array[1] = wikiNode;
1247
1248 array[2] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1249 orderByComparator, false);
1250
1251 return array;
1252 }
1253 catch (Exception e) {
1254 throw processException(e);
1255 }
1256 finally {
1257 closeSession(session);
1258 }
1259 }
1260
1261 protected WikiNode getByGroupId_PrevAndNext(Session session,
1262 WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1263 boolean previous) {
1264 StringBundler query = null;
1265
1266 if (orderByComparator != null) {
1267 query = new StringBundler(6 +
1268 (orderByComparator.getOrderByFields().length * 6));
1269 }
1270 else {
1271 query = new StringBundler(3);
1272 }
1273
1274 query.append(_SQL_SELECT_WIKINODE_WHERE);
1275
1276 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1277
1278 if (orderByComparator != null) {
1279 String[] orderByFields = orderByComparator.getOrderByFields();
1280
1281 if (orderByFields.length > 0) {
1282 query.append(WHERE_AND);
1283 }
1284
1285 for (int i = 0; i < orderByFields.length; i++) {
1286 query.append(_ORDER_BY_ENTITY_ALIAS);
1287 query.append(orderByFields[i]);
1288
1289 if ((i + 1) < orderByFields.length) {
1290 if (orderByComparator.isAscending() ^ previous) {
1291 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1292 }
1293 else {
1294 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1295 }
1296 }
1297 else {
1298 if (orderByComparator.isAscending() ^ previous) {
1299 query.append(WHERE_GREATER_THAN);
1300 }
1301 else {
1302 query.append(WHERE_LESSER_THAN);
1303 }
1304 }
1305 }
1306
1307 query.append(ORDER_BY_CLAUSE);
1308
1309 for (int i = 0; i < orderByFields.length; i++) {
1310 query.append(_ORDER_BY_ENTITY_ALIAS);
1311 query.append(orderByFields[i]);
1312
1313 if ((i + 1) < orderByFields.length) {
1314 if (orderByComparator.isAscending() ^ previous) {
1315 query.append(ORDER_BY_ASC_HAS_NEXT);
1316 }
1317 else {
1318 query.append(ORDER_BY_DESC_HAS_NEXT);
1319 }
1320 }
1321 else {
1322 if (orderByComparator.isAscending() ^ previous) {
1323 query.append(ORDER_BY_ASC);
1324 }
1325 else {
1326 query.append(ORDER_BY_DESC);
1327 }
1328 }
1329 }
1330 }
1331
1332 else {
1333 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1334 }
1335
1336 String sql = query.toString();
1337
1338 Query q = session.createQuery(sql);
1339
1340 q.setFirstResult(0);
1341 q.setMaxResults(2);
1342
1343 QueryPos qPos = QueryPos.getInstance(q);
1344
1345 qPos.add(groupId);
1346
1347 if (orderByComparator != null) {
1348 Object[] values = orderByComparator.getOrderByValues(wikiNode);
1349
1350 for (Object value : values) {
1351 qPos.add(value);
1352 }
1353 }
1354
1355 List<WikiNode> list = q.list();
1356
1357 if (list.size() == 2) {
1358 return list.get(1);
1359 }
1360 else {
1361 return null;
1362 }
1363 }
1364
1365
1372 public List<WikiNode> filterFindByGroupId(long groupId)
1373 throws SystemException {
1374 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1375 QueryUtil.ALL_POS, null);
1376 }
1377
1378
1391 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end)
1392 throws SystemException {
1393 return filterFindByGroupId(groupId, start, end, null);
1394 }
1395
1396
1410 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end,
1411 OrderByComparator orderByComparator) throws SystemException {
1412 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1413 return findByGroupId(groupId, start, end, orderByComparator);
1414 }
1415
1416 Session session = null;
1417
1418 try {
1419 session = openSession();
1420
1421 StringBundler query = null;
1422
1423 if (orderByComparator != null) {
1424 query = new StringBundler(3 +
1425 (orderByComparator.getOrderByFields().length * 3));
1426 }
1427 else {
1428 query = new StringBundler(3);
1429 }
1430
1431 query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1432
1433 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1434
1435 if (orderByComparator != null) {
1436 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1437 orderByComparator);
1438 }
1439
1440 else {
1441 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1442 }
1443
1444 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1445 WikiNode.class.getName(), _FILTER_COLUMN_PK,
1446 _FILTER_COLUMN_USERID, groupId);
1447
1448 SQLQuery q = session.createSQLQuery(sql);
1449
1450 q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1451
1452 QueryPos qPos = QueryPos.getInstance(q);
1453
1454 qPos.add(groupId);
1455
1456 return (List<WikiNode>)QueryUtil.list(q, getDialect(), start, end);
1457 }
1458 catch (Exception e) {
1459 throw processException(e);
1460 }
1461 finally {
1462 closeSession(session);
1463 }
1464 }
1465
1466
1473 public List<WikiNode> findByCompanyId(long companyId)
1474 throws SystemException {
1475 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1476 null);
1477 }
1478
1479
1492 public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1493 throws SystemException {
1494 return findByCompanyId(companyId, start, end, null);
1495 }
1496
1497
1511 public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1512 OrderByComparator orderByComparator) throws SystemException {
1513 Object[] finderArgs = new Object[] {
1514 companyId,
1515
1516 String.valueOf(start), String.valueOf(end),
1517 String.valueOf(orderByComparator)
1518 };
1519
1520 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1521 finderArgs, this);
1522
1523 if (list == null) {
1524 Session session = null;
1525
1526 try {
1527 session = openSession();
1528
1529 StringBundler query = null;
1530
1531 if (orderByComparator != null) {
1532 query = new StringBundler(3 +
1533 (orderByComparator.getOrderByFields().length * 3));
1534 }
1535 else {
1536 query = new StringBundler(3);
1537 }
1538
1539 query.append(_SQL_SELECT_WIKINODE_WHERE);
1540
1541 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1542
1543 if (orderByComparator != null) {
1544 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1545 orderByComparator);
1546 }
1547
1548 else {
1549 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1550 }
1551
1552 String sql = query.toString();
1553
1554 Query q = session.createQuery(sql);
1555
1556 QueryPos qPos = QueryPos.getInstance(q);
1557
1558 qPos.add(companyId);
1559
1560 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1561 end);
1562 }
1563 catch (Exception e) {
1564 throw processException(e);
1565 }
1566 finally {
1567 if (list == null) {
1568 list = new ArrayList<WikiNode>();
1569 }
1570
1571 cacheResult(list);
1572
1573 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1574 finderArgs, list);
1575
1576 closeSession(session);
1577 }
1578 }
1579
1580 return list;
1581 }
1582
1583
1596 public WikiNode findByCompanyId_First(long companyId,
1597 OrderByComparator orderByComparator)
1598 throws NoSuchNodeException, SystemException {
1599 List<WikiNode> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1600
1601 if (list.isEmpty()) {
1602 StringBundler msg = new StringBundler(4);
1603
1604 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1605
1606 msg.append("companyId=");
1607 msg.append(companyId);
1608
1609 msg.append(StringPool.CLOSE_CURLY_BRACE);
1610
1611 throw new NoSuchNodeException(msg.toString());
1612 }
1613 else {
1614 return list.get(0);
1615 }
1616 }
1617
1618
1631 public WikiNode findByCompanyId_Last(long companyId,
1632 OrderByComparator orderByComparator)
1633 throws NoSuchNodeException, SystemException {
1634 int count = countByCompanyId(companyId);
1635
1636 List<WikiNode> list = findByCompanyId(companyId, count - 1, count,
1637 orderByComparator);
1638
1639 if (list.isEmpty()) {
1640 StringBundler msg = new StringBundler(4);
1641
1642 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1643
1644 msg.append("companyId=");
1645 msg.append(companyId);
1646
1647 msg.append(StringPool.CLOSE_CURLY_BRACE);
1648
1649 throw new NoSuchNodeException(msg.toString());
1650 }
1651 else {
1652 return list.get(0);
1653 }
1654 }
1655
1656
1670 public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
1671 OrderByComparator orderByComparator)
1672 throws NoSuchNodeException, SystemException {
1673 WikiNode wikiNode = findByPrimaryKey(nodeId);
1674
1675 Session session = null;
1676
1677 try {
1678 session = openSession();
1679
1680 WikiNode[] array = new WikiNodeImpl[3];
1681
1682 array[0] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
1683 orderByComparator, true);
1684
1685 array[1] = wikiNode;
1686
1687 array[2] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
1688 orderByComparator, false);
1689
1690 return array;
1691 }
1692 catch (Exception e) {
1693 throw processException(e);
1694 }
1695 finally {
1696 closeSession(session);
1697 }
1698 }
1699
1700 protected WikiNode getByCompanyId_PrevAndNext(Session session,
1701 WikiNode wikiNode, long companyId, OrderByComparator orderByComparator,
1702 boolean previous) {
1703 StringBundler query = null;
1704
1705 if (orderByComparator != null) {
1706 query = new StringBundler(6 +
1707 (orderByComparator.getOrderByFields().length * 6));
1708 }
1709 else {
1710 query = new StringBundler(3);
1711 }
1712
1713 query.append(_SQL_SELECT_WIKINODE_WHERE);
1714
1715 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1716
1717 if (orderByComparator != null) {
1718 String[] orderByFields = orderByComparator.getOrderByFields();
1719
1720 if (orderByFields.length > 0) {
1721 query.append(WHERE_AND);
1722 }
1723
1724 for (int i = 0; i < orderByFields.length; i++) {
1725 query.append(_ORDER_BY_ENTITY_ALIAS);
1726 query.append(orderByFields[i]);
1727
1728 if ((i + 1) < orderByFields.length) {
1729 if (orderByComparator.isAscending() ^ previous) {
1730 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1731 }
1732 else {
1733 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1734 }
1735 }
1736 else {
1737 if (orderByComparator.isAscending() ^ previous) {
1738 query.append(WHERE_GREATER_THAN);
1739 }
1740 else {
1741 query.append(WHERE_LESSER_THAN);
1742 }
1743 }
1744 }
1745
1746 query.append(ORDER_BY_CLAUSE);
1747
1748 for (int i = 0; i < orderByFields.length; i++) {
1749 query.append(_ORDER_BY_ENTITY_ALIAS);
1750 query.append(orderByFields[i]);
1751
1752 if ((i + 1) < orderByFields.length) {
1753 if (orderByComparator.isAscending() ^ previous) {
1754 query.append(ORDER_BY_ASC_HAS_NEXT);
1755 }
1756 else {
1757 query.append(ORDER_BY_DESC_HAS_NEXT);
1758 }
1759 }
1760 else {
1761 if (orderByComparator.isAscending() ^ previous) {
1762 query.append(ORDER_BY_ASC);
1763 }
1764 else {
1765 query.append(ORDER_BY_DESC);
1766 }
1767 }
1768 }
1769 }
1770
1771 else {
1772 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1773 }
1774
1775 String sql = query.toString();
1776
1777 Query q = session.createQuery(sql);
1778
1779 q.setFirstResult(0);
1780 q.setMaxResults(2);
1781
1782 QueryPos qPos = QueryPos.getInstance(q);
1783
1784 qPos.add(companyId);
1785
1786 if (orderByComparator != null) {
1787 Object[] values = orderByComparator.getOrderByValues(wikiNode);
1788
1789 for (Object value : values) {
1790 qPos.add(value);
1791 }
1792 }
1793
1794 List<WikiNode> list = q.list();
1795
1796 if (list.size() == 2) {
1797 return list.get(1);
1798 }
1799 else {
1800 return null;
1801 }
1802 }
1803
1804
1813 public WikiNode findByG_N(long groupId, String name)
1814 throws NoSuchNodeException, SystemException {
1815 WikiNode wikiNode = fetchByG_N(groupId, name);
1816
1817 if (wikiNode == null) {
1818 StringBundler msg = new StringBundler(6);
1819
1820 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1821
1822 msg.append("groupId=");
1823 msg.append(groupId);
1824
1825 msg.append(", name=");
1826 msg.append(name);
1827
1828 msg.append(StringPool.CLOSE_CURLY_BRACE);
1829
1830 if (_log.isWarnEnabled()) {
1831 _log.warn(msg.toString());
1832 }
1833
1834 throw new NoSuchNodeException(msg.toString());
1835 }
1836
1837 return wikiNode;
1838 }
1839
1840
1848 public WikiNode fetchByG_N(long groupId, String name)
1849 throws SystemException {
1850 return fetchByG_N(groupId, name, true);
1851 }
1852
1853
1861 public WikiNode fetchByG_N(long groupId, String name,
1862 boolean retrieveFromCache) throws SystemException {
1863 Object[] finderArgs = new Object[] { groupId, name };
1864
1865 Object result = null;
1866
1867 if (retrieveFromCache) {
1868 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1869 finderArgs, this);
1870 }
1871
1872 if (result == null) {
1873 Session session = null;
1874
1875 try {
1876 session = openSession();
1877
1878 StringBundler query = new StringBundler(4);
1879
1880 query.append(_SQL_SELECT_WIKINODE_WHERE);
1881
1882 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1883
1884 if (name == null) {
1885 query.append(_FINDER_COLUMN_G_N_NAME_1);
1886 }
1887 else {
1888 if (name.equals(StringPool.BLANK)) {
1889 query.append(_FINDER_COLUMN_G_N_NAME_3);
1890 }
1891 else {
1892 query.append(_FINDER_COLUMN_G_N_NAME_2);
1893 }
1894 }
1895
1896 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1897
1898 String sql = query.toString();
1899
1900 Query q = session.createQuery(sql);
1901
1902 QueryPos qPos = QueryPos.getInstance(q);
1903
1904 qPos.add(groupId);
1905
1906 if (name != null) {
1907 qPos.add(name);
1908 }
1909
1910 List<WikiNode> list = q.list();
1911
1912 result = list;
1913
1914 WikiNode wikiNode = null;
1915
1916 if (list.isEmpty()) {
1917 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1918 finderArgs, list);
1919 }
1920 else {
1921 wikiNode = list.get(0);
1922
1923 cacheResult(wikiNode);
1924
1925 if ((wikiNode.getGroupId() != groupId) ||
1926 (wikiNode.getName() == null) ||
1927 !wikiNode.getName().equals(name)) {
1928 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1929 finderArgs, wikiNode);
1930 }
1931 }
1932
1933 return wikiNode;
1934 }
1935 catch (Exception e) {
1936 throw processException(e);
1937 }
1938 finally {
1939 if (result == null) {
1940 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1941 finderArgs, new ArrayList<WikiNode>());
1942 }
1943
1944 closeSession(session);
1945 }
1946 }
1947 else {
1948 if (result instanceof List<?>) {
1949 return null;
1950 }
1951 else {
1952 return (WikiNode)result;
1953 }
1954 }
1955 }
1956
1957
1963 public List<WikiNode> findAll() throws SystemException {
1964 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1965 }
1966
1967
1979 public List<WikiNode> findAll(int start, int end) throws SystemException {
1980 return findAll(start, end, null);
1981 }
1982
1983
1996 public List<WikiNode> findAll(int start, int end,
1997 OrderByComparator orderByComparator) throws SystemException {
1998 Object[] finderArgs = new Object[] {
1999 String.valueOf(start), String.valueOf(end),
2000 String.valueOf(orderByComparator)
2001 };
2002
2003 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2004 finderArgs, this);
2005
2006 if (list == null) {
2007 Session session = null;
2008
2009 try {
2010 session = openSession();
2011
2012 StringBundler query = null;
2013 String sql = null;
2014
2015 if (orderByComparator != null) {
2016 query = new StringBundler(2 +
2017 (orderByComparator.getOrderByFields().length * 3));
2018
2019 query.append(_SQL_SELECT_WIKINODE);
2020
2021 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2022 orderByComparator);
2023
2024 sql = query.toString();
2025 }
2026 else {
2027 sql = _SQL_SELECT_WIKINODE.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
2028 }
2029
2030 Query q = session.createQuery(sql);
2031
2032 if (orderByComparator == null) {
2033 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2034 start, end, false);
2035
2036 Collections.sort(list);
2037 }
2038 else {
2039 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2040 start, end);
2041 }
2042 }
2043 catch (Exception e) {
2044 throw processException(e);
2045 }
2046 finally {
2047 if (list == null) {
2048 list = new ArrayList<WikiNode>();
2049 }
2050
2051 cacheResult(list);
2052
2053 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2054
2055 closeSession(session);
2056 }
2057 }
2058
2059 return list;
2060 }
2061
2062
2068 public void removeByUuid(String uuid) throws SystemException {
2069 for (WikiNode wikiNode : findByUuid(uuid)) {
2070 remove(wikiNode);
2071 }
2072 }
2073
2074
2081 public void removeByUUID_G(String uuid, long groupId)
2082 throws NoSuchNodeException, SystemException {
2083 WikiNode wikiNode = findByUUID_G(uuid, groupId);
2084
2085 remove(wikiNode);
2086 }
2087
2088
2094 public void removeByGroupId(long groupId) throws SystemException {
2095 for (WikiNode wikiNode : findByGroupId(groupId)) {
2096 remove(wikiNode);
2097 }
2098 }
2099
2100
2106 public void removeByCompanyId(long companyId) throws SystemException {
2107 for (WikiNode wikiNode : findByCompanyId(companyId)) {
2108 remove(wikiNode);
2109 }
2110 }
2111
2112
2119 public void removeByG_N(long groupId, String name)
2120 throws NoSuchNodeException, SystemException {
2121 WikiNode wikiNode = findByG_N(groupId, name);
2122
2123 remove(wikiNode);
2124 }
2125
2126
2131 public void removeAll() throws SystemException {
2132 for (WikiNode wikiNode : findAll()) {
2133 remove(wikiNode);
2134 }
2135 }
2136
2137
2144 public int countByUuid(String uuid) throws SystemException {
2145 Object[] finderArgs = new Object[] { uuid };
2146
2147 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2148 finderArgs, this);
2149
2150 if (count == null) {
2151 Session session = null;
2152
2153 try {
2154 session = openSession();
2155
2156 StringBundler query = new StringBundler(2);
2157
2158 query.append(_SQL_COUNT_WIKINODE_WHERE);
2159
2160 if (uuid == null) {
2161 query.append(_FINDER_COLUMN_UUID_UUID_1);
2162 }
2163 else {
2164 if (uuid.equals(StringPool.BLANK)) {
2165 query.append(_FINDER_COLUMN_UUID_UUID_3);
2166 }
2167 else {
2168 query.append(_FINDER_COLUMN_UUID_UUID_2);
2169 }
2170 }
2171
2172 String sql = query.toString();
2173
2174 Query q = session.createQuery(sql);
2175
2176 QueryPos qPos = QueryPos.getInstance(q);
2177
2178 if (uuid != null) {
2179 qPos.add(uuid);
2180 }
2181
2182 count = (Long)q.uniqueResult();
2183 }
2184 catch (Exception e) {
2185 throw processException(e);
2186 }
2187 finally {
2188 if (count == null) {
2189 count = Long.valueOf(0);
2190 }
2191
2192 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2193 finderArgs, count);
2194
2195 closeSession(session);
2196 }
2197 }
2198
2199 return count.intValue();
2200 }
2201
2202
2210 public int countByUUID_G(String uuid, long groupId)
2211 throws SystemException {
2212 Object[] finderArgs = new Object[] { uuid, groupId };
2213
2214 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2215 finderArgs, this);
2216
2217 if (count == null) {
2218 Session session = null;
2219
2220 try {
2221 session = openSession();
2222
2223 StringBundler query = new StringBundler(3);
2224
2225 query.append(_SQL_COUNT_WIKINODE_WHERE);
2226
2227 if (uuid == null) {
2228 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2229 }
2230 else {
2231 if (uuid.equals(StringPool.BLANK)) {
2232 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2233 }
2234 else {
2235 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2236 }
2237 }
2238
2239 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2240
2241 String sql = query.toString();
2242
2243 Query q = session.createQuery(sql);
2244
2245 QueryPos qPos = QueryPos.getInstance(q);
2246
2247 if (uuid != null) {
2248 qPos.add(uuid);
2249 }
2250
2251 qPos.add(groupId);
2252
2253 count = (Long)q.uniqueResult();
2254 }
2255 catch (Exception e) {
2256 throw processException(e);
2257 }
2258 finally {
2259 if (count == null) {
2260 count = Long.valueOf(0);
2261 }
2262
2263 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2264 finderArgs, count);
2265
2266 closeSession(session);
2267 }
2268 }
2269
2270 return count.intValue();
2271 }
2272
2273
2280 public int countByGroupId(long groupId) throws SystemException {
2281 Object[] finderArgs = new Object[] { groupId };
2282
2283 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2284 finderArgs, this);
2285
2286 if (count == null) {
2287 Session session = null;
2288
2289 try {
2290 session = openSession();
2291
2292 StringBundler query = new StringBundler(2);
2293
2294 query.append(_SQL_COUNT_WIKINODE_WHERE);
2295
2296 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2297
2298 String sql = query.toString();
2299
2300 Query q = session.createQuery(sql);
2301
2302 QueryPos qPos = QueryPos.getInstance(q);
2303
2304 qPos.add(groupId);
2305
2306 count = (Long)q.uniqueResult();
2307 }
2308 catch (Exception e) {
2309 throw processException(e);
2310 }
2311 finally {
2312 if (count == null) {
2313 count = Long.valueOf(0);
2314 }
2315
2316 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2317 finderArgs, count);
2318
2319 closeSession(session);
2320 }
2321 }
2322
2323 return count.intValue();
2324 }
2325
2326
2333 public int filterCountByGroupId(long groupId) throws SystemException {
2334 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2335 return countByGroupId(groupId);
2336 }
2337
2338 Session session = null;
2339
2340 try {
2341 session = openSession();
2342
2343 StringBundler query = new StringBundler(2);
2344
2345 query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2346
2347 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2348
2349 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2350 WikiNode.class.getName(), _FILTER_COLUMN_PK,
2351 _FILTER_COLUMN_USERID, groupId);
2352
2353 SQLQuery q = session.createSQLQuery(sql);
2354
2355 q.addScalar(COUNT_COLUMN_NAME,
2356 com.liferay.portal.kernel.dao.orm.Type.LONG);
2357
2358 QueryPos qPos = QueryPos.getInstance(q);
2359
2360 qPos.add(groupId);
2361
2362 Long count = (Long)q.uniqueResult();
2363
2364 return count.intValue();
2365 }
2366 catch (Exception e) {
2367 throw processException(e);
2368 }
2369 finally {
2370 closeSession(session);
2371 }
2372 }
2373
2374
2381 public int countByCompanyId(long companyId) throws SystemException {
2382 Object[] finderArgs = new Object[] { companyId };
2383
2384 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2385 finderArgs, this);
2386
2387 if (count == null) {
2388 Session session = null;
2389
2390 try {
2391 session = openSession();
2392
2393 StringBundler query = new StringBundler(2);
2394
2395 query.append(_SQL_COUNT_WIKINODE_WHERE);
2396
2397 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2398
2399 String sql = query.toString();
2400
2401 Query q = session.createQuery(sql);
2402
2403 QueryPos qPos = QueryPos.getInstance(q);
2404
2405 qPos.add(companyId);
2406
2407 count = (Long)q.uniqueResult();
2408 }
2409 catch (Exception e) {
2410 throw processException(e);
2411 }
2412 finally {
2413 if (count == null) {
2414 count = Long.valueOf(0);
2415 }
2416
2417 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2418 finderArgs, count);
2419
2420 closeSession(session);
2421 }
2422 }
2423
2424 return count.intValue();
2425 }
2426
2427
2435 public int countByG_N(long groupId, String name) throws SystemException {
2436 Object[] finderArgs = new Object[] { groupId, name };
2437
2438 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
2439 finderArgs, this);
2440
2441 if (count == null) {
2442 Session session = null;
2443
2444 try {
2445 session = openSession();
2446
2447 StringBundler query = new StringBundler(3);
2448
2449 query.append(_SQL_COUNT_WIKINODE_WHERE);
2450
2451 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2452
2453 if (name == null) {
2454 query.append(_FINDER_COLUMN_G_N_NAME_1);
2455 }
2456 else {
2457 if (name.equals(StringPool.BLANK)) {
2458 query.append(_FINDER_COLUMN_G_N_NAME_3);
2459 }
2460 else {
2461 query.append(_FINDER_COLUMN_G_N_NAME_2);
2462 }
2463 }
2464
2465 String sql = query.toString();
2466
2467 Query q = session.createQuery(sql);
2468
2469 QueryPos qPos = QueryPos.getInstance(q);
2470
2471 qPos.add(groupId);
2472
2473 if (name != null) {
2474 qPos.add(name);
2475 }
2476
2477 count = (Long)q.uniqueResult();
2478 }
2479 catch (Exception e) {
2480 throw processException(e);
2481 }
2482 finally {
2483 if (count == null) {
2484 count = Long.valueOf(0);
2485 }
2486
2487 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
2488 count);
2489
2490 closeSession(session);
2491 }
2492 }
2493
2494 return count.intValue();
2495 }
2496
2497
2505 public int filterCountByG_N(long groupId, String name)
2506 throws SystemException {
2507 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2508 return countByG_N(groupId, name);
2509 }
2510
2511 Session session = null;
2512
2513 try {
2514 session = openSession();
2515
2516 StringBundler query = new StringBundler(3);
2517
2518 query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2519
2520 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2521
2522 if (name == null) {
2523 query.append(_FINDER_COLUMN_G_N_NAME_1);
2524 }
2525 else {
2526 if (name.equals(StringPool.BLANK)) {
2527 query.append(_FINDER_COLUMN_G_N_NAME_3);
2528 }
2529 else {
2530 query.append(_FINDER_COLUMN_G_N_NAME_2);
2531 }
2532 }
2533
2534 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2535 WikiNode.class.getName(), _FILTER_COLUMN_PK,
2536 _FILTER_COLUMN_USERID, groupId);
2537
2538 SQLQuery q = session.createSQLQuery(sql);
2539
2540 q.addScalar(COUNT_COLUMN_NAME,
2541 com.liferay.portal.kernel.dao.orm.Type.LONG);
2542
2543 QueryPos qPos = QueryPos.getInstance(q);
2544
2545 qPos.add(groupId);
2546
2547 if (name != null) {
2548 qPos.add(name);
2549 }
2550
2551 Long count = (Long)q.uniqueResult();
2552
2553 return count.intValue();
2554 }
2555 catch (Exception e) {
2556 throw processException(e);
2557 }
2558 finally {
2559 closeSession(session);
2560 }
2561 }
2562
2563
2569 public int countAll() throws SystemException {
2570 Object[] finderArgs = new Object[0];
2571
2572 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2573 finderArgs, this);
2574
2575 if (count == null) {
2576 Session session = null;
2577
2578 try {
2579 session = openSession();
2580
2581 Query q = session.createQuery(_SQL_COUNT_WIKINODE);
2582
2583 count = (Long)q.uniqueResult();
2584 }
2585 catch (Exception e) {
2586 throw processException(e);
2587 }
2588 finally {
2589 if (count == null) {
2590 count = Long.valueOf(0);
2591 }
2592
2593 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2594 count);
2595
2596 closeSession(session);
2597 }
2598 }
2599
2600 return count.intValue();
2601 }
2602
2603
2606 public void afterPropertiesSet() {
2607 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2608 com.liferay.portal.util.PropsUtil.get(
2609 "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
2610
2611 if (listenerClassNames.length > 0) {
2612 try {
2613 List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
2614
2615 for (String listenerClassName : listenerClassNames) {
2616 listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
2617 listenerClassName));
2618 }
2619
2620 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2621 }
2622 catch (Exception e) {
2623 _log.error(e);
2624 }
2625 }
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_COUNT_WIKINODE_WHERE = "SELECT COUNT(DISTINCT wikiNode.nodeId) AS COUNT_VALUE FROM WikiNode wikiNode WHERE ";
2661 private static final String _FILTER_COLUMN_PK = "wikiNode.nodeId";
2662 private static final String _FILTER_COLUMN_USERID = "wikiNode.userId";
2663 private static final String _FILTER_ENTITY_ALIAS = "wikiNode";
2664 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
2665 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
2666 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
2667 private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
2668 }