001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchPhoneException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.model.Phone;
039 import com.liferay.portal.model.impl.PhoneImpl;
040 import com.liferay.portal.model.impl.PhoneModelImpl;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import java.io.Serializable;
044
045 import java.util.ArrayList;
046 import java.util.Collections;
047 import java.util.List;
048
049
061 public class PhonePersistenceImpl extends BasePersistenceImpl<Phone>
062 implements PhonePersistence {
063
068 public static final String FINDER_CLASS_NAME_ENTITY = PhoneImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070 ".List1";
071 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List2";
073 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
074 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
075 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
077 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
078 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
080 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
082 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
083 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
084 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
085 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
086 new String[] {
087 Long.class.getName(),
088
089 Integer.class.getName(), Integer.class.getName(),
090 OrderByComparator.class.getName()
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
093 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
094 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
096 new String[] { Long.class.getName() },
097 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
098 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
099 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
100 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
102 new String[] { Long.class.getName() });
103
104
111 public List<Phone> findByCompanyId(long companyId)
112 throws SystemException {
113 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
114 null);
115 }
116
117
130 public List<Phone> findByCompanyId(long companyId, int start, int end)
131 throws SystemException {
132 return findByCompanyId(companyId, start, end, null);
133 }
134
135
149 public List<Phone> findByCompanyId(long companyId, int start, int end,
150 OrderByComparator orderByComparator) throws SystemException {
151 boolean pagination = true;
152 FinderPath finderPath = null;
153 Object[] finderArgs = null;
154
155 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156 (orderByComparator == null)) {
157 pagination = false;
158 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
159 finderArgs = new Object[] { companyId };
160 }
161 else {
162 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
163 finderArgs = new Object[] { companyId, start, end, orderByComparator };
164 }
165
166 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
167 finderArgs, this);
168
169 if ((list != null) && !list.isEmpty()) {
170 for (Phone phone : list) {
171 if ((companyId != phone.getCompanyId())) {
172 list = null;
173
174 break;
175 }
176 }
177 }
178
179 if (list == null) {
180 StringBundler query = null;
181
182 if (orderByComparator != null) {
183 query = new StringBundler(3 +
184 (orderByComparator.getOrderByFields().length * 3));
185 }
186 else {
187 query = new StringBundler(3);
188 }
189
190 query.append(_SQL_SELECT_PHONE_WHERE);
191
192 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
193
194 if (orderByComparator != null) {
195 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
196 orderByComparator);
197 }
198 else
199 if (pagination) {
200 query.append(PhoneModelImpl.ORDER_BY_JPQL);
201 }
202
203 String sql = query.toString();
204
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 Query q = session.createQuery(sql);
211
212 QueryPos qPos = QueryPos.getInstance(q);
213
214 qPos.add(companyId);
215
216 if (!pagination) {
217 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
218 end, false);
219
220 Collections.sort(list);
221
222 list = new UnmodifiableList<Phone>(list);
223 }
224 else {
225 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
226 end);
227 }
228
229 cacheResult(list);
230
231 FinderCacheUtil.putResult(finderPath, finderArgs, list);
232 }
233 catch (Exception e) {
234 FinderCacheUtil.removeResult(finderPath, finderArgs);
235
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240 }
241 }
242
243 return list;
244 }
245
246
255 public Phone findByCompanyId_First(long companyId,
256 OrderByComparator orderByComparator)
257 throws NoSuchPhoneException, SystemException {
258 Phone phone = fetchByCompanyId_First(companyId, orderByComparator);
259
260 if (phone != null) {
261 return phone;
262 }
263
264 StringBundler msg = new StringBundler(4);
265
266 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
267
268 msg.append("companyId=");
269 msg.append(companyId);
270
271 msg.append(StringPool.CLOSE_CURLY_BRACE);
272
273 throw new NoSuchPhoneException(msg.toString());
274 }
275
276
284 public Phone fetchByCompanyId_First(long companyId,
285 OrderByComparator orderByComparator) throws SystemException {
286 List<Phone> list = findByCompanyId(companyId, 0, 1, orderByComparator);
287
288 if (!list.isEmpty()) {
289 return list.get(0);
290 }
291
292 return null;
293 }
294
295
304 public Phone findByCompanyId_Last(long companyId,
305 OrderByComparator orderByComparator)
306 throws NoSuchPhoneException, SystemException {
307 Phone phone = fetchByCompanyId_Last(companyId, orderByComparator);
308
309 if (phone != null) {
310 return phone;
311 }
312
313 StringBundler msg = new StringBundler(4);
314
315 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
316
317 msg.append("companyId=");
318 msg.append(companyId);
319
320 msg.append(StringPool.CLOSE_CURLY_BRACE);
321
322 throw new NoSuchPhoneException(msg.toString());
323 }
324
325
333 public Phone fetchByCompanyId_Last(long companyId,
334 OrderByComparator orderByComparator) throws SystemException {
335 int count = countByCompanyId(companyId);
336
337 List<Phone> list = findByCompanyId(companyId, count - 1, count,
338 orderByComparator);
339
340 if (!list.isEmpty()) {
341 return list.get(0);
342 }
343
344 return null;
345 }
346
347
357 public Phone[] findByCompanyId_PrevAndNext(long phoneId, long companyId,
358 OrderByComparator orderByComparator)
359 throws NoSuchPhoneException, SystemException {
360 Phone phone = findByPrimaryKey(phoneId);
361
362 Session session = null;
363
364 try {
365 session = openSession();
366
367 Phone[] array = new PhoneImpl[3];
368
369 array[0] = getByCompanyId_PrevAndNext(session, phone, companyId,
370 orderByComparator, true);
371
372 array[1] = phone;
373
374 array[2] = getByCompanyId_PrevAndNext(session, phone, companyId,
375 orderByComparator, false);
376
377 return array;
378 }
379 catch (Exception e) {
380 throw processException(e);
381 }
382 finally {
383 closeSession(session);
384 }
385 }
386
387 protected Phone getByCompanyId_PrevAndNext(Session session, Phone phone,
388 long companyId, OrderByComparator orderByComparator, boolean previous) {
389 StringBundler query = null;
390
391 if (orderByComparator != null) {
392 query = new StringBundler(6 +
393 (orderByComparator.getOrderByFields().length * 6));
394 }
395 else {
396 query = new StringBundler(3);
397 }
398
399 query.append(_SQL_SELECT_PHONE_WHERE);
400
401 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
402
403 if (orderByComparator != null) {
404 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
405
406 if (orderByConditionFields.length > 0) {
407 query.append(WHERE_AND);
408 }
409
410 for (int i = 0; i < orderByConditionFields.length; i++) {
411 query.append(_ORDER_BY_ENTITY_ALIAS);
412 query.append(orderByConditionFields[i]);
413
414 if ((i + 1) < orderByConditionFields.length) {
415 if (orderByComparator.isAscending() ^ previous) {
416 query.append(WHERE_GREATER_THAN_HAS_NEXT);
417 }
418 else {
419 query.append(WHERE_LESSER_THAN_HAS_NEXT);
420 }
421 }
422 else {
423 if (orderByComparator.isAscending() ^ previous) {
424 query.append(WHERE_GREATER_THAN);
425 }
426 else {
427 query.append(WHERE_LESSER_THAN);
428 }
429 }
430 }
431
432 query.append(ORDER_BY_CLAUSE);
433
434 String[] orderByFields = orderByComparator.getOrderByFields();
435
436 for (int i = 0; i < orderByFields.length; i++) {
437 query.append(_ORDER_BY_ENTITY_ALIAS);
438 query.append(orderByFields[i]);
439
440 if ((i + 1) < orderByFields.length) {
441 if (orderByComparator.isAscending() ^ previous) {
442 query.append(ORDER_BY_ASC_HAS_NEXT);
443 }
444 else {
445 query.append(ORDER_BY_DESC_HAS_NEXT);
446 }
447 }
448 else {
449 if (orderByComparator.isAscending() ^ previous) {
450 query.append(ORDER_BY_ASC);
451 }
452 else {
453 query.append(ORDER_BY_DESC);
454 }
455 }
456 }
457 }
458 else {
459 query.append(PhoneModelImpl.ORDER_BY_JPQL);
460 }
461
462 String sql = query.toString();
463
464 Query q = session.createQuery(sql);
465
466 q.setFirstResult(0);
467 q.setMaxResults(2);
468
469 QueryPos qPos = QueryPos.getInstance(q);
470
471 qPos.add(companyId);
472
473 if (orderByComparator != null) {
474 Object[] values = orderByComparator.getOrderByConditionValues(phone);
475
476 for (Object value : values) {
477 qPos.add(value);
478 }
479 }
480
481 List<Phone> list = q.list();
482
483 if (list.size() == 2) {
484 return list.get(1);
485 }
486 else {
487 return null;
488 }
489 }
490
491
497 public void removeByCompanyId(long companyId) throws SystemException {
498 for (Phone phone : findByCompanyId(companyId, QueryUtil.ALL_POS,
499 QueryUtil.ALL_POS, null)) {
500 remove(phone);
501 }
502 }
503
504
511 public int countByCompanyId(long companyId) throws SystemException {
512 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
513
514 Object[] finderArgs = new Object[] { companyId };
515
516 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
517 this);
518
519 if (count == null) {
520 StringBundler query = new StringBundler(2);
521
522 query.append(_SQL_COUNT_PHONE_WHERE);
523
524 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
525
526 String sql = query.toString();
527
528 Session session = null;
529
530 try {
531 session = openSession();
532
533 Query q = session.createQuery(sql);
534
535 QueryPos qPos = QueryPos.getInstance(q);
536
537 qPos.add(companyId);
538
539 count = (Long)q.uniqueResult();
540
541 FinderCacheUtil.putResult(finderPath, finderArgs, count);
542 }
543 catch (Exception e) {
544 FinderCacheUtil.removeResult(finderPath, finderArgs);
545
546 throw processException(e);
547 }
548 finally {
549 closeSession(session);
550 }
551 }
552
553 return count.intValue();
554 }
555
556 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "phone.companyId = ?";
557 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
558 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
559 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
560 new String[] {
561 Long.class.getName(),
562
563 Integer.class.getName(), Integer.class.getName(),
564 OrderByComparator.class.getName()
565 });
566 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
567 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
568 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
569 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
570 new String[] { Long.class.getName() },
571 PhoneModelImpl.USERID_COLUMN_BITMASK |
572 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
573 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
574 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
575 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
576 new String[] { Long.class.getName() });
577
578
585 public List<Phone> findByUserId(long userId) throws SystemException {
586 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
587 }
588
589
602 public List<Phone> findByUserId(long userId, int start, int end)
603 throws SystemException {
604 return findByUserId(userId, start, end, null);
605 }
606
607
621 public List<Phone> findByUserId(long userId, int start, int end,
622 OrderByComparator orderByComparator) throws SystemException {
623 boolean pagination = true;
624 FinderPath finderPath = null;
625 Object[] finderArgs = null;
626
627 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
628 (orderByComparator == null)) {
629 pagination = false;
630 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
631 finderArgs = new Object[] { userId };
632 }
633 else {
634 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
635 finderArgs = new Object[] { userId, start, end, orderByComparator };
636 }
637
638 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
639 finderArgs, this);
640
641 if ((list != null) && !list.isEmpty()) {
642 for (Phone phone : list) {
643 if ((userId != phone.getUserId())) {
644 list = null;
645
646 break;
647 }
648 }
649 }
650
651 if (list == null) {
652 StringBundler query = null;
653
654 if (orderByComparator != null) {
655 query = new StringBundler(3 +
656 (orderByComparator.getOrderByFields().length * 3));
657 }
658 else {
659 query = new StringBundler(3);
660 }
661
662 query.append(_SQL_SELECT_PHONE_WHERE);
663
664 query.append(_FINDER_COLUMN_USERID_USERID_2);
665
666 if (orderByComparator != null) {
667 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
668 orderByComparator);
669 }
670 else
671 if (pagination) {
672 query.append(PhoneModelImpl.ORDER_BY_JPQL);
673 }
674
675 String sql = query.toString();
676
677 Session session = null;
678
679 try {
680 session = openSession();
681
682 Query q = session.createQuery(sql);
683
684 QueryPos qPos = QueryPos.getInstance(q);
685
686 qPos.add(userId);
687
688 if (!pagination) {
689 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
690 end, false);
691
692 Collections.sort(list);
693
694 list = new UnmodifiableList<Phone>(list);
695 }
696 else {
697 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
698 end);
699 }
700
701 cacheResult(list);
702
703 FinderCacheUtil.putResult(finderPath, finderArgs, list);
704 }
705 catch (Exception e) {
706 FinderCacheUtil.removeResult(finderPath, finderArgs);
707
708 throw processException(e);
709 }
710 finally {
711 closeSession(session);
712 }
713 }
714
715 return list;
716 }
717
718
727 public Phone findByUserId_First(long userId,
728 OrderByComparator orderByComparator)
729 throws NoSuchPhoneException, SystemException {
730 Phone phone = fetchByUserId_First(userId, orderByComparator);
731
732 if (phone != null) {
733 return phone;
734 }
735
736 StringBundler msg = new StringBundler(4);
737
738 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
739
740 msg.append("userId=");
741 msg.append(userId);
742
743 msg.append(StringPool.CLOSE_CURLY_BRACE);
744
745 throw new NoSuchPhoneException(msg.toString());
746 }
747
748
756 public Phone fetchByUserId_First(long userId,
757 OrderByComparator orderByComparator) throws SystemException {
758 List<Phone> list = findByUserId(userId, 0, 1, orderByComparator);
759
760 if (!list.isEmpty()) {
761 return list.get(0);
762 }
763
764 return null;
765 }
766
767
776 public Phone findByUserId_Last(long userId,
777 OrderByComparator orderByComparator)
778 throws NoSuchPhoneException, SystemException {
779 Phone phone = fetchByUserId_Last(userId, orderByComparator);
780
781 if (phone != null) {
782 return phone;
783 }
784
785 StringBundler msg = new StringBundler(4);
786
787 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
788
789 msg.append("userId=");
790 msg.append(userId);
791
792 msg.append(StringPool.CLOSE_CURLY_BRACE);
793
794 throw new NoSuchPhoneException(msg.toString());
795 }
796
797
805 public Phone fetchByUserId_Last(long userId,
806 OrderByComparator orderByComparator) throws SystemException {
807 int count = countByUserId(userId);
808
809 List<Phone> list = findByUserId(userId, count - 1, count,
810 orderByComparator);
811
812 if (!list.isEmpty()) {
813 return list.get(0);
814 }
815
816 return null;
817 }
818
819
829 public Phone[] findByUserId_PrevAndNext(long phoneId, long userId,
830 OrderByComparator orderByComparator)
831 throws NoSuchPhoneException, SystemException {
832 Phone phone = findByPrimaryKey(phoneId);
833
834 Session session = null;
835
836 try {
837 session = openSession();
838
839 Phone[] array = new PhoneImpl[3];
840
841 array[0] = getByUserId_PrevAndNext(session, phone, userId,
842 orderByComparator, true);
843
844 array[1] = phone;
845
846 array[2] = getByUserId_PrevAndNext(session, phone, userId,
847 orderByComparator, false);
848
849 return array;
850 }
851 catch (Exception e) {
852 throw processException(e);
853 }
854 finally {
855 closeSession(session);
856 }
857 }
858
859 protected Phone getByUserId_PrevAndNext(Session session, Phone phone,
860 long userId, OrderByComparator orderByComparator, boolean previous) {
861 StringBundler query = null;
862
863 if (orderByComparator != null) {
864 query = new StringBundler(6 +
865 (orderByComparator.getOrderByFields().length * 6));
866 }
867 else {
868 query = new StringBundler(3);
869 }
870
871 query.append(_SQL_SELECT_PHONE_WHERE);
872
873 query.append(_FINDER_COLUMN_USERID_USERID_2);
874
875 if (orderByComparator != null) {
876 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
877
878 if (orderByConditionFields.length > 0) {
879 query.append(WHERE_AND);
880 }
881
882 for (int i = 0; i < orderByConditionFields.length; i++) {
883 query.append(_ORDER_BY_ENTITY_ALIAS);
884 query.append(orderByConditionFields[i]);
885
886 if ((i + 1) < orderByConditionFields.length) {
887 if (orderByComparator.isAscending() ^ previous) {
888 query.append(WHERE_GREATER_THAN_HAS_NEXT);
889 }
890 else {
891 query.append(WHERE_LESSER_THAN_HAS_NEXT);
892 }
893 }
894 else {
895 if (orderByComparator.isAscending() ^ previous) {
896 query.append(WHERE_GREATER_THAN);
897 }
898 else {
899 query.append(WHERE_LESSER_THAN);
900 }
901 }
902 }
903
904 query.append(ORDER_BY_CLAUSE);
905
906 String[] orderByFields = orderByComparator.getOrderByFields();
907
908 for (int i = 0; i < orderByFields.length; i++) {
909 query.append(_ORDER_BY_ENTITY_ALIAS);
910 query.append(orderByFields[i]);
911
912 if ((i + 1) < orderByFields.length) {
913 if (orderByComparator.isAscending() ^ previous) {
914 query.append(ORDER_BY_ASC_HAS_NEXT);
915 }
916 else {
917 query.append(ORDER_BY_DESC_HAS_NEXT);
918 }
919 }
920 else {
921 if (orderByComparator.isAscending() ^ previous) {
922 query.append(ORDER_BY_ASC);
923 }
924 else {
925 query.append(ORDER_BY_DESC);
926 }
927 }
928 }
929 }
930 else {
931 query.append(PhoneModelImpl.ORDER_BY_JPQL);
932 }
933
934 String sql = query.toString();
935
936 Query q = session.createQuery(sql);
937
938 q.setFirstResult(0);
939 q.setMaxResults(2);
940
941 QueryPos qPos = QueryPos.getInstance(q);
942
943 qPos.add(userId);
944
945 if (orderByComparator != null) {
946 Object[] values = orderByComparator.getOrderByConditionValues(phone);
947
948 for (Object value : values) {
949 qPos.add(value);
950 }
951 }
952
953 List<Phone> list = q.list();
954
955 if (list.size() == 2) {
956 return list.get(1);
957 }
958 else {
959 return null;
960 }
961 }
962
963
969 public void removeByUserId(long userId) throws SystemException {
970 for (Phone phone : findByUserId(userId, QueryUtil.ALL_POS,
971 QueryUtil.ALL_POS, null)) {
972 remove(phone);
973 }
974 }
975
976
983 public int countByUserId(long userId) throws SystemException {
984 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
985
986 Object[] finderArgs = new Object[] { userId };
987
988 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
989 this);
990
991 if (count == null) {
992 StringBundler query = new StringBundler(2);
993
994 query.append(_SQL_COUNT_PHONE_WHERE);
995
996 query.append(_FINDER_COLUMN_USERID_USERID_2);
997
998 String sql = query.toString();
999
1000 Session session = null;
1001
1002 try {
1003 session = openSession();
1004
1005 Query q = session.createQuery(sql);
1006
1007 QueryPos qPos = QueryPos.getInstance(q);
1008
1009 qPos.add(userId);
1010
1011 count = (Long)q.uniqueResult();
1012
1013 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1014 }
1015 catch (Exception e) {
1016 FinderCacheUtil.removeResult(finderPath, finderArgs);
1017
1018 throw processException(e);
1019 }
1020 finally {
1021 closeSession(session);
1022 }
1023 }
1024
1025 return count.intValue();
1026 }
1027
1028 private static final String _FINDER_COLUMN_USERID_USERID_2 = "phone.userId = ?";
1029 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1030 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1031 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
1032 new String[] {
1033 Long.class.getName(), Long.class.getName(),
1034
1035 Integer.class.getName(), Integer.class.getName(),
1036 OrderByComparator.class.getName()
1037 });
1038 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1039 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1040 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
1041 new String[] { Long.class.getName(), Long.class.getName() },
1042 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
1043 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1044 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
1045 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1046 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
1047 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
1048 new String[] { Long.class.getName(), Long.class.getName() });
1049
1050
1058 public List<Phone> findByC_C(long companyId, long classNameId)
1059 throws SystemException {
1060 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
1061 QueryUtil.ALL_POS, null);
1062 }
1063
1064
1078 public List<Phone> findByC_C(long companyId, long classNameId, int start,
1079 int end) throws SystemException {
1080 return findByC_C(companyId, classNameId, start, end, null);
1081 }
1082
1083
1098 public List<Phone> findByC_C(long companyId, long classNameId, int start,
1099 int end, OrderByComparator orderByComparator) throws SystemException {
1100 boolean pagination = true;
1101 FinderPath finderPath = null;
1102 Object[] finderArgs = null;
1103
1104 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1105 (orderByComparator == null)) {
1106 pagination = false;
1107 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
1108 finderArgs = new Object[] { companyId, classNameId };
1109 }
1110 else {
1111 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
1112 finderArgs = new Object[] {
1113 companyId, classNameId,
1114
1115 start, end, orderByComparator
1116 };
1117 }
1118
1119 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
1120 finderArgs, this);
1121
1122 if ((list != null) && !list.isEmpty()) {
1123 for (Phone phone : list) {
1124 if ((companyId != phone.getCompanyId()) ||
1125 (classNameId != phone.getClassNameId())) {
1126 list = null;
1127
1128 break;
1129 }
1130 }
1131 }
1132
1133 if (list == null) {
1134 StringBundler query = null;
1135
1136 if (orderByComparator != null) {
1137 query = new StringBundler(4 +
1138 (orderByComparator.getOrderByFields().length * 3));
1139 }
1140 else {
1141 query = new StringBundler(4);
1142 }
1143
1144 query.append(_SQL_SELECT_PHONE_WHERE);
1145
1146 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1147
1148 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1149
1150 if (orderByComparator != null) {
1151 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1152 orderByComparator);
1153 }
1154 else
1155 if (pagination) {
1156 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1157 }
1158
1159 String sql = query.toString();
1160
1161 Session session = null;
1162
1163 try {
1164 session = openSession();
1165
1166 Query q = session.createQuery(sql);
1167
1168 QueryPos qPos = QueryPos.getInstance(q);
1169
1170 qPos.add(companyId);
1171
1172 qPos.add(classNameId);
1173
1174 if (!pagination) {
1175 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1176 end, false);
1177
1178 Collections.sort(list);
1179
1180 list = new UnmodifiableList<Phone>(list);
1181 }
1182 else {
1183 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1184 end);
1185 }
1186
1187 cacheResult(list);
1188
1189 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1190 }
1191 catch (Exception e) {
1192 FinderCacheUtil.removeResult(finderPath, finderArgs);
1193
1194 throw processException(e);
1195 }
1196 finally {
1197 closeSession(session);
1198 }
1199 }
1200
1201 return list;
1202 }
1203
1204
1214 public Phone findByC_C_First(long companyId, long classNameId,
1215 OrderByComparator orderByComparator)
1216 throws NoSuchPhoneException, SystemException {
1217 Phone phone = fetchByC_C_First(companyId, classNameId, orderByComparator);
1218
1219 if (phone != null) {
1220 return phone;
1221 }
1222
1223 StringBundler msg = new StringBundler(6);
1224
1225 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1226
1227 msg.append("companyId=");
1228 msg.append(companyId);
1229
1230 msg.append(", classNameId=");
1231 msg.append(classNameId);
1232
1233 msg.append(StringPool.CLOSE_CURLY_BRACE);
1234
1235 throw new NoSuchPhoneException(msg.toString());
1236 }
1237
1238
1247 public Phone fetchByC_C_First(long companyId, long classNameId,
1248 OrderByComparator orderByComparator) throws SystemException {
1249 List<Phone> list = findByC_C(companyId, classNameId, 0, 1,
1250 orderByComparator);
1251
1252 if (!list.isEmpty()) {
1253 return list.get(0);
1254 }
1255
1256 return null;
1257 }
1258
1259
1269 public Phone findByC_C_Last(long companyId, long classNameId,
1270 OrderByComparator orderByComparator)
1271 throws NoSuchPhoneException, SystemException {
1272 Phone phone = fetchByC_C_Last(companyId, classNameId, orderByComparator);
1273
1274 if (phone != null) {
1275 return phone;
1276 }
1277
1278 StringBundler msg = new StringBundler(6);
1279
1280 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1281
1282 msg.append("companyId=");
1283 msg.append(companyId);
1284
1285 msg.append(", classNameId=");
1286 msg.append(classNameId);
1287
1288 msg.append(StringPool.CLOSE_CURLY_BRACE);
1289
1290 throw new NoSuchPhoneException(msg.toString());
1291 }
1292
1293
1302 public Phone fetchByC_C_Last(long companyId, long classNameId,
1303 OrderByComparator orderByComparator) throws SystemException {
1304 int count = countByC_C(companyId, classNameId);
1305
1306 List<Phone> list = findByC_C(companyId, classNameId, count - 1, count,
1307 orderByComparator);
1308
1309 if (!list.isEmpty()) {
1310 return list.get(0);
1311 }
1312
1313 return null;
1314 }
1315
1316
1327 public Phone[] findByC_C_PrevAndNext(long phoneId, long companyId,
1328 long classNameId, OrderByComparator orderByComparator)
1329 throws NoSuchPhoneException, SystemException {
1330 Phone phone = findByPrimaryKey(phoneId);
1331
1332 Session session = null;
1333
1334 try {
1335 session = openSession();
1336
1337 Phone[] array = new PhoneImpl[3];
1338
1339 array[0] = getByC_C_PrevAndNext(session, phone, companyId,
1340 classNameId, orderByComparator, true);
1341
1342 array[1] = phone;
1343
1344 array[2] = getByC_C_PrevAndNext(session, phone, companyId,
1345 classNameId, orderByComparator, false);
1346
1347 return array;
1348 }
1349 catch (Exception e) {
1350 throw processException(e);
1351 }
1352 finally {
1353 closeSession(session);
1354 }
1355 }
1356
1357 protected Phone getByC_C_PrevAndNext(Session session, Phone phone,
1358 long companyId, long classNameId, OrderByComparator orderByComparator,
1359 boolean previous) {
1360 StringBundler query = null;
1361
1362 if (orderByComparator != null) {
1363 query = new StringBundler(6 +
1364 (orderByComparator.getOrderByFields().length * 6));
1365 }
1366 else {
1367 query = new StringBundler(3);
1368 }
1369
1370 query.append(_SQL_SELECT_PHONE_WHERE);
1371
1372 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1373
1374 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1375
1376 if (orderByComparator != null) {
1377 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1378
1379 if (orderByConditionFields.length > 0) {
1380 query.append(WHERE_AND);
1381 }
1382
1383 for (int i = 0; i < orderByConditionFields.length; i++) {
1384 query.append(_ORDER_BY_ENTITY_ALIAS);
1385 query.append(orderByConditionFields[i]);
1386
1387 if ((i + 1) < orderByConditionFields.length) {
1388 if (orderByComparator.isAscending() ^ previous) {
1389 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1390 }
1391 else {
1392 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1393 }
1394 }
1395 else {
1396 if (orderByComparator.isAscending() ^ previous) {
1397 query.append(WHERE_GREATER_THAN);
1398 }
1399 else {
1400 query.append(WHERE_LESSER_THAN);
1401 }
1402 }
1403 }
1404
1405 query.append(ORDER_BY_CLAUSE);
1406
1407 String[] orderByFields = orderByComparator.getOrderByFields();
1408
1409 for (int i = 0; i < orderByFields.length; i++) {
1410 query.append(_ORDER_BY_ENTITY_ALIAS);
1411 query.append(orderByFields[i]);
1412
1413 if ((i + 1) < orderByFields.length) {
1414 if (orderByComparator.isAscending() ^ previous) {
1415 query.append(ORDER_BY_ASC_HAS_NEXT);
1416 }
1417 else {
1418 query.append(ORDER_BY_DESC_HAS_NEXT);
1419 }
1420 }
1421 else {
1422 if (orderByComparator.isAscending() ^ previous) {
1423 query.append(ORDER_BY_ASC);
1424 }
1425 else {
1426 query.append(ORDER_BY_DESC);
1427 }
1428 }
1429 }
1430 }
1431 else {
1432 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1433 }
1434
1435 String sql = query.toString();
1436
1437 Query q = session.createQuery(sql);
1438
1439 q.setFirstResult(0);
1440 q.setMaxResults(2);
1441
1442 QueryPos qPos = QueryPos.getInstance(q);
1443
1444 qPos.add(companyId);
1445
1446 qPos.add(classNameId);
1447
1448 if (orderByComparator != null) {
1449 Object[] values = orderByComparator.getOrderByConditionValues(phone);
1450
1451 for (Object value : values) {
1452 qPos.add(value);
1453 }
1454 }
1455
1456 List<Phone> list = q.list();
1457
1458 if (list.size() == 2) {
1459 return list.get(1);
1460 }
1461 else {
1462 return null;
1463 }
1464 }
1465
1466
1473 public void removeByC_C(long companyId, long classNameId)
1474 throws SystemException {
1475 for (Phone phone : findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
1476 QueryUtil.ALL_POS, null)) {
1477 remove(phone);
1478 }
1479 }
1480
1481
1489 public int countByC_C(long companyId, long classNameId)
1490 throws SystemException {
1491 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1492
1493 Object[] finderArgs = new Object[] { companyId, classNameId };
1494
1495 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1496 this);
1497
1498 if (count == null) {
1499 StringBundler query = new StringBundler(3);
1500
1501 query.append(_SQL_COUNT_PHONE_WHERE);
1502
1503 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1504
1505 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1506
1507 String sql = query.toString();
1508
1509 Session session = null;
1510
1511 try {
1512 session = openSession();
1513
1514 Query q = session.createQuery(sql);
1515
1516 QueryPos qPos = QueryPos.getInstance(q);
1517
1518 qPos.add(companyId);
1519
1520 qPos.add(classNameId);
1521
1522 count = (Long)q.uniqueResult();
1523
1524 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1525 }
1526 catch (Exception e) {
1527 FinderCacheUtil.removeResult(finderPath, finderArgs);
1528
1529 throw processException(e);
1530 }
1531 finally {
1532 closeSession(session);
1533 }
1534 }
1535
1536 return count.intValue();
1537 }
1538
1539 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
1540 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "phone.classNameId = ?";
1541 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1542 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1543 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
1544 new String[] {
1545 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1546
1547 Integer.class.getName(), Integer.class.getName(),
1548 OrderByComparator.class.getName()
1549 });
1550 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1551 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1552 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
1553 new String[] {
1554 Long.class.getName(), Long.class.getName(), Long.class.getName()
1555 },
1556 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
1557 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1558 PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
1559 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
1560 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1561 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
1562 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
1563 new String[] {
1564 Long.class.getName(), Long.class.getName(), Long.class.getName()
1565 });
1566
1567
1576 public List<Phone> findByC_C_C(long companyId, long classNameId,
1577 long classPK) throws SystemException {
1578 return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1579 QueryUtil.ALL_POS, null);
1580 }
1581
1582
1597 public List<Phone> findByC_C_C(long companyId, long classNameId,
1598 long classPK, int start, int end) throws SystemException {
1599 return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1600 }
1601
1602
1618 public List<Phone> findByC_C_C(long companyId, long classNameId,
1619 long classPK, int start, int end, OrderByComparator orderByComparator)
1620 throws SystemException {
1621 boolean pagination = true;
1622 FinderPath finderPath = null;
1623 Object[] finderArgs = null;
1624
1625 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1626 (orderByComparator == null)) {
1627 pagination = false;
1628 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
1629 finderArgs = new Object[] { companyId, classNameId, classPK };
1630 }
1631 else {
1632 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
1633 finderArgs = new Object[] {
1634 companyId, classNameId, classPK,
1635
1636 start, end, orderByComparator
1637 };
1638 }
1639
1640 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
1641 finderArgs, this);
1642
1643 if ((list != null) && !list.isEmpty()) {
1644 for (Phone phone : list) {
1645 if ((companyId != phone.getCompanyId()) ||
1646 (classNameId != phone.getClassNameId()) ||
1647 (classPK != phone.getClassPK())) {
1648 list = null;
1649
1650 break;
1651 }
1652 }
1653 }
1654
1655 if (list == null) {
1656 StringBundler query = null;
1657
1658 if (orderByComparator != null) {
1659 query = new StringBundler(5 +
1660 (orderByComparator.getOrderByFields().length * 3));
1661 }
1662 else {
1663 query = new StringBundler(5);
1664 }
1665
1666 query.append(_SQL_SELECT_PHONE_WHERE);
1667
1668 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1669
1670 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1671
1672 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1673
1674 if (orderByComparator != null) {
1675 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1676 orderByComparator);
1677 }
1678 else
1679 if (pagination) {
1680 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1681 }
1682
1683 String sql = query.toString();
1684
1685 Session session = null;
1686
1687 try {
1688 session = openSession();
1689
1690 Query q = session.createQuery(sql);
1691
1692 QueryPos qPos = QueryPos.getInstance(q);
1693
1694 qPos.add(companyId);
1695
1696 qPos.add(classNameId);
1697
1698 qPos.add(classPK);
1699
1700 if (!pagination) {
1701 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1702 end, false);
1703
1704 Collections.sort(list);
1705
1706 list = new UnmodifiableList<Phone>(list);
1707 }
1708 else {
1709 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1710 end);
1711 }
1712
1713 cacheResult(list);
1714
1715 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1716 }
1717 catch (Exception e) {
1718 FinderCacheUtil.removeResult(finderPath, finderArgs);
1719
1720 throw processException(e);
1721 }
1722 finally {
1723 closeSession(session);
1724 }
1725 }
1726
1727 return list;
1728 }
1729
1730
1741 public Phone findByC_C_C_First(long companyId, long classNameId,
1742 long classPK, OrderByComparator orderByComparator)
1743 throws NoSuchPhoneException, SystemException {
1744 Phone phone = fetchByC_C_C_First(companyId, classNameId, classPK,
1745 orderByComparator);
1746
1747 if (phone != null) {
1748 return phone;
1749 }
1750
1751 StringBundler msg = new StringBundler(8);
1752
1753 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1754
1755 msg.append("companyId=");
1756 msg.append(companyId);
1757
1758 msg.append(", classNameId=");
1759 msg.append(classNameId);
1760
1761 msg.append(", classPK=");
1762 msg.append(classPK);
1763
1764 msg.append(StringPool.CLOSE_CURLY_BRACE);
1765
1766 throw new NoSuchPhoneException(msg.toString());
1767 }
1768
1769
1779 public Phone fetchByC_C_C_First(long companyId, long classNameId,
1780 long classPK, OrderByComparator orderByComparator)
1781 throws SystemException {
1782 List<Phone> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
1783 orderByComparator);
1784
1785 if (!list.isEmpty()) {
1786 return list.get(0);
1787 }
1788
1789 return null;
1790 }
1791
1792
1803 public Phone findByC_C_C_Last(long companyId, long classNameId,
1804 long classPK, OrderByComparator orderByComparator)
1805 throws NoSuchPhoneException, SystemException {
1806 Phone phone = fetchByC_C_C_Last(companyId, classNameId, classPK,
1807 orderByComparator);
1808
1809 if (phone != null) {
1810 return phone;
1811 }
1812
1813 StringBundler msg = new StringBundler(8);
1814
1815 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1816
1817 msg.append("companyId=");
1818 msg.append(companyId);
1819
1820 msg.append(", classNameId=");
1821 msg.append(classNameId);
1822
1823 msg.append(", classPK=");
1824 msg.append(classPK);
1825
1826 msg.append(StringPool.CLOSE_CURLY_BRACE);
1827
1828 throw new NoSuchPhoneException(msg.toString());
1829 }
1830
1831
1841 public Phone fetchByC_C_C_Last(long companyId, long classNameId,
1842 long classPK, OrderByComparator orderByComparator)
1843 throws SystemException {
1844 int count = countByC_C_C(companyId, classNameId, classPK);
1845
1846 List<Phone> list = findByC_C_C(companyId, classNameId, classPK,
1847 count - 1, count, orderByComparator);
1848
1849 if (!list.isEmpty()) {
1850 return list.get(0);
1851 }
1852
1853 return null;
1854 }
1855
1856
1868 public Phone[] findByC_C_C_PrevAndNext(long phoneId, long companyId,
1869 long classNameId, long classPK, OrderByComparator orderByComparator)
1870 throws NoSuchPhoneException, SystemException {
1871 Phone phone = findByPrimaryKey(phoneId);
1872
1873 Session session = null;
1874
1875 try {
1876 session = openSession();
1877
1878 Phone[] array = new PhoneImpl[3];
1879
1880 array[0] = getByC_C_C_PrevAndNext(session, phone, companyId,
1881 classNameId, classPK, orderByComparator, true);
1882
1883 array[1] = phone;
1884
1885 array[2] = getByC_C_C_PrevAndNext(session, phone, companyId,
1886 classNameId, classPK, orderByComparator, false);
1887
1888 return array;
1889 }
1890 catch (Exception e) {
1891 throw processException(e);
1892 }
1893 finally {
1894 closeSession(session);
1895 }
1896 }
1897
1898 protected Phone getByC_C_C_PrevAndNext(Session session, Phone phone,
1899 long companyId, long classNameId, long classPK,
1900 OrderByComparator orderByComparator, boolean previous) {
1901 StringBundler query = null;
1902
1903 if (orderByComparator != null) {
1904 query = new StringBundler(6 +
1905 (orderByComparator.getOrderByFields().length * 6));
1906 }
1907 else {
1908 query = new StringBundler(3);
1909 }
1910
1911 query.append(_SQL_SELECT_PHONE_WHERE);
1912
1913 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1914
1915 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1916
1917 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1918
1919 if (orderByComparator != null) {
1920 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1921
1922 if (orderByConditionFields.length > 0) {
1923 query.append(WHERE_AND);
1924 }
1925
1926 for (int i = 0; i < orderByConditionFields.length; i++) {
1927 query.append(_ORDER_BY_ENTITY_ALIAS);
1928 query.append(orderByConditionFields[i]);
1929
1930 if ((i + 1) < orderByConditionFields.length) {
1931 if (orderByComparator.isAscending() ^ previous) {
1932 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1933 }
1934 else {
1935 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1936 }
1937 }
1938 else {
1939 if (orderByComparator.isAscending() ^ previous) {
1940 query.append(WHERE_GREATER_THAN);
1941 }
1942 else {
1943 query.append(WHERE_LESSER_THAN);
1944 }
1945 }
1946 }
1947
1948 query.append(ORDER_BY_CLAUSE);
1949
1950 String[] orderByFields = orderByComparator.getOrderByFields();
1951
1952 for (int i = 0; i < orderByFields.length; i++) {
1953 query.append(_ORDER_BY_ENTITY_ALIAS);
1954 query.append(orderByFields[i]);
1955
1956 if ((i + 1) < orderByFields.length) {
1957 if (orderByComparator.isAscending() ^ previous) {
1958 query.append(ORDER_BY_ASC_HAS_NEXT);
1959 }
1960 else {
1961 query.append(ORDER_BY_DESC_HAS_NEXT);
1962 }
1963 }
1964 else {
1965 if (orderByComparator.isAscending() ^ previous) {
1966 query.append(ORDER_BY_ASC);
1967 }
1968 else {
1969 query.append(ORDER_BY_DESC);
1970 }
1971 }
1972 }
1973 }
1974 else {
1975 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1976 }
1977
1978 String sql = query.toString();
1979
1980 Query q = session.createQuery(sql);
1981
1982 q.setFirstResult(0);
1983 q.setMaxResults(2);
1984
1985 QueryPos qPos = QueryPos.getInstance(q);
1986
1987 qPos.add(companyId);
1988
1989 qPos.add(classNameId);
1990
1991 qPos.add(classPK);
1992
1993 if (orderByComparator != null) {
1994 Object[] values = orderByComparator.getOrderByConditionValues(phone);
1995
1996 for (Object value : values) {
1997 qPos.add(value);
1998 }
1999 }
2000
2001 List<Phone> list = q.list();
2002
2003 if (list.size() == 2) {
2004 return list.get(1);
2005 }
2006 else {
2007 return null;
2008 }
2009 }
2010
2011
2019 public void removeByC_C_C(long companyId, long classNameId, long classPK)
2020 throws SystemException {
2021 for (Phone phone : findByC_C_C(companyId, classNameId, classPK,
2022 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2023 remove(phone);
2024 }
2025 }
2026
2027
2036 public int countByC_C_C(long companyId, long classNameId, long classPK)
2037 throws SystemException {
2038 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
2039
2040 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2041
2042 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2043 this);
2044
2045 if (count == null) {
2046 StringBundler query = new StringBundler(4);
2047
2048 query.append(_SQL_COUNT_PHONE_WHERE);
2049
2050 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2051
2052 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2053
2054 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2055
2056 String sql = query.toString();
2057
2058 Session session = null;
2059
2060 try {
2061 session = openSession();
2062
2063 Query q = session.createQuery(sql);
2064
2065 QueryPos qPos = QueryPos.getInstance(q);
2066
2067 qPos.add(companyId);
2068
2069 qPos.add(classNameId);
2070
2071 qPos.add(classPK);
2072
2073 count = (Long)q.uniqueResult();
2074
2075 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2076 }
2077 catch (Exception e) {
2078 FinderCacheUtil.removeResult(finderPath, finderArgs);
2079
2080 throw processException(e);
2081 }
2082 finally {
2083 closeSession(session);
2084 }
2085 }
2086
2087 return count.intValue();
2088 }
2089
2090 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
2091 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
2092 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "phone.classPK = ?";
2093 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2094 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2095 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_P",
2096 new String[] {
2097 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2098 Boolean.class.getName(),
2099
2100 Integer.class.getName(), Integer.class.getName(),
2101 OrderByComparator.class.getName()
2102 });
2103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P =
2104 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2105 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_P",
2107 new String[] {
2108 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2109 Boolean.class.getName()
2110 },
2111 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
2112 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2113 PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
2114 PhoneModelImpl.PRIMARY_COLUMN_BITMASK |
2115 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
2116 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2117 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
2118 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_P",
2119 new String[] {
2120 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2121 Boolean.class.getName()
2122 });
2123
2124
2134 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
2135 long classPK, boolean primary) throws SystemException {
2136 return findByC_C_C_P(companyId, classNameId, classPK, primary,
2137 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2138 }
2139
2140
2156 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
2157 long classPK, boolean primary, int start, int end)
2158 throws SystemException {
2159 return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
2160 end, null);
2161 }
2162
2163
2180 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
2181 long classPK, boolean primary, int start, int end,
2182 OrderByComparator orderByComparator) throws SystemException {
2183 boolean pagination = true;
2184 FinderPath finderPath = null;
2185 Object[] finderArgs = null;
2186
2187 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2188 (orderByComparator == null)) {
2189 pagination = false;
2190 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P;
2191 finderArgs = new Object[] { companyId, classNameId, classPK, primary };
2192 }
2193 else {
2194 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
2195 finderArgs = new Object[] {
2196 companyId, classNameId, classPK, primary,
2197
2198 start, end, orderByComparator
2199 };
2200 }
2201
2202 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
2203 finderArgs, this);
2204
2205 if ((list != null) && !list.isEmpty()) {
2206 for (Phone phone : list) {
2207 if ((companyId != phone.getCompanyId()) ||
2208 (classNameId != phone.getClassNameId()) ||
2209 (classPK != phone.getClassPK()) ||
2210 (primary != phone.getPrimary())) {
2211 list = null;
2212
2213 break;
2214 }
2215 }
2216 }
2217
2218 if (list == null) {
2219 StringBundler query = null;
2220
2221 if (orderByComparator != null) {
2222 query = new StringBundler(6 +
2223 (orderByComparator.getOrderByFields().length * 3));
2224 }
2225 else {
2226 query = new StringBundler(6);
2227 }
2228
2229 query.append(_SQL_SELECT_PHONE_WHERE);
2230
2231 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2232
2233 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2234
2235 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2236
2237 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2238
2239 if (orderByComparator != null) {
2240 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2241 orderByComparator);
2242 }
2243 else
2244 if (pagination) {
2245 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2246 }
2247
2248 String sql = query.toString();
2249
2250 Session session = null;
2251
2252 try {
2253 session = openSession();
2254
2255 Query q = session.createQuery(sql);
2256
2257 QueryPos qPos = QueryPos.getInstance(q);
2258
2259 qPos.add(companyId);
2260
2261 qPos.add(classNameId);
2262
2263 qPos.add(classPK);
2264
2265 qPos.add(primary);
2266
2267 if (!pagination) {
2268 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2269 end, false);
2270
2271 Collections.sort(list);
2272
2273 list = new UnmodifiableList<Phone>(list);
2274 }
2275 else {
2276 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2277 end);
2278 }
2279
2280 cacheResult(list);
2281
2282 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2283 }
2284 catch (Exception e) {
2285 FinderCacheUtil.removeResult(finderPath, finderArgs);
2286
2287 throw processException(e);
2288 }
2289 finally {
2290 closeSession(session);
2291 }
2292 }
2293
2294 return list;
2295 }
2296
2297
2309 public Phone findByC_C_C_P_First(long companyId, long classNameId,
2310 long classPK, boolean primary, OrderByComparator orderByComparator)
2311 throws NoSuchPhoneException, SystemException {
2312 Phone phone = fetchByC_C_C_P_First(companyId, classNameId, classPK,
2313 primary, orderByComparator);
2314
2315 if (phone != null) {
2316 return phone;
2317 }
2318
2319 StringBundler msg = new StringBundler(10);
2320
2321 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2322
2323 msg.append("companyId=");
2324 msg.append(companyId);
2325
2326 msg.append(", classNameId=");
2327 msg.append(classNameId);
2328
2329 msg.append(", classPK=");
2330 msg.append(classPK);
2331
2332 msg.append(", primary=");
2333 msg.append(primary);
2334
2335 msg.append(StringPool.CLOSE_CURLY_BRACE);
2336
2337 throw new NoSuchPhoneException(msg.toString());
2338 }
2339
2340
2351 public Phone fetchByC_C_C_P_First(long companyId, long classNameId,
2352 long classPK, boolean primary, OrderByComparator orderByComparator)
2353 throws SystemException {
2354 List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
2355 primary, 0, 1, orderByComparator);
2356
2357 if (!list.isEmpty()) {
2358 return list.get(0);
2359 }
2360
2361 return null;
2362 }
2363
2364
2376 public Phone findByC_C_C_P_Last(long companyId, long classNameId,
2377 long classPK, boolean primary, OrderByComparator orderByComparator)
2378 throws NoSuchPhoneException, SystemException {
2379 Phone phone = fetchByC_C_C_P_Last(companyId, classNameId, classPK,
2380 primary, orderByComparator);
2381
2382 if (phone != null) {
2383 return phone;
2384 }
2385
2386 StringBundler msg = new StringBundler(10);
2387
2388 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2389
2390 msg.append("companyId=");
2391 msg.append(companyId);
2392
2393 msg.append(", classNameId=");
2394 msg.append(classNameId);
2395
2396 msg.append(", classPK=");
2397 msg.append(classPK);
2398
2399 msg.append(", primary=");
2400 msg.append(primary);
2401
2402 msg.append(StringPool.CLOSE_CURLY_BRACE);
2403
2404 throw new NoSuchPhoneException(msg.toString());
2405 }
2406
2407
2418 public Phone fetchByC_C_C_P_Last(long companyId, long classNameId,
2419 long classPK, boolean primary, OrderByComparator orderByComparator)
2420 throws SystemException {
2421 int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
2422
2423 List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
2424 primary, count - 1, count, orderByComparator);
2425
2426 if (!list.isEmpty()) {
2427 return list.get(0);
2428 }
2429
2430 return null;
2431 }
2432
2433
2446 public Phone[] findByC_C_C_P_PrevAndNext(long phoneId, long companyId,
2447 long classNameId, long classPK, boolean primary,
2448 OrderByComparator orderByComparator)
2449 throws NoSuchPhoneException, SystemException {
2450 Phone phone = findByPrimaryKey(phoneId);
2451
2452 Session session = null;
2453
2454 try {
2455 session = openSession();
2456
2457 Phone[] array = new PhoneImpl[3];
2458
2459 array[0] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
2460 classNameId, classPK, primary, orderByComparator, true);
2461
2462 array[1] = phone;
2463
2464 array[2] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
2465 classNameId, classPK, primary, orderByComparator, false);
2466
2467 return array;
2468 }
2469 catch (Exception e) {
2470 throw processException(e);
2471 }
2472 finally {
2473 closeSession(session);
2474 }
2475 }
2476
2477 protected Phone getByC_C_C_P_PrevAndNext(Session session, Phone phone,
2478 long companyId, long classNameId, long classPK, boolean primary,
2479 OrderByComparator orderByComparator, boolean previous) {
2480 StringBundler query = null;
2481
2482 if (orderByComparator != null) {
2483 query = new StringBundler(6 +
2484 (orderByComparator.getOrderByFields().length * 6));
2485 }
2486 else {
2487 query = new StringBundler(3);
2488 }
2489
2490 query.append(_SQL_SELECT_PHONE_WHERE);
2491
2492 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2493
2494 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2495
2496 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2497
2498 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2499
2500 if (orderByComparator != null) {
2501 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2502
2503 if (orderByConditionFields.length > 0) {
2504 query.append(WHERE_AND);
2505 }
2506
2507 for (int i = 0; i < orderByConditionFields.length; i++) {
2508 query.append(_ORDER_BY_ENTITY_ALIAS);
2509 query.append(orderByConditionFields[i]);
2510
2511 if ((i + 1) < orderByConditionFields.length) {
2512 if (orderByComparator.isAscending() ^ previous) {
2513 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2514 }
2515 else {
2516 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2517 }
2518 }
2519 else {
2520 if (orderByComparator.isAscending() ^ previous) {
2521 query.append(WHERE_GREATER_THAN);
2522 }
2523 else {
2524 query.append(WHERE_LESSER_THAN);
2525 }
2526 }
2527 }
2528
2529 query.append(ORDER_BY_CLAUSE);
2530
2531 String[] orderByFields = orderByComparator.getOrderByFields();
2532
2533 for (int i = 0; i < orderByFields.length; i++) {
2534 query.append(_ORDER_BY_ENTITY_ALIAS);
2535 query.append(orderByFields[i]);
2536
2537 if ((i + 1) < orderByFields.length) {
2538 if (orderByComparator.isAscending() ^ previous) {
2539 query.append(ORDER_BY_ASC_HAS_NEXT);
2540 }
2541 else {
2542 query.append(ORDER_BY_DESC_HAS_NEXT);
2543 }
2544 }
2545 else {
2546 if (orderByComparator.isAscending() ^ previous) {
2547 query.append(ORDER_BY_ASC);
2548 }
2549 else {
2550 query.append(ORDER_BY_DESC);
2551 }
2552 }
2553 }
2554 }
2555 else {
2556 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2557 }
2558
2559 String sql = query.toString();
2560
2561 Query q = session.createQuery(sql);
2562
2563 q.setFirstResult(0);
2564 q.setMaxResults(2);
2565
2566 QueryPos qPos = QueryPos.getInstance(q);
2567
2568 qPos.add(companyId);
2569
2570 qPos.add(classNameId);
2571
2572 qPos.add(classPK);
2573
2574 qPos.add(primary);
2575
2576 if (orderByComparator != null) {
2577 Object[] values = orderByComparator.getOrderByConditionValues(phone);
2578
2579 for (Object value : values) {
2580 qPos.add(value);
2581 }
2582 }
2583
2584 List<Phone> list = q.list();
2585
2586 if (list.size() == 2) {
2587 return list.get(1);
2588 }
2589 else {
2590 return null;
2591 }
2592 }
2593
2594
2603 public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
2604 boolean primary) throws SystemException {
2605 for (Phone phone : findByC_C_C_P(companyId, classNameId, classPK,
2606 primary, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2607 remove(phone);
2608 }
2609 }
2610
2611
2621 public int countByC_C_C_P(long companyId, long classNameId, long classPK,
2622 boolean primary) throws SystemException {
2623 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C_P;
2624
2625 Object[] finderArgs = new Object[] {
2626 companyId, classNameId, classPK, primary
2627 };
2628
2629 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2630 this);
2631
2632 if (count == null) {
2633 StringBundler query = new StringBundler(5);
2634
2635 query.append(_SQL_COUNT_PHONE_WHERE);
2636
2637 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2638
2639 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2640
2641 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2642
2643 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2644
2645 String sql = query.toString();
2646
2647 Session session = null;
2648
2649 try {
2650 session = openSession();
2651
2652 Query q = session.createQuery(sql);
2653
2654 QueryPos qPos = QueryPos.getInstance(q);
2655
2656 qPos.add(companyId);
2657
2658 qPos.add(classNameId);
2659
2660 qPos.add(classPK);
2661
2662 qPos.add(primary);
2663
2664 count = (Long)q.uniqueResult();
2665
2666 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2667 }
2668 catch (Exception e) {
2669 FinderCacheUtil.removeResult(finderPath, finderArgs);
2670
2671 throw processException(e);
2672 }
2673 finally {
2674 closeSession(session);
2675 }
2676 }
2677
2678 return count.intValue();
2679 }
2680
2681 private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "phone.companyId = ? AND ";
2682 private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
2683 private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "phone.classPK = ? AND ";
2684 private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "phone.primary = ?";
2685
2686
2691 public void cacheResult(Phone phone) {
2692 EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2693 PhoneImpl.class, phone.getPrimaryKey(), phone);
2694
2695 phone.resetOriginalValues();
2696 }
2697
2698
2703 public void cacheResult(List<Phone> phones) {
2704 for (Phone phone : phones) {
2705 if (EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2706 PhoneImpl.class, phone.getPrimaryKey()) == null) {
2707 cacheResult(phone);
2708 }
2709 else {
2710 phone.resetOriginalValues();
2711 }
2712 }
2713 }
2714
2715
2722 @Override
2723 public void clearCache() {
2724 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2725 CacheRegistryUtil.clear(PhoneImpl.class.getName());
2726 }
2727
2728 EntityCacheUtil.clearCache(PhoneImpl.class.getName());
2729
2730 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2731 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2732 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2733 }
2734
2735
2742 @Override
2743 public void clearCache(Phone phone) {
2744 EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2745 PhoneImpl.class, phone.getPrimaryKey());
2746
2747 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2748 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2749 }
2750
2751 @Override
2752 public void clearCache(List<Phone> phones) {
2753 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2754 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2755
2756 for (Phone phone : phones) {
2757 EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2758 PhoneImpl.class, phone.getPrimaryKey());
2759 }
2760 }
2761
2762
2768 public Phone create(long phoneId) {
2769 Phone phone = new PhoneImpl();
2770
2771 phone.setNew(true);
2772 phone.setPrimaryKey(phoneId);
2773
2774 return phone;
2775 }
2776
2777
2785 public Phone remove(long phoneId)
2786 throws NoSuchPhoneException, SystemException {
2787 return remove((Serializable)phoneId);
2788 }
2789
2790
2798 @Override
2799 public Phone remove(Serializable primaryKey)
2800 throws NoSuchPhoneException, SystemException {
2801 Session session = null;
2802
2803 try {
2804 session = openSession();
2805
2806 Phone phone = (Phone)session.get(PhoneImpl.class, primaryKey);
2807
2808 if (phone == null) {
2809 if (_log.isWarnEnabled()) {
2810 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2811 }
2812
2813 throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2814 primaryKey);
2815 }
2816
2817 return remove(phone);
2818 }
2819 catch (NoSuchPhoneException nsee) {
2820 throw nsee;
2821 }
2822 catch (Exception e) {
2823 throw processException(e);
2824 }
2825 finally {
2826 closeSession(session);
2827 }
2828 }
2829
2830 @Override
2831 protected Phone removeImpl(Phone phone) throws SystemException {
2832 phone = toUnwrappedModel(phone);
2833
2834 Session session = null;
2835
2836 try {
2837 session = openSession();
2838
2839 if (!session.contains(phone)) {
2840 phone = (Phone)session.get(PhoneImpl.class,
2841 phone.getPrimaryKeyObj());
2842 }
2843
2844 if (phone != null) {
2845 session.delete(phone);
2846 }
2847 }
2848 catch (Exception e) {
2849 throw processException(e);
2850 }
2851 finally {
2852 closeSession(session);
2853 }
2854
2855 if (phone != null) {
2856 clearCache(phone);
2857 }
2858
2859 return phone;
2860 }
2861
2862 @Override
2863 public Phone updateImpl(com.liferay.portal.model.Phone phone)
2864 throws SystemException {
2865 phone = toUnwrappedModel(phone);
2866
2867 boolean isNew = phone.isNew();
2868
2869 PhoneModelImpl phoneModelImpl = (PhoneModelImpl)phone;
2870
2871 Session session = null;
2872
2873 try {
2874 session = openSession();
2875
2876 if (phone.isNew()) {
2877 session.save(phone);
2878
2879 phone.setNew(false);
2880 }
2881 else {
2882 session.merge(phone);
2883 }
2884 }
2885 catch (Exception e) {
2886 throw processException(e);
2887 }
2888 finally {
2889 closeSession(session);
2890 }
2891
2892 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2893
2894 if (isNew || !PhoneModelImpl.COLUMN_BITMASK_ENABLED) {
2895 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2896 }
2897
2898 else {
2899 if ((phoneModelImpl.getColumnBitmask() &
2900 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2901 Object[] args = new Object[] {
2902 phoneModelImpl.getOriginalCompanyId()
2903 };
2904
2905 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2906 args);
2907 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2908 args);
2909
2910 args = new Object[] { phoneModelImpl.getCompanyId() };
2911
2912 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2913 args);
2914 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2915 args);
2916 }
2917
2918 if ((phoneModelImpl.getColumnBitmask() &
2919 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2920 Object[] args = new Object[] { phoneModelImpl.getOriginalUserId() };
2921
2922 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2923 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2924 args);
2925
2926 args = new Object[] { phoneModelImpl.getUserId() };
2927
2928 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2929 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2930 args);
2931 }
2932
2933 if ((phoneModelImpl.getColumnBitmask() &
2934 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
2935 Object[] args = new Object[] {
2936 phoneModelImpl.getOriginalCompanyId(),
2937 phoneModelImpl.getOriginalClassNameId()
2938 };
2939
2940 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2941 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
2942 args);
2943
2944 args = new Object[] {
2945 phoneModelImpl.getCompanyId(),
2946 phoneModelImpl.getClassNameId()
2947 };
2948
2949 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2950 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
2951 args);
2952 }
2953
2954 if ((phoneModelImpl.getColumnBitmask() &
2955 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
2956 Object[] args = new Object[] {
2957 phoneModelImpl.getOriginalCompanyId(),
2958 phoneModelImpl.getOriginalClassNameId(),
2959 phoneModelImpl.getOriginalClassPK()
2960 };
2961
2962 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2963 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2964 args);
2965
2966 args = new Object[] {
2967 phoneModelImpl.getCompanyId(),
2968 phoneModelImpl.getClassNameId(),
2969 phoneModelImpl.getClassPK()
2970 };
2971
2972 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2973 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2974 args);
2975 }
2976
2977 if ((phoneModelImpl.getColumnBitmask() &
2978 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P.getColumnBitmask()) != 0) {
2979 Object[] args = new Object[] {
2980 phoneModelImpl.getOriginalCompanyId(),
2981 phoneModelImpl.getOriginalClassNameId(),
2982 phoneModelImpl.getOriginalClassPK(),
2983 phoneModelImpl.getOriginalPrimary()
2984 };
2985
2986 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
2987 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
2988 args);
2989
2990 args = new Object[] {
2991 phoneModelImpl.getCompanyId(),
2992 phoneModelImpl.getClassNameId(),
2993 phoneModelImpl.getClassPK(), phoneModelImpl.getPrimary()
2994 };
2995
2996 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
2997 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
2998 args);
2999 }
3000 }
3001
3002 EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3003 PhoneImpl.class, phone.getPrimaryKey(), phone);
3004
3005 return phone;
3006 }
3007
3008 protected Phone toUnwrappedModel(Phone phone) {
3009 if (phone instanceof PhoneImpl) {
3010 return phone;
3011 }
3012
3013 PhoneImpl phoneImpl = new PhoneImpl();
3014
3015 phoneImpl.setNew(phone.isNew());
3016 phoneImpl.setPrimaryKey(phone.getPrimaryKey());
3017
3018 phoneImpl.setPhoneId(phone.getPhoneId());
3019 phoneImpl.setCompanyId(phone.getCompanyId());
3020 phoneImpl.setUserId(phone.getUserId());
3021 phoneImpl.setUserName(phone.getUserName());
3022 phoneImpl.setCreateDate(phone.getCreateDate());
3023 phoneImpl.setModifiedDate(phone.getModifiedDate());
3024 phoneImpl.setClassNameId(phone.getClassNameId());
3025 phoneImpl.setClassPK(phone.getClassPK());
3026 phoneImpl.setNumber(phone.getNumber());
3027 phoneImpl.setExtension(phone.getExtension());
3028 phoneImpl.setTypeId(phone.getTypeId());
3029 phoneImpl.setPrimary(phone.isPrimary());
3030
3031 return phoneImpl;
3032 }
3033
3034
3042 @Override
3043 public Phone findByPrimaryKey(Serializable primaryKey)
3044 throws NoSuchPhoneException, SystemException {
3045 Phone phone = fetchByPrimaryKey(primaryKey);
3046
3047 if (phone == null) {
3048 if (_log.isWarnEnabled()) {
3049 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3050 }
3051
3052 throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3053 primaryKey);
3054 }
3055
3056 return phone;
3057 }
3058
3059
3067 public Phone findByPrimaryKey(long phoneId)
3068 throws NoSuchPhoneException, SystemException {
3069 return findByPrimaryKey((Serializable)phoneId);
3070 }
3071
3072
3079 @Override
3080 public Phone fetchByPrimaryKey(Serializable primaryKey)
3081 throws SystemException {
3082 Phone phone = (Phone)EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3083 PhoneImpl.class, primaryKey);
3084
3085 if (phone == _nullPhone) {
3086 return null;
3087 }
3088
3089 if (phone == null) {
3090 Session session = null;
3091
3092 try {
3093 session = openSession();
3094
3095 phone = (Phone)session.get(PhoneImpl.class, primaryKey);
3096
3097 if (phone != null) {
3098 cacheResult(phone);
3099 }
3100 else {
3101 EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3102 PhoneImpl.class, primaryKey, _nullPhone);
3103 }
3104 }
3105 catch (Exception e) {
3106 EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3107 PhoneImpl.class, primaryKey);
3108
3109 throw processException(e);
3110 }
3111 finally {
3112 closeSession(session);
3113 }
3114 }
3115
3116 return phone;
3117 }
3118
3119
3126 public Phone fetchByPrimaryKey(long phoneId) throws SystemException {
3127 return fetchByPrimaryKey((Serializable)phoneId);
3128 }
3129
3130
3136 public List<Phone> findAll() throws SystemException {
3137 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3138 }
3139
3140
3152 public List<Phone> findAll(int start, int end) throws SystemException {
3153 return findAll(start, end, null);
3154 }
3155
3156
3169 public List<Phone> findAll(int start, int end,
3170 OrderByComparator orderByComparator) throws SystemException {
3171 boolean pagination = true;
3172 FinderPath finderPath = null;
3173 Object[] finderArgs = null;
3174
3175 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3176 (orderByComparator == null)) {
3177 pagination = false;
3178 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3179 finderArgs = FINDER_ARGS_EMPTY;
3180 }
3181 else {
3182 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3183 finderArgs = new Object[] { start, end, orderByComparator };
3184 }
3185
3186 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
3187 finderArgs, this);
3188
3189 if (list == null) {
3190 StringBundler query = null;
3191 String sql = null;
3192
3193 if (orderByComparator != null) {
3194 query = new StringBundler(2 +
3195 (orderByComparator.getOrderByFields().length * 3));
3196
3197 query.append(_SQL_SELECT_PHONE);
3198
3199 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3200 orderByComparator);
3201
3202 sql = query.toString();
3203 }
3204 else {
3205 sql = _SQL_SELECT_PHONE;
3206
3207 if (pagination) {
3208 sql = sql.concat(PhoneModelImpl.ORDER_BY_JPQL);
3209 }
3210 }
3211
3212 Session session = null;
3213
3214 try {
3215 session = openSession();
3216
3217 Query q = session.createQuery(sql);
3218
3219 if (!pagination) {
3220 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
3221 end, false);
3222
3223 Collections.sort(list);
3224
3225 list = new UnmodifiableList<Phone>(list);
3226 }
3227 else {
3228 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
3229 end);
3230 }
3231
3232 cacheResult(list);
3233
3234 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3235 }
3236 catch (Exception e) {
3237 FinderCacheUtil.removeResult(finderPath, finderArgs);
3238
3239 throw processException(e);
3240 }
3241 finally {
3242 closeSession(session);
3243 }
3244 }
3245
3246 return list;
3247 }
3248
3249
3254 public void removeAll() throws SystemException {
3255 for (Phone phone : findAll()) {
3256 remove(phone);
3257 }
3258 }
3259
3260
3266 public int countAll() throws SystemException {
3267 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3268 FINDER_ARGS_EMPTY, this);
3269
3270 if (count == null) {
3271 Session session = null;
3272
3273 try {
3274 session = openSession();
3275
3276 Query q = session.createQuery(_SQL_COUNT_PHONE);
3277
3278 count = (Long)q.uniqueResult();
3279
3280 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3281 FINDER_ARGS_EMPTY, count);
3282 }
3283 catch (Exception e) {
3284 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3285 FINDER_ARGS_EMPTY);
3286
3287 throw processException(e);
3288 }
3289 finally {
3290 closeSession(session);
3291 }
3292 }
3293
3294 return count.intValue();
3295 }
3296
3297
3300 public void afterPropertiesSet() {
3301 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3302 com.liferay.portal.util.PropsUtil.get(
3303 "value.object.listener.com.liferay.portal.model.Phone")));
3304
3305 if (listenerClassNames.length > 0) {
3306 try {
3307 List<ModelListener<Phone>> listenersList = new ArrayList<ModelListener<Phone>>();
3308
3309 for (String listenerClassName : listenerClassNames) {
3310 listenersList.add((ModelListener<Phone>)InstanceFactory.newInstance(
3311 listenerClassName));
3312 }
3313
3314 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3315 }
3316 catch (Exception e) {
3317 _log.error(e);
3318 }
3319 }
3320 }
3321
3322 public void destroy() {
3323 EntityCacheUtil.removeCache(PhoneImpl.class.getName());
3324 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3325 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3326 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3327 }
3328
3329 private static final String _SQL_SELECT_PHONE = "SELECT phone FROM Phone phone";
3330 private static final String _SQL_SELECT_PHONE_WHERE = "SELECT phone FROM Phone phone WHERE ";
3331 private static final String _SQL_COUNT_PHONE = "SELECT COUNT(phone) FROM Phone phone";
3332 private static final String _SQL_COUNT_PHONE_WHERE = "SELECT COUNT(phone) FROM Phone phone WHERE ";
3333 private static final String _ORDER_BY_ENTITY_ALIAS = "phone.";
3334 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Phone exists with the primary key ";
3335 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Phone exists with the key {";
3336 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3337 private static Log _log = LogFactoryUtil.getLog(PhonePersistenceImpl.class);
3338 private static Phone _nullPhone = new PhoneImpl() {
3339 @Override
3340 public Object clone() {
3341 return this;
3342 }
3343
3344 @Override
3345 public CacheModel<Phone> toCacheModel() {
3346 return _nullPhoneCacheModel;
3347 }
3348 };
3349
3350 private static CacheModel<Phone> _nullPhoneCacheModel = new CacheModel<Phone>() {
3351 public Phone toEntityModel() {
3352 return _nullPhone;
3353 }
3354 };
3355 }