001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchPhoneException;
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.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.SetUtil;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.Validator;
034 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.MVCCModel;
037 import com.liferay.portal.model.Phone;
038 import com.liferay.portal.model.impl.PhoneImpl;
039 import com.liferay.portal.model.impl.PhoneModelImpl;
040 import com.liferay.portal.service.ServiceContext;
041 import com.liferay.portal.service.ServiceContextThreadLocal;
042 import com.liferay.portal.service.persistence.PhonePersistence;
043
044 import java.io.Serializable;
045
046 import java.util.Collections;
047 import java.util.Date;
048 import java.util.HashMap;
049 import java.util.HashSet;
050 import java.util.Iterator;
051 import java.util.List;
052 import java.util.Map;
053 import java.util.Set;
054
055
067 @ProviderType
068 public class PhonePersistenceImpl extends BasePersistenceImpl<Phone>
069 implements PhonePersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = PhoneImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
081 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
082 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
084 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
087 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
090 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
091 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
092 new String[] {
093 String.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
099 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
101 new String[] { String.class.getName() },
102 PhoneModelImpl.UUID_COLUMN_BITMASK |
103 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
105 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107 new String[] { String.class.getName() });
108
109
115 @Override
116 public List<Phone> findByUuid(String uuid) {
117 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
132 @Override
133 public List<Phone> findByUuid(String uuid, int start, int end) {
134 return findByUuid(uuid, start, end, null);
135 }
136
137
150 @Override
151 public List<Phone> findByUuid(String uuid, int start, int end,
152 OrderByComparator<Phone> orderByComparator) {
153 boolean pagination = true;
154 FinderPath finderPath = null;
155 Object[] finderArgs = null;
156
157 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158 (orderByComparator == null)) {
159 pagination = false;
160 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
161 finderArgs = new Object[] { uuid };
162 }
163 else {
164 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
165 finderArgs = new Object[] { uuid, start, end, orderByComparator };
166 }
167
168 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
169 finderArgs, this);
170
171 if ((list != null) && !list.isEmpty()) {
172 for (Phone phone : list) {
173 if (!Validator.equals(uuid, phone.getUuid())) {
174 list = null;
175
176 break;
177 }
178 }
179 }
180
181 if (list == null) {
182 StringBundler query = null;
183
184 if (orderByComparator != null) {
185 query = new StringBundler(3 +
186 (orderByComparator.getOrderByFields().length * 3));
187 }
188 else {
189 query = new StringBundler(3);
190 }
191
192 query.append(_SQL_SELECT_PHONE_WHERE);
193
194 boolean bindUuid = false;
195
196 if (uuid == null) {
197 query.append(_FINDER_COLUMN_UUID_UUID_1);
198 }
199 else if (uuid.equals(StringPool.BLANK)) {
200 query.append(_FINDER_COLUMN_UUID_UUID_3);
201 }
202 else {
203 bindUuid = true;
204
205 query.append(_FINDER_COLUMN_UUID_UUID_2);
206 }
207
208 if (orderByComparator != null) {
209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210 orderByComparator);
211 }
212 else
213 if (pagination) {
214 query.append(PhoneModelImpl.ORDER_BY_JPQL);
215 }
216
217 String sql = query.toString();
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 Query q = session.createQuery(sql);
225
226 QueryPos qPos = QueryPos.getInstance(q);
227
228 if (bindUuid) {
229 qPos.add(uuid);
230 }
231
232 if (!pagination) {
233 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
234 end, false);
235
236 Collections.sort(list);
237
238 list = Collections.unmodifiableList(list);
239 }
240 else {
241 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
242 end);
243 }
244
245 cacheResult(list);
246
247 FinderCacheUtil.putResult(finderPath, finderArgs, list);
248 }
249 catch (Exception e) {
250 FinderCacheUtil.removeResult(finderPath, finderArgs);
251
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 return list;
260 }
261
262
270 @Override
271 public Phone findByUuid_First(String uuid,
272 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
273 Phone phone = fetchByUuid_First(uuid, orderByComparator);
274
275 if (phone != null) {
276 return phone;
277 }
278
279 StringBundler msg = new StringBundler(4);
280
281 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
282
283 msg.append("uuid=");
284 msg.append(uuid);
285
286 msg.append(StringPool.CLOSE_CURLY_BRACE);
287
288 throw new NoSuchPhoneException(msg.toString());
289 }
290
291
298 @Override
299 public Phone fetchByUuid_First(String uuid,
300 OrderByComparator<Phone> orderByComparator) {
301 List<Phone> list = findByUuid(uuid, 0, 1, orderByComparator);
302
303 if (!list.isEmpty()) {
304 return list.get(0);
305 }
306
307 return null;
308 }
309
310
318 @Override
319 public Phone findByUuid_Last(String uuid,
320 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
321 Phone phone = fetchByUuid_Last(uuid, orderByComparator);
322
323 if (phone != null) {
324 return phone;
325 }
326
327 StringBundler msg = new StringBundler(4);
328
329 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
330
331 msg.append("uuid=");
332 msg.append(uuid);
333
334 msg.append(StringPool.CLOSE_CURLY_BRACE);
335
336 throw new NoSuchPhoneException(msg.toString());
337 }
338
339
346 @Override
347 public Phone fetchByUuid_Last(String uuid,
348 OrderByComparator<Phone> orderByComparator) {
349 int count = countByUuid(uuid);
350
351 if (count == 0) {
352 return null;
353 }
354
355 List<Phone> list = findByUuid(uuid, count - 1, count, orderByComparator);
356
357 if (!list.isEmpty()) {
358 return list.get(0);
359 }
360
361 return null;
362 }
363
364
373 @Override
374 public Phone[] findByUuid_PrevAndNext(long phoneId, String uuid,
375 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
376 Phone phone = findByPrimaryKey(phoneId);
377
378 Session session = null;
379
380 try {
381 session = openSession();
382
383 Phone[] array = new PhoneImpl[3];
384
385 array[0] = getByUuid_PrevAndNext(session, phone, uuid,
386 orderByComparator, true);
387
388 array[1] = phone;
389
390 array[2] = getByUuid_PrevAndNext(session, phone, uuid,
391 orderByComparator, false);
392
393 return array;
394 }
395 catch (Exception e) {
396 throw processException(e);
397 }
398 finally {
399 closeSession(session);
400 }
401 }
402
403 protected Phone getByUuid_PrevAndNext(Session session, Phone phone,
404 String uuid, OrderByComparator<Phone> orderByComparator,
405 boolean previous) {
406 StringBundler query = null;
407
408 if (orderByComparator != null) {
409 query = new StringBundler(6 +
410 (orderByComparator.getOrderByFields().length * 6));
411 }
412 else {
413 query = new StringBundler(3);
414 }
415
416 query.append(_SQL_SELECT_PHONE_WHERE);
417
418 boolean bindUuid = false;
419
420 if (uuid == null) {
421 query.append(_FINDER_COLUMN_UUID_UUID_1);
422 }
423 else if (uuid.equals(StringPool.BLANK)) {
424 query.append(_FINDER_COLUMN_UUID_UUID_3);
425 }
426 else {
427 bindUuid = true;
428
429 query.append(_FINDER_COLUMN_UUID_UUID_2);
430 }
431
432 if (orderByComparator != null) {
433 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
434
435 if (orderByConditionFields.length > 0) {
436 query.append(WHERE_AND);
437 }
438
439 for (int i = 0; i < orderByConditionFields.length; i++) {
440 query.append(_ORDER_BY_ENTITY_ALIAS);
441 query.append(orderByConditionFields[i]);
442
443 if ((i + 1) < orderByConditionFields.length) {
444 if (orderByComparator.isAscending() ^ previous) {
445 query.append(WHERE_GREATER_THAN_HAS_NEXT);
446 }
447 else {
448 query.append(WHERE_LESSER_THAN_HAS_NEXT);
449 }
450 }
451 else {
452 if (orderByComparator.isAscending() ^ previous) {
453 query.append(WHERE_GREATER_THAN);
454 }
455 else {
456 query.append(WHERE_LESSER_THAN);
457 }
458 }
459 }
460
461 query.append(ORDER_BY_CLAUSE);
462
463 String[] orderByFields = orderByComparator.getOrderByFields();
464
465 for (int i = 0; i < orderByFields.length; i++) {
466 query.append(_ORDER_BY_ENTITY_ALIAS);
467 query.append(orderByFields[i]);
468
469 if ((i + 1) < orderByFields.length) {
470 if (orderByComparator.isAscending() ^ previous) {
471 query.append(ORDER_BY_ASC_HAS_NEXT);
472 }
473 else {
474 query.append(ORDER_BY_DESC_HAS_NEXT);
475 }
476 }
477 else {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(ORDER_BY_ASC);
480 }
481 else {
482 query.append(ORDER_BY_DESC);
483 }
484 }
485 }
486 }
487 else {
488 query.append(PhoneModelImpl.ORDER_BY_JPQL);
489 }
490
491 String sql = query.toString();
492
493 Query q = session.createQuery(sql);
494
495 q.setFirstResult(0);
496 q.setMaxResults(2);
497
498 QueryPos qPos = QueryPos.getInstance(q);
499
500 if (bindUuid) {
501 qPos.add(uuid);
502 }
503
504 if (orderByComparator != null) {
505 Object[] values = orderByComparator.getOrderByConditionValues(phone);
506
507 for (Object value : values) {
508 qPos.add(value);
509 }
510 }
511
512 List<Phone> list = q.list();
513
514 if (list.size() == 2) {
515 return list.get(1);
516 }
517 else {
518 return null;
519 }
520 }
521
522
527 @Override
528 public void removeByUuid(String uuid) {
529 for (Phone phone : findByUuid(uuid, QueryUtil.ALL_POS,
530 QueryUtil.ALL_POS, null)) {
531 remove(phone);
532 }
533 }
534
535
541 @Override
542 public int countByUuid(String uuid) {
543 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
544
545 Object[] finderArgs = new Object[] { uuid };
546
547 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
548 this);
549
550 if (count == null) {
551 StringBundler query = new StringBundler(2);
552
553 query.append(_SQL_COUNT_PHONE_WHERE);
554
555 boolean bindUuid = false;
556
557 if (uuid == null) {
558 query.append(_FINDER_COLUMN_UUID_UUID_1);
559 }
560 else if (uuid.equals(StringPool.BLANK)) {
561 query.append(_FINDER_COLUMN_UUID_UUID_3);
562 }
563 else {
564 bindUuid = true;
565
566 query.append(_FINDER_COLUMN_UUID_UUID_2);
567 }
568
569 String sql = query.toString();
570
571 Session session = null;
572
573 try {
574 session = openSession();
575
576 Query q = session.createQuery(sql);
577
578 QueryPos qPos = QueryPos.getInstance(q);
579
580 if (bindUuid) {
581 qPos.add(uuid);
582 }
583
584 count = (Long)q.uniqueResult();
585
586 FinderCacheUtil.putResult(finderPath, finderArgs, count);
587 }
588 catch (Exception e) {
589 FinderCacheUtil.removeResult(finderPath, finderArgs);
590
591 throw processException(e);
592 }
593 finally {
594 closeSession(session);
595 }
596 }
597
598 return count.intValue();
599 }
600
601 private static final String _FINDER_COLUMN_UUID_UUID_1 = "phone.uuid IS NULL";
602 private static final String _FINDER_COLUMN_UUID_UUID_2 = "phone.uuid = ?";
603 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(phone.uuid IS NULL OR phone.uuid = '')";
604 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
605 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
606 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
607 new String[] {
608 String.class.getName(), Long.class.getName(),
609
610 Integer.class.getName(), Integer.class.getName(),
611 OrderByComparator.class.getName()
612 });
613 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
614 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
615 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
616 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
617 new String[] { String.class.getName(), Long.class.getName() },
618 PhoneModelImpl.UUID_COLUMN_BITMASK |
619 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
620 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
621 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
622 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
623 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
624 new String[] { String.class.getName(), Long.class.getName() });
625
626
633 @Override
634 public List<Phone> findByUuid_C(String uuid, long companyId) {
635 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
636 QueryUtil.ALL_POS, null);
637 }
638
639
652 @Override
653 public List<Phone> findByUuid_C(String uuid, long companyId, int start,
654 int end) {
655 return findByUuid_C(uuid, companyId, start, end, null);
656 }
657
658
672 @Override
673 public List<Phone> findByUuid_C(String uuid, long companyId, int start,
674 int end, OrderByComparator<Phone> orderByComparator) {
675 boolean pagination = true;
676 FinderPath finderPath = null;
677 Object[] finderArgs = null;
678
679 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
680 (orderByComparator == null)) {
681 pagination = false;
682 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
683 finderArgs = new Object[] { uuid, companyId };
684 }
685 else {
686 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
687 finderArgs = new Object[] {
688 uuid, companyId,
689
690 start, end, orderByComparator
691 };
692 }
693
694 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
695 finderArgs, this);
696
697 if ((list != null) && !list.isEmpty()) {
698 for (Phone phone : list) {
699 if (!Validator.equals(uuid, phone.getUuid()) ||
700 (companyId != phone.getCompanyId())) {
701 list = null;
702
703 break;
704 }
705 }
706 }
707
708 if (list == null) {
709 StringBundler query = null;
710
711 if (orderByComparator != null) {
712 query = new StringBundler(4 +
713 (orderByComparator.getOrderByFields().length * 3));
714 }
715 else {
716 query = new StringBundler(4);
717 }
718
719 query.append(_SQL_SELECT_PHONE_WHERE);
720
721 boolean bindUuid = false;
722
723 if (uuid == null) {
724 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
725 }
726 else if (uuid.equals(StringPool.BLANK)) {
727 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
728 }
729 else {
730 bindUuid = true;
731
732 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
733 }
734
735 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
736
737 if (orderByComparator != null) {
738 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
739 orderByComparator);
740 }
741 else
742 if (pagination) {
743 query.append(PhoneModelImpl.ORDER_BY_JPQL);
744 }
745
746 String sql = query.toString();
747
748 Session session = null;
749
750 try {
751 session = openSession();
752
753 Query q = session.createQuery(sql);
754
755 QueryPos qPos = QueryPos.getInstance(q);
756
757 if (bindUuid) {
758 qPos.add(uuid);
759 }
760
761 qPos.add(companyId);
762
763 if (!pagination) {
764 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
765 end, false);
766
767 Collections.sort(list);
768
769 list = Collections.unmodifiableList(list);
770 }
771 else {
772 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
773 end);
774 }
775
776 cacheResult(list);
777
778 FinderCacheUtil.putResult(finderPath, finderArgs, list);
779 }
780 catch (Exception e) {
781 FinderCacheUtil.removeResult(finderPath, finderArgs);
782
783 throw processException(e);
784 }
785 finally {
786 closeSession(session);
787 }
788 }
789
790 return list;
791 }
792
793
802 @Override
803 public Phone findByUuid_C_First(String uuid, long companyId,
804 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
805 Phone phone = fetchByUuid_C_First(uuid, companyId, orderByComparator);
806
807 if (phone != null) {
808 return phone;
809 }
810
811 StringBundler msg = new StringBundler(6);
812
813 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
814
815 msg.append("uuid=");
816 msg.append(uuid);
817
818 msg.append(", companyId=");
819 msg.append(companyId);
820
821 msg.append(StringPool.CLOSE_CURLY_BRACE);
822
823 throw new NoSuchPhoneException(msg.toString());
824 }
825
826
834 @Override
835 public Phone fetchByUuid_C_First(String uuid, long companyId,
836 OrderByComparator<Phone> orderByComparator) {
837 List<Phone> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
838
839 if (!list.isEmpty()) {
840 return list.get(0);
841 }
842
843 return null;
844 }
845
846
855 @Override
856 public Phone findByUuid_C_Last(String uuid, long companyId,
857 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
858 Phone phone = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
859
860 if (phone != null) {
861 return phone;
862 }
863
864 StringBundler msg = new StringBundler(6);
865
866 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
867
868 msg.append("uuid=");
869 msg.append(uuid);
870
871 msg.append(", companyId=");
872 msg.append(companyId);
873
874 msg.append(StringPool.CLOSE_CURLY_BRACE);
875
876 throw new NoSuchPhoneException(msg.toString());
877 }
878
879
887 @Override
888 public Phone fetchByUuid_C_Last(String uuid, long companyId,
889 OrderByComparator<Phone> orderByComparator) {
890 int count = countByUuid_C(uuid, companyId);
891
892 if (count == 0) {
893 return null;
894 }
895
896 List<Phone> list = findByUuid_C(uuid, companyId, count - 1, count,
897 orderByComparator);
898
899 if (!list.isEmpty()) {
900 return list.get(0);
901 }
902
903 return null;
904 }
905
906
916 @Override
917 public Phone[] findByUuid_C_PrevAndNext(long phoneId, String uuid,
918 long companyId, OrderByComparator<Phone> orderByComparator)
919 throws NoSuchPhoneException {
920 Phone phone = findByPrimaryKey(phoneId);
921
922 Session session = null;
923
924 try {
925 session = openSession();
926
927 Phone[] array = new PhoneImpl[3];
928
929 array[0] = getByUuid_C_PrevAndNext(session, phone, uuid, companyId,
930 orderByComparator, true);
931
932 array[1] = phone;
933
934 array[2] = getByUuid_C_PrevAndNext(session, phone, uuid, companyId,
935 orderByComparator, false);
936
937 return array;
938 }
939 catch (Exception e) {
940 throw processException(e);
941 }
942 finally {
943 closeSession(session);
944 }
945 }
946
947 protected Phone getByUuid_C_PrevAndNext(Session session, Phone phone,
948 String uuid, long companyId,
949 OrderByComparator<Phone> orderByComparator, boolean previous) {
950 StringBundler query = null;
951
952 if (orderByComparator != null) {
953 query = new StringBundler(6 +
954 (orderByComparator.getOrderByFields().length * 6));
955 }
956 else {
957 query = new StringBundler(3);
958 }
959
960 query.append(_SQL_SELECT_PHONE_WHERE);
961
962 boolean bindUuid = false;
963
964 if (uuid == null) {
965 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
966 }
967 else if (uuid.equals(StringPool.BLANK)) {
968 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
969 }
970 else {
971 bindUuid = true;
972
973 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
974 }
975
976 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
977
978 if (orderByComparator != null) {
979 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
980
981 if (orderByConditionFields.length > 0) {
982 query.append(WHERE_AND);
983 }
984
985 for (int i = 0; i < orderByConditionFields.length; i++) {
986 query.append(_ORDER_BY_ENTITY_ALIAS);
987 query.append(orderByConditionFields[i]);
988
989 if ((i + 1) < orderByConditionFields.length) {
990 if (orderByComparator.isAscending() ^ previous) {
991 query.append(WHERE_GREATER_THAN_HAS_NEXT);
992 }
993 else {
994 query.append(WHERE_LESSER_THAN_HAS_NEXT);
995 }
996 }
997 else {
998 if (orderByComparator.isAscending() ^ previous) {
999 query.append(WHERE_GREATER_THAN);
1000 }
1001 else {
1002 query.append(WHERE_LESSER_THAN);
1003 }
1004 }
1005 }
1006
1007 query.append(ORDER_BY_CLAUSE);
1008
1009 String[] orderByFields = orderByComparator.getOrderByFields();
1010
1011 for (int i = 0; i < orderByFields.length; i++) {
1012 query.append(_ORDER_BY_ENTITY_ALIAS);
1013 query.append(orderByFields[i]);
1014
1015 if ((i + 1) < orderByFields.length) {
1016 if (orderByComparator.isAscending() ^ previous) {
1017 query.append(ORDER_BY_ASC_HAS_NEXT);
1018 }
1019 else {
1020 query.append(ORDER_BY_DESC_HAS_NEXT);
1021 }
1022 }
1023 else {
1024 if (orderByComparator.isAscending() ^ previous) {
1025 query.append(ORDER_BY_ASC);
1026 }
1027 else {
1028 query.append(ORDER_BY_DESC);
1029 }
1030 }
1031 }
1032 }
1033 else {
1034 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1035 }
1036
1037 String sql = query.toString();
1038
1039 Query q = session.createQuery(sql);
1040
1041 q.setFirstResult(0);
1042 q.setMaxResults(2);
1043
1044 QueryPos qPos = QueryPos.getInstance(q);
1045
1046 if (bindUuid) {
1047 qPos.add(uuid);
1048 }
1049
1050 qPos.add(companyId);
1051
1052 if (orderByComparator != null) {
1053 Object[] values = orderByComparator.getOrderByConditionValues(phone);
1054
1055 for (Object value : values) {
1056 qPos.add(value);
1057 }
1058 }
1059
1060 List<Phone> list = q.list();
1061
1062 if (list.size() == 2) {
1063 return list.get(1);
1064 }
1065 else {
1066 return null;
1067 }
1068 }
1069
1070
1076 @Override
1077 public void removeByUuid_C(String uuid, long companyId) {
1078 for (Phone phone : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1079 QueryUtil.ALL_POS, null)) {
1080 remove(phone);
1081 }
1082 }
1083
1084
1091 @Override
1092 public int countByUuid_C(String uuid, long companyId) {
1093 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1094
1095 Object[] finderArgs = new Object[] { uuid, companyId };
1096
1097 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1098 this);
1099
1100 if (count == null) {
1101 StringBundler query = new StringBundler(3);
1102
1103 query.append(_SQL_COUNT_PHONE_WHERE);
1104
1105 boolean bindUuid = false;
1106
1107 if (uuid == null) {
1108 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1109 }
1110 else if (uuid.equals(StringPool.BLANK)) {
1111 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1112 }
1113 else {
1114 bindUuid = true;
1115
1116 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1117 }
1118
1119 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1120
1121 String sql = query.toString();
1122
1123 Session session = null;
1124
1125 try {
1126 session = openSession();
1127
1128 Query q = session.createQuery(sql);
1129
1130 QueryPos qPos = QueryPos.getInstance(q);
1131
1132 if (bindUuid) {
1133 qPos.add(uuid);
1134 }
1135
1136 qPos.add(companyId);
1137
1138 count = (Long)q.uniqueResult();
1139
1140 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1141 }
1142 catch (Exception e) {
1143 FinderCacheUtil.removeResult(finderPath, finderArgs);
1144
1145 throw processException(e);
1146 }
1147 finally {
1148 closeSession(session);
1149 }
1150 }
1151
1152 return count.intValue();
1153 }
1154
1155 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "phone.uuid IS NULL AND ";
1156 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "phone.uuid = ? AND ";
1157 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(phone.uuid IS NULL OR phone.uuid = '') AND ";
1158 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "phone.companyId = ?";
1159 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1160 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1161 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1162 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1163 new String[] {
1164 Long.class.getName(),
1165
1166 Integer.class.getName(), Integer.class.getName(),
1167 OrderByComparator.class.getName()
1168 });
1169 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1170 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1171 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1172 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1173 new String[] { Long.class.getName() },
1174 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
1175 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
1176 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1177 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
1178 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1179 new String[] { Long.class.getName() });
1180
1181
1187 @Override
1188 public List<Phone> findByCompanyId(long companyId) {
1189 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1190 null);
1191 }
1192
1193
1205 @Override
1206 public List<Phone> findByCompanyId(long companyId, int start, int end) {
1207 return findByCompanyId(companyId, start, end, null);
1208 }
1209
1210
1223 @Override
1224 public List<Phone> findByCompanyId(long companyId, int start, int end,
1225 OrderByComparator<Phone> orderByComparator) {
1226 boolean pagination = true;
1227 FinderPath finderPath = null;
1228 Object[] finderArgs = null;
1229
1230 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1231 (orderByComparator == null)) {
1232 pagination = false;
1233 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1234 finderArgs = new Object[] { companyId };
1235 }
1236 else {
1237 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1238 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1239 }
1240
1241 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
1242 finderArgs, this);
1243
1244 if ((list != null) && !list.isEmpty()) {
1245 for (Phone phone : list) {
1246 if ((companyId != phone.getCompanyId())) {
1247 list = null;
1248
1249 break;
1250 }
1251 }
1252 }
1253
1254 if (list == null) {
1255 StringBundler query = null;
1256
1257 if (orderByComparator != null) {
1258 query = new StringBundler(3 +
1259 (orderByComparator.getOrderByFields().length * 3));
1260 }
1261 else {
1262 query = new StringBundler(3);
1263 }
1264
1265 query.append(_SQL_SELECT_PHONE_WHERE);
1266
1267 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1268
1269 if (orderByComparator != null) {
1270 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1271 orderByComparator);
1272 }
1273 else
1274 if (pagination) {
1275 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1276 }
1277
1278 String sql = query.toString();
1279
1280 Session session = null;
1281
1282 try {
1283 session = openSession();
1284
1285 Query q = session.createQuery(sql);
1286
1287 QueryPos qPos = QueryPos.getInstance(q);
1288
1289 qPos.add(companyId);
1290
1291 if (!pagination) {
1292 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1293 end, false);
1294
1295 Collections.sort(list);
1296
1297 list = Collections.unmodifiableList(list);
1298 }
1299 else {
1300 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1301 end);
1302 }
1303
1304 cacheResult(list);
1305
1306 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1307 }
1308 catch (Exception e) {
1309 FinderCacheUtil.removeResult(finderPath, finderArgs);
1310
1311 throw processException(e);
1312 }
1313 finally {
1314 closeSession(session);
1315 }
1316 }
1317
1318 return list;
1319 }
1320
1321
1329 @Override
1330 public Phone findByCompanyId_First(long companyId,
1331 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1332 Phone phone = fetchByCompanyId_First(companyId, orderByComparator);
1333
1334 if (phone != null) {
1335 return phone;
1336 }
1337
1338 StringBundler msg = new StringBundler(4);
1339
1340 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1341
1342 msg.append("companyId=");
1343 msg.append(companyId);
1344
1345 msg.append(StringPool.CLOSE_CURLY_BRACE);
1346
1347 throw new NoSuchPhoneException(msg.toString());
1348 }
1349
1350
1357 @Override
1358 public Phone fetchByCompanyId_First(long companyId,
1359 OrderByComparator<Phone> orderByComparator) {
1360 List<Phone> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1361
1362 if (!list.isEmpty()) {
1363 return list.get(0);
1364 }
1365
1366 return null;
1367 }
1368
1369
1377 @Override
1378 public Phone findByCompanyId_Last(long companyId,
1379 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1380 Phone phone = fetchByCompanyId_Last(companyId, orderByComparator);
1381
1382 if (phone != null) {
1383 return phone;
1384 }
1385
1386 StringBundler msg = new StringBundler(4);
1387
1388 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1389
1390 msg.append("companyId=");
1391 msg.append(companyId);
1392
1393 msg.append(StringPool.CLOSE_CURLY_BRACE);
1394
1395 throw new NoSuchPhoneException(msg.toString());
1396 }
1397
1398
1405 @Override
1406 public Phone fetchByCompanyId_Last(long companyId,
1407 OrderByComparator<Phone> orderByComparator) {
1408 int count = countByCompanyId(companyId);
1409
1410 if (count == 0) {
1411 return null;
1412 }
1413
1414 List<Phone> list = findByCompanyId(companyId, count - 1, count,
1415 orderByComparator);
1416
1417 if (!list.isEmpty()) {
1418 return list.get(0);
1419 }
1420
1421 return null;
1422 }
1423
1424
1433 @Override
1434 public Phone[] findByCompanyId_PrevAndNext(long phoneId, long companyId,
1435 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1436 Phone phone = findByPrimaryKey(phoneId);
1437
1438 Session session = null;
1439
1440 try {
1441 session = openSession();
1442
1443 Phone[] array = new PhoneImpl[3];
1444
1445 array[0] = getByCompanyId_PrevAndNext(session, phone, companyId,
1446 orderByComparator, true);
1447
1448 array[1] = phone;
1449
1450 array[2] = getByCompanyId_PrevAndNext(session, phone, companyId,
1451 orderByComparator, false);
1452
1453 return array;
1454 }
1455 catch (Exception e) {
1456 throw processException(e);
1457 }
1458 finally {
1459 closeSession(session);
1460 }
1461 }
1462
1463 protected Phone getByCompanyId_PrevAndNext(Session session, Phone phone,
1464 long companyId, OrderByComparator<Phone> orderByComparator,
1465 boolean previous) {
1466 StringBundler query = null;
1467
1468 if (orderByComparator != null) {
1469 query = new StringBundler(6 +
1470 (orderByComparator.getOrderByFields().length * 6));
1471 }
1472 else {
1473 query = new StringBundler(3);
1474 }
1475
1476 query.append(_SQL_SELECT_PHONE_WHERE);
1477
1478 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1479
1480 if (orderByComparator != null) {
1481 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1482
1483 if (orderByConditionFields.length > 0) {
1484 query.append(WHERE_AND);
1485 }
1486
1487 for (int i = 0; i < orderByConditionFields.length; i++) {
1488 query.append(_ORDER_BY_ENTITY_ALIAS);
1489 query.append(orderByConditionFields[i]);
1490
1491 if ((i + 1) < orderByConditionFields.length) {
1492 if (orderByComparator.isAscending() ^ previous) {
1493 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1494 }
1495 else {
1496 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1497 }
1498 }
1499 else {
1500 if (orderByComparator.isAscending() ^ previous) {
1501 query.append(WHERE_GREATER_THAN);
1502 }
1503 else {
1504 query.append(WHERE_LESSER_THAN);
1505 }
1506 }
1507 }
1508
1509 query.append(ORDER_BY_CLAUSE);
1510
1511 String[] orderByFields = orderByComparator.getOrderByFields();
1512
1513 for (int i = 0; i < orderByFields.length; i++) {
1514 query.append(_ORDER_BY_ENTITY_ALIAS);
1515 query.append(orderByFields[i]);
1516
1517 if ((i + 1) < orderByFields.length) {
1518 if (orderByComparator.isAscending() ^ previous) {
1519 query.append(ORDER_BY_ASC_HAS_NEXT);
1520 }
1521 else {
1522 query.append(ORDER_BY_DESC_HAS_NEXT);
1523 }
1524 }
1525 else {
1526 if (orderByComparator.isAscending() ^ previous) {
1527 query.append(ORDER_BY_ASC);
1528 }
1529 else {
1530 query.append(ORDER_BY_DESC);
1531 }
1532 }
1533 }
1534 }
1535 else {
1536 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1537 }
1538
1539 String sql = query.toString();
1540
1541 Query q = session.createQuery(sql);
1542
1543 q.setFirstResult(0);
1544 q.setMaxResults(2);
1545
1546 QueryPos qPos = QueryPos.getInstance(q);
1547
1548 qPos.add(companyId);
1549
1550 if (orderByComparator != null) {
1551 Object[] values = orderByComparator.getOrderByConditionValues(phone);
1552
1553 for (Object value : values) {
1554 qPos.add(value);
1555 }
1556 }
1557
1558 List<Phone> list = q.list();
1559
1560 if (list.size() == 2) {
1561 return list.get(1);
1562 }
1563 else {
1564 return null;
1565 }
1566 }
1567
1568
1573 @Override
1574 public void removeByCompanyId(long companyId) {
1575 for (Phone phone : findByCompanyId(companyId, QueryUtil.ALL_POS,
1576 QueryUtil.ALL_POS, null)) {
1577 remove(phone);
1578 }
1579 }
1580
1581
1587 @Override
1588 public int countByCompanyId(long companyId) {
1589 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1590
1591 Object[] finderArgs = new Object[] { companyId };
1592
1593 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1594 this);
1595
1596 if (count == null) {
1597 StringBundler query = new StringBundler(2);
1598
1599 query.append(_SQL_COUNT_PHONE_WHERE);
1600
1601 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1602
1603 String sql = query.toString();
1604
1605 Session session = null;
1606
1607 try {
1608 session = openSession();
1609
1610 Query q = session.createQuery(sql);
1611
1612 QueryPos qPos = QueryPos.getInstance(q);
1613
1614 qPos.add(companyId);
1615
1616 count = (Long)q.uniqueResult();
1617
1618 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1619 }
1620 catch (Exception e) {
1621 FinderCacheUtil.removeResult(finderPath, finderArgs);
1622
1623 throw processException(e);
1624 }
1625 finally {
1626 closeSession(session);
1627 }
1628 }
1629
1630 return count.intValue();
1631 }
1632
1633 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "phone.companyId = ?";
1634 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1635 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1636 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1637 new String[] {
1638 Long.class.getName(),
1639
1640 Integer.class.getName(), Integer.class.getName(),
1641 OrderByComparator.class.getName()
1642 });
1643 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1644 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1645 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1646 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1647 new String[] { Long.class.getName() },
1648 PhoneModelImpl.USERID_COLUMN_BITMASK |
1649 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
1650 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1651 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
1652 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1653 new String[] { Long.class.getName() });
1654
1655
1661 @Override
1662 public List<Phone> findByUserId(long userId) {
1663 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1664 }
1665
1666
1678 @Override
1679 public List<Phone> findByUserId(long userId, int start, int end) {
1680 return findByUserId(userId, start, end, null);
1681 }
1682
1683
1696 @Override
1697 public List<Phone> findByUserId(long userId, int start, int end,
1698 OrderByComparator<Phone> orderByComparator) {
1699 boolean pagination = true;
1700 FinderPath finderPath = null;
1701 Object[] finderArgs = null;
1702
1703 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1704 (orderByComparator == null)) {
1705 pagination = false;
1706 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1707 finderArgs = new Object[] { userId };
1708 }
1709 else {
1710 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1711 finderArgs = new Object[] { userId, start, end, orderByComparator };
1712 }
1713
1714 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
1715 finderArgs, this);
1716
1717 if ((list != null) && !list.isEmpty()) {
1718 for (Phone phone : list) {
1719 if ((userId != phone.getUserId())) {
1720 list = null;
1721
1722 break;
1723 }
1724 }
1725 }
1726
1727 if (list == null) {
1728 StringBundler query = null;
1729
1730 if (orderByComparator != null) {
1731 query = new StringBundler(3 +
1732 (orderByComparator.getOrderByFields().length * 3));
1733 }
1734 else {
1735 query = new StringBundler(3);
1736 }
1737
1738 query.append(_SQL_SELECT_PHONE_WHERE);
1739
1740 query.append(_FINDER_COLUMN_USERID_USERID_2);
1741
1742 if (orderByComparator != null) {
1743 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1744 orderByComparator);
1745 }
1746 else
1747 if (pagination) {
1748 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1749 }
1750
1751 String sql = query.toString();
1752
1753 Session session = null;
1754
1755 try {
1756 session = openSession();
1757
1758 Query q = session.createQuery(sql);
1759
1760 QueryPos qPos = QueryPos.getInstance(q);
1761
1762 qPos.add(userId);
1763
1764 if (!pagination) {
1765 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1766 end, false);
1767
1768 Collections.sort(list);
1769
1770 list = Collections.unmodifiableList(list);
1771 }
1772 else {
1773 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1774 end);
1775 }
1776
1777 cacheResult(list);
1778
1779 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1780 }
1781 catch (Exception e) {
1782 FinderCacheUtil.removeResult(finderPath, finderArgs);
1783
1784 throw processException(e);
1785 }
1786 finally {
1787 closeSession(session);
1788 }
1789 }
1790
1791 return list;
1792 }
1793
1794
1802 @Override
1803 public Phone findByUserId_First(long userId,
1804 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1805 Phone phone = fetchByUserId_First(userId, orderByComparator);
1806
1807 if (phone != null) {
1808 return phone;
1809 }
1810
1811 StringBundler msg = new StringBundler(4);
1812
1813 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1814
1815 msg.append("userId=");
1816 msg.append(userId);
1817
1818 msg.append(StringPool.CLOSE_CURLY_BRACE);
1819
1820 throw new NoSuchPhoneException(msg.toString());
1821 }
1822
1823
1830 @Override
1831 public Phone fetchByUserId_First(long userId,
1832 OrderByComparator<Phone> orderByComparator) {
1833 List<Phone> list = findByUserId(userId, 0, 1, orderByComparator);
1834
1835 if (!list.isEmpty()) {
1836 return list.get(0);
1837 }
1838
1839 return null;
1840 }
1841
1842
1850 @Override
1851 public Phone findByUserId_Last(long userId,
1852 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1853 Phone phone = fetchByUserId_Last(userId, orderByComparator);
1854
1855 if (phone != null) {
1856 return phone;
1857 }
1858
1859 StringBundler msg = new StringBundler(4);
1860
1861 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1862
1863 msg.append("userId=");
1864 msg.append(userId);
1865
1866 msg.append(StringPool.CLOSE_CURLY_BRACE);
1867
1868 throw new NoSuchPhoneException(msg.toString());
1869 }
1870
1871
1878 @Override
1879 public Phone fetchByUserId_Last(long userId,
1880 OrderByComparator<Phone> orderByComparator) {
1881 int count = countByUserId(userId);
1882
1883 if (count == 0) {
1884 return null;
1885 }
1886
1887 List<Phone> list = findByUserId(userId, count - 1, count,
1888 orderByComparator);
1889
1890 if (!list.isEmpty()) {
1891 return list.get(0);
1892 }
1893
1894 return null;
1895 }
1896
1897
1906 @Override
1907 public Phone[] findByUserId_PrevAndNext(long phoneId, long userId,
1908 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1909 Phone phone = findByPrimaryKey(phoneId);
1910
1911 Session session = null;
1912
1913 try {
1914 session = openSession();
1915
1916 Phone[] array = new PhoneImpl[3];
1917
1918 array[0] = getByUserId_PrevAndNext(session, phone, userId,
1919 orderByComparator, true);
1920
1921 array[1] = phone;
1922
1923 array[2] = getByUserId_PrevAndNext(session, phone, userId,
1924 orderByComparator, false);
1925
1926 return array;
1927 }
1928 catch (Exception e) {
1929 throw processException(e);
1930 }
1931 finally {
1932 closeSession(session);
1933 }
1934 }
1935
1936 protected Phone getByUserId_PrevAndNext(Session session, Phone phone,
1937 long userId, OrderByComparator<Phone> orderByComparator,
1938 boolean previous) {
1939 StringBundler query = null;
1940
1941 if (orderByComparator != null) {
1942 query = new StringBundler(6 +
1943 (orderByComparator.getOrderByFields().length * 6));
1944 }
1945 else {
1946 query = new StringBundler(3);
1947 }
1948
1949 query.append(_SQL_SELECT_PHONE_WHERE);
1950
1951 query.append(_FINDER_COLUMN_USERID_USERID_2);
1952
1953 if (orderByComparator != null) {
1954 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1955
1956 if (orderByConditionFields.length > 0) {
1957 query.append(WHERE_AND);
1958 }
1959
1960 for (int i = 0; i < orderByConditionFields.length; i++) {
1961 query.append(_ORDER_BY_ENTITY_ALIAS);
1962 query.append(orderByConditionFields[i]);
1963
1964 if ((i + 1) < orderByConditionFields.length) {
1965 if (orderByComparator.isAscending() ^ previous) {
1966 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1967 }
1968 else {
1969 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1970 }
1971 }
1972 else {
1973 if (orderByComparator.isAscending() ^ previous) {
1974 query.append(WHERE_GREATER_THAN);
1975 }
1976 else {
1977 query.append(WHERE_LESSER_THAN);
1978 }
1979 }
1980 }
1981
1982 query.append(ORDER_BY_CLAUSE);
1983
1984 String[] orderByFields = orderByComparator.getOrderByFields();
1985
1986 for (int i = 0; i < orderByFields.length; i++) {
1987 query.append(_ORDER_BY_ENTITY_ALIAS);
1988 query.append(orderByFields[i]);
1989
1990 if ((i + 1) < orderByFields.length) {
1991 if (orderByComparator.isAscending() ^ previous) {
1992 query.append(ORDER_BY_ASC_HAS_NEXT);
1993 }
1994 else {
1995 query.append(ORDER_BY_DESC_HAS_NEXT);
1996 }
1997 }
1998 else {
1999 if (orderByComparator.isAscending() ^ previous) {
2000 query.append(ORDER_BY_ASC);
2001 }
2002 else {
2003 query.append(ORDER_BY_DESC);
2004 }
2005 }
2006 }
2007 }
2008 else {
2009 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2010 }
2011
2012 String sql = query.toString();
2013
2014 Query q = session.createQuery(sql);
2015
2016 q.setFirstResult(0);
2017 q.setMaxResults(2);
2018
2019 QueryPos qPos = QueryPos.getInstance(q);
2020
2021 qPos.add(userId);
2022
2023 if (orderByComparator != null) {
2024 Object[] values = orderByComparator.getOrderByConditionValues(phone);
2025
2026 for (Object value : values) {
2027 qPos.add(value);
2028 }
2029 }
2030
2031 List<Phone> list = q.list();
2032
2033 if (list.size() == 2) {
2034 return list.get(1);
2035 }
2036 else {
2037 return null;
2038 }
2039 }
2040
2041
2046 @Override
2047 public void removeByUserId(long userId) {
2048 for (Phone phone : findByUserId(userId, QueryUtil.ALL_POS,
2049 QueryUtil.ALL_POS, null)) {
2050 remove(phone);
2051 }
2052 }
2053
2054
2060 @Override
2061 public int countByUserId(long userId) {
2062 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2063
2064 Object[] finderArgs = new Object[] { userId };
2065
2066 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2067 this);
2068
2069 if (count == null) {
2070 StringBundler query = new StringBundler(2);
2071
2072 query.append(_SQL_COUNT_PHONE_WHERE);
2073
2074 query.append(_FINDER_COLUMN_USERID_USERID_2);
2075
2076 String sql = query.toString();
2077
2078 Session session = null;
2079
2080 try {
2081 session = openSession();
2082
2083 Query q = session.createQuery(sql);
2084
2085 QueryPos qPos = QueryPos.getInstance(q);
2086
2087 qPos.add(userId);
2088
2089 count = (Long)q.uniqueResult();
2090
2091 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2092 }
2093 catch (Exception e) {
2094 FinderCacheUtil.removeResult(finderPath, finderArgs);
2095
2096 throw processException(e);
2097 }
2098 finally {
2099 closeSession(session);
2100 }
2101 }
2102
2103 return count.intValue();
2104 }
2105
2106 private static final String _FINDER_COLUMN_USERID_USERID_2 = "phone.userId = ?";
2107 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2108 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2109 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
2110 new String[] {
2111 Long.class.getName(), Long.class.getName(),
2112
2113 Integer.class.getName(), Integer.class.getName(),
2114 OrderByComparator.class.getName()
2115 });
2116 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2117 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2118 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
2119 new String[] { Long.class.getName(), Long.class.getName() },
2120 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
2121 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2122 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
2123 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2124 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
2125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2126 new String[] { Long.class.getName(), Long.class.getName() });
2127
2128
2135 @Override
2136 public List<Phone> findByC_C(long companyId, long classNameId) {
2137 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
2138 QueryUtil.ALL_POS, null);
2139 }
2140
2141
2154 @Override
2155 public List<Phone> findByC_C(long companyId, long classNameId, int start,
2156 int end) {
2157 return findByC_C(companyId, classNameId, start, end, null);
2158 }
2159
2160
2174 @Override
2175 public List<Phone> findByC_C(long companyId, long classNameId, int start,
2176 int end, OrderByComparator<Phone> orderByComparator) {
2177 boolean pagination = true;
2178 FinderPath finderPath = null;
2179 Object[] finderArgs = null;
2180
2181 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2182 (orderByComparator == null)) {
2183 pagination = false;
2184 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2185 finderArgs = new Object[] { companyId, classNameId };
2186 }
2187 else {
2188 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2189 finderArgs = new Object[] {
2190 companyId, classNameId,
2191
2192 start, end, orderByComparator
2193 };
2194 }
2195
2196 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
2197 finderArgs, this);
2198
2199 if ((list != null) && !list.isEmpty()) {
2200 for (Phone phone : list) {
2201 if ((companyId != phone.getCompanyId()) ||
2202 (classNameId != phone.getClassNameId())) {
2203 list = null;
2204
2205 break;
2206 }
2207 }
2208 }
2209
2210 if (list == null) {
2211 StringBundler query = null;
2212
2213 if (orderByComparator != null) {
2214 query = new StringBundler(4 +
2215 (orderByComparator.getOrderByFields().length * 3));
2216 }
2217 else {
2218 query = new StringBundler(4);
2219 }
2220
2221 query.append(_SQL_SELECT_PHONE_WHERE);
2222
2223 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2224
2225 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2226
2227 if (orderByComparator != null) {
2228 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2229 orderByComparator);
2230 }
2231 else
2232 if (pagination) {
2233 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2234 }
2235
2236 String sql = query.toString();
2237
2238 Session session = null;
2239
2240 try {
2241 session = openSession();
2242
2243 Query q = session.createQuery(sql);
2244
2245 QueryPos qPos = QueryPos.getInstance(q);
2246
2247 qPos.add(companyId);
2248
2249 qPos.add(classNameId);
2250
2251 if (!pagination) {
2252 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2253 end, false);
2254
2255 Collections.sort(list);
2256
2257 list = Collections.unmodifiableList(list);
2258 }
2259 else {
2260 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2261 end);
2262 }
2263
2264 cacheResult(list);
2265
2266 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2267 }
2268 catch (Exception e) {
2269 FinderCacheUtil.removeResult(finderPath, finderArgs);
2270
2271 throw processException(e);
2272 }
2273 finally {
2274 closeSession(session);
2275 }
2276 }
2277
2278 return list;
2279 }
2280
2281
2290 @Override
2291 public Phone findByC_C_First(long companyId, long classNameId,
2292 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2293 Phone phone = fetchByC_C_First(companyId, classNameId, orderByComparator);
2294
2295 if (phone != null) {
2296 return phone;
2297 }
2298
2299 StringBundler msg = new StringBundler(6);
2300
2301 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2302
2303 msg.append("companyId=");
2304 msg.append(companyId);
2305
2306 msg.append(", classNameId=");
2307 msg.append(classNameId);
2308
2309 msg.append(StringPool.CLOSE_CURLY_BRACE);
2310
2311 throw new NoSuchPhoneException(msg.toString());
2312 }
2313
2314
2322 @Override
2323 public Phone fetchByC_C_First(long companyId, long classNameId,
2324 OrderByComparator<Phone> orderByComparator) {
2325 List<Phone> list = findByC_C(companyId, classNameId, 0, 1,
2326 orderByComparator);
2327
2328 if (!list.isEmpty()) {
2329 return list.get(0);
2330 }
2331
2332 return null;
2333 }
2334
2335
2344 @Override
2345 public Phone findByC_C_Last(long companyId, long classNameId,
2346 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2347 Phone phone = fetchByC_C_Last(companyId, classNameId, orderByComparator);
2348
2349 if (phone != null) {
2350 return phone;
2351 }
2352
2353 StringBundler msg = new StringBundler(6);
2354
2355 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2356
2357 msg.append("companyId=");
2358 msg.append(companyId);
2359
2360 msg.append(", classNameId=");
2361 msg.append(classNameId);
2362
2363 msg.append(StringPool.CLOSE_CURLY_BRACE);
2364
2365 throw new NoSuchPhoneException(msg.toString());
2366 }
2367
2368
2376 @Override
2377 public Phone fetchByC_C_Last(long companyId, long classNameId,
2378 OrderByComparator<Phone> orderByComparator) {
2379 int count = countByC_C(companyId, classNameId);
2380
2381 if (count == 0) {
2382 return null;
2383 }
2384
2385 List<Phone> list = findByC_C(companyId, classNameId, count - 1, count,
2386 orderByComparator);
2387
2388 if (!list.isEmpty()) {
2389 return list.get(0);
2390 }
2391
2392 return null;
2393 }
2394
2395
2405 @Override
2406 public Phone[] findByC_C_PrevAndNext(long phoneId, long companyId,
2407 long classNameId, OrderByComparator<Phone> orderByComparator)
2408 throws NoSuchPhoneException {
2409 Phone phone = findByPrimaryKey(phoneId);
2410
2411 Session session = null;
2412
2413 try {
2414 session = openSession();
2415
2416 Phone[] array = new PhoneImpl[3];
2417
2418 array[0] = getByC_C_PrevAndNext(session, phone, companyId,
2419 classNameId, orderByComparator, true);
2420
2421 array[1] = phone;
2422
2423 array[2] = getByC_C_PrevAndNext(session, phone, companyId,
2424 classNameId, orderByComparator, false);
2425
2426 return array;
2427 }
2428 catch (Exception e) {
2429 throw processException(e);
2430 }
2431 finally {
2432 closeSession(session);
2433 }
2434 }
2435
2436 protected Phone getByC_C_PrevAndNext(Session session, Phone phone,
2437 long companyId, long classNameId,
2438 OrderByComparator<Phone> orderByComparator, boolean previous) {
2439 StringBundler query = null;
2440
2441 if (orderByComparator != null) {
2442 query = new StringBundler(6 +
2443 (orderByComparator.getOrderByFields().length * 6));
2444 }
2445 else {
2446 query = new StringBundler(3);
2447 }
2448
2449 query.append(_SQL_SELECT_PHONE_WHERE);
2450
2451 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2452
2453 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2454
2455 if (orderByComparator != null) {
2456 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2457
2458 if (orderByConditionFields.length > 0) {
2459 query.append(WHERE_AND);
2460 }
2461
2462 for (int i = 0; i < orderByConditionFields.length; i++) {
2463 query.append(_ORDER_BY_ENTITY_ALIAS);
2464 query.append(orderByConditionFields[i]);
2465
2466 if ((i + 1) < orderByConditionFields.length) {
2467 if (orderByComparator.isAscending() ^ previous) {
2468 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2469 }
2470 else {
2471 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2472 }
2473 }
2474 else {
2475 if (orderByComparator.isAscending() ^ previous) {
2476 query.append(WHERE_GREATER_THAN);
2477 }
2478 else {
2479 query.append(WHERE_LESSER_THAN);
2480 }
2481 }
2482 }
2483
2484 query.append(ORDER_BY_CLAUSE);
2485
2486 String[] orderByFields = orderByComparator.getOrderByFields();
2487
2488 for (int i = 0; i < orderByFields.length; i++) {
2489 query.append(_ORDER_BY_ENTITY_ALIAS);
2490 query.append(orderByFields[i]);
2491
2492 if ((i + 1) < orderByFields.length) {
2493 if (orderByComparator.isAscending() ^ previous) {
2494 query.append(ORDER_BY_ASC_HAS_NEXT);
2495 }
2496 else {
2497 query.append(ORDER_BY_DESC_HAS_NEXT);
2498 }
2499 }
2500 else {
2501 if (orderByComparator.isAscending() ^ previous) {
2502 query.append(ORDER_BY_ASC);
2503 }
2504 else {
2505 query.append(ORDER_BY_DESC);
2506 }
2507 }
2508 }
2509 }
2510 else {
2511 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2512 }
2513
2514 String sql = query.toString();
2515
2516 Query q = session.createQuery(sql);
2517
2518 q.setFirstResult(0);
2519 q.setMaxResults(2);
2520
2521 QueryPos qPos = QueryPos.getInstance(q);
2522
2523 qPos.add(companyId);
2524
2525 qPos.add(classNameId);
2526
2527 if (orderByComparator != null) {
2528 Object[] values = orderByComparator.getOrderByConditionValues(phone);
2529
2530 for (Object value : values) {
2531 qPos.add(value);
2532 }
2533 }
2534
2535 List<Phone> list = q.list();
2536
2537 if (list.size() == 2) {
2538 return list.get(1);
2539 }
2540 else {
2541 return null;
2542 }
2543 }
2544
2545
2551 @Override
2552 public void removeByC_C(long companyId, long classNameId) {
2553 for (Phone phone : findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
2554 QueryUtil.ALL_POS, null)) {
2555 remove(phone);
2556 }
2557 }
2558
2559
2566 @Override
2567 public int countByC_C(long companyId, long classNameId) {
2568 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
2569
2570 Object[] finderArgs = new Object[] { companyId, classNameId };
2571
2572 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2573 this);
2574
2575 if (count == null) {
2576 StringBundler query = new StringBundler(3);
2577
2578 query.append(_SQL_COUNT_PHONE_WHERE);
2579
2580 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2581
2582 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2583
2584 String sql = query.toString();
2585
2586 Session session = null;
2587
2588 try {
2589 session = openSession();
2590
2591 Query q = session.createQuery(sql);
2592
2593 QueryPos qPos = QueryPos.getInstance(q);
2594
2595 qPos.add(companyId);
2596
2597 qPos.add(classNameId);
2598
2599 count = (Long)q.uniqueResult();
2600
2601 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2602 }
2603 catch (Exception e) {
2604 FinderCacheUtil.removeResult(finderPath, finderArgs);
2605
2606 throw processException(e);
2607 }
2608 finally {
2609 closeSession(session);
2610 }
2611 }
2612
2613 return count.intValue();
2614 }
2615
2616 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
2617 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "phone.classNameId = ?";
2618 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2619 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2620 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
2621 new String[] {
2622 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2623
2624 Integer.class.getName(), Integer.class.getName(),
2625 OrderByComparator.class.getName()
2626 });
2627 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2628 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2629 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
2630 new String[] {
2631 Long.class.getName(), Long.class.getName(), Long.class.getName()
2632 },
2633 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
2634 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2635 PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
2636 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
2637 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2638 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
2639 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
2640 new String[] {
2641 Long.class.getName(), Long.class.getName(), Long.class.getName()
2642 });
2643
2644
2652 @Override
2653 public List<Phone> findByC_C_C(long companyId, long classNameId,
2654 long classPK) {
2655 return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
2656 QueryUtil.ALL_POS, null);
2657 }
2658
2659
2673 @Override
2674 public List<Phone> findByC_C_C(long companyId, long classNameId,
2675 long classPK, int start, int end) {
2676 return findByC_C_C(companyId, classNameId, classPK, start, end, null);
2677 }
2678
2679
2694 @Override
2695 public List<Phone> findByC_C_C(long companyId, long classNameId,
2696 long classPK, int start, int end,
2697 OrderByComparator<Phone> orderByComparator) {
2698 boolean pagination = true;
2699 FinderPath finderPath = null;
2700 Object[] finderArgs = null;
2701
2702 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2703 (orderByComparator == null)) {
2704 pagination = false;
2705 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
2706 finderArgs = new Object[] { companyId, classNameId, classPK };
2707 }
2708 else {
2709 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
2710 finderArgs = new Object[] {
2711 companyId, classNameId, classPK,
2712
2713 start, end, orderByComparator
2714 };
2715 }
2716
2717 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
2718 finderArgs, this);
2719
2720 if ((list != null) && !list.isEmpty()) {
2721 for (Phone phone : list) {
2722 if ((companyId != phone.getCompanyId()) ||
2723 (classNameId != phone.getClassNameId()) ||
2724 (classPK != phone.getClassPK())) {
2725 list = null;
2726
2727 break;
2728 }
2729 }
2730 }
2731
2732 if (list == null) {
2733 StringBundler query = null;
2734
2735 if (orderByComparator != null) {
2736 query = new StringBundler(5 +
2737 (orderByComparator.getOrderByFields().length * 3));
2738 }
2739 else {
2740 query = new StringBundler(5);
2741 }
2742
2743 query.append(_SQL_SELECT_PHONE_WHERE);
2744
2745 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2746
2747 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2748
2749 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2750
2751 if (orderByComparator != null) {
2752 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2753 orderByComparator);
2754 }
2755 else
2756 if (pagination) {
2757 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2758 }
2759
2760 String sql = query.toString();
2761
2762 Session session = null;
2763
2764 try {
2765 session = openSession();
2766
2767 Query q = session.createQuery(sql);
2768
2769 QueryPos qPos = QueryPos.getInstance(q);
2770
2771 qPos.add(companyId);
2772
2773 qPos.add(classNameId);
2774
2775 qPos.add(classPK);
2776
2777 if (!pagination) {
2778 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2779 end, false);
2780
2781 Collections.sort(list);
2782
2783 list = Collections.unmodifiableList(list);
2784 }
2785 else {
2786 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2787 end);
2788 }
2789
2790 cacheResult(list);
2791
2792 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2793 }
2794 catch (Exception e) {
2795 FinderCacheUtil.removeResult(finderPath, finderArgs);
2796
2797 throw processException(e);
2798 }
2799 finally {
2800 closeSession(session);
2801 }
2802 }
2803
2804 return list;
2805 }
2806
2807
2817 @Override
2818 public Phone findByC_C_C_First(long companyId, long classNameId,
2819 long classPK, OrderByComparator<Phone> orderByComparator)
2820 throws NoSuchPhoneException {
2821 Phone phone = fetchByC_C_C_First(companyId, classNameId, classPK,
2822 orderByComparator);
2823
2824 if (phone != null) {
2825 return phone;
2826 }
2827
2828 StringBundler msg = new StringBundler(8);
2829
2830 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2831
2832 msg.append("companyId=");
2833 msg.append(companyId);
2834
2835 msg.append(", classNameId=");
2836 msg.append(classNameId);
2837
2838 msg.append(", classPK=");
2839 msg.append(classPK);
2840
2841 msg.append(StringPool.CLOSE_CURLY_BRACE);
2842
2843 throw new NoSuchPhoneException(msg.toString());
2844 }
2845
2846
2855 @Override
2856 public Phone fetchByC_C_C_First(long companyId, long classNameId,
2857 long classPK, OrderByComparator<Phone> orderByComparator) {
2858 List<Phone> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
2859 orderByComparator);
2860
2861 if (!list.isEmpty()) {
2862 return list.get(0);
2863 }
2864
2865 return null;
2866 }
2867
2868
2878 @Override
2879 public Phone findByC_C_C_Last(long companyId, long classNameId,
2880 long classPK, OrderByComparator<Phone> orderByComparator)
2881 throws NoSuchPhoneException {
2882 Phone phone = fetchByC_C_C_Last(companyId, classNameId, classPK,
2883 orderByComparator);
2884
2885 if (phone != null) {
2886 return phone;
2887 }
2888
2889 StringBundler msg = new StringBundler(8);
2890
2891 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2892
2893 msg.append("companyId=");
2894 msg.append(companyId);
2895
2896 msg.append(", classNameId=");
2897 msg.append(classNameId);
2898
2899 msg.append(", classPK=");
2900 msg.append(classPK);
2901
2902 msg.append(StringPool.CLOSE_CURLY_BRACE);
2903
2904 throw new NoSuchPhoneException(msg.toString());
2905 }
2906
2907
2916 @Override
2917 public Phone fetchByC_C_C_Last(long companyId, long classNameId,
2918 long classPK, OrderByComparator<Phone> orderByComparator) {
2919 int count = countByC_C_C(companyId, classNameId, classPK);
2920
2921 if (count == 0) {
2922 return null;
2923 }
2924
2925 List<Phone> list = findByC_C_C(companyId, classNameId, classPK,
2926 count - 1, count, orderByComparator);
2927
2928 if (!list.isEmpty()) {
2929 return list.get(0);
2930 }
2931
2932 return null;
2933 }
2934
2935
2946 @Override
2947 public Phone[] findByC_C_C_PrevAndNext(long phoneId, long companyId,
2948 long classNameId, long classPK,
2949 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2950 Phone phone = findByPrimaryKey(phoneId);
2951
2952 Session session = null;
2953
2954 try {
2955 session = openSession();
2956
2957 Phone[] array = new PhoneImpl[3];
2958
2959 array[0] = getByC_C_C_PrevAndNext(session, phone, companyId,
2960 classNameId, classPK, orderByComparator, true);
2961
2962 array[1] = phone;
2963
2964 array[2] = getByC_C_C_PrevAndNext(session, phone, companyId,
2965 classNameId, classPK, orderByComparator, false);
2966
2967 return array;
2968 }
2969 catch (Exception e) {
2970 throw processException(e);
2971 }
2972 finally {
2973 closeSession(session);
2974 }
2975 }
2976
2977 protected Phone getByC_C_C_PrevAndNext(Session session, Phone phone,
2978 long companyId, long classNameId, long classPK,
2979 OrderByComparator<Phone> orderByComparator, boolean previous) {
2980 StringBundler query = null;
2981
2982 if (orderByComparator != null) {
2983 query = new StringBundler(6 +
2984 (orderByComparator.getOrderByFields().length * 6));
2985 }
2986 else {
2987 query = new StringBundler(3);
2988 }
2989
2990 query.append(_SQL_SELECT_PHONE_WHERE);
2991
2992 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2993
2994 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2995
2996 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2997
2998 if (orderByComparator != null) {
2999 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3000
3001 if (orderByConditionFields.length > 0) {
3002 query.append(WHERE_AND);
3003 }
3004
3005 for (int i = 0; i < orderByConditionFields.length; i++) {
3006 query.append(_ORDER_BY_ENTITY_ALIAS);
3007 query.append(orderByConditionFields[i]);
3008
3009 if ((i + 1) < orderByConditionFields.length) {
3010 if (orderByComparator.isAscending() ^ previous) {
3011 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3012 }
3013 else {
3014 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3015 }
3016 }
3017 else {
3018 if (orderByComparator.isAscending() ^ previous) {
3019 query.append(WHERE_GREATER_THAN);
3020 }
3021 else {
3022 query.append(WHERE_LESSER_THAN);
3023 }
3024 }
3025 }
3026
3027 query.append(ORDER_BY_CLAUSE);
3028
3029 String[] orderByFields = orderByComparator.getOrderByFields();
3030
3031 for (int i = 0; i < orderByFields.length; i++) {
3032 query.append(_ORDER_BY_ENTITY_ALIAS);
3033 query.append(orderByFields[i]);
3034
3035 if ((i + 1) < orderByFields.length) {
3036 if (orderByComparator.isAscending() ^ previous) {
3037 query.append(ORDER_BY_ASC_HAS_NEXT);
3038 }
3039 else {
3040 query.append(ORDER_BY_DESC_HAS_NEXT);
3041 }
3042 }
3043 else {
3044 if (orderByComparator.isAscending() ^ previous) {
3045 query.append(ORDER_BY_ASC);
3046 }
3047 else {
3048 query.append(ORDER_BY_DESC);
3049 }
3050 }
3051 }
3052 }
3053 else {
3054 query.append(PhoneModelImpl.ORDER_BY_JPQL);
3055 }
3056
3057 String sql = query.toString();
3058
3059 Query q = session.createQuery(sql);
3060
3061 q.setFirstResult(0);
3062 q.setMaxResults(2);
3063
3064 QueryPos qPos = QueryPos.getInstance(q);
3065
3066 qPos.add(companyId);
3067
3068 qPos.add(classNameId);
3069
3070 qPos.add(classPK);
3071
3072 if (orderByComparator != null) {
3073 Object[] values = orderByComparator.getOrderByConditionValues(phone);
3074
3075 for (Object value : values) {
3076 qPos.add(value);
3077 }
3078 }
3079
3080 List<Phone> list = q.list();
3081
3082 if (list.size() == 2) {
3083 return list.get(1);
3084 }
3085 else {
3086 return null;
3087 }
3088 }
3089
3090
3097 @Override
3098 public void removeByC_C_C(long companyId, long classNameId, long classPK) {
3099 for (Phone phone : findByC_C_C(companyId, classNameId, classPK,
3100 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3101 remove(phone);
3102 }
3103 }
3104
3105
3113 @Override
3114 public int countByC_C_C(long companyId, long classNameId, long classPK) {
3115 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
3116
3117 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
3118
3119 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3120 this);
3121
3122 if (count == null) {
3123 StringBundler query = new StringBundler(4);
3124
3125 query.append(_SQL_COUNT_PHONE_WHERE);
3126
3127 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3128
3129 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3130
3131 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3132
3133 String sql = query.toString();
3134
3135 Session session = null;
3136
3137 try {
3138 session = openSession();
3139
3140 Query q = session.createQuery(sql);
3141
3142 QueryPos qPos = QueryPos.getInstance(q);
3143
3144 qPos.add(companyId);
3145
3146 qPos.add(classNameId);
3147
3148 qPos.add(classPK);
3149
3150 count = (Long)q.uniqueResult();
3151
3152 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3153 }
3154 catch (Exception e) {
3155 FinderCacheUtil.removeResult(finderPath, finderArgs);
3156
3157 throw processException(e);
3158 }
3159 finally {
3160 closeSession(session);
3161 }
3162 }
3163
3164 return count.intValue();
3165 }
3166
3167 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
3168 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
3169 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "phone.classPK = ?";
3170 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3171 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
3172 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_P",
3173 new String[] {
3174 Long.class.getName(), Long.class.getName(), Long.class.getName(),
3175 Boolean.class.getName(),
3176
3177 Integer.class.getName(), Integer.class.getName(),
3178 OrderByComparator.class.getName()
3179 });
3180 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P =
3181 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3182 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
3183 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_P",
3184 new String[] {
3185 Long.class.getName(), Long.class.getName(), Long.class.getName(),
3186 Boolean.class.getName()
3187 },
3188 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
3189 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3190 PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
3191 PhoneModelImpl.PRIMARY_COLUMN_BITMASK |
3192 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
3193 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3194 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
3195 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_P",
3196 new String[] {
3197 Long.class.getName(), Long.class.getName(), Long.class.getName(),
3198 Boolean.class.getName()
3199 });
3200
3201
3210 @Override
3211 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3212 long classPK, boolean primary) {
3213 return findByC_C_C_P(companyId, classNameId, classPK, primary,
3214 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3215 }
3216
3217
3232 @Override
3233 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3234 long classPK, boolean primary, int start, int end) {
3235 return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
3236 end, null);
3237 }
3238
3239
3255 @Override
3256 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3257 long classPK, boolean primary, int start, int end,
3258 OrderByComparator<Phone> orderByComparator) {
3259 boolean pagination = true;
3260 FinderPath finderPath = null;
3261 Object[] finderArgs = null;
3262
3263 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3264 (orderByComparator == null)) {
3265 pagination = false;
3266 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P;
3267 finderArgs = new Object[] { companyId, classNameId, classPK, primary };
3268 }
3269 else {
3270 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
3271 finderArgs = new Object[] {
3272 companyId, classNameId, classPK, primary,
3273
3274 start, end, orderByComparator
3275 };
3276 }
3277
3278 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
3279 finderArgs, this);
3280
3281 if ((list != null) && !list.isEmpty()) {
3282 for (Phone phone : list) {
3283 if ((companyId != phone.getCompanyId()) ||
3284 (classNameId != phone.getClassNameId()) ||
3285 (classPK != phone.getClassPK()) ||
3286 (primary != phone.getPrimary())) {
3287 list = null;
3288
3289 break;
3290 }
3291 }
3292 }
3293
3294 if (list == null) {
3295 StringBundler query = null;
3296
3297 if (orderByComparator != null) {
3298 query = new StringBundler(6 +
3299 (orderByComparator.getOrderByFields().length * 3));
3300 }
3301 else {
3302 query = new StringBundler(6);
3303 }
3304
3305 query.append(_SQL_SELECT_PHONE_WHERE);
3306
3307 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3308
3309 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3310
3311 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3312
3313 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3314
3315 if (orderByComparator != null) {
3316 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3317 orderByComparator);
3318 }
3319 else
3320 if (pagination) {
3321 query.append(PhoneModelImpl.ORDER_BY_JPQL);
3322 }
3323
3324 String sql = query.toString();
3325
3326 Session session = null;
3327
3328 try {
3329 session = openSession();
3330
3331 Query q = session.createQuery(sql);
3332
3333 QueryPos qPos = QueryPos.getInstance(q);
3334
3335 qPos.add(companyId);
3336
3337 qPos.add(classNameId);
3338
3339 qPos.add(classPK);
3340
3341 qPos.add(primary);
3342
3343 if (!pagination) {
3344 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
3345 end, false);
3346
3347 Collections.sort(list);
3348
3349 list = Collections.unmodifiableList(list);
3350 }
3351 else {
3352 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
3353 end);
3354 }
3355
3356 cacheResult(list);
3357
3358 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3359 }
3360 catch (Exception e) {
3361 FinderCacheUtil.removeResult(finderPath, finderArgs);
3362
3363 throw processException(e);
3364 }
3365 finally {
3366 closeSession(session);
3367 }
3368 }
3369
3370 return list;
3371 }
3372
3373
3384 @Override
3385 public Phone findByC_C_C_P_First(long companyId, long classNameId,
3386 long classPK, boolean primary,
3387 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3388 Phone phone = fetchByC_C_C_P_First(companyId, classNameId, classPK,
3389 primary, orderByComparator);
3390
3391 if (phone != null) {
3392 return phone;
3393 }
3394
3395 StringBundler msg = new StringBundler(10);
3396
3397 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3398
3399 msg.append("companyId=");
3400 msg.append(companyId);
3401
3402 msg.append(", classNameId=");
3403 msg.append(classNameId);
3404
3405 msg.append(", classPK=");
3406 msg.append(classPK);
3407
3408 msg.append(", primary=");
3409 msg.append(primary);
3410
3411 msg.append(StringPool.CLOSE_CURLY_BRACE);
3412
3413 throw new NoSuchPhoneException(msg.toString());
3414 }
3415
3416
3426 @Override
3427 public Phone fetchByC_C_C_P_First(long companyId, long classNameId,
3428 long classPK, boolean primary,
3429 OrderByComparator<Phone> orderByComparator) {
3430 List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
3431 primary, 0, 1, orderByComparator);
3432
3433 if (!list.isEmpty()) {
3434 return list.get(0);
3435 }
3436
3437 return null;
3438 }
3439
3440
3451 @Override
3452 public Phone findByC_C_C_P_Last(long companyId, long classNameId,
3453 long classPK, boolean primary,
3454 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3455 Phone phone = fetchByC_C_C_P_Last(companyId, classNameId, classPK,
3456 primary, orderByComparator);
3457
3458 if (phone != null) {
3459 return phone;
3460 }
3461
3462 StringBundler msg = new StringBundler(10);
3463
3464 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3465
3466 msg.append("companyId=");
3467 msg.append(companyId);
3468
3469 msg.append(", classNameId=");
3470 msg.append(classNameId);
3471
3472 msg.append(", classPK=");
3473 msg.append(classPK);
3474
3475 msg.append(", primary=");
3476 msg.append(primary);
3477
3478 msg.append(StringPool.CLOSE_CURLY_BRACE);
3479
3480 throw new NoSuchPhoneException(msg.toString());
3481 }
3482
3483
3493 @Override
3494 public Phone fetchByC_C_C_P_Last(long companyId, long classNameId,
3495 long classPK, boolean primary,
3496 OrderByComparator<Phone> orderByComparator) {
3497 int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
3498
3499 if (count == 0) {
3500 return null;
3501 }
3502
3503 List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
3504 primary, count - 1, count, orderByComparator);
3505
3506 if (!list.isEmpty()) {
3507 return list.get(0);
3508 }
3509
3510 return null;
3511 }
3512
3513
3525 @Override
3526 public Phone[] findByC_C_C_P_PrevAndNext(long phoneId, long companyId,
3527 long classNameId, long classPK, boolean primary,
3528 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3529 Phone phone = findByPrimaryKey(phoneId);
3530
3531 Session session = null;
3532
3533 try {
3534 session = openSession();
3535
3536 Phone[] array = new PhoneImpl[3];
3537
3538 array[0] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
3539 classNameId, classPK, primary, orderByComparator, true);
3540
3541 array[1] = phone;
3542
3543 array[2] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
3544 classNameId, classPK, primary, orderByComparator, false);
3545
3546 return array;
3547 }
3548 catch (Exception e) {
3549 throw processException(e);
3550 }
3551 finally {
3552 closeSession(session);
3553 }
3554 }
3555
3556 protected Phone getByC_C_C_P_PrevAndNext(Session session, Phone phone,
3557 long companyId, long classNameId, long classPK, boolean primary,
3558 OrderByComparator<Phone> orderByComparator, boolean previous) {
3559 StringBundler query = null;
3560
3561 if (orderByComparator != null) {
3562 query = new StringBundler(6 +
3563 (orderByComparator.getOrderByFields().length * 6));
3564 }
3565 else {
3566 query = new StringBundler(3);
3567 }
3568
3569 query.append(_SQL_SELECT_PHONE_WHERE);
3570
3571 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3572
3573 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3574
3575 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3576
3577 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3578
3579 if (orderByComparator != null) {
3580 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3581
3582 if (orderByConditionFields.length > 0) {
3583 query.append(WHERE_AND);
3584 }
3585
3586 for (int i = 0; i < orderByConditionFields.length; i++) {
3587 query.append(_ORDER_BY_ENTITY_ALIAS);
3588 query.append(orderByConditionFields[i]);
3589
3590 if ((i + 1) < orderByConditionFields.length) {
3591 if (orderByComparator.isAscending() ^ previous) {
3592 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3593 }
3594 else {
3595 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3596 }
3597 }
3598 else {
3599 if (orderByComparator.isAscending() ^ previous) {
3600 query.append(WHERE_GREATER_THAN);
3601 }
3602 else {
3603 query.append(WHERE_LESSER_THAN);
3604 }
3605 }
3606 }
3607
3608 query.append(ORDER_BY_CLAUSE);
3609
3610 String[] orderByFields = orderByComparator.getOrderByFields();
3611
3612 for (int i = 0; i < orderByFields.length; i++) {
3613 query.append(_ORDER_BY_ENTITY_ALIAS);
3614 query.append(orderByFields[i]);
3615
3616 if ((i + 1) < orderByFields.length) {
3617 if (orderByComparator.isAscending() ^ previous) {
3618 query.append(ORDER_BY_ASC_HAS_NEXT);
3619 }
3620 else {
3621 query.append(ORDER_BY_DESC_HAS_NEXT);
3622 }
3623 }
3624 else {
3625 if (orderByComparator.isAscending() ^ previous) {
3626 query.append(ORDER_BY_ASC);
3627 }
3628 else {
3629 query.append(ORDER_BY_DESC);
3630 }
3631 }
3632 }
3633 }
3634 else {
3635 query.append(PhoneModelImpl.ORDER_BY_JPQL);
3636 }
3637
3638 String sql = query.toString();
3639
3640 Query q = session.createQuery(sql);
3641
3642 q.setFirstResult(0);
3643 q.setMaxResults(2);
3644
3645 QueryPos qPos = QueryPos.getInstance(q);
3646
3647 qPos.add(companyId);
3648
3649 qPos.add(classNameId);
3650
3651 qPos.add(classPK);
3652
3653 qPos.add(primary);
3654
3655 if (orderByComparator != null) {
3656 Object[] values = orderByComparator.getOrderByConditionValues(phone);
3657
3658 for (Object value : values) {
3659 qPos.add(value);
3660 }
3661 }
3662
3663 List<Phone> list = q.list();
3664
3665 if (list.size() == 2) {
3666 return list.get(1);
3667 }
3668 else {
3669 return null;
3670 }
3671 }
3672
3673
3681 @Override
3682 public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
3683 boolean primary) {
3684 for (Phone phone : findByC_C_C_P(companyId, classNameId, classPK,
3685 primary, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3686 remove(phone);
3687 }
3688 }
3689
3690
3699 @Override
3700 public int countByC_C_C_P(long companyId, long classNameId, long classPK,
3701 boolean primary) {
3702 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C_P;
3703
3704 Object[] finderArgs = new Object[] {
3705 companyId, classNameId, classPK, primary
3706 };
3707
3708 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3709 this);
3710
3711 if (count == null) {
3712 StringBundler query = new StringBundler(5);
3713
3714 query.append(_SQL_COUNT_PHONE_WHERE);
3715
3716 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3717
3718 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3719
3720 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3721
3722 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3723
3724 String sql = query.toString();
3725
3726 Session session = null;
3727
3728 try {
3729 session = openSession();
3730
3731 Query q = session.createQuery(sql);
3732
3733 QueryPos qPos = QueryPos.getInstance(q);
3734
3735 qPos.add(companyId);
3736
3737 qPos.add(classNameId);
3738
3739 qPos.add(classPK);
3740
3741 qPos.add(primary);
3742
3743 count = (Long)q.uniqueResult();
3744
3745 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3746 }
3747 catch (Exception e) {
3748 FinderCacheUtil.removeResult(finderPath, finderArgs);
3749
3750 throw processException(e);
3751 }
3752 finally {
3753 closeSession(session);
3754 }
3755 }
3756
3757 return count.intValue();
3758 }
3759
3760 private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "phone.companyId = ? AND ";
3761 private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
3762 private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "phone.classPK = ? AND ";
3763 private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "phone.primary = ?";
3764
3765 public PhonePersistenceImpl() {
3766 setModelClass(Phone.class);
3767 }
3768
3769
3774 @Override
3775 public void cacheResult(Phone phone) {
3776 EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3777 PhoneImpl.class, phone.getPrimaryKey(), phone);
3778
3779 phone.resetOriginalValues();
3780 }
3781
3782
3787 @Override
3788 public void cacheResult(List<Phone> phones) {
3789 for (Phone phone : phones) {
3790 if (EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3791 PhoneImpl.class, phone.getPrimaryKey()) == null) {
3792 cacheResult(phone);
3793 }
3794 else {
3795 phone.resetOriginalValues();
3796 }
3797 }
3798 }
3799
3800
3807 @Override
3808 public void clearCache() {
3809 EntityCacheUtil.clearCache(PhoneImpl.class);
3810
3811 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3812 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3813 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3814 }
3815
3816
3823 @Override
3824 public void clearCache(Phone phone) {
3825 EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3826 PhoneImpl.class, phone.getPrimaryKey());
3827
3828 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3829 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3830 }
3831
3832 @Override
3833 public void clearCache(List<Phone> phones) {
3834 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3835 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3836
3837 for (Phone phone : phones) {
3838 EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3839 PhoneImpl.class, phone.getPrimaryKey());
3840 }
3841 }
3842
3843
3849 @Override
3850 public Phone create(long phoneId) {
3851 Phone phone = new PhoneImpl();
3852
3853 phone.setNew(true);
3854 phone.setPrimaryKey(phoneId);
3855
3856 String uuid = PortalUUIDUtil.generate();
3857
3858 phone.setUuid(uuid);
3859
3860 return phone;
3861 }
3862
3863
3870 @Override
3871 public Phone remove(long phoneId) throws NoSuchPhoneException {
3872 return remove((Serializable)phoneId);
3873 }
3874
3875
3882 @Override
3883 public Phone remove(Serializable primaryKey) throws NoSuchPhoneException {
3884 Session session = null;
3885
3886 try {
3887 session = openSession();
3888
3889 Phone phone = (Phone)session.get(PhoneImpl.class, primaryKey);
3890
3891 if (phone == null) {
3892 if (_log.isWarnEnabled()) {
3893 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3894 }
3895
3896 throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3897 primaryKey);
3898 }
3899
3900 return remove(phone);
3901 }
3902 catch (NoSuchPhoneException nsee) {
3903 throw nsee;
3904 }
3905 catch (Exception e) {
3906 throw processException(e);
3907 }
3908 finally {
3909 closeSession(session);
3910 }
3911 }
3912
3913 @Override
3914 protected Phone removeImpl(Phone phone) {
3915 phone = toUnwrappedModel(phone);
3916
3917 Session session = null;
3918
3919 try {
3920 session = openSession();
3921
3922 if (!session.contains(phone)) {
3923 phone = (Phone)session.get(PhoneImpl.class,
3924 phone.getPrimaryKeyObj());
3925 }
3926
3927 if (phone != null) {
3928 session.delete(phone);
3929 }
3930 }
3931 catch (Exception e) {
3932 throw processException(e);
3933 }
3934 finally {
3935 closeSession(session);
3936 }
3937
3938 if (phone != null) {
3939 clearCache(phone);
3940 }
3941
3942 return phone;
3943 }
3944
3945 @Override
3946 public Phone updateImpl(Phone phone) {
3947 phone = toUnwrappedModel(phone);
3948
3949 boolean isNew = phone.isNew();
3950
3951 PhoneModelImpl phoneModelImpl = (PhoneModelImpl)phone;
3952
3953 if (Validator.isNull(phone.getUuid())) {
3954 String uuid = PortalUUIDUtil.generate();
3955
3956 phone.setUuid(uuid);
3957 }
3958
3959 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
3960
3961 Date now = new Date();
3962
3963 if (isNew && (phone.getCreateDate() == null)) {
3964 if (serviceContext == null) {
3965 phone.setCreateDate(now);
3966 }
3967 else {
3968 phone.setCreateDate(serviceContext.getCreateDate(now));
3969 }
3970 }
3971
3972 if (!phoneModelImpl.hasSetModifiedDate()) {
3973 if (serviceContext == null) {
3974 phone.setModifiedDate(now);
3975 }
3976 else {
3977 phone.setModifiedDate(serviceContext.getModifiedDate(now));
3978 }
3979 }
3980
3981 Session session = null;
3982
3983 try {
3984 session = openSession();
3985
3986 if (phone.isNew()) {
3987 session.save(phone);
3988
3989 phone.setNew(false);
3990 }
3991 else {
3992 session.merge(phone);
3993 }
3994 }
3995 catch (Exception e) {
3996 throw processException(e);
3997 }
3998 finally {
3999 closeSession(session);
4000 }
4001
4002 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4003
4004 if (isNew || !PhoneModelImpl.COLUMN_BITMASK_ENABLED) {
4005 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4006 }
4007
4008 else {
4009 if ((phoneModelImpl.getColumnBitmask() &
4010 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4011 Object[] args = new Object[] { phoneModelImpl.getOriginalUuid() };
4012
4013 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4014 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4015 args);
4016
4017 args = new Object[] { phoneModelImpl.getUuid() };
4018
4019 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4020 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4021 args);
4022 }
4023
4024 if ((phoneModelImpl.getColumnBitmask() &
4025 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4026 Object[] args = new Object[] {
4027 phoneModelImpl.getOriginalUuid(),
4028 phoneModelImpl.getOriginalCompanyId()
4029 };
4030
4031 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4032 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4033 args);
4034
4035 args = new Object[] {
4036 phoneModelImpl.getUuid(), phoneModelImpl.getCompanyId()
4037 };
4038
4039 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4040 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4041 args);
4042 }
4043
4044 if ((phoneModelImpl.getColumnBitmask() &
4045 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4046 Object[] args = new Object[] {
4047 phoneModelImpl.getOriginalCompanyId()
4048 };
4049
4050 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4051 args);
4052 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4053 args);
4054
4055 args = new Object[] { phoneModelImpl.getCompanyId() };
4056
4057 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4058 args);
4059 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4060 args);
4061 }
4062
4063 if ((phoneModelImpl.getColumnBitmask() &
4064 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
4065 Object[] args = new Object[] { phoneModelImpl.getOriginalUserId() };
4066
4067 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4068 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4069 args);
4070
4071 args = new Object[] { phoneModelImpl.getUserId() };
4072
4073 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4074 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4075 args);
4076 }
4077
4078 if ((phoneModelImpl.getColumnBitmask() &
4079 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
4080 Object[] args = new Object[] {
4081 phoneModelImpl.getOriginalCompanyId(),
4082 phoneModelImpl.getOriginalClassNameId()
4083 };
4084
4085 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4086 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4087 args);
4088
4089 args = new Object[] {
4090 phoneModelImpl.getCompanyId(),
4091 phoneModelImpl.getClassNameId()
4092 };
4093
4094 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4095 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4096 args);
4097 }
4098
4099 if ((phoneModelImpl.getColumnBitmask() &
4100 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
4101 Object[] args = new Object[] {
4102 phoneModelImpl.getOriginalCompanyId(),
4103 phoneModelImpl.getOriginalClassNameId(),
4104 phoneModelImpl.getOriginalClassPK()
4105 };
4106
4107 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4108 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4109 args);
4110
4111 args = new Object[] {
4112 phoneModelImpl.getCompanyId(),
4113 phoneModelImpl.getClassNameId(),
4114 phoneModelImpl.getClassPK()
4115 };
4116
4117 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4118 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4119 args);
4120 }
4121
4122 if ((phoneModelImpl.getColumnBitmask() &
4123 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P.getColumnBitmask()) != 0) {
4124 Object[] args = new Object[] {
4125 phoneModelImpl.getOriginalCompanyId(),
4126 phoneModelImpl.getOriginalClassNameId(),
4127 phoneModelImpl.getOriginalClassPK(),
4128 phoneModelImpl.getOriginalPrimary()
4129 };
4130
4131 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4132 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4133 args);
4134
4135 args = new Object[] {
4136 phoneModelImpl.getCompanyId(),
4137 phoneModelImpl.getClassNameId(),
4138 phoneModelImpl.getClassPK(), phoneModelImpl.getPrimary()
4139 };
4140
4141 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4142 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4143 args);
4144 }
4145 }
4146
4147 EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4148 PhoneImpl.class, phone.getPrimaryKey(), phone, false);
4149
4150 phone.resetOriginalValues();
4151
4152 return phone;
4153 }
4154
4155 protected Phone toUnwrappedModel(Phone phone) {
4156 if (phone instanceof PhoneImpl) {
4157 return phone;
4158 }
4159
4160 PhoneImpl phoneImpl = new PhoneImpl();
4161
4162 phoneImpl.setNew(phone.isNew());
4163 phoneImpl.setPrimaryKey(phone.getPrimaryKey());
4164
4165 phoneImpl.setMvccVersion(phone.getMvccVersion());
4166 phoneImpl.setUuid(phone.getUuid());
4167 phoneImpl.setPhoneId(phone.getPhoneId());
4168 phoneImpl.setCompanyId(phone.getCompanyId());
4169 phoneImpl.setUserId(phone.getUserId());
4170 phoneImpl.setUserName(phone.getUserName());
4171 phoneImpl.setCreateDate(phone.getCreateDate());
4172 phoneImpl.setModifiedDate(phone.getModifiedDate());
4173 phoneImpl.setClassNameId(phone.getClassNameId());
4174 phoneImpl.setClassPK(phone.getClassPK());
4175 phoneImpl.setNumber(phone.getNumber());
4176 phoneImpl.setExtension(phone.getExtension());
4177 phoneImpl.setTypeId(phone.getTypeId());
4178 phoneImpl.setPrimary(phone.isPrimary());
4179
4180 return phoneImpl;
4181 }
4182
4183
4190 @Override
4191 public Phone findByPrimaryKey(Serializable primaryKey)
4192 throws NoSuchPhoneException {
4193 Phone phone = fetchByPrimaryKey(primaryKey);
4194
4195 if (phone == null) {
4196 if (_log.isWarnEnabled()) {
4197 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4198 }
4199
4200 throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4201 primaryKey);
4202 }
4203
4204 return phone;
4205 }
4206
4207
4214 @Override
4215 public Phone findByPrimaryKey(long phoneId) throws NoSuchPhoneException {
4216 return findByPrimaryKey((Serializable)phoneId);
4217 }
4218
4219
4225 @Override
4226 public Phone fetchByPrimaryKey(Serializable primaryKey) {
4227 Phone phone = (Phone)EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4228 PhoneImpl.class, primaryKey);
4229
4230 if (phone == _nullPhone) {
4231 return null;
4232 }
4233
4234 if (phone == null) {
4235 Session session = null;
4236
4237 try {
4238 session = openSession();
4239
4240 phone = (Phone)session.get(PhoneImpl.class, primaryKey);
4241
4242 if (phone != null) {
4243 cacheResult(phone);
4244 }
4245 else {
4246 EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4247 PhoneImpl.class, primaryKey, _nullPhone);
4248 }
4249 }
4250 catch (Exception e) {
4251 EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4252 PhoneImpl.class, primaryKey);
4253
4254 throw processException(e);
4255 }
4256 finally {
4257 closeSession(session);
4258 }
4259 }
4260
4261 return phone;
4262 }
4263
4264
4270 @Override
4271 public Phone fetchByPrimaryKey(long phoneId) {
4272 return fetchByPrimaryKey((Serializable)phoneId);
4273 }
4274
4275 @Override
4276 public Map<Serializable, Phone> fetchByPrimaryKeys(
4277 Set<Serializable> primaryKeys) {
4278 if (primaryKeys.isEmpty()) {
4279 return Collections.emptyMap();
4280 }
4281
4282 Map<Serializable, Phone> map = new HashMap<Serializable, Phone>();
4283
4284 if (primaryKeys.size() == 1) {
4285 Iterator<Serializable> iterator = primaryKeys.iterator();
4286
4287 Serializable primaryKey = iterator.next();
4288
4289 Phone phone = fetchByPrimaryKey(primaryKey);
4290
4291 if (phone != null) {
4292 map.put(primaryKey, phone);
4293 }
4294
4295 return map;
4296 }
4297
4298 Set<Serializable> uncachedPrimaryKeys = null;
4299
4300 for (Serializable primaryKey : primaryKeys) {
4301 Phone phone = (Phone)EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4302 PhoneImpl.class, primaryKey);
4303
4304 if (phone == null) {
4305 if (uncachedPrimaryKeys == null) {
4306 uncachedPrimaryKeys = new HashSet<Serializable>();
4307 }
4308
4309 uncachedPrimaryKeys.add(primaryKey);
4310 }
4311 else {
4312 map.put(primaryKey, phone);
4313 }
4314 }
4315
4316 if (uncachedPrimaryKeys == null) {
4317 return map;
4318 }
4319
4320 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
4321 1);
4322
4323 query.append(_SQL_SELECT_PHONE_WHERE_PKS_IN);
4324
4325 for (Serializable primaryKey : uncachedPrimaryKeys) {
4326 query.append(String.valueOf(primaryKey));
4327
4328 query.append(StringPool.COMMA);
4329 }
4330
4331 query.setIndex(query.index() - 1);
4332
4333 query.append(StringPool.CLOSE_PARENTHESIS);
4334
4335 String sql = query.toString();
4336
4337 Session session = null;
4338
4339 try {
4340 session = openSession();
4341
4342 Query q = session.createQuery(sql);
4343
4344 for (Phone phone : (List<Phone>)q.list()) {
4345 map.put(phone.getPrimaryKeyObj(), phone);
4346
4347 cacheResult(phone);
4348
4349 uncachedPrimaryKeys.remove(phone.getPrimaryKeyObj());
4350 }
4351
4352 for (Serializable primaryKey : uncachedPrimaryKeys) {
4353 EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4354 PhoneImpl.class, primaryKey, _nullPhone);
4355 }
4356 }
4357 catch (Exception e) {
4358 throw processException(e);
4359 }
4360 finally {
4361 closeSession(session);
4362 }
4363
4364 return map;
4365 }
4366
4367
4372 @Override
4373 public List<Phone> findAll() {
4374 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4375 }
4376
4377
4388 @Override
4389 public List<Phone> findAll(int start, int end) {
4390 return findAll(start, end, null);
4391 }
4392
4393
4405 @Override
4406 public List<Phone> findAll(int start, int end,
4407 OrderByComparator<Phone> orderByComparator) {
4408 boolean pagination = true;
4409 FinderPath finderPath = null;
4410 Object[] finderArgs = null;
4411
4412 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4413 (orderByComparator == null)) {
4414 pagination = false;
4415 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4416 finderArgs = FINDER_ARGS_EMPTY;
4417 }
4418 else {
4419 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4420 finderArgs = new Object[] { start, end, orderByComparator };
4421 }
4422
4423 List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
4424 finderArgs, this);
4425
4426 if (list == null) {
4427 StringBundler query = null;
4428 String sql = null;
4429
4430 if (orderByComparator != null) {
4431 query = new StringBundler(2 +
4432 (orderByComparator.getOrderByFields().length * 3));
4433
4434 query.append(_SQL_SELECT_PHONE);
4435
4436 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4437 orderByComparator);
4438
4439 sql = query.toString();
4440 }
4441 else {
4442 sql = _SQL_SELECT_PHONE;
4443
4444 if (pagination) {
4445 sql = sql.concat(PhoneModelImpl.ORDER_BY_JPQL);
4446 }
4447 }
4448
4449 Session session = null;
4450
4451 try {
4452 session = openSession();
4453
4454 Query q = session.createQuery(sql);
4455
4456 if (!pagination) {
4457 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
4458 end, false);
4459
4460 Collections.sort(list);
4461
4462 list = Collections.unmodifiableList(list);
4463 }
4464 else {
4465 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
4466 end);
4467 }
4468
4469 cacheResult(list);
4470
4471 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4472 }
4473 catch (Exception e) {
4474 FinderCacheUtil.removeResult(finderPath, finderArgs);
4475
4476 throw processException(e);
4477 }
4478 finally {
4479 closeSession(session);
4480 }
4481 }
4482
4483 return list;
4484 }
4485
4486
4490 @Override
4491 public void removeAll() {
4492 for (Phone phone : findAll()) {
4493 remove(phone);
4494 }
4495 }
4496
4497
4502 @Override
4503 public int countAll() {
4504 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4505 FINDER_ARGS_EMPTY, this);
4506
4507 if (count == null) {
4508 Session session = null;
4509
4510 try {
4511 session = openSession();
4512
4513 Query q = session.createQuery(_SQL_COUNT_PHONE);
4514
4515 count = (Long)q.uniqueResult();
4516
4517 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4518 FINDER_ARGS_EMPTY, count);
4519 }
4520 catch (Exception e) {
4521 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4522 FINDER_ARGS_EMPTY);
4523
4524 throw processException(e);
4525 }
4526 finally {
4527 closeSession(session);
4528 }
4529 }
4530
4531 return count.intValue();
4532 }
4533
4534 @Override
4535 protected Set<String> getBadColumnNames() {
4536 return _badColumnNames;
4537 }
4538
4539
4542 public void afterPropertiesSet() {
4543 }
4544
4545 public void destroy() {
4546 EntityCacheUtil.removeCache(PhoneImpl.class.getName());
4547 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4548 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4549 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4550 }
4551
4552 private static final String _SQL_SELECT_PHONE = "SELECT phone FROM Phone phone";
4553 private static final String _SQL_SELECT_PHONE_WHERE_PKS_IN = "SELECT phone FROM Phone phone WHERE phoneId IN (";
4554 private static final String _SQL_SELECT_PHONE_WHERE = "SELECT phone FROM Phone phone WHERE ";
4555 private static final String _SQL_COUNT_PHONE = "SELECT COUNT(phone) FROM Phone phone";
4556 private static final String _SQL_COUNT_PHONE_WHERE = "SELECT COUNT(phone) FROM Phone phone WHERE ";
4557 private static final String _ORDER_BY_ENTITY_ALIAS = "phone.";
4558 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Phone exists with the primary key ";
4559 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Phone exists with the key {";
4560 private static final Log _log = LogFactoryUtil.getLog(PhonePersistenceImpl.class);
4561 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
4562 "uuid", "number", "primary"
4563 });
4564 private static final Phone _nullPhone = new PhoneImpl() {
4565 @Override
4566 public Object clone() {
4567 return this;
4568 }
4569
4570 @Override
4571 public CacheModel<Phone> toCacheModel() {
4572 return _nullPhoneCacheModel;
4573 }
4574 };
4575
4576 private static final CacheModel<Phone> _nullPhoneCacheModel = new NullCacheModel();
4577
4578 private static class NullCacheModel implements CacheModel<Phone>, MVCCModel {
4579 @Override
4580 public long getMvccVersion() {
4581 return -1;
4582 }
4583
4584 @Override
4585 public void setMvccVersion(long mvccVersion) {
4586 }
4587
4588 @Override
4589 public Phone toEntityModel() {
4590 return _nullPhone;
4591 }
4592 }
4593 }