001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchPluginSettingException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.PluginSetting;
041 import com.liferay.portal.model.impl.PluginSettingImpl;
042 import com.liferay.portal.model.impl.PluginSettingModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050 import java.util.Set;
051
052
064 public class PluginSettingPersistenceImpl extends BasePersistenceImpl<PluginSetting>
065 implements PluginSettingPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = PluginSettingImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
077 PluginSettingModelImpl.FINDER_CACHE_ENABLED,
078 PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
079 "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
081 PluginSettingModelImpl.FINDER_CACHE_ENABLED,
082 PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
083 "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
085 PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
088 new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
089 PluginSettingModelImpl.FINDER_CACHE_ENABLED,
090 PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091 "findByCompanyId",
092 new String[] {
093 Long.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
099 new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
100 PluginSettingModelImpl.FINDER_CACHE_ENABLED,
101 PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
102 "findByCompanyId", new String[] { Long.class.getName() },
103 PluginSettingModelImpl.COMPANYID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
105 PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
107 new String[] { Long.class.getName() });
108
109
116 @Override
117 public List<PluginSetting> findByCompanyId(long companyId)
118 throws SystemException {
119 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
120 null);
121 }
122
123
136 @Override
137 public List<PluginSetting> findByCompanyId(long companyId, int start,
138 int end) throws SystemException {
139 return findByCompanyId(companyId, start, end, null);
140 }
141
142
156 @Override
157 public List<PluginSetting> findByCompanyId(long companyId, int start,
158 int end, OrderByComparator orderByComparator) throws SystemException {
159 boolean pagination = true;
160 FinderPath finderPath = null;
161 Object[] finderArgs = null;
162
163 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164 (orderByComparator == null)) {
165 pagination = false;
166 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
167 finderArgs = new Object[] { companyId };
168 }
169 else {
170 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
171 finderArgs = new Object[] { companyId, start, end, orderByComparator };
172 }
173
174 List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(finderPath,
175 finderArgs, this);
176
177 if ((list != null) && !list.isEmpty()) {
178 for (PluginSetting pluginSetting : list) {
179 if ((companyId != pluginSetting.getCompanyId())) {
180 list = null;
181
182 break;
183 }
184 }
185 }
186
187 if (list == null) {
188 StringBundler query = null;
189
190 if (orderByComparator != null) {
191 query = new StringBundler(3 +
192 (orderByComparator.getOrderByFields().length * 3));
193 }
194 else {
195 query = new StringBundler(3);
196 }
197
198 query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
199
200 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
201
202 if (orderByComparator != null) {
203 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
204 orderByComparator);
205 }
206 else
207 if (pagination) {
208 query.append(PluginSettingModelImpl.ORDER_BY_JPQL);
209 }
210
211 String sql = query.toString();
212
213 Session session = null;
214
215 try {
216 session = openSession();
217
218 Query q = session.createQuery(sql);
219
220 QueryPos qPos = QueryPos.getInstance(q);
221
222 qPos.add(companyId);
223
224 if (!pagination) {
225 list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
226 start, end, false);
227
228 Collections.sort(list);
229
230 list = new UnmodifiableList<PluginSetting>(list);
231 }
232 else {
233 list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
234 start, end);
235 }
236
237 cacheResult(list);
238
239 FinderCacheUtil.putResult(finderPath, finderArgs, list);
240 }
241 catch (Exception e) {
242 FinderCacheUtil.removeResult(finderPath, finderArgs);
243
244 throw processException(e);
245 }
246 finally {
247 closeSession(session);
248 }
249 }
250
251 return list;
252 }
253
254
263 @Override
264 public PluginSetting findByCompanyId_First(long companyId,
265 OrderByComparator orderByComparator)
266 throws NoSuchPluginSettingException, SystemException {
267 PluginSetting pluginSetting = fetchByCompanyId_First(companyId,
268 orderByComparator);
269
270 if (pluginSetting != null) {
271 return pluginSetting;
272 }
273
274 StringBundler msg = new StringBundler(4);
275
276 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
277
278 msg.append("companyId=");
279 msg.append(companyId);
280
281 msg.append(StringPool.CLOSE_CURLY_BRACE);
282
283 throw new NoSuchPluginSettingException(msg.toString());
284 }
285
286
294 @Override
295 public PluginSetting fetchByCompanyId_First(long companyId,
296 OrderByComparator orderByComparator) throws SystemException {
297 List<PluginSetting> list = findByCompanyId(companyId, 0, 1,
298 orderByComparator);
299
300 if (!list.isEmpty()) {
301 return list.get(0);
302 }
303
304 return null;
305 }
306
307
316 @Override
317 public PluginSetting findByCompanyId_Last(long companyId,
318 OrderByComparator orderByComparator)
319 throws NoSuchPluginSettingException, SystemException {
320 PluginSetting pluginSetting = fetchByCompanyId_Last(companyId,
321 orderByComparator);
322
323 if (pluginSetting != null) {
324 return pluginSetting;
325 }
326
327 StringBundler msg = new StringBundler(4);
328
329 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
330
331 msg.append("companyId=");
332 msg.append(companyId);
333
334 msg.append(StringPool.CLOSE_CURLY_BRACE);
335
336 throw new NoSuchPluginSettingException(msg.toString());
337 }
338
339
347 @Override
348 public PluginSetting fetchByCompanyId_Last(long companyId,
349 OrderByComparator orderByComparator) throws SystemException {
350 int count = countByCompanyId(companyId);
351
352 if (count == 0) {
353 return null;
354 }
355
356 List<PluginSetting> list = findByCompanyId(companyId, count - 1, count,
357 orderByComparator);
358
359 if (!list.isEmpty()) {
360 return list.get(0);
361 }
362
363 return null;
364 }
365
366
376 @Override
377 public PluginSetting[] findByCompanyId_PrevAndNext(long pluginSettingId,
378 long companyId, OrderByComparator orderByComparator)
379 throws NoSuchPluginSettingException, SystemException {
380 PluginSetting pluginSetting = findByPrimaryKey(pluginSettingId);
381
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 PluginSetting[] array = new PluginSettingImpl[3];
388
389 array[0] = getByCompanyId_PrevAndNext(session, pluginSetting,
390 companyId, orderByComparator, true);
391
392 array[1] = pluginSetting;
393
394 array[2] = getByCompanyId_PrevAndNext(session, pluginSetting,
395 companyId, orderByComparator, false);
396
397 return array;
398 }
399 catch (Exception e) {
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 protected PluginSetting getByCompanyId_PrevAndNext(Session session,
408 PluginSetting pluginSetting, long companyId,
409 OrderByComparator orderByComparator, boolean previous) {
410 StringBundler query = null;
411
412 if (orderByComparator != null) {
413 query = new StringBundler(6 +
414 (orderByComparator.getOrderByFields().length * 6));
415 }
416 else {
417 query = new StringBundler(3);
418 }
419
420 query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
421
422 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
423
424 if (orderByComparator != null) {
425 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
426
427 if (orderByConditionFields.length > 0) {
428 query.append(WHERE_AND);
429 }
430
431 for (int i = 0; i < orderByConditionFields.length; i++) {
432 query.append(_ORDER_BY_ENTITY_ALIAS);
433 query.append(orderByConditionFields[i]);
434
435 if ((i + 1) < orderByConditionFields.length) {
436 if (orderByComparator.isAscending() ^ previous) {
437 query.append(WHERE_GREATER_THAN_HAS_NEXT);
438 }
439 else {
440 query.append(WHERE_LESSER_THAN_HAS_NEXT);
441 }
442 }
443 else {
444 if (orderByComparator.isAscending() ^ previous) {
445 query.append(WHERE_GREATER_THAN);
446 }
447 else {
448 query.append(WHERE_LESSER_THAN);
449 }
450 }
451 }
452
453 query.append(ORDER_BY_CLAUSE);
454
455 String[] orderByFields = orderByComparator.getOrderByFields();
456
457 for (int i = 0; i < orderByFields.length; i++) {
458 query.append(_ORDER_BY_ENTITY_ALIAS);
459 query.append(orderByFields[i]);
460
461 if ((i + 1) < orderByFields.length) {
462 if (orderByComparator.isAscending() ^ previous) {
463 query.append(ORDER_BY_ASC_HAS_NEXT);
464 }
465 else {
466 query.append(ORDER_BY_DESC_HAS_NEXT);
467 }
468 }
469 else {
470 if (orderByComparator.isAscending() ^ previous) {
471 query.append(ORDER_BY_ASC);
472 }
473 else {
474 query.append(ORDER_BY_DESC);
475 }
476 }
477 }
478 }
479 else {
480 query.append(PluginSettingModelImpl.ORDER_BY_JPQL);
481 }
482
483 String sql = query.toString();
484
485 Query q = session.createQuery(sql);
486
487 q.setFirstResult(0);
488 q.setMaxResults(2);
489
490 QueryPos qPos = QueryPos.getInstance(q);
491
492 qPos.add(companyId);
493
494 if (orderByComparator != null) {
495 Object[] values = orderByComparator.getOrderByConditionValues(pluginSetting);
496
497 for (Object value : values) {
498 qPos.add(value);
499 }
500 }
501
502 List<PluginSetting> list = q.list();
503
504 if (list.size() == 2) {
505 return list.get(1);
506 }
507 else {
508 return null;
509 }
510 }
511
512
518 @Override
519 public void removeByCompanyId(long companyId) throws SystemException {
520 for (PluginSetting pluginSetting : findByCompanyId(companyId,
521 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
522 remove(pluginSetting);
523 }
524 }
525
526
533 @Override
534 public int countByCompanyId(long companyId) throws SystemException {
535 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
536
537 Object[] finderArgs = new Object[] { companyId };
538
539 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
540 this);
541
542 if (count == null) {
543 StringBundler query = new StringBundler(2);
544
545 query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
546
547 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
548
549 String sql = query.toString();
550
551 Session session = null;
552
553 try {
554 session = openSession();
555
556 Query q = session.createQuery(sql);
557
558 QueryPos qPos = QueryPos.getInstance(q);
559
560 qPos.add(companyId);
561
562 count = (Long)q.uniqueResult();
563
564 FinderCacheUtil.putResult(finderPath, finderArgs, count);
565 }
566 catch (Exception e) {
567 FinderCacheUtil.removeResult(finderPath, finderArgs);
568
569 throw processException(e);
570 }
571 finally {
572 closeSession(session);
573 }
574 }
575
576 return count.intValue();
577 }
578
579 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "pluginSetting.companyId = ?";
580 public static final FinderPath FINDER_PATH_FETCH_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
581 PluginSettingModelImpl.FINDER_CACHE_ENABLED,
582 PluginSettingImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_I_T",
583 new String[] {
584 Long.class.getName(), String.class.getName(),
585 String.class.getName()
586 },
587 PluginSettingModelImpl.COMPANYID_COLUMN_BITMASK |
588 PluginSettingModelImpl.PLUGINID_COLUMN_BITMASK |
589 PluginSettingModelImpl.PLUGINTYPE_COLUMN_BITMASK);
590 public static final FinderPath FINDER_PATH_COUNT_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
591 PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
592 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_I_T",
593 new String[] {
594 Long.class.getName(), String.class.getName(),
595 String.class.getName()
596 });
597
598
608 @Override
609 public PluginSetting findByC_I_T(long companyId, String pluginId,
610 String pluginType) throws NoSuchPluginSettingException, SystemException {
611 PluginSetting pluginSetting = fetchByC_I_T(companyId, pluginId,
612 pluginType);
613
614 if (pluginSetting == null) {
615 StringBundler msg = new StringBundler(8);
616
617 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
618
619 msg.append("companyId=");
620 msg.append(companyId);
621
622 msg.append(", pluginId=");
623 msg.append(pluginId);
624
625 msg.append(", pluginType=");
626 msg.append(pluginType);
627
628 msg.append(StringPool.CLOSE_CURLY_BRACE);
629
630 if (_log.isWarnEnabled()) {
631 _log.warn(msg.toString());
632 }
633
634 throw new NoSuchPluginSettingException(msg.toString());
635 }
636
637 return pluginSetting;
638 }
639
640
649 @Override
650 public PluginSetting fetchByC_I_T(long companyId, String pluginId,
651 String pluginType) throws SystemException {
652 return fetchByC_I_T(companyId, pluginId, pluginType, true);
653 }
654
655
665 @Override
666 public PluginSetting fetchByC_I_T(long companyId, String pluginId,
667 String pluginType, boolean retrieveFromCache) throws SystemException {
668 Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
669
670 Object result = null;
671
672 if (retrieveFromCache) {
673 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_I_T,
674 finderArgs, this);
675 }
676
677 if (result instanceof PluginSetting) {
678 PluginSetting pluginSetting = (PluginSetting)result;
679
680 if ((companyId != pluginSetting.getCompanyId()) ||
681 !Validator.equals(pluginId, pluginSetting.getPluginId()) ||
682 !Validator.equals(pluginType, pluginSetting.getPluginType())) {
683 result = null;
684 }
685 }
686
687 if (result == null) {
688 StringBundler query = new StringBundler(5);
689
690 query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
691
692 query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
693
694 boolean bindPluginId = false;
695
696 if (pluginId == null) {
697 query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
698 }
699 else if (pluginId.equals(StringPool.BLANK)) {
700 query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
701 }
702 else {
703 bindPluginId = true;
704
705 query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
706 }
707
708 boolean bindPluginType = false;
709
710 if (pluginType == null) {
711 query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
712 }
713 else if (pluginType.equals(StringPool.BLANK)) {
714 query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
715 }
716 else {
717 bindPluginType = true;
718
719 query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
720 }
721
722 String sql = query.toString();
723
724 Session session = null;
725
726 try {
727 session = openSession();
728
729 Query q = session.createQuery(sql);
730
731 QueryPos qPos = QueryPos.getInstance(q);
732
733 qPos.add(companyId);
734
735 if (bindPluginId) {
736 qPos.add(pluginId);
737 }
738
739 if (bindPluginType) {
740 qPos.add(pluginType);
741 }
742
743 List<PluginSetting> list = q.list();
744
745 if (list.isEmpty()) {
746 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
747 finderArgs, list);
748 }
749 else {
750 PluginSetting pluginSetting = list.get(0);
751
752 result = pluginSetting;
753
754 cacheResult(pluginSetting);
755
756 if ((pluginSetting.getCompanyId() != companyId) ||
757 (pluginSetting.getPluginId() == null) ||
758 !pluginSetting.getPluginId().equals(pluginId) ||
759 (pluginSetting.getPluginType() == null) ||
760 !pluginSetting.getPluginType().equals(pluginType)) {
761 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
762 finderArgs, pluginSetting);
763 }
764 }
765 }
766 catch (Exception e) {
767 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
768 finderArgs);
769
770 throw processException(e);
771 }
772 finally {
773 closeSession(session);
774 }
775 }
776
777 if (result instanceof List<?>) {
778 return null;
779 }
780 else {
781 return (PluginSetting)result;
782 }
783 }
784
785
794 @Override
795 public PluginSetting removeByC_I_T(long companyId, String pluginId,
796 String pluginType) throws NoSuchPluginSettingException, SystemException {
797 PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
798 pluginType);
799
800 return remove(pluginSetting);
801 }
802
803
812 @Override
813 public int countByC_I_T(long companyId, String pluginId, String pluginType)
814 throws SystemException {
815 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_I_T;
816
817 Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
818
819 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
820 this);
821
822 if (count == null) {
823 StringBundler query = new StringBundler(4);
824
825 query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
826
827 query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
828
829 boolean bindPluginId = false;
830
831 if (pluginId == null) {
832 query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
833 }
834 else if (pluginId.equals(StringPool.BLANK)) {
835 query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
836 }
837 else {
838 bindPluginId = true;
839
840 query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
841 }
842
843 boolean bindPluginType = false;
844
845 if (pluginType == null) {
846 query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
847 }
848 else if (pluginType.equals(StringPool.BLANK)) {
849 query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
850 }
851 else {
852 bindPluginType = true;
853
854 query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
855 }
856
857 String sql = query.toString();
858
859 Session session = null;
860
861 try {
862 session = openSession();
863
864 Query q = session.createQuery(sql);
865
866 QueryPos qPos = QueryPos.getInstance(q);
867
868 qPos.add(companyId);
869
870 if (bindPluginId) {
871 qPos.add(pluginId);
872 }
873
874 if (bindPluginType) {
875 qPos.add(pluginType);
876 }
877
878 count = (Long)q.uniqueResult();
879
880 FinderCacheUtil.putResult(finderPath, finderArgs, count);
881 }
882 catch (Exception e) {
883 FinderCacheUtil.removeResult(finderPath, finderArgs);
884
885 throw processException(e);
886 }
887 finally {
888 closeSession(session);
889 }
890 }
891
892 return count.intValue();
893 }
894
895 private static final String _FINDER_COLUMN_C_I_T_COMPANYID_2 = "pluginSetting.companyId = ? AND ";
896 private static final String _FINDER_COLUMN_C_I_T_PLUGINID_1 = "pluginSetting.pluginId IS NULL AND ";
897 private static final String _FINDER_COLUMN_C_I_T_PLUGINID_2 = "pluginSetting.pluginId = ? AND ";
898 private static final String _FINDER_COLUMN_C_I_T_PLUGINID_3 = "(pluginSetting.pluginId IS NULL OR pluginSetting.pluginId = '') AND ";
899 private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_1 = "pluginSetting.pluginType IS NULL";
900 private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_2 = "pluginSetting.pluginType = ?";
901 private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_3 = "(pluginSetting.pluginType IS NULL OR pluginSetting.pluginType = '')";
902
903 public PluginSettingPersistenceImpl() {
904 setModelClass(PluginSetting.class);
905 }
906
907
912 @Override
913 public void cacheResult(PluginSetting pluginSetting) {
914 EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
915 PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
916 pluginSetting);
917
918 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
919 new Object[] {
920 pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
921 pluginSetting.getPluginType()
922 }, pluginSetting);
923
924 pluginSetting.resetOriginalValues();
925 }
926
927
932 @Override
933 public void cacheResult(List<PluginSetting> pluginSettings) {
934 for (PluginSetting pluginSetting : pluginSettings) {
935 if (EntityCacheUtil.getResult(
936 PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
937 PluginSettingImpl.class, pluginSetting.getPrimaryKey()) == null) {
938 cacheResult(pluginSetting);
939 }
940 else {
941 pluginSetting.resetOriginalValues();
942 }
943 }
944 }
945
946
953 @Override
954 public void clearCache() {
955 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
956 CacheRegistryUtil.clear(PluginSettingImpl.class.getName());
957 }
958
959 EntityCacheUtil.clearCache(PluginSettingImpl.class.getName());
960
961 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
962 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
963 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
964 }
965
966
973 @Override
974 public void clearCache(PluginSetting pluginSetting) {
975 EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
976 PluginSettingImpl.class, pluginSetting.getPrimaryKey());
977
978 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
979 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
980
981 clearUniqueFindersCache(pluginSetting);
982 }
983
984 @Override
985 public void clearCache(List<PluginSetting> pluginSettings) {
986 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
987 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
988
989 for (PluginSetting pluginSetting : pluginSettings) {
990 EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
991 PluginSettingImpl.class, pluginSetting.getPrimaryKey());
992
993 clearUniqueFindersCache(pluginSetting);
994 }
995 }
996
997 protected void cacheUniqueFindersCache(PluginSetting pluginSetting) {
998 if (pluginSetting.isNew()) {
999 Object[] args = new Object[] {
1000 pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
1001 pluginSetting.getPluginType()
1002 };
1003
1004 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T, args,
1005 Long.valueOf(1));
1006 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T, args,
1007 pluginSetting);
1008 }
1009 else {
1010 PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1011
1012 if ((pluginSettingModelImpl.getColumnBitmask() &
1013 FINDER_PATH_FETCH_BY_C_I_T.getColumnBitmask()) != 0) {
1014 Object[] args = new Object[] {
1015 pluginSetting.getCompanyId(),
1016 pluginSetting.getPluginId(),
1017 pluginSetting.getPluginType()
1018 };
1019
1020 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T, args,
1021 Long.valueOf(1));
1022 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T, args,
1023 pluginSetting);
1024 }
1025 }
1026 }
1027
1028 protected void clearUniqueFindersCache(PluginSetting pluginSetting) {
1029 PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1030
1031 Object[] args = new Object[] {
1032 pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
1033 pluginSetting.getPluginType()
1034 };
1035
1036 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_I_T, args);
1037 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T, args);
1038
1039 if ((pluginSettingModelImpl.getColumnBitmask() &
1040 FINDER_PATH_FETCH_BY_C_I_T.getColumnBitmask()) != 0) {
1041 args = new Object[] {
1042 pluginSettingModelImpl.getOriginalCompanyId(),
1043 pluginSettingModelImpl.getOriginalPluginId(),
1044 pluginSettingModelImpl.getOriginalPluginType()
1045 };
1046
1047 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_I_T, args);
1048 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T, args);
1049 }
1050 }
1051
1052
1058 @Override
1059 public PluginSetting create(long pluginSettingId) {
1060 PluginSetting pluginSetting = new PluginSettingImpl();
1061
1062 pluginSetting.setNew(true);
1063 pluginSetting.setPrimaryKey(pluginSettingId);
1064
1065 return pluginSetting;
1066 }
1067
1068
1076 @Override
1077 public PluginSetting remove(long pluginSettingId)
1078 throws NoSuchPluginSettingException, SystemException {
1079 return remove((Serializable)pluginSettingId);
1080 }
1081
1082
1090 @Override
1091 public PluginSetting remove(Serializable primaryKey)
1092 throws NoSuchPluginSettingException, SystemException {
1093 Session session = null;
1094
1095 try {
1096 session = openSession();
1097
1098 PluginSetting pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1099 primaryKey);
1100
1101 if (pluginSetting == null) {
1102 if (_log.isWarnEnabled()) {
1103 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1104 }
1105
1106 throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1107 primaryKey);
1108 }
1109
1110 return remove(pluginSetting);
1111 }
1112 catch (NoSuchPluginSettingException nsee) {
1113 throw nsee;
1114 }
1115 catch (Exception e) {
1116 throw processException(e);
1117 }
1118 finally {
1119 closeSession(session);
1120 }
1121 }
1122
1123 @Override
1124 protected PluginSetting removeImpl(PluginSetting pluginSetting)
1125 throws SystemException {
1126 pluginSetting = toUnwrappedModel(pluginSetting);
1127
1128 Session session = null;
1129
1130 try {
1131 session = openSession();
1132
1133 if (!session.contains(pluginSetting)) {
1134 pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1135 pluginSetting.getPrimaryKeyObj());
1136 }
1137
1138 if (pluginSetting != null) {
1139 session.delete(pluginSetting);
1140 }
1141 }
1142 catch (Exception e) {
1143 throw processException(e);
1144 }
1145 finally {
1146 closeSession(session);
1147 }
1148
1149 if (pluginSetting != null) {
1150 clearCache(pluginSetting);
1151 }
1152
1153 return pluginSetting;
1154 }
1155
1156 @Override
1157 public PluginSetting updateImpl(
1158 com.liferay.portal.model.PluginSetting pluginSetting)
1159 throws SystemException {
1160 pluginSetting = toUnwrappedModel(pluginSetting);
1161
1162 boolean isNew = pluginSetting.isNew();
1163
1164 PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1165
1166 Session session = null;
1167
1168 try {
1169 session = openSession();
1170
1171 if (pluginSetting.isNew()) {
1172 session.save(pluginSetting);
1173
1174 pluginSetting.setNew(false);
1175 }
1176 else {
1177 session.merge(pluginSetting);
1178 }
1179 }
1180 catch (Exception e) {
1181 throw processException(e);
1182 }
1183 finally {
1184 closeSession(session);
1185 }
1186
1187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1188
1189 if (isNew || !PluginSettingModelImpl.COLUMN_BITMASK_ENABLED) {
1190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1191 }
1192
1193 else {
1194 if ((pluginSettingModelImpl.getColumnBitmask() &
1195 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1196 Object[] args = new Object[] {
1197 pluginSettingModelImpl.getOriginalCompanyId()
1198 };
1199
1200 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1201 args);
1202 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1203 args);
1204
1205 args = new Object[] { pluginSettingModelImpl.getCompanyId() };
1206
1207 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1208 args);
1209 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1210 args);
1211 }
1212 }
1213
1214 EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1215 PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
1216 pluginSetting);
1217
1218 clearUniqueFindersCache(pluginSetting);
1219 cacheUniqueFindersCache(pluginSetting);
1220
1221 return pluginSetting;
1222 }
1223
1224 protected PluginSetting toUnwrappedModel(PluginSetting pluginSetting) {
1225 if (pluginSetting instanceof PluginSettingImpl) {
1226 return pluginSetting;
1227 }
1228
1229 PluginSettingImpl pluginSettingImpl = new PluginSettingImpl();
1230
1231 pluginSettingImpl.setNew(pluginSetting.isNew());
1232 pluginSettingImpl.setPrimaryKey(pluginSetting.getPrimaryKey());
1233
1234 pluginSettingImpl.setPluginSettingId(pluginSetting.getPluginSettingId());
1235 pluginSettingImpl.setCompanyId(pluginSetting.getCompanyId());
1236 pluginSettingImpl.setPluginId(pluginSetting.getPluginId());
1237 pluginSettingImpl.setPluginType(pluginSetting.getPluginType());
1238 pluginSettingImpl.setRoles(pluginSetting.getRoles());
1239 pluginSettingImpl.setActive(pluginSetting.isActive());
1240
1241 return pluginSettingImpl;
1242 }
1243
1244
1252 @Override
1253 public PluginSetting findByPrimaryKey(Serializable primaryKey)
1254 throws NoSuchPluginSettingException, SystemException {
1255 PluginSetting pluginSetting = fetchByPrimaryKey(primaryKey);
1256
1257 if (pluginSetting == null) {
1258 if (_log.isWarnEnabled()) {
1259 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1260 }
1261
1262 throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1263 primaryKey);
1264 }
1265
1266 return pluginSetting;
1267 }
1268
1269
1277 @Override
1278 public PluginSetting findByPrimaryKey(long pluginSettingId)
1279 throws NoSuchPluginSettingException, SystemException {
1280 return findByPrimaryKey((Serializable)pluginSettingId);
1281 }
1282
1283
1290 @Override
1291 public PluginSetting fetchByPrimaryKey(Serializable primaryKey)
1292 throws SystemException {
1293 PluginSetting pluginSetting = (PluginSetting)EntityCacheUtil.getResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1294 PluginSettingImpl.class, primaryKey);
1295
1296 if (pluginSetting == _nullPluginSetting) {
1297 return null;
1298 }
1299
1300 if (pluginSetting == null) {
1301 Session session = null;
1302
1303 try {
1304 session = openSession();
1305
1306 pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1307 primaryKey);
1308
1309 if (pluginSetting != null) {
1310 cacheResult(pluginSetting);
1311 }
1312 else {
1313 EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1314 PluginSettingImpl.class, primaryKey, _nullPluginSetting);
1315 }
1316 }
1317 catch (Exception e) {
1318 EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1319 PluginSettingImpl.class, primaryKey);
1320
1321 throw processException(e);
1322 }
1323 finally {
1324 closeSession(session);
1325 }
1326 }
1327
1328 return pluginSetting;
1329 }
1330
1331
1338 @Override
1339 public PluginSetting fetchByPrimaryKey(long pluginSettingId)
1340 throws SystemException {
1341 return fetchByPrimaryKey((Serializable)pluginSettingId);
1342 }
1343
1344
1350 @Override
1351 public List<PluginSetting> findAll() throws SystemException {
1352 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1353 }
1354
1355
1367 @Override
1368 public List<PluginSetting> findAll(int start, int end)
1369 throws SystemException {
1370 return findAll(start, end, null);
1371 }
1372
1373
1386 @Override
1387 public List<PluginSetting> findAll(int start, int end,
1388 OrderByComparator orderByComparator) throws SystemException {
1389 boolean pagination = true;
1390 FinderPath finderPath = null;
1391 Object[] finderArgs = null;
1392
1393 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1394 (orderByComparator == null)) {
1395 pagination = false;
1396 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1397 finderArgs = FINDER_ARGS_EMPTY;
1398 }
1399 else {
1400 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1401 finderArgs = new Object[] { start, end, orderByComparator };
1402 }
1403
1404 List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(finderPath,
1405 finderArgs, this);
1406
1407 if (list == null) {
1408 StringBundler query = null;
1409 String sql = null;
1410
1411 if (orderByComparator != null) {
1412 query = new StringBundler(2 +
1413 (orderByComparator.getOrderByFields().length * 3));
1414
1415 query.append(_SQL_SELECT_PLUGINSETTING);
1416
1417 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1418 orderByComparator);
1419
1420 sql = query.toString();
1421 }
1422 else {
1423 sql = _SQL_SELECT_PLUGINSETTING;
1424
1425 if (pagination) {
1426 sql = sql.concat(PluginSettingModelImpl.ORDER_BY_JPQL);
1427 }
1428 }
1429
1430 Session session = null;
1431
1432 try {
1433 session = openSession();
1434
1435 Query q = session.createQuery(sql);
1436
1437 if (!pagination) {
1438 list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1439 start, end, false);
1440
1441 Collections.sort(list);
1442
1443 list = new UnmodifiableList<PluginSetting>(list);
1444 }
1445 else {
1446 list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1447 start, end);
1448 }
1449
1450 cacheResult(list);
1451
1452 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1453 }
1454 catch (Exception e) {
1455 FinderCacheUtil.removeResult(finderPath, finderArgs);
1456
1457 throw processException(e);
1458 }
1459 finally {
1460 closeSession(session);
1461 }
1462 }
1463
1464 return list;
1465 }
1466
1467
1472 @Override
1473 public void removeAll() throws SystemException {
1474 for (PluginSetting pluginSetting : findAll()) {
1475 remove(pluginSetting);
1476 }
1477 }
1478
1479
1485 @Override
1486 public int countAll() throws SystemException {
1487 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1488 FINDER_ARGS_EMPTY, this);
1489
1490 if (count == null) {
1491 Session session = null;
1492
1493 try {
1494 session = openSession();
1495
1496 Query q = session.createQuery(_SQL_COUNT_PLUGINSETTING);
1497
1498 count = (Long)q.uniqueResult();
1499
1500 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1501 FINDER_ARGS_EMPTY, count);
1502 }
1503 catch (Exception e) {
1504 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1505 FINDER_ARGS_EMPTY);
1506
1507 throw processException(e);
1508 }
1509 finally {
1510 closeSession(session);
1511 }
1512 }
1513
1514 return count.intValue();
1515 }
1516
1517 @Override
1518 protected Set<String> getBadColumnNames() {
1519 return _badColumnNames;
1520 }
1521
1522
1525 public void afterPropertiesSet() {
1526 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1527 com.liferay.portal.util.PropsUtil.get(
1528 "value.object.listener.com.liferay.portal.model.PluginSetting")));
1529
1530 if (listenerClassNames.length > 0) {
1531 try {
1532 List<ModelListener<PluginSetting>> listenersList = new ArrayList<ModelListener<PluginSetting>>();
1533
1534 for (String listenerClassName : listenerClassNames) {
1535 listenersList.add((ModelListener<PluginSetting>)InstanceFactory.newInstance(
1536 getClassLoader(), listenerClassName));
1537 }
1538
1539 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1540 }
1541 catch (Exception e) {
1542 _log.error(e);
1543 }
1544 }
1545 }
1546
1547 public void destroy() {
1548 EntityCacheUtil.removeCache(PluginSettingImpl.class.getName());
1549 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1550 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1551 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1552 }
1553
1554 private static final String _SQL_SELECT_PLUGINSETTING = "SELECT pluginSetting FROM PluginSetting pluginSetting";
1555 private static final String _SQL_SELECT_PLUGINSETTING_WHERE = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE ";
1556 private static final String _SQL_COUNT_PLUGINSETTING = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting";
1557 private static final String _SQL_COUNT_PLUGINSETTING_WHERE = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting WHERE ";
1558 private static final String _ORDER_BY_ENTITY_ALIAS = "pluginSetting.";
1559 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PluginSetting exists with the primary key ";
1560 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PluginSetting exists with the key {";
1561 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1562 private static Log _log = LogFactoryUtil.getLog(PluginSettingPersistenceImpl.class);
1563 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1564 "active"
1565 });
1566 private static PluginSetting _nullPluginSetting = new PluginSettingImpl() {
1567 @Override
1568 public Object clone() {
1569 return this;
1570 }
1571
1572 @Override
1573 public CacheModel<PluginSetting> toCacheModel() {
1574 return _nullPluginSettingCacheModel;
1575 }
1576 };
1577
1578 private static CacheModel<PluginSetting> _nullPluginSettingCacheModel = new CacheModel<PluginSetting>() {
1579 @Override
1580 public PluginSetting toEntityModel() {
1581 return _nullPluginSetting;
1582 }
1583 };
1584 }