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