001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchPasswordPolicyException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
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.model.ModelListener;
039 import com.liferay.portal.model.PasswordPolicy;
040 import com.liferay.portal.model.impl.PasswordPolicyImpl;
041 import com.liferay.portal.model.impl.PasswordPolicyModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
066 public class PasswordPolicyPersistenceImpl extends BasePersistenceImpl<PasswordPolicy>
067 implements PasswordPolicyPersistence {
068 public static final String FINDER_CLASS_NAME_ENTITY = PasswordPolicyImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070 ".List";
071 public static final FinderPath FINDER_PATH_FETCH_BY_C_DP = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
072 PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
073 FINDER_CLASS_NAME_ENTITY, "fetchByC_DP",
074 new String[] { Long.class.getName(), Boolean.class.getName() });
075 public static final FinderPath FINDER_PATH_COUNT_BY_C_DP = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
076 PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
077 FINDER_CLASS_NAME_LIST, "countByC_DP",
078 new String[] { Long.class.getName(), Boolean.class.getName() });
079 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
080 PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
081 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
082 new String[] { Long.class.getName(), String.class.getName() });
083 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
084 PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
085 FINDER_CLASS_NAME_LIST, "countByC_N",
086 new String[] { Long.class.getName(), String.class.getName() });
087 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
088 PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
089 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
090 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
091 PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
092 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
093
094
099 public void cacheResult(PasswordPolicy passwordPolicy) {
100 EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
101 PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey(),
102 passwordPolicy);
103
104 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
105 new Object[] {
106 new Long(passwordPolicy.getCompanyId()),
107 Boolean.valueOf(passwordPolicy.getDefaultPolicy())
108 }, passwordPolicy);
109
110 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
111 new Object[] {
112 new Long(passwordPolicy.getCompanyId()),
113
114 passwordPolicy.getName()
115 }, passwordPolicy);
116 }
117
118
123 public void cacheResult(List<PasswordPolicy> passwordPolicies) {
124 for (PasswordPolicy passwordPolicy : passwordPolicies) {
125 if (EntityCacheUtil.getResult(
126 PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
127 PasswordPolicyImpl.class,
128 passwordPolicy.getPrimaryKey(), this) == null) {
129 cacheResult(passwordPolicy);
130 }
131 }
132 }
133
134
141 public void clearCache() {
142 CacheRegistryUtil.clear(PasswordPolicyImpl.class.getName());
143 EntityCacheUtil.clearCache(PasswordPolicyImpl.class.getName());
144 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
145 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
146 }
147
148
155 public void clearCache(PasswordPolicy passwordPolicy) {
156 EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
157 PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey());
158
159 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP,
160 new Object[] {
161 new Long(passwordPolicy.getCompanyId()),
162 Boolean.valueOf(passwordPolicy.getDefaultPolicy())
163 });
164
165 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
166 new Object[] {
167 new Long(passwordPolicy.getCompanyId()),
168
169 passwordPolicy.getName()
170 });
171 }
172
173
179 public PasswordPolicy create(long passwordPolicyId) {
180 PasswordPolicy passwordPolicy = new PasswordPolicyImpl();
181
182 passwordPolicy.setNew(true);
183 passwordPolicy.setPrimaryKey(passwordPolicyId);
184
185 return passwordPolicy;
186 }
187
188
196 public PasswordPolicy remove(Serializable primaryKey)
197 throws NoSuchModelException, SystemException {
198 return remove(((Long)primaryKey).longValue());
199 }
200
201
209 public PasswordPolicy remove(long passwordPolicyId)
210 throws NoSuchPasswordPolicyException, SystemException {
211 Session session = null;
212
213 try {
214 session = openSession();
215
216 PasswordPolicy passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
217 new Long(passwordPolicyId));
218
219 if (passwordPolicy == null) {
220 if (_log.isWarnEnabled()) {
221 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
222 passwordPolicyId);
223 }
224
225 throw new NoSuchPasswordPolicyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
226 passwordPolicyId);
227 }
228
229 return remove(passwordPolicy);
230 }
231 catch (NoSuchPasswordPolicyException nsee) {
232 throw nsee;
233 }
234 catch (Exception e) {
235 throw processException(e);
236 }
237 finally {
238 closeSession(session);
239 }
240 }
241
242 protected PasswordPolicy removeImpl(PasswordPolicy passwordPolicy)
243 throws SystemException {
244 passwordPolicy = toUnwrappedModel(passwordPolicy);
245
246 Session session = null;
247
248 try {
249 session = openSession();
250
251 BatchSessionUtil.delete(session, passwordPolicy);
252 }
253 catch (Exception e) {
254 throw processException(e);
255 }
256 finally {
257 closeSession(session);
258 }
259
260 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
261
262 PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
263
264 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP,
265 new Object[] {
266 new Long(passwordPolicyModelImpl.getCompanyId()),
267 Boolean.valueOf(passwordPolicyModelImpl.getDefaultPolicy())
268 });
269
270 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
271 new Object[] {
272 new Long(passwordPolicyModelImpl.getCompanyId()),
273
274 passwordPolicyModelImpl.getName()
275 });
276
277 EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
278 PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey());
279
280 return passwordPolicy;
281 }
282
283 public PasswordPolicy updateImpl(
284 com.liferay.portal.model.PasswordPolicy passwordPolicy, boolean merge)
285 throws SystemException {
286 passwordPolicy = toUnwrappedModel(passwordPolicy);
287
288 boolean isNew = passwordPolicy.isNew();
289
290 PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
291
292 Session session = null;
293
294 try {
295 session = openSession();
296
297 BatchSessionUtil.update(session, passwordPolicy, merge);
298
299 passwordPolicy.setNew(false);
300 }
301 catch (Exception e) {
302 throw processException(e);
303 }
304 finally {
305 closeSession(session);
306 }
307
308 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
309
310 EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
311 PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey(),
312 passwordPolicy);
313
314 if (!isNew &&
315 ((passwordPolicy.getCompanyId() != passwordPolicyModelImpl.getOriginalCompanyId()) ||
316 (passwordPolicy.getDefaultPolicy() != passwordPolicyModelImpl.getOriginalDefaultPolicy()))) {
317 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP,
318 new Object[] {
319 new Long(passwordPolicyModelImpl.getOriginalCompanyId()),
320 Boolean.valueOf(
321 passwordPolicyModelImpl.getOriginalDefaultPolicy())
322 });
323 }
324
325 if (isNew ||
326 ((passwordPolicy.getCompanyId() != passwordPolicyModelImpl.getOriginalCompanyId()) ||
327 (passwordPolicy.getDefaultPolicy() != passwordPolicyModelImpl.getOriginalDefaultPolicy()))) {
328 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
329 new Object[] {
330 new Long(passwordPolicy.getCompanyId()),
331 Boolean.valueOf(passwordPolicy.getDefaultPolicy())
332 }, passwordPolicy);
333 }
334
335 if (!isNew &&
336 ((passwordPolicy.getCompanyId() != passwordPolicyModelImpl.getOriginalCompanyId()) ||
337 !Validator.equals(passwordPolicy.getName(),
338 passwordPolicyModelImpl.getOriginalName()))) {
339 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
340 new Object[] {
341 new Long(passwordPolicyModelImpl.getOriginalCompanyId()),
342
343 passwordPolicyModelImpl.getOriginalName()
344 });
345 }
346
347 if (isNew ||
348 ((passwordPolicy.getCompanyId() != passwordPolicyModelImpl.getOriginalCompanyId()) ||
349 !Validator.equals(passwordPolicy.getName(),
350 passwordPolicyModelImpl.getOriginalName()))) {
351 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
352 new Object[] {
353 new Long(passwordPolicy.getCompanyId()),
354
355 passwordPolicy.getName()
356 }, passwordPolicy);
357 }
358
359 return passwordPolicy;
360 }
361
362 protected PasswordPolicy toUnwrappedModel(PasswordPolicy passwordPolicy) {
363 if (passwordPolicy instanceof PasswordPolicyImpl) {
364 return passwordPolicy;
365 }
366
367 PasswordPolicyImpl passwordPolicyImpl = new PasswordPolicyImpl();
368
369 passwordPolicyImpl.setNew(passwordPolicy.isNew());
370 passwordPolicyImpl.setPrimaryKey(passwordPolicy.getPrimaryKey());
371
372 passwordPolicyImpl.setPasswordPolicyId(passwordPolicy.getPasswordPolicyId());
373 passwordPolicyImpl.setCompanyId(passwordPolicy.getCompanyId());
374 passwordPolicyImpl.setUserId(passwordPolicy.getUserId());
375 passwordPolicyImpl.setUserName(passwordPolicy.getUserName());
376 passwordPolicyImpl.setCreateDate(passwordPolicy.getCreateDate());
377 passwordPolicyImpl.setModifiedDate(passwordPolicy.getModifiedDate());
378 passwordPolicyImpl.setDefaultPolicy(passwordPolicy.isDefaultPolicy());
379 passwordPolicyImpl.setName(passwordPolicy.getName());
380 passwordPolicyImpl.setDescription(passwordPolicy.getDescription());
381 passwordPolicyImpl.setChangeable(passwordPolicy.isChangeable());
382 passwordPolicyImpl.setChangeRequired(passwordPolicy.isChangeRequired());
383 passwordPolicyImpl.setMinAge(passwordPolicy.getMinAge());
384 passwordPolicyImpl.setCheckSyntax(passwordPolicy.isCheckSyntax());
385 passwordPolicyImpl.setAllowDictionaryWords(passwordPolicy.isAllowDictionaryWords());
386 passwordPolicyImpl.setMinAlphanumeric(passwordPolicy.getMinAlphanumeric());
387 passwordPolicyImpl.setMinLength(passwordPolicy.getMinLength());
388 passwordPolicyImpl.setMinLowerCase(passwordPolicy.getMinLowerCase());
389 passwordPolicyImpl.setMinNumbers(passwordPolicy.getMinNumbers());
390 passwordPolicyImpl.setMinSymbols(passwordPolicy.getMinSymbols());
391 passwordPolicyImpl.setMinUpperCase(passwordPolicy.getMinUpperCase());
392 passwordPolicyImpl.setHistory(passwordPolicy.isHistory());
393 passwordPolicyImpl.setHistoryCount(passwordPolicy.getHistoryCount());
394 passwordPolicyImpl.setExpireable(passwordPolicy.isExpireable());
395 passwordPolicyImpl.setMaxAge(passwordPolicy.getMaxAge());
396 passwordPolicyImpl.setWarningTime(passwordPolicy.getWarningTime());
397 passwordPolicyImpl.setGraceLimit(passwordPolicy.getGraceLimit());
398 passwordPolicyImpl.setLockout(passwordPolicy.isLockout());
399 passwordPolicyImpl.setMaxFailure(passwordPolicy.getMaxFailure());
400 passwordPolicyImpl.setLockoutDuration(passwordPolicy.getLockoutDuration());
401 passwordPolicyImpl.setRequireUnlock(passwordPolicy.isRequireUnlock());
402 passwordPolicyImpl.setResetFailureCount(passwordPolicy.getResetFailureCount());
403 passwordPolicyImpl.setResetTicketMaxAge(passwordPolicy.getResetTicketMaxAge());
404
405 return passwordPolicyImpl;
406 }
407
408
416 public PasswordPolicy findByPrimaryKey(Serializable primaryKey)
417 throws NoSuchModelException, SystemException {
418 return findByPrimaryKey(((Long)primaryKey).longValue());
419 }
420
421
429 public PasswordPolicy findByPrimaryKey(long passwordPolicyId)
430 throws NoSuchPasswordPolicyException, SystemException {
431 PasswordPolicy passwordPolicy = fetchByPrimaryKey(passwordPolicyId);
432
433 if (passwordPolicy == null) {
434 if (_log.isWarnEnabled()) {
435 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + passwordPolicyId);
436 }
437
438 throw new NoSuchPasswordPolicyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
439 passwordPolicyId);
440 }
441
442 return passwordPolicy;
443 }
444
445
452 public PasswordPolicy fetchByPrimaryKey(Serializable primaryKey)
453 throws SystemException {
454 return fetchByPrimaryKey(((Long)primaryKey).longValue());
455 }
456
457
464 public PasswordPolicy fetchByPrimaryKey(long passwordPolicyId)
465 throws SystemException {
466 PasswordPolicy passwordPolicy = (PasswordPolicy)EntityCacheUtil.getResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
467 PasswordPolicyImpl.class, passwordPolicyId, this);
468
469 if (passwordPolicy == null) {
470 Session session = null;
471
472 try {
473 session = openSession();
474
475 passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
476 new Long(passwordPolicyId));
477 }
478 catch (Exception e) {
479 throw processException(e);
480 }
481 finally {
482 if (passwordPolicy != null) {
483 cacheResult(passwordPolicy);
484 }
485
486 closeSession(session);
487 }
488 }
489
490 return passwordPolicy;
491 }
492
493
502 public PasswordPolicy findByC_DP(long companyId, boolean defaultPolicy)
503 throws NoSuchPasswordPolicyException, SystemException {
504 PasswordPolicy passwordPolicy = fetchByC_DP(companyId, defaultPolicy);
505
506 if (passwordPolicy == null) {
507 StringBundler msg = new StringBundler(6);
508
509 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
510
511 msg.append("companyId=");
512 msg.append(companyId);
513
514 msg.append(", defaultPolicy=");
515 msg.append(defaultPolicy);
516
517 msg.append(StringPool.CLOSE_CURLY_BRACE);
518
519 if (_log.isWarnEnabled()) {
520 _log.warn(msg.toString());
521 }
522
523 throw new NoSuchPasswordPolicyException(msg.toString());
524 }
525
526 return passwordPolicy;
527 }
528
529
537 public PasswordPolicy fetchByC_DP(long companyId, boolean defaultPolicy)
538 throws SystemException {
539 return fetchByC_DP(companyId, defaultPolicy, true);
540 }
541
542
550 public PasswordPolicy fetchByC_DP(long companyId, boolean defaultPolicy,
551 boolean retrieveFromCache) throws SystemException {
552 Object[] finderArgs = new Object[] { companyId, defaultPolicy };
553
554 Object result = null;
555
556 if (retrieveFromCache) {
557 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_DP,
558 finderArgs, this);
559 }
560
561 if (result == null) {
562 StringBundler query = new StringBundler(3);
563
564 query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
565
566 query.append(_FINDER_COLUMN_C_DP_COMPANYID_2);
567
568 query.append(_FINDER_COLUMN_C_DP_DEFAULTPOLICY_2);
569
570 String sql = query.toString();
571
572 Session session = null;
573
574 try {
575 session = openSession();
576
577 Query q = session.createQuery(sql);
578
579 QueryPos qPos = QueryPos.getInstance(q);
580
581 qPos.add(companyId);
582
583 qPos.add(defaultPolicy);
584
585 List<PasswordPolicy> list = q.list();
586
587 result = list;
588
589 PasswordPolicy passwordPolicy = null;
590
591 if (list.isEmpty()) {
592 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
593 finderArgs, list);
594 }
595 else {
596 passwordPolicy = list.get(0);
597
598 cacheResult(passwordPolicy);
599
600 if ((passwordPolicy.getCompanyId() != companyId) ||
601 (passwordPolicy.getDefaultPolicy() != defaultPolicy)) {
602 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
603 finderArgs, passwordPolicy);
604 }
605 }
606
607 return passwordPolicy;
608 }
609 catch (Exception e) {
610 throw processException(e);
611 }
612 finally {
613 if (result == null) {
614 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP,
615 finderArgs);
616 }
617
618 closeSession(session);
619 }
620 }
621 else {
622 if (result instanceof List<?>) {
623 return null;
624 }
625 else {
626 return (PasswordPolicy)result;
627 }
628 }
629 }
630
631
640 public PasswordPolicy findByC_N(long companyId, String name)
641 throws NoSuchPasswordPolicyException, SystemException {
642 PasswordPolicy passwordPolicy = fetchByC_N(companyId, name);
643
644 if (passwordPolicy == null) {
645 StringBundler msg = new StringBundler(6);
646
647 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
648
649 msg.append("companyId=");
650 msg.append(companyId);
651
652 msg.append(", name=");
653 msg.append(name);
654
655 msg.append(StringPool.CLOSE_CURLY_BRACE);
656
657 if (_log.isWarnEnabled()) {
658 _log.warn(msg.toString());
659 }
660
661 throw new NoSuchPasswordPolicyException(msg.toString());
662 }
663
664 return passwordPolicy;
665 }
666
667
675 public PasswordPolicy fetchByC_N(long companyId, String name)
676 throws SystemException {
677 return fetchByC_N(companyId, name, true);
678 }
679
680
688 public PasswordPolicy fetchByC_N(long companyId, String name,
689 boolean retrieveFromCache) throws SystemException {
690 Object[] finderArgs = new Object[] { companyId, name };
691
692 Object result = null;
693
694 if (retrieveFromCache) {
695 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
696 finderArgs, this);
697 }
698
699 if (result == null) {
700 StringBundler query = new StringBundler(3);
701
702 query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
703
704 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
705
706 if (name == null) {
707 query.append(_FINDER_COLUMN_C_N_NAME_1);
708 }
709 else {
710 if (name.equals(StringPool.BLANK)) {
711 query.append(_FINDER_COLUMN_C_N_NAME_3);
712 }
713 else {
714 query.append(_FINDER_COLUMN_C_N_NAME_2);
715 }
716 }
717
718 String sql = query.toString();
719
720 Session session = null;
721
722 try {
723 session = openSession();
724
725 Query q = session.createQuery(sql);
726
727 QueryPos qPos = QueryPos.getInstance(q);
728
729 qPos.add(companyId);
730
731 if (name != null) {
732 qPos.add(name);
733 }
734
735 List<PasswordPolicy> list = q.list();
736
737 result = list;
738
739 PasswordPolicy passwordPolicy = null;
740
741 if (list.isEmpty()) {
742 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
743 finderArgs, list);
744 }
745 else {
746 passwordPolicy = list.get(0);
747
748 cacheResult(passwordPolicy);
749
750 if ((passwordPolicy.getCompanyId() != companyId) ||
751 (passwordPolicy.getName() == null) ||
752 !passwordPolicy.getName().equals(name)) {
753 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
754 finderArgs, passwordPolicy);
755 }
756 }
757
758 return passwordPolicy;
759 }
760 catch (Exception e) {
761 throw processException(e);
762 }
763 finally {
764 if (result == null) {
765 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
766 finderArgs);
767 }
768
769 closeSession(session);
770 }
771 }
772 else {
773 if (result instanceof List<?>) {
774 return null;
775 }
776 else {
777 return (PasswordPolicy)result;
778 }
779 }
780 }
781
782
788 public List<PasswordPolicy> findAll() throws SystemException {
789 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
790 }
791
792
804 public List<PasswordPolicy> findAll(int start, int end)
805 throws SystemException {
806 return findAll(start, end, null);
807 }
808
809
822 public List<PasswordPolicy> findAll(int start, int end,
823 OrderByComparator orderByComparator) throws SystemException {
824 Object[] finderArgs = new Object[] {
825 String.valueOf(start), String.valueOf(end),
826 String.valueOf(orderByComparator)
827 };
828
829 List<PasswordPolicy> list = (List<PasswordPolicy>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
830 finderArgs, this);
831
832 if (list == null) {
833 StringBundler query = null;
834 String sql = null;
835
836 if (orderByComparator != null) {
837 query = new StringBundler(2 +
838 (orderByComparator.getOrderByFields().length * 3));
839
840 query.append(_SQL_SELECT_PASSWORDPOLICY);
841
842 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
843 orderByComparator);
844
845 sql = query.toString();
846 }
847 else {
848 sql = _SQL_SELECT_PASSWORDPOLICY;
849 }
850
851 Session session = null;
852
853 try {
854 session = openSession();
855
856 Query q = session.createQuery(sql);
857
858 if (orderByComparator == null) {
859 list = (List<PasswordPolicy>)QueryUtil.list(q,
860 getDialect(), start, end, false);
861
862 Collections.sort(list);
863 }
864 else {
865 list = (List<PasswordPolicy>)QueryUtil.list(q,
866 getDialect(), start, end);
867 }
868 }
869 catch (Exception e) {
870 throw processException(e);
871 }
872 finally {
873 if (list == null) {
874 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
875 finderArgs);
876 }
877 else {
878 cacheResult(list);
879
880 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
881 list);
882 }
883
884 closeSession(session);
885 }
886 }
887
888 return list;
889 }
890
891
898 public void removeByC_DP(long companyId, boolean defaultPolicy)
899 throws NoSuchPasswordPolicyException, SystemException {
900 PasswordPolicy passwordPolicy = findByC_DP(companyId, defaultPolicy);
901
902 remove(passwordPolicy);
903 }
904
905
912 public void removeByC_N(long companyId, String name)
913 throws NoSuchPasswordPolicyException, SystemException {
914 PasswordPolicy passwordPolicy = findByC_N(companyId, name);
915
916 remove(passwordPolicy);
917 }
918
919
924 public void removeAll() throws SystemException {
925 for (PasswordPolicy passwordPolicy : findAll()) {
926 remove(passwordPolicy);
927 }
928 }
929
930
938 public int countByC_DP(long companyId, boolean defaultPolicy)
939 throws SystemException {
940 Object[] finderArgs = new Object[] { companyId, defaultPolicy };
941
942 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_DP,
943 finderArgs, this);
944
945 if (count == null) {
946 StringBundler query = new StringBundler(3);
947
948 query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
949
950 query.append(_FINDER_COLUMN_C_DP_COMPANYID_2);
951
952 query.append(_FINDER_COLUMN_C_DP_DEFAULTPOLICY_2);
953
954 String sql = query.toString();
955
956 Session session = null;
957
958 try {
959 session = openSession();
960
961 Query q = session.createQuery(sql);
962
963 QueryPos qPos = QueryPos.getInstance(q);
964
965 qPos.add(companyId);
966
967 qPos.add(defaultPolicy);
968
969 count = (Long)q.uniqueResult();
970 }
971 catch (Exception e) {
972 throw processException(e);
973 }
974 finally {
975 if (count == null) {
976 count = Long.valueOf(0);
977 }
978
979 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_DP,
980 finderArgs, count);
981
982 closeSession(session);
983 }
984 }
985
986 return count.intValue();
987 }
988
989
997 public int countByC_N(long companyId, String name)
998 throws SystemException {
999 Object[] finderArgs = new Object[] { companyId, name };
1000
1001 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1002 finderArgs, this);
1003
1004 if (count == null) {
1005 StringBundler query = new StringBundler(3);
1006
1007 query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
1008
1009 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1010
1011 if (name == null) {
1012 query.append(_FINDER_COLUMN_C_N_NAME_1);
1013 }
1014 else {
1015 if (name.equals(StringPool.BLANK)) {
1016 query.append(_FINDER_COLUMN_C_N_NAME_3);
1017 }
1018 else {
1019 query.append(_FINDER_COLUMN_C_N_NAME_2);
1020 }
1021 }
1022
1023 String sql = query.toString();
1024
1025 Session session = null;
1026
1027 try {
1028 session = openSession();
1029
1030 Query q = session.createQuery(sql);
1031
1032 QueryPos qPos = QueryPos.getInstance(q);
1033
1034 qPos.add(companyId);
1035
1036 if (name != null) {
1037 qPos.add(name);
1038 }
1039
1040 count = (Long)q.uniqueResult();
1041 }
1042 catch (Exception e) {
1043 throw processException(e);
1044 }
1045 finally {
1046 if (count == null) {
1047 count = Long.valueOf(0);
1048 }
1049
1050 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1051 count);
1052
1053 closeSession(session);
1054 }
1055 }
1056
1057 return count.intValue();
1058 }
1059
1060
1066 public int countAll() throws SystemException {
1067 Object[] finderArgs = new Object[0];
1068
1069 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1070 finderArgs, this);
1071
1072 if (count == null) {
1073 Session session = null;
1074
1075 try {
1076 session = openSession();
1077
1078 Query q = session.createQuery(_SQL_COUNT_PASSWORDPOLICY);
1079
1080 count = (Long)q.uniqueResult();
1081 }
1082 catch (Exception e) {
1083 throw processException(e);
1084 }
1085 finally {
1086 if (count == null) {
1087 count = Long.valueOf(0);
1088 }
1089
1090 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1091 count);
1092
1093 closeSession(session);
1094 }
1095 }
1096
1097 return count.intValue();
1098 }
1099
1100
1103 public void afterPropertiesSet() {
1104 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1105 com.liferay.portal.util.PropsUtil.get(
1106 "value.object.listener.com.liferay.portal.model.PasswordPolicy")));
1107
1108 if (listenerClassNames.length > 0) {
1109 try {
1110 List<ModelListener<PasswordPolicy>> listenersList = new ArrayList<ModelListener<PasswordPolicy>>();
1111
1112 for (String listenerClassName : listenerClassNames) {
1113 listenersList.add((ModelListener<PasswordPolicy>)InstanceFactory.newInstance(
1114 listenerClassName));
1115 }
1116
1117 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1118 }
1119 catch (Exception e) {
1120 _log.error(e);
1121 }
1122 }
1123 }
1124
1125 public void destroy() {
1126 EntityCacheUtil.removeCache(PasswordPolicyImpl.class.getName());
1127 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1128 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1129 }
1130
1131 @BeanReference(type = AccountPersistence.class)
1132 protected AccountPersistence accountPersistence;
1133 @BeanReference(type = AddressPersistence.class)
1134 protected AddressPersistence addressPersistence;
1135 @BeanReference(type = BrowserTrackerPersistence.class)
1136 protected BrowserTrackerPersistence browserTrackerPersistence;
1137 @BeanReference(type = ClassNamePersistence.class)
1138 protected ClassNamePersistence classNamePersistence;
1139 @BeanReference(type = ClusterGroupPersistence.class)
1140 protected ClusterGroupPersistence clusterGroupPersistence;
1141 @BeanReference(type = CompanyPersistence.class)
1142 protected CompanyPersistence companyPersistence;
1143 @BeanReference(type = ContactPersistence.class)
1144 protected ContactPersistence contactPersistence;
1145 @BeanReference(type = CountryPersistence.class)
1146 protected CountryPersistence countryPersistence;
1147 @BeanReference(type = EmailAddressPersistence.class)
1148 protected EmailAddressPersistence emailAddressPersistence;
1149 @BeanReference(type = GroupPersistence.class)
1150 protected GroupPersistence groupPersistence;
1151 @BeanReference(type = ImagePersistence.class)
1152 protected ImagePersistence imagePersistence;
1153 @BeanReference(type = LayoutPersistence.class)
1154 protected LayoutPersistence layoutPersistence;
1155 @BeanReference(type = LayoutPrototypePersistence.class)
1156 protected LayoutPrototypePersistence layoutPrototypePersistence;
1157 @BeanReference(type = LayoutSetPersistence.class)
1158 protected LayoutSetPersistence layoutSetPersistence;
1159 @BeanReference(type = LayoutSetPrototypePersistence.class)
1160 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1161 @BeanReference(type = ListTypePersistence.class)
1162 protected ListTypePersistence listTypePersistence;
1163 @BeanReference(type = LockPersistence.class)
1164 protected LockPersistence lockPersistence;
1165 @BeanReference(type = MembershipRequestPersistence.class)
1166 protected MembershipRequestPersistence membershipRequestPersistence;
1167 @BeanReference(type = OrganizationPersistence.class)
1168 protected OrganizationPersistence organizationPersistence;
1169 @BeanReference(type = OrgGroupPermissionPersistence.class)
1170 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1171 @BeanReference(type = OrgGroupRolePersistence.class)
1172 protected OrgGroupRolePersistence orgGroupRolePersistence;
1173 @BeanReference(type = OrgLaborPersistence.class)
1174 protected OrgLaborPersistence orgLaborPersistence;
1175 @BeanReference(type = PasswordPolicyPersistence.class)
1176 protected PasswordPolicyPersistence passwordPolicyPersistence;
1177 @BeanReference(type = PasswordPolicyRelPersistence.class)
1178 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1179 @BeanReference(type = PasswordTrackerPersistence.class)
1180 protected PasswordTrackerPersistence passwordTrackerPersistence;
1181 @BeanReference(type = PermissionPersistence.class)
1182 protected PermissionPersistence permissionPersistence;
1183 @BeanReference(type = PhonePersistence.class)
1184 protected PhonePersistence phonePersistence;
1185 @BeanReference(type = PluginSettingPersistence.class)
1186 protected PluginSettingPersistence pluginSettingPersistence;
1187 @BeanReference(type = PortletPersistence.class)
1188 protected PortletPersistence portletPersistence;
1189 @BeanReference(type = PortletItemPersistence.class)
1190 protected PortletItemPersistence portletItemPersistence;
1191 @BeanReference(type = PortletPreferencesPersistence.class)
1192 protected PortletPreferencesPersistence portletPreferencesPersistence;
1193 @BeanReference(type = RegionPersistence.class)
1194 protected RegionPersistence regionPersistence;
1195 @BeanReference(type = ReleasePersistence.class)
1196 protected ReleasePersistence releasePersistence;
1197 @BeanReference(type = ResourcePersistence.class)
1198 protected ResourcePersistence resourcePersistence;
1199 @BeanReference(type = ResourceActionPersistence.class)
1200 protected ResourceActionPersistence resourceActionPersistence;
1201 @BeanReference(type = ResourceCodePersistence.class)
1202 protected ResourceCodePersistence resourceCodePersistence;
1203 @BeanReference(type = ResourcePermissionPersistence.class)
1204 protected ResourcePermissionPersistence resourcePermissionPersistence;
1205 @BeanReference(type = RolePersistence.class)
1206 protected RolePersistence rolePersistence;
1207 @BeanReference(type = ServiceComponentPersistence.class)
1208 protected ServiceComponentPersistence serviceComponentPersistence;
1209 @BeanReference(type = ShardPersistence.class)
1210 protected ShardPersistence shardPersistence;
1211 @BeanReference(type = SubscriptionPersistence.class)
1212 protected SubscriptionPersistence subscriptionPersistence;
1213 @BeanReference(type = TicketPersistence.class)
1214 protected TicketPersistence ticketPersistence;
1215 @BeanReference(type = TeamPersistence.class)
1216 protected TeamPersistence teamPersistence;
1217 @BeanReference(type = UserPersistence.class)
1218 protected UserPersistence userPersistence;
1219 @BeanReference(type = UserGroupPersistence.class)
1220 protected UserGroupPersistence userGroupPersistence;
1221 @BeanReference(type = UserGroupGroupRolePersistence.class)
1222 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1223 @BeanReference(type = UserGroupRolePersistence.class)
1224 protected UserGroupRolePersistence userGroupRolePersistence;
1225 @BeanReference(type = UserIdMapperPersistence.class)
1226 protected UserIdMapperPersistence userIdMapperPersistence;
1227 @BeanReference(type = UserTrackerPersistence.class)
1228 protected UserTrackerPersistence userTrackerPersistence;
1229 @BeanReference(type = UserTrackerPathPersistence.class)
1230 protected UserTrackerPathPersistence userTrackerPathPersistence;
1231 @BeanReference(type = WebDAVPropsPersistence.class)
1232 protected WebDAVPropsPersistence webDAVPropsPersistence;
1233 @BeanReference(type = WebsitePersistence.class)
1234 protected WebsitePersistence websitePersistence;
1235 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1236 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1237 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1238 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1239 private static final String _SQL_SELECT_PASSWORDPOLICY = "SELECT passwordPolicy FROM PasswordPolicy passwordPolicy";
1240 private static final String _SQL_SELECT_PASSWORDPOLICY_WHERE = "SELECT passwordPolicy FROM PasswordPolicy passwordPolicy WHERE ";
1241 private static final String _SQL_COUNT_PASSWORDPOLICY = "SELECT COUNT(passwordPolicy) FROM PasswordPolicy passwordPolicy";
1242 private static final String _SQL_COUNT_PASSWORDPOLICY_WHERE = "SELECT COUNT(passwordPolicy) FROM PasswordPolicy passwordPolicy WHERE ";
1243 private static final String _FINDER_COLUMN_C_DP_COMPANYID_2 = "passwordPolicy.companyId = ? AND ";
1244 private static final String _FINDER_COLUMN_C_DP_DEFAULTPOLICY_2 = "passwordPolicy.defaultPolicy = ?";
1245 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "passwordPolicy.companyId = ? AND ";
1246 private static final String _FINDER_COLUMN_C_N_NAME_1 = "passwordPolicy.name IS NULL";
1247 private static final String _FINDER_COLUMN_C_N_NAME_2 = "passwordPolicy.name = ?";
1248 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(passwordPolicy.name IS NULL OR passwordPolicy.name = ?)";
1249 private static final String _ORDER_BY_ENTITY_ALIAS = "passwordPolicy.";
1250 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordPolicy exists with the primary key ";
1251 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordPolicy exists with the key {";
1252 private static Log _log = LogFactoryUtil.getLog(PasswordPolicyPersistenceImpl.class);
1253 }