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