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 else {
403 if ((wikiNodeModelImpl.getColumnBitmask() &
404 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
405 Object[] args = new Object[] { wikiNodeModelImpl.getOriginalUuid() };
406
407 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
408 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
409 args);
410
411 args = new Object[] { wikiNodeModelImpl.getUuid() };
412
413 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
414 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
415 args);
416 }
417
418 if ((wikiNodeModelImpl.getColumnBitmask() &
419 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
420 Object[] args = new Object[] {
421 Long.valueOf(wikiNodeModelImpl.getOriginalGroupId())
422 };
423
424 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
425 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
426 args);
427
428 args = new Object[] { Long.valueOf(wikiNodeModelImpl.getGroupId()) };
429
430 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
431 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
432 args);
433 }
434
435 if ((wikiNodeModelImpl.getColumnBitmask() &
436 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
437 Object[] args = new Object[] {
438 Long.valueOf(wikiNodeModelImpl.getOriginalCompanyId())
439 };
440
441 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
442 args);
443 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
444 args);
445
446 args = new Object[] {
447 Long.valueOf(wikiNodeModelImpl.getCompanyId())
448 };
449
450 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
451 args);
452 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
453 args);
454 }
455 }
456
457 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
458 WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
459
460 if (isNew) {
461 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
462 new Object[] {
463 wikiNode.getUuid(), Long.valueOf(wikiNode.getGroupId())
464 }, wikiNode);
465
466 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
467 new Object[] {
468 Long.valueOf(wikiNode.getGroupId()),
469
470 wikiNode.getName()
471 }, wikiNode);
472 }
473 else {
474 if ((wikiNodeModelImpl.getColumnBitmask() &
475 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
476 Object[] args = new Object[] {
477 wikiNodeModelImpl.getOriginalUuid(),
478 Long.valueOf(wikiNodeModelImpl.getOriginalGroupId())
479 };
480
481 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
482 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
483
484 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
485 new Object[] {
486 wikiNode.getUuid(), Long.valueOf(wikiNode.getGroupId())
487 }, wikiNode);
488 }
489
490 if ((wikiNodeModelImpl.getColumnBitmask() &
491 FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
492 Object[] args = new Object[] {
493 Long.valueOf(wikiNodeModelImpl.getOriginalGroupId()),
494
495 wikiNodeModelImpl.getOriginalName()
496 };
497
498 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
499 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
500
501 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
502 new Object[] {
503 Long.valueOf(wikiNode.getGroupId()),
504
505 wikiNode.getName()
506 }, wikiNode);
507 }
508 }
509
510 return wikiNode;
511 }
512
513 protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
514 if (wikiNode instanceof WikiNodeImpl) {
515 return wikiNode;
516 }
517
518 WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
519
520 wikiNodeImpl.setNew(wikiNode.isNew());
521 wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
522
523 wikiNodeImpl.setUuid(wikiNode.getUuid());
524 wikiNodeImpl.setNodeId(wikiNode.getNodeId());
525 wikiNodeImpl.setGroupId(wikiNode.getGroupId());
526 wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
527 wikiNodeImpl.setUserId(wikiNode.getUserId());
528 wikiNodeImpl.setUserName(wikiNode.getUserName());
529 wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
530 wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
531 wikiNodeImpl.setName(wikiNode.getName());
532 wikiNodeImpl.setDescription(wikiNode.getDescription());
533 wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
534
535 return wikiNodeImpl;
536 }
537
538
546 @Override
547 public WikiNode findByPrimaryKey(Serializable primaryKey)
548 throws NoSuchModelException, SystemException {
549 return findByPrimaryKey(((Long)primaryKey).longValue());
550 }
551
552
560 public WikiNode findByPrimaryKey(long nodeId)
561 throws NoSuchNodeException, SystemException {
562 WikiNode wikiNode = fetchByPrimaryKey(nodeId);
563
564 if (wikiNode == null) {
565 if (_log.isWarnEnabled()) {
566 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
567 }
568
569 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
570 nodeId);
571 }
572
573 return wikiNode;
574 }
575
576
583 @Override
584 public WikiNode fetchByPrimaryKey(Serializable primaryKey)
585 throws SystemException {
586 return fetchByPrimaryKey(((Long)primaryKey).longValue());
587 }
588
589
596 public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
597 WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
598 WikiNodeImpl.class, nodeId);
599
600 if (wikiNode == _nullWikiNode) {
601 return null;
602 }
603
604 if (wikiNode == null) {
605 Session session = null;
606
607 boolean hasException = false;
608
609 try {
610 session = openSession();
611
612 wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
613 Long.valueOf(nodeId));
614 }
615 catch (Exception e) {
616 hasException = true;
617
618 throw processException(e);
619 }
620 finally {
621 if (wikiNode != null) {
622 cacheResult(wikiNode);
623 }
624 else if (!hasException) {
625 EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
626 WikiNodeImpl.class, nodeId, _nullWikiNode);
627 }
628
629 closeSession(session);
630 }
631 }
632
633 return wikiNode;
634 }
635
636
643 public List<WikiNode> findByUuid(String uuid) throws SystemException {
644 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
645 }
646
647
660 public List<WikiNode> findByUuid(String uuid, int start, int end)
661 throws SystemException {
662 return findByUuid(uuid, start, end, null);
663 }
664
665
679 public List<WikiNode> findByUuid(String uuid, int start, int end,
680 OrderByComparator orderByComparator) throws SystemException {
681 FinderPath finderPath = null;
682 Object[] finderArgs = null;
683
684 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
685 (orderByComparator == null)) {
686 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
687 finderArgs = new Object[] { uuid };
688 }
689 else {
690 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
691 finderArgs = new Object[] { uuid, start, end, orderByComparator };
692 }
693
694 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
695 finderArgs, this);
696
697 if ((list != null) && !list.isEmpty()) {
698 for (WikiNode wikiNode : list) {
699 if (!Validator.equals(uuid, wikiNode.getUuid())) {
700 list = null;
701
702 break;
703 }
704 }
705 }
706
707 if (list == null) {
708 StringBundler query = null;
709
710 if (orderByComparator != null) {
711 query = new StringBundler(3 +
712 (orderByComparator.getOrderByFields().length * 3));
713 }
714 else {
715 query = new StringBundler(3);
716 }
717
718 query.append(_SQL_SELECT_WIKINODE_WHERE);
719
720 if (uuid == null) {
721 query.append(_FINDER_COLUMN_UUID_UUID_1);
722 }
723 else {
724 if (uuid.equals(StringPool.BLANK)) {
725 query.append(_FINDER_COLUMN_UUID_UUID_3);
726 }
727 else {
728 query.append(_FINDER_COLUMN_UUID_UUID_2);
729 }
730 }
731
732 if (orderByComparator != null) {
733 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
734 orderByComparator);
735 }
736
737 else {
738 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
739 }
740
741 String sql = query.toString();
742
743 Session session = null;
744
745 try {
746 session = openSession();
747
748 Query q = session.createQuery(sql);
749
750 QueryPos qPos = QueryPos.getInstance(q);
751
752 if (uuid != null) {
753 qPos.add(uuid);
754 }
755
756 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
757 end);
758 }
759 catch (Exception e) {
760 throw processException(e);
761 }
762 finally {
763 if (list == null) {
764 FinderCacheUtil.removeResult(finderPath, finderArgs);
765 }
766 else {
767 cacheResult(list);
768
769 FinderCacheUtil.putResult(finderPath, finderArgs, list);
770 }
771
772 closeSession(session);
773 }
774 }
775
776 return list;
777 }
778
779
792 public WikiNode findByUuid_First(String uuid,
793 OrderByComparator orderByComparator)
794 throws NoSuchNodeException, SystemException {
795 List<WikiNode> list = findByUuid(uuid, 0, 1, orderByComparator);
796
797 if (list.isEmpty()) {
798 StringBundler msg = new StringBundler(4);
799
800 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
801
802 msg.append("uuid=");
803 msg.append(uuid);
804
805 msg.append(StringPool.CLOSE_CURLY_BRACE);
806
807 throw new NoSuchNodeException(msg.toString());
808 }
809 else {
810 return list.get(0);
811 }
812 }
813
814
827 public WikiNode findByUuid_Last(String uuid,
828 OrderByComparator orderByComparator)
829 throws NoSuchNodeException, SystemException {
830 int count = countByUuid(uuid);
831
832 List<WikiNode> list = findByUuid(uuid, count - 1, count,
833 orderByComparator);
834
835 if (list.isEmpty()) {
836 StringBundler msg = new StringBundler(4);
837
838 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
839
840 msg.append("uuid=");
841 msg.append(uuid);
842
843 msg.append(StringPool.CLOSE_CURLY_BRACE);
844
845 throw new NoSuchNodeException(msg.toString());
846 }
847 else {
848 return list.get(0);
849 }
850 }
851
852
866 public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
867 OrderByComparator orderByComparator)
868 throws NoSuchNodeException, SystemException {
869 WikiNode wikiNode = findByPrimaryKey(nodeId);
870
871 Session session = null;
872
873 try {
874 session = openSession();
875
876 WikiNode[] array = new WikiNodeImpl[3];
877
878 array[0] = getByUuid_PrevAndNext(session, wikiNode, uuid,
879 orderByComparator, true);
880
881 array[1] = wikiNode;
882
883 array[2] = getByUuid_PrevAndNext(session, wikiNode, uuid,
884 orderByComparator, false);
885
886 return array;
887 }
888 catch (Exception e) {
889 throw processException(e);
890 }
891 finally {
892 closeSession(session);
893 }
894 }
895
896 protected WikiNode getByUuid_PrevAndNext(Session session,
897 WikiNode wikiNode, String uuid, OrderByComparator orderByComparator,
898 boolean previous) {
899 StringBundler query = null;
900
901 if (orderByComparator != null) {
902 query = new StringBundler(6 +
903 (orderByComparator.getOrderByFields().length * 6));
904 }
905 else {
906 query = new StringBundler(3);
907 }
908
909 query.append(_SQL_SELECT_WIKINODE_WHERE);
910
911 if (uuid == null) {
912 query.append(_FINDER_COLUMN_UUID_UUID_1);
913 }
914 else {
915 if (uuid.equals(StringPool.BLANK)) {
916 query.append(_FINDER_COLUMN_UUID_UUID_3);
917 }
918 else {
919 query.append(_FINDER_COLUMN_UUID_UUID_2);
920 }
921 }
922
923 if (orderByComparator != null) {
924 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
925
926 if (orderByConditionFields.length > 0) {
927 query.append(WHERE_AND);
928 }
929
930 for (int i = 0; i < orderByConditionFields.length; i++) {
931 query.append(_ORDER_BY_ENTITY_ALIAS);
932 query.append(orderByConditionFields[i]);
933
934 if ((i + 1) < orderByConditionFields.length) {
935 if (orderByComparator.isAscending() ^ previous) {
936 query.append(WHERE_GREATER_THAN_HAS_NEXT);
937 }
938 else {
939 query.append(WHERE_LESSER_THAN_HAS_NEXT);
940 }
941 }
942 else {
943 if (orderByComparator.isAscending() ^ previous) {
944 query.append(WHERE_GREATER_THAN);
945 }
946 else {
947 query.append(WHERE_LESSER_THAN);
948 }
949 }
950 }
951
952 query.append(ORDER_BY_CLAUSE);
953
954 String[] orderByFields = orderByComparator.getOrderByFields();
955
956 for (int i = 0; i < orderByFields.length; i++) {
957 query.append(_ORDER_BY_ENTITY_ALIAS);
958 query.append(orderByFields[i]);
959
960 if ((i + 1) < orderByFields.length) {
961 if (orderByComparator.isAscending() ^ previous) {
962 query.append(ORDER_BY_ASC_HAS_NEXT);
963 }
964 else {
965 query.append(ORDER_BY_DESC_HAS_NEXT);
966 }
967 }
968 else {
969 if (orderByComparator.isAscending() ^ previous) {
970 query.append(ORDER_BY_ASC);
971 }
972 else {
973 query.append(ORDER_BY_DESC);
974 }
975 }
976 }
977 }
978
979 else {
980 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
981 }
982
983 String sql = query.toString();
984
985 Query q = session.createQuery(sql);
986
987 q.setFirstResult(0);
988 q.setMaxResults(2);
989
990 QueryPos qPos = QueryPos.getInstance(q);
991
992 if (uuid != null) {
993 qPos.add(uuid);
994 }
995
996 if (orderByComparator != null) {
997 Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
998
999 for (Object value : values) {
1000 qPos.add(value);
1001 }
1002 }
1003
1004 List<WikiNode> list = q.list();
1005
1006 if (list.size() == 2) {
1007 return list.get(1);
1008 }
1009 else {
1010 return null;
1011 }
1012 }
1013
1014
1023 public WikiNode findByUUID_G(String uuid, long groupId)
1024 throws NoSuchNodeException, SystemException {
1025 WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
1026
1027 if (wikiNode == null) {
1028 StringBundler msg = new StringBundler(6);
1029
1030 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1031
1032 msg.append("uuid=");
1033 msg.append(uuid);
1034
1035 msg.append(", groupId=");
1036 msg.append(groupId);
1037
1038 msg.append(StringPool.CLOSE_CURLY_BRACE);
1039
1040 if (_log.isWarnEnabled()) {
1041 _log.warn(msg.toString());
1042 }
1043
1044 throw new NoSuchNodeException(msg.toString());
1045 }
1046
1047 return wikiNode;
1048 }
1049
1050
1058 public WikiNode fetchByUUID_G(String uuid, long groupId)
1059 throws SystemException {
1060 return fetchByUUID_G(uuid, groupId, true);
1061 }
1062
1063
1072 public WikiNode fetchByUUID_G(String uuid, long groupId,
1073 boolean retrieveFromCache) throws SystemException {
1074 Object[] finderArgs = new Object[] { uuid, groupId };
1075
1076 Object result = null;
1077
1078 if (retrieveFromCache) {
1079 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1080 finderArgs, this);
1081 }
1082
1083 if (result instanceof WikiNode) {
1084 WikiNode wikiNode = (WikiNode)result;
1085
1086 if (!Validator.equals(uuid, wikiNode.getUuid()) ||
1087 (groupId != wikiNode.getGroupId())) {
1088 result = null;
1089 }
1090 }
1091
1092 if (result == null) {
1093 StringBundler query = new StringBundler(4);
1094
1095 query.append(_SQL_SELECT_WIKINODE_WHERE);
1096
1097 if (uuid == null) {
1098 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1099 }
1100 else {
1101 if (uuid.equals(StringPool.BLANK)) {
1102 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1103 }
1104 else {
1105 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1106 }
1107 }
1108
1109 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1110
1111 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1112
1113 String sql = query.toString();
1114
1115 Session session = null;
1116
1117 try {
1118 session = openSession();
1119
1120 Query q = session.createQuery(sql);
1121
1122 QueryPos qPos = QueryPos.getInstance(q);
1123
1124 if (uuid != null) {
1125 qPos.add(uuid);
1126 }
1127
1128 qPos.add(groupId);
1129
1130 List<WikiNode> list = q.list();
1131
1132 result = list;
1133
1134 WikiNode wikiNode = null;
1135
1136 if (list.isEmpty()) {
1137 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1138 finderArgs, list);
1139 }
1140 else {
1141 wikiNode = list.get(0);
1142
1143 cacheResult(wikiNode);
1144
1145 if ((wikiNode.getUuid() == null) ||
1146 !wikiNode.getUuid().equals(uuid) ||
1147 (wikiNode.getGroupId() != groupId)) {
1148 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1149 finderArgs, wikiNode);
1150 }
1151 }
1152
1153 return wikiNode;
1154 }
1155 catch (Exception e) {
1156 throw processException(e);
1157 }
1158 finally {
1159 if (result == null) {
1160 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1161 finderArgs);
1162 }
1163
1164 closeSession(session);
1165 }
1166 }
1167 else {
1168 if (result instanceof List<?>) {
1169 return null;
1170 }
1171 else {
1172 return (WikiNode)result;
1173 }
1174 }
1175 }
1176
1177
1184 public List<WikiNode> findByGroupId(long groupId) throws SystemException {
1185 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1186 }
1187
1188
1201 public List<WikiNode> findByGroupId(long groupId, int start, int end)
1202 throws SystemException {
1203 return findByGroupId(groupId, start, end, null);
1204 }
1205
1206
1220 public List<WikiNode> findByGroupId(long groupId, int start, int end,
1221 OrderByComparator orderByComparator) throws SystemException {
1222 FinderPath finderPath = null;
1223 Object[] finderArgs = null;
1224
1225 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1226 (orderByComparator == null)) {
1227 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1228 finderArgs = new Object[] { groupId };
1229 }
1230 else {
1231 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1232 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1233 }
1234
1235 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
1236 finderArgs, this);
1237
1238 if ((list != null) && !list.isEmpty()) {
1239 for (WikiNode wikiNode : list) {
1240 if ((groupId != wikiNode.getGroupId())) {
1241 list = null;
1242
1243 break;
1244 }
1245 }
1246 }
1247
1248 if (list == null) {
1249 StringBundler query = null;
1250
1251 if (orderByComparator != null) {
1252 query = new StringBundler(3 +
1253 (orderByComparator.getOrderByFields().length * 3));
1254 }
1255 else {
1256 query = new StringBundler(3);
1257 }
1258
1259 query.append(_SQL_SELECT_WIKINODE_WHERE);
1260
1261 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1262
1263 if (orderByComparator != null) {
1264 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1265 orderByComparator);
1266 }
1267
1268 else {
1269 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1270 }
1271
1272 String sql = query.toString();
1273
1274 Session session = null;
1275
1276 try {
1277 session = openSession();
1278
1279 Query q = session.createQuery(sql);
1280
1281 QueryPos qPos = QueryPos.getInstance(q);
1282
1283 qPos.add(groupId);
1284
1285 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1286 end);
1287 }
1288 catch (Exception e) {
1289 throw processException(e);
1290 }
1291 finally {
1292 if (list == null) {
1293 FinderCacheUtil.removeResult(finderPath, finderArgs);
1294 }
1295 else {
1296 cacheResult(list);
1297
1298 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1299 }
1300
1301 closeSession(session);
1302 }
1303 }
1304
1305 return list;
1306 }
1307
1308
1321 public WikiNode findByGroupId_First(long groupId,
1322 OrderByComparator orderByComparator)
1323 throws NoSuchNodeException, SystemException {
1324 List<WikiNode> list = findByGroupId(groupId, 0, 1, orderByComparator);
1325
1326 if (list.isEmpty()) {
1327 StringBundler msg = new StringBundler(4);
1328
1329 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1330
1331 msg.append("groupId=");
1332 msg.append(groupId);
1333
1334 msg.append(StringPool.CLOSE_CURLY_BRACE);
1335
1336 throw new NoSuchNodeException(msg.toString());
1337 }
1338 else {
1339 return list.get(0);
1340 }
1341 }
1342
1343
1356 public WikiNode findByGroupId_Last(long groupId,
1357 OrderByComparator orderByComparator)
1358 throws NoSuchNodeException, SystemException {
1359 int count = countByGroupId(groupId);
1360
1361 List<WikiNode> list = findByGroupId(groupId, count - 1, count,
1362 orderByComparator);
1363
1364 if (list.isEmpty()) {
1365 StringBundler msg = new StringBundler(4);
1366
1367 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1368
1369 msg.append("groupId=");
1370 msg.append(groupId);
1371
1372 msg.append(StringPool.CLOSE_CURLY_BRACE);
1373
1374 throw new NoSuchNodeException(msg.toString());
1375 }
1376 else {
1377 return list.get(0);
1378 }
1379 }
1380
1381
1395 public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
1396 OrderByComparator orderByComparator)
1397 throws NoSuchNodeException, SystemException {
1398 WikiNode wikiNode = findByPrimaryKey(nodeId);
1399
1400 Session session = null;
1401
1402 try {
1403 session = openSession();
1404
1405 WikiNode[] array = new WikiNodeImpl[3];
1406
1407 array[0] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1408 orderByComparator, true);
1409
1410 array[1] = wikiNode;
1411
1412 array[2] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1413 orderByComparator, false);
1414
1415 return array;
1416 }
1417 catch (Exception e) {
1418 throw processException(e);
1419 }
1420 finally {
1421 closeSession(session);
1422 }
1423 }
1424
1425 protected WikiNode getByGroupId_PrevAndNext(Session session,
1426 WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1427 boolean previous) {
1428 StringBundler query = null;
1429
1430 if (orderByComparator != null) {
1431 query = new StringBundler(6 +
1432 (orderByComparator.getOrderByFields().length * 6));
1433 }
1434 else {
1435 query = new StringBundler(3);
1436 }
1437
1438 query.append(_SQL_SELECT_WIKINODE_WHERE);
1439
1440 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1441
1442 if (orderByComparator != null) {
1443 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1444
1445 if (orderByConditionFields.length > 0) {
1446 query.append(WHERE_AND);
1447 }
1448
1449 for (int i = 0; i < orderByConditionFields.length; i++) {
1450 query.append(_ORDER_BY_ENTITY_ALIAS);
1451 query.append(orderByConditionFields[i]);
1452
1453 if ((i + 1) < orderByConditionFields.length) {
1454 if (orderByComparator.isAscending() ^ previous) {
1455 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1456 }
1457 else {
1458 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1459 }
1460 }
1461 else {
1462 if (orderByComparator.isAscending() ^ previous) {
1463 query.append(WHERE_GREATER_THAN);
1464 }
1465 else {
1466 query.append(WHERE_LESSER_THAN);
1467 }
1468 }
1469 }
1470
1471 query.append(ORDER_BY_CLAUSE);
1472
1473 String[] orderByFields = orderByComparator.getOrderByFields();
1474
1475 for (int i = 0; i < orderByFields.length; i++) {
1476 query.append(_ORDER_BY_ENTITY_ALIAS);
1477 query.append(orderByFields[i]);
1478
1479 if ((i + 1) < orderByFields.length) {
1480 if (orderByComparator.isAscending() ^ previous) {
1481 query.append(ORDER_BY_ASC_HAS_NEXT);
1482 }
1483 else {
1484 query.append(ORDER_BY_DESC_HAS_NEXT);
1485 }
1486 }
1487 else {
1488 if (orderByComparator.isAscending() ^ previous) {
1489 query.append(ORDER_BY_ASC);
1490 }
1491 else {
1492 query.append(ORDER_BY_DESC);
1493 }
1494 }
1495 }
1496 }
1497
1498 else {
1499 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1500 }
1501
1502 String sql = query.toString();
1503
1504 Query q = session.createQuery(sql);
1505
1506 q.setFirstResult(0);
1507 q.setMaxResults(2);
1508
1509 QueryPos qPos = QueryPos.getInstance(q);
1510
1511 qPos.add(groupId);
1512
1513 if (orderByComparator != null) {
1514 Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1515
1516 for (Object value : values) {
1517 qPos.add(value);
1518 }
1519 }
1520
1521 List<WikiNode> list = q.list();
1522
1523 if (list.size() == 2) {
1524 return list.get(1);
1525 }
1526 else {
1527 return null;
1528 }
1529 }
1530
1531
1538 public List<WikiNode> filterFindByGroupId(long groupId)
1539 throws SystemException {
1540 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1541 QueryUtil.ALL_POS, null);
1542 }
1543
1544
1557 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end)
1558 throws SystemException {
1559 return filterFindByGroupId(groupId, start, end, null);
1560 }
1561
1562
1576 public List<WikiNode> filterFindByGroupId(long groupId, int start, int end,
1577 OrderByComparator orderByComparator) throws SystemException {
1578 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1579 return findByGroupId(groupId, start, end, orderByComparator);
1580 }
1581
1582 StringBundler query = null;
1583
1584 if (orderByComparator != null) {
1585 query = new StringBundler(3 +
1586 (orderByComparator.getOrderByFields().length * 3));
1587 }
1588 else {
1589 query = new StringBundler(3);
1590 }
1591
1592 if (getDB().isSupportsInlineDistinct()) {
1593 query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1594 }
1595 else {
1596 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
1597 }
1598
1599 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1600
1601 if (!getDB().isSupportsInlineDistinct()) {
1602 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
1603 }
1604
1605 if (orderByComparator != null) {
1606 if (getDB().isSupportsInlineDistinct()) {
1607 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1608 orderByComparator);
1609 }
1610 else {
1611 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1612 orderByComparator);
1613 }
1614 }
1615
1616 else {
1617 if (getDB().isSupportsInlineDistinct()) {
1618 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1619 }
1620 else {
1621 query.append(WikiNodeModelImpl.ORDER_BY_SQL);
1622 }
1623 }
1624
1625 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1626 WikiNode.class.getName(),
1627 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1628
1629 Session session = null;
1630
1631 try {
1632 session = openSession();
1633
1634 SQLQuery q = session.createSQLQuery(sql);
1635
1636 if (getDB().isSupportsInlineDistinct()) {
1637 q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1638 }
1639 else {
1640 q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
1641 }
1642
1643 QueryPos qPos = QueryPos.getInstance(q);
1644
1645 qPos.add(groupId);
1646
1647 return (List<WikiNode>)QueryUtil.list(q, getDialect(), start, end);
1648 }
1649 catch (Exception e) {
1650 throw processException(e);
1651 }
1652 finally {
1653 closeSession(session);
1654 }
1655 }
1656
1657
1667 public WikiNode[] filterFindByGroupId_PrevAndNext(long nodeId,
1668 long groupId, OrderByComparator orderByComparator)
1669 throws NoSuchNodeException, SystemException {
1670 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1671 return findByGroupId_PrevAndNext(nodeId, groupId, orderByComparator);
1672 }
1673
1674 WikiNode wikiNode = findByPrimaryKey(nodeId);
1675
1676 Session session = null;
1677
1678 try {
1679 session = openSession();
1680
1681 WikiNode[] array = new WikiNodeImpl[3];
1682
1683 array[0] = filterGetByGroupId_PrevAndNext(session, wikiNode,
1684 groupId, orderByComparator, true);
1685
1686 array[1] = wikiNode;
1687
1688 array[2] = filterGetByGroupId_PrevAndNext(session, wikiNode,
1689 groupId, orderByComparator, false);
1690
1691 return array;
1692 }
1693 catch (Exception e) {
1694 throw processException(e);
1695 }
1696 finally {
1697 closeSession(session);
1698 }
1699 }
1700
1701 protected WikiNode filterGetByGroupId_PrevAndNext(Session session,
1702 WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1703 boolean previous) {
1704 StringBundler query = null;
1705
1706 if (orderByComparator != null) {
1707 query = new StringBundler(6 +
1708 (orderByComparator.getOrderByFields().length * 6));
1709 }
1710 else {
1711 query = new StringBundler(3);
1712 }
1713
1714 if (getDB().isSupportsInlineDistinct()) {
1715 query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1716 }
1717 else {
1718 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
1719 }
1720
1721 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1722
1723 if (!getDB().isSupportsInlineDistinct()) {
1724 query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
1725 }
1726
1727 if (orderByComparator != null) {
1728 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1729
1730 if (orderByConditionFields.length > 0) {
1731 query.append(WHERE_AND);
1732 }
1733
1734 for (int i = 0; i < orderByConditionFields.length; i++) {
1735 if (getDB().isSupportsInlineDistinct()) {
1736 query.append(_ORDER_BY_ENTITY_ALIAS);
1737 }
1738 else {
1739 query.append(_ORDER_BY_ENTITY_TABLE);
1740 }
1741
1742 query.append(orderByConditionFields[i]);
1743
1744 if ((i + 1) < orderByConditionFields.length) {
1745 if (orderByComparator.isAscending() ^ previous) {
1746 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1747 }
1748 else {
1749 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1750 }
1751 }
1752 else {
1753 if (orderByComparator.isAscending() ^ previous) {
1754 query.append(WHERE_GREATER_THAN);
1755 }
1756 else {
1757 query.append(WHERE_LESSER_THAN);
1758 }
1759 }
1760 }
1761
1762 query.append(ORDER_BY_CLAUSE);
1763
1764 String[] orderByFields = orderByComparator.getOrderByFields();
1765
1766 for (int i = 0; i < orderByFields.length; i++) {
1767 if (getDB().isSupportsInlineDistinct()) {
1768 query.append(_ORDER_BY_ENTITY_ALIAS);
1769 }
1770 else {
1771 query.append(_ORDER_BY_ENTITY_TABLE);
1772 }
1773
1774 query.append(orderByFields[i]);
1775
1776 if ((i + 1) < orderByFields.length) {
1777 if (orderByComparator.isAscending() ^ previous) {
1778 query.append(ORDER_BY_ASC_HAS_NEXT);
1779 }
1780 else {
1781 query.append(ORDER_BY_DESC_HAS_NEXT);
1782 }
1783 }
1784 else {
1785 if (orderByComparator.isAscending() ^ previous) {
1786 query.append(ORDER_BY_ASC);
1787 }
1788 else {
1789 query.append(ORDER_BY_DESC);
1790 }
1791 }
1792 }
1793 }
1794
1795 else {
1796 if (getDB().isSupportsInlineDistinct()) {
1797 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1798 }
1799 else {
1800 query.append(WikiNodeModelImpl.ORDER_BY_SQL);
1801 }
1802 }
1803
1804 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1805 WikiNode.class.getName(),
1806 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1807
1808 SQLQuery q = session.createSQLQuery(sql);
1809
1810 q.setFirstResult(0);
1811 q.setMaxResults(2);
1812
1813 if (getDB().isSupportsInlineDistinct()) {
1814 q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1815 }
1816 else {
1817 q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
1818 }
1819
1820 QueryPos qPos = QueryPos.getInstance(q);
1821
1822 qPos.add(groupId);
1823
1824 if (orderByComparator != null) {
1825 Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1826
1827 for (Object value : values) {
1828 qPos.add(value);
1829 }
1830 }
1831
1832 List<WikiNode> list = q.list();
1833
1834 if (list.size() == 2) {
1835 return list.get(1);
1836 }
1837 else {
1838 return null;
1839 }
1840 }
1841
1842
1849 public List<WikiNode> findByCompanyId(long companyId)
1850 throws SystemException {
1851 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1852 null);
1853 }
1854
1855
1868 public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1869 throws SystemException {
1870 return findByCompanyId(companyId, start, end, null);
1871 }
1872
1873
1887 public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1888 OrderByComparator orderByComparator) throws SystemException {
1889 FinderPath finderPath = null;
1890 Object[] finderArgs = null;
1891
1892 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1893 (orderByComparator == null)) {
1894 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1895 finderArgs = new Object[] { companyId };
1896 }
1897 else {
1898 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1899 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1900 }
1901
1902 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
1903 finderArgs, this);
1904
1905 if ((list != null) && !list.isEmpty()) {
1906 for (WikiNode wikiNode : list) {
1907 if ((companyId != wikiNode.getCompanyId())) {
1908 list = null;
1909
1910 break;
1911 }
1912 }
1913 }
1914
1915 if (list == null) {
1916 StringBundler query = null;
1917
1918 if (orderByComparator != null) {
1919 query = new StringBundler(3 +
1920 (orderByComparator.getOrderByFields().length * 3));
1921 }
1922 else {
1923 query = new StringBundler(3);
1924 }
1925
1926 query.append(_SQL_SELECT_WIKINODE_WHERE);
1927
1928 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1929
1930 if (orderByComparator != null) {
1931 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1932 orderByComparator);
1933 }
1934
1935 else {
1936 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1937 }
1938
1939 String sql = query.toString();
1940
1941 Session session = null;
1942
1943 try {
1944 session = openSession();
1945
1946 Query q = session.createQuery(sql);
1947
1948 QueryPos qPos = QueryPos.getInstance(q);
1949
1950 qPos.add(companyId);
1951
1952 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1953 end);
1954 }
1955 catch (Exception e) {
1956 throw processException(e);
1957 }
1958 finally {
1959 if (list == null) {
1960 FinderCacheUtil.removeResult(finderPath, finderArgs);
1961 }
1962 else {
1963 cacheResult(list);
1964
1965 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1966 }
1967
1968 closeSession(session);
1969 }
1970 }
1971
1972 return list;
1973 }
1974
1975
1988 public WikiNode findByCompanyId_First(long companyId,
1989 OrderByComparator orderByComparator)
1990 throws NoSuchNodeException, SystemException {
1991 List<WikiNode> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1992
1993 if (list.isEmpty()) {
1994 StringBundler msg = new StringBundler(4);
1995
1996 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1997
1998 msg.append("companyId=");
1999 msg.append(companyId);
2000
2001 msg.append(StringPool.CLOSE_CURLY_BRACE);
2002
2003 throw new NoSuchNodeException(msg.toString());
2004 }
2005 else {
2006 return list.get(0);
2007 }
2008 }
2009
2010
2023 public WikiNode findByCompanyId_Last(long companyId,
2024 OrderByComparator orderByComparator)
2025 throws NoSuchNodeException, SystemException {
2026 int count = countByCompanyId(companyId);
2027
2028 List<WikiNode> list = findByCompanyId(companyId, count - 1, count,
2029 orderByComparator);
2030
2031 if (list.isEmpty()) {
2032 StringBundler msg = new StringBundler(4);
2033
2034 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2035
2036 msg.append("companyId=");
2037 msg.append(companyId);
2038
2039 msg.append(StringPool.CLOSE_CURLY_BRACE);
2040
2041 throw new NoSuchNodeException(msg.toString());
2042 }
2043 else {
2044 return list.get(0);
2045 }
2046 }
2047
2048
2062 public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
2063 OrderByComparator orderByComparator)
2064 throws NoSuchNodeException, SystemException {
2065 WikiNode wikiNode = findByPrimaryKey(nodeId);
2066
2067 Session session = null;
2068
2069 try {
2070 session = openSession();
2071
2072 WikiNode[] array = new WikiNodeImpl[3];
2073
2074 array[0] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
2075 orderByComparator, true);
2076
2077 array[1] = wikiNode;
2078
2079 array[2] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
2080 orderByComparator, false);
2081
2082 return array;
2083 }
2084 catch (Exception e) {
2085 throw processException(e);
2086 }
2087 finally {
2088 closeSession(session);
2089 }
2090 }
2091
2092 protected WikiNode getByCompanyId_PrevAndNext(Session session,
2093 WikiNode wikiNode, long companyId, OrderByComparator orderByComparator,
2094 boolean previous) {
2095 StringBundler query = null;
2096
2097 if (orderByComparator != null) {
2098 query = new StringBundler(6 +
2099 (orderByComparator.getOrderByFields().length * 6));
2100 }
2101 else {
2102 query = new StringBundler(3);
2103 }
2104
2105 query.append(_SQL_SELECT_WIKINODE_WHERE);
2106
2107 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2108
2109 if (orderByComparator != null) {
2110 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2111
2112 if (orderByConditionFields.length > 0) {
2113 query.append(WHERE_AND);
2114 }
2115
2116 for (int i = 0; i < orderByConditionFields.length; i++) {
2117 query.append(_ORDER_BY_ENTITY_ALIAS);
2118 query.append(orderByConditionFields[i]);
2119
2120 if ((i + 1) < orderByConditionFields.length) {
2121 if (orderByComparator.isAscending() ^ previous) {
2122 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2123 }
2124 else {
2125 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2126 }
2127 }
2128 else {
2129 if (orderByComparator.isAscending() ^ previous) {
2130 query.append(WHERE_GREATER_THAN);
2131 }
2132 else {
2133 query.append(WHERE_LESSER_THAN);
2134 }
2135 }
2136 }
2137
2138 query.append(ORDER_BY_CLAUSE);
2139
2140 String[] orderByFields = orderByComparator.getOrderByFields();
2141
2142 for (int i = 0; i < orderByFields.length; i++) {
2143 query.append(_ORDER_BY_ENTITY_ALIAS);
2144 query.append(orderByFields[i]);
2145
2146 if ((i + 1) < orderByFields.length) {
2147 if (orderByComparator.isAscending() ^ previous) {
2148 query.append(ORDER_BY_ASC_HAS_NEXT);
2149 }
2150 else {
2151 query.append(ORDER_BY_DESC_HAS_NEXT);
2152 }
2153 }
2154 else {
2155 if (orderByComparator.isAscending() ^ previous) {
2156 query.append(ORDER_BY_ASC);
2157 }
2158 else {
2159 query.append(ORDER_BY_DESC);
2160 }
2161 }
2162 }
2163 }
2164
2165 else {
2166 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2167 }
2168
2169 String sql = query.toString();
2170
2171 Query q = session.createQuery(sql);
2172
2173 q.setFirstResult(0);
2174 q.setMaxResults(2);
2175
2176 QueryPos qPos = QueryPos.getInstance(q);
2177
2178 qPos.add(companyId);
2179
2180 if (orderByComparator != null) {
2181 Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
2182
2183 for (Object value : values) {
2184 qPos.add(value);
2185 }
2186 }
2187
2188 List<WikiNode> list = q.list();
2189
2190 if (list.size() == 2) {
2191 return list.get(1);
2192 }
2193 else {
2194 return null;
2195 }
2196 }
2197
2198
2207 public WikiNode findByG_N(long groupId, String name)
2208 throws NoSuchNodeException, SystemException {
2209 WikiNode wikiNode = fetchByG_N(groupId, name);
2210
2211 if (wikiNode == null) {
2212 StringBundler msg = new StringBundler(6);
2213
2214 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2215
2216 msg.append("groupId=");
2217 msg.append(groupId);
2218
2219 msg.append(", name=");
2220 msg.append(name);
2221
2222 msg.append(StringPool.CLOSE_CURLY_BRACE);
2223
2224 if (_log.isWarnEnabled()) {
2225 _log.warn(msg.toString());
2226 }
2227
2228 throw new NoSuchNodeException(msg.toString());
2229 }
2230
2231 return wikiNode;
2232 }
2233
2234
2242 public WikiNode fetchByG_N(long groupId, String name)
2243 throws SystemException {
2244 return fetchByG_N(groupId, name, true);
2245 }
2246
2247
2256 public WikiNode fetchByG_N(long groupId, String name,
2257 boolean retrieveFromCache) throws SystemException {
2258 Object[] finderArgs = new Object[] { groupId, name };
2259
2260 Object result = null;
2261
2262 if (retrieveFromCache) {
2263 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
2264 finderArgs, this);
2265 }
2266
2267 if (result instanceof WikiNode) {
2268 WikiNode wikiNode = (WikiNode)result;
2269
2270 if ((groupId != wikiNode.getGroupId()) ||
2271 !Validator.equals(name, wikiNode.getName())) {
2272 result = null;
2273 }
2274 }
2275
2276 if (result == null) {
2277 StringBundler query = new StringBundler(4);
2278
2279 query.append(_SQL_SELECT_WIKINODE_WHERE);
2280
2281 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2282
2283 if (name == null) {
2284 query.append(_FINDER_COLUMN_G_N_NAME_1);
2285 }
2286 else {
2287 if (name.equals(StringPool.BLANK)) {
2288 query.append(_FINDER_COLUMN_G_N_NAME_3);
2289 }
2290 else {
2291 query.append(_FINDER_COLUMN_G_N_NAME_2);
2292 }
2293 }
2294
2295 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2296
2297 String sql = query.toString();
2298
2299 Session session = null;
2300
2301 try {
2302 session = openSession();
2303
2304 Query q = session.createQuery(sql);
2305
2306 QueryPos qPos = QueryPos.getInstance(q);
2307
2308 qPos.add(groupId);
2309
2310 if (name != null) {
2311 qPos.add(name);
2312 }
2313
2314 List<WikiNode> list = q.list();
2315
2316 result = list;
2317
2318 WikiNode wikiNode = null;
2319
2320 if (list.isEmpty()) {
2321 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2322 finderArgs, list);
2323 }
2324 else {
2325 wikiNode = list.get(0);
2326
2327 cacheResult(wikiNode);
2328
2329 if ((wikiNode.getGroupId() != groupId) ||
2330 (wikiNode.getName() == null) ||
2331 !wikiNode.getName().equals(name)) {
2332 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2333 finderArgs, wikiNode);
2334 }
2335 }
2336
2337 return wikiNode;
2338 }
2339 catch (Exception e) {
2340 throw processException(e);
2341 }
2342 finally {
2343 if (result == null) {
2344 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
2345 finderArgs);
2346 }
2347
2348 closeSession(session);
2349 }
2350 }
2351 else {
2352 if (result instanceof List<?>) {
2353 return null;
2354 }
2355 else {
2356 return (WikiNode)result;
2357 }
2358 }
2359 }
2360
2361
2367 public List<WikiNode> findAll() throws SystemException {
2368 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2369 }
2370
2371
2383 public List<WikiNode> findAll(int start, int end) throws SystemException {
2384 return findAll(start, end, null);
2385 }
2386
2387
2400 public List<WikiNode> findAll(int start, int end,
2401 OrderByComparator orderByComparator) throws SystemException {
2402 FinderPath finderPath = null;
2403 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2404
2405 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2406 (orderByComparator == null)) {
2407 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2408 finderArgs = FINDER_ARGS_EMPTY;
2409 }
2410 else {
2411 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2412 finderArgs = new Object[] { start, end, orderByComparator };
2413 }
2414
2415 List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
2416 finderArgs, this);
2417
2418 if (list == null) {
2419 StringBundler query = null;
2420 String sql = null;
2421
2422 if (orderByComparator != null) {
2423 query = new StringBundler(2 +
2424 (orderByComparator.getOrderByFields().length * 3));
2425
2426 query.append(_SQL_SELECT_WIKINODE);
2427
2428 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2429 orderByComparator);
2430
2431 sql = query.toString();
2432 }
2433 else {
2434 sql = _SQL_SELECT_WIKINODE.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
2435 }
2436
2437 Session session = null;
2438
2439 try {
2440 session = openSession();
2441
2442 Query q = session.createQuery(sql);
2443
2444 if (orderByComparator == null) {
2445 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2446 start, end, false);
2447
2448 Collections.sort(list);
2449 }
2450 else {
2451 list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2452 start, end);
2453 }
2454 }
2455 catch (Exception e) {
2456 throw processException(e);
2457 }
2458 finally {
2459 if (list == null) {
2460 FinderCacheUtil.removeResult(finderPath, finderArgs);
2461 }
2462 else {
2463 cacheResult(list);
2464
2465 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2466 }
2467
2468 closeSession(session);
2469 }
2470 }
2471
2472 return list;
2473 }
2474
2475
2481 public void removeByUuid(String uuid) throws SystemException {
2482 for (WikiNode wikiNode : findByUuid(uuid)) {
2483 remove(wikiNode);
2484 }
2485 }
2486
2487
2494 public void removeByUUID_G(String uuid, long groupId)
2495 throws NoSuchNodeException, SystemException {
2496 WikiNode wikiNode = findByUUID_G(uuid, groupId);
2497
2498 remove(wikiNode);
2499 }
2500
2501
2507 public void removeByGroupId(long groupId) throws SystemException {
2508 for (WikiNode wikiNode : findByGroupId(groupId)) {
2509 remove(wikiNode);
2510 }
2511 }
2512
2513
2519 public void removeByCompanyId(long companyId) throws SystemException {
2520 for (WikiNode wikiNode : findByCompanyId(companyId)) {
2521 remove(wikiNode);
2522 }
2523 }
2524
2525
2532 public void removeByG_N(long groupId, String name)
2533 throws NoSuchNodeException, SystemException {
2534 WikiNode wikiNode = findByG_N(groupId, name);
2535
2536 remove(wikiNode);
2537 }
2538
2539
2544 public void removeAll() throws SystemException {
2545 for (WikiNode wikiNode : findAll()) {
2546 remove(wikiNode);
2547 }
2548 }
2549
2550
2557 public int countByUuid(String uuid) throws SystemException {
2558 Object[] finderArgs = new Object[] { uuid };
2559
2560 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2561 finderArgs, this);
2562
2563 if (count == null) {
2564 StringBundler query = new StringBundler(2);
2565
2566 query.append(_SQL_COUNT_WIKINODE_WHERE);
2567
2568 if (uuid == null) {
2569 query.append(_FINDER_COLUMN_UUID_UUID_1);
2570 }
2571 else {
2572 if (uuid.equals(StringPool.BLANK)) {
2573 query.append(_FINDER_COLUMN_UUID_UUID_3);
2574 }
2575 else {
2576 query.append(_FINDER_COLUMN_UUID_UUID_2);
2577 }
2578 }
2579
2580 String sql = query.toString();
2581
2582 Session session = null;
2583
2584 try {
2585 session = openSession();
2586
2587 Query q = session.createQuery(sql);
2588
2589 QueryPos qPos = QueryPos.getInstance(q);
2590
2591 if (uuid != null) {
2592 qPos.add(uuid);
2593 }
2594
2595 count = (Long)q.uniqueResult();
2596 }
2597 catch (Exception e) {
2598 throw processException(e);
2599 }
2600 finally {
2601 if (count == null) {
2602 count = Long.valueOf(0);
2603 }
2604
2605 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2606 finderArgs, count);
2607
2608 closeSession(session);
2609 }
2610 }
2611
2612 return count.intValue();
2613 }
2614
2615
2623 public int countByUUID_G(String uuid, long groupId)
2624 throws SystemException {
2625 Object[] finderArgs = new Object[] { uuid, groupId };
2626
2627 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2628 finderArgs, this);
2629
2630 if (count == null) {
2631 StringBundler query = new StringBundler(3);
2632
2633 query.append(_SQL_COUNT_WIKINODE_WHERE);
2634
2635 if (uuid == null) {
2636 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2637 }
2638 else {
2639 if (uuid.equals(StringPool.BLANK)) {
2640 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2641 }
2642 else {
2643 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2644 }
2645 }
2646
2647 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2648
2649 String sql = query.toString();
2650
2651 Session session = null;
2652
2653 try {
2654 session = openSession();
2655
2656 Query q = session.createQuery(sql);
2657
2658 QueryPos qPos = QueryPos.getInstance(q);
2659
2660 if (uuid != null) {
2661 qPos.add(uuid);
2662 }
2663
2664 qPos.add(groupId);
2665
2666 count = (Long)q.uniqueResult();
2667 }
2668 catch (Exception e) {
2669 throw processException(e);
2670 }
2671 finally {
2672 if (count == null) {
2673 count = Long.valueOf(0);
2674 }
2675
2676 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2677 finderArgs, count);
2678
2679 closeSession(session);
2680 }
2681 }
2682
2683 return count.intValue();
2684 }
2685
2686
2693 public int countByGroupId(long groupId) throws SystemException {
2694 Object[] finderArgs = new Object[] { groupId };
2695
2696 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2697 finderArgs, this);
2698
2699 if (count == null) {
2700 StringBundler query = new StringBundler(2);
2701
2702 query.append(_SQL_COUNT_WIKINODE_WHERE);
2703
2704 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2705
2706 String sql = query.toString();
2707
2708 Session session = null;
2709
2710 try {
2711 session = openSession();
2712
2713 Query q = session.createQuery(sql);
2714
2715 QueryPos qPos = QueryPos.getInstance(q);
2716
2717 qPos.add(groupId);
2718
2719 count = (Long)q.uniqueResult();
2720 }
2721 catch (Exception e) {
2722 throw processException(e);
2723 }
2724 finally {
2725 if (count == null) {
2726 count = Long.valueOf(0);
2727 }
2728
2729 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2730 finderArgs, count);
2731
2732 closeSession(session);
2733 }
2734 }
2735
2736 return count.intValue();
2737 }
2738
2739
2746 public int filterCountByGroupId(long groupId) throws SystemException {
2747 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2748 return countByGroupId(groupId);
2749 }
2750
2751 StringBundler query = new StringBundler(2);
2752
2753 query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2754
2755 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2756
2757 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2758 WikiNode.class.getName(),
2759 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2760
2761 Session session = null;
2762
2763 try {
2764 session = openSession();
2765
2766 SQLQuery q = session.createSQLQuery(sql);
2767
2768 q.addScalar(COUNT_COLUMN_NAME,
2769 com.liferay.portal.kernel.dao.orm.Type.LONG);
2770
2771 QueryPos qPos = QueryPos.getInstance(q);
2772
2773 qPos.add(groupId);
2774
2775 Long count = (Long)q.uniqueResult();
2776
2777 return count.intValue();
2778 }
2779 catch (Exception e) {
2780 throw processException(e);
2781 }
2782 finally {
2783 closeSession(session);
2784 }
2785 }
2786
2787
2794 public int countByCompanyId(long companyId) throws SystemException {
2795 Object[] finderArgs = new Object[] { companyId };
2796
2797 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2798 finderArgs, this);
2799
2800 if (count == null) {
2801 StringBundler query = new StringBundler(2);
2802
2803 query.append(_SQL_COUNT_WIKINODE_WHERE);
2804
2805 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2806
2807 String sql = query.toString();
2808
2809 Session session = null;
2810
2811 try {
2812 session = openSession();
2813
2814 Query q = session.createQuery(sql);
2815
2816 QueryPos qPos = QueryPos.getInstance(q);
2817
2818 qPos.add(companyId);
2819
2820 count = (Long)q.uniqueResult();
2821 }
2822 catch (Exception e) {
2823 throw processException(e);
2824 }
2825 finally {
2826 if (count == null) {
2827 count = Long.valueOf(0);
2828 }
2829
2830 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2831 finderArgs, count);
2832
2833 closeSession(session);
2834 }
2835 }
2836
2837 return count.intValue();
2838 }
2839
2840
2848 public int countByG_N(long groupId, String name) throws SystemException {
2849 Object[] finderArgs = new Object[] { groupId, name };
2850
2851 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
2852 finderArgs, this);
2853
2854 if (count == null) {
2855 StringBundler query = new StringBundler(3);
2856
2857 query.append(_SQL_COUNT_WIKINODE_WHERE);
2858
2859 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2860
2861 if (name == null) {
2862 query.append(_FINDER_COLUMN_G_N_NAME_1);
2863 }
2864 else {
2865 if (name.equals(StringPool.BLANK)) {
2866 query.append(_FINDER_COLUMN_G_N_NAME_3);
2867 }
2868 else {
2869 query.append(_FINDER_COLUMN_G_N_NAME_2);
2870 }
2871 }
2872
2873 String sql = query.toString();
2874
2875 Session session = null;
2876
2877 try {
2878 session = openSession();
2879
2880 Query q = session.createQuery(sql);
2881
2882 QueryPos qPos = QueryPos.getInstance(q);
2883
2884 qPos.add(groupId);
2885
2886 if (name != null) {
2887 qPos.add(name);
2888 }
2889
2890 count = (Long)q.uniqueResult();
2891 }
2892 catch (Exception e) {
2893 throw processException(e);
2894 }
2895 finally {
2896 if (count == null) {
2897 count = Long.valueOf(0);
2898 }
2899
2900 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
2901 count);
2902
2903 closeSession(session);
2904 }
2905 }
2906
2907 return count.intValue();
2908 }
2909
2910
2916 public int countAll() throws SystemException {
2917 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2918 FINDER_ARGS_EMPTY, this);
2919
2920 if (count == null) {
2921 Session session = null;
2922
2923 try {
2924 session = openSession();
2925
2926 Query q = session.createQuery(_SQL_COUNT_WIKINODE);
2927
2928 count = (Long)q.uniqueResult();
2929 }
2930 catch (Exception e) {
2931 throw processException(e);
2932 }
2933 finally {
2934 if (count == null) {
2935 count = Long.valueOf(0);
2936 }
2937
2938 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2939 FINDER_ARGS_EMPTY, count);
2940
2941 closeSession(session);
2942 }
2943 }
2944
2945 return count.intValue();
2946 }
2947
2948
2951 public void afterPropertiesSet() {
2952 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2953 com.liferay.portal.util.PropsUtil.get(
2954 "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
2955
2956 if (listenerClassNames.length > 0) {
2957 try {
2958 List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
2959
2960 for (String listenerClassName : listenerClassNames) {
2961 listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
2962 listenerClassName));
2963 }
2964
2965 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2966 }
2967 catch (Exception e) {
2968 _log.error(e);
2969 }
2970 }
2971 }
2972
2973 public void destroy() {
2974 EntityCacheUtil.removeCache(WikiNodeImpl.class.getName());
2975 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2976 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2977 }
2978
2979 @BeanReference(type = WikiNodePersistence.class)
2980 protected WikiNodePersistence wikiNodePersistence;
2981 @BeanReference(type = WikiPagePersistence.class)
2982 protected WikiPagePersistence wikiPagePersistence;
2983 @BeanReference(type = WikiPageResourcePersistence.class)
2984 protected WikiPageResourcePersistence wikiPageResourcePersistence;
2985 @BeanReference(type = GroupPersistence.class)
2986 protected GroupPersistence groupPersistence;
2987 @BeanReference(type = ResourcePersistence.class)
2988 protected ResourcePersistence resourcePersistence;
2989 @BeanReference(type = SubscriptionPersistence.class)
2990 protected SubscriptionPersistence subscriptionPersistence;
2991 @BeanReference(type = UserPersistence.class)
2992 protected UserPersistence userPersistence;
2993 private static final String _SQL_SELECT_WIKINODE = "SELECT wikiNode FROM WikiNode wikiNode";
2994 private static final String _SQL_SELECT_WIKINODE_WHERE = "SELECT wikiNode FROM WikiNode wikiNode WHERE ";
2995 private static final String _SQL_COUNT_WIKINODE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode";
2996 private static final String _SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode WHERE ";
2997 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiNode.uuid IS NULL";
2998 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiNode.uuid = ?";
2999 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?)";
3000 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiNode.uuid IS NULL AND ";
3001 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiNode.uuid = ? AND ";
3002 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?) AND ";
3003 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiNode.groupId = ?";
3004 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "wikiNode.groupId = ?";
3005 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "wikiNode.companyId = ?";
3006 private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "wikiNode.groupId = ? AND ";
3007 private static final String _FINDER_COLUMN_G_N_NAME_1 = "wikiNode.name IS NULL";
3008 private static final String _FINDER_COLUMN_G_N_NAME_2 = "wikiNode.name = ?";
3009 private static final String _FINDER_COLUMN_G_N_NAME_3 = "(wikiNode.name IS NULL OR wikiNode.name = ?)";
3010 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiNode.nodeId";
3011 private static final String _FILTER_SQL_SELECT_WIKINODE_WHERE = "SELECT DISTINCT {wikiNode.*} FROM WikiNode wikiNode WHERE ";
3012 private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1 =
3013 "SELECT {WikiNode.*} FROM (SELECT DISTINCT wikiNode.nodeId FROM WikiNode wikiNode WHERE ";
3014 private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2 =
3015 ") TEMP_TABLE INNER JOIN WikiNode ON TEMP_TABLE.nodeId = WikiNode.nodeId";
3016 private static final String _FILTER_SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(DISTINCT wikiNode.nodeId) AS COUNT_VALUE FROM WikiNode wikiNode WHERE ";
3017 private static final String _FILTER_ENTITY_ALIAS = "wikiNode";
3018 private static final String _FILTER_ENTITY_TABLE = "WikiNode";
3019 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
3020 private static final String _ORDER_BY_ENTITY_TABLE = "WikiNode.";
3021 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
3022 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
3023 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3024 private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
3025 private static WikiNode _nullWikiNode = new WikiNodeImpl() {
3026 @Override
3027 public Object clone() {
3028 return this;
3029 }
3030
3031 @Override
3032 public CacheModel<WikiNode> toCacheModel() {
3033 return _nullWikiNodeCacheModel;
3034 }
3035 };
3036
3037 private static CacheModel<WikiNode> _nullWikiNodeCacheModel = new CacheModel<WikiNode>() {
3038 public WikiNode toEntityModel() {
3039 return _nullWikiNode;
3040 }
3041 };
3042 }