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