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