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