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.bean.BeanReference;
021 import com.liferay.portal.kernel.dao.orm.EntityCache;
022 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderCache;
024 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025 import com.liferay.portal.kernel.dao.orm.FinderPath;
026 import com.liferay.portal.kernel.dao.orm.Query;
027 import com.liferay.portal.kernel.dao.orm.QueryPos;
028 import com.liferay.portal.kernel.dao.orm.QueryUtil;
029 import com.liferay.portal.kernel.dao.orm.Session;
030 import com.liferay.portal.kernel.log.Log;
031 import com.liferay.portal.kernel.log.LogFactoryUtil;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.SetUtil;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.MVCCModel;
040 import com.liferay.portal.model.Phone;
041 import com.liferay.portal.model.impl.PhoneImpl;
042 import com.liferay.portal.model.impl.PhoneModelImpl;
043 import com.liferay.portal.service.ServiceContext;
044 import com.liferay.portal.service.ServiceContextThreadLocal;
045 import com.liferay.portal.service.persistence.CompanyProvider;
046 import com.liferay.portal.service.persistence.PhonePersistence;
047
048 import java.io.Serializable;
049
050 import java.util.Collections;
051 import java.util.Date;
052 import java.util.HashMap;
053 import java.util.HashSet;
054 import java.util.Iterator;
055 import java.util.List;
056 import java.util.Map;
057 import java.util.Set;
058
059
071 @ProviderType
072 public class PhonePersistenceImpl extends BasePersistenceImpl<Phone>
073 implements PhonePersistence {
074
079 public static final String FINDER_CLASS_NAME_ENTITY = PhoneImpl.class.getName();
080 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List1";
082 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083 ".List2";
084 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
085 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
086 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
088 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
090 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
091 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
093 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
094 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
095 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096 new String[] {
097 String.class.getName(),
098
099 Integer.class.getName(), Integer.class.getName(),
100 OrderByComparator.class.getName()
101 });
102 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
103 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105 new String[] { String.class.getName() },
106 PhoneModelImpl.UUID_COLUMN_BITMASK |
107 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
109 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111 new String[] { String.class.getName() });
112
113
119 @Override
120 public List<Phone> findByUuid(String uuid) {
121 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122 }
123
124
136 @Override
137 public List<Phone> findByUuid(String uuid, int start, int end) {
138 return findByUuid(uuid, start, end, null);
139 }
140
141
154 @Override
155 public List<Phone> findByUuid(String uuid, int start, int end,
156 OrderByComparator<Phone> orderByComparator) {
157 return findByUuid(uuid, start, end, orderByComparator, true);
158 }
159
160
174 @Override
175 public List<Phone> findByUuid(String uuid, int start, int end,
176 OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
177 boolean pagination = true;
178 FinderPath finderPath = null;
179 Object[] finderArgs = null;
180
181 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
182 (orderByComparator == null)) {
183 pagination = false;
184 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
185 finderArgs = new Object[] { uuid };
186 }
187 else {
188 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
189 finderArgs = new Object[] { uuid, start, end, orderByComparator };
190 }
191
192 List<Phone> list = null;
193
194 if (retrieveFromCache) {
195 list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
196 this);
197
198 if ((list != null) && !list.isEmpty()) {
199 for (Phone phone : list) {
200 if (!Validator.equals(uuid, phone.getUuid())) {
201 list = null;
202
203 break;
204 }
205 }
206 }
207 }
208
209 if (list == null) {
210 StringBundler query = null;
211
212 if (orderByComparator != null) {
213 query = new StringBundler(3 +
214 (orderByComparator.getOrderByFields().length * 3));
215 }
216 else {
217 query = new StringBundler(3);
218 }
219
220 query.append(_SQL_SELECT_PHONE_WHERE);
221
222 boolean bindUuid = false;
223
224 if (uuid == null) {
225 query.append(_FINDER_COLUMN_UUID_UUID_1);
226 }
227 else if (uuid.equals(StringPool.BLANK)) {
228 query.append(_FINDER_COLUMN_UUID_UUID_3);
229 }
230 else {
231 bindUuid = true;
232
233 query.append(_FINDER_COLUMN_UUID_UUID_2);
234 }
235
236 if (orderByComparator != null) {
237 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
238 orderByComparator);
239 }
240 else
241 if (pagination) {
242 query.append(PhoneModelImpl.ORDER_BY_JPQL);
243 }
244
245 String sql = query.toString();
246
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 Query q = session.createQuery(sql);
253
254 QueryPos qPos = QueryPos.getInstance(q);
255
256 if (bindUuid) {
257 qPos.add(uuid);
258 }
259
260 if (!pagination) {
261 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
262 end, false);
263
264 Collections.sort(list);
265
266 list = Collections.unmodifiableList(list);
267 }
268 else {
269 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
270 end);
271 }
272
273 cacheResult(list);
274
275 finderCache.putResult(finderPath, finderArgs, list);
276 }
277 catch (Exception e) {
278 finderCache.removeResult(finderPath, finderArgs);
279
280 throw processException(e);
281 }
282 finally {
283 closeSession(session);
284 }
285 }
286
287 return list;
288 }
289
290
298 @Override
299 public Phone findByUuid_First(String uuid,
300 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
301 Phone phone = fetchByUuid_First(uuid, orderByComparator);
302
303 if (phone != null) {
304 return phone;
305 }
306
307 StringBundler msg = new StringBundler(4);
308
309 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
310
311 msg.append("uuid=");
312 msg.append(uuid);
313
314 msg.append(StringPool.CLOSE_CURLY_BRACE);
315
316 throw new NoSuchPhoneException(msg.toString());
317 }
318
319
326 @Override
327 public Phone fetchByUuid_First(String uuid,
328 OrderByComparator<Phone> orderByComparator) {
329 List<Phone> list = findByUuid(uuid, 0, 1, orderByComparator);
330
331 if (!list.isEmpty()) {
332 return list.get(0);
333 }
334
335 return null;
336 }
337
338
346 @Override
347 public Phone findByUuid_Last(String uuid,
348 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
349 Phone phone = fetchByUuid_Last(uuid, orderByComparator);
350
351 if (phone != null) {
352 return phone;
353 }
354
355 StringBundler msg = new StringBundler(4);
356
357 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
358
359 msg.append("uuid=");
360 msg.append(uuid);
361
362 msg.append(StringPool.CLOSE_CURLY_BRACE);
363
364 throw new NoSuchPhoneException(msg.toString());
365 }
366
367
374 @Override
375 public Phone fetchByUuid_Last(String uuid,
376 OrderByComparator<Phone> orderByComparator) {
377 int count = countByUuid(uuid);
378
379 if (count == 0) {
380 return null;
381 }
382
383 List<Phone> list = findByUuid(uuid, count - 1, count, orderByComparator);
384
385 if (!list.isEmpty()) {
386 return list.get(0);
387 }
388
389 return null;
390 }
391
392
401 @Override
402 public Phone[] findByUuid_PrevAndNext(long phoneId, String uuid,
403 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
404 Phone phone = findByPrimaryKey(phoneId);
405
406 Session session = null;
407
408 try {
409 session = openSession();
410
411 Phone[] array = new PhoneImpl[3];
412
413 array[0] = getByUuid_PrevAndNext(session, phone, uuid,
414 orderByComparator, true);
415
416 array[1] = phone;
417
418 array[2] = getByUuid_PrevAndNext(session, phone, uuid,
419 orderByComparator, false);
420
421 return array;
422 }
423 catch (Exception e) {
424 throw processException(e);
425 }
426 finally {
427 closeSession(session);
428 }
429 }
430
431 protected Phone getByUuid_PrevAndNext(Session session, Phone phone,
432 String uuid, OrderByComparator<Phone> orderByComparator,
433 boolean previous) {
434 StringBundler query = null;
435
436 if (orderByComparator != null) {
437 query = new StringBundler(6 +
438 (orderByComparator.getOrderByFields().length * 6));
439 }
440 else {
441 query = new StringBundler(3);
442 }
443
444 query.append(_SQL_SELECT_PHONE_WHERE);
445
446 boolean bindUuid = false;
447
448 if (uuid == null) {
449 query.append(_FINDER_COLUMN_UUID_UUID_1);
450 }
451 else if (uuid.equals(StringPool.BLANK)) {
452 query.append(_FINDER_COLUMN_UUID_UUID_3);
453 }
454 else {
455 bindUuid = true;
456
457 query.append(_FINDER_COLUMN_UUID_UUID_2);
458 }
459
460 if (orderByComparator != null) {
461 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
462
463 if (orderByConditionFields.length > 0) {
464 query.append(WHERE_AND);
465 }
466
467 for (int i = 0; i < orderByConditionFields.length; i++) {
468 query.append(_ORDER_BY_ENTITY_ALIAS);
469 query.append(orderByConditionFields[i]);
470
471 if ((i + 1) < orderByConditionFields.length) {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(WHERE_GREATER_THAN_HAS_NEXT);
474 }
475 else {
476 query.append(WHERE_LESSER_THAN_HAS_NEXT);
477 }
478 }
479 else {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(WHERE_GREATER_THAN);
482 }
483 else {
484 query.append(WHERE_LESSER_THAN);
485 }
486 }
487 }
488
489 query.append(ORDER_BY_CLAUSE);
490
491 String[] orderByFields = orderByComparator.getOrderByFields();
492
493 for (int i = 0; i < orderByFields.length; i++) {
494 query.append(_ORDER_BY_ENTITY_ALIAS);
495 query.append(orderByFields[i]);
496
497 if ((i + 1) < orderByFields.length) {
498 if (orderByComparator.isAscending() ^ previous) {
499 query.append(ORDER_BY_ASC_HAS_NEXT);
500 }
501 else {
502 query.append(ORDER_BY_DESC_HAS_NEXT);
503 }
504 }
505 else {
506 if (orderByComparator.isAscending() ^ previous) {
507 query.append(ORDER_BY_ASC);
508 }
509 else {
510 query.append(ORDER_BY_DESC);
511 }
512 }
513 }
514 }
515 else {
516 query.append(PhoneModelImpl.ORDER_BY_JPQL);
517 }
518
519 String sql = query.toString();
520
521 Query q = session.createQuery(sql);
522
523 q.setFirstResult(0);
524 q.setMaxResults(2);
525
526 QueryPos qPos = QueryPos.getInstance(q);
527
528 if (bindUuid) {
529 qPos.add(uuid);
530 }
531
532 if (orderByComparator != null) {
533 Object[] values = orderByComparator.getOrderByConditionValues(phone);
534
535 for (Object value : values) {
536 qPos.add(value);
537 }
538 }
539
540 List<Phone> list = q.list();
541
542 if (list.size() == 2) {
543 return list.get(1);
544 }
545 else {
546 return null;
547 }
548 }
549
550
555 @Override
556 public void removeByUuid(String uuid) {
557 for (Phone phone : findByUuid(uuid, QueryUtil.ALL_POS,
558 QueryUtil.ALL_POS, null)) {
559 remove(phone);
560 }
561 }
562
563
569 @Override
570 public int countByUuid(String uuid) {
571 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
572
573 Object[] finderArgs = new Object[] { uuid };
574
575 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
576
577 if (count == null) {
578 StringBundler query = new StringBundler(2);
579
580 query.append(_SQL_COUNT_PHONE_WHERE);
581
582 boolean bindUuid = false;
583
584 if (uuid == null) {
585 query.append(_FINDER_COLUMN_UUID_UUID_1);
586 }
587 else if (uuid.equals(StringPool.BLANK)) {
588 query.append(_FINDER_COLUMN_UUID_UUID_3);
589 }
590 else {
591 bindUuid = true;
592
593 query.append(_FINDER_COLUMN_UUID_UUID_2);
594 }
595
596 String sql = query.toString();
597
598 Session session = null;
599
600 try {
601 session = openSession();
602
603 Query q = session.createQuery(sql);
604
605 QueryPos qPos = QueryPos.getInstance(q);
606
607 if (bindUuid) {
608 qPos.add(uuid);
609 }
610
611 count = (Long)q.uniqueResult();
612
613 finderCache.putResult(finderPath, finderArgs, count);
614 }
615 catch (Exception e) {
616 finderCache.removeResult(finderPath, finderArgs);
617
618 throw processException(e);
619 }
620 finally {
621 closeSession(session);
622 }
623 }
624
625 return count.intValue();
626 }
627
628 private static final String _FINDER_COLUMN_UUID_UUID_1 = "phone.uuid IS NULL";
629 private static final String _FINDER_COLUMN_UUID_UUID_2 = "phone.uuid = ?";
630 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(phone.uuid IS NULL OR phone.uuid = '')";
631 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
632 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
633 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
634 new String[] {
635 String.class.getName(), Long.class.getName(),
636
637 Integer.class.getName(), Integer.class.getName(),
638 OrderByComparator.class.getName()
639 });
640 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
641 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
642 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
643 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
644 new String[] { String.class.getName(), Long.class.getName() },
645 PhoneModelImpl.UUID_COLUMN_BITMASK |
646 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
647 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
648 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
649 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
650 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
651 new String[] { String.class.getName(), Long.class.getName() });
652
653
660 @Override
661 public List<Phone> findByUuid_C(String uuid, long companyId) {
662 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
663 QueryUtil.ALL_POS, null);
664 }
665
666
679 @Override
680 public List<Phone> findByUuid_C(String uuid, long companyId, int start,
681 int end) {
682 return findByUuid_C(uuid, companyId, start, end, null);
683 }
684
685
699 @Override
700 public List<Phone> findByUuid_C(String uuid, long companyId, int start,
701 int end, OrderByComparator<Phone> orderByComparator) {
702 return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
703 }
704
705
720 @Override
721 public List<Phone> findByUuid_C(String uuid, long companyId, int start,
722 int end, OrderByComparator<Phone> orderByComparator,
723 boolean retrieveFromCache) {
724 boolean pagination = true;
725 FinderPath finderPath = null;
726 Object[] finderArgs = null;
727
728 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
729 (orderByComparator == null)) {
730 pagination = false;
731 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
732 finderArgs = new Object[] { uuid, companyId };
733 }
734 else {
735 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
736 finderArgs = new Object[] {
737 uuid, companyId,
738
739 start, end, orderByComparator
740 };
741 }
742
743 List<Phone> list = null;
744
745 if (retrieveFromCache) {
746 list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
747 this);
748
749 if ((list != null) && !list.isEmpty()) {
750 for (Phone phone : list) {
751 if (!Validator.equals(uuid, phone.getUuid()) ||
752 (companyId != phone.getCompanyId())) {
753 list = null;
754
755 break;
756 }
757 }
758 }
759 }
760
761 if (list == null) {
762 StringBundler query = null;
763
764 if (orderByComparator != null) {
765 query = new StringBundler(4 +
766 (orderByComparator.getOrderByFields().length * 3));
767 }
768 else {
769 query = new StringBundler(4);
770 }
771
772 query.append(_SQL_SELECT_PHONE_WHERE);
773
774 boolean bindUuid = false;
775
776 if (uuid == null) {
777 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
778 }
779 else if (uuid.equals(StringPool.BLANK)) {
780 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
781 }
782 else {
783 bindUuid = true;
784
785 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
786 }
787
788 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
789
790 if (orderByComparator != null) {
791 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
792 orderByComparator);
793 }
794 else
795 if (pagination) {
796 query.append(PhoneModelImpl.ORDER_BY_JPQL);
797 }
798
799 String sql = query.toString();
800
801 Session session = null;
802
803 try {
804 session = openSession();
805
806 Query q = session.createQuery(sql);
807
808 QueryPos qPos = QueryPos.getInstance(q);
809
810 if (bindUuid) {
811 qPos.add(uuid);
812 }
813
814 qPos.add(companyId);
815
816 if (!pagination) {
817 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
818 end, false);
819
820 Collections.sort(list);
821
822 list = Collections.unmodifiableList(list);
823 }
824 else {
825 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
826 end);
827 }
828
829 cacheResult(list);
830
831 finderCache.putResult(finderPath, finderArgs, list);
832 }
833 catch (Exception e) {
834 finderCache.removeResult(finderPath, finderArgs);
835
836 throw processException(e);
837 }
838 finally {
839 closeSession(session);
840 }
841 }
842
843 return list;
844 }
845
846
855 @Override
856 public Phone findByUuid_C_First(String uuid, long companyId,
857 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
858 Phone phone = fetchByUuid_C_First(uuid, companyId, orderByComparator);
859
860 if (phone != null) {
861 return phone;
862 }
863
864 StringBundler msg = new StringBundler(6);
865
866 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
867
868 msg.append("uuid=");
869 msg.append(uuid);
870
871 msg.append(", companyId=");
872 msg.append(companyId);
873
874 msg.append(StringPool.CLOSE_CURLY_BRACE);
875
876 throw new NoSuchPhoneException(msg.toString());
877 }
878
879
887 @Override
888 public Phone fetchByUuid_C_First(String uuid, long companyId,
889 OrderByComparator<Phone> orderByComparator) {
890 List<Phone> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
891
892 if (!list.isEmpty()) {
893 return list.get(0);
894 }
895
896 return null;
897 }
898
899
908 @Override
909 public Phone findByUuid_C_Last(String uuid, long companyId,
910 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
911 Phone phone = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
912
913 if (phone != null) {
914 return phone;
915 }
916
917 StringBundler msg = new StringBundler(6);
918
919 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
920
921 msg.append("uuid=");
922 msg.append(uuid);
923
924 msg.append(", companyId=");
925 msg.append(companyId);
926
927 msg.append(StringPool.CLOSE_CURLY_BRACE);
928
929 throw new NoSuchPhoneException(msg.toString());
930 }
931
932
940 @Override
941 public Phone fetchByUuid_C_Last(String uuid, long companyId,
942 OrderByComparator<Phone> orderByComparator) {
943 int count = countByUuid_C(uuid, companyId);
944
945 if (count == 0) {
946 return null;
947 }
948
949 List<Phone> list = findByUuid_C(uuid, companyId, count - 1, count,
950 orderByComparator);
951
952 if (!list.isEmpty()) {
953 return list.get(0);
954 }
955
956 return null;
957 }
958
959
969 @Override
970 public Phone[] findByUuid_C_PrevAndNext(long phoneId, String uuid,
971 long companyId, OrderByComparator<Phone> orderByComparator)
972 throws NoSuchPhoneException {
973 Phone phone = findByPrimaryKey(phoneId);
974
975 Session session = null;
976
977 try {
978 session = openSession();
979
980 Phone[] array = new PhoneImpl[3];
981
982 array[0] = getByUuid_C_PrevAndNext(session, phone, uuid, companyId,
983 orderByComparator, true);
984
985 array[1] = phone;
986
987 array[2] = getByUuid_C_PrevAndNext(session, phone, uuid, companyId,
988 orderByComparator, false);
989
990 return array;
991 }
992 catch (Exception e) {
993 throw processException(e);
994 }
995 finally {
996 closeSession(session);
997 }
998 }
999
1000 protected Phone getByUuid_C_PrevAndNext(Session session, Phone phone,
1001 String uuid, long companyId,
1002 OrderByComparator<Phone> orderByComparator, boolean previous) {
1003 StringBundler query = null;
1004
1005 if (orderByComparator != null) {
1006 query = new StringBundler(6 +
1007 (orderByComparator.getOrderByFields().length * 6));
1008 }
1009 else {
1010 query = new StringBundler(3);
1011 }
1012
1013 query.append(_SQL_SELECT_PHONE_WHERE);
1014
1015 boolean bindUuid = false;
1016
1017 if (uuid == null) {
1018 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1019 }
1020 else if (uuid.equals(StringPool.BLANK)) {
1021 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1022 }
1023 else {
1024 bindUuid = true;
1025
1026 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1027 }
1028
1029 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1030
1031 if (orderByComparator != null) {
1032 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1033
1034 if (orderByConditionFields.length > 0) {
1035 query.append(WHERE_AND);
1036 }
1037
1038 for (int i = 0; i < orderByConditionFields.length; i++) {
1039 query.append(_ORDER_BY_ENTITY_ALIAS);
1040 query.append(orderByConditionFields[i]);
1041
1042 if ((i + 1) < orderByConditionFields.length) {
1043 if (orderByComparator.isAscending() ^ previous) {
1044 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1045 }
1046 else {
1047 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1048 }
1049 }
1050 else {
1051 if (orderByComparator.isAscending() ^ previous) {
1052 query.append(WHERE_GREATER_THAN);
1053 }
1054 else {
1055 query.append(WHERE_LESSER_THAN);
1056 }
1057 }
1058 }
1059
1060 query.append(ORDER_BY_CLAUSE);
1061
1062 String[] orderByFields = orderByComparator.getOrderByFields();
1063
1064 for (int i = 0; i < orderByFields.length; i++) {
1065 query.append(_ORDER_BY_ENTITY_ALIAS);
1066 query.append(orderByFields[i]);
1067
1068 if ((i + 1) < orderByFields.length) {
1069 if (orderByComparator.isAscending() ^ previous) {
1070 query.append(ORDER_BY_ASC_HAS_NEXT);
1071 }
1072 else {
1073 query.append(ORDER_BY_DESC_HAS_NEXT);
1074 }
1075 }
1076 else {
1077 if (orderByComparator.isAscending() ^ previous) {
1078 query.append(ORDER_BY_ASC);
1079 }
1080 else {
1081 query.append(ORDER_BY_DESC);
1082 }
1083 }
1084 }
1085 }
1086 else {
1087 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1088 }
1089
1090 String sql = query.toString();
1091
1092 Query q = session.createQuery(sql);
1093
1094 q.setFirstResult(0);
1095 q.setMaxResults(2);
1096
1097 QueryPos qPos = QueryPos.getInstance(q);
1098
1099 if (bindUuid) {
1100 qPos.add(uuid);
1101 }
1102
1103 qPos.add(companyId);
1104
1105 if (orderByComparator != null) {
1106 Object[] values = orderByComparator.getOrderByConditionValues(phone);
1107
1108 for (Object value : values) {
1109 qPos.add(value);
1110 }
1111 }
1112
1113 List<Phone> list = q.list();
1114
1115 if (list.size() == 2) {
1116 return list.get(1);
1117 }
1118 else {
1119 return null;
1120 }
1121 }
1122
1123
1129 @Override
1130 public void removeByUuid_C(String uuid, long companyId) {
1131 for (Phone phone : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1132 QueryUtil.ALL_POS, null)) {
1133 remove(phone);
1134 }
1135 }
1136
1137
1144 @Override
1145 public int countByUuid_C(String uuid, long companyId) {
1146 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1147
1148 Object[] finderArgs = new Object[] { uuid, companyId };
1149
1150 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1151
1152 if (count == null) {
1153 StringBundler query = new StringBundler(3);
1154
1155 query.append(_SQL_COUNT_PHONE_WHERE);
1156
1157 boolean bindUuid = false;
1158
1159 if (uuid == null) {
1160 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1161 }
1162 else if (uuid.equals(StringPool.BLANK)) {
1163 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1164 }
1165 else {
1166 bindUuid = true;
1167
1168 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1169 }
1170
1171 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1172
1173 String sql = query.toString();
1174
1175 Session session = null;
1176
1177 try {
1178 session = openSession();
1179
1180 Query q = session.createQuery(sql);
1181
1182 QueryPos qPos = QueryPos.getInstance(q);
1183
1184 if (bindUuid) {
1185 qPos.add(uuid);
1186 }
1187
1188 qPos.add(companyId);
1189
1190 count = (Long)q.uniqueResult();
1191
1192 finderCache.putResult(finderPath, finderArgs, count);
1193 }
1194 catch (Exception e) {
1195 finderCache.removeResult(finderPath, finderArgs);
1196
1197 throw processException(e);
1198 }
1199 finally {
1200 closeSession(session);
1201 }
1202 }
1203
1204 return count.intValue();
1205 }
1206
1207 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "phone.uuid IS NULL AND ";
1208 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "phone.uuid = ? AND ";
1209 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(phone.uuid IS NULL OR phone.uuid = '') AND ";
1210 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "phone.companyId = ?";
1211 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1212 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1213 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1214 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1215 new String[] {
1216 Long.class.getName(),
1217
1218 Integer.class.getName(), Integer.class.getName(),
1219 OrderByComparator.class.getName()
1220 });
1221 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1222 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1223 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1224 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1225 new String[] { Long.class.getName() },
1226 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
1227 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
1228 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1229 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
1230 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1231 new String[] { Long.class.getName() });
1232
1233
1239 @Override
1240 public List<Phone> findByCompanyId(long companyId) {
1241 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1242 null);
1243 }
1244
1245
1257 @Override
1258 public List<Phone> findByCompanyId(long companyId, int start, int end) {
1259 return findByCompanyId(companyId, start, end, null);
1260 }
1261
1262
1275 @Override
1276 public List<Phone> findByCompanyId(long companyId, int start, int end,
1277 OrderByComparator<Phone> orderByComparator) {
1278 return findByCompanyId(companyId, start, end, orderByComparator, true);
1279 }
1280
1281
1295 @Override
1296 public List<Phone> findByCompanyId(long companyId, int start, int end,
1297 OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
1298 boolean pagination = true;
1299 FinderPath finderPath = null;
1300 Object[] finderArgs = null;
1301
1302 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1303 (orderByComparator == null)) {
1304 pagination = false;
1305 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1306 finderArgs = new Object[] { companyId };
1307 }
1308 else {
1309 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1310 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1311 }
1312
1313 List<Phone> list = null;
1314
1315 if (retrieveFromCache) {
1316 list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
1317 this);
1318
1319 if ((list != null) && !list.isEmpty()) {
1320 for (Phone phone : list) {
1321 if ((companyId != phone.getCompanyId())) {
1322 list = null;
1323
1324 break;
1325 }
1326 }
1327 }
1328 }
1329
1330 if (list == null) {
1331 StringBundler query = null;
1332
1333 if (orderByComparator != null) {
1334 query = new StringBundler(3 +
1335 (orderByComparator.getOrderByFields().length * 3));
1336 }
1337 else {
1338 query = new StringBundler(3);
1339 }
1340
1341 query.append(_SQL_SELECT_PHONE_WHERE);
1342
1343 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1344
1345 if (orderByComparator != null) {
1346 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1347 orderByComparator);
1348 }
1349 else
1350 if (pagination) {
1351 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1352 }
1353
1354 String sql = query.toString();
1355
1356 Session session = null;
1357
1358 try {
1359 session = openSession();
1360
1361 Query q = session.createQuery(sql);
1362
1363 QueryPos qPos = QueryPos.getInstance(q);
1364
1365 qPos.add(companyId);
1366
1367 if (!pagination) {
1368 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1369 end, false);
1370
1371 Collections.sort(list);
1372
1373 list = Collections.unmodifiableList(list);
1374 }
1375 else {
1376 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1377 end);
1378 }
1379
1380 cacheResult(list);
1381
1382 finderCache.putResult(finderPath, finderArgs, list);
1383 }
1384 catch (Exception e) {
1385 finderCache.removeResult(finderPath, finderArgs);
1386
1387 throw processException(e);
1388 }
1389 finally {
1390 closeSession(session);
1391 }
1392 }
1393
1394 return list;
1395 }
1396
1397
1405 @Override
1406 public Phone findByCompanyId_First(long companyId,
1407 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1408 Phone phone = fetchByCompanyId_First(companyId, orderByComparator);
1409
1410 if (phone != null) {
1411 return phone;
1412 }
1413
1414 StringBundler msg = new StringBundler(4);
1415
1416 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1417
1418 msg.append("companyId=");
1419 msg.append(companyId);
1420
1421 msg.append(StringPool.CLOSE_CURLY_BRACE);
1422
1423 throw new NoSuchPhoneException(msg.toString());
1424 }
1425
1426
1433 @Override
1434 public Phone fetchByCompanyId_First(long companyId,
1435 OrderByComparator<Phone> orderByComparator) {
1436 List<Phone> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1437
1438 if (!list.isEmpty()) {
1439 return list.get(0);
1440 }
1441
1442 return null;
1443 }
1444
1445
1453 @Override
1454 public Phone findByCompanyId_Last(long companyId,
1455 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1456 Phone phone = fetchByCompanyId_Last(companyId, orderByComparator);
1457
1458 if (phone != null) {
1459 return phone;
1460 }
1461
1462 StringBundler msg = new StringBundler(4);
1463
1464 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1465
1466 msg.append("companyId=");
1467 msg.append(companyId);
1468
1469 msg.append(StringPool.CLOSE_CURLY_BRACE);
1470
1471 throw new NoSuchPhoneException(msg.toString());
1472 }
1473
1474
1481 @Override
1482 public Phone fetchByCompanyId_Last(long companyId,
1483 OrderByComparator<Phone> orderByComparator) {
1484 int count = countByCompanyId(companyId);
1485
1486 if (count == 0) {
1487 return null;
1488 }
1489
1490 List<Phone> list = findByCompanyId(companyId, count - 1, count,
1491 orderByComparator);
1492
1493 if (!list.isEmpty()) {
1494 return list.get(0);
1495 }
1496
1497 return null;
1498 }
1499
1500
1509 @Override
1510 public Phone[] findByCompanyId_PrevAndNext(long phoneId, long companyId,
1511 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1512 Phone phone = findByPrimaryKey(phoneId);
1513
1514 Session session = null;
1515
1516 try {
1517 session = openSession();
1518
1519 Phone[] array = new PhoneImpl[3];
1520
1521 array[0] = getByCompanyId_PrevAndNext(session, phone, companyId,
1522 orderByComparator, true);
1523
1524 array[1] = phone;
1525
1526 array[2] = getByCompanyId_PrevAndNext(session, phone, companyId,
1527 orderByComparator, false);
1528
1529 return array;
1530 }
1531 catch (Exception e) {
1532 throw processException(e);
1533 }
1534 finally {
1535 closeSession(session);
1536 }
1537 }
1538
1539 protected Phone getByCompanyId_PrevAndNext(Session session, Phone phone,
1540 long companyId, OrderByComparator<Phone> orderByComparator,
1541 boolean previous) {
1542 StringBundler query = null;
1543
1544 if (orderByComparator != null) {
1545 query = new StringBundler(6 +
1546 (orderByComparator.getOrderByFields().length * 6));
1547 }
1548 else {
1549 query = new StringBundler(3);
1550 }
1551
1552 query.append(_SQL_SELECT_PHONE_WHERE);
1553
1554 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1555
1556 if (orderByComparator != null) {
1557 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1558
1559 if (orderByConditionFields.length > 0) {
1560 query.append(WHERE_AND);
1561 }
1562
1563 for (int i = 0; i < orderByConditionFields.length; i++) {
1564 query.append(_ORDER_BY_ENTITY_ALIAS);
1565 query.append(orderByConditionFields[i]);
1566
1567 if ((i + 1) < orderByConditionFields.length) {
1568 if (orderByComparator.isAscending() ^ previous) {
1569 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1570 }
1571 else {
1572 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1573 }
1574 }
1575 else {
1576 if (orderByComparator.isAscending() ^ previous) {
1577 query.append(WHERE_GREATER_THAN);
1578 }
1579 else {
1580 query.append(WHERE_LESSER_THAN);
1581 }
1582 }
1583 }
1584
1585 query.append(ORDER_BY_CLAUSE);
1586
1587 String[] orderByFields = orderByComparator.getOrderByFields();
1588
1589 for (int i = 0; i < orderByFields.length; i++) {
1590 query.append(_ORDER_BY_ENTITY_ALIAS);
1591 query.append(orderByFields[i]);
1592
1593 if ((i + 1) < orderByFields.length) {
1594 if (orderByComparator.isAscending() ^ previous) {
1595 query.append(ORDER_BY_ASC_HAS_NEXT);
1596 }
1597 else {
1598 query.append(ORDER_BY_DESC_HAS_NEXT);
1599 }
1600 }
1601 else {
1602 if (orderByComparator.isAscending() ^ previous) {
1603 query.append(ORDER_BY_ASC);
1604 }
1605 else {
1606 query.append(ORDER_BY_DESC);
1607 }
1608 }
1609 }
1610 }
1611 else {
1612 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1613 }
1614
1615 String sql = query.toString();
1616
1617 Query q = session.createQuery(sql);
1618
1619 q.setFirstResult(0);
1620 q.setMaxResults(2);
1621
1622 QueryPos qPos = QueryPos.getInstance(q);
1623
1624 qPos.add(companyId);
1625
1626 if (orderByComparator != null) {
1627 Object[] values = orderByComparator.getOrderByConditionValues(phone);
1628
1629 for (Object value : values) {
1630 qPos.add(value);
1631 }
1632 }
1633
1634 List<Phone> list = q.list();
1635
1636 if (list.size() == 2) {
1637 return list.get(1);
1638 }
1639 else {
1640 return null;
1641 }
1642 }
1643
1644
1649 @Override
1650 public void removeByCompanyId(long companyId) {
1651 for (Phone phone : findByCompanyId(companyId, QueryUtil.ALL_POS,
1652 QueryUtil.ALL_POS, null)) {
1653 remove(phone);
1654 }
1655 }
1656
1657
1663 @Override
1664 public int countByCompanyId(long companyId) {
1665 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1666
1667 Object[] finderArgs = new Object[] { companyId };
1668
1669 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1670
1671 if (count == null) {
1672 StringBundler query = new StringBundler(2);
1673
1674 query.append(_SQL_COUNT_PHONE_WHERE);
1675
1676 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1677
1678 String sql = query.toString();
1679
1680 Session session = null;
1681
1682 try {
1683 session = openSession();
1684
1685 Query q = session.createQuery(sql);
1686
1687 QueryPos qPos = QueryPos.getInstance(q);
1688
1689 qPos.add(companyId);
1690
1691 count = (Long)q.uniqueResult();
1692
1693 finderCache.putResult(finderPath, finderArgs, count);
1694 }
1695 catch (Exception e) {
1696 finderCache.removeResult(finderPath, finderArgs);
1697
1698 throw processException(e);
1699 }
1700 finally {
1701 closeSession(session);
1702 }
1703 }
1704
1705 return count.intValue();
1706 }
1707
1708 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "phone.companyId = ?";
1709 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1710 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1711 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1712 new String[] {
1713 Long.class.getName(),
1714
1715 Integer.class.getName(), Integer.class.getName(),
1716 OrderByComparator.class.getName()
1717 });
1718 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1719 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1720 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1721 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1722 new String[] { Long.class.getName() },
1723 PhoneModelImpl.USERID_COLUMN_BITMASK |
1724 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
1725 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1726 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
1727 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1728 new String[] { Long.class.getName() });
1729
1730
1736 @Override
1737 public List<Phone> findByUserId(long userId) {
1738 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1739 }
1740
1741
1753 @Override
1754 public List<Phone> findByUserId(long userId, int start, int end) {
1755 return findByUserId(userId, start, end, null);
1756 }
1757
1758
1771 @Override
1772 public List<Phone> findByUserId(long userId, int start, int end,
1773 OrderByComparator<Phone> orderByComparator) {
1774 return findByUserId(userId, start, end, orderByComparator, true);
1775 }
1776
1777
1791 @Override
1792 public List<Phone> findByUserId(long userId, int start, int end,
1793 OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
1794 boolean pagination = true;
1795 FinderPath finderPath = null;
1796 Object[] finderArgs = null;
1797
1798 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1799 (orderByComparator == null)) {
1800 pagination = false;
1801 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1802 finderArgs = new Object[] { userId };
1803 }
1804 else {
1805 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1806 finderArgs = new Object[] { userId, start, end, orderByComparator };
1807 }
1808
1809 List<Phone> list = null;
1810
1811 if (retrieveFromCache) {
1812 list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
1813 this);
1814
1815 if ((list != null) && !list.isEmpty()) {
1816 for (Phone phone : list) {
1817 if ((userId != phone.getUserId())) {
1818 list = null;
1819
1820 break;
1821 }
1822 }
1823 }
1824 }
1825
1826 if (list == null) {
1827 StringBundler query = null;
1828
1829 if (orderByComparator != null) {
1830 query = new StringBundler(3 +
1831 (orderByComparator.getOrderByFields().length * 3));
1832 }
1833 else {
1834 query = new StringBundler(3);
1835 }
1836
1837 query.append(_SQL_SELECT_PHONE_WHERE);
1838
1839 query.append(_FINDER_COLUMN_USERID_USERID_2);
1840
1841 if (orderByComparator != null) {
1842 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1843 orderByComparator);
1844 }
1845 else
1846 if (pagination) {
1847 query.append(PhoneModelImpl.ORDER_BY_JPQL);
1848 }
1849
1850 String sql = query.toString();
1851
1852 Session session = null;
1853
1854 try {
1855 session = openSession();
1856
1857 Query q = session.createQuery(sql);
1858
1859 QueryPos qPos = QueryPos.getInstance(q);
1860
1861 qPos.add(userId);
1862
1863 if (!pagination) {
1864 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1865 end, false);
1866
1867 Collections.sort(list);
1868
1869 list = Collections.unmodifiableList(list);
1870 }
1871 else {
1872 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1873 end);
1874 }
1875
1876 cacheResult(list);
1877
1878 finderCache.putResult(finderPath, finderArgs, list);
1879 }
1880 catch (Exception e) {
1881 finderCache.removeResult(finderPath, finderArgs);
1882
1883 throw processException(e);
1884 }
1885 finally {
1886 closeSession(session);
1887 }
1888 }
1889
1890 return list;
1891 }
1892
1893
1901 @Override
1902 public Phone findByUserId_First(long userId,
1903 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1904 Phone phone = fetchByUserId_First(userId, orderByComparator);
1905
1906 if (phone != null) {
1907 return phone;
1908 }
1909
1910 StringBundler msg = new StringBundler(4);
1911
1912 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1913
1914 msg.append("userId=");
1915 msg.append(userId);
1916
1917 msg.append(StringPool.CLOSE_CURLY_BRACE);
1918
1919 throw new NoSuchPhoneException(msg.toString());
1920 }
1921
1922
1929 @Override
1930 public Phone fetchByUserId_First(long userId,
1931 OrderByComparator<Phone> orderByComparator) {
1932 List<Phone> list = findByUserId(userId, 0, 1, orderByComparator);
1933
1934 if (!list.isEmpty()) {
1935 return list.get(0);
1936 }
1937
1938 return null;
1939 }
1940
1941
1949 @Override
1950 public Phone findByUserId_Last(long userId,
1951 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1952 Phone phone = fetchByUserId_Last(userId, orderByComparator);
1953
1954 if (phone != null) {
1955 return phone;
1956 }
1957
1958 StringBundler msg = new StringBundler(4);
1959
1960 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1961
1962 msg.append("userId=");
1963 msg.append(userId);
1964
1965 msg.append(StringPool.CLOSE_CURLY_BRACE);
1966
1967 throw new NoSuchPhoneException(msg.toString());
1968 }
1969
1970
1977 @Override
1978 public Phone fetchByUserId_Last(long userId,
1979 OrderByComparator<Phone> orderByComparator) {
1980 int count = countByUserId(userId);
1981
1982 if (count == 0) {
1983 return null;
1984 }
1985
1986 List<Phone> list = findByUserId(userId, count - 1, count,
1987 orderByComparator);
1988
1989 if (!list.isEmpty()) {
1990 return list.get(0);
1991 }
1992
1993 return null;
1994 }
1995
1996
2005 @Override
2006 public Phone[] findByUserId_PrevAndNext(long phoneId, long userId,
2007 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2008 Phone phone = findByPrimaryKey(phoneId);
2009
2010 Session session = null;
2011
2012 try {
2013 session = openSession();
2014
2015 Phone[] array = new PhoneImpl[3];
2016
2017 array[0] = getByUserId_PrevAndNext(session, phone, userId,
2018 orderByComparator, true);
2019
2020 array[1] = phone;
2021
2022 array[2] = getByUserId_PrevAndNext(session, phone, userId,
2023 orderByComparator, false);
2024
2025 return array;
2026 }
2027 catch (Exception e) {
2028 throw processException(e);
2029 }
2030 finally {
2031 closeSession(session);
2032 }
2033 }
2034
2035 protected Phone getByUserId_PrevAndNext(Session session, Phone phone,
2036 long userId, OrderByComparator<Phone> orderByComparator,
2037 boolean previous) {
2038 StringBundler query = null;
2039
2040 if (orderByComparator != null) {
2041 query = new StringBundler(6 +
2042 (orderByComparator.getOrderByFields().length * 6));
2043 }
2044 else {
2045 query = new StringBundler(3);
2046 }
2047
2048 query.append(_SQL_SELECT_PHONE_WHERE);
2049
2050 query.append(_FINDER_COLUMN_USERID_USERID_2);
2051
2052 if (orderByComparator != null) {
2053 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2054
2055 if (orderByConditionFields.length > 0) {
2056 query.append(WHERE_AND);
2057 }
2058
2059 for (int i = 0; i < orderByConditionFields.length; i++) {
2060 query.append(_ORDER_BY_ENTITY_ALIAS);
2061 query.append(orderByConditionFields[i]);
2062
2063 if ((i + 1) < orderByConditionFields.length) {
2064 if (orderByComparator.isAscending() ^ previous) {
2065 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2066 }
2067 else {
2068 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2069 }
2070 }
2071 else {
2072 if (orderByComparator.isAscending() ^ previous) {
2073 query.append(WHERE_GREATER_THAN);
2074 }
2075 else {
2076 query.append(WHERE_LESSER_THAN);
2077 }
2078 }
2079 }
2080
2081 query.append(ORDER_BY_CLAUSE);
2082
2083 String[] orderByFields = orderByComparator.getOrderByFields();
2084
2085 for (int i = 0; i < orderByFields.length; i++) {
2086 query.append(_ORDER_BY_ENTITY_ALIAS);
2087 query.append(orderByFields[i]);
2088
2089 if ((i + 1) < orderByFields.length) {
2090 if (orderByComparator.isAscending() ^ previous) {
2091 query.append(ORDER_BY_ASC_HAS_NEXT);
2092 }
2093 else {
2094 query.append(ORDER_BY_DESC_HAS_NEXT);
2095 }
2096 }
2097 else {
2098 if (orderByComparator.isAscending() ^ previous) {
2099 query.append(ORDER_BY_ASC);
2100 }
2101 else {
2102 query.append(ORDER_BY_DESC);
2103 }
2104 }
2105 }
2106 }
2107 else {
2108 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2109 }
2110
2111 String sql = query.toString();
2112
2113 Query q = session.createQuery(sql);
2114
2115 q.setFirstResult(0);
2116 q.setMaxResults(2);
2117
2118 QueryPos qPos = QueryPos.getInstance(q);
2119
2120 qPos.add(userId);
2121
2122 if (orderByComparator != null) {
2123 Object[] values = orderByComparator.getOrderByConditionValues(phone);
2124
2125 for (Object value : values) {
2126 qPos.add(value);
2127 }
2128 }
2129
2130 List<Phone> list = q.list();
2131
2132 if (list.size() == 2) {
2133 return list.get(1);
2134 }
2135 else {
2136 return null;
2137 }
2138 }
2139
2140
2145 @Override
2146 public void removeByUserId(long userId) {
2147 for (Phone phone : findByUserId(userId, QueryUtil.ALL_POS,
2148 QueryUtil.ALL_POS, null)) {
2149 remove(phone);
2150 }
2151 }
2152
2153
2159 @Override
2160 public int countByUserId(long userId) {
2161 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2162
2163 Object[] finderArgs = new Object[] { userId };
2164
2165 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2166
2167 if (count == null) {
2168 StringBundler query = new StringBundler(2);
2169
2170 query.append(_SQL_COUNT_PHONE_WHERE);
2171
2172 query.append(_FINDER_COLUMN_USERID_USERID_2);
2173
2174 String sql = query.toString();
2175
2176 Session session = null;
2177
2178 try {
2179 session = openSession();
2180
2181 Query q = session.createQuery(sql);
2182
2183 QueryPos qPos = QueryPos.getInstance(q);
2184
2185 qPos.add(userId);
2186
2187 count = (Long)q.uniqueResult();
2188
2189 finderCache.putResult(finderPath, finderArgs, count);
2190 }
2191 catch (Exception e) {
2192 finderCache.removeResult(finderPath, finderArgs);
2193
2194 throw processException(e);
2195 }
2196 finally {
2197 closeSession(session);
2198 }
2199 }
2200
2201 return count.intValue();
2202 }
2203
2204 private static final String _FINDER_COLUMN_USERID_USERID_2 = "phone.userId = ?";
2205 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2206 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2207 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
2208 new String[] {
2209 Long.class.getName(), Long.class.getName(),
2210
2211 Integer.class.getName(), Integer.class.getName(),
2212 OrderByComparator.class.getName()
2213 });
2214 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2215 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2216 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
2217 new String[] { Long.class.getName(), Long.class.getName() },
2218 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
2219 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2220 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
2221 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2222 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
2223 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2224 new String[] { Long.class.getName(), Long.class.getName() });
2225
2226
2233 @Override
2234 public List<Phone> findByC_C(long companyId, long classNameId) {
2235 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
2236 QueryUtil.ALL_POS, null);
2237 }
2238
2239
2252 @Override
2253 public List<Phone> findByC_C(long companyId, long classNameId, int start,
2254 int end) {
2255 return findByC_C(companyId, classNameId, start, end, null);
2256 }
2257
2258
2272 @Override
2273 public List<Phone> findByC_C(long companyId, long classNameId, int start,
2274 int end, OrderByComparator<Phone> orderByComparator) {
2275 return findByC_C(companyId, classNameId, start, end, orderByComparator,
2276 true);
2277 }
2278
2279
2294 @Override
2295 public List<Phone> findByC_C(long companyId, long classNameId, int start,
2296 int end, OrderByComparator<Phone> orderByComparator,
2297 boolean retrieveFromCache) {
2298 boolean pagination = true;
2299 FinderPath finderPath = null;
2300 Object[] finderArgs = null;
2301
2302 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2303 (orderByComparator == null)) {
2304 pagination = false;
2305 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2306 finderArgs = new Object[] { companyId, classNameId };
2307 }
2308 else {
2309 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2310 finderArgs = new Object[] {
2311 companyId, classNameId,
2312
2313 start, end, orderByComparator
2314 };
2315 }
2316
2317 List<Phone> list = null;
2318
2319 if (retrieveFromCache) {
2320 list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
2321 this);
2322
2323 if ((list != null) && !list.isEmpty()) {
2324 for (Phone phone : list) {
2325 if ((companyId != phone.getCompanyId()) ||
2326 (classNameId != phone.getClassNameId())) {
2327 list = null;
2328
2329 break;
2330 }
2331 }
2332 }
2333 }
2334
2335 if (list == null) {
2336 StringBundler query = null;
2337
2338 if (orderByComparator != null) {
2339 query = new StringBundler(4 +
2340 (orderByComparator.getOrderByFields().length * 3));
2341 }
2342 else {
2343 query = new StringBundler(4);
2344 }
2345
2346 query.append(_SQL_SELECT_PHONE_WHERE);
2347
2348 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2349
2350 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2351
2352 if (orderByComparator != null) {
2353 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2354 orderByComparator);
2355 }
2356 else
2357 if (pagination) {
2358 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2359 }
2360
2361 String sql = query.toString();
2362
2363 Session session = null;
2364
2365 try {
2366 session = openSession();
2367
2368 Query q = session.createQuery(sql);
2369
2370 QueryPos qPos = QueryPos.getInstance(q);
2371
2372 qPos.add(companyId);
2373
2374 qPos.add(classNameId);
2375
2376 if (!pagination) {
2377 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2378 end, false);
2379
2380 Collections.sort(list);
2381
2382 list = Collections.unmodifiableList(list);
2383 }
2384 else {
2385 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2386 end);
2387 }
2388
2389 cacheResult(list);
2390
2391 finderCache.putResult(finderPath, finderArgs, list);
2392 }
2393 catch (Exception e) {
2394 finderCache.removeResult(finderPath, finderArgs);
2395
2396 throw processException(e);
2397 }
2398 finally {
2399 closeSession(session);
2400 }
2401 }
2402
2403 return list;
2404 }
2405
2406
2415 @Override
2416 public Phone findByC_C_First(long companyId, long classNameId,
2417 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2418 Phone phone = fetchByC_C_First(companyId, classNameId, orderByComparator);
2419
2420 if (phone != null) {
2421 return phone;
2422 }
2423
2424 StringBundler msg = new StringBundler(6);
2425
2426 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2427
2428 msg.append("companyId=");
2429 msg.append(companyId);
2430
2431 msg.append(", classNameId=");
2432 msg.append(classNameId);
2433
2434 msg.append(StringPool.CLOSE_CURLY_BRACE);
2435
2436 throw new NoSuchPhoneException(msg.toString());
2437 }
2438
2439
2447 @Override
2448 public Phone fetchByC_C_First(long companyId, long classNameId,
2449 OrderByComparator<Phone> orderByComparator) {
2450 List<Phone> list = findByC_C(companyId, classNameId, 0, 1,
2451 orderByComparator);
2452
2453 if (!list.isEmpty()) {
2454 return list.get(0);
2455 }
2456
2457 return null;
2458 }
2459
2460
2469 @Override
2470 public Phone findByC_C_Last(long companyId, long classNameId,
2471 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2472 Phone phone = fetchByC_C_Last(companyId, classNameId, orderByComparator);
2473
2474 if (phone != null) {
2475 return phone;
2476 }
2477
2478 StringBundler msg = new StringBundler(6);
2479
2480 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2481
2482 msg.append("companyId=");
2483 msg.append(companyId);
2484
2485 msg.append(", classNameId=");
2486 msg.append(classNameId);
2487
2488 msg.append(StringPool.CLOSE_CURLY_BRACE);
2489
2490 throw new NoSuchPhoneException(msg.toString());
2491 }
2492
2493
2501 @Override
2502 public Phone fetchByC_C_Last(long companyId, long classNameId,
2503 OrderByComparator<Phone> orderByComparator) {
2504 int count = countByC_C(companyId, classNameId);
2505
2506 if (count == 0) {
2507 return null;
2508 }
2509
2510 List<Phone> list = findByC_C(companyId, classNameId, count - 1, count,
2511 orderByComparator);
2512
2513 if (!list.isEmpty()) {
2514 return list.get(0);
2515 }
2516
2517 return null;
2518 }
2519
2520
2530 @Override
2531 public Phone[] findByC_C_PrevAndNext(long phoneId, long companyId,
2532 long classNameId, OrderByComparator<Phone> orderByComparator)
2533 throws NoSuchPhoneException {
2534 Phone phone = findByPrimaryKey(phoneId);
2535
2536 Session session = null;
2537
2538 try {
2539 session = openSession();
2540
2541 Phone[] array = new PhoneImpl[3];
2542
2543 array[0] = getByC_C_PrevAndNext(session, phone, companyId,
2544 classNameId, orderByComparator, true);
2545
2546 array[1] = phone;
2547
2548 array[2] = getByC_C_PrevAndNext(session, phone, companyId,
2549 classNameId, orderByComparator, false);
2550
2551 return array;
2552 }
2553 catch (Exception e) {
2554 throw processException(e);
2555 }
2556 finally {
2557 closeSession(session);
2558 }
2559 }
2560
2561 protected Phone getByC_C_PrevAndNext(Session session, Phone phone,
2562 long companyId, long classNameId,
2563 OrderByComparator<Phone> orderByComparator, boolean previous) {
2564 StringBundler query = null;
2565
2566 if (orderByComparator != null) {
2567 query = new StringBundler(6 +
2568 (orderByComparator.getOrderByFields().length * 6));
2569 }
2570 else {
2571 query = new StringBundler(3);
2572 }
2573
2574 query.append(_SQL_SELECT_PHONE_WHERE);
2575
2576 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2577
2578 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2579
2580 if (orderByComparator != null) {
2581 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2582
2583 if (orderByConditionFields.length > 0) {
2584 query.append(WHERE_AND);
2585 }
2586
2587 for (int i = 0; i < orderByConditionFields.length; i++) {
2588 query.append(_ORDER_BY_ENTITY_ALIAS);
2589 query.append(orderByConditionFields[i]);
2590
2591 if ((i + 1) < orderByConditionFields.length) {
2592 if (orderByComparator.isAscending() ^ previous) {
2593 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2594 }
2595 else {
2596 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2597 }
2598 }
2599 else {
2600 if (orderByComparator.isAscending() ^ previous) {
2601 query.append(WHERE_GREATER_THAN);
2602 }
2603 else {
2604 query.append(WHERE_LESSER_THAN);
2605 }
2606 }
2607 }
2608
2609 query.append(ORDER_BY_CLAUSE);
2610
2611 String[] orderByFields = orderByComparator.getOrderByFields();
2612
2613 for (int i = 0; i < orderByFields.length; i++) {
2614 query.append(_ORDER_BY_ENTITY_ALIAS);
2615 query.append(orderByFields[i]);
2616
2617 if ((i + 1) < orderByFields.length) {
2618 if (orderByComparator.isAscending() ^ previous) {
2619 query.append(ORDER_BY_ASC_HAS_NEXT);
2620 }
2621 else {
2622 query.append(ORDER_BY_DESC_HAS_NEXT);
2623 }
2624 }
2625 else {
2626 if (orderByComparator.isAscending() ^ previous) {
2627 query.append(ORDER_BY_ASC);
2628 }
2629 else {
2630 query.append(ORDER_BY_DESC);
2631 }
2632 }
2633 }
2634 }
2635 else {
2636 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2637 }
2638
2639 String sql = query.toString();
2640
2641 Query q = session.createQuery(sql);
2642
2643 q.setFirstResult(0);
2644 q.setMaxResults(2);
2645
2646 QueryPos qPos = QueryPos.getInstance(q);
2647
2648 qPos.add(companyId);
2649
2650 qPos.add(classNameId);
2651
2652 if (orderByComparator != null) {
2653 Object[] values = orderByComparator.getOrderByConditionValues(phone);
2654
2655 for (Object value : values) {
2656 qPos.add(value);
2657 }
2658 }
2659
2660 List<Phone> list = q.list();
2661
2662 if (list.size() == 2) {
2663 return list.get(1);
2664 }
2665 else {
2666 return null;
2667 }
2668 }
2669
2670
2676 @Override
2677 public void removeByC_C(long companyId, long classNameId) {
2678 for (Phone phone : findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
2679 QueryUtil.ALL_POS, null)) {
2680 remove(phone);
2681 }
2682 }
2683
2684
2691 @Override
2692 public int countByC_C(long companyId, long classNameId) {
2693 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
2694
2695 Object[] finderArgs = new Object[] { companyId, classNameId };
2696
2697 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2698
2699 if (count == null) {
2700 StringBundler query = new StringBundler(3);
2701
2702 query.append(_SQL_COUNT_PHONE_WHERE);
2703
2704 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2705
2706 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2707
2708 String sql = query.toString();
2709
2710 Session session = null;
2711
2712 try {
2713 session = openSession();
2714
2715 Query q = session.createQuery(sql);
2716
2717 QueryPos qPos = QueryPos.getInstance(q);
2718
2719 qPos.add(companyId);
2720
2721 qPos.add(classNameId);
2722
2723 count = (Long)q.uniqueResult();
2724
2725 finderCache.putResult(finderPath, finderArgs, count);
2726 }
2727 catch (Exception e) {
2728 finderCache.removeResult(finderPath, finderArgs);
2729
2730 throw processException(e);
2731 }
2732 finally {
2733 closeSession(session);
2734 }
2735 }
2736
2737 return count.intValue();
2738 }
2739
2740 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
2741 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "phone.classNameId = ?";
2742 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2743 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2744 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
2745 new String[] {
2746 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2747
2748 Integer.class.getName(), Integer.class.getName(),
2749 OrderByComparator.class.getName()
2750 });
2751 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2752 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2753 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
2754 new String[] {
2755 Long.class.getName(), Long.class.getName(), Long.class.getName()
2756 },
2757 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
2758 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2759 PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
2760 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
2761 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2762 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
2763 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
2764 new String[] {
2765 Long.class.getName(), Long.class.getName(), Long.class.getName()
2766 });
2767
2768
2776 @Override
2777 public List<Phone> findByC_C_C(long companyId, long classNameId,
2778 long classPK) {
2779 return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
2780 QueryUtil.ALL_POS, null);
2781 }
2782
2783
2797 @Override
2798 public List<Phone> findByC_C_C(long companyId, long classNameId,
2799 long classPK, int start, int end) {
2800 return findByC_C_C(companyId, classNameId, classPK, start, end, null);
2801 }
2802
2803
2818 @Override
2819 public List<Phone> findByC_C_C(long companyId, long classNameId,
2820 long classPK, int start, int end,
2821 OrderByComparator<Phone> orderByComparator) {
2822 return findByC_C_C(companyId, classNameId, classPK, start, end,
2823 orderByComparator, true);
2824 }
2825
2826
2842 @Override
2843 public List<Phone> findByC_C_C(long companyId, long classNameId,
2844 long classPK, int start, int end,
2845 OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
2846 boolean pagination = true;
2847 FinderPath finderPath = null;
2848 Object[] finderArgs = null;
2849
2850 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2851 (orderByComparator == null)) {
2852 pagination = false;
2853 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
2854 finderArgs = new Object[] { companyId, classNameId, classPK };
2855 }
2856 else {
2857 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
2858 finderArgs = new Object[] {
2859 companyId, classNameId, classPK,
2860
2861 start, end, orderByComparator
2862 };
2863 }
2864
2865 List<Phone> list = null;
2866
2867 if (retrieveFromCache) {
2868 list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
2869 this);
2870
2871 if ((list != null) && !list.isEmpty()) {
2872 for (Phone phone : list) {
2873 if ((companyId != phone.getCompanyId()) ||
2874 (classNameId != phone.getClassNameId()) ||
2875 (classPK != phone.getClassPK())) {
2876 list = null;
2877
2878 break;
2879 }
2880 }
2881 }
2882 }
2883
2884 if (list == null) {
2885 StringBundler query = null;
2886
2887 if (orderByComparator != null) {
2888 query = new StringBundler(5 +
2889 (orderByComparator.getOrderByFields().length * 3));
2890 }
2891 else {
2892 query = new StringBundler(5);
2893 }
2894
2895 query.append(_SQL_SELECT_PHONE_WHERE);
2896
2897 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2898
2899 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2900
2901 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2902
2903 if (orderByComparator != null) {
2904 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2905 orderByComparator);
2906 }
2907 else
2908 if (pagination) {
2909 query.append(PhoneModelImpl.ORDER_BY_JPQL);
2910 }
2911
2912 String sql = query.toString();
2913
2914 Session session = null;
2915
2916 try {
2917 session = openSession();
2918
2919 Query q = session.createQuery(sql);
2920
2921 QueryPos qPos = QueryPos.getInstance(q);
2922
2923 qPos.add(companyId);
2924
2925 qPos.add(classNameId);
2926
2927 qPos.add(classPK);
2928
2929 if (!pagination) {
2930 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2931 end, false);
2932
2933 Collections.sort(list);
2934
2935 list = Collections.unmodifiableList(list);
2936 }
2937 else {
2938 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2939 end);
2940 }
2941
2942 cacheResult(list);
2943
2944 finderCache.putResult(finderPath, finderArgs, list);
2945 }
2946 catch (Exception e) {
2947 finderCache.removeResult(finderPath, finderArgs);
2948
2949 throw processException(e);
2950 }
2951 finally {
2952 closeSession(session);
2953 }
2954 }
2955
2956 return list;
2957 }
2958
2959
2969 @Override
2970 public Phone findByC_C_C_First(long companyId, long classNameId,
2971 long classPK, OrderByComparator<Phone> orderByComparator)
2972 throws NoSuchPhoneException {
2973 Phone phone = fetchByC_C_C_First(companyId, classNameId, classPK,
2974 orderByComparator);
2975
2976 if (phone != null) {
2977 return phone;
2978 }
2979
2980 StringBundler msg = new StringBundler(8);
2981
2982 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2983
2984 msg.append("companyId=");
2985 msg.append(companyId);
2986
2987 msg.append(", classNameId=");
2988 msg.append(classNameId);
2989
2990 msg.append(", classPK=");
2991 msg.append(classPK);
2992
2993 msg.append(StringPool.CLOSE_CURLY_BRACE);
2994
2995 throw new NoSuchPhoneException(msg.toString());
2996 }
2997
2998
3007 @Override
3008 public Phone fetchByC_C_C_First(long companyId, long classNameId,
3009 long classPK, OrderByComparator<Phone> orderByComparator) {
3010 List<Phone> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
3011 orderByComparator);
3012
3013 if (!list.isEmpty()) {
3014 return list.get(0);
3015 }
3016
3017 return null;
3018 }
3019
3020
3030 @Override
3031 public Phone findByC_C_C_Last(long companyId, long classNameId,
3032 long classPK, OrderByComparator<Phone> orderByComparator)
3033 throws NoSuchPhoneException {
3034 Phone phone = fetchByC_C_C_Last(companyId, classNameId, classPK,
3035 orderByComparator);
3036
3037 if (phone != null) {
3038 return phone;
3039 }
3040
3041 StringBundler msg = new StringBundler(8);
3042
3043 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3044
3045 msg.append("companyId=");
3046 msg.append(companyId);
3047
3048 msg.append(", classNameId=");
3049 msg.append(classNameId);
3050
3051 msg.append(", classPK=");
3052 msg.append(classPK);
3053
3054 msg.append(StringPool.CLOSE_CURLY_BRACE);
3055
3056 throw new NoSuchPhoneException(msg.toString());
3057 }
3058
3059
3068 @Override
3069 public Phone fetchByC_C_C_Last(long companyId, long classNameId,
3070 long classPK, OrderByComparator<Phone> orderByComparator) {
3071 int count = countByC_C_C(companyId, classNameId, classPK);
3072
3073 if (count == 0) {
3074 return null;
3075 }
3076
3077 List<Phone> list = findByC_C_C(companyId, classNameId, classPK,
3078 count - 1, count, orderByComparator);
3079
3080 if (!list.isEmpty()) {
3081 return list.get(0);
3082 }
3083
3084 return null;
3085 }
3086
3087
3098 @Override
3099 public Phone[] findByC_C_C_PrevAndNext(long phoneId, long companyId,
3100 long classNameId, long classPK,
3101 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3102 Phone phone = findByPrimaryKey(phoneId);
3103
3104 Session session = null;
3105
3106 try {
3107 session = openSession();
3108
3109 Phone[] array = new PhoneImpl[3];
3110
3111 array[0] = getByC_C_C_PrevAndNext(session, phone, companyId,
3112 classNameId, classPK, orderByComparator, true);
3113
3114 array[1] = phone;
3115
3116 array[2] = getByC_C_C_PrevAndNext(session, phone, companyId,
3117 classNameId, classPK, orderByComparator, false);
3118
3119 return array;
3120 }
3121 catch (Exception e) {
3122 throw processException(e);
3123 }
3124 finally {
3125 closeSession(session);
3126 }
3127 }
3128
3129 protected Phone getByC_C_C_PrevAndNext(Session session, Phone phone,
3130 long companyId, long classNameId, long classPK,
3131 OrderByComparator<Phone> orderByComparator, boolean previous) {
3132 StringBundler query = null;
3133
3134 if (orderByComparator != null) {
3135 query = new StringBundler(6 +
3136 (orderByComparator.getOrderByFields().length * 6));
3137 }
3138 else {
3139 query = new StringBundler(3);
3140 }
3141
3142 query.append(_SQL_SELECT_PHONE_WHERE);
3143
3144 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3145
3146 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3147
3148 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3149
3150 if (orderByComparator != null) {
3151 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3152
3153 if (orderByConditionFields.length > 0) {
3154 query.append(WHERE_AND);
3155 }
3156
3157 for (int i = 0; i < orderByConditionFields.length; i++) {
3158 query.append(_ORDER_BY_ENTITY_ALIAS);
3159 query.append(orderByConditionFields[i]);
3160
3161 if ((i + 1) < orderByConditionFields.length) {
3162 if (orderByComparator.isAscending() ^ previous) {
3163 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3164 }
3165 else {
3166 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3167 }
3168 }
3169 else {
3170 if (orderByComparator.isAscending() ^ previous) {
3171 query.append(WHERE_GREATER_THAN);
3172 }
3173 else {
3174 query.append(WHERE_LESSER_THAN);
3175 }
3176 }
3177 }
3178
3179 query.append(ORDER_BY_CLAUSE);
3180
3181 String[] orderByFields = orderByComparator.getOrderByFields();
3182
3183 for (int i = 0; i < orderByFields.length; i++) {
3184 query.append(_ORDER_BY_ENTITY_ALIAS);
3185 query.append(orderByFields[i]);
3186
3187 if ((i + 1) < orderByFields.length) {
3188 if (orderByComparator.isAscending() ^ previous) {
3189 query.append(ORDER_BY_ASC_HAS_NEXT);
3190 }
3191 else {
3192 query.append(ORDER_BY_DESC_HAS_NEXT);
3193 }
3194 }
3195 else {
3196 if (orderByComparator.isAscending() ^ previous) {
3197 query.append(ORDER_BY_ASC);
3198 }
3199 else {
3200 query.append(ORDER_BY_DESC);
3201 }
3202 }
3203 }
3204 }
3205 else {
3206 query.append(PhoneModelImpl.ORDER_BY_JPQL);
3207 }
3208
3209 String sql = query.toString();
3210
3211 Query q = session.createQuery(sql);
3212
3213 q.setFirstResult(0);
3214 q.setMaxResults(2);
3215
3216 QueryPos qPos = QueryPos.getInstance(q);
3217
3218 qPos.add(companyId);
3219
3220 qPos.add(classNameId);
3221
3222 qPos.add(classPK);
3223
3224 if (orderByComparator != null) {
3225 Object[] values = orderByComparator.getOrderByConditionValues(phone);
3226
3227 for (Object value : values) {
3228 qPos.add(value);
3229 }
3230 }
3231
3232 List<Phone> list = q.list();
3233
3234 if (list.size() == 2) {
3235 return list.get(1);
3236 }
3237 else {
3238 return null;
3239 }
3240 }
3241
3242
3249 @Override
3250 public void removeByC_C_C(long companyId, long classNameId, long classPK) {
3251 for (Phone phone : findByC_C_C(companyId, classNameId, classPK,
3252 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3253 remove(phone);
3254 }
3255 }
3256
3257
3265 @Override
3266 public int countByC_C_C(long companyId, long classNameId, long classPK) {
3267 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
3268
3269 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
3270
3271 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3272
3273 if (count == null) {
3274 StringBundler query = new StringBundler(4);
3275
3276 query.append(_SQL_COUNT_PHONE_WHERE);
3277
3278 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3279
3280 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3281
3282 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3283
3284 String sql = query.toString();
3285
3286 Session session = null;
3287
3288 try {
3289 session = openSession();
3290
3291 Query q = session.createQuery(sql);
3292
3293 QueryPos qPos = QueryPos.getInstance(q);
3294
3295 qPos.add(companyId);
3296
3297 qPos.add(classNameId);
3298
3299 qPos.add(classPK);
3300
3301 count = (Long)q.uniqueResult();
3302
3303 finderCache.putResult(finderPath, finderArgs, count);
3304 }
3305 catch (Exception e) {
3306 finderCache.removeResult(finderPath, finderArgs);
3307
3308 throw processException(e);
3309 }
3310 finally {
3311 closeSession(session);
3312 }
3313 }
3314
3315 return count.intValue();
3316 }
3317
3318 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
3319 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
3320 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "phone.classPK = ?";
3321 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3322 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
3323 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_P",
3324 new String[] {
3325 Long.class.getName(), Long.class.getName(), Long.class.getName(),
3326 Boolean.class.getName(),
3327
3328 Integer.class.getName(), Integer.class.getName(),
3329 OrderByComparator.class.getName()
3330 });
3331 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P =
3332 new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3333 PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
3334 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_P",
3335 new String[] {
3336 Long.class.getName(), Long.class.getName(), Long.class.getName(),
3337 Boolean.class.getName()
3338 },
3339 PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
3340 PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3341 PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
3342 PhoneModelImpl.PRIMARY_COLUMN_BITMASK |
3343 PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
3344 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3345 PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
3346 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_P",
3347 new String[] {
3348 Long.class.getName(), Long.class.getName(), Long.class.getName(),
3349 Boolean.class.getName()
3350 });
3351
3352
3361 @Override
3362 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3363 long classPK, boolean primary) {
3364 return findByC_C_C_P(companyId, classNameId, classPK, primary,
3365 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3366 }
3367
3368
3383 @Override
3384 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3385 long classPK, boolean primary, int start, int end) {
3386 return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
3387 end, null);
3388 }
3389
3390
3406 @Override
3407 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3408 long classPK, boolean primary, int start, int end,
3409 OrderByComparator<Phone> orderByComparator) {
3410 return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
3411 end, orderByComparator, true);
3412 }
3413
3414
3431 @Override
3432 public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3433 long classPK, boolean primary, int start, int end,
3434 OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
3435 boolean pagination = true;
3436 FinderPath finderPath = null;
3437 Object[] finderArgs = null;
3438
3439 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3440 (orderByComparator == null)) {
3441 pagination = false;
3442 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P;
3443 finderArgs = new Object[] { companyId, classNameId, classPK, primary };
3444 }
3445 else {
3446 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
3447 finderArgs = new Object[] {
3448 companyId, classNameId, classPK, primary,
3449
3450 start, end, orderByComparator
3451 };
3452 }
3453
3454 List<Phone> list = null;
3455
3456 if (retrieveFromCache) {
3457 list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
3458 this);
3459
3460 if ((list != null) && !list.isEmpty()) {
3461 for (Phone phone : list) {
3462 if ((companyId != phone.getCompanyId()) ||
3463 (classNameId != phone.getClassNameId()) ||
3464 (classPK != phone.getClassPK()) ||
3465 (primary != phone.getPrimary())) {
3466 list = null;
3467
3468 break;
3469 }
3470 }
3471 }
3472 }
3473
3474 if (list == null) {
3475 StringBundler query = null;
3476
3477 if (orderByComparator != null) {
3478 query = new StringBundler(6 +
3479 (orderByComparator.getOrderByFields().length * 3));
3480 }
3481 else {
3482 query = new StringBundler(6);
3483 }
3484
3485 query.append(_SQL_SELECT_PHONE_WHERE);
3486
3487 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3488
3489 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3490
3491 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3492
3493 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3494
3495 if (orderByComparator != null) {
3496 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3497 orderByComparator);
3498 }
3499 else
3500 if (pagination) {
3501 query.append(PhoneModelImpl.ORDER_BY_JPQL);
3502 }
3503
3504 String sql = query.toString();
3505
3506 Session session = null;
3507
3508 try {
3509 session = openSession();
3510
3511 Query q = session.createQuery(sql);
3512
3513 QueryPos qPos = QueryPos.getInstance(q);
3514
3515 qPos.add(companyId);
3516
3517 qPos.add(classNameId);
3518
3519 qPos.add(classPK);
3520
3521 qPos.add(primary);
3522
3523 if (!pagination) {
3524 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
3525 end, false);
3526
3527 Collections.sort(list);
3528
3529 list = Collections.unmodifiableList(list);
3530 }
3531 else {
3532 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
3533 end);
3534 }
3535
3536 cacheResult(list);
3537
3538 finderCache.putResult(finderPath, finderArgs, list);
3539 }
3540 catch (Exception e) {
3541 finderCache.removeResult(finderPath, finderArgs);
3542
3543 throw processException(e);
3544 }
3545 finally {
3546 closeSession(session);
3547 }
3548 }
3549
3550 return list;
3551 }
3552
3553
3564 @Override
3565 public Phone findByC_C_C_P_First(long companyId, long classNameId,
3566 long classPK, boolean primary,
3567 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3568 Phone phone = fetchByC_C_C_P_First(companyId, classNameId, classPK,
3569 primary, orderByComparator);
3570
3571 if (phone != null) {
3572 return phone;
3573 }
3574
3575 StringBundler msg = new StringBundler(10);
3576
3577 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3578
3579 msg.append("companyId=");
3580 msg.append(companyId);
3581
3582 msg.append(", classNameId=");
3583 msg.append(classNameId);
3584
3585 msg.append(", classPK=");
3586 msg.append(classPK);
3587
3588 msg.append(", primary=");
3589 msg.append(primary);
3590
3591 msg.append(StringPool.CLOSE_CURLY_BRACE);
3592
3593 throw new NoSuchPhoneException(msg.toString());
3594 }
3595
3596
3606 @Override
3607 public Phone fetchByC_C_C_P_First(long companyId, long classNameId,
3608 long classPK, boolean primary,
3609 OrderByComparator<Phone> orderByComparator) {
3610 List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
3611 primary, 0, 1, orderByComparator);
3612
3613 if (!list.isEmpty()) {
3614 return list.get(0);
3615 }
3616
3617 return null;
3618 }
3619
3620
3631 @Override
3632 public Phone findByC_C_C_P_Last(long companyId, long classNameId,
3633 long classPK, boolean primary,
3634 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3635 Phone phone = fetchByC_C_C_P_Last(companyId, classNameId, classPK,
3636 primary, orderByComparator);
3637
3638 if (phone != null) {
3639 return phone;
3640 }
3641
3642 StringBundler msg = new StringBundler(10);
3643
3644 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3645
3646 msg.append("companyId=");
3647 msg.append(companyId);
3648
3649 msg.append(", classNameId=");
3650 msg.append(classNameId);
3651
3652 msg.append(", classPK=");
3653 msg.append(classPK);
3654
3655 msg.append(", primary=");
3656 msg.append(primary);
3657
3658 msg.append(StringPool.CLOSE_CURLY_BRACE);
3659
3660 throw new NoSuchPhoneException(msg.toString());
3661 }
3662
3663
3673 @Override
3674 public Phone fetchByC_C_C_P_Last(long companyId, long classNameId,
3675 long classPK, boolean primary,
3676 OrderByComparator<Phone> orderByComparator) {
3677 int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
3678
3679 if (count == 0) {
3680 return null;
3681 }
3682
3683 List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
3684 primary, count - 1, count, orderByComparator);
3685
3686 if (!list.isEmpty()) {
3687 return list.get(0);
3688 }
3689
3690 return null;
3691 }
3692
3693
3705 @Override
3706 public Phone[] findByC_C_C_P_PrevAndNext(long phoneId, long companyId,
3707 long classNameId, long classPK, boolean primary,
3708 OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3709 Phone phone = findByPrimaryKey(phoneId);
3710
3711 Session session = null;
3712
3713 try {
3714 session = openSession();
3715
3716 Phone[] array = new PhoneImpl[3];
3717
3718 array[0] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
3719 classNameId, classPK, primary, orderByComparator, true);
3720
3721 array[1] = phone;
3722
3723 array[2] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
3724 classNameId, classPK, primary, orderByComparator, false);
3725
3726 return array;
3727 }
3728 catch (Exception e) {
3729 throw processException(e);
3730 }
3731 finally {
3732 closeSession(session);
3733 }
3734 }
3735
3736 protected Phone getByC_C_C_P_PrevAndNext(Session session, Phone phone,
3737 long companyId, long classNameId, long classPK, boolean primary,
3738 OrderByComparator<Phone> orderByComparator, boolean previous) {
3739 StringBundler query = null;
3740
3741 if (orderByComparator != null) {
3742 query = new StringBundler(6 +
3743 (orderByComparator.getOrderByFields().length * 6));
3744 }
3745 else {
3746 query = new StringBundler(3);
3747 }
3748
3749 query.append(_SQL_SELECT_PHONE_WHERE);
3750
3751 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3752
3753 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3754
3755 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3756
3757 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3758
3759 if (orderByComparator != null) {
3760 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3761
3762 if (orderByConditionFields.length > 0) {
3763 query.append(WHERE_AND);
3764 }
3765
3766 for (int i = 0; i < orderByConditionFields.length; i++) {
3767 query.append(_ORDER_BY_ENTITY_ALIAS);
3768 query.append(orderByConditionFields[i]);
3769
3770 if ((i + 1) < orderByConditionFields.length) {
3771 if (orderByComparator.isAscending() ^ previous) {
3772 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3773 }
3774 else {
3775 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3776 }
3777 }
3778 else {
3779 if (orderByComparator.isAscending() ^ previous) {
3780 query.append(WHERE_GREATER_THAN);
3781 }
3782 else {
3783 query.append(WHERE_LESSER_THAN);
3784 }
3785 }
3786 }
3787
3788 query.append(ORDER_BY_CLAUSE);
3789
3790 String[] orderByFields = orderByComparator.getOrderByFields();
3791
3792 for (int i = 0; i < orderByFields.length; i++) {
3793 query.append(_ORDER_BY_ENTITY_ALIAS);
3794 query.append(orderByFields[i]);
3795
3796 if ((i + 1) < orderByFields.length) {
3797 if (orderByComparator.isAscending() ^ previous) {
3798 query.append(ORDER_BY_ASC_HAS_NEXT);
3799 }
3800 else {
3801 query.append(ORDER_BY_DESC_HAS_NEXT);
3802 }
3803 }
3804 else {
3805 if (orderByComparator.isAscending() ^ previous) {
3806 query.append(ORDER_BY_ASC);
3807 }
3808 else {
3809 query.append(ORDER_BY_DESC);
3810 }
3811 }
3812 }
3813 }
3814 else {
3815 query.append(PhoneModelImpl.ORDER_BY_JPQL);
3816 }
3817
3818 String sql = query.toString();
3819
3820 Query q = session.createQuery(sql);
3821
3822 q.setFirstResult(0);
3823 q.setMaxResults(2);
3824
3825 QueryPos qPos = QueryPos.getInstance(q);
3826
3827 qPos.add(companyId);
3828
3829 qPos.add(classNameId);
3830
3831 qPos.add(classPK);
3832
3833 qPos.add(primary);
3834
3835 if (orderByComparator != null) {
3836 Object[] values = orderByComparator.getOrderByConditionValues(phone);
3837
3838 for (Object value : values) {
3839 qPos.add(value);
3840 }
3841 }
3842
3843 List<Phone> list = q.list();
3844
3845 if (list.size() == 2) {
3846 return list.get(1);
3847 }
3848 else {
3849 return null;
3850 }
3851 }
3852
3853
3861 @Override
3862 public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
3863 boolean primary) {
3864 for (Phone phone : findByC_C_C_P(companyId, classNameId, classPK,
3865 primary, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3866 remove(phone);
3867 }
3868 }
3869
3870
3879 @Override
3880 public int countByC_C_C_P(long companyId, long classNameId, long classPK,
3881 boolean primary) {
3882 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C_P;
3883
3884 Object[] finderArgs = new Object[] {
3885 companyId, classNameId, classPK, primary
3886 };
3887
3888 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3889
3890 if (count == null) {
3891 StringBundler query = new StringBundler(5);
3892
3893 query.append(_SQL_COUNT_PHONE_WHERE);
3894
3895 query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3896
3897 query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3898
3899 query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3900
3901 query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3902
3903 String sql = query.toString();
3904
3905 Session session = null;
3906
3907 try {
3908 session = openSession();
3909
3910 Query q = session.createQuery(sql);
3911
3912 QueryPos qPos = QueryPos.getInstance(q);
3913
3914 qPos.add(companyId);
3915
3916 qPos.add(classNameId);
3917
3918 qPos.add(classPK);
3919
3920 qPos.add(primary);
3921
3922 count = (Long)q.uniqueResult();
3923
3924 finderCache.putResult(finderPath, finderArgs, count);
3925 }
3926 catch (Exception e) {
3927 finderCache.removeResult(finderPath, finderArgs);
3928
3929 throw processException(e);
3930 }
3931 finally {
3932 closeSession(session);
3933 }
3934 }
3935
3936 return count.intValue();
3937 }
3938
3939 private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "phone.companyId = ? AND ";
3940 private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
3941 private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "phone.classPK = ? AND ";
3942 private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "phone.primary = ?";
3943
3944 public PhonePersistenceImpl() {
3945 setModelClass(Phone.class);
3946 }
3947
3948
3953 @Override
3954 public void cacheResult(Phone phone) {
3955 entityCache.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3956 PhoneImpl.class, phone.getPrimaryKey(), phone);
3957
3958 phone.resetOriginalValues();
3959 }
3960
3961
3966 @Override
3967 public void cacheResult(List<Phone> phones) {
3968 for (Phone phone : phones) {
3969 if (entityCache.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3970 PhoneImpl.class, phone.getPrimaryKey()) == null) {
3971 cacheResult(phone);
3972 }
3973 else {
3974 phone.resetOriginalValues();
3975 }
3976 }
3977 }
3978
3979
3986 @Override
3987 public void clearCache() {
3988 entityCache.clearCache(PhoneImpl.class);
3989
3990 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
3991 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3992 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3993 }
3994
3995
4002 @Override
4003 public void clearCache(Phone phone) {
4004 entityCache.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4005 PhoneImpl.class, phone.getPrimaryKey());
4006
4007 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4008 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4009 }
4010
4011 @Override
4012 public void clearCache(List<Phone> phones) {
4013 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4014 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4015
4016 for (Phone phone : phones) {
4017 entityCache.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4018 PhoneImpl.class, phone.getPrimaryKey());
4019 }
4020 }
4021
4022
4028 @Override
4029 public Phone create(long phoneId) {
4030 Phone phone = new PhoneImpl();
4031
4032 phone.setNew(true);
4033 phone.setPrimaryKey(phoneId);
4034
4035 String uuid = PortalUUIDUtil.generate();
4036
4037 phone.setUuid(uuid);
4038
4039 return phone;
4040 }
4041
4042
4049 @Override
4050 public Phone remove(long phoneId) throws NoSuchPhoneException {
4051 return remove((Serializable)phoneId);
4052 }
4053
4054
4061 @Override
4062 public Phone remove(Serializable primaryKey) throws NoSuchPhoneException {
4063 Session session = null;
4064
4065 try {
4066 session = openSession();
4067
4068 Phone phone = (Phone)session.get(PhoneImpl.class, primaryKey);
4069
4070 if (phone == null) {
4071 if (_log.isWarnEnabled()) {
4072 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4073 }
4074
4075 throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4076 primaryKey);
4077 }
4078
4079 return remove(phone);
4080 }
4081 catch (NoSuchPhoneException nsee) {
4082 throw nsee;
4083 }
4084 catch (Exception e) {
4085 throw processException(e);
4086 }
4087 finally {
4088 closeSession(session);
4089 }
4090 }
4091
4092 @Override
4093 protected Phone removeImpl(Phone phone) {
4094 phone = toUnwrappedModel(phone);
4095
4096 Session session = null;
4097
4098 try {
4099 session = openSession();
4100
4101 if (!session.contains(phone)) {
4102 phone = (Phone)session.get(PhoneImpl.class,
4103 phone.getPrimaryKeyObj());
4104 }
4105
4106 if (phone != null) {
4107 session.delete(phone);
4108 }
4109 }
4110 catch (Exception e) {
4111 throw processException(e);
4112 }
4113 finally {
4114 closeSession(session);
4115 }
4116
4117 if (phone != null) {
4118 clearCache(phone);
4119 }
4120
4121 return phone;
4122 }
4123
4124 @Override
4125 public Phone updateImpl(Phone phone) {
4126 phone = toUnwrappedModel(phone);
4127
4128 boolean isNew = phone.isNew();
4129
4130 PhoneModelImpl phoneModelImpl = (PhoneModelImpl)phone;
4131
4132 if (Validator.isNull(phone.getUuid())) {
4133 String uuid = PortalUUIDUtil.generate();
4134
4135 phone.setUuid(uuid);
4136 }
4137
4138 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
4139
4140 Date now = new Date();
4141
4142 if (isNew && (phone.getCreateDate() == null)) {
4143 if (serviceContext == null) {
4144 phone.setCreateDate(now);
4145 }
4146 else {
4147 phone.setCreateDate(serviceContext.getCreateDate(now));
4148 }
4149 }
4150
4151 if (!phoneModelImpl.hasSetModifiedDate()) {
4152 if (serviceContext == null) {
4153 phone.setModifiedDate(now);
4154 }
4155 else {
4156 phone.setModifiedDate(serviceContext.getModifiedDate(now));
4157 }
4158 }
4159
4160 Session session = null;
4161
4162 try {
4163 session = openSession();
4164
4165 if (phone.isNew()) {
4166 session.save(phone);
4167
4168 phone.setNew(false);
4169 }
4170 else {
4171 phone = (Phone)session.merge(phone);
4172 }
4173 }
4174 catch (Exception e) {
4175 throw processException(e);
4176 }
4177 finally {
4178 closeSession(session);
4179 }
4180
4181 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4182
4183 if (isNew || !PhoneModelImpl.COLUMN_BITMASK_ENABLED) {
4184 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4185 }
4186
4187 else {
4188 if ((phoneModelImpl.getColumnBitmask() &
4189 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4190 Object[] args = new Object[] { phoneModelImpl.getOriginalUuid() };
4191
4192 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4193 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4194 args);
4195
4196 args = new Object[] { phoneModelImpl.getUuid() };
4197
4198 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4199 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4200 args);
4201 }
4202
4203 if ((phoneModelImpl.getColumnBitmask() &
4204 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4205 Object[] args = new Object[] {
4206 phoneModelImpl.getOriginalUuid(),
4207 phoneModelImpl.getOriginalCompanyId()
4208 };
4209
4210 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4211 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4212 args);
4213
4214 args = new Object[] {
4215 phoneModelImpl.getUuid(), phoneModelImpl.getCompanyId()
4216 };
4217
4218 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4219 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4220 args);
4221 }
4222
4223 if ((phoneModelImpl.getColumnBitmask() &
4224 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4225 Object[] args = new Object[] {
4226 phoneModelImpl.getOriginalCompanyId()
4227 };
4228
4229 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
4230 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4231 args);
4232
4233 args = new Object[] { phoneModelImpl.getCompanyId() };
4234
4235 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
4236 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4237 args);
4238 }
4239
4240 if ((phoneModelImpl.getColumnBitmask() &
4241 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
4242 Object[] args = new Object[] { phoneModelImpl.getOriginalUserId() };
4243
4244 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4245 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4246 args);
4247
4248 args = new Object[] { phoneModelImpl.getUserId() };
4249
4250 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4251 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4252 args);
4253 }
4254
4255 if ((phoneModelImpl.getColumnBitmask() &
4256 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
4257 Object[] args = new Object[] {
4258 phoneModelImpl.getOriginalCompanyId(),
4259 phoneModelImpl.getOriginalClassNameId()
4260 };
4261
4262 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4263 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4264 args);
4265
4266 args = new Object[] {
4267 phoneModelImpl.getCompanyId(),
4268 phoneModelImpl.getClassNameId()
4269 };
4270
4271 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4272 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4273 args);
4274 }
4275
4276 if ((phoneModelImpl.getColumnBitmask() &
4277 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
4278 Object[] args = new Object[] {
4279 phoneModelImpl.getOriginalCompanyId(),
4280 phoneModelImpl.getOriginalClassNameId(),
4281 phoneModelImpl.getOriginalClassPK()
4282 };
4283
4284 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4285 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4286 args);
4287
4288 args = new Object[] {
4289 phoneModelImpl.getCompanyId(),
4290 phoneModelImpl.getClassNameId(),
4291 phoneModelImpl.getClassPK()
4292 };
4293
4294 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4295 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4296 args);
4297 }
4298
4299 if ((phoneModelImpl.getColumnBitmask() &
4300 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P.getColumnBitmask()) != 0) {
4301 Object[] args = new Object[] {
4302 phoneModelImpl.getOriginalCompanyId(),
4303 phoneModelImpl.getOriginalClassNameId(),
4304 phoneModelImpl.getOriginalClassPK(),
4305 phoneModelImpl.getOriginalPrimary()
4306 };
4307
4308 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4309 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4310 args);
4311
4312 args = new Object[] {
4313 phoneModelImpl.getCompanyId(),
4314 phoneModelImpl.getClassNameId(),
4315 phoneModelImpl.getClassPK(), phoneModelImpl.getPrimary()
4316 };
4317
4318 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4319 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4320 args);
4321 }
4322 }
4323
4324 entityCache.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4325 PhoneImpl.class, phone.getPrimaryKey(), phone, false);
4326
4327 phone.resetOriginalValues();
4328
4329 return phone;
4330 }
4331
4332 protected Phone toUnwrappedModel(Phone phone) {
4333 if (phone instanceof PhoneImpl) {
4334 return phone;
4335 }
4336
4337 PhoneImpl phoneImpl = new PhoneImpl();
4338
4339 phoneImpl.setNew(phone.isNew());
4340 phoneImpl.setPrimaryKey(phone.getPrimaryKey());
4341
4342 phoneImpl.setMvccVersion(phone.getMvccVersion());
4343 phoneImpl.setUuid(phone.getUuid());
4344 phoneImpl.setPhoneId(phone.getPhoneId());
4345 phoneImpl.setCompanyId(phone.getCompanyId());
4346 phoneImpl.setUserId(phone.getUserId());
4347 phoneImpl.setUserName(phone.getUserName());
4348 phoneImpl.setCreateDate(phone.getCreateDate());
4349 phoneImpl.setModifiedDate(phone.getModifiedDate());
4350 phoneImpl.setClassNameId(phone.getClassNameId());
4351 phoneImpl.setClassPK(phone.getClassPK());
4352 phoneImpl.setNumber(phone.getNumber());
4353 phoneImpl.setExtension(phone.getExtension());
4354 phoneImpl.setTypeId(phone.getTypeId());
4355 phoneImpl.setPrimary(phone.isPrimary());
4356
4357 return phoneImpl;
4358 }
4359
4360
4367 @Override
4368 public Phone findByPrimaryKey(Serializable primaryKey)
4369 throws NoSuchPhoneException {
4370 Phone phone = fetchByPrimaryKey(primaryKey);
4371
4372 if (phone == null) {
4373 if (_log.isWarnEnabled()) {
4374 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4375 }
4376
4377 throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4378 primaryKey);
4379 }
4380
4381 return phone;
4382 }
4383
4384
4391 @Override
4392 public Phone findByPrimaryKey(long phoneId) throws NoSuchPhoneException {
4393 return findByPrimaryKey((Serializable)phoneId);
4394 }
4395
4396
4402 @Override
4403 public Phone fetchByPrimaryKey(Serializable primaryKey) {
4404 Phone phone = (Phone)entityCache.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4405 PhoneImpl.class, primaryKey);
4406
4407 if (phone == _nullPhone) {
4408 return null;
4409 }
4410
4411 if (phone == null) {
4412 Session session = null;
4413
4414 try {
4415 session = openSession();
4416
4417 phone = (Phone)session.get(PhoneImpl.class, primaryKey);
4418
4419 if (phone != null) {
4420 cacheResult(phone);
4421 }
4422 else {
4423 entityCache.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4424 PhoneImpl.class, primaryKey, _nullPhone);
4425 }
4426 }
4427 catch (Exception e) {
4428 entityCache.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4429 PhoneImpl.class, primaryKey);
4430
4431 throw processException(e);
4432 }
4433 finally {
4434 closeSession(session);
4435 }
4436 }
4437
4438 return phone;
4439 }
4440
4441
4447 @Override
4448 public Phone fetchByPrimaryKey(long phoneId) {
4449 return fetchByPrimaryKey((Serializable)phoneId);
4450 }
4451
4452 @Override
4453 public Map<Serializable, Phone> fetchByPrimaryKeys(
4454 Set<Serializable> primaryKeys) {
4455 if (primaryKeys.isEmpty()) {
4456 return Collections.emptyMap();
4457 }
4458
4459 Map<Serializable, Phone> map = new HashMap<Serializable, Phone>();
4460
4461 if (primaryKeys.size() == 1) {
4462 Iterator<Serializable> iterator = primaryKeys.iterator();
4463
4464 Serializable primaryKey = iterator.next();
4465
4466 Phone phone = fetchByPrimaryKey(primaryKey);
4467
4468 if (phone != null) {
4469 map.put(primaryKey, phone);
4470 }
4471
4472 return map;
4473 }
4474
4475 Set<Serializable> uncachedPrimaryKeys = null;
4476
4477 for (Serializable primaryKey : primaryKeys) {
4478 Phone phone = (Phone)entityCache.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4479 PhoneImpl.class, primaryKey);
4480
4481 if (phone == null) {
4482 if (uncachedPrimaryKeys == null) {
4483 uncachedPrimaryKeys = new HashSet<Serializable>();
4484 }
4485
4486 uncachedPrimaryKeys.add(primaryKey);
4487 }
4488 else {
4489 map.put(primaryKey, phone);
4490 }
4491 }
4492
4493 if (uncachedPrimaryKeys == null) {
4494 return map;
4495 }
4496
4497 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
4498 1);
4499
4500 query.append(_SQL_SELECT_PHONE_WHERE_PKS_IN);
4501
4502 for (Serializable primaryKey : uncachedPrimaryKeys) {
4503 query.append(String.valueOf(primaryKey));
4504
4505 query.append(StringPool.COMMA);
4506 }
4507
4508 query.setIndex(query.index() - 1);
4509
4510 query.append(StringPool.CLOSE_PARENTHESIS);
4511
4512 String sql = query.toString();
4513
4514 Session session = null;
4515
4516 try {
4517 session = openSession();
4518
4519 Query q = session.createQuery(sql);
4520
4521 for (Phone phone : (List<Phone>)q.list()) {
4522 map.put(phone.getPrimaryKeyObj(), phone);
4523
4524 cacheResult(phone);
4525
4526 uncachedPrimaryKeys.remove(phone.getPrimaryKeyObj());
4527 }
4528
4529 for (Serializable primaryKey : uncachedPrimaryKeys) {
4530 entityCache.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4531 PhoneImpl.class, primaryKey, _nullPhone);
4532 }
4533 }
4534 catch (Exception e) {
4535 throw processException(e);
4536 }
4537 finally {
4538 closeSession(session);
4539 }
4540
4541 return map;
4542 }
4543
4544
4549 @Override
4550 public List<Phone> findAll() {
4551 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4552 }
4553
4554
4565 @Override
4566 public List<Phone> findAll(int start, int end) {
4567 return findAll(start, end, null);
4568 }
4569
4570
4582 @Override
4583 public List<Phone> findAll(int start, int end,
4584 OrderByComparator<Phone> orderByComparator) {
4585 return findAll(start, end, orderByComparator, true);
4586 }
4587
4588
4601 @Override
4602 public List<Phone> findAll(int start, int end,
4603 OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
4604 boolean pagination = true;
4605 FinderPath finderPath = null;
4606 Object[] finderArgs = null;
4607
4608 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4609 (orderByComparator == null)) {
4610 pagination = false;
4611 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4612 finderArgs = FINDER_ARGS_EMPTY;
4613 }
4614 else {
4615 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4616 finderArgs = new Object[] { start, end, orderByComparator };
4617 }
4618
4619 List<Phone> list = null;
4620
4621 if (retrieveFromCache) {
4622 list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
4623 this);
4624 }
4625
4626 if (list == null) {
4627 StringBundler query = null;
4628 String sql = null;
4629
4630 if (orderByComparator != null) {
4631 query = new StringBundler(2 +
4632 (orderByComparator.getOrderByFields().length * 3));
4633
4634 query.append(_SQL_SELECT_PHONE);
4635
4636 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4637 orderByComparator);
4638
4639 sql = query.toString();
4640 }
4641 else {
4642 sql = _SQL_SELECT_PHONE;
4643
4644 if (pagination) {
4645 sql = sql.concat(PhoneModelImpl.ORDER_BY_JPQL);
4646 }
4647 }
4648
4649 Session session = null;
4650
4651 try {
4652 session = openSession();
4653
4654 Query q = session.createQuery(sql);
4655
4656 if (!pagination) {
4657 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
4658 end, false);
4659
4660 Collections.sort(list);
4661
4662 list = Collections.unmodifiableList(list);
4663 }
4664 else {
4665 list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
4666 end);
4667 }
4668
4669 cacheResult(list);
4670
4671 finderCache.putResult(finderPath, finderArgs, list);
4672 }
4673 catch (Exception e) {
4674 finderCache.removeResult(finderPath, finderArgs);
4675
4676 throw processException(e);
4677 }
4678 finally {
4679 closeSession(session);
4680 }
4681 }
4682
4683 return list;
4684 }
4685
4686
4690 @Override
4691 public void removeAll() {
4692 for (Phone phone : findAll()) {
4693 remove(phone);
4694 }
4695 }
4696
4697
4702 @Override
4703 public int countAll() {
4704 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
4705 FINDER_ARGS_EMPTY, this);
4706
4707 if (count == null) {
4708 Session session = null;
4709
4710 try {
4711 session = openSession();
4712
4713 Query q = session.createQuery(_SQL_COUNT_PHONE);
4714
4715 count = (Long)q.uniqueResult();
4716
4717 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
4718 count);
4719 }
4720 catch (Exception e) {
4721 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
4722 FINDER_ARGS_EMPTY);
4723
4724 throw processException(e);
4725 }
4726 finally {
4727 closeSession(session);
4728 }
4729 }
4730
4731 return count.intValue();
4732 }
4733
4734 @Override
4735 public Set<String> getBadColumnNames() {
4736 return _badColumnNames;
4737 }
4738
4739 @Override
4740 protected Map<String, Integer> getTableColumnsMap() {
4741 return PhoneModelImpl.TABLE_COLUMNS_MAP;
4742 }
4743
4744
4747 public void afterPropertiesSet() {
4748 }
4749
4750 public void destroy() {
4751 entityCache.removeCache(PhoneImpl.class.getName());
4752 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
4753 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4754 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4755 }
4756
4757 @BeanReference(type = CompanyProvider.class)
4758 protected CompanyProvider companyProvider;
4759 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
4760 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
4761 private static final String _SQL_SELECT_PHONE = "SELECT phone FROM Phone phone";
4762 private static final String _SQL_SELECT_PHONE_WHERE_PKS_IN = "SELECT phone FROM Phone phone WHERE phoneId IN (";
4763 private static final String _SQL_SELECT_PHONE_WHERE = "SELECT phone FROM Phone phone WHERE ";
4764 private static final String _SQL_COUNT_PHONE = "SELECT COUNT(phone) FROM Phone phone";
4765 private static final String _SQL_COUNT_PHONE_WHERE = "SELECT COUNT(phone) FROM Phone phone WHERE ";
4766 private static final String _ORDER_BY_ENTITY_ALIAS = "phone.";
4767 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Phone exists with the primary key ";
4768 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Phone exists with the key {";
4769 private static final Log _log = LogFactoryUtil.getLog(PhonePersistenceImpl.class);
4770 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
4771 "uuid", "number", "primary"
4772 });
4773 private static final Phone _nullPhone = new PhoneImpl() {
4774 @Override
4775 public Object clone() {
4776 return this;
4777 }
4778
4779 @Override
4780 public CacheModel<Phone> toCacheModel() {
4781 return _nullPhoneCacheModel;
4782 }
4783 };
4784
4785 private static final CacheModel<Phone> _nullPhoneCacheModel = new NullCacheModel();
4786
4787 private static class NullCacheModel implements CacheModel<Phone>, MVCCModel {
4788 @Override
4789 public long getMvccVersion() {
4790 return -1;
4791 }
4792
4793 @Override
4794 public void setMvccVersion(long mvccVersion) {
4795 }
4796
4797 @Override
4798 public Phone toEntityModel() {
4799 return _nullPhone;
4800 }
4801 }
4802 }