001
014
015 package com.liferay.portlet.wiki.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.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.CacheModel;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042 import com.liferay.portal.service.persistence.BatchSessionUtil;
043 import com.liferay.portal.service.persistence.GroupPersistence;
044 import com.liferay.portal.service.persistence.ResourcePersistence;
045 import com.liferay.portal.service.persistence.SubscriptionPersistence;
046 import com.liferay.portal.service.persistence.UserPersistence;
047 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048
049 import com.liferay.portlet.wiki.NoSuchNodeException;
050 import com.liferay.portlet.wiki.model.WikiNode;
051 import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
052 import com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl;
053
054 import java.io.Serializable;
055
056 import java.util.ArrayList;
057 import java.util.Collections;
058 import java.util.List;
059
060
072 public class WikiNodePersistenceImpl extends BasePersistenceImpl<WikiNode>
073 implements WikiNodePersistence {
074
079 public static final String FINDER_CLASS_NAME_ENTITY = WikiNodeImpl.class.getName();
080 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List1";
082 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083 ".List2";
084 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
085 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
086 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
087 new String[] {
088 String.class.getName(),
089
090 "java.lang.Integer", "java.lang.Integer",
091 "com.liferay.portal.kernel.util.OrderByComparator"
092 });
093 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
094 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
096 new String[] { String.class.getName() },
097 WikiNodeModelImpl.UUID_COLUMN_BITMASK);
098 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
099 WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
101 new String[] { String.class.getName() });
102 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
103 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
104 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
105 new String[] { String.class.getName(), Long.class.getName() },
106 WikiNodeModelImpl.UUID_COLUMN_BITMASK |
107 WikiNodeModelImpl.GROUPID_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
109 WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
111 new String[] { String.class.getName(), Long.class.getName() });
112 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
113 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
114 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
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_WITHOUT_PAGINATION_FIND_BY_GROUPID =
122 new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
123 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
124 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
125 new String[] { Long.class.getName() },
126 WikiNodeModelImpl.GROUPID_COLUMN_BITMASK);
127 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
128 WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
129 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
130 new String[] { Long.class.getName() });
131 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
132 new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
133 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
134 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
135 new String[] {
136 Long.class.getName(),
137
138 "java.lang.Integer", "java.lang.Integer",
139 "com.liferay.portal.kernel.util.OrderByComparator"
140 });
141 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
142 new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
143 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
144 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
145 new String[] { Long.class.getName() },
146 WikiNodeModelImpl.COMPANYID_COLUMN_BITMASK);
147 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
148 WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
149 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
150 new String[] { Long.class.getName() });
151 public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
152 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
153 FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
154 new String[] { Long.class.getName(), String.class.getName() },
155 WikiNodeModelImpl.GROUPID_COLUMN_BITMASK |
156 WikiNodeModelImpl.NAME_COLUMN_BITMASK);
157 public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
158 WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
159 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
160 new String[] { Long.class.getName(), String.class.getName() });
161 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
162 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
163 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
164 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
165 WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
166 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
167 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
168 WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
169 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
170
171
176 public void cacheResult(WikiNode wikiNode) {
177 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
178 WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
179
180 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
181 new Object[] { wikiNode.getUuid(), Long.valueOf(
182 wikiNode.getGroupId()) }, wikiNode);
183
184 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
185 new Object[] { Long.valueOf(wikiNode.getGroupId()), wikiNode.getName() },
186 wikiNode);
187
188 wikiNode.resetOriginalValues();
189 }
190
191
196 public void cacheResult(List<WikiNode> wikiNodes) {
197 for (WikiNode wikiNode : wikiNodes) {
198 if (EntityCacheUtil.getResult(
199 WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
200 WikiNodeImpl.class, wikiNode.getPrimaryKey()) == null) {
201 cacheResult(wikiNode);
202 }
203 else {
204 wikiNode.resetOriginalValues();
205 }
206 }
207 }
208
209
216 @Override
217 public void clearCache() {
218 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
219 CacheRegistryUtil.clear(WikiNodeImpl.class.getName());
220 }
221
222 EntityCacheUtil.clearCache(WikiNodeImpl.class.getName());
223
224 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
226 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
227 }
228
229
236 @Override
237 public void clearCache(WikiNode wikiNode) {
238 EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
239 WikiNodeImpl.class, wikiNode.getPrimaryKey());
240
241 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
242 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
243
244 clearUniqueFindersCache(wikiNode);
245 }
246
247 @Override
248 public void clearCache(List<WikiNode> wikiNodes) {
249 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
250 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
251
252 for (WikiNode wikiNode : wikiNodes) {
253 EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
254 WikiNodeImpl.class, wikiNode.getPrimaryKey());
255
256 clearUniqueFindersCache(wikiNode);
257 }
258 }
259
260 protected void clearUniqueFindersCache(WikiNode wikiNode) {
261 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
262 new Object[] { wikiNode.getUuid(), Long.valueOf(
263 wikiNode.getGroupId()) });
264
265 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
266 new Object[] { Long.valueOf(wikiNode.getGroupId()), wikiNode.getName() });
267 }
268
269
275 public WikiNode create(long nodeId) {
276 WikiNode wikiNode = new WikiNodeImpl();
277
278 wikiNode.setNew(true);
279 wikiNode.setPrimaryKey(nodeId);
280
281 String uuid = PortalUUIDUtil.generate();
282
283 wikiNode.setUuid(uuid);
284
285 return wikiNode;
286 }
287
288
296 public WikiNode remove(long nodeId)
297 throws NoSuchNodeException, SystemException {
298 return remove(Long.valueOf(nodeId));
299 }
300
301
309 @Override
310 public WikiNode remove(Serializable primaryKey)
311 throws NoSuchNodeException, SystemException {
312 Session session = null;
313
314 try {
315 session = openSession();
316
317 WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
318 primaryKey);
319
320 if (wikiNode == null) {
321 if (_log.isWarnEnabled()) {
322 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
323 }
324
325 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
326 primaryKey);
327 }
328
329 return remove(wikiNode);
330 }
331 catch (NoSuchNodeException nsee) {
332 throw nsee;
333 }
334 catch (Exception e) {
335 throw processException(e);
336 }
337 finally {
338 closeSession(session);
339 }
340 }
341
342 @Override
343 protected WikiNode removeImpl(WikiNode wikiNode) throws SystemException {
344 wikiNode = toUnwrappedModel(wikiNode);
345
346 Session session = null;
347
348 try {
349 session = openSession();
350
351 BatchSessionUtil.delete(session, wikiNode);
352 }
353 catch (Exception e) {
354 throw processException(e);
355 }
356 finally {
357 closeSession(session);
358 }
359
360 clearCache(wikiNode);
361
362 return wikiNode;
363 }
364
365 @Override
366 public WikiNode updateImpl(
367 com.liferay.portlet.wiki.model.WikiNode wikiNode, boolean merge)
368 throws SystemException {
369 wikiNode = toUnwrappedModel(wikiNode);
370
371 boolean isNew = wikiNode.isNew();
372
373 WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
374
375 if (Validator.isNull(wikiNode.getUuid())) {
376 String uuid = PortalUUIDUtil.generate();
377
378 wikiNode.setUuid(uuid);
379 }
380
381 Session session = null;
382
383 try {
384 session = openSession();
385
386 BatchSessionUtil.update(session, wikiNode, merge);
387
388 wikiNode.setNew(false);
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396
397 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
398
399 if (isNew || !WikiNodeModelImpl.COLUMN_BITMASK_ENABLED) {
400 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
401 }
402
403 else {
404 if ((wikiNodeModelImpl.getColumnBitmask() &
405 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
406 Object[] args = new Object[] { wikiNodeModelImpl.getOriginalUuid() };
407
408 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
409 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
410 args);
411
412 args = new Object[] { wikiNodeModelImpl.getUuid() };
413
414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
415 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
416 args);
417 }
418
419 if ((wikiNodeModelImpl.getColumnBitmask() &
420 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
421 Object[] args = new Object[] {
422 Long.valueOf(wikiNodeModelImpl.getOriginalGroupId())
423 };
424
425 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
426 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
427 args);
428
429 args = new Object[] { Long.valueOf(wikiNodeModelImpl.getGroupId()) };
430
431 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
432 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
433 args);
434 }
435
436 if ((wikiNodeModelImpl.getColumnBitmask() &
437 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
438 Object[] args = new Object[] {
439 Long.valueOf(wikiNodeModelImpl.getOriginalCompanyId())
440 };
441
442 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
443 args);
444 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
445 args);
446
447 args = new Object[] {
448 Long.valueOf(wikiNodeModelImpl.getCompanyId())
449 };
450
451 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
452 args);
453 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
454 args);
455 }
456 }
457
458 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
459 WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
460
461 if (isNew) {
462 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
463 new Object[] {
464 wikiNode.getUuid(), Long.valueOf(wikiNode.getGroupId())
465 }, wikiNode);
466
467 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
468 new Object[] {
469 Long.valueOf(wikiNode.getGroupId()),
470
471 wikiNode.getName()
472 }, wikiNode);
473 }
474 else {
475 if ((wikiNodeModelImpl.getColumnBitmask() &
476 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
477 Object[] args = new Object[] {
478 wikiNodeModelImpl.getOriginalUuid(),
479 Long.valueOf(wikiNodeModelImpl.getOriginalGroupId())
480 };
481
482 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
483
484 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
485
486 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
487 new Object[] {
488 wikiNode.getUuid(), Long.valueOf(wikiNode.getGroupId())
489 }, wikiNode);
490 }
491
492 if ((wikiNodeModelImpl.getColumnBitmask() &
493 FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
494 Object[] args = new Object[] {
495 Long.valueOf(wikiNodeModelImpl.getOriginalGroupId()),
496
497 wikiNodeModelImpl.getOriginalName()
498 };
499
500 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
501
502 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
503
504 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
505 new Object[] {
506 Long.valueOf(wikiNode.getGroupId()),
507
508 wikiNode.getName()
509 }, wikiNode);
510 }
511 }
512
513 return wikiNode;
514 }
515
516 protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
517 if (wikiNode instanceof WikiNodeImpl) {
518 return wikiNode;
519 }
520
521 WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
522
523 wikiNodeImpl.setNew(wikiNode.isNew());
524 wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
525
526 wikiNodeImpl.setUuid(wikiNode.getUuid());
527 wikiNodeImpl.setNodeId(wikiNode.getNodeId());
528 wikiNodeImpl.setGroupId(wikiNode.getGroupId());
529 wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
530 wikiNodeImpl.setUserId(wikiNode.getUserId());
531 wikiNodeImpl.setUserName(wikiNode.getUserName());
532 wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
533 wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
534 wikiNodeImpl.setName(wikiNode.getName());
535 wikiNodeImpl.setDescription(wikiNode.getDescription());
536 wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
537
538 return wikiNodeImpl;
539 }
540
541
549 @Override
550 public WikiNode findByPrimaryKey(Serializable primaryKey)
551 throws NoSuchModelException, SystemException {
552 return findByPrimaryKey(((Long)primaryKey).longValue());
553 }
554
555
563 public WikiNode findByPrimaryKey(long nodeId)
564 throws NoSuchNodeException, SystemException {
565 WikiNode wikiNode = fetchByPrimaryKey(nodeId);
566
567 if (wikiNode == null) {
568 if (_log.isWarnEnabled()) {
569 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
570 }
571
572 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
573 nodeId);
574 }
575
576 return wikiNode;
577 }
578
579
586 @Override
587 public WikiNode fetchByPrimaryKey(Serializable primaryKey)
588 throws SystemException {
589 return fetchByPrimaryKey(((Long)primaryKey).longValue());
590 }
591
592
599 public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
600 WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
601 WikiNodeImpl.class, nodeId);
602
603 if (wikiNode == _nullWikiNode) {
604 return null;
605 }
606
607 if (wikiNode == null) {
608 Session session = null;
609
610 boolean hasException = false;
611
612 try {
613 session = openSession();
614
615 wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
616 Long.valueOf(nodeId));
617 }
618 catch (Exception e) {
619 hasException = true;
620
621 throw processException(e);
622 }
623 finally {
624 if (wikiNode != null) {
625 cacheResult(wikiNode);
626 }
627 else if (!hasException) {
628 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
629 WikiNodeImpl.class, nodeId, _nullWikiNode);
630 }
631
632 closeSession(session);
633 }
634 }
635
636 return wikiNode;
637 }
638
639
646 public List<WikiNode> findByUuid(String uuid) throws SystemException {
647 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
648 }
649
650
663 public List<WikiNode> findByUuid(String uuid, int start, int end)
664 throws SystemException {
665 return findByUuid(uuid, start, end, null);
666 }
667
668
682 public List<WikiNode> findByUuid(String uuid, int start, int end,
683 OrderByComparator orderByComparator) throws SystemException {
684 FinderPath finderPath = null;
685 Object[] finderArgs = null;
686
687 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
688 (orderByComparator == null)) {
689 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
690 finderArgs = new Object[] { uuid };
691 }
692 else {
693 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
694 finderArgs = new Object[] { uuid, start, end, orderByComparator };
695 }
696
697 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
698 finderArgs, this);
699
700 if ((list != null) && !list.isEmpty()) {
701 for (WikiNode wikiNode : list) {
702 if (!Validator.equals(uuid, wikiNode.getUuid())) {
703 list = null;
704
705 break;
706 }
707 }
708 }
709
710 if (list == null) {
711 StringBundler query = null;
712
713 if (orderByComparator != null) {
714 query = new StringBundler(3 +
715 (orderByComparator.getOrderByFields().length * 3));
716 }
717 else {
718 query = new StringBundler(3);
719 }
720
721 query.append(_SQL_SELECT_WIKINODE_WHERE);
722
723 if (uuid == null) {
724 query.append(_FINDER_COLUMN_UUID_UUID_1);
725 }
726 else {
727 if (uuid.equals(StringPool.BLANK)) {
728 query.append(_FINDER_COLUMN_UUID_UUID_3);
729 }
730 else {
731 query.append(_FINDER_COLUMN_UUID_UUID_2);
732 }
733 }
734
735 if (orderByComparator != null) {
736 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
737 orderByComparator);
738 }
739
740 else {
741 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
742 }
743
744 String sql = query.toString();
745
746 Session session = null;
747
748 try {
749 session = openSession();
750
751 Query q = session.createQuery(sql);
752
753 QueryPos qPos = QueryPos.getInstance(q);
754
755 if (uuid != null) {
756 qPos.add(uuid);
757 }
758
759 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
760 end);
761 }
762 catch (Exception e) {
763 throw processException(e);
764 }
765 finally {
766 if (list == null) {
767 FinderCacheUtil.removeResult(finderPath, finderArgs);
768 }
769 else {
770 cacheResult(list);
771
772 FinderCacheUtil.putResult(finderPath, finderArgs, list);
773 }
774
775 closeSession(session);
776 }
777 }
778
779 return list;
780 }
781
782
791 public WikiNode findByUuid_First(String uuid,
792 OrderByComparator orderByComparator)
793 throws NoSuchNodeException, SystemException {
794 WikiNode wikiNode = fetchByUuid_First(uuid, orderByComparator);
795
796 if (wikiNode != null) {
797 return wikiNode;
798 }
799
800 StringBundler msg = new StringBundler(4);
801
802 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
803
804 msg.append("uuid=");
805 msg.append(uuid);
806
807 msg.append(StringPool.CLOSE_CURLY_BRACE);
808
809 throw new NoSuchNodeException(msg.toString());
810 }
811
812
820 public WikiNode fetchByUuid_First(String uuid,
821 OrderByComparator orderByComparator) throws SystemException {
822 List<WikiNode> list = findByUuid(uuid, 0, 1, orderByComparator);
823
824 if (!list.isEmpty()) {
825 return list.get(0);
826 }
827
828 return null;
829 }
830
831
840 public WikiNode findByUuid_Last(String uuid,
841 OrderByComparator orderByComparator)
842 throws NoSuchNodeException, SystemException {
843 WikiNode wikiNode = fetchByUuid_Last(uuid, orderByComparator);
844
845 if (wikiNode != null) {
846 return wikiNode;
847 }
848
849 StringBundler msg = new StringBundler(4);
850
851 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
852
853 msg.append("uuid=");
854 msg.append(uuid);
855
856 msg.append(StringPool.CLOSE_CURLY_BRACE);
857
858 throw new NoSuchNodeException(msg.toString());
859 }
860
861
869 public WikiNode fetchByUuid_Last(String uuid,
870 OrderByComparator orderByComparator) throws SystemException {
871 int count = countByUuid(uuid);
872
873 List<WikiNode> list = findByUuid(uuid, count - 1, count,
874 orderByComparator);
875
876 if (!list.isEmpty()) {
877 return list.get(0);
878 }
879
880 return null;
881 }
882
883
893 public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
894 OrderByComparator orderByComparator)
895 throws NoSuchNodeException, SystemException {
896 WikiNode wikiNode = findByPrimaryKey(nodeId);
897
898 Session session = null;
899
900 try {
901 session = openSession();
902
903 WikiNode[] array = new WikiNodeImpl[3];
904
905 array[0] = getByUuid_PrevAndNext(session, wikiNode, uuid,
906 orderByComparator, true);
907
908 array[1] = wikiNode;
909
910 array[2] = getByUuid_PrevAndNext(session, wikiNode, uuid,
911 orderByComparator, false);
912
913 return array;
914 }
915 catch (Exception e) {
916 throw processException(e);
917 }
918 finally {
919 closeSession(session);
920 }
921 }
922
923 protected WikiNode getByUuid_PrevAndNext(Session session,
924 WikiNode wikiNode, String uuid, OrderByComparator orderByComparator,
925 boolean previous) {
926 StringBundler query = null;
927
928 if (orderByComparator != null) {
929 query = new StringBundler(6 +
930 (orderByComparator.getOrderByFields().length * 6));
931 }
932 else {
933 query = new StringBundler(3);
934 }
935
936 query.append(_SQL_SELECT_WIKINODE_WHERE);
937
938 if (uuid == null) {
939 query.append(_FINDER_COLUMN_UUID_UUID_1);
940 }
941 else {
942 if (uuid.equals(StringPool.BLANK)) {
943 query.append(_FINDER_COLUMN_UUID_UUID_3);
944 }
945 else {
946 query.append(_FINDER_COLUMN_UUID_UUID_2);
947 }
948 }
949
950 if (orderByComparator != null) {
951 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
952
953 if (orderByConditionFields.length > 0) {
954 query.append(WHERE_AND);
955 }
956
957 for (int i = 0; i < orderByConditionFields.length; i++) {
958 query.append(_ORDER_BY_ENTITY_ALIAS);
959 query.append(orderByConditionFields[i]);
960
961 if ((i + 1) < orderByConditionFields.length) {
962 if (orderByComparator.isAscending() ^ previous) {
963 query.append(WHERE_GREATER_THAN_HAS_NEXT);
964 }
965 else {
966 query.append(WHERE_LESSER_THAN_HAS_NEXT);
967 }
968 }
969 else {
970 if (orderByComparator.isAscending() ^ previous) {
971 query.append(WHERE_GREATER_THAN);
972 }
973 else {
974 query.append(WHERE_LESSER_THAN);
975 }
976 }
977 }
978
979 query.append(ORDER_BY_CLAUSE);
980
981 String[] orderByFields = orderByComparator.getOrderByFields();
982
983 for (int i = 0; i < orderByFields.length; i++) {
984 query.append(_ORDER_BY_ENTITY_ALIAS);
985 query.append(orderByFields[i]);
986
987 if ((i + 1) < orderByFields.length) {
988 if (orderByComparator.isAscending() ^ previous) {
989 query.append(ORDER_BY_ASC_HAS_NEXT);
990 }
991 else {
992 query.append(ORDER_BY_DESC_HAS_NEXT);
993 }
994 }
995 else {
996 if (orderByComparator.isAscending() ^ previous) {
997 query.append(ORDER_BY_ASC);
998 }
999 else {
1000 query.append(ORDER_BY_DESC);
1001 }
1002 }
1003 }
1004 }
1005
1006 else {
1007 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1008 }
1009
1010 String sql = query.toString();
1011
1012 Query q = session.createQuery(sql);
1013
1014 q.setFirstResult(0);
1015 q.setMaxResults(2);
1016
1017 QueryPos qPos = QueryPos.getInstance(q);
1018
1019 if (uuid != null) {
1020 qPos.add(uuid);
1021 }
1022
1023 if (orderByComparator != null) {
1024 Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1025
1026 for (Object value : values) {
1027 qPos.add(value);
1028 }
1029 }
1030
1031 List<WikiNode> list = q.list();
1032
1033 if (list.size() == 2) {
1034 return list.get(1);
1035 }
1036 else {
1037 return null;
1038 }
1039 }
1040
1041
1050 public WikiNode findByUUID_G(String uuid, long groupId)
1051 throws NoSuchNodeException, SystemException {
1052 WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
1053
1054 if (wikiNode == null) {
1055 StringBundler msg = new StringBundler(6);
1056
1057 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1058
1059 msg.append("uuid=");
1060 msg.append(uuid);
1061
1062 msg.append(", groupId=");
1063 msg.append(groupId);
1064
1065 msg.append(StringPool.CLOSE_CURLY_BRACE);
1066
1067 if (_log.isWarnEnabled()) {
1068 _log.warn(msg.toString());
1069 }
1070
1071 throw new NoSuchNodeException(msg.toString());
1072 }
1073
1074 return wikiNode;
1075 }
1076
1077
1085 public WikiNode fetchByUUID_G(String uuid, long groupId)
1086 throws SystemException {
1087 return fetchByUUID_G(uuid, groupId, true);
1088 }
1089
1090
1099 public WikiNode fetchByUUID_G(String uuid, long groupId,
1100 boolean retrieveFromCache) throws SystemException {
1101 Object[] finderArgs = new Object[] { uuid, groupId };
1102
1103 Object result = null;
1104
1105 if (retrieveFromCache) {
1106 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1107 finderArgs, this);
1108 }
1109
1110 if (result instanceof WikiNode) {
1111 WikiNode wikiNode = (WikiNode)result;
1112
1113 if (!Validator.equals(uuid, wikiNode.getUuid()) ||
1114 (groupId != wikiNode.getGroupId())) {
1115 result = null;
1116 }
1117 }
1118
1119 if (result == null) {
1120 StringBundler query = new StringBundler(4);
1121
1122 query.append(_SQL_SELECT_WIKINODE_WHERE);
1123
1124 if (uuid == null) {
1125 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1126 }
1127 else {
1128 if (uuid.equals(StringPool.BLANK)) {
1129 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1130 }
1131 else {
1132 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1133 }
1134 }
1135
1136 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1137
1138 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1139
1140 String sql = query.toString();
1141
1142 Session session = null;
1143
1144 try {
1145 session = openSession();
1146
1147 Query q = session.createQuery(sql);
1148
1149 QueryPos qPos = QueryPos.getInstance(q);
1150
1151 if (uuid != null) {
1152 qPos.add(uuid);
1153 }
1154
1155 qPos.add(groupId);
1156
1157 List<WikiNode> list = q.list();
1158
1159 result = list;
1160
1161 WikiNode wikiNode = null;
1162
1163 if (list.isEmpty()) {
1164 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1165 finderArgs, list);
1166 }
1167 else {
1168 wikiNode = list.get(0);
1169
1170 cacheResult(wikiNode);
1171
1172 if ((wikiNode.getUuid() == null) ||
1173 !wikiNode.getUuid().equals(uuid) ||
1174 (wikiNode.getGroupId() != groupId)) {
1175 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1176 finderArgs, wikiNode);
1177 }
1178 }
1179
1180 return wikiNode;
1181 }
1182 catch (Exception e) {
1183 throw processException(e);
1184 }
1185 finally {
1186 if (result == null) {
1187 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1188 finderArgs);
1189 }
1190
1191 closeSession(session);
1192 }
1193 }
1194 else {
1195 if (result instanceof List<?>) {
1196 return null;
1197 }
1198 else {
1199 return (WikiNode)result;
1200 }
1201 }
1202 }
1203
1204
1211 public List<WikiNode> findByGroupId(long groupId) throws SystemException {
1212 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1213 }
1214
1215
1228 public List<WikiNode> findByGroupId(long groupId, int start, int end)
1229 throws SystemException {
1230 return findByGroupId(groupId, start, end, null);
1231 }
1232
1233
1247 public List<WikiNode> findByGroupId(long groupId, int start, int end,
1248 OrderByComparator orderByComparator) throws SystemException {
1249 FinderPath finderPath = null;
1250 Object[] finderArgs = null;
1251
1252 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1253 (orderByComparator == null)) {
1254 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1255 finderArgs = new Object[] { groupId };
1256 }
1257 else {
1258 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1259 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1260 }
1261
1262 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
1263 finderArgs, this);
1264
1265 if ((list != null) && !list.isEmpty()) {
1266 for (WikiNode wikiNode : list) {
1267 if ((groupId != wikiNode.getGroupId())) {
1268 list = null;
1269
1270 break;
1271 }
1272 }
1273 }
1274
1275 if (list == null) {
1276 StringBundler query = null;
1277
1278 if (orderByComparator != null) {
1279 query = new StringBundler(3 +
1280 (orderByComparator.getOrderByFields().length * 3));
1281 }
1282 else {
1283 query = new StringBundler(3);
1284 }
1285
1286 query.append(_SQL_SELECT_WIKINODE_WHERE);
1287
1288 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1289
1290 if (orderByComparator != null) {
1291 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1292 orderByComparator);
1293 }
1294
1295 else {
1296 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1297 }
1298
1299 String sql = query.toString();
1300
1301 Session session = null;
1302
1303 try {
1304 session = openSession();
1305
1306 Query q = session.createQuery(sql);
1307
1308 QueryPos qPos = QueryPos.getInstance(q);
1309
1310 qPos.add(groupId);
1311
1312 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1313 end);
1314 }
1315 catch (Exception e) {
1316 throw processException(e);
1317 }
1318 finally {
1319 if (list == null) {
1320 FinderCacheUtil.removeResult(finderPath, finderArgs);
1321 }
1322 else {
1323 cacheResult(list);
1324
1325 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1326 }
1327
1328 closeSession(session);
1329 }
1330 }
1331
1332 return list;
1333 }
1334
1335
1344 public WikiNode findByGroupId_First(long groupId,
1345 OrderByComparator orderByComparator)
1346 throws NoSuchNodeException, SystemException {
1347 WikiNode wikiNode = fetchByGroupId_First(groupId, orderByComparator);
1348
1349 if (wikiNode != null) {
1350 return wikiNode;
1351 }
1352
1353 StringBundler msg = new StringBundler(4);
1354
1355 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1356
1357 msg.append("groupId=");
1358 msg.append(groupId);
1359
1360 msg.append(StringPool.CLOSE_CURLY_BRACE);
1361
1362 throw new NoSuchNodeException(msg.toString());
1363 }
1364
1365
1373 public WikiNode fetchByGroupId_First(long groupId,
1374 OrderByComparator orderByComparator) throws SystemException {
1375 List<WikiNode> list = findByGroupId(groupId, 0, 1, orderByComparator);
1376
1377 if (!list.isEmpty()) {
1378 return list.get(0);
1379 }
1380
1381 return null;
1382 }
1383
1384
1393 public WikiNode findByGroupId_Last(long groupId,
1394 OrderByComparator orderByComparator)
1395 throws NoSuchNodeException, SystemException {
1396 WikiNode wikiNode = fetchByGroupId_Last(groupId, orderByComparator);
1397
1398 if (wikiNode != null) {
1399 return wikiNode;
1400 }
1401
1402 StringBundler msg = new StringBundler(4);
1403
1404 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1405
1406 msg.append("groupId=");
1407 msg.append(groupId);
1408
1409 msg.append(StringPool.CLOSE_CURLY_BRACE);
1410
1411 throw new NoSuchNodeException(msg.toString());
1412 }
1413
1414
1422 public WikiNode fetchByGroupId_Last(long groupId,
1423 OrderByComparator orderByComparator) throws SystemException {
1424 int count = countByGroupId(groupId);
1425
1426 List<WikiNode> list = findByGroupId(groupId, count - 1, count,
1427 orderByComparator);
1428
1429 if (!list.isEmpty()) {
1430 return list.get(0);
1431 }
1432
1433 return null;
1434 }
1435
1436
1446 public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
1447 OrderByComparator orderByComparator)
1448 throws NoSuchNodeException, SystemException {
1449 WikiNode wikiNode = findByPrimaryKey(nodeId);
1450
1451 Session session = null;
1452
1453 try {
1454 session = openSession();
1455
1456 WikiNode[] array = new WikiNodeImpl[3];
1457
1458 array[0] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1459 orderByComparator, true);
1460
1461 array[1] = wikiNode;
1462
1463 array[2] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1464 orderByComparator, false);
1465
1466 return array;
1467 }
1468 catch (Exception e) {
1469 throw processException(e);
1470 }
1471 finally {
1472 closeSession(session);
1473 }
1474 }
1475
1476 protected WikiNode getByGroupId_PrevAndNext(Session session,
1477 WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1478 boolean previous) {
1479 StringBundler query = null;
1480
1481 if (orderByComparator != null) {
1482 query = new StringBundler(6 +
1483 (orderByComparator.getOrderByFields().length * 6));
1484 }
1485 else {
1486 query = new StringBundler(3);
1487 }
1488
1489 query.append(_SQL_SELECT_WIKINODE_WHERE);
1490
1491 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1492
1493 if (orderByComparator != null) {
1494 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1495
1496 if (orderByConditionFields.length > 0) {
1497 query.append(WHERE_AND);
1498 }
1499
1500 for (int i = 0; i < orderByConditionFields.length; i++) {
1501 query.append(_ORDER_BY_ENTITY_ALIAS);
1502 query.append(orderByConditionFields[i]);
1503
1504 if ((i + 1) < orderByConditionFields.length) {
1505 if (orderByComparator.isAscending() ^ previous) {
1506 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1507 }
1508 else {
1509 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1510 }
1511 }
1512 else {
1513 if (orderByComparator.isAscending() ^ previous) {
1514 query.append(WHERE_GREATER_THAN);
1515 }
1516 else {
1517 query.append(WHERE_LESSER_THAN);
1518 }
1519 }
1520 }
1521
1522 query.append(ORDER_BY_CLAUSE);
1523
1524 String[] orderByFields = orderByComparator.getOrderByFields();
1525
1526 for (int i = 0; i < orderByFields.length; i++) {
1527 query.append(_ORDER_BY_ENTITY_ALIAS);
1528 query.append(orderByFields[i]);
1529
1530 if ((i + 1) < orderByFields.length) {
1531 if (orderByComparator.isAscending() ^ previous) {
1532 query.append(ORDER_BY_ASC_HAS_NEXT);
1533 }
1534 else {
1535 query.append(ORDER_BY_DESC_HAS_NEXT);
1536 }
1537 }
1538 else {
1539 if (orderByComparator.isAscending() ^ previous) {
1540 query.append(ORDER_BY_ASC);
1541 }
1542 else {
1543 query.append(ORDER_BY_DESC);
1544 }
1545 }
1546 }
1547 }
1548
1549 else {
1550 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1551 }
1552
1553 String sql = query.toString();
1554
1555 Query q = session.createQuery(sql);
1556
1557 q.setFirstResult(0);
1558 q.setMaxResults(2);
1559
1560 QueryPos qPos = QueryPos.getInstance(q);
1561
1562 qPos.add(groupId);
1563
1564 if (orderByComparator != null) {
1565 Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1566
1567 for (Object value : values) {
1568 qPos.add(value);
1569 }
1570 }
1571
1572 List<WikiNode> list = q.list();
1573
1574 if (list.size() == 2) {
1575 return list.get(1);
1576 }
1577 else {
1578 return null;
1579 }
1580 }
1581
1582
1589 public List<WikiNode> filterFindByGroupId(long groupId)
1590 throws SystemException {
1591 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1592 QueryUtil.ALL_POS, null);
1593 }
1594
1595
1608 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end)
1609 throws SystemException {
1610 return filterFindByGroupId(groupId, start, end, null);
1611 }
1612
1613
1627 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end,
1628 OrderByComparator orderByComparator) throws SystemException {
1629 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1630 return findByGroupId(groupId, start, end, orderByComparator);
1631 }
1632
1633 StringBundler query = null;
1634
1635 if (orderByComparator != null) {
1636 query = new StringBundler(3 +
1637 (orderByComparator.getOrderByFields().length * 3));
1638 }
1639 else {
1640 query = new StringBundler(3);
1641 }
1642
1643 if (getDB().isSupportsInlineDistinct()) {
1644 query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1645 }
1646 else {
1647 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
1648 }
1649
1650 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1651
1652 if (!getDB().isSupportsInlineDistinct()) {
1653 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
1654 }
1655
1656 if (orderByComparator != null) {
1657 if (getDB().isSupportsInlineDistinct()) {
1658 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1659 orderByComparator);
1660 }
1661 else {
1662 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1663 orderByComparator);
1664 }
1665 }
1666
1667 else {
1668 if (getDB().isSupportsInlineDistinct()) {
1669 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1670 }
1671 else {
1672 query.append(WikiNodeModelImpl.ORDER_BY_SQL);
1673 }
1674 }
1675
1676 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1677 WikiNode.class.getName(),
1678 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1679
1680 Session session = null;
1681
1682 try {
1683 session = openSession();
1684
1685 SQLQuery q = session.createSQLQuery(sql);
1686
1687 if (getDB().isSupportsInlineDistinct()) {
1688 q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1689 }
1690 else {
1691 q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
1692 }
1693
1694 QueryPos qPos = QueryPos.getInstance(q);
1695
1696 qPos.add(groupId);
1697
1698 return (List<WikiNode>)QueryUtil.list(q, getDialect(), start, end);
1699 }
1700 catch (Exception e) {
1701 throw processException(e);
1702 }
1703 finally {
1704 closeSession(session);
1705 }
1706 }
1707
1708
1718 public WikiNode[] filterFindByGroupId_PrevAndNext(long nodeId,
1719 long groupId, OrderByComparator orderByComparator)
1720 throws NoSuchNodeException, SystemException {
1721 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1722 return findByGroupId_PrevAndNext(nodeId, groupId, orderByComparator);
1723 }
1724
1725 WikiNode wikiNode = findByPrimaryKey(nodeId);
1726
1727 Session session = null;
1728
1729 try {
1730 session = openSession();
1731
1732 WikiNode[] array = new WikiNodeImpl[3];
1733
1734 array[0] = filterGetByGroupId_PrevAndNext(session, wikiNode,
1735 groupId, orderByComparator, true);
1736
1737 array[1] = wikiNode;
1738
1739 array[2] = filterGetByGroupId_PrevAndNext(session, wikiNode,
1740 groupId, orderByComparator, false);
1741
1742 return array;
1743 }
1744 catch (Exception e) {
1745 throw processException(e);
1746 }
1747 finally {
1748 closeSession(session);
1749 }
1750 }
1751
1752 protected WikiNode filterGetByGroupId_PrevAndNext(Session session,
1753 WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1754 boolean previous) {
1755 StringBundler query = null;
1756
1757 if (orderByComparator != null) {
1758 query = new StringBundler(6 +
1759 (orderByComparator.getOrderByFields().length * 6));
1760 }
1761 else {
1762 query = new StringBundler(3);
1763 }
1764
1765 if (getDB().isSupportsInlineDistinct()) {
1766 query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1767 }
1768 else {
1769 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
1770 }
1771
1772 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1773
1774 if (!getDB().isSupportsInlineDistinct()) {
1775 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
1776 }
1777
1778 if (orderByComparator != null) {
1779 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1780
1781 if (orderByConditionFields.length > 0) {
1782 query.append(WHERE_AND);
1783 }
1784
1785 for (int i = 0; i < orderByConditionFields.length; i++) {
1786 if (getDB().isSupportsInlineDistinct()) {
1787 query.append(_ORDER_BY_ENTITY_ALIAS);
1788 }
1789 else {
1790 query.append(_ORDER_BY_ENTITY_TABLE);
1791 }
1792
1793 query.append(orderByConditionFields[i]);
1794
1795 if ((i + 1) < orderByConditionFields.length) {
1796 if (orderByComparator.isAscending() ^ previous) {
1797 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1798 }
1799 else {
1800 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1801 }
1802 }
1803 else {
1804 if (orderByComparator.isAscending() ^ previous) {
1805 query.append(WHERE_GREATER_THAN);
1806 }
1807 else {
1808 query.append(WHERE_LESSER_THAN);
1809 }
1810 }
1811 }
1812
1813 query.append(ORDER_BY_CLAUSE);
1814
1815 String[] orderByFields = orderByComparator.getOrderByFields();
1816
1817 for (int i = 0; i < orderByFields.length; i++) {
1818 if (getDB().isSupportsInlineDistinct()) {
1819 query.append(_ORDER_BY_ENTITY_ALIAS);
1820 }
1821 else {
1822 query.append(_ORDER_BY_ENTITY_TABLE);
1823 }
1824
1825 query.append(orderByFields[i]);
1826
1827 if ((i + 1) < orderByFields.length) {
1828 if (orderByComparator.isAscending() ^ previous) {
1829 query.append(ORDER_BY_ASC_HAS_NEXT);
1830 }
1831 else {
1832 query.append(ORDER_BY_DESC_HAS_NEXT);
1833 }
1834 }
1835 else {
1836 if (orderByComparator.isAscending() ^ previous) {
1837 query.append(ORDER_BY_ASC);
1838 }
1839 else {
1840 query.append(ORDER_BY_DESC);
1841 }
1842 }
1843 }
1844 }
1845
1846 else {
1847 if (getDB().isSupportsInlineDistinct()) {
1848 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1849 }
1850 else {
1851 query.append(WikiNodeModelImpl.ORDER_BY_SQL);
1852 }
1853 }
1854
1855 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1856 WikiNode.class.getName(),
1857 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1858
1859 SQLQuery q = session.createSQLQuery(sql);
1860
1861 q.setFirstResult(0);
1862 q.setMaxResults(2);
1863
1864 if (getDB().isSupportsInlineDistinct()) {
1865 q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1866 }
1867 else {
1868 q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
1869 }
1870
1871 QueryPos qPos = QueryPos.getInstance(q);
1872
1873 qPos.add(groupId);
1874
1875 if (orderByComparator != null) {
1876 Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1877
1878 for (Object value : values) {
1879 qPos.add(value);
1880 }
1881 }
1882
1883 List<WikiNode> list = q.list();
1884
1885 if (list.size() == 2) {
1886 return list.get(1);
1887 }
1888 else {
1889 return null;
1890 }
1891 }
1892
1893
1900 public List<WikiNode> findByCompanyId(long companyId)
1901 throws SystemException {
1902 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1903 null);
1904 }
1905
1906
1919 public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1920 throws SystemException {
1921 return findByCompanyId(companyId, start, end, null);
1922 }
1923
1924
1938 public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1939 OrderByComparator orderByComparator) throws SystemException {
1940 FinderPath finderPath = null;
1941 Object[] finderArgs = null;
1942
1943 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1944 (orderByComparator == null)) {
1945 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1946 finderArgs = new Object[] { companyId };
1947 }
1948 else {
1949 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1950 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1951 }
1952
1953 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
1954 finderArgs, this);
1955
1956 if ((list != null) && !list.isEmpty()) {
1957 for (WikiNode wikiNode : list) {
1958 if ((companyId != wikiNode.getCompanyId())) {
1959 list = null;
1960
1961 break;
1962 }
1963 }
1964 }
1965
1966 if (list == null) {
1967 StringBundler query = null;
1968
1969 if (orderByComparator != null) {
1970 query = new StringBundler(3 +
1971 (orderByComparator.getOrderByFields().length * 3));
1972 }
1973 else {
1974 query = new StringBundler(3);
1975 }
1976
1977 query.append(_SQL_SELECT_WIKINODE_WHERE);
1978
1979 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1980
1981 if (orderByComparator != null) {
1982 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1983 orderByComparator);
1984 }
1985
1986 else {
1987 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1988 }
1989
1990 String sql = query.toString();
1991
1992 Session session = null;
1993
1994 try {
1995 session = openSession();
1996
1997 Query q = session.createQuery(sql);
1998
1999 QueryPos qPos = QueryPos.getInstance(q);
2000
2001 qPos.add(companyId);
2002
2003 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
2004 end);
2005 }
2006 catch (Exception e) {
2007 throw processException(e);
2008 }
2009 finally {
2010 if (list == null) {
2011 FinderCacheUtil.removeResult(finderPath, finderArgs);
2012 }
2013 else {
2014 cacheResult(list);
2015
2016 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2017 }
2018
2019 closeSession(session);
2020 }
2021 }
2022
2023 return list;
2024 }
2025
2026
2035 public WikiNode findByCompanyId_First(long companyId,
2036 OrderByComparator orderByComparator)
2037 throws NoSuchNodeException, SystemException {
2038 WikiNode wikiNode = fetchByCompanyId_First(companyId, orderByComparator);
2039
2040 if (wikiNode != null) {
2041 return wikiNode;
2042 }
2043
2044 StringBundler msg = new StringBundler(4);
2045
2046 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2047
2048 msg.append("companyId=");
2049 msg.append(companyId);
2050
2051 msg.append(StringPool.CLOSE_CURLY_BRACE);
2052
2053 throw new NoSuchNodeException(msg.toString());
2054 }
2055
2056
2064 public WikiNode fetchByCompanyId_First(long companyId,
2065 OrderByComparator orderByComparator) throws SystemException {
2066 List<WikiNode> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2067
2068 if (!list.isEmpty()) {
2069 return list.get(0);
2070 }
2071
2072 return null;
2073 }
2074
2075
2084 public WikiNode findByCompanyId_Last(long companyId,
2085 OrderByComparator orderByComparator)
2086 throws NoSuchNodeException, SystemException {
2087 WikiNode wikiNode = fetchByCompanyId_Last(companyId, orderByComparator);
2088
2089 if (wikiNode != null) {
2090 return wikiNode;
2091 }
2092
2093 StringBundler msg = new StringBundler(4);
2094
2095 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2096
2097 msg.append("companyId=");
2098 msg.append(companyId);
2099
2100 msg.append(StringPool.CLOSE_CURLY_BRACE);
2101
2102 throw new NoSuchNodeException(msg.toString());
2103 }
2104
2105
2113 public WikiNode fetchByCompanyId_Last(long companyId,
2114 OrderByComparator orderByComparator) throws SystemException {
2115 int count = countByCompanyId(companyId);
2116
2117 List<WikiNode> list = findByCompanyId(companyId, count - 1, count,
2118 orderByComparator);
2119
2120 if (!list.isEmpty()) {
2121 return list.get(0);
2122 }
2123
2124 return null;
2125 }
2126
2127
2137 public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
2138 OrderByComparator orderByComparator)
2139 throws NoSuchNodeException, SystemException {
2140 WikiNode wikiNode = findByPrimaryKey(nodeId);
2141
2142 Session session = null;
2143
2144 try {
2145 session = openSession();
2146
2147 WikiNode[] array = new WikiNodeImpl[3];
2148
2149 array[0] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
2150 orderByComparator, true);
2151
2152 array[1] = wikiNode;
2153
2154 array[2] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
2155 orderByComparator, false);
2156
2157 return array;
2158 }
2159 catch (Exception e) {
2160 throw processException(e);
2161 }
2162 finally {
2163 closeSession(session);
2164 }
2165 }
2166
2167 protected WikiNode getByCompanyId_PrevAndNext(Session session,
2168 WikiNode wikiNode, long companyId, OrderByComparator orderByComparator,
2169 boolean previous) {
2170 StringBundler query = null;
2171
2172 if (orderByComparator != null) {
2173 query = new StringBundler(6 +
2174 (orderByComparator.getOrderByFields().length * 6));
2175 }
2176 else {
2177 query = new StringBundler(3);
2178 }
2179
2180 query.append(_SQL_SELECT_WIKINODE_WHERE);
2181
2182 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2183
2184 if (orderByComparator != null) {
2185 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2186
2187 if (orderByConditionFields.length > 0) {
2188 query.append(WHERE_AND);
2189 }
2190
2191 for (int i = 0; i < orderByConditionFields.length; i++) {
2192 query.append(_ORDER_BY_ENTITY_ALIAS);
2193 query.append(orderByConditionFields[i]);
2194
2195 if ((i + 1) < orderByConditionFields.length) {
2196 if (orderByComparator.isAscending() ^ previous) {
2197 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2198 }
2199 else {
2200 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2201 }
2202 }
2203 else {
2204 if (orderByComparator.isAscending() ^ previous) {
2205 query.append(WHERE_GREATER_THAN);
2206 }
2207 else {
2208 query.append(WHERE_LESSER_THAN);
2209 }
2210 }
2211 }
2212
2213 query.append(ORDER_BY_CLAUSE);
2214
2215 String[] orderByFields = orderByComparator.getOrderByFields();
2216
2217 for (int i = 0; i < orderByFields.length; i++) {
2218 query.append(_ORDER_BY_ENTITY_ALIAS);
2219 query.append(orderByFields[i]);
2220
2221 if ((i + 1) < orderByFields.length) {
2222 if (orderByComparator.isAscending() ^ previous) {
2223 query.append(ORDER_BY_ASC_HAS_NEXT);
2224 }
2225 else {
2226 query.append(ORDER_BY_DESC_HAS_NEXT);
2227 }
2228 }
2229 else {
2230 if (orderByComparator.isAscending() ^ previous) {
2231 query.append(ORDER_BY_ASC);
2232 }
2233 else {
2234 query.append(ORDER_BY_DESC);
2235 }
2236 }
2237 }
2238 }
2239
2240 else {
2241 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2242 }
2243
2244 String sql = query.toString();
2245
2246 Query q = session.createQuery(sql);
2247
2248 q.setFirstResult(0);
2249 q.setMaxResults(2);
2250
2251 QueryPos qPos = QueryPos.getInstance(q);
2252
2253 qPos.add(companyId);
2254
2255 if (orderByComparator != null) {
2256 Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
2257
2258 for (Object value : values) {
2259 qPos.add(value);
2260 }
2261 }
2262
2263 List<WikiNode> list = q.list();
2264
2265 if (list.size() == 2) {
2266 return list.get(1);
2267 }
2268 else {
2269 return null;
2270 }
2271 }
2272
2273
2282 public WikiNode findByG_N(long groupId, String name)
2283 throws NoSuchNodeException, SystemException {
2284 WikiNode wikiNode = fetchByG_N(groupId, name);
2285
2286 if (wikiNode == null) {
2287 StringBundler msg = new StringBundler(6);
2288
2289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2290
2291 msg.append("groupId=");
2292 msg.append(groupId);
2293
2294 msg.append(", name=");
2295 msg.append(name);
2296
2297 msg.append(StringPool.CLOSE_CURLY_BRACE);
2298
2299 if (_log.isWarnEnabled()) {
2300 _log.warn(msg.toString());
2301 }
2302
2303 throw new NoSuchNodeException(msg.toString());
2304 }
2305
2306 return wikiNode;
2307 }
2308
2309
2317 public WikiNode fetchByG_N(long groupId, String name)
2318 throws SystemException {
2319 return fetchByG_N(groupId, name, true);
2320 }
2321
2322
2331 public WikiNode fetchByG_N(long groupId, String name,
2332 boolean retrieveFromCache) throws SystemException {
2333 Object[] finderArgs = new Object[] { groupId, name };
2334
2335 Object result = null;
2336
2337 if (retrieveFromCache) {
2338 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
2339 finderArgs, this);
2340 }
2341
2342 if (result instanceof WikiNode) {
2343 WikiNode wikiNode = (WikiNode)result;
2344
2345 if ((groupId != wikiNode.getGroupId()) ||
2346 !Validator.equals(name, wikiNode.getName())) {
2347 result = null;
2348 }
2349 }
2350
2351 if (result == null) {
2352 StringBundler query = new StringBundler(4);
2353
2354 query.append(_SQL_SELECT_WIKINODE_WHERE);
2355
2356 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2357
2358 if (name == null) {
2359 query.append(_FINDER_COLUMN_G_N_NAME_1);
2360 }
2361 else {
2362 if (name.equals(StringPool.BLANK)) {
2363 query.append(_FINDER_COLUMN_G_N_NAME_3);
2364 }
2365 else {
2366 query.append(_FINDER_COLUMN_G_N_NAME_2);
2367 }
2368 }
2369
2370 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2371
2372 String sql = query.toString();
2373
2374 Session session = null;
2375
2376 try {
2377 session = openSession();
2378
2379 Query q = session.createQuery(sql);
2380
2381 QueryPos qPos = QueryPos.getInstance(q);
2382
2383 qPos.add(groupId);
2384
2385 if (name != null) {
2386 qPos.add(name);
2387 }
2388
2389 List<WikiNode> list = q.list();
2390
2391 result = list;
2392
2393 WikiNode wikiNode = null;
2394
2395 if (list.isEmpty()) {
2396 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2397 finderArgs, list);
2398 }
2399 else {
2400 wikiNode = list.get(0);
2401
2402 cacheResult(wikiNode);
2403
2404 if ((wikiNode.getGroupId() != groupId) ||
2405 (wikiNode.getName() == null) ||
2406 !wikiNode.getName().equals(name)) {
2407 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2408 finderArgs, wikiNode);
2409 }
2410 }
2411
2412 return wikiNode;
2413 }
2414 catch (Exception e) {
2415 throw processException(e);
2416 }
2417 finally {
2418 if (result == null) {
2419 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
2420 finderArgs);
2421 }
2422
2423 closeSession(session);
2424 }
2425 }
2426 else {
2427 if (result instanceof List<?>) {
2428 return null;
2429 }
2430 else {
2431 return (WikiNode)result;
2432 }
2433 }
2434 }
2435
2436
2442 public List<WikiNode> findAll() throws SystemException {
2443 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2444 }
2445
2446
2458 public List<WikiNode> findAll(int start, int end) throws SystemException {
2459 return findAll(start, end, null);
2460 }
2461
2462
2475 public List<WikiNode> findAll(int start, int end,
2476 OrderByComparator orderByComparator) throws SystemException {
2477 FinderPath finderPath = null;
2478 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2479
2480 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2481 (orderByComparator == null)) {
2482 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2483 finderArgs = FINDER_ARGS_EMPTY;
2484 }
2485 else {
2486 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2487 finderArgs = new Object[] { start, end, orderByComparator };
2488 }
2489
2490 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
2491 finderArgs, this);
2492
2493 if (list == null) {
2494 StringBundler query = null;
2495 String sql = null;
2496
2497 if (orderByComparator != null) {
2498 query = new StringBundler(2 +
2499 (orderByComparator.getOrderByFields().length * 3));
2500
2501 query.append(_SQL_SELECT_WIKINODE);
2502
2503 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2504 orderByComparator);
2505
2506 sql = query.toString();
2507 }
2508 else {
2509 sql = _SQL_SELECT_WIKINODE.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
2510 }
2511
2512 Session session = null;
2513
2514 try {
2515 session = openSession();
2516
2517 Query q = session.createQuery(sql);
2518
2519 if (orderByComparator == null) {
2520 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2521 start, end, false);
2522
2523 Collections.sort(list);
2524 }
2525 else {
2526 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2527 start, end);
2528 }
2529 }
2530 catch (Exception e) {
2531 throw processException(e);
2532 }
2533 finally {
2534 if (list == null) {
2535 FinderCacheUtil.removeResult(finderPath, finderArgs);
2536 }
2537 else {
2538 cacheResult(list);
2539
2540 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2541 }
2542
2543 closeSession(session);
2544 }
2545 }
2546
2547 return list;
2548 }
2549
2550
2556 public void removeByUuid(String uuid) throws SystemException {
2557 for (WikiNode wikiNode : findByUuid(uuid)) {
2558 remove(wikiNode);
2559 }
2560 }
2561
2562
2570 public WikiNode removeByUUID_G(String uuid, long groupId)
2571 throws NoSuchNodeException, SystemException {
2572 WikiNode wikiNode = findByUUID_G(uuid, groupId);
2573
2574 return remove(wikiNode);
2575 }
2576
2577
2583 public void removeByGroupId(long groupId) throws SystemException {
2584 for (WikiNode wikiNode : findByGroupId(groupId)) {
2585 remove(wikiNode);
2586 }
2587 }
2588
2589
2595 public void removeByCompanyId(long companyId) throws SystemException {
2596 for (WikiNode wikiNode : findByCompanyId(companyId)) {
2597 remove(wikiNode);
2598 }
2599 }
2600
2601
2609 public WikiNode removeByG_N(long groupId, String name)
2610 throws NoSuchNodeException, SystemException {
2611 WikiNode wikiNode = findByG_N(groupId, name);
2612
2613 return remove(wikiNode);
2614 }
2615
2616
2621 public void removeAll() throws SystemException {
2622 for (WikiNode wikiNode : findAll()) {
2623 remove(wikiNode);
2624 }
2625 }
2626
2627
2634 public int countByUuid(String uuid) throws SystemException {
2635 Object[] finderArgs = new Object[] { uuid };
2636
2637 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2638 finderArgs, this);
2639
2640 if (count == null) {
2641 StringBundler query = new StringBundler(2);
2642
2643 query.append(_SQL_COUNT_WIKINODE_WHERE);
2644
2645 if (uuid == null) {
2646 query.append(_FINDER_COLUMN_UUID_UUID_1);
2647 }
2648 else {
2649 if (uuid.equals(StringPool.BLANK)) {
2650 query.append(_FINDER_COLUMN_UUID_UUID_3);
2651 }
2652 else {
2653 query.append(_FINDER_COLUMN_UUID_UUID_2);
2654 }
2655 }
2656
2657 String sql = query.toString();
2658
2659 Session session = null;
2660
2661 try {
2662 session = openSession();
2663
2664 Query q = session.createQuery(sql);
2665
2666 QueryPos qPos = QueryPos.getInstance(q);
2667
2668 if (uuid != null) {
2669 qPos.add(uuid);
2670 }
2671
2672 count = (Long)q.uniqueResult();
2673 }
2674 catch (Exception e) {
2675 throw processException(e);
2676 }
2677 finally {
2678 if (count == null) {
2679 count = Long.valueOf(0);
2680 }
2681
2682 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2683 finderArgs, count);
2684
2685 closeSession(session);
2686 }
2687 }
2688
2689 return count.intValue();
2690 }
2691
2692
2700 public int countByUUID_G(String uuid, long groupId)
2701 throws SystemException {
2702 Object[] finderArgs = new Object[] { uuid, groupId };
2703
2704 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2705 finderArgs, this);
2706
2707 if (count == null) {
2708 StringBundler query = new StringBundler(3);
2709
2710 query.append(_SQL_COUNT_WIKINODE_WHERE);
2711
2712 if (uuid == null) {
2713 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2714 }
2715 else {
2716 if (uuid.equals(StringPool.BLANK)) {
2717 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2718 }
2719 else {
2720 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2721 }
2722 }
2723
2724 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2725
2726 String sql = query.toString();
2727
2728 Session session = null;
2729
2730 try {
2731 session = openSession();
2732
2733 Query q = session.createQuery(sql);
2734
2735 QueryPos qPos = QueryPos.getInstance(q);
2736
2737 if (uuid != null) {
2738 qPos.add(uuid);
2739 }
2740
2741 qPos.add(groupId);
2742
2743 count = (Long)q.uniqueResult();
2744 }
2745 catch (Exception e) {
2746 throw processException(e);
2747 }
2748 finally {
2749 if (count == null) {
2750 count = Long.valueOf(0);
2751 }
2752
2753 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2754 finderArgs, count);
2755
2756 closeSession(session);
2757 }
2758 }
2759
2760 return count.intValue();
2761 }
2762
2763
2770 public int countByGroupId(long groupId) throws SystemException {
2771 Object[] finderArgs = new Object[] { groupId };
2772
2773 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2774 finderArgs, this);
2775
2776 if (count == null) {
2777 StringBundler query = new StringBundler(2);
2778
2779 query.append(_SQL_COUNT_WIKINODE_WHERE);
2780
2781 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2782
2783 String sql = query.toString();
2784
2785 Session session = null;
2786
2787 try {
2788 session = openSession();
2789
2790 Query q = session.createQuery(sql);
2791
2792 QueryPos qPos = QueryPos.getInstance(q);
2793
2794 qPos.add(groupId);
2795
2796 count = (Long)q.uniqueResult();
2797 }
2798 catch (Exception e) {
2799 throw processException(e);
2800 }
2801 finally {
2802 if (count == null) {
2803 count = Long.valueOf(0);
2804 }
2805
2806 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2807 finderArgs, count);
2808
2809 closeSession(session);
2810 }
2811 }
2812
2813 return count.intValue();
2814 }
2815
2816
2823 public int filterCountByGroupId(long groupId) throws SystemException {
2824 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2825 return countByGroupId(groupId);
2826 }
2827
2828 StringBundler query = new StringBundler(2);
2829
2830 query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2831
2832 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2833
2834 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2835 WikiNode.class.getName(),
2836 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2837
2838 Session session = null;
2839
2840 try {
2841 session = openSession();
2842
2843 SQLQuery q = session.createSQLQuery(sql);
2844
2845 q.addScalar(COUNT_COLUMN_NAME,
2846 com.liferay.portal.kernel.dao.orm.Type.LONG);
2847
2848 QueryPos qPos = QueryPos.getInstance(q);
2849
2850 qPos.add(groupId);
2851
2852 Long count = (Long)q.uniqueResult();
2853
2854 return count.intValue();
2855 }
2856 catch (Exception e) {
2857 throw processException(e);
2858 }
2859 finally {
2860 closeSession(session);
2861 }
2862 }
2863
2864
2871 public int countByCompanyId(long companyId) throws SystemException {
2872 Object[] finderArgs = new Object[] { companyId };
2873
2874 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2875 finderArgs, this);
2876
2877 if (count == null) {
2878 StringBundler query = new StringBundler(2);
2879
2880 query.append(_SQL_COUNT_WIKINODE_WHERE);
2881
2882 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2883
2884 String sql = query.toString();
2885
2886 Session session = null;
2887
2888 try {
2889 session = openSession();
2890
2891 Query q = session.createQuery(sql);
2892
2893 QueryPos qPos = QueryPos.getInstance(q);
2894
2895 qPos.add(companyId);
2896
2897 count = (Long)q.uniqueResult();
2898 }
2899 catch (Exception e) {
2900 throw processException(e);
2901 }
2902 finally {
2903 if (count == null) {
2904 count = Long.valueOf(0);
2905 }
2906
2907 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2908 finderArgs, count);
2909
2910 closeSession(session);
2911 }
2912 }
2913
2914 return count.intValue();
2915 }
2916
2917
2925 public int countByG_N(long groupId, String name) throws SystemException {
2926 Object[] finderArgs = new Object[] { groupId, name };
2927
2928 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
2929 finderArgs, this);
2930
2931 if (count == null) {
2932 StringBundler query = new StringBundler(3);
2933
2934 query.append(_SQL_COUNT_WIKINODE_WHERE);
2935
2936 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2937
2938 if (name == null) {
2939 query.append(_FINDER_COLUMN_G_N_NAME_1);
2940 }
2941 else {
2942 if (name.equals(StringPool.BLANK)) {
2943 query.append(_FINDER_COLUMN_G_N_NAME_3);
2944 }
2945 else {
2946 query.append(_FINDER_COLUMN_G_N_NAME_2);
2947 }
2948 }
2949
2950 String sql = query.toString();
2951
2952 Session session = null;
2953
2954 try {
2955 session = openSession();
2956
2957 Query q = session.createQuery(sql);
2958
2959 QueryPos qPos = QueryPos.getInstance(q);
2960
2961 qPos.add(groupId);
2962
2963 if (name != null) {
2964 qPos.add(name);
2965 }
2966
2967 count = (Long)q.uniqueResult();
2968 }
2969 catch (Exception e) {
2970 throw processException(e);
2971 }
2972 finally {
2973 if (count == null) {
2974 count = Long.valueOf(0);
2975 }
2976
2977 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
2978 count);
2979
2980 closeSession(session);
2981 }
2982 }
2983
2984 return count.intValue();
2985 }
2986
2987
2993 public int countAll() throws SystemException {
2994 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2995 FINDER_ARGS_EMPTY, this);
2996
2997 if (count == null) {
2998 Session session = null;
2999
3000 try {
3001 session = openSession();
3002
3003 Query q = session.createQuery(_SQL_COUNT_WIKINODE);
3004
3005 count = (Long)q.uniqueResult();
3006 }
3007 catch (Exception e) {
3008 throw processException(e);
3009 }
3010 finally {
3011 if (count == null) {
3012 count = Long.valueOf(0);
3013 }
3014
3015 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3016 FINDER_ARGS_EMPTY, count);
3017
3018 closeSession(session);
3019 }
3020 }
3021
3022 return count.intValue();
3023 }
3024
3025
3028 public void afterPropertiesSet() {
3029 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3030 com.liferay.portal.util.PropsUtil.get(
3031 "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
3032
3033 if (listenerClassNames.length > 0) {
3034 try {
3035 List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
3036
3037 for (String listenerClassName : listenerClassNames) {
3038 listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
3039 listenerClassName));
3040 }
3041
3042 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3043 }
3044 catch (Exception e) {
3045 _log.error(e);
3046 }
3047 }
3048 }
3049
3050 public void destroy() {
3051 EntityCacheUtil.removeCache(WikiNodeImpl.class.getName());
3052 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3053 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3054 }
3055
3056 @BeanReference(type = WikiNodePersistence.class)
3057 protected WikiNodePersistence wikiNodePersistence;
3058 @BeanReference(type = WikiPagePersistence.class)
3059 protected WikiPagePersistence wikiPagePersistence;
3060 @BeanReference(type = WikiPageResourcePersistence.class)
3061 protected WikiPageResourcePersistence wikiPageResourcePersistence;
3062 @BeanReference(type = GroupPersistence.class)
3063 protected GroupPersistence groupPersistence;
3064 @BeanReference(type = ResourcePersistence.class)
3065 protected ResourcePersistence resourcePersistence;
3066 @BeanReference(type = SubscriptionPersistence.class)
3067 protected SubscriptionPersistence subscriptionPersistence;
3068 @BeanReference(type = UserPersistence.class)
3069 protected UserPersistence userPersistence;
3070 private static final String _SQL_SELECT_WIKINODE = "SELECT wikiNode FROM WikiNode wikiNode";
3071 private static final String _SQL_SELECT_WIKINODE_WHERE = "SELECT wikiNode FROM WikiNode wikiNode WHERE ";
3072 private static final String _SQL_COUNT_WIKINODE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode";
3073 private static final String _SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode WHERE ";
3074 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiNode.uuid IS NULL";
3075 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiNode.uuid = ?";
3076 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?)";
3077 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiNode.uuid IS NULL AND ";
3078 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiNode.uuid = ? AND ";
3079 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?) AND ";
3080 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiNode.groupId = ?";
3081 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "wikiNode.groupId = ?";
3082 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "wikiNode.companyId = ?";
3083 private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "wikiNode.groupId = ? AND ";
3084 private static final String _FINDER_COLUMN_G_N_NAME_1 = "wikiNode.name IS NULL";
3085 private static final String _FINDER_COLUMN_G_N_NAME_2 = "wikiNode.name = ?";
3086 private static final String _FINDER_COLUMN_G_N_NAME_3 = "(wikiNode.name IS NULL OR wikiNode.name = ?)";
3087 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiNode.nodeId";
3088 private static final String _FILTER_SQL_SELECT_WIKINODE_WHERE = "SELECT DISTINCT {wikiNode.*} FROM WikiNode wikiNode WHERE ";
3089 private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1 =
3090 "SELECT {WikiNode.*} FROM (SELECT DISTINCT wikiNode.nodeId FROM WikiNode wikiNode WHERE ";
3091 private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2 =
3092 ") TEMP_TABLE INNER JOIN WikiNode ON TEMP_TABLE.nodeId = WikiNode.nodeId";
3093 private static final String _FILTER_SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(DISTINCT wikiNode.nodeId) AS COUNT_VALUE FROM WikiNode wikiNode WHERE ";
3094 private static final String _FILTER_ENTITY_ALIAS = "wikiNode";
3095 private static final String _FILTER_ENTITY_TABLE = "WikiNode";
3096 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
3097 private static final String _ORDER_BY_ENTITY_TABLE = "WikiNode.";
3098 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
3099 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
3100 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3101 private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
3102 private static WikiNode _nullWikiNode = new WikiNodeImpl() {
3103 @Override
3104 public Object clone() {
3105 return this;
3106 }
3107
3108 @Override
3109 public CacheModel<WikiNode> toCacheModel() {
3110 return _nullWikiNodeCacheModel;
3111 }
3112 };
3113
3114 private static CacheModel<WikiNode> _nullWikiNodeCacheModel = new CacheModel<WikiNode>() {
3115 public WikiNode toEntityModel() {
3116 return _nullWikiNode;
3117 }
3118 };
3119 }