1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.NoSuchPhoneException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29  import com.liferay.portal.kernel.dao.orm.Query;
30  import com.liferay.portal.kernel.dao.orm.QueryPos;
31  import com.liferay.portal.kernel.dao.orm.QueryUtil;
32  import com.liferay.portal.kernel.dao.orm.Session;
33  import com.liferay.portal.kernel.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.model.Phone;
40  import com.liferay.portal.model.impl.PhoneImpl;
41  import com.liferay.portal.model.impl.PhoneModelImpl;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import org.apache.commons.logging.Log;
45  import org.apache.commons.logging.LogFactory;
46  
47  import java.util.ArrayList;
48  import java.util.Collections;
49  import java.util.Iterator;
50  import java.util.List;
51  
52  /**
53   * <a href="PhonePersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * @author Brian Wing Shun Chan
56   *
57   */
58  public class PhonePersistenceImpl extends BasePersistenceImpl
59      implements PhonePersistence {
60      public Phone create(long phoneId) {
61          Phone phone = new PhoneImpl();
62  
63          phone.setNew(true);
64          phone.setPrimaryKey(phoneId);
65  
66          return phone;
67      }
68  
69      public Phone remove(long phoneId)
70          throws NoSuchPhoneException, SystemException {
71          Session session = null;
72  
73          try {
74              session = openSession();
75  
76              Phone phone = (Phone)session.get(PhoneImpl.class, new Long(phoneId));
77  
78              if (phone == null) {
79                  if (_log.isWarnEnabled()) {
80                      _log.warn("No Phone exists with the primary key " +
81                          phoneId);
82                  }
83  
84                  throw new NoSuchPhoneException(
85                      "No Phone exists with the primary key " + phoneId);
86              }
87  
88              return remove(phone);
89          }
90          catch (NoSuchPhoneException nsee) {
91              throw nsee;
92          }
93          catch (Exception e) {
94              throw processException(e);
95          }
96          finally {
97              closeSession(session);
98          }
99      }
100 
101     public Phone remove(Phone phone) throws SystemException {
102         if (_listeners.length > 0) {
103             for (ModelListener listener : _listeners) {
104                 listener.onBeforeRemove(phone);
105             }
106         }
107 
108         phone = removeImpl(phone);
109 
110         if (_listeners.length > 0) {
111             for (ModelListener listener : _listeners) {
112                 listener.onAfterRemove(phone);
113             }
114         }
115 
116         return phone;
117     }
118 
119     protected Phone removeImpl(Phone phone) throws SystemException {
120         Session session = null;
121 
122         try {
123             session = openSession();
124 
125             session.delete(phone);
126 
127             session.flush();
128 
129             return phone;
130         }
131         catch (Exception e) {
132             throw processException(e);
133         }
134         finally {
135             closeSession(session);
136 
137             FinderCacheUtil.clearCache(Phone.class.getName());
138         }
139     }
140 
141     /**
142      * @deprecated Use <code>update(Phone phone, boolean merge)</code>.
143      */
144     public Phone update(Phone phone) throws SystemException {
145         if (_log.isWarnEnabled()) {
146             _log.warn(
147                 "Using the deprecated update(Phone phone) method. Use update(Phone phone, boolean merge) instead.");
148         }
149 
150         return update(phone, false);
151     }
152 
153     /**
154      * Add, update, or merge, the entity. This method also calls the model
155      * listeners to trigger the proper events associated with adding, deleting,
156      * or updating an entity.
157      *
158      * @param        phone the entity to add, update, or merge
159      * @param        merge boolean value for whether to merge the entity. The
160      *                default value is false. Setting merge to true is more
161      *                expensive and should only be true when phone is
162      *                transient. See LEP-5473 for a detailed discussion of this
163      *                method.
164      * @return        true if the portlet can be displayed via Ajax
165      */
166     public Phone update(Phone phone, boolean merge) throws SystemException {
167         boolean isNew = phone.isNew();
168 
169         if (_listeners.length > 0) {
170             for (ModelListener listener : _listeners) {
171                 if (isNew) {
172                     listener.onBeforeCreate(phone);
173                 }
174                 else {
175                     listener.onBeforeUpdate(phone);
176                 }
177             }
178         }
179 
180         phone = updateImpl(phone, merge);
181 
182         if (_listeners.length > 0) {
183             for (ModelListener listener : _listeners) {
184                 if (isNew) {
185                     listener.onAfterCreate(phone);
186                 }
187                 else {
188                     listener.onAfterUpdate(phone);
189                 }
190             }
191         }
192 
193         return phone;
194     }
195 
196     public Phone updateImpl(com.liferay.portal.model.Phone phone, boolean merge)
197         throws SystemException {
198         Session session = null;
199 
200         try {
201             session = openSession();
202 
203             if (merge) {
204                 session.merge(phone);
205             }
206             else {
207                 if (phone.isNew()) {
208                     session.save(phone);
209                 }
210             }
211 
212             session.flush();
213 
214             phone.setNew(false);
215 
216             return phone;
217         }
218         catch (Exception e) {
219             throw processException(e);
220         }
221         finally {
222             closeSession(session);
223 
224             FinderCacheUtil.clearCache(Phone.class.getName());
225         }
226     }
227 
228     public Phone findByPrimaryKey(long phoneId)
229         throws NoSuchPhoneException, SystemException {
230         Phone phone = fetchByPrimaryKey(phoneId);
231 
232         if (phone == null) {
233             if (_log.isWarnEnabled()) {
234                 _log.warn("No Phone exists with the primary key " + phoneId);
235             }
236 
237             throw new NoSuchPhoneException(
238                 "No Phone exists with the primary key " + phoneId);
239         }
240 
241         return phone;
242     }
243 
244     public Phone fetchByPrimaryKey(long phoneId) throws SystemException {
245         Session session = null;
246 
247         try {
248             session = openSession();
249 
250             return (Phone)session.get(PhoneImpl.class, new Long(phoneId));
251         }
252         catch (Exception e) {
253             throw processException(e);
254         }
255         finally {
256             closeSession(session);
257         }
258     }
259 
260     public List<Phone> findByCompanyId(long companyId)
261         throws SystemException {
262         boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
263         String finderClassName = Phone.class.getName();
264         String finderMethodName = "findByCompanyId";
265         String[] finderParams = new String[] { Long.class.getName() };
266         Object[] finderArgs = new Object[] { new Long(companyId) };
267 
268         Object result = null;
269 
270         if (finderClassNameCacheEnabled) {
271             result = FinderCacheUtil.getResult(finderClassName,
272                     finderMethodName, finderParams, finderArgs, this);
273         }
274 
275         if (result == null) {
276             Session session = null;
277 
278             try {
279                 session = openSession();
280 
281                 StringBuilder query = new StringBuilder();
282 
283                 query.append("FROM com.liferay.portal.model.Phone WHERE ");
284 
285                 query.append("companyId = ?");
286 
287                 query.append(" ");
288 
289                 query.append("ORDER BY ");
290 
291                 query.append("createDate ASC");
292 
293                 Query q = session.createQuery(query.toString());
294 
295                 QueryPos qPos = QueryPos.getInstance(q);
296 
297                 qPos.add(companyId);
298 
299                 List<Phone> list = q.list();
300 
301                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
302                     finderClassName, finderMethodName, finderParams,
303                     finderArgs, list);
304 
305                 return list;
306             }
307             catch (Exception e) {
308                 throw processException(e);
309             }
310             finally {
311                 closeSession(session);
312             }
313         }
314         else {
315             return (List<Phone>)result;
316         }
317     }
318 
319     public List<Phone> findByCompanyId(long companyId, int start, int end)
320         throws SystemException {
321         return findByCompanyId(companyId, start, end, null);
322     }
323 
324     public List<Phone> findByCompanyId(long companyId, int start, int end,
325         OrderByComparator obc) throws SystemException {
326         boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
327         String finderClassName = Phone.class.getName();
328         String finderMethodName = "findByCompanyId";
329         String[] finderParams = new String[] {
330                 Long.class.getName(),
331                 
332                 "java.lang.Integer", "java.lang.Integer",
333                 "com.liferay.portal.kernel.util.OrderByComparator"
334             };
335         Object[] finderArgs = new Object[] {
336                 new Long(companyId),
337                 
338                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
339             };
340 
341         Object result = null;
342 
343         if (finderClassNameCacheEnabled) {
344             result = FinderCacheUtil.getResult(finderClassName,
345                     finderMethodName, finderParams, finderArgs, this);
346         }
347 
348         if (result == null) {
349             Session session = null;
350 
351             try {
352                 session = openSession();
353 
354                 StringBuilder query = new StringBuilder();
355 
356                 query.append("FROM com.liferay.portal.model.Phone WHERE ");
357 
358                 query.append("companyId = ?");
359 
360                 query.append(" ");
361 
362                 if (obc != null) {
363                     query.append("ORDER BY ");
364                     query.append(obc.getOrderBy());
365                 }
366 
367                 else {
368                     query.append("ORDER BY ");
369 
370                     query.append("createDate ASC");
371                 }
372 
373                 Query q = session.createQuery(query.toString());
374 
375                 QueryPos qPos = QueryPos.getInstance(q);
376 
377                 qPos.add(companyId);
378 
379                 List<Phone> list = (List<Phone>)QueryUtil.list(q, getDialect(),
380                         start, end);
381 
382                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
383                     finderClassName, finderMethodName, finderParams,
384                     finderArgs, list);
385 
386                 return list;
387             }
388             catch (Exception e) {
389                 throw processException(e);
390             }
391             finally {
392                 closeSession(session);
393             }
394         }
395         else {
396             return (List<Phone>)result;
397         }
398     }
399 
400     public Phone findByCompanyId_First(long companyId, OrderByComparator obc)
401         throws NoSuchPhoneException, SystemException {
402         List<Phone> list = findByCompanyId(companyId, 0, 1, obc);
403 
404         if (list.size() == 0) {
405             StringBuilder msg = new StringBuilder();
406 
407             msg.append("No Phone exists with the key {");
408 
409             msg.append("companyId=" + companyId);
410 
411             msg.append(StringPool.CLOSE_CURLY_BRACE);
412 
413             throw new NoSuchPhoneException(msg.toString());
414         }
415         else {
416             return list.get(0);
417         }
418     }
419 
420     public Phone findByCompanyId_Last(long companyId, OrderByComparator obc)
421         throws NoSuchPhoneException, SystemException {
422         int count = countByCompanyId(companyId);
423 
424         List<Phone> list = findByCompanyId(companyId, count - 1, count, obc);
425 
426         if (list.size() == 0) {
427             StringBuilder msg = new StringBuilder();
428 
429             msg.append("No Phone exists with the key {");
430 
431             msg.append("companyId=" + companyId);
432 
433             msg.append(StringPool.CLOSE_CURLY_BRACE);
434 
435             throw new NoSuchPhoneException(msg.toString());
436         }
437         else {
438             return list.get(0);
439         }
440     }
441 
442     public Phone[] findByCompanyId_PrevAndNext(long phoneId, long companyId,
443         OrderByComparator obc) throws NoSuchPhoneException, SystemException {
444         Phone phone = findByPrimaryKey(phoneId);
445 
446         int count = countByCompanyId(companyId);
447 
448         Session session = null;
449 
450         try {
451             session = openSession();
452 
453             StringBuilder query = new StringBuilder();
454 
455             query.append("FROM com.liferay.portal.model.Phone WHERE ");
456 
457             query.append("companyId = ?");
458 
459             query.append(" ");
460 
461             if (obc != null) {
462                 query.append("ORDER BY ");
463                 query.append(obc.getOrderBy());
464             }
465 
466             else {
467                 query.append("ORDER BY ");
468 
469                 query.append("createDate ASC");
470             }
471 
472             Query q = session.createQuery(query.toString());
473 
474             QueryPos qPos = QueryPos.getInstance(q);
475 
476             qPos.add(companyId);
477 
478             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, phone);
479 
480             Phone[] array = new PhoneImpl[3];
481 
482             array[0] = (Phone)objArray[0];
483             array[1] = (Phone)objArray[1];
484             array[2] = (Phone)objArray[2];
485 
486             return array;
487         }
488         catch (Exception e) {
489             throw processException(e);
490         }
491         finally {
492             closeSession(session);
493         }
494     }
495 
496     public List<Phone> findByUserId(long userId) throws SystemException {
497         boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
498         String finderClassName = Phone.class.getName();
499         String finderMethodName = "findByUserId";
500         String[] finderParams = new String[] { Long.class.getName() };
501         Object[] finderArgs = new Object[] { new Long(userId) };
502 
503         Object result = null;
504 
505         if (finderClassNameCacheEnabled) {
506             result = FinderCacheUtil.getResult(finderClassName,
507                     finderMethodName, finderParams, finderArgs, this);
508         }
509 
510         if (result == null) {
511             Session session = null;
512 
513             try {
514                 session = openSession();
515 
516                 StringBuilder query = new StringBuilder();
517 
518                 query.append("FROM com.liferay.portal.model.Phone WHERE ");
519 
520                 query.append("userId = ?");
521 
522                 query.append(" ");
523 
524                 query.append("ORDER BY ");
525 
526                 query.append("createDate ASC");
527 
528                 Query q = session.createQuery(query.toString());
529 
530                 QueryPos qPos = QueryPos.getInstance(q);
531 
532                 qPos.add(userId);
533 
534                 List<Phone> list = q.list();
535 
536                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
537                     finderClassName, finderMethodName, finderParams,
538                     finderArgs, list);
539 
540                 return list;
541             }
542             catch (Exception e) {
543                 throw processException(e);
544             }
545             finally {
546                 closeSession(session);
547             }
548         }
549         else {
550             return (List<Phone>)result;
551         }
552     }
553 
554     public List<Phone> findByUserId(long userId, int start, int end)
555         throws SystemException {
556         return findByUserId(userId, start, end, null);
557     }
558 
559     public List<Phone> findByUserId(long userId, int start, int end,
560         OrderByComparator obc) throws SystemException {
561         boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
562         String finderClassName = Phone.class.getName();
563         String finderMethodName = "findByUserId";
564         String[] finderParams = new String[] {
565                 Long.class.getName(),
566                 
567                 "java.lang.Integer", "java.lang.Integer",
568                 "com.liferay.portal.kernel.util.OrderByComparator"
569             };
570         Object[] finderArgs = new Object[] {
571                 new Long(userId),
572                 
573                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
574             };
575 
576         Object result = null;
577 
578         if (finderClassNameCacheEnabled) {
579             result = FinderCacheUtil.getResult(finderClassName,
580                     finderMethodName, finderParams, finderArgs, this);
581         }
582 
583         if (result == null) {
584             Session session = null;
585 
586             try {
587                 session = openSession();
588 
589                 StringBuilder query = new StringBuilder();
590 
591                 query.append("FROM com.liferay.portal.model.Phone WHERE ");
592 
593                 query.append("userId = ?");
594 
595                 query.append(" ");
596 
597                 if (obc != null) {
598                     query.append("ORDER BY ");
599                     query.append(obc.getOrderBy());
600                 }
601 
602                 else {
603                     query.append("ORDER BY ");
604 
605                     query.append("createDate ASC");
606                 }
607 
608                 Query q = session.createQuery(query.toString());
609 
610                 QueryPos qPos = QueryPos.getInstance(q);
611 
612                 qPos.add(userId);
613 
614                 List<Phone> list = (List<Phone>)QueryUtil.list(q, getDialect(),
615                         start, end);
616 
617                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
618                     finderClassName, finderMethodName, finderParams,
619                     finderArgs, list);
620 
621                 return list;
622             }
623             catch (Exception e) {
624                 throw processException(e);
625             }
626             finally {
627                 closeSession(session);
628             }
629         }
630         else {
631             return (List<Phone>)result;
632         }
633     }
634 
635     public Phone findByUserId_First(long userId, OrderByComparator obc)
636         throws NoSuchPhoneException, SystemException {
637         List<Phone> list = findByUserId(userId, 0, 1, obc);
638 
639         if (list.size() == 0) {
640             StringBuilder msg = new StringBuilder();
641 
642             msg.append("No Phone exists with the key {");
643 
644             msg.append("userId=" + userId);
645 
646             msg.append(StringPool.CLOSE_CURLY_BRACE);
647 
648             throw new NoSuchPhoneException(msg.toString());
649         }
650         else {
651             return list.get(0);
652         }
653     }
654 
655     public Phone findByUserId_Last(long userId, OrderByComparator obc)
656         throws NoSuchPhoneException, SystemException {
657         int count = countByUserId(userId);
658 
659         List<Phone> list = findByUserId(userId, count - 1, count, obc);
660 
661         if (list.size() == 0) {
662             StringBuilder msg = new StringBuilder();
663 
664             msg.append("No Phone exists with the key {");
665 
666             msg.append("userId=" + userId);
667 
668             msg.append(StringPool.CLOSE_CURLY_BRACE);
669 
670             throw new NoSuchPhoneException(msg.toString());
671         }
672         else {
673             return list.get(0);
674         }
675     }
676 
677     public Phone[] findByUserId_PrevAndNext(long phoneId, long userId,
678         OrderByComparator obc) throws NoSuchPhoneException, SystemException {
679         Phone phone = findByPrimaryKey(phoneId);
680 
681         int count = countByUserId(userId);
682 
683         Session session = null;
684 
685         try {
686             session = openSession();
687 
688             StringBuilder query = new StringBuilder();
689 
690             query.append("FROM com.liferay.portal.model.Phone WHERE ");
691 
692             query.append("userId = ?");
693 
694             query.append(" ");
695 
696             if (obc != null) {
697                 query.append("ORDER BY ");
698                 query.append(obc.getOrderBy());
699             }
700 
701             else {
702                 query.append("ORDER BY ");
703 
704                 query.append("createDate ASC");
705             }
706 
707             Query q = session.createQuery(query.toString());
708 
709             QueryPos qPos = QueryPos.getInstance(q);
710 
711             qPos.add(userId);
712 
713             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, phone);
714 
715             Phone[] array = new PhoneImpl[3];
716 
717             array[0] = (Phone)objArray[0];
718             array[1] = (Phone)objArray[1];
719             array[2] = (Phone)objArray[2];
720 
721             return array;
722         }
723         catch (Exception e) {
724             throw processException(e);
725         }
726         finally {
727             closeSession(session);
728         }
729     }
730 
731     public List<Phone> findByC_C(long companyId, long classNameId)
732         throws SystemException {
733         boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
734         String finderClassName = Phone.class.getName();
735         String finderMethodName = "findByC_C";
736         String[] finderParams = new String[] {
737                 Long.class.getName(), Long.class.getName()
738             };
739         Object[] finderArgs = new Object[] {
740                 new Long(companyId), new Long(classNameId)
741             };
742 
743         Object result = null;
744 
745         if (finderClassNameCacheEnabled) {
746             result = FinderCacheUtil.getResult(finderClassName,
747                     finderMethodName, finderParams, finderArgs, this);
748         }
749 
750         if (result == null) {
751             Session session = null;
752 
753             try {
754                 session = openSession();
755 
756                 StringBuilder query = new StringBuilder();
757 
758                 query.append("FROM com.liferay.portal.model.Phone WHERE ");
759 
760                 query.append("companyId = ?");
761 
762                 query.append(" AND ");
763 
764                 query.append("classNameId = ?");
765 
766                 query.append(" ");
767 
768                 query.append("ORDER BY ");
769 
770                 query.append("createDate ASC");
771 
772                 Query q = session.createQuery(query.toString());
773 
774                 QueryPos qPos = QueryPos.getInstance(q);
775 
776                 qPos.add(companyId);
777 
778                 qPos.add(classNameId);
779 
780                 List<Phone> list = q.list();
781 
782                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
783                     finderClassName, finderMethodName, finderParams,
784                     finderArgs, list);
785 
786                 return list;
787             }
788             catch (Exception e) {
789                 throw processException(e);
790             }
791             finally {
792                 closeSession(session);
793             }
794         }
795         else {
796             return (List<Phone>)result;
797         }
798     }
799 
800     public List<Phone> findByC_C(long companyId, long classNameId, int start,
801         int end) throws SystemException {
802         return findByC_C(companyId, classNameId, start, end, null);
803     }
804 
805     public List<Phone> findByC_C(long companyId, long classNameId, int start,
806         int end, OrderByComparator obc) throws SystemException {
807         boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
808         String finderClassName = Phone.class.getName();
809         String finderMethodName = "findByC_C";
810         String[] finderParams = new String[] {
811                 Long.class.getName(), Long.class.getName(),
812                 
813                 "java.lang.Integer", "java.lang.Integer",
814                 "com.liferay.portal.kernel.util.OrderByComparator"
815             };
816         Object[] finderArgs = new Object[] {
817                 new Long(companyId), new Long(classNameId),
818                 
819                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
820             };
821 
822         Object result = null;
823 
824         if (finderClassNameCacheEnabled) {
825             result = FinderCacheUtil.getResult(finderClassName,
826                     finderMethodName, finderParams, finderArgs, this);
827         }
828 
829         if (result == null) {
830             Session session = null;
831 
832             try {
833                 session = openSession();
834 
835                 StringBuilder query = new StringBuilder();
836 
837                 query.append("FROM com.liferay.portal.model.Phone WHERE ");
838 
839                 query.append("companyId = ?");
840 
841                 query.append(" AND ");
842 
843                 query.append("classNameId = ?");
844 
845                 query.append(" ");
846 
847                 if (obc != null) {
848                     query.append("ORDER BY ");
849                     query.append(obc.getOrderBy());
850                 }
851 
852                 else {
853                     query.append("ORDER BY ");
854 
855                     query.append("createDate ASC");
856                 }
857 
858                 Query q = session.createQuery(query.toString());
859 
860                 QueryPos qPos = QueryPos.getInstance(q);
861 
862                 qPos.add(companyId);
863 
864                 qPos.add(classNameId);
865 
866                 List<Phone> list = (List<Phone>)QueryUtil.list(q, getDialect(),
867                         start, end);
868 
869                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
870                     finderClassName, finderMethodName, finderParams,
871                     finderArgs, list);
872 
873                 return list;
874             }
875             catch (Exception e) {
876                 throw processException(e);
877             }
878             finally {
879                 closeSession(session);
880             }
881         }
882         else {
883             return (List<Phone>)result;
884         }
885     }
886 
887     public Phone findByC_C_First(long companyId, long classNameId,
888         OrderByComparator obc) throws NoSuchPhoneException, SystemException {
889         List<Phone> list = findByC_C(companyId, classNameId, 0, 1, obc);
890 
891         if (list.size() == 0) {
892             StringBuilder msg = new StringBuilder();
893 
894             msg.append("No Phone exists with the key {");
895 
896             msg.append("companyId=" + companyId);
897 
898             msg.append(", ");
899             msg.append("classNameId=" + classNameId);
900 
901             msg.append(StringPool.CLOSE_CURLY_BRACE);
902 
903             throw new NoSuchPhoneException(msg.toString());
904         }
905         else {
906             return list.get(0);
907         }
908     }
909 
910     public Phone findByC_C_Last(long companyId, long classNameId,
911         OrderByComparator obc) throws NoSuchPhoneException, SystemException {
912         int count = countByC_C(companyId, classNameId);
913 
914         List<Phone> list = findByC_C(companyId, classNameId, count - 1, count,
915                 obc);
916 
917         if (list.size() == 0) {
918             StringBuilder msg = new StringBuilder();
919 
920             msg.append("No Phone exists with the key {");
921 
922             msg.append("companyId=" + companyId);
923 
924             msg.append(", ");
925             msg.append("classNameId=" + classNameId);
926 
927             msg.append(StringPool.CLOSE_CURLY_BRACE);
928 
929             throw new NoSuchPhoneException(msg.toString());
930         }
931         else {
932             return list.get(0);
933         }
934     }
935 
936     public Phone[] findByC_C_PrevAndNext(long phoneId, long companyId,
937         long classNameId, OrderByComparator obc)
938         throws NoSuchPhoneException, SystemException {
939         Phone phone = findByPrimaryKey(phoneId);
940 
941         int count = countByC_C(companyId, classNameId);
942 
943         Session session = null;
944 
945         try {
946             session = openSession();
947 
948             StringBuilder query = new StringBuilder();
949 
950             query.append("FROM com.liferay.portal.model.Phone WHERE ");
951 
952             query.append("companyId = ?");
953 
954             query.append(" AND ");
955 
956             query.append("classNameId = ?");
957 
958             query.append(" ");
959 
960             if (obc != null) {
961                 query.append("ORDER BY ");
962                 query.append(obc.getOrderBy());
963             }
964 
965             else {
966                 query.append("ORDER BY ");
967 
968                 query.append("createDate ASC");
969             }
970 
971             Query q = session.createQuery(query.toString());
972 
973             QueryPos qPos = QueryPos.getInstance(q);
974 
975             qPos.add(companyId);
976 
977             qPos.add(classNameId);
978 
979             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, phone);
980 
981             Phone[] array = new PhoneImpl[3];
982 
983             array[0] = (Phone)objArray[0];
984             array[1] = (Phone)objArray[1];
985             array[2] = (Phone)objArray[2];
986 
987             return array;
988         }
989         catch (Exception e) {
990             throw processException(e);
991         }
992         finally {
993             closeSession(session);
994         }
995     }
996 
997     public List<Phone> findByC_C_C(long companyId, long classNameId,
998         long classPK) throws SystemException {
999         boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1000        String finderClassName = Phone.class.getName();
1001        String finderMethodName = "findByC_C_C";
1002        String[] finderParams = new String[] {
1003                Long.class.getName(), Long.class.getName(), Long.class.getName()
1004            };
1005        Object[] finderArgs = new Object[] {
1006                new Long(companyId), new Long(classNameId), new Long(classPK)
1007            };
1008
1009        Object result = null;
1010
1011        if (finderClassNameCacheEnabled) {
1012            result = FinderCacheUtil.getResult(finderClassName,
1013                    finderMethodName, finderParams, finderArgs, this);
1014        }
1015
1016        if (result == null) {
1017            Session session = null;
1018
1019            try {
1020                session = openSession();
1021
1022                StringBuilder query = new StringBuilder();
1023
1024                query.append("FROM com.liferay.portal.model.Phone WHERE ");
1025
1026                query.append("companyId = ?");
1027
1028                query.append(" AND ");
1029
1030                query.append("classNameId = ?");
1031
1032                query.append(" AND ");
1033
1034                query.append("classPK = ?");
1035
1036                query.append(" ");
1037
1038                query.append("ORDER BY ");
1039
1040                query.append("createDate ASC");
1041
1042                Query q = session.createQuery(query.toString());
1043
1044                QueryPos qPos = QueryPos.getInstance(q);
1045
1046                qPos.add(companyId);
1047
1048                qPos.add(classNameId);
1049
1050                qPos.add(classPK);
1051
1052                List<Phone> list = q.list();
1053
1054                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1055                    finderClassName, finderMethodName, finderParams,
1056                    finderArgs, list);
1057
1058                return list;
1059            }
1060            catch (Exception e) {
1061                throw processException(e);
1062            }
1063            finally {
1064                closeSession(session);
1065            }
1066        }
1067        else {
1068            return (List<Phone>)result;
1069        }
1070    }
1071
1072    public List<Phone> findByC_C_C(long companyId, long classNameId,
1073        long classPK, int start, int end) throws SystemException {
1074        return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1075    }
1076
1077    public List<Phone> findByC_C_C(long companyId, long classNameId,
1078        long classPK, int start, int end, OrderByComparator obc)
1079        throws SystemException {
1080        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1081        String finderClassName = Phone.class.getName();
1082        String finderMethodName = "findByC_C_C";
1083        String[] finderParams = new String[] {
1084                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1085                
1086                "java.lang.Integer", "java.lang.Integer",
1087                "com.liferay.portal.kernel.util.OrderByComparator"
1088            };
1089        Object[] finderArgs = new Object[] {
1090                new Long(companyId), new Long(classNameId), new Long(classPK),
1091                
1092                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1093            };
1094
1095        Object result = null;
1096
1097        if (finderClassNameCacheEnabled) {
1098            result = FinderCacheUtil.getResult(finderClassName,
1099                    finderMethodName, finderParams, finderArgs, this);
1100        }
1101
1102        if (result == null) {
1103            Session session = null;
1104
1105            try {
1106                session = openSession();
1107
1108                StringBuilder query = new StringBuilder();
1109
1110                query.append("FROM com.liferay.portal.model.Phone WHERE ");
1111
1112                query.append("companyId = ?");
1113
1114                query.append(" AND ");
1115
1116                query.append("classNameId = ?");
1117
1118                query.append(" AND ");
1119
1120                query.append("classPK = ?");
1121
1122                query.append(" ");
1123
1124                if (obc != null) {
1125                    query.append("ORDER BY ");
1126                    query.append(obc.getOrderBy());
1127                }
1128
1129                else {
1130                    query.append("ORDER BY ");
1131
1132                    query.append("createDate ASC");
1133                }
1134
1135                Query q = session.createQuery(query.toString());
1136
1137                QueryPos qPos = QueryPos.getInstance(q);
1138
1139                qPos.add(companyId);
1140
1141                qPos.add(classNameId);
1142
1143                qPos.add(classPK);
1144
1145                List<Phone> list = (List<Phone>)QueryUtil.list(q, getDialect(),
1146                        start, end);
1147
1148                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1149                    finderClassName, finderMethodName, finderParams,
1150                    finderArgs, list);
1151
1152                return list;
1153            }
1154            catch (Exception e) {
1155                throw processException(e);
1156            }
1157            finally {
1158                closeSession(session);
1159            }
1160        }
1161        else {
1162            return (List<Phone>)result;
1163        }
1164    }
1165
1166    public Phone findByC_C_C_First(long companyId, long classNameId,
1167        long classPK, OrderByComparator obc)
1168        throws NoSuchPhoneException, SystemException {
1169        List<Phone> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
1170                obc);
1171
1172        if (list.size() == 0) {
1173            StringBuilder msg = new StringBuilder();
1174
1175            msg.append("No Phone exists with the key {");
1176
1177            msg.append("companyId=" + companyId);
1178
1179            msg.append(", ");
1180            msg.append("classNameId=" + classNameId);
1181
1182            msg.append(", ");
1183            msg.append("classPK=" + classPK);
1184
1185            msg.append(StringPool.CLOSE_CURLY_BRACE);
1186
1187            throw new NoSuchPhoneException(msg.toString());
1188        }
1189        else {
1190            return list.get(0);
1191        }
1192    }
1193
1194    public Phone findByC_C_C_Last(long companyId, long classNameId,
1195        long classPK, OrderByComparator obc)
1196        throws NoSuchPhoneException, SystemException {
1197        int count = countByC_C_C(companyId, classNameId, classPK);
1198
1199        List<Phone> list = findByC_C_C(companyId, classNameId, classPK,
1200                count - 1, count, obc);
1201
1202        if (list.size() == 0) {
1203            StringBuilder msg = new StringBuilder();
1204
1205            msg.append("No Phone exists with the key {");
1206
1207            msg.append("companyId=" + companyId);
1208
1209            msg.append(", ");
1210            msg.append("classNameId=" + classNameId);
1211
1212            msg.append(", ");
1213            msg.append("classPK=" + classPK);
1214
1215            msg.append(StringPool.CLOSE_CURLY_BRACE);
1216
1217            throw new NoSuchPhoneException(msg.toString());
1218        }
1219        else {
1220            return list.get(0);
1221        }
1222    }
1223
1224    public Phone[] findByC_C_C_PrevAndNext(long phoneId, long companyId,
1225        long classNameId, long classPK, OrderByComparator obc)
1226        throws NoSuchPhoneException, SystemException {
1227        Phone phone = findByPrimaryKey(phoneId);
1228
1229        int count = countByC_C_C(companyId, classNameId, classPK);
1230
1231        Session session = null;
1232
1233        try {
1234            session = openSession();
1235
1236            StringBuilder query = new StringBuilder();
1237
1238            query.append("FROM com.liferay.portal.model.Phone WHERE ");
1239
1240            query.append("companyId = ?");
1241
1242            query.append(" AND ");
1243
1244            query.append("classNameId = ?");
1245
1246            query.append(" AND ");
1247
1248            query.append("classPK = ?");
1249
1250            query.append(" ");
1251
1252            if (obc != null) {
1253                query.append("ORDER BY ");
1254                query.append(obc.getOrderBy());
1255            }
1256
1257            else {
1258                query.append("ORDER BY ");
1259
1260                query.append("createDate ASC");
1261            }
1262
1263            Query q = session.createQuery(query.toString());
1264
1265            QueryPos qPos = QueryPos.getInstance(q);
1266
1267            qPos.add(companyId);
1268
1269            qPos.add(classNameId);
1270
1271            qPos.add(classPK);
1272
1273            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, phone);
1274
1275            Phone[] array = new PhoneImpl[3];
1276
1277            array[0] = (Phone)objArray[0];
1278            array[1] = (Phone)objArray[1];
1279            array[2] = (Phone)objArray[2];
1280
1281            return array;
1282        }
1283        catch (Exception e) {
1284            throw processException(e);
1285        }
1286        finally {
1287            closeSession(session);
1288        }
1289    }
1290
1291    public List<Phone> findByC_C_C_P(long companyId, long classNameId,
1292        long classPK, boolean primary) throws SystemException {
1293        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1294        String finderClassName = Phone.class.getName();
1295        String finderMethodName = "findByC_C_C_P";
1296        String[] finderParams = new String[] {
1297                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1298                Boolean.class.getName()
1299            };
1300        Object[] finderArgs = new Object[] {
1301                new Long(companyId), new Long(classNameId), new Long(classPK),
1302                Boolean.valueOf(primary)
1303            };
1304
1305        Object result = null;
1306
1307        if (finderClassNameCacheEnabled) {
1308            result = FinderCacheUtil.getResult(finderClassName,
1309                    finderMethodName, finderParams, finderArgs, this);
1310        }
1311
1312        if (result == null) {
1313            Session session = null;
1314
1315            try {
1316                session = openSession();
1317
1318                StringBuilder query = new StringBuilder();
1319
1320                query.append("FROM com.liferay.portal.model.Phone WHERE ");
1321
1322                query.append("companyId = ?");
1323
1324                query.append(" AND ");
1325
1326                query.append("classNameId = ?");
1327
1328                query.append(" AND ");
1329
1330                query.append("classPK = ?");
1331
1332                query.append(" AND ");
1333
1334                query.append("primary_ = ?");
1335
1336                query.append(" ");
1337
1338                query.append("ORDER BY ");
1339
1340                query.append("createDate ASC");
1341
1342                Query q = session.createQuery(query.toString());
1343
1344                QueryPos qPos = QueryPos.getInstance(q);
1345
1346                qPos.add(companyId);
1347
1348                qPos.add(classNameId);
1349
1350                qPos.add(classPK);
1351
1352                qPos.add(primary);
1353
1354                List<Phone> list = q.list();
1355
1356                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1357                    finderClassName, finderMethodName, finderParams,
1358                    finderArgs, list);
1359
1360                return list;
1361            }
1362            catch (Exception e) {
1363                throw processException(e);
1364            }
1365            finally {
1366                closeSession(session);
1367            }
1368        }
1369        else {
1370            return (List<Phone>)result;
1371        }
1372    }
1373
1374    public List<Phone> findByC_C_C_P(long companyId, long classNameId,
1375        long classPK, boolean primary, int start, int end)
1376        throws SystemException {
1377        return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
1378            end, null);
1379    }
1380
1381    public List<Phone> findByC_C_C_P(long companyId, long classNameId,
1382        long classPK, boolean primary, int start, int end, OrderByComparator obc)
1383        throws SystemException {
1384        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1385        String finderClassName = Phone.class.getName();
1386        String finderMethodName = "findByC_C_C_P";
1387        String[] finderParams = new String[] {
1388                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1389                Boolean.class.getName(),
1390                
1391                "java.lang.Integer", "java.lang.Integer",
1392                "com.liferay.portal.kernel.util.OrderByComparator"
1393            };
1394        Object[] finderArgs = new Object[] {
1395                new Long(companyId), new Long(classNameId), new Long(classPK),
1396                Boolean.valueOf(primary),
1397                
1398                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1399            };
1400
1401        Object result = null;
1402
1403        if (finderClassNameCacheEnabled) {
1404            result = FinderCacheUtil.getResult(finderClassName,
1405                    finderMethodName, finderParams, finderArgs, this);
1406        }
1407
1408        if (result == null) {
1409            Session session = null;
1410
1411            try {
1412                session = openSession();
1413
1414                StringBuilder query = new StringBuilder();
1415
1416                query.append("FROM com.liferay.portal.model.Phone WHERE ");
1417
1418                query.append("companyId = ?");
1419
1420                query.append(" AND ");
1421
1422                query.append("classNameId = ?");
1423
1424                query.append(" AND ");
1425
1426                query.append("classPK = ?");
1427
1428                query.append(" AND ");
1429
1430                query.append("primary_ = ?");
1431
1432                query.append(" ");
1433
1434                if (obc != null) {
1435                    query.append("ORDER BY ");
1436                    query.append(obc.getOrderBy());
1437                }
1438
1439                else {
1440                    query.append("ORDER BY ");
1441
1442                    query.append("createDate ASC");
1443                }
1444
1445                Query q = session.createQuery(query.toString());
1446
1447                QueryPos qPos = QueryPos.getInstance(q);
1448
1449                qPos.add(companyId);
1450
1451                qPos.add(classNameId);
1452
1453                qPos.add(classPK);
1454
1455                qPos.add(primary);
1456
1457                List<Phone> list = (List<Phone>)QueryUtil.list(q, getDialect(),
1458                        start, end);
1459
1460                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1461                    finderClassName, finderMethodName, finderParams,
1462                    finderArgs, list);
1463
1464                return list;
1465            }
1466            catch (Exception e) {
1467                throw processException(e);
1468            }
1469            finally {
1470                closeSession(session);
1471            }
1472        }
1473        else {
1474            return (List<Phone>)result;
1475        }
1476    }
1477
1478    public Phone findByC_C_C_P_First(long companyId, long classNameId,
1479        long classPK, boolean primary, OrderByComparator obc)
1480        throws NoSuchPhoneException, SystemException {
1481        List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
1482                primary, 0, 1, obc);
1483
1484        if (list.size() == 0) {
1485            StringBuilder msg = new StringBuilder();
1486
1487            msg.append("No Phone exists with the key {");
1488
1489            msg.append("companyId=" + companyId);
1490
1491            msg.append(", ");
1492            msg.append("classNameId=" + classNameId);
1493
1494            msg.append(", ");
1495            msg.append("classPK=" + classPK);
1496
1497            msg.append(", ");
1498            msg.append("primary=" + primary);
1499
1500            msg.append(StringPool.CLOSE_CURLY_BRACE);
1501
1502            throw new NoSuchPhoneException(msg.toString());
1503        }
1504        else {
1505            return list.get(0);
1506        }
1507    }
1508
1509    public Phone findByC_C_C_P_Last(long companyId, long classNameId,
1510        long classPK, boolean primary, OrderByComparator obc)
1511        throws NoSuchPhoneException, SystemException {
1512        int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
1513
1514        List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
1515                primary, count - 1, count, obc);
1516
1517        if (list.size() == 0) {
1518            StringBuilder msg = new StringBuilder();
1519
1520            msg.append("No Phone exists with the key {");
1521
1522            msg.append("companyId=" + companyId);
1523
1524            msg.append(", ");
1525            msg.append("classNameId=" + classNameId);
1526
1527            msg.append(", ");
1528            msg.append("classPK=" + classPK);
1529
1530            msg.append(", ");
1531            msg.append("primary=" + primary);
1532
1533            msg.append(StringPool.CLOSE_CURLY_BRACE);
1534
1535            throw new NoSuchPhoneException(msg.toString());
1536        }
1537        else {
1538            return list.get(0);
1539        }
1540    }
1541
1542    public Phone[] findByC_C_C_P_PrevAndNext(long phoneId, long companyId,
1543        long classNameId, long classPK, boolean primary, OrderByComparator obc)
1544        throws NoSuchPhoneException, SystemException {
1545        Phone phone = findByPrimaryKey(phoneId);
1546
1547        int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
1548
1549        Session session = null;
1550
1551        try {
1552            session = openSession();
1553
1554            StringBuilder query = new StringBuilder();
1555
1556            query.append("FROM com.liferay.portal.model.Phone WHERE ");
1557
1558            query.append("companyId = ?");
1559
1560            query.append(" AND ");
1561
1562            query.append("classNameId = ?");
1563
1564            query.append(" AND ");
1565
1566            query.append("classPK = ?");
1567
1568            query.append(" AND ");
1569
1570            query.append("primary_ = ?");
1571
1572            query.append(" ");
1573
1574            if (obc != null) {
1575                query.append("ORDER BY ");
1576                query.append(obc.getOrderBy());
1577            }
1578
1579            else {
1580                query.append("ORDER BY ");
1581
1582                query.append("createDate ASC");
1583            }
1584
1585            Query q = session.createQuery(query.toString());
1586
1587            QueryPos qPos = QueryPos.getInstance(q);
1588
1589            qPos.add(companyId);
1590
1591            qPos.add(classNameId);
1592
1593            qPos.add(classPK);
1594
1595            qPos.add(primary);
1596
1597            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, phone);
1598
1599            Phone[] array = new PhoneImpl[3];
1600
1601            array[0] = (Phone)objArray[0];
1602            array[1] = (Phone)objArray[1];
1603            array[2] = (Phone)objArray[2];
1604
1605            return array;
1606        }
1607        catch (Exception e) {
1608            throw processException(e);
1609        }
1610        finally {
1611            closeSession(session);
1612        }
1613    }
1614
1615    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1616        throws SystemException {
1617        Session session = null;
1618
1619        try {
1620            session = openSession();
1621
1622            dynamicQuery.compile(session);
1623
1624            return dynamicQuery.list();
1625        }
1626        catch (Exception e) {
1627            throw processException(e);
1628        }
1629        finally {
1630            closeSession(session);
1631        }
1632    }
1633
1634    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1635        int start, int end) throws SystemException {
1636        Session session = null;
1637
1638        try {
1639            session = openSession();
1640
1641            dynamicQuery.setLimit(start, end);
1642
1643            dynamicQuery.compile(session);
1644
1645            return dynamicQuery.list();
1646        }
1647        catch (Exception e) {
1648            throw processException(e);
1649        }
1650        finally {
1651            closeSession(session);
1652        }
1653    }
1654
1655    public List<Phone> findAll() throws SystemException {
1656        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1657    }
1658
1659    public List<Phone> findAll(int start, int end) throws SystemException {
1660        return findAll(start, end, null);
1661    }
1662
1663    public List<Phone> findAll(int start, int end, OrderByComparator obc)
1664        throws SystemException {
1665        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1666        String finderClassName = Phone.class.getName();
1667        String finderMethodName = "findAll";
1668        String[] finderParams = new String[] {
1669                "java.lang.Integer", "java.lang.Integer",
1670                "com.liferay.portal.kernel.util.OrderByComparator"
1671            };
1672        Object[] finderArgs = new Object[] {
1673                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1674            };
1675
1676        Object result = null;
1677
1678        if (finderClassNameCacheEnabled) {
1679            result = FinderCacheUtil.getResult(finderClassName,
1680                    finderMethodName, finderParams, finderArgs, this);
1681        }
1682
1683        if (result == null) {
1684            Session session = null;
1685
1686            try {
1687                session = openSession();
1688
1689                StringBuilder query = new StringBuilder();
1690
1691                query.append("FROM com.liferay.portal.model.Phone ");
1692
1693                if (obc != null) {
1694                    query.append("ORDER BY ");
1695                    query.append(obc.getOrderBy());
1696                }
1697
1698                else {
1699                    query.append("ORDER BY ");
1700
1701                    query.append("createDate ASC");
1702                }
1703
1704                Query q = session.createQuery(query.toString());
1705
1706                List<Phone> list = (List<Phone>)QueryUtil.list(q, getDialect(),
1707                        start, end);
1708
1709                if (obc == null) {
1710                    Collections.sort(list);
1711                }
1712
1713                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1714                    finderClassName, finderMethodName, finderParams,
1715                    finderArgs, list);
1716
1717                return list;
1718            }
1719            catch (Exception e) {
1720                throw processException(e);
1721            }
1722            finally {
1723                closeSession(session);
1724            }
1725        }
1726        else {
1727            return (List<Phone>)result;
1728        }
1729    }
1730
1731    public void removeByCompanyId(long companyId) throws SystemException {
1732        for (Phone phone : findByCompanyId(companyId)) {
1733            remove(phone);
1734        }
1735    }
1736
1737    public void removeByUserId(long userId) throws SystemException {
1738        for (Phone phone : findByUserId(userId)) {
1739            remove(phone);
1740        }
1741    }
1742
1743    public void removeByC_C(long companyId, long classNameId)
1744        throws SystemException {
1745        for (Phone phone : findByC_C(companyId, classNameId)) {
1746            remove(phone);
1747        }
1748    }
1749
1750    public void removeByC_C_C(long companyId, long classNameId, long classPK)
1751        throws SystemException {
1752        for (Phone phone : findByC_C_C(companyId, classNameId, classPK)) {
1753            remove(phone);
1754        }
1755    }
1756
1757    public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
1758        boolean primary) throws SystemException {
1759        for (Phone phone : findByC_C_C_P(companyId, classNameId, classPK,
1760                primary)) {
1761            remove(phone);
1762        }
1763    }
1764
1765    public void removeAll() throws SystemException {
1766        for (Phone phone : findAll()) {
1767            remove(phone);
1768        }
1769    }
1770
1771    public int countByCompanyId(long companyId) throws SystemException {
1772        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1773        String finderClassName = Phone.class.getName();
1774        String finderMethodName = "countByCompanyId";
1775        String[] finderParams = new String[] { Long.class.getName() };
1776        Object[] finderArgs = new Object[] { new Long(companyId) };
1777
1778        Object result = null;
1779
1780        if (finderClassNameCacheEnabled) {
1781            result = FinderCacheUtil.getResult(finderClassName,
1782                    finderMethodName, finderParams, finderArgs, this);
1783        }
1784
1785        if (result == null) {
1786            Session session = null;
1787
1788            try {
1789                session = openSession();
1790
1791                StringBuilder query = new StringBuilder();
1792
1793                query.append("SELECT COUNT(*) ");
1794                query.append("FROM com.liferay.portal.model.Phone WHERE ");
1795
1796                query.append("companyId = ?");
1797
1798                query.append(" ");
1799
1800                Query q = session.createQuery(query.toString());
1801
1802                QueryPos qPos = QueryPos.getInstance(q);
1803
1804                qPos.add(companyId);
1805
1806                Long count = null;
1807
1808                Iterator<Long> itr = q.list().iterator();
1809
1810                if (itr.hasNext()) {
1811                    count = itr.next();
1812                }
1813
1814                if (count == null) {
1815                    count = new Long(0);
1816                }
1817
1818                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1819                    finderClassName, finderMethodName, finderParams,
1820                    finderArgs, count);
1821
1822                return count.intValue();
1823            }
1824            catch (Exception e) {
1825                throw processException(e);
1826            }
1827            finally {
1828                closeSession(session);
1829            }
1830        }
1831        else {
1832            return ((Long)result).intValue();
1833        }
1834    }
1835
1836    public int countByUserId(long userId) throws SystemException {
1837        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1838        String finderClassName = Phone.class.getName();
1839        String finderMethodName = "countByUserId";
1840        String[] finderParams = new String[] { Long.class.getName() };
1841        Object[] finderArgs = new Object[] { new Long(userId) };
1842
1843        Object result = null;
1844
1845        if (finderClassNameCacheEnabled) {
1846            result = FinderCacheUtil.getResult(finderClassName,
1847                    finderMethodName, finderParams, finderArgs, this);
1848        }
1849
1850        if (result == null) {
1851            Session session = null;
1852
1853            try {
1854                session = openSession();
1855
1856                StringBuilder query = new StringBuilder();
1857
1858                query.append("SELECT COUNT(*) ");
1859                query.append("FROM com.liferay.portal.model.Phone WHERE ");
1860
1861                query.append("userId = ?");
1862
1863                query.append(" ");
1864
1865                Query q = session.createQuery(query.toString());
1866
1867                QueryPos qPos = QueryPos.getInstance(q);
1868
1869                qPos.add(userId);
1870
1871                Long count = null;
1872
1873                Iterator<Long> itr = q.list().iterator();
1874
1875                if (itr.hasNext()) {
1876                    count = itr.next();
1877                }
1878
1879                if (count == null) {
1880                    count = new Long(0);
1881                }
1882
1883                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1884                    finderClassName, finderMethodName, finderParams,
1885                    finderArgs, count);
1886
1887                return count.intValue();
1888            }
1889            catch (Exception e) {
1890                throw processException(e);
1891            }
1892            finally {
1893                closeSession(session);
1894            }
1895        }
1896        else {
1897            return ((Long)result).intValue();
1898        }
1899    }
1900
1901    public int countByC_C(long companyId, long classNameId)
1902        throws SystemException {
1903        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1904        String finderClassName = Phone.class.getName();
1905        String finderMethodName = "countByC_C";
1906        String[] finderParams = new String[] {
1907                Long.class.getName(), Long.class.getName()
1908            };
1909        Object[] finderArgs = new Object[] {
1910                new Long(companyId), new Long(classNameId)
1911            };
1912
1913        Object result = null;
1914
1915        if (finderClassNameCacheEnabled) {
1916            result = FinderCacheUtil.getResult(finderClassName,
1917                    finderMethodName, finderParams, finderArgs, this);
1918        }
1919
1920        if (result == null) {
1921            Session session = null;
1922
1923            try {
1924                session = openSession();
1925
1926                StringBuilder query = new StringBuilder();
1927
1928                query.append("SELECT COUNT(*) ");
1929                query.append("FROM com.liferay.portal.model.Phone WHERE ");
1930
1931                query.append("companyId = ?");
1932
1933                query.append(" AND ");
1934
1935                query.append("classNameId = ?");
1936
1937                query.append(" ");
1938
1939                Query q = session.createQuery(query.toString());
1940
1941                QueryPos qPos = QueryPos.getInstance(q);
1942
1943                qPos.add(companyId);
1944
1945                qPos.add(classNameId);
1946
1947                Long count = null;
1948
1949                Iterator<Long> itr = q.list().iterator();
1950
1951                if (itr.hasNext()) {
1952                    count = itr.next();
1953                }
1954
1955                if (count == null) {
1956                    count = new Long(0);
1957                }
1958
1959                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1960                    finderClassName, finderMethodName, finderParams,
1961                    finderArgs, count);
1962
1963                return count.intValue();
1964            }
1965            catch (Exception e) {
1966                throw processException(e);
1967            }
1968            finally {
1969                closeSession(session);
1970            }
1971        }
1972        else {
1973            return ((Long)result).intValue();
1974        }
1975    }
1976
1977    public int countByC_C_C(long companyId, long classNameId, long classPK)
1978        throws SystemException {
1979        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
1980        String finderClassName = Phone.class.getName();
1981        String finderMethodName = "countByC_C_C";
1982        String[] finderParams = new String[] {
1983                Long.class.getName(), Long.class.getName(), Long.class.getName()
1984            };
1985        Object[] finderArgs = new Object[] {
1986                new Long(companyId), new Long(classNameId), new Long(classPK)
1987            };
1988
1989        Object result = null;
1990
1991        if (finderClassNameCacheEnabled) {
1992            result = FinderCacheUtil.getResult(finderClassName,
1993                    finderMethodName, finderParams, finderArgs, this);
1994        }
1995
1996        if (result == null) {
1997            Session session = null;
1998
1999            try {
2000                session = openSession();
2001
2002                StringBuilder query = new StringBuilder();
2003
2004                query.append("SELECT COUNT(*) ");
2005                query.append("FROM com.liferay.portal.model.Phone WHERE ");
2006
2007                query.append("companyId = ?");
2008
2009                query.append(" AND ");
2010
2011                query.append("classNameId = ?");
2012
2013                query.append(" AND ");
2014
2015                query.append("classPK = ?");
2016
2017                query.append(" ");
2018
2019                Query q = session.createQuery(query.toString());
2020
2021                QueryPos qPos = QueryPos.getInstance(q);
2022
2023                qPos.add(companyId);
2024
2025                qPos.add(classNameId);
2026
2027                qPos.add(classPK);
2028
2029                Long count = null;
2030
2031                Iterator<Long> itr = q.list().iterator();
2032
2033                if (itr.hasNext()) {
2034                    count = itr.next();
2035                }
2036
2037                if (count == null) {
2038                    count = new Long(0);
2039                }
2040
2041                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2042                    finderClassName, finderMethodName, finderParams,
2043                    finderArgs, count);
2044
2045                return count.intValue();
2046            }
2047            catch (Exception e) {
2048                throw processException(e);
2049            }
2050            finally {
2051                closeSession(session);
2052            }
2053        }
2054        else {
2055            return ((Long)result).intValue();
2056        }
2057    }
2058
2059    public int countByC_C_C_P(long companyId, long classNameId, long classPK,
2060        boolean primary) throws SystemException {
2061        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
2062        String finderClassName = Phone.class.getName();
2063        String finderMethodName = "countByC_C_C_P";
2064        String[] finderParams = new String[] {
2065                Long.class.getName(), Long.class.getName(), Long.class.getName(),
2066                Boolean.class.getName()
2067            };
2068        Object[] finderArgs = new Object[] {
2069                new Long(companyId), new Long(classNameId), new Long(classPK),
2070                Boolean.valueOf(primary)
2071            };
2072
2073        Object result = null;
2074
2075        if (finderClassNameCacheEnabled) {
2076            result = FinderCacheUtil.getResult(finderClassName,
2077                    finderMethodName, finderParams, finderArgs, this);
2078        }
2079
2080        if (result == null) {
2081            Session session = null;
2082
2083            try {
2084                session = openSession();
2085
2086                StringBuilder query = new StringBuilder();
2087
2088                query.append("SELECT COUNT(*) ");
2089                query.append("FROM com.liferay.portal.model.Phone WHERE ");
2090
2091                query.append("companyId = ?");
2092
2093                query.append(" AND ");
2094
2095                query.append("classNameId = ?");
2096
2097                query.append(" AND ");
2098
2099                query.append("classPK = ?");
2100
2101                query.append(" AND ");
2102
2103                query.append("primary_ = ?");
2104
2105                query.append(" ");
2106
2107                Query q = session.createQuery(query.toString());
2108
2109                QueryPos qPos = QueryPos.getInstance(q);
2110
2111                qPos.add(companyId);
2112
2113                qPos.add(classNameId);
2114
2115                qPos.add(classPK);
2116
2117                qPos.add(primary);
2118
2119                Long count = null;
2120
2121                Iterator<Long> itr = q.list().iterator();
2122
2123                if (itr.hasNext()) {
2124                    count = itr.next();
2125                }
2126
2127                if (count == null) {
2128                    count = new Long(0);
2129                }
2130
2131                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2132                    finderClassName, finderMethodName, finderParams,
2133                    finderArgs, count);
2134
2135                return count.intValue();
2136            }
2137            catch (Exception e) {
2138                throw processException(e);
2139            }
2140            finally {
2141                closeSession(session);
2142            }
2143        }
2144        else {
2145            return ((Long)result).intValue();
2146        }
2147    }
2148
2149    public int countAll() throws SystemException {
2150        boolean finderClassNameCacheEnabled = PhoneModelImpl.CACHE_ENABLED;
2151        String finderClassName = Phone.class.getName();
2152        String finderMethodName = "countAll";
2153        String[] finderParams = new String[] {  };
2154        Object[] finderArgs = new Object[] {  };
2155
2156        Object result = null;
2157
2158        if (finderClassNameCacheEnabled) {
2159            result = FinderCacheUtil.getResult(finderClassName,
2160                    finderMethodName, finderParams, finderArgs, this);
2161        }
2162
2163        if (result == null) {
2164            Session session = null;
2165
2166            try {
2167                session = openSession();
2168
2169                Query q = session.createQuery(
2170                        "SELECT COUNT(*) FROM com.liferay.portal.model.Phone");
2171
2172                Long count = null;
2173
2174                Iterator<Long> itr = q.list().iterator();
2175
2176                if (itr.hasNext()) {
2177                    count = itr.next();
2178                }
2179
2180                if (count == null) {
2181                    count = new Long(0);
2182                }
2183
2184                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2185                    finderClassName, finderMethodName, finderParams,
2186                    finderArgs, count);
2187
2188                return count.intValue();
2189            }
2190            catch (Exception e) {
2191                throw processException(e);
2192            }
2193            finally {
2194                closeSession(session);
2195            }
2196        }
2197        else {
2198            return ((Long)result).intValue();
2199        }
2200    }
2201
2202    public void registerListener(ModelListener listener) {
2203        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2204
2205        listeners.add(listener);
2206
2207        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2208    }
2209
2210    public void unregisterListener(ModelListener listener) {
2211        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2212
2213        listeners.remove(listener);
2214
2215        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2216    }
2217
2218    public void afterPropertiesSet() {
2219        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2220                    com.liferay.portal.util.PropsUtil.get(
2221                        "value.object.listener.com.liferay.portal.model.Phone")));
2222
2223        if (listenerClassNames.length > 0) {
2224            try {
2225                List<ModelListener> listeners = new ArrayList<ModelListener>();
2226
2227                for (String listenerClassName : listenerClassNames) {
2228                    listeners.add((ModelListener)Class.forName(
2229                            listenerClassName).newInstance());
2230                }
2231
2232                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2233            }
2234            catch (Exception e) {
2235                _log.error(e);
2236            }
2237        }
2238    }
2239
2240    private static Log _log = LogFactory.getLog(PhonePersistenceImpl.class);
2241    private ModelListener[] _listeners = new ModelListener[0];
2242}