1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchPasswordPolicyRelException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.annotation.BeanReference;
28  import com.liferay.portal.kernel.cache.CacheRegistry;
29  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32  import com.liferay.portal.kernel.dao.orm.FinderPath;
33  import com.liferay.portal.kernel.dao.orm.Query;
34  import com.liferay.portal.kernel.dao.orm.QueryPos;
35  import com.liferay.portal.kernel.dao.orm.QueryUtil;
36  import com.liferay.portal.kernel.dao.orm.Session;
37  import com.liferay.portal.kernel.log.Log;
38  import com.liferay.portal.kernel.log.LogFactoryUtil;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.OrderByComparator;
41  import com.liferay.portal.kernel.util.StringPool;
42  import com.liferay.portal.kernel.util.StringUtil;
43  import com.liferay.portal.model.ModelListener;
44  import com.liferay.portal.model.PasswordPolicyRel;
45  import com.liferay.portal.model.impl.PasswordPolicyRelImpl;
46  import com.liferay.portal.model.impl.PasswordPolicyRelModelImpl;
47  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
48  
49  import java.util.ArrayList;
50  import java.util.Collections;
51  import java.util.List;
52  
53  /**
54   * <a href="PasswordPolicyRelPersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * <p>
57   * ServiceBuilder generated this class. Modifications in this class will be
58   * overwritten the next time is generated.
59   * </p>
60   *
61   * @author    Brian Wing Shun Chan
62   * @see       PasswordPolicyRelPersistence
63   * @see       PasswordPolicyRelUtil
64   * @generated
65   */
66  public class PasswordPolicyRelPersistenceImpl extends BasePersistenceImpl
67      implements PasswordPolicyRelPersistence {
68      public static final String FINDER_CLASS_NAME_ENTITY = PasswordPolicyRelImpl.class.getName();
69      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70          ".List";
71      public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
72              PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
73              FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
74              new String[] { Long.class.getName(), Long.class.getName() });
75      public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
76              PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
77              FINDER_CLASS_NAME_LIST, "countByC_C",
78              new String[] { Long.class.getName(), Long.class.getName() });
79      public static final FinderPath FINDER_PATH_FETCH_BY_P_C_C = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
80              PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
81              FINDER_CLASS_NAME_ENTITY, "fetchByP_C_C",
82              new String[] {
83                  Long.class.getName(), Long.class.getName(), Long.class.getName()
84              });
85      public static final FinderPath FINDER_PATH_COUNT_BY_P_C_C = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
86              PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
87              FINDER_CLASS_NAME_LIST, "countByP_C_C",
88              new String[] {
89                  Long.class.getName(), Long.class.getName(), Long.class.getName()
90              });
91      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
92              PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
93              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
94      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
95              PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
96              FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
97  
98      public void cacheResult(PasswordPolicyRel passwordPolicyRel) {
99          EntityCacheUtil.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
100             PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey(),
101             passwordPolicyRel);
102 
103         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
104             new Object[] {
105                 new Long(passwordPolicyRel.getClassNameId()),
106                 new Long(passwordPolicyRel.getClassPK())
107             }, passwordPolicyRel);
108 
109         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_C_C,
110             new Object[] {
111                 new Long(passwordPolicyRel.getPasswordPolicyId()),
112                 new Long(passwordPolicyRel.getClassNameId()),
113                 new Long(passwordPolicyRel.getClassPK())
114             }, passwordPolicyRel);
115     }
116 
117     public void cacheResult(List<PasswordPolicyRel> passwordPolicyRels) {
118         for (PasswordPolicyRel passwordPolicyRel : passwordPolicyRels) {
119             if (EntityCacheUtil.getResult(
120                         PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
121                         PasswordPolicyRelImpl.class,
122                         passwordPolicyRel.getPrimaryKey(), this) == null) {
123                 cacheResult(passwordPolicyRel);
124             }
125         }
126     }
127 
128     public void clearCache() {
129         CacheRegistry.clear(PasswordPolicyRelImpl.class.getName());
130         EntityCacheUtil.clearCache(PasswordPolicyRelImpl.class.getName());
131         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
133     }
134 
135     public PasswordPolicyRel create(long passwordPolicyRelId) {
136         PasswordPolicyRel passwordPolicyRel = new PasswordPolicyRelImpl();
137 
138         passwordPolicyRel.setNew(true);
139         passwordPolicyRel.setPrimaryKey(passwordPolicyRelId);
140 
141         return passwordPolicyRel;
142     }
143 
144     public PasswordPolicyRel remove(long passwordPolicyRelId)
145         throws NoSuchPasswordPolicyRelException, SystemException {
146         Session session = null;
147 
148         try {
149             session = openSession();
150 
151             PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
152                     new Long(passwordPolicyRelId));
153 
154             if (passwordPolicyRel == null) {
155                 if (_log.isWarnEnabled()) {
156                     _log.warn(
157                         "No PasswordPolicyRel exists with the primary key " +
158                         passwordPolicyRelId);
159                 }
160 
161                 throw new NoSuchPasswordPolicyRelException(
162                     "No PasswordPolicyRel exists with the primary key " +
163                     passwordPolicyRelId);
164             }
165 
166             return remove(passwordPolicyRel);
167         }
168         catch (NoSuchPasswordPolicyRelException nsee) {
169             throw nsee;
170         }
171         catch (Exception e) {
172             throw processException(e);
173         }
174         finally {
175             closeSession(session);
176         }
177     }
178 
179     public PasswordPolicyRel remove(PasswordPolicyRel passwordPolicyRel)
180         throws SystemException {
181         for (ModelListener<PasswordPolicyRel> listener : listeners) {
182             listener.onBeforeRemove(passwordPolicyRel);
183         }
184 
185         passwordPolicyRel = removeImpl(passwordPolicyRel);
186 
187         for (ModelListener<PasswordPolicyRel> listener : listeners) {
188             listener.onAfterRemove(passwordPolicyRel);
189         }
190 
191         return passwordPolicyRel;
192     }
193 
194     protected PasswordPolicyRel removeImpl(PasswordPolicyRel passwordPolicyRel)
195         throws SystemException {
196         Session session = null;
197 
198         try {
199             session = openSession();
200 
201             if (passwordPolicyRel.isCachedModel() ||
202                     BatchSessionUtil.isEnabled()) {
203                 Object staleObject = session.get(PasswordPolicyRelImpl.class,
204                         passwordPolicyRel.getPrimaryKeyObj());
205 
206                 if (staleObject != null) {
207                     session.evict(staleObject);
208                 }
209             }
210 
211             session.delete(passwordPolicyRel);
212 
213             session.flush();
214         }
215         catch (Exception e) {
216             throw processException(e);
217         }
218         finally {
219             closeSession(session);
220         }
221 
222         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
223 
224         PasswordPolicyRelModelImpl passwordPolicyRelModelImpl = (PasswordPolicyRelModelImpl)passwordPolicyRel;
225 
226         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
227             new Object[] {
228                 new Long(passwordPolicyRelModelImpl.getOriginalClassNameId()),
229                 new Long(passwordPolicyRelModelImpl.getOriginalClassPK())
230             });
231 
232         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_C_C,
233             new Object[] {
234                 new Long(passwordPolicyRelModelImpl.getOriginalPasswordPolicyId()),
235                 new Long(passwordPolicyRelModelImpl.getOriginalClassNameId()),
236                 new Long(passwordPolicyRelModelImpl.getOriginalClassPK())
237             });
238 
239         EntityCacheUtil.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
240             PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey());
241 
242         return passwordPolicyRel;
243     }
244 
245     /**
246      * @deprecated Use {@link #update(PasswordPolicyRel, boolean merge)}.
247      */
248     public PasswordPolicyRel update(PasswordPolicyRel passwordPolicyRel)
249         throws SystemException {
250         if (_log.isWarnEnabled()) {
251             _log.warn(
252                 "Using the deprecated update(PasswordPolicyRel passwordPolicyRel) method. Use update(PasswordPolicyRel passwordPolicyRel, boolean merge) instead.");
253         }
254 
255         return update(passwordPolicyRel, false);
256     }
257 
258     /**
259      * Add, update, or merge, the entity. This method also calls the model
260      * listeners to trigger the proper events associated with adding, deleting,
261      * or updating an entity.
262      *
263      * @param  passwordPolicyRel the entity to add, update, or merge
264      * @param  merge boolean value for whether to merge the entity. The default
265      *         value is false. Setting merge to true is more expensive and
266      *         should only be true when passwordPolicyRel is transient. See
267      *         LEP-5473 for a detailed discussion of this method.
268      * @return the entity that was added, updated, or merged
269      */
270     public PasswordPolicyRel update(PasswordPolicyRel passwordPolicyRel,
271         boolean merge) throws SystemException {
272         boolean isNew = passwordPolicyRel.isNew();
273 
274         for (ModelListener<PasswordPolicyRel> listener : listeners) {
275             if (isNew) {
276                 listener.onBeforeCreate(passwordPolicyRel);
277             }
278             else {
279                 listener.onBeforeUpdate(passwordPolicyRel);
280             }
281         }
282 
283         passwordPolicyRel = updateImpl(passwordPolicyRel, merge);
284 
285         for (ModelListener<PasswordPolicyRel> listener : listeners) {
286             if (isNew) {
287                 listener.onAfterCreate(passwordPolicyRel);
288             }
289             else {
290                 listener.onAfterUpdate(passwordPolicyRel);
291             }
292         }
293 
294         return passwordPolicyRel;
295     }
296 
297     public PasswordPolicyRel updateImpl(
298         com.liferay.portal.model.PasswordPolicyRel passwordPolicyRel,
299         boolean merge) throws SystemException {
300         boolean isNew = passwordPolicyRel.isNew();
301 
302         PasswordPolicyRelModelImpl passwordPolicyRelModelImpl = (PasswordPolicyRelModelImpl)passwordPolicyRel;
303 
304         Session session = null;
305 
306         try {
307             session = openSession();
308 
309             BatchSessionUtil.update(session, passwordPolicyRel, merge);
310 
311             passwordPolicyRel.setNew(false);
312         }
313         catch (Exception e) {
314             throw processException(e);
315         }
316         finally {
317             closeSession(session);
318         }
319 
320         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
321 
322         EntityCacheUtil.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
323             PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey(),
324             passwordPolicyRel);
325 
326         if (!isNew &&
327                 ((passwordPolicyRel.getClassNameId() != passwordPolicyRelModelImpl.getOriginalClassNameId()) ||
328                 (passwordPolicyRel.getClassPK() != passwordPolicyRelModelImpl.getOriginalClassPK()))) {
329             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
330                 new Object[] {
331                     new Long(passwordPolicyRelModelImpl.getOriginalClassNameId()),
332                     new Long(passwordPolicyRelModelImpl.getOriginalClassPK())
333                 });
334         }
335 
336         if (isNew ||
337                 ((passwordPolicyRel.getClassNameId() != passwordPolicyRelModelImpl.getOriginalClassNameId()) ||
338                 (passwordPolicyRel.getClassPK() != passwordPolicyRelModelImpl.getOriginalClassPK()))) {
339             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
340                 new Object[] {
341                     new Long(passwordPolicyRel.getClassNameId()),
342                     new Long(passwordPolicyRel.getClassPK())
343                 }, passwordPolicyRel);
344         }
345 
346         if (!isNew &&
347                 ((passwordPolicyRel.getPasswordPolicyId() != passwordPolicyRelModelImpl.getOriginalPasswordPolicyId()) ||
348                 (passwordPolicyRel.getClassNameId() != passwordPolicyRelModelImpl.getOriginalClassNameId()) ||
349                 (passwordPolicyRel.getClassPK() != passwordPolicyRelModelImpl.getOriginalClassPK()))) {
350             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_C_C,
351                 new Object[] {
352                     new Long(passwordPolicyRelModelImpl.getOriginalPasswordPolicyId()),
353                     new Long(passwordPolicyRelModelImpl.getOriginalClassNameId()),
354                     new Long(passwordPolicyRelModelImpl.getOriginalClassPK())
355                 });
356         }
357 
358         if (isNew ||
359                 ((passwordPolicyRel.getPasswordPolicyId() != passwordPolicyRelModelImpl.getOriginalPasswordPolicyId()) ||
360                 (passwordPolicyRel.getClassNameId() != passwordPolicyRelModelImpl.getOriginalClassNameId()) ||
361                 (passwordPolicyRel.getClassPK() != passwordPolicyRelModelImpl.getOriginalClassPK()))) {
362             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_C_C,
363                 new Object[] {
364                     new Long(passwordPolicyRel.getPasswordPolicyId()),
365                     new Long(passwordPolicyRel.getClassNameId()),
366                     new Long(passwordPolicyRel.getClassPK())
367                 }, passwordPolicyRel);
368         }
369 
370         return passwordPolicyRel;
371     }
372 
373     public PasswordPolicyRel findByPrimaryKey(long passwordPolicyRelId)
374         throws NoSuchPasswordPolicyRelException, SystemException {
375         PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(passwordPolicyRelId);
376 
377         if (passwordPolicyRel == null) {
378             if (_log.isWarnEnabled()) {
379                 _log.warn("No PasswordPolicyRel exists with the primary key " +
380                     passwordPolicyRelId);
381             }
382 
383             throw new NoSuchPasswordPolicyRelException(
384                 "No PasswordPolicyRel exists with the primary key " +
385                 passwordPolicyRelId);
386         }
387 
388         return passwordPolicyRel;
389     }
390 
391     public PasswordPolicyRel fetchByPrimaryKey(long passwordPolicyRelId)
392         throws SystemException {
393         PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)EntityCacheUtil.getResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
394                 PasswordPolicyRelImpl.class, passwordPolicyRelId, this);
395 
396         if (passwordPolicyRel == null) {
397             Session session = null;
398 
399             try {
400                 session = openSession();
401 
402                 passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
403                         new Long(passwordPolicyRelId));
404             }
405             catch (Exception e) {
406                 throw processException(e);
407             }
408             finally {
409                 if (passwordPolicyRel != null) {
410                     cacheResult(passwordPolicyRel);
411                 }
412 
413                 closeSession(session);
414             }
415         }
416 
417         return passwordPolicyRel;
418     }
419 
420     public PasswordPolicyRel findByC_C(long classNameId, long classPK)
421         throws NoSuchPasswordPolicyRelException, SystemException {
422         PasswordPolicyRel passwordPolicyRel = fetchByC_C(classNameId, classPK);
423 
424         if (passwordPolicyRel == null) {
425             StringBuilder msg = new StringBuilder();
426 
427             msg.append("No PasswordPolicyRel exists with the key {");
428 
429             msg.append("classNameId=" + classNameId);
430 
431             msg.append(", ");
432             msg.append("classPK=" + classPK);
433 
434             msg.append(StringPool.CLOSE_CURLY_BRACE);
435 
436             if (_log.isWarnEnabled()) {
437                 _log.warn(msg.toString());
438             }
439 
440             throw new NoSuchPasswordPolicyRelException(msg.toString());
441         }
442 
443         return passwordPolicyRel;
444     }
445 
446     public PasswordPolicyRel fetchByC_C(long classNameId, long classPK)
447         throws SystemException {
448         return fetchByC_C(classNameId, classPK, true);
449     }
450 
451     public PasswordPolicyRel fetchByC_C(long classNameId, long classPK,
452         boolean retrieveFromCache) throws SystemException {
453         Object[] finderArgs = new Object[] {
454                 new Long(classNameId), new Long(classPK)
455             };
456 
457         Object result = null;
458 
459         if (retrieveFromCache) {
460             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
461                     finderArgs, this);
462         }
463 
464         if (result == null) {
465             Session session = null;
466 
467             try {
468                 session = openSession();
469 
470                 StringBuilder query = new StringBuilder();
471 
472                 query.append(
473                     "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE ");
474 
475                 query.append("passwordPolicyRel.classNameId = ?");
476 
477                 query.append(" AND ");
478 
479                 query.append("passwordPolicyRel.classPK = ?");
480 
481                 query.append(" ");
482 
483                 Query q = session.createQuery(query.toString());
484 
485                 QueryPos qPos = QueryPos.getInstance(q);
486 
487                 qPos.add(classNameId);
488 
489                 qPos.add(classPK);
490 
491                 List<PasswordPolicyRel> list = q.list();
492 
493                 result = list;
494 
495                 PasswordPolicyRel passwordPolicyRel = null;
496 
497                 if (list.isEmpty()) {
498                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
499                         finderArgs, list);
500                 }
501                 else {
502                     passwordPolicyRel = list.get(0);
503 
504                     cacheResult(passwordPolicyRel);
505 
506                     if ((passwordPolicyRel.getClassNameId() != classNameId) ||
507                             (passwordPolicyRel.getClassPK() != classPK)) {
508                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
509                             finderArgs, passwordPolicyRel);
510                     }
511                 }
512 
513                 return passwordPolicyRel;
514             }
515             catch (Exception e) {
516                 throw processException(e);
517             }
518             finally {
519                 if (result == null) {
520                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
521                         finderArgs, new ArrayList<PasswordPolicyRel>());
522                 }
523 
524                 closeSession(session);
525             }
526         }
527         else {
528             if (result instanceof List<?>) {
529                 return null;
530             }
531             else {
532                 return (PasswordPolicyRel)result;
533             }
534         }
535     }
536 
537     public PasswordPolicyRel findByP_C_C(long passwordPolicyId,
538         long classNameId, long classPK)
539         throws NoSuchPasswordPolicyRelException, SystemException {
540         PasswordPolicyRel passwordPolicyRel = fetchByP_C_C(passwordPolicyId,
541                 classNameId, classPK);
542 
543         if (passwordPolicyRel == null) {
544             StringBuilder msg = new StringBuilder();
545 
546             msg.append("No PasswordPolicyRel exists with the key {");
547 
548             msg.append("passwordPolicyId=" + passwordPolicyId);
549 
550             msg.append(", ");
551             msg.append("classNameId=" + classNameId);
552 
553             msg.append(", ");
554             msg.append("classPK=" + classPK);
555 
556             msg.append(StringPool.CLOSE_CURLY_BRACE);
557 
558             if (_log.isWarnEnabled()) {
559                 _log.warn(msg.toString());
560             }
561 
562             throw new NoSuchPasswordPolicyRelException(msg.toString());
563         }
564 
565         return passwordPolicyRel;
566     }
567 
568     public PasswordPolicyRel fetchByP_C_C(long passwordPolicyId,
569         long classNameId, long classPK) throws SystemException {
570         return fetchByP_C_C(passwordPolicyId, classNameId, classPK, true);
571     }
572 
573     public PasswordPolicyRel fetchByP_C_C(long passwordPolicyId,
574         long classNameId, long classPK, boolean retrieveFromCache)
575         throws SystemException {
576         Object[] finderArgs = new Object[] {
577                 new Long(passwordPolicyId), new Long(classNameId),
578                 new Long(classPK)
579             };
580 
581         Object result = null;
582 
583         if (retrieveFromCache) {
584             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_P_C_C,
585                     finderArgs, this);
586         }
587 
588         if (result == null) {
589             Session session = null;
590 
591             try {
592                 session = openSession();
593 
594                 StringBuilder query = new StringBuilder();
595 
596                 query.append(
597                     "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE ");
598 
599                 query.append("passwordPolicyRel.passwordPolicyId = ?");
600 
601                 query.append(" AND ");
602 
603                 query.append("passwordPolicyRel.classNameId = ?");
604 
605                 query.append(" AND ");
606 
607                 query.append("passwordPolicyRel.classPK = ?");
608 
609                 query.append(" ");
610 
611                 Query q = session.createQuery(query.toString());
612 
613                 QueryPos qPos = QueryPos.getInstance(q);
614 
615                 qPos.add(passwordPolicyId);
616 
617                 qPos.add(classNameId);
618 
619                 qPos.add(classPK);
620 
621                 List<PasswordPolicyRel> list = q.list();
622 
623                 result = list;
624 
625                 PasswordPolicyRel passwordPolicyRel = null;
626 
627                 if (list.isEmpty()) {
628                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_C_C,
629                         finderArgs, list);
630                 }
631                 else {
632                     passwordPolicyRel = list.get(0);
633 
634                     cacheResult(passwordPolicyRel);
635 
636                     if ((passwordPolicyRel.getPasswordPolicyId() != passwordPolicyId) ||
637                             (passwordPolicyRel.getClassNameId() != classNameId) ||
638                             (passwordPolicyRel.getClassPK() != classPK)) {
639                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_C_C,
640                             finderArgs, passwordPolicyRel);
641                     }
642                 }
643 
644                 return passwordPolicyRel;
645             }
646             catch (Exception e) {
647                 throw processException(e);
648             }
649             finally {
650                 if (result == null) {
651                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_C_C,
652                         finderArgs, new ArrayList<PasswordPolicyRel>());
653                 }
654 
655                 closeSession(session);
656             }
657         }
658         else {
659             if (result instanceof List<?>) {
660                 return null;
661             }
662             else {
663                 return (PasswordPolicyRel)result;
664             }
665         }
666     }
667 
668     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
669         throws SystemException {
670         Session session = null;
671 
672         try {
673             session = openSession();
674 
675             dynamicQuery.compile(session);
676 
677             return dynamicQuery.list();
678         }
679         catch (Exception e) {
680             throw processException(e);
681         }
682         finally {
683             closeSession(session);
684         }
685     }
686 
687     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
688         int start, int end) throws SystemException {
689         Session session = null;
690 
691         try {
692             session = openSession();
693 
694             dynamicQuery.setLimit(start, end);
695 
696             dynamicQuery.compile(session);
697 
698             return dynamicQuery.list();
699         }
700         catch (Exception e) {
701             throw processException(e);
702         }
703         finally {
704             closeSession(session);
705         }
706     }
707 
708     public List<PasswordPolicyRel> findAll() throws SystemException {
709         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
710     }
711 
712     public List<PasswordPolicyRel> findAll(int start, int end)
713         throws SystemException {
714         return findAll(start, end, null);
715     }
716 
717     public List<PasswordPolicyRel> findAll(int start, int end,
718         OrderByComparator obc) throws SystemException {
719         Object[] finderArgs = new Object[] {
720                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
721             };
722 
723         List<PasswordPolicyRel> list = (List<PasswordPolicyRel>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
724                 finderArgs, this);
725 
726         if (list == null) {
727             Session session = null;
728 
729             try {
730                 session = openSession();
731 
732                 StringBuilder query = new StringBuilder();
733 
734                 query.append(
735                     "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel ");
736 
737                 if (obc != null) {
738                     query.append("ORDER BY ");
739 
740                     String[] orderByFields = obc.getOrderByFields();
741 
742                     for (int i = 0; i < orderByFields.length; i++) {
743                         query.append("passwordPolicyRel.");
744                         query.append(orderByFields[i]);
745 
746                         if (obc.isAscending()) {
747                             query.append(" ASC");
748                         }
749                         else {
750                             query.append(" DESC");
751                         }
752 
753                         if ((i + 1) < orderByFields.length) {
754                             query.append(", ");
755                         }
756                     }
757                 }
758 
759                 Query q = session.createQuery(query.toString());
760 
761                 if (obc == null) {
762                     list = (List<PasswordPolicyRel>)QueryUtil.list(q,
763                             getDialect(), start, end, false);
764 
765                     Collections.sort(list);
766                 }
767                 else {
768                     list = (List<PasswordPolicyRel>)QueryUtil.list(q,
769                             getDialect(), start, end);
770                 }
771             }
772             catch (Exception e) {
773                 throw processException(e);
774             }
775             finally {
776                 if (list == null) {
777                     list = new ArrayList<PasswordPolicyRel>();
778                 }
779 
780                 cacheResult(list);
781 
782                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
783 
784                 closeSession(session);
785             }
786         }
787 
788         return list;
789     }
790 
791     public void removeByC_C(long classNameId, long classPK)
792         throws NoSuchPasswordPolicyRelException, SystemException {
793         PasswordPolicyRel passwordPolicyRel = findByC_C(classNameId, classPK);
794 
795         remove(passwordPolicyRel);
796     }
797 
798     public void removeByP_C_C(long passwordPolicyId, long classNameId,
799         long classPK) throws NoSuchPasswordPolicyRelException, SystemException {
800         PasswordPolicyRel passwordPolicyRel = findByP_C_C(passwordPolicyId,
801                 classNameId, classPK);
802 
803         remove(passwordPolicyRel);
804     }
805 
806     public void removeAll() throws SystemException {
807         for (PasswordPolicyRel passwordPolicyRel : findAll()) {
808             remove(passwordPolicyRel);
809         }
810     }
811 
812     public int countByC_C(long classNameId, long classPK)
813         throws SystemException {
814         Object[] finderArgs = new Object[] {
815                 new Long(classNameId), new Long(classPK)
816             };
817 
818         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
819                 finderArgs, this);
820 
821         if (count == null) {
822             Session session = null;
823 
824             try {
825                 session = openSession();
826 
827                 StringBuilder query = new StringBuilder();
828 
829                 query.append("SELECT COUNT(passwordPolicyRel) ");
830                 query.append("FROM PasswordPolicyRel passwordPolicyRel WHERE ");
831 
832                 query.append("passwordPolicyRel.classNameId = ?");
833 
834                 query.append(" AND ");
835 
836                 query.append("passwordPolicyRel.classPK = ?");
837 
838                 query.append(" ");
839 
840                 Query q = session.createQuery(query.toString());
841 
842                 QueryPos qPos = QueryPos.getInstance(q);
843 
844                 qPos.add(classNameId);
845 
846                 qPos.add(classPK);
847 
848                 count = (Long)q.uniqueResult();
849             }
850             catch (Exception e) {
851                 throw processException(e);
852             }
853             finally {
854                 if (count == null) {
855                     count = Long.valueOf(0);
856                 }
857 
858                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
859                     count);
860 
861                 closeSession(session);
862             }
863         }
864 
865         return count.intValue();
866     }
867 
868     public int countByP_C_C(long passwordPolicyId, long classNameId,
869         long classPK) throws SystemException {
870         Object[] finderArgs = new Object[] {
871                 new Long(passwordPolicyId), new Long(classNameId),
872                 new Long(classPK)
873             };
874 
875         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_C_C,
876                 finderArgs, this);
877 
878         if (count == null) {
879             Session session = null;
880 
881             try {
882                 session = openSession();
883 
884                 StringBuilder query = new StringBuilder();
885 
886                 query.append("SELECT COUNT(passwordPolicyRel) ");
887                 query.append("FROM PasswordPolicyRel passwordPolicyRel WHERE ");
888 
889                 query.append("passwordPolicyRel.passwordPolicyId = ?");
890 
891                 query.append(" AND ");
892 
893                 query.append("passwordPolicyRel.classNameId = ?");
894 
895                 query.append(" AND ");
896 
897                 query.append("passwordPolicyRel.classPK = ?");
898 
899                 query.append(" ");
900 
901                 Query q = session.createQuery(query.toString());
902 
903                 QueryPos qPos = QueryPos.getInstance(q);
904 
905                 qPos.add(passwordPolicyId);
906 
907                 qPos.add(classNameId);
908 
909                 qPos.add(classPK);
910 
911                 count = (Long)q.uniqueResult();
912             }
913             catch (Exception e) {
914                 throw processException(e);
915             }
916             finally {
917                 if (count == null) {
918                     count = Long.valueOf(0);
919                 }
920 
921                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_C_C,
922                     finderArgs, count);
923 
924                 closeSession(session);
925             }
926         }
927 
928         return count.intValue();
929     }
930 
931     public int countAll() throws SystemException {
932         Object[] finderArgs = new Object[0];
933 
934         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
935                 finderArgs, this);
936 
937         if (count == null) {
938             Session session = null;
939 
940             try {
941                 session = openSession();
942 
943                 Query q = session.createQuery(
944                         "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel");
945 
946                 count = (Long)q.uniqueResult();
947             }
948             catch (Exception e) {
949                 throw processException(e);
950             }
951             finally {
952                 if (count == null) {
953                     count = Long.valueOf(0);
954                 }
955 
956                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
957                     count);
958 
959                 closeSession(session);
960             }
961         }
962 
963         return count.intValue();
964     }
965 
966     public void afterPropertiesSet() {
967         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
968                     com.liferay.portal.util.PropsUtil.get(
969                         "value.object.listener.com.liferay.portal.model.PasswordPolicyRel")));
970 
971         if (listenerClassNames.length > 0) {
972             try {
973                 List<ModelListener<PasswordPolicyRel>> listenersList = new ArrayList<ModelListener<PasswordPolicyRel>>();
974 
975                 for (String listenerClassName : listenerClassNames) {
976                     listenersList.add((ModelListener<PasswordPolicyRel>)Class.forName(
977                             listenerClassName).newInstance());
978                 }
979 
980                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
981             }
982             catch (Exception e) {
983                 _log.error(e);
984             }
985         }
986     }
987 
988     @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
989     protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
990     @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
991     protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
992     @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
993     protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
994     @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
995     protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
996     @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
997     protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
998     @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
999     protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1000    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1001    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1002    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1003    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1004    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1005    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1006    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1007    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1008    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1009    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1010    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1011    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1012    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1013    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1014    @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
1015    protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
1016    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1017    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1018    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1019    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1020    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1021    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1022    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1023    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1024    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1025    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1026    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1027    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1028    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1029    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1030    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1031    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1032    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1033    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1034    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1035    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1036    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1037    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1038    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1039    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1040    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1041    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1042    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1043    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1044    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1045    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1046    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1047    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1048    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1049    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1050    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1051    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1052    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1053    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1054    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1055    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1056    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1057    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1058    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1059    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1060    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1061    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1062    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1063    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1064    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1065    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1066    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1067    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1068    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1069    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1070    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1071    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1072    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1073    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1074    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1075    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1076    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1077    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1078    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1079    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1080    private static Log _log = LogFactoryUtil.getLog(PasswordPolicyRelPersistenceImpl.class);
1081}