001
014
015 package com.liferay.portlet.mobiledevicerules.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.UserPersistence;
046 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047
048 import com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException;
049 import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup;
050 import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupImpl;
051 import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl;
052
053 import java.io.Serializable;
054
055 import java.util.ArrayList;
056 import java.util.Collections;
057 import java.util.List;
058
059
071 public class MDRRuleGroupPersistenceImpl extends BasePersistenceImpl<MDRRuleGroup>
072 implements MDRRuleGroupPersistence {
073
078 public static final String FINDER_CLASS_NAME_ENTITY = MDRRuleGroupImpl.class.getName();
079 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080 ".List1";
081 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List2";
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
084 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
085 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
086 new String[] {
087 String.class.getName(),
088
089 "java.lang.Integer", "java.lang.Integer",
090 "com.liferay.portal.kernel.util.OrderByComparator"
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
093 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
095 new String[] { String.class.getName() },
096 MDRRuleGroupModelImpl.UUID_COLUMN_BITMASK);
097 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
098 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
100 new String[] { String.class.getName() });
101 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
102 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
103 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
104 new String[] { String.class.getName(), Long.class.getName() },
105 MDRRuleGroupModelImpl.UUID_COLUMN_BITMASK |
106 MDRRuleGroupModelImpl.GROUPID_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
108 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
110 new String[] { String.class.getName(), Long.class.getName() });
111 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
112 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
113 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
114 new String[] {
115 Long.class.getName(),
116
117 "java.lang.Integer", "java.lang.Integer",
118 "com.liferay.portal.kernel.util.OrderByComparator"
119 });
120 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
121 new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
122 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
123 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
124 new String[] { Long.class.getName() },
125 MDRRuleGroupModelImpl.GROUPID_COLUMN_BITMASK);
126 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
127 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
129 new String[] { Long.class.getName() });
130 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
131 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
132 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
133 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
134 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
135 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
136 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
137 MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
138 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
139
140
145 public void cacheResult(MDRRuleGroup mdrRuleGroup) {
146 EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
147 MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey(), mdrRuleGroup);
148
149 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
150 new Object[] {
151 mdrRuleGroup.getUuid(), Long.valueOf(mdrRuleGroup.getGroupId())
152 }, mdrRuleGroup);
153
154 mdrRuleGroup.resetOriginalValues();
155 }
156
157
162 public void cacheResult(List<MDRRuleGroup> mdrRuleGroups) {
163 for (MDRRuleGroup mdrRuleGroup : mdrRuleGroups) {
164 if (EntityCacheUtil.getResult(
165 MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
166 MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey()) == null) {
167 cacheResult(mdrRuleGroup);
168 }
169 else {
170 mdrRuleGroup.resetOriginalValues();
171 }
172 }
173 }
174
175
182 @Override
183 public void clearCache() {
184 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
185 CacheRegistryUtil.clear(MDRRuleGroupImpl.class.getName());
186 }
187
188 EntityCacheUtil.clearCache(MDRRuleGroupImpl.class.getName());
189
190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
191 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
192 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
193 }
194
195
202 @Override
203 public void clearCache(MDRRuleGroup mdrRuleGroup) {
204 EntityCacheUtil.removeResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
205 MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey());
206
207 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
208 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
209
210 clearUniqueFindersCache(mdrRuleGroup);
211 }
212
213 @Override
214 public void clearCache(List<MDRRuleGroup> mdrRuleGroups) {
215 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
216 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
217
218 for (MDRRuleGroup mdrRuleGroup : mdrRuleGroups) {
219 EntityCacheUtil.removeResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
220 MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey());
221
222 clearUniqueFindersCache(mdrRuleGroup);
223 }
224 }
225
226 protected void cacheUniqueFindersCache(MDRRuleGroup mdrRuleGroup) {
227 if (mdrRuleGroup.isNew()) {
228 Object[] args = new Object[] {
229 mdrRuleGroup.getUuid(),
230 Long.valueOf(mdrRuleGroup.getGroupId())
231 };
232
233 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
234 Long.valueOf(1));
235 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
236 mdrRuleGroup);
237 }
238 else {
239 MDRRuleGroupModelImpl mdrRuleGroupModelImpl = (MDRRuleGroupModelImpl)mdrRuleGroup;
240
241 if ((mdrRuleGroupModelImpl.getColumnBitmask() &
242 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
243 Object[] args = new Object[] {
244 mdrRuleGroup.getUuid(),
245 Long.valueOf(mdrRuleGroup.getGroupId())
246 };
247
248 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
249 Long.valueOf(1));
250 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
251 mdrRuleGroup);
252 }
253 }
254 }
255
256 protected void clearUniqueFindersCache(MDRRuleGroup mdrRuleGroup) {
257 MDRRuleGroupModelImpl mdrRuleGroupModelImpl = (MDRRuleGroupModelImpl)mdrRuleGroup;
258
259 Object[] args = new Object[] {
260 mdrRuleGroup.getUuid(), Long.valueOf(mdrRuleGroup.getGroupId())
261 };
262
263 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
264 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
265
266 if ((mdrRuleGroupModelImpl.getColumnBitmask() &
267 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
268 args = new Object[] {
269 mdrRuleGroupModelImpl.getOriginalUuid(),
270 Long.valueOf(mdrRuleGroupModelImpl.getOriginalGroupId())
271 };
272
273 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
274 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
275 }
276 }
277
278
284 public MDRRuleGroup create(long ruleGroupId) {
285 MDRRuleGroup mdrRuleGroup = new MDRRuleGroupImpl();
286
287 mdrRuleGroup.setNew(true);
288 mdrRuleGroup.setPrimaryKey(ruleGroupId);
289
290 String uuid = PortalUUIDUtil.generate();
291
292 mdrRuleGroup.setUuid(uuid);
293
294 return mdrRuleGroup;
295 }
296
297
305 public MDRRuleGroup remove(long ruleGroupId)
306 throws NoSuchRuleGroupException, SystemException {
307 return remove(Long.valueOf(ruleGroupId));
308 }
309
310
318 @Override
319 public MDRRuleGroup remove(Serializable primaryKey)
320 throws NoSuchRuleGroupException, SystemException {
321 Session session = null;
322
323 try {
324 session = openSession();
325
326 MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)session.get(MDRRuleGroupImpl.class,
327 primaryKey);
328
329 if (mdrRuleGroup == null) {
330 if (_log.isWarnEnabled()) {
331 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
332 }
333
334 throw new NoSuchRuleGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
335 primaryKey);
336 }
337
338 return remove(mdrRuleGroup);
339 }
340 catch (NoSuchRuleGroupException nsee) {
341 throw nsee;
342 }
343 catch (Exception e) {
344 throw processException(e);
345 }
346 finally {
347 closeSession(session);
348 }
349 }
350
351 @Override
352 protected MDRRuleGroup removeImpl(MDRRuleGroup mdrRuleGroup)
353 throws SystemException {
354 mdrRuleGroup = toUnwrappedModel(mdrRuleGroup);
355
356 Session session = null;
357
358 try {
359 session = openSession();
360
361 BatchSessionUtil.delete(session, mdrRuleGroup);
362 }
363 catch (Exception e) {
364 throw processException(e);
365 }
366 finally {
367 closeSession(session);
368 }
369
370 clearCache(mdrRuleGroup);
371
372 return mdrRuleGroup;
373 }
374
375 @Override
376 public MDRRuleGroup updateImpl(
377 com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup mdrRuleGroup,
378 boolean merge) throws SystemException {
379 mdrRuleGroup = toUnwrappedModel(mdrRuleGroup);
380
381 boolean isNew = mdrRuleGroup.isNew();
382
383 MDRRuleGroupModelImpl mdrRuleGroupModelImpl = (MDRRuleGroupModelImpl)mdrRuleGroup;
384
385 if (Validator.isNull(mdrRuleGroup.getUuid())) {
386 String uuid = PortalUUIDUtil.generate();
387
388 mdrRuleGroup.setUuid(uuid);
389 }
390
391 Session session = null;
392
393 try {
394 session = openSession();
395
396 BatchSessionUtil.update(session, mdrRuleGroup, merge);
397
398 mdrRuleGroup.setNew(false);
399 }
400 catch (Exception e) {
401 throw processException(e);
402 }
403 finally {
404 closeSession(session);
405 }
406
407 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
408
409 if (isNew || !MDRRuleGroupModelImpl.COLUMN_BITMASK_ENABLED) {
410 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
411 }
412
413 else {
414 if ((mdrRuleGroupModelImpl.getColumnBitmask() &
415 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
416 Object[] args = new Object[] {
417 mdrRuleGroupModelImpl.getOriginalUuid()
418 };
419
420 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
421 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
422 args);
423
424 args = new Object[] { mdrRuleGroupModelImpl.getUuid() };
425
426 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
427 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
428 args);
429 }
430
431 if ((mdrRuleGroupModelImpl.getColumnBitmask() &
432 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
433 Object[] args = new Object[] {
434 Long.valueOf(mdrRuleGroupModelImpl.getOriginalGroupId())
435 };
436
437 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
438 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
439 args);
440
441 args = new Object[] {
442 Long.valueOf(mdrRuleGroupModelImpl.getGroupId())
443 };
444
445 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
446 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
447 args);
448 }
449 }
450
451 EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
452 MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey(), mdrRuleGroup);
453
454 clearUniqueFindersCache(mdrRuleGroup);
455 cacheUniqueFindersCache(mdrRuleGroup);
456
457 return mdrRuleGroup;
458 }
459
460 protected MDRRuleGroup toUnwrappedModel(MDRRuleGroup mdrRuleGroup) {
461 if (mdrRuleGroup instanceof MDRRuleGroupImpl) {
462 return mdrRuleGroup;
463 }
464
465 MDRRuleGroupImpl mdrRuleGroupImpl = new MDRRuleGroupImpl();
466
467 mdrRuleGroupImpl.setNew(mdrRuleGroup.isNew());
468 mdrRuleGroupImpl.setPrimaryKey(mdrRuleGroup.getPrimaryKey());
469
470 mdrRuleGroupImpl.setUuid(mdrRuleGroup.getUuid());
471 mdrRuleGroupImpl.setRuleGroupId(mdrRuleGroup.getRuleGroupId());
472 mdrRuleGroupImpl.setGroupId(mdrRuleGroup.getGroupId());
473 mdrRuleGroupImpl.setCompanyId(mdrRuleGroup.getCompanyId());
474 mdrRuleGroupImpl.setUserId(mdrRuleGroup.getUserId());
475 mdrRuleGroupImpl.setUserName(mdrRuleGroup.getUserName());
476 mdrRuleGroupImpl.setCreateDate(mdrRuleGroup.getCreateDate());
477 mdrRuleGroupImpl.setModifiedDate(mdrRuleGroup.getModifiedDate());
478 mdrRuleGroupImpl.setName(mdrRuleGroup.getName());
479 mdrRuleGroupImpl.setDescription(mdrRuleGroup.getDescription());
480
481 return mdrRuleGroupImpl;
482 }
483
484
492 @Override
493 public MDRRuleGroup findByPrimaryKey(Serializable primaryKey)
494 throws NoSuchModelException, SystemException {
495 return findByPrimaryKey(((Long)primaryKey).longValue());
496 }
497
498
506 public MDRRuleGroup findByPrimaryKey(long ruleGroupId)
507 throws NoSuchRuleGroupException, SystemException {
508 MDRRuleGroup mdrRuleGroup = fetchByPrimaryKey(ruleGroupId);
509
510 if (mdrRuleGroup == null) {
511 if (_log.isWarnEnabled()) {
512 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + ruleGroupId);
513 }
514
515 throw new NoSuchRuleGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
516 ruleGroupId);
517 }
518
519 return mdrRuleGroup;
520 }
521
522
529 @Override
530 public MDRRuleGroup fetchByPrimaryKey(Serializable primaryKey)
531 throws SystemException {
532 return fetchByPrimaryKey(((Long)primaryKey).longValue());
533 }
534
535
542 public MDRRuleGroup fetchByPrimaryKey(long ruleGroupId)
543 throws SystemException {
544 MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)EntityCacheUtil.getResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
545 MDRRuleGroupImpl.class, ruleGroupId);
546
547 if (mdrRuleGroup == _nullMDRRuleGroup) {
548 return null;
549 }
550
551 if (mdrRuleGroup == null) {
552 Session session = null;
553
554 boolean hasException = false;
555
556 try {
557 session = openSession();
558
559 mdrRuleGroup = (MDRRuleGroup)session.get(MDRRuleGroupImpl.class,
560 Long.valueOf(ruleGroupId));
561 }
562 catch (Exception e) {
563 hasException = true;
564
565 throw processException(e);
566 }
567 finally {
568 if (mdrRuleGroup != null) {
569 cacheResult(mdrRuleGroup);
570 }
571 else if (!hasException) {
572 EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
573 MDRRuleGroupImpl.class, ruleGroupId, _nullMDRRuleGroup);
574 }
575
576 closeSession(session);
577 }
578 }
579
580 return mdrRuleGroup;
581 }
582
583
590 public List<MDRRuleGroup> findByUuid(String uuid) throws SystemException {
591 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
592 }
593
594
607 public List<MDRRuleGroup> findByUuid(String uuid, int start, int end)
608 throws SystemException {
609 return findByUuid(uuid, start, end, null);
610 }
611
612
626 public List<MDRRuleGroup> findByUuid(String uuid, int start, int end,
627 OrderByComparator orderByComparator) throws SystemException {
628 FinderPath finderPath = null;
629 Object[] finderArgs = null;
630
631 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
632 (orderByComparator == null)) {
633 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
634 finderArgs = new Object[] { uuid };
635 }
636 else {
637 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
638 finderArgs = new Object[] { uuid, start, end, orderByComparator };
639 }
640
641 List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
642 finderArgs, this);
643
644 if ((list != null) && !list.isEmpty()) {
645 for (MDRRuleGroup mdrRuleGroup : list) {
646 if (!Validator.equals(uuid, mdrRuleGroup.getUuid())) {
647 list = null;
648
649 break;
650 }
651 }
652 }
653
654 if (list == null) {
655 StringBundler query = null;
656
657 if (orderByComparator != null) {
658 query = new StringBundler(3 +
659 (orderByComparator.getOrderByFields().length * 3));
660 }
661 else {
662 query = new StringBundler(2);
663 }
664
665 query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
666
667 if (uuid == null) {
668 query.append(_FINDER_COLUMN_UUID_UUID_1);
669 }
670 else {
671 if (uuid.equals(StringPool.BLANK)) {
672 query.append(_FINDER_COLUMN_UUID_UUID_3);
673 }
674 else {
675 query.append(_FINDER_COLUMN_UUID_UUID_2);
676 }
677 }
678
679 if (orderByComparator != null) {
680 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
681 orderByComparator);
682 }
683
684 String sql = query.toString();
685
686 Session session = null;
687
688 try {
689 session = openSession();
690
691 Query q = session.createQuery(sql);
692
693 QueryPos qPos = QueryPos.getInstance(q);
694
695 if (uuid != null) {
696 qPos.add(uuid);
697 }
698
699 list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
700 start, end);
701 }
702 catch (Exception e) {
703 throw processException(e);
704 }
705 finally {
706 if (list == null) {
707 FinderCacheUtil.removeResult(finderPath, finderArgs);
708 }
709 else {
710 cacheResult(list);
711
712 FinderCacheUtil.putResult(finderPath, finderArgs, list);
713 }
714
715 closeSession(session);
716 }
717 }
718
719 return list;
720 }
721
722
731 public MDRRuleGroup findByUuid_First(String uuid,
732 OrderByComparator orderByComparator)
733 throws NoSuchRuleGroupException, SystemException {
734 MDRRuleGroup mdrRuleGroup = fetchByUuid_First(uuid, orderByComparator);
735
736 if (mdrRuleGroup != null) {
737 return mdrRuleGroup;
738 }
739
740 StringBundler msg = new StringBundler(4);
741
742 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
743
744 msg.append("uuid=");
745 msg.append(uuid);
746
747 msg.append(StringPool.CLOSE_CURLY_BRACE);
748
749 throw new NoSuchRuleGroupException(msg.toString());
750 }
751
752
760 public MDRRuleGroup fetchByUuid_First(String uuid,
761 OrderByComparator orderByComparator) throws SystemException {
762 List<MDRRuleGroup> list = findByUuid(uuid, 0, 1, orderByComparator);
763
764 if (!list.isEmpty()) {
765 return list.get(0);
766 }
767
768 return null;
769 }
770
771
780 public MDRRuleGroup findByUuid_Last(String uuid,
781 OrderByComparator orderByComparator)
782 throws NoSuchRuleGroupException, SystemException {
783 MDRRuleGroup mdrRuleGroup = fetchByUuid_Last(uuid, orderByComparator);
784
785 if (mdrRuleGroup != null) {
786 return mdrRuleGroup;
787 }
788
789 StringBundler msg = new StringBundler(4);
790
791 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
792
793 msg.append("uuid=");
794 msg.append(uuid);
795
796 msg.append(StringPool.CLOSE_CURLY_BRACE);
797
798 throw new NoSuchRuleGroupException(msg.toString());
799 }
800
801
809 public MDRRuleGroup fetchByUuid_Last(String uuid,
810 OrderByComparator orderByComparator) throws SystemException {
811 int count = countByUuid(uuid);
812
813 List<MDRRuleGroup> list = findByUuid(uuid, count - 1, count,
814 orderByComparator);
815
816 if (!list.isEmpty()) {
817 return list.get(0);
818 }
819
820 return null;
821 }
822
823
833 public MDRRuleGroup[] findByUuid_PrevAndNext(long ruleGroupId, String uuid,
834 OrderByComparator orderByComparator)
835 throws NoSuchRuleGroupException, SystemException {
836 MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
837
838 Session session = null;
839
840 try {
841 session = openSession();
842
843 MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
844
845 array[0] = getByUuid_PrevAndNext(session, mdrRuleGroup, uuid,
846 orderByComparator, true);
847
848 array[1] = mdrRuleGroup;
849
850 array[2] = getByUuid_PrevAndNext(session, mdrRuleGroup, uuid,
851 orderByComparator, false);
852
853 return array;
854 }
855 catch (Exception e) {
856 throw processException(e);
857 }
858 finally {
859 closeSession(session);
860 }
861 }
862
863 protected MDRRuleGroup getByUuid_PrevAndNext(Session session,
864 MDRRuleGroup mdrRuleGroup, String uuid,
865 OrderByComparator orderByComparator, boolean previous) {
866 StringBundler query = null;
867
868 if (orderByComparator != null) {
869 query = new StringBundler(6 +
870 (orderByComparator.getOrderByFields().length * 6));
871 }
872 else {
873 query = new StringBundler(3);
874 }
875
876 query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
877
878 if (uuid == null) {
879 query.append(_FINDER_COLUMN_UUID_UUID_1);
880 }
881 else {
882 if (uuid.equals(StringPool.BLANK)) {
883 query.append(_FINDER_COLUMN_UUID_UUID_3);
884 }
885 else {
886 query.append(_FINDER_COLUMN_UUID_UUID_2);
887 }
888 }
889
890 if (orderByComparator != null) {
891 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
892
893 if (orderByConditionFields.length > 0) {
894 query.append(WHERE_AND);
895 }
896
897 for (int i = 0; i < orderByConditionFields.length; i++) {
898 query.append(_ORDER_BY_ENTITY_ALIAS);
899 query.append(orderByConditionFields[i]);
900
901 if ((i + 1) < orderByConditionFields.length) {
902 if (orderByComparator.isAscending() ^ previous) {
903 query.append(WHERE_GREATER_THAN_HAS_NEXT);
904 }
905 else {
906 query.append(WHERE_LESSER_THAN_HAS_NEXT);
907 }
908 }
909 else {
910 if (orderByComparator.isAscending() ^ previous) {
911 query.append(WHERE_GREATER_THAN);
912 }
913 else {
914 query.append(WHERE_LESSER_THAN);
915 }
916 }
917 }
918
919 query.append(ORDER_BY_CLAUSE);
920
921 String[] orderByFields = orderByComparator.getOrderByFields();
922
923 for (int i = 0; i < orderByFields.length; i++) {
924 query.append(_ORDER_BY_ENTITY_ALIAS);
925 query.append(orderByFields[i]);
926
927 if ((i + 1) < orderByFields.length) {
928 if (orderByComparator.isAscending() ^ previous) {
929 query.append(ORDER_BY_ASC_HAS_NEXT);
930 }
931 else {
932 query.append(ORDER_BY_DESC_HAS_NEXT);
933 }
934 }
935 else {
936 if (orderByComparator.isAscending() ^ previous) {
937 query.append(ORDER_BY_ASC);
938 }
939 else {
940 query.append(ORDER_BY_DESC);
941 }
942 }
943 }
944 }
945
946 String sql = query.toString();
947
948 Query q = session.createQuery(sql);
949
950 q.setFirstResult(0);
951 q.setMaxResults(2);
952
953 QueryPos qPos = QueryPos.getInstance(q);
954
955 if (uuid != null) {
956 qPos.add(uuid);
957 }
958
959 if (orderByComparator != null) {
960 Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
961
962 for (Object value : values) {
963 qPos.add(value);
964 }
965 }
966
967 List<MDRRuleGroup> list = q.list();
968
969 if (list.size() == 2) {
970 return list.get(1);
971 }
972 else {
973 return null;
974 }
975 }
976
977
986 public MDRRuleGroup findByUUID_G(String uuid, long groupId)
987 throws NoSuchRuleGroupException, SystemException {
988 MDRRuleGroup mdrRuleGroup = fetchByUUID_G(uuid, groupId);
989
990 if (mdrRuleGroup == null) {
991 StringBundler msg = new StringBundler(6);
992
993 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
994
995 msg.append("uuid=");
996 msg.append(uuid);
997
998 msg.append(", groupId=");
999 msg.append(groupId);
1000
1001 msg.append(StringPool.CLOSE_CURLY_BRACE);
1002
1003 if (_log.isWarnEnabled()) {
1004 _log.warn(msg.toString());
1005 }
1006
1007 throw new NoSuchRuleGroupException(msg.toString());
1008 }
1009
1010 return mdrRuleGroup;
1011 }
1012
1013
1021 public MDRRuleGroup fetchByUUID_G(String uuid, long groupId)
1022 throws SystemException {
1023 return fetchByUUID_G(uuid, groupId, true);
1024 }
1025
1026
1035 public MDRRuleGroup fetchByUUID_G(String uuid, long groupId,
1036 boolean retrieveFromCache) throws SystemException {
1037 Object[] finderArgs = new Object[] { uuid, groupId };
1038
1039 Object result = null;
1040
1041 if (retrieveFromCache) {
1042 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1043 finderArgs, this);
1044 }
1045
1046 if (result instanceof MDRRuleGroup) {
1047 MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)result;
1048
1049 if (!Validator.equals(uuid, mdrRuleGroup.getUuid()) ||
1050 (groupId != mdrRuleGroup.getGroupId())) {
1051 result = null;
1052 }
1053 }
1054
1055 if (result == null) {
1056 StringBundler query = new StringBundler(3);
1057
1058 query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1059
1060 if (uuid == null) {
1061 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1062 }
1063 else {
1064 if (uuid.equals(StringPool.BLANK)) {
1065 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1066 }
1067 else {
1068 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1069 }
1070 }
1071
1072 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1073
1074 String sql = query.toString();
1075
1076 Session session = null;
1077
1078 try {
1079 session = openSession();
1080
1081 Query q = session.createQuery(sql);
1082
1083 QueryPos qPos = QueryPos.getInstance(q);
1084
1085 if (uuid != null) {
1086 qPos.add(uuid);
1087 }
1088
1089 qPos.add(groupId);
1090
1091 List<MDRRuleGroup> list = q.list();
1092
1093 result = list;
1094
1095 MDRRuleGroup mdrRuleGroup = null;
1096
1097 if (list.isEmpty()) {
1098 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1099 finderArgs, list);
1100 }
1101 else {
1102 mdrRuleGroup = list.get(0);
1103
1104 cacheResult(mdrRuleGroup);
1105
1106 if ((mdrRuleGroup.getUuid() == null) ||
1107 !mdrRuleGroup.getUuid().equals(uuid) ||
1108 (mdrRuleGroup.getGroupId() != groupId)) {
1109 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1110 finderArgs, mdrRuleGroup);
1111 }
1112 }
1113
1114 return mdrRuleGroup;
1115 }
1116 catch (Exception e) {
1117 throw processException(e);
1118 }
1119 finally {
1120 if (result == null) {
1121 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1122 finderArgs);
1123 }
1124
1125 closeSession(session);
1126 }
1127 }
1128 else {
1129 if (result instanceof List<?>) {
1130 return null;
1131 }
1132 else {
1133 return (MDRRuleGroup)result;
1134 }
1135 }
1136 }
1137
1138
1145 public List<MDRRuleGroup> findByGroupId(long groupId)
1146 throws SystemException {
1147 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1148 }
1149
1150
1163 public List<MDRRuleGroup> findByGroupId(long groupId, int start, int end)
1164 throws SystemException {
1165 return findByGroupId(groupId, start, end, null);
1166 }
1167
1168
1182 public List<MDRRuleGroup> findByGroupId(long groupId, int start, int end,
1183 OrderByComparator orderByComparator) throws SystemException {
1184 FinderPath finderPath = null;
1185 Object[] finderArgs = null;
1186
1187 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1188 (orderByComparator == null)) {
1189 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1190 finderArgs = new Object[] { groupId };
1191 }
1192 else {
1193 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1194 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1195 }
1196
1197 List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
1198 finderArgs, this);
1199
1200 if ((list != null) && !list.isEmpty()) {
1201 for (MDRRuleGroup mdrRuleGroup : list) {
1202 if ((groupId != mdrRuleGroup.getGroupId())) {
1203 list = null;
1204
1205 break;
1206 }
1207 }
1208 }
1209
1210 if (list == null) {
1211 StringBundler query = null;
1212
1213 if (orderByComparator != null) {
1214 query = new StringBundler(3 +
1215 (orderByComparator.getOrderByFields().length * 3));
1216 }
1217 else {
1218 query = new StringBundler(2);
1219 }
1220
1221 query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1222
1223 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1224
1225 if (orderByComparator != null) {
1226 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1227 orderByComparator);
1228 }
1229
1230 String sql = query.toString();
1231
1232 Session session = null;
1233
1234 try {
1235 session = openSession();
1236
1237 Query q = session.createQuery(sql);
1238
1239 QueryPos qPos = QueryPos.getInstance(q);
1240
1241 qPos.add(groupId);
1242
1243 list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
1244 start, end);
1245 }
1246 catch (Exception e) {
1247 throw processException(e);
1248 }
1249 finally {
1250 if (list == null) {
1251 FinderCacheUtil.removeResult(finderPath, finderArgs);
1252 }
1253 else {
1254 cacheResult(list);
1255
1256 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1257 }
1258
1259 closeSession(session);
1260 }
1261 }
1262
1263 return list;
1264 }
1265
1266
1275 public MDRRuleGroup findByGroupId_First(long groupId,
1276 OrderByComparator orderByComparator)
1277 throws NoSuchRuleGroupException, SystemException {
1278 MDRRuleGroup mdrRuleGroup = fetchByGroupId_First(groupId,
1279 orderByComparator);
1280
1281 if (mdrRuleGroup != null) {
1282 return mdrRuleGroup;
1283 }
1284
1285 StringBundler msg = new StringBundler(4);
1286
1287 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1288
1289 msg.append("groupId=");
1290 msg.append(groupId);
1291
1292 msg.append(StringPool.CLOSE_CURLY_BRACE);
1293
1294 throw new NoSuchRuleGroupException(msg.toString());
1295 }
1296
1297
1305 public MDRRuleGroup fetchByGroupId_First(long groupId,
1306 OrderByComparator orderByComparator) throws SystemException {
1307 List<MDRRuleGroup> list = findByGroupId(groupId, 0, 1, orderByComparator);
1308
1309 if (!list.isEmpty()) {
1310 return list.get(0);
1311 }
1312
1313 return null;
1314 }
1315
1316
1325 public MDRRuleGroup findByGroupId_Last(long groupId,
1326 OrderByComparator orderByComparator)
1327 throws NoSuchRuleGroupException, SystemException {
1328 MDRRuleGroup mdrRuleGroup = fetchByGroupId_Last(groupId,
1329 orderByComparator);
1330
1331 if (mdrRuleGroup != null) {
1332 return mdrRuleGroup;
1333 }
1334
1335 StringBundler msg = new StringBundler(4);
1336
1337 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1338
1339 msg.append("groupId=");
1340 msg.append(groupId);
1341
1342 msg.append(StringPool.CLOSE_CURLY_BRACE);
1343
1344 throw new NoSuchRuleGroupException(msg.toString());
1345 }
1346
1347
1355 public MDRRuleGroup fetchByGroupId_Last(long groupId,
1356 OrderByComparator orderByComparator) throws SystemException {
1357 int count = countByGroupId(groupId);
1358
1359 List<MDRRuleGroup> list = findByGroupId(groupId, count - 1, count,
1360 orderByComparator);
1361
1362 if (!list.isEmpty()) {
1363 return list.get(0);
1364 }
1365
1366 return null;
1367 }
1368
1369
1379 public MDRRuleGroup[] findByGroupId_PrevAndNext(long ruleGroupId,
1380 long groupId, OrderByComparator orderByComparator)
1381 throws NoSuchRuleGroupException, SystemException {
1382 MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
1383
1384 Session session = null;
1385
1386 try {
1387 session = openSession();
1388
1389 MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
1390
1391 array[0] = getByGroupId_PrevAndNext(session, mdrRuleGroup, groupId,
1392 orderByComparator, true);
1393
1394 array[1] = mdrRuleGroup;
1395
1396 array[2] = getByGroupId_PrevAndNext(session, mdrRuleGroup, groupId,
1397 orderByComparator, false);
1398
1399 return array;
1400 }
1401 catch (Exception e) {
1402 throw processException(e);
1403 }
1404 finally {
1405 closeSession(session);
1406 }
1407 }
1408
1409 protected MDRRuleGroup getByGroupId_PrevAndNext(Session session,
1410 MDRRuleGroup mdrRuleGroup, long groupId,
1411 OrderByComparator orderByComparator, boolean previous) {
1412 StringBundler query = null;
1413
1414 if (orderByComparator != null) {
1415 query = new StringBundler(6 +
1416 (orderByComparator.getOrderByFields().length * 6));
1417 }
1418 else {
1419 query = new StringBundler(3);
1420 }
1421
1422 query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1423
1424 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1425
1426 if (orderByComparator != null) {
1427 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1428
1429 if (orderByConditionFields.length > 0) {
1430 query.append(WHERE_AND);
1431 }
1432
1433 for (int i = 0; i < orderByConditionFields.length; i++) {
1434 query.append(_ORDER_BY_ENTITY_ALIAS);
1435 query.append(orderByConditionFields[i]);
1436
1437 if ((i + 1) < orderByConditionFields.length) {
1438 if (orderByComparator.isAscending() ^ previous) {
1439 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1440 }
1441 else {
1442 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1443 }
1444 }
1445 else {
1446 if (orderByComparator.isAscending() ^ previous) {
1447 query.append(WHERE_GREATER_THAN);
1448 }
1449 else {
1450 query.append(WHERE_LESSER_THAN);
1451 }
1452 }
1453 }
1454
1455 query.append(ORDER_BY_CLAUSE);
1456
1457 String[] orderByFields = orderByComparator.getOrderByFields();
1458
1459 for (int i = 0; i < orderByFields.length; i++) {
1460 query.append(_ORDER_BY_ENTITY_ALIAS);
1461 query.append(orderByFields[i]);
1462
1463 if ((i + 1) < orderByFields.length) {
1464 if (orderByComparator.isAscending() ^ previous) {
1465 query.append(ORDER_BY_ASC_HAS_NEXT);
1466 }
1467 else {
1468 query.append(ORDER_BY_DESC_HAS_NEXT);
1469 }
1470 }
1471 else {
1472 if (orderByComparator.isAscending() ^ previous) {
1473 query.append(ORDER_BY_ASC);
1474 }
1475 else {
1476 query.append(ORDER_BY_DESC);
1477 }
1478 }
1479 }
1480 }
1481
1482 String sql = query.toString();
1483
1484 Query q = session.createQuery(sql);
1485
1486 q.setFirstResult(0);
1487 q.setMaxResults(2);
1488
1489 QueryPos qPos = QueryPos.getInstance(q);
1490
1491 qPos.add(groupId);
1492
1493 if (orderByComparator != null) {
1494 Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
1495
1496 for (Object value : values) {
1497 qPos.add(value);
1498 }
1499 }
1500
1501 List<MDRRuleGroup> list = q.list();
1502
1503 if (list.size() == 2) {
1504 return list.get(1);
1505 }
1506 else {
1507 return null;
1508 }
1509 }
1510
1511
1518 public List<MDRRuleGroup> filterFindByGroupId(long groupId)
1519 throws SystemException {
1520 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1521 QueryUtil.ALL_POS, null);
1522 }
1523
1524
1537 public List<MDRRuleGroup> filterFindByGroupId(long groupId, int start,
1538 int end) throws SystemException {
1539 return filterFindByGroupId(groupId, start, end, null);
1540 }
1541
1542
1556 public List<MDRRuleGroup> filterFindByGroupId(long groupId, int start,
1557 int end, OrderByComparator orderByComparator) throws SystemException {
1558 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1559 return findByGroupId(groupId, start, end, orderByComparator);
1560 }
1561
1562 StringBundler query = null;
1563
1564 if (orderByComparator != null) {
1565 query = new StringBundler(3 +
1566 (orderByComparator.getOrderByFields().length * 3));
1567 }
1568 else {
1569 query = new StringBundler(2);
1570 }
1571
1572 if (getDB().isSupportsInlineDistinct()) {
1573 query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_WHERE);
1574 }
1575 else {
1576 query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1);
1577 }
1578
1579 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1580
1581 if (!getDB().isSupportsInlineDistinct()) {
1582 query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2);
1583 }
1584
1585 if (orderByComparator != null) {
1586 if (getDB().isSupportsInlineDistinct()) {
1587 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1588 orderByComparator);
1589 }
1590 else {
1591 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1592 orderByComparator);
1593 }
1594 }
1595
1596 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1597 MDRRuleGroup.class.getName(),
1598 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1599
1600 Session session = null;
1601
1602 try {
1603 session = openSession();
1604
1605 SQLQuery q = session.createSQLQuery(sql);
1606
1607 if (getDB().isSupportsInlineDistinct()) {
1608 q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupImpl.class);
1609 }
1610 else {
1611 q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupImpl.class);
1612 }
1613
1614 QueryPos qPos = QueryPos.getInstance(q);
1615
1616 qPos.add(groupId);
1617
1618 return (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(), start,
1619 end);
1620 }
1621 catch (Exception e) {
1622 throw processException(e);
1623 }
1624 finally {
1625 closeSession(session);
1626 }
1627 }
1628
1629
1639 public MDRRuleGroup[] filterFindByGroupId_PrevAndNext(long ruleGroupId,
1640 long groupId, OrderByComparator orderByComparator)
1641 throws NoSuchRuleGroupException, SystemException {
1642 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1643 return findByGroupId_PrevAndNext(ruleGroupId, groupId,
1644 orderByComparator);
1645 }
1646
1647 MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
1648
1649 Session session = null;
1650
1651 try {
1652 session = openSession();
1653
1654 MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
1655
1656 array[0] = filterGetByGroupId_PrevAndNext(session, mdrRuleGroup,
1657 groupId, orderByComparator, true);
1658
1659 array[1] = mdrRuleGroup;
1660
1661 array[2] = filterGetByGroupId_PrevAndNext(session, mdrRuleGroup,
1662 groupId, orderByComparator, false);
1663
1664 return array;
1665 }
1666 catch (Exception e) {
1667 throw processException(e);
1668 }
1669 finally {
1670 closeSession(session);
1671 }
1672 }
1673
1674 protected MDRRuleGroup filterGetByGroupId_PrevAndNext(Session session,
1675 MDRRuleGroup mdrRuleGroup, long groupId,
1676 OrderByComparator orderByComparator, boolean previous) {
1677 StringBundler query = null;
1678
1679 if (orderByComparator != null) {
1680 query = new StringBundler(6 +
1681 (orderByComparator.getOrderByFields().length * 6));
1682 }
1683 else {
1684 query = new StringBundler(3);
1685 }
1686
1687 if (getDB().isSupportsInlineDistinct()) {
1688 query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_WHERE);
1689 }
1690 else {
1691 query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1);
1692 }
1693
1694 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1695
1696 if (!getDB().isSupportsInlineDistinct()) {
1697 query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2);
1698 }
1699
1700 if (orderByComparator != null) {
1701 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1702
1703 if (orderByConditionFields.length > 0) {
1704 query.append(WHERE_AND);
1705 }
1706
1707 for (int i = 0; i < orderByConditionFields.length; i++) {
1708 if (getDB().isSupportsInlineDistinct()) {
1709 query.append(_ORDER_BY_ENTITY_ALIAS);
1710 }
1711 else {
1712 query.append(_ORDER_BY_ENTITY_TABLE);
1713 }
1714
1715 query.append(orderByConditionFields[i]);
1716
1717 if ((i + 1) < orderByConditionFields.length) {
1718 if (orderByComparator.isAscending() ^ previous) {
1719 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1720 }
1721 else {
1722 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1723 }
1724 }
1725 else {
1726 if (orderByComparator.isAscending() ^ previous) {
1727 query.append(WHERE_GREATER_THAN);
1728 }
1729 else {
1730 query.append(WHERE_LESSER_THAN);
1731 }
1732 }
1733 }
1734
1735 query.append(ORDER_BY_CLAUSE);
1736
1737 String[] orderByFields = orderByComparator.getOrderByFields();
1738
1739 for (int i = 0; i < orderByFields.length; i++) {
1740 if (getDB().isSupportsInlineDistinct()) {
1741 query.append(_ORDER_BY_ENTITY_ALIAS);
1742 }
1743 else {
1744 query.append(_ORDER_BY_ENTITY_TABLE);
1745 }
1746
1747 query.append(orderByFields[i]);
1748
1749 if ((i + 1) < orderByFields.length) {
1750 if (orderByComparator.isAscending() ^ previous) {
1751 query.append(ORDER_BY_ASC_HAS_NEXT);
1752 }
1753 else {
1754 query.append(ORDER_BY_DESC_HAS_NEXT);
1755 }
1756 }
1757 else {
1758 if (orderByComparator.isAscending() ^ previous) {
1759 query.append(ORDER_BY_ASC);
1760 }
1761 else {
1762 query.append(ORDER_BY_DESC);
1763 }
1764 }
1765 }
1766 }
1767
1768 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1769 MDRRuleGroup.class.getName(),
1770 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1771
1772 SQLQuery q = session.createSQLQuery(sql);
1773
1774 q.setFirstResult(0);
1775 q.setMaxResults(2);
1776
1777 if (getDB().isSupportsInlineDistinct()) {
1778 q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupImpl.class);
1779 }
1780 else {
1781 q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupImpl.class);
1782 }
1783
1784 QueryPos qPos = QueryPos.getInstance(q);
1785
1786 qPos.add(groupId);
1787
1788 if (orderByComparator != null) {
1789 Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
1790
1791 for (Object value : values) {
1792 qPos.add(value);
1793 }
1794 }
1795
1796 List<MDRRuleGroup> list = q.list();
1797
1798 if (list.size() == 2) {
1799 return list.get(1);
1800 }
1801 else {
1802 return null;
1803 }
1804 }
1805
1806
1812 public List<MDRRuleGroup> findAll() throws SystemException {
1813 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1814 }
1815
1816
1828 public List<MDRRuleGroup> findAll(int start, int end)
1829 throws SystemException {
1830 return findAll(start, end, null);
1831 }
1832
1833
1846 public List<MDRRuleGroup> findAll(int start, int end,
1847 OrderByComparator orderByComparator) throws SystemException {
1848 FinderPath finderPath = null;
1849 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1850
1851 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1852 (orderByComparator == null)) {
1853 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1854 finderArgs = FINDER_ARGS_EMPTY;
1855 }
1856 else {
1857 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1858 finderArgs = new Object[] { start, end, orderByComparator };
1859 }
1860
1861 List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
1862 finderArgs, this);
1863
1864 if (list == null) {
1865 StringBundler query = null;
1866 String sql = null;
1867
1868 if (orderByComparator != null) {
1869 query = new StringBundler(2 +
1870 (orderByComparator.getOrderByFields().length * 3));
1871
1872 query.append(_SQL_SELECT_MDRRULEGROUP);
1873
1874 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1875 orderByComparator);
1876
1877 sql = query.toString();
1878 }
1879 else {
1880 sql = _SQL_SELECT_MDRRULEGROUP;
1881 }
1882
1883 Session session = null;
1884
1885 try {
1886 session = openSession();
1887
1888 Query q = session.createQuery(sql);
1889
1890 if (orderByComparator == null) {
1891 list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
1892 start, end, false);
1893
1894 Collections.sort(list);
1895 }
1896 else {
1897 list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
1898 start, end);
1899 }
1900 }
1901 catch (Exception e) {
1902 throw processException(e);
1903 }
1904 finally {
1905 if (list == null) {
1906 FinderCacheUtil.removeResult(finderPath, finderArgs);
1907 }
1908 else {
1909 cacheResult(list);
1910
1911 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1912 }
1913
1914 closeSession(session);
1915 }
1916 }
1917
1918 return list;
1919 }
1920
1921
1927 public void removeByUuid(String uuid) throws SystemException {
1928 for (MDRRuleGroup mdrRuleGroup : findByUuid(uuid)) {
1929 remove(mdrRuleGroup);
1930 }
1931 }
1932
1933
1941 public MDRRuleGroup removeByUUID_G(String uuid, long groupId)
1942 throws NoSuchRuleGroupException, SystemException {
1943 MDRRuleGroup mdrRuleGroup = findByUUID_G(uuid, groupId);
1944
1945 return remove(mdrRuleGroup);
1946 }
1947
1948
1954 public void removeByGroupId(long groupId) throws SystemException {
1955 for (MDRRuleGroup mdrRuleGroup : findByGroupId(groupId)) {
1956 remove(mdrRuleGroup);
1957 }
1958 }
1959
1960
1965 public void removeAll() throws SystemException {
1966 for (MDRRuleGroup mdrRuleGroup : findAll()) {
1967 remove(mdrRuleGroup);
1968 }
1969 }
1970
1971
1978 public int countByUuid(String uuid) throws SystemException {
1979 Object[] finderArgs = new Object[] { uuid };
1980
1981 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1982 finderArgs, this);
1983
1984 if (count == null) {
1985 StringBundler query = new StringBundler(2);
1986
1987 query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
1988
1989 if (uuid == null) {
1990 query.append(_FINDER_COLUMN_UUID_UUID_1);
1991 }
1992 else {
1993 if (uuid.equals(StringPool.BLANK)) {
1994 query.append(_FINDER_COLUMN_UUID_UUID_3);
1995 }
1996 else {
1997 query.append(_FINDER_COLUMN_UUID_UUID_2);
1998 }
1999 }
2000
2001 String sql = query.toString();
2002
2003 Session session = null;
2004
2005 try {
2006 session = openSession();
2007
2008 Query q = session.createQuery(sql);
2009
2010 QueryPos qPos = QueryPos.getInstance(q);
2011
2012 if (uuid != null) {
2013 qPos.add(uuid);
2014 }
2015
2016 count = (Long)q.uniqueResult();
2017 }
2018 catch (Exception e) {
2019 throw processException(e);
2020 }
2021 finally {
2022 if (count == null) {
2023 count = Long.valueOf(0);
2024 }
2025
2026 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2027 finderArgs, count);
2028
2029 closeSession(session);
2030 }
2031 }
2032
2033 return count.intValue();
2034 }
2035
2036
2044 public int countByUUID_G(String uuid, long groupId)
2045 throws SystemException {
2046 Object[] finderArgs = new Object[] { uuid, groupId };
2047
2048 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2049 finderArgs, this);
2050
2051 if (count == null) {
2052 StringBundler query = new StringBundler(3);
2053
2054 query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
2055
2056 if (uuid == null) {
2057 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2058 }
2059 else {
2060 if (uuid.equals(StringPool.BLANK)) {
2061 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2062 }
2063 else {
2064 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2065 }
2066 }
2067
2068 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2069
2070 String sql = query.toString();
2071
2072 Session session = null;
2073
2074 try {
2075 session = openSession();
2076
2077 Query q = session.createQuery(sql);
2078
2079 QueryPos qPos = QueryPos.getInstance(q);
2080
2081 if (uuid != null) {
2082 qPos.add(uuid);
2083 }
2084
2085 qPos.add(groupId);
2086
2087 count = (Long)q.uniqueResult();
2088 }
2089 catch (Exception e) {
2090 throw processException(e);
2091 }
2092 finally {
2093 if (count == null) {
2094 count = Long.valueOf(0);
2095 }
2096
2097 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2098 finderArgs, count);
2099
2100 closeSession(session);
2101 }
2102 }
2103
2104 return count.intValue();
2105 }
2106
2107
2114 public int countByGroupId(long groupId) throws SystemException {
2115 Object[] finderArgs = new Object[] { groupId };
2116
2117 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2118 finderArgs, this);
2119
2120 if (count == null) {
2121 StringBundler query = new StringBundler(2);
2122
2123 query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
2124
2125 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2126
2127 String sql = query.toString();
2128
2129 Session session = null;
2130
2131 try {
2132 session = openSession();
2133
2134 Query q = session.createQuery(sql);
2135
2136 QueryPos qPos = QueryPos.getInstance(q);
2137
2138 qPos.add(groupId);
2139
2140 count = (Long)q.uniqueResult();
2141 }
2142 catch (Exception e) {
2143 throw processException(e);
2144 }
2145 finally {
2146 if (count == null) {
2147 count = Long.valueOf(0);
2148 }
2149
2150 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2151 finderArgs, count);
2152
2153 closeSession(session);
2154 }
2155 }
2156
2157 return count.intValue();
2158 }
2159
2160
2167 public int filterCountByGroupId(long groupId) throws SystemException {
2168 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2169 return countByGroupId(groupId);
2170 }
2171
2172 StringBundler query = new StringBundler(2);
2173
2174 query.append(_FILTER_SQL_COUNT_MDRRULEGROUP_WHERE);
2175
2176 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2177
2178 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2179 MDRRuleGroup.class.getName(),
2180 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2181
2182 Session session = null;
2183
2184 try {
2185 session = openSession();
2186
2187 SQLQuery q = session.createSQLQuery(sql);
2188
2189 q.addScalar(COUNT_COLUMN_NAME,
2190 com.liferay.portal.kernel.dao.orm.Type.LONG);
2191
2192 QueryPos qPos = QueryPos.getInstance(q);
2193
2194 qPos.add(groupId);
2195
2196 Long count = (Long)q.uniqueResult();
2197
2198 return count.intValue();
2199 }
2200 catch (Exception e) {
2201 throw processException(e);
2202 }
2203 finally {
2204 closeSession(session);
2205 }
2206 }
2207
2208
2214 public int countAll() throws SystemException {
2215 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2216 FINDER_ARGS_EMPTY, this);
2217
2218 if (count == null) {
2219 Session session = null;
2220
2221 try {
2222 session = openSession();
2223
2224 Query q = session.createQuery(_SQL_COUNT_MDRRULEGROUP);
2225
2226 count = (Long)q.uniqueResult();
2227 }
2228 catch (Exception e) {
2229 throw processException(e);
2230 }
2231 finally {
2232 if (count == null) {
2233 count = Long.valueOf(0);
2234 }
2235
2236 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2237 FINDER_ARGS_EMPTY, count);
2238
2239 closeSession(session);
2240 }
2241 }
2242
2243 return count.intValue();
2244 }
2245
2246
2249 public void afterPropertiesSet() {
2250 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2251 com.liferay.portal.util.PropsUtil.get(
2252 "value.object.listener.com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup")));
2253
2254 if (listenerClassNames.length > 0) {
2255 try {
2256 List<ModelListener<MDRRuleGroup>> listenersList = new ArrayList<ModelListener<MDRRuleGroup>>();
2257
2258 for (String listenerClassName : listenerClassNames) {
2259 Class<?> clazz = getClass();
2260
2261 listenersList.add((ModelListener<MDRRuleGroup>)InstanceFactory.newInstance(
2262 clazz.getClassLoader(), listenerClassName));
2263 }
2264
2265 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2266 }
2267 catch (Exception e) {
2268 _log.error(e);
2269 }
2270 }
2271 }
2272
2273 public void destroy() {
2274 EntityCacheUtil.removeCache(MDRRuleGroupImpl.class.getName());
2275 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2276 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2277 }
2278
2279 @BeanReference(type = MDRActionPersistence.class)
2280 protected MDRActionPersistence mdrActionPersistence;
2281 @BeanReference(type = MDRRulePersistence.class)
2282 protected MDRRulePersistence mdrRulePersistence;
2283 @BeanReference(type = MDRRuleGroupPersistence.class)
2284 protected MDRRuleGroupPersistence mdrRuleGroupPersistence;
2285 @BeanReference(type = MDRRuleGroupInstancePersistence.class)
2286 protected MDRRuleGroupInstancePersistence mdrRuleGroupInstancePersistence;
2287 @BeanReference(type = GroupPersistence.class)
2288 protected GroupPersistence groupPersistence;
2289 @BeanReference(type = ResourcePersistence.class)
2290 protected ResourcePersistence resourcePersistence;
2291 @BeanReference(type = UserPersistence.class)
2292 protected UserPersistence userPersistence;
2293 private static final String _SQL_SELECT_MDRRULEGROUP = "SELECT mdrRuleGroup FROM MDRRuleGroup mdrRuleGroup";
2294 private static final String _SQL_SELECT_MDRRULEGROUP_WHERE = "SELECT mdrRuleGroup FROM MDRRuleGroup mdrRuleGroup WHERE ";
2295 private static final String _SQL_COUNT_MDRRULEGROUP = "SELECT COUNT(mdrRuleGroup) FROM MDRRuleGroup mdrRuleGroup";
2296 private static final String _SQL_COUNT_MDRRULEGROUP_WHERE = "SELECT COUNT(mdrRuleGroup) FROM MDRRuleGroup mdrRuleGroup WHERE ";
2297 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mdrRuleGroup.uuid IS NULL";
2298 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrRuleGroup.uuid = ?";
2299 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrRuleGroup.uuid IS NULL OR mdrRuleGroup.uuid = ?)";
2300 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mdrRuleGroup.uuid IS NULL AND ";
2301 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrRuleGroup.uuid = ? AND ";
2302 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrRuleGroup.uuid IS NULL OR mdrRuleGroup.uuid = ?) AND ";
2303 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrRuleGroup.groupId = ?";
2304 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mdrRuleGroup.groupId = ?";
2305 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mdrRuleGroup.ruleGroupId";
2306 private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_WHERE = "SELECT DISTINCT {mdrRuleGroup.*} FROM MDRRuleGroup mdrRuleGroup WHERE ";
2307 private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1 =
2308 "SELECT {MDRRuleGroup.*} FROM (SELECT DISTINCT mdrRuleGroup.ruleGroupId FROM MDRRuleGroup mdrRuleGroup WHERE ";
2309 private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2 =
2310 ") TEMP_TABLE INNER JOIN MDRRuleGroup ON TEMP_TABLE.ruleGroupId = MDRRuleGroup.ruleGroupId";
2311 private static final String _FILTER_SQL_COUNT_MDRRULEGROUP_WHERE = "SELECT COUNT(DISTINCT mdrRuleGroup.ruleGroupId) AS COUNT_VALUE FROM MDRRuleGroup mdrRuleGroup WHERE ";
2312 private static final String _FILTER_ENTITY_ALIAS = "mdrRuleGroup";
2313 private static final String _FILTER_ENTITY_TABLE = "MDRRuleGroup";
2314 private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRuleGroup.";
2315 private static final String _ORDER_BY_ENTITY_TABLE = "MDRRuleGroup.";
2316 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRuleGroup exists with the primary key ";
2317 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRuleGroup exists with the key {";
2318 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2319 private static Log _log = LogFactoryUtil.getLog(MDRRuleGroupPersistenceImpl.class);
2320 private static MDRRuleGroup _nullMDRRuleGroup = new MDRRuleGroupImpl() {
2321 @Override
2322 public Object clone() {
2323 return this;
2324 }
2325
2326 @Override
2327 public CacheModel<MDRRuleGroup> toCacheModel() {
2328 return _nullMDRRuleGroupCacheModel;
2329 }
2330 };
2331
2332 private static CacheModel<MDRRuleGroup> _nullMDRRuleGroupCacheModel = new CacheModel<MDRRuleGroup>() {
2333 public MDRRuleGroup toEntityModel() {
2334 return _nullMDRRuleGroup;
2335 }
2336 };
2337 }