001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchContactException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.Contact;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.impl.ContactImpl;
041 import com.liferay.portal.model.impl.ContactModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class ContactPersistenceImpl extends BasePersistenceImpl<Contact>
063 implements ContactPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = ContactImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
075 new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
076 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
078 new String[] {
079 Long.class.getName(),
080
081 "java.lang.Integer", "java.lang.Integer",
082 "com.liferay.portal.kernel.util.OrderByComparator"
083 });
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
085 new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
086 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
088 new String[] { Long.class.getName() },
089 ContactModelImpl.COMPANYID_COLUMN_BITMASK);
090 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
091 ContactModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
093 new String[] { Long.class.getName() });
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACCOUNTID =
095 new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
096 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
097 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByAccountId",
098 new String[] {
099 Long.class.getName(),
100
101 "java.lang.Integer", "java.lang.Integer",
102 "com.liferay.portal.kernel.util.OrderByComparator"
103 });
104 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID =
105 new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
106 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByAccountId",
108 new String[] { Long.class.getName() },
109 ContactModelImpl.ACCOUNTID_COLUMN_BITMASK);
110 public static final FinderPath FINDER_PATH_COUNT_BY_ACCOUNTID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
111 ContactModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByAccountId",
113 new String[] { Long.class.getName() });
114 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
115 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
116 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
117 new String[] {
118 Long.class.getName(), Long.class.getName(),
119
120 "java.lang.Integer", "java.lang.Integer",
121 "com.liferay.portal.kernel.util.OrderByComparator"
122 });
123 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
124 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
126 new String[] { Long.class.getName(), Long.class.getName() },
127 ContactModelImpl.CLASSNAMEID_COLUMN_BITMASK |
128 ContactModelImpl.CLASSPK_COLUMN_BITMASK);
129 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
130 ContactModelImpl.FINDER_CACHE_ENABLED, Long.class,
131 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
132 new String[] { Long.class.getName(), Long.class.getName() });
133 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
134 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
135 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
136 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
137 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
138 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
139 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
140 ContactModelImpl.FINDER_CACHE_ENABLED, Long.class,
141 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
142
143
148 public void cacheResult(Contact contact) {
149 EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
150 ContactImpl.class, contact.getPrimaryKey(), contact);
151
152 contact.resetOriginalValues();
153 }
154
155
160 public void cacheResult(List<Contact> contacts) {
161 for (Contact contact : contacts) {
162 if (EntityCacheUtil.getResult(
163 ContactModelImpl.ENTITY_CACHE_ENABLED,
164 ContactImpl.class, contact.getPrimaryKey()) == null) {
165 cacheResult(contact);
166 }
167 else {
168 contact.resetOriginalValues();
169 }
170 }
171 }
172
173
180 @Override
181 public void clearCache() {
182 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
183 CacheRegistryUtil.clear(ContactImpl.class.getName());
184 }
185
186 EntityCacheUtil.clearCache(ContactImpl.class.getName());
187
188 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
189 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
191 }
192
193
200 @Override
201 public void clearCache(Contact contact) {
202 EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
203 ContactImpl.class, contact.getPrimaryKey());
204
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
207 }
208
209 @Override
210 public void clearCache(List<Contact> contacts) {
211 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
212 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
213
214 for (Contact contact : contacts) {
215 EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
216 ContactImpl.class, contact.getPrimaryKey());
217 }
218 }
219
220
226 public Contact create(long contactId) {
227 Contact contact = new ContactImpl();
228
229 contact.setNew(true);
230 contact.setPrimaryKey(contactId);
231
232 return contact;
233 }
234
235
243 public Contact remove(long contactId)
244 throws NoSuchContactException, SystemException {
245 return remove(Long.valueOf(contactId));
246 }
247
248
256 @Override
257 public Contact remove(Serializable primaryKey)
258 throws NoSuchContactException, SystemException {
259 Session session = null;
260
261 try {
262 session = openSession();
263
264 Contact contact = (Contact)session.get(ContactImpl.class, primaryKey);
265
266 if (contact == null) {
267 if (_log.isWarnEnabled()) {
268 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
269 }
270
271 throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
272 primaryKey);
273 }
274
275 return remove(contact);
276 }
277 catch (NoSuchContactException nsee) {
278 throw nsee;
279 }
280 catch (Exception e) {
281 throw processException(e);
282 }
283 finally {
284 closeSession(session);
285 }
286 }
287
288 @Override
289 protected Contact removeImpl(Contact contact) throws SystemException {
290 contact = toUnwrappedModel(contact);
291
292 Session session = null;
293
294 try {
295 session = openSession();
296
297 if (contact.isCachedModel()) {
298 contact = (Contact)session.get(ContactImpl.class,
299 contact.getPrimaryKeyObj());
300 }
301
302 session.delete(contact);
303 }
304 catch (Exception e) {
305 throw processException(e);
306 }
307 finally {
308 closeSession(session);
309 }
310
311 clearCache(contact);
312
313 return contact;
314 }
315
316 @Override
317 public Contact updateImpl(com.liferay.portal.model.Contact contact)
318 throws SystemException {
319 contact = toUnwrappedModel(contact);
320
321 boolean isNew = contact.isNew();
322
323 ContactModelImpl contactModelImpl = (ContactModelImpl)contact;
324
325 Session session = null;
326
327 try {
328 session = openSession();
329
330 if (contact.isNew()) {
331 session.save(contact);
332
333 contact.setNew(false);
334 }
335 else {
336 session.merge(contact);
337 }
338 }
339 catch (Exception e) {
340 throw processException(e);
341 }
342 finally {
343 closeSession(session);
344 }
345
346 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
347
348 if (isNew || !ContactModelImpl.COLUMN_BITMASK_ENABLED) {
349 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
350 }
351
352 else {
353 if ((contactModelImpl.getColumnBitmask() &
354 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
355 Object[] args = new Object[] {
356 Long.valueOf(contactModelImpl.getOriginalCompanyId())
357 };
358
359 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
360 args);
361 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
362 args);
363
364 args = new Object[] {
365 Long.valueOf(contactModelImpl.getCompanyId())
366 };
367
368 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
369 args);
370 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
371 args);
372 }
373
374 if ((contactModelImpl.getColumnBitmask() &
375 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID.getColumnBitmask()) != 0) {
376 Object[] args = new Object[] {
377 Long.valueOf(contactModelImpl.getOriginalAccountId())
378 };
379
380 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACCOUNTID,
381 args);
382 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID,
383 args);
384
385 args = new Object[] {
386 Long.valueOf(contactModelImpl.getAccountId())
387 };
388
389 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACCOUNTID,
390 args);
391 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID,
392 args);
393 }
394
395 if ((contactModelImpl.getColumnBitmask() &
396 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
397 Object[] args = new Object[] {
398 Long.valueOf(contactModelImpl.getOriginalClassNameId()),
399 Long.valueOf(contactModelImpl.getOriginalClassPK())
400 };
401
402 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
403 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
404 args);
405
406 args = new Object[] {
407 Long.valueOf(contactModelImpl.getClassNameId()),
408 Long.valueOf(contactModelImpl.getClassPK())
409 };
410
411 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
412 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
413 args);
414 }
415 }
416
417 EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
418 ContactImpl.class, contact.getPrimaryKey(), contact);
419
420 return contact;
421 }
422
423 protected Contact toUnwrappedModel(Contact contact) {
424 if (contact instanceof ContactImpl) {
425 return contact;
426 }
427
428 ContactImpl contactImpl = new ContactImpl();
429
430 contactImpl.setNew(contact.isNew());
431 contactImpl.setPrimaryKey(contact.getPrimaryKey());
432
433 contactImpl.setContactId(contact.getContactId());
434 contactImpl.setCompanyId(contact.getCompanyId());
435 contactImpl.setUserId(contact.getUserId());
436 contactImpl.setUserName(contact.getUserName());
437 contactImpl.setCreateDate(contact.getCreateDate());
438 contactImpl.setModifiedDate(contact.getModifiedDate());
439 contactImpl.setClassNameId(contact.getClassNameId());
440 contactImpl.setClassPK(contact.getClassPK());
441 contactImpl.setAccountId(contact.getAccountId());
442 contactImpl.setParentContactId(contact.getParentContactId());
443 contactImpl.setEmailAddress(contact.getEmailAddress());
444 contactImpl.setFirstName(contact.getFirstName());
445 contactImpl.setMiddleName(contact.getMiddleName());
446 contactImpl.setLastName(contact.getLastName());
447 contactImpl.setPrefixId(contact.getPrefixId());
448 contactImpl.setSuffixId(contact.getSuffixId());
449 contactImpl.setMale(contact.isMale());
450 contactImpl.setBirthday(contact.getBirthday());
451 contactImpl.setSmsSn(contact.getSmsSn());
452 contactImpl.setAimSn(contact.getAimSn());
453 contactImpl.setFacebookSn(contact.getFacebookSn());
454 contactImpl.setIcqSn(contact.getIcqSn());
455 contactImpl.setJabberSn(contact.getJabberSn());
456 contactImpl.setMsnSn(contact.getMsnSn());
457 contactImpl.setMySpaceSn(contact.getMySpaceSn());
458 contactImpl.setSkypeSn(contact.getSkypeSn());
459 contactImpl.setTwitterSn(contact.getTwitterSn());
460 contactImpl.setYmSn(contact.getYmSn());
461 contactImpl.setEmployeeStatusId(contact.getEmployeeStatusId());
462 contactImpl.setEmployeeNumber(contact.getEmployeeNumber());
463 contactImpl.setJobTitle(contact.getJobTitle());
464 contactImpl.setJobClass(contact.getJobClass());
465 contactImpl.setHoursOfOperation(contact.getHoursOfOperation());
466
467 return contactImpl;
468 }
469
470
478 @Override
479 public Contact findByPrimaryKey(Serializable primaryKey)
480 throws NoSuchModelException, SystemException {
481 return findByPrimaryKey(((Long)primaryKey).longValue());
482 }
483
484
492 public Contact findByPrimaryKey(long contactId)
493 throws NoSuchContactException, SystemException {
494 Contact contact = fetchByPrimaryKey(contactId);
495
496 if (contact == null) {
497 if (_log.isWarnEnabled()) {
498 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
499 }
500
501 throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
502 contactId);
503 }
504
505 return contact;
506 }
507
508
515 @Override
516 public Contact fetchByPrimaryKey(Serializable primaryKey)
517 throws SystemException {
518 return fetchByPrimaryKey(((Long)primaryKey).longValue());
519 }
520
521
528 public Contact fetchByPrimaryKey(long contactId) throws SystemException {
529 Contact contact = (Contact)EntityCacheUtil.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
530 ContactImpl.class, contactId);
531
532 if (contact == _nullContact) {
533 return null;
534 }
535
536 if (contact == null) {
537 Session session = null;
538
539 boolean hasException = false;
540
541 try {
542 session = openSession();
543
544 contact = (Contact)session.get(ContactImpl.class,
545 Long.valueOf(contactId));
546 }
547 catch (Exception e) {
548 hasException = true;
549
550 throw processException(e);
551 }
552 finally {
553 if (contact != null) {
554 cacheResult(contact);
555 }
556 else if (!hasException) {
557 EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
558 ContactImpl.class, contactId, _nullContact);
559 }
560
561 closeSession(session);
562 }
563 }
564
565 return contact;
566 }
567
568
575 public List<Contact> findByCompanyId(long companyId)
576 throws SystemException {
577 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
578 null);
579 }
580
581
594 public List<Contact> findByCompanyId(long companyId, int start, int end)
595 throws SystemException {
596 return findByCompanyId(companyId, start, end, null);
597 }
598
599
613 public List<Contact> findByCompanyId(long companyId, int start, int end,
614 OrderByComparator orderByComparator) throws SystemException {
615 FinderPath finderPath = null;
616 Object[] finderArgs = null;
617
618 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
619 (orderByComparator == null)) {
620 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
621 finderArgs = new Object[] { companyId };
622 }
623 else {
624 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
625 finderArgs = new Object[] { companyId, start, end, orderByComparator };
626 }
627
628 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
629 finderArgs, this);
630
631 if ((list != null) && !list.isEmpty()) {
632 for (Contact contact : list) {
633 if ((companyId != contact.getCompanyId())) {
634 list = null;
635
636 break;
637 }
638 }
639 }
640
641 if (list == null) {
642 StringBundler query = null;
643
644 if (orderByComparator != null) {
645 query = new StringBundler(3 +
646 (orderByComparator.getOrderByFields().length * 3));
647 }
648 else {
649 query = new StringBundler(2);
650 }
651
652 query.append(_SQL_SELECT_CONTACT_WHERE);
653
654 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
655
656 if (orderByComparator != null) {
657 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
658 orderByComparator);
659 }
660
661 String sql = query.toString();
662
663 Session session = null;
664
665 try {
666 session = openSession();
667
668 Query q = session.createQuery(sql);
669
670 QueryPos qPos = QueryPos.getInstance(q);
671
672 qPos.add(companyId);
673
674 list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
675 }
676 catch (Exception e) {
677 throw processException(e);
678 }
679 finally {
680 if (list == null) {
681 FinderCacheUtil.removeResult(finderPath, finderArgs);
682 }
683 else {
684 cacheResult(list);
685
686 FinderCacheUtil.putResult(finderPath, finderArgs, list);
687 }
688
689 closeSession(session);
690 }
691 }
692
693 return list;
694 }
695
696
705 public Contact findByCompanyId_First(long companyId,
706 OrderByComparator orderByComparator)
707 throws NoSuchContactException, SystemException {
708 Contact contact = fetchByCompanyId_First(companyId, orderByComparator);
709
710 if (contact != null) {
711 return contact;
712 }
713
714 StringBundler msg = new StringBundler(4);
715
716 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
717
718 msg.append("companyId=");
719 msg.append(companyId);
720
721 msg.append(StringPool.CLOSE_CURLY_BRACE);
722
723 throw new NoSuchContactException(msg.toString());
724 }
725
726
734 public Contact fetchByCompanyId_First(long companyId,
735 OrderByComparator orderByComparator) throws SystemException {
736 List<Contact> list = findByCompanyId(companyId, 0, 1, orderByComparator);
737
738 if (!list.isEmpty()) {
739 return list.get(0);
740 }
741
742 return null;
743 }
744
745
754 public Contact findByCompanyId_Last(long companyId,
755 OrderByComparator orderByComparator)
756 throws NoSuchContactException, SystemException {
757 Contact contact = fetchByCompanyId_Last(companyId, orderByComparator);
758
759 if (contact != null) {
760 return contact;
761 }
762
763 StringBundler msg = new StringBundler(4);
764
765 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
766
767 msg.append("companyId=");
768 msg.append(companyId);
769
770 msg.append(StringPool.CLOSE_CURLY_BRACE);
771
772 throw new NoSuchContactException(msg.toString());
773 }
774
775
783 public Contact fetchByCompanyId_Last(long companyId,
784 OrderByComparator orderByComparator) throws SystemException {
785 int count = countByCompanyId(companyId);
786
787 List<Contact> list = findByCompanyId(companyId, count - 1, count,
788 orderByComparator);
789
790 if (!list.isEmpty()) {
791 return list.get(0);
792 }
793
794 return null;
795 }
796
797
807 public Contact[] findByCompanyId_PrevAndNext(long contactId,
808 long companyId, OrderByComparator orderByComparator)
809 throws NoSuchContactException, SystemException {
810 Contact contact = findByPrimaryKey(contactId);
811
812 Session session = null;
813
814 try {
815 session = openSession();
816
817 Contact[] array = new ContactImpl[3];
818
819 array[0] = getByCompanyId_PrevAndNext(session, contact, companyId,
820 orderByComparator, true);
821
822 array[1] = contact;
823
824 array[2] = getByCompanyId_PrevAndNext(session, contact, companyId,
825 orderByComparator, false);
826
827 return array;
828 }
829 catch (Exception e) {
830 throw processException(e);
831 }
832 finally {
833 closeSession(session);
834 }
835 }
836
837 protected Contact getByCompanyId_PrevAndNext(Session session,
838 Contact contact, long companyId, OrderByComparator orderByComparator,
839 boolean previous) {
840 StringBundler query = null;
841
842 if (orderByComparator != null) {
843 query = new StringBundler(6 +
844 (orderByComparator.getOrderByFields().length * 6));
845 }
846 else {
847 query = new StringBundler(3);
848 }
849
850 query.append(_SQL_SELECT_CONTACT_WHERE);
851
852 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
853
854 if (orderByComparator != null) {
855 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
856
857 if (orderByConditionFields.length > 0) {
858 query.append(WHERE_AND);
859 }
860
861 for (int i = 0; i < orderByConditionFields.length; i++) {
862 query.append(_ORDER_BY_ENTITY_ALIAS);
863 query.append(orderByConditionFields[i]);
864
865 if ((i + 1) < orderByConditionFields.length) {
866 if (orderByComparator.isAscending() ^ previous) {
867 query.append(WHERE_GREATER_THAN_HAS_NEXT);
868 }
869 else {
870 query.append(WHERE_LESSER_THAN_HAS_NEXT);
871 }
872 }
873 else {
874 if (orderByComparator.isAscending() ^ previous) {
875 query.append(WHERE_GREATER_THAN);
876 }
877 else {
878 query.append(WHERE_LESSER_THAN);
879 }
880 }
881 }
882
883 query.append(ORDER_BY_CLAUSE);
884
885 String[] orderByFields = orderByComparator.getOrderByFields();
886
887 for (int i = 0; i < orderByFields.length; i++) {
888 query.append(_ORDER_BY_ENTITY_ALIAS);
889 query.append(orderByFields[i]);
890
891 if ((i + 1) < orderByFields.length) {
892 if (orderByComparator.isAscending() ^ previous) {
893 query.append(ORDER_BY_ASC_HAS_NEXT);
894 }
895 else {
896 query.append(ORDER_BY_DESC_HAS_NEXT);
897 }
898 }
899 else {
900 if (orderByComparator.isAscending() ^ previous) {
901 query.append(ORDER_BY_ASC);
902 }
903 else {
904 query.append(ORDER_BY_DESC);
905 }
906 }
907 }
908 }
909
910 String sql = query.toString();
911
912 Query q = session.createQuery(sql);
913
914 q.setFirstResult(0);
915 q.setMaxResults(2);
916
917 QueryPos qPos = QueryPos.getInstance(q);
918
919 qPos.add(companyId);
920
921 if (orderByComparator != null) {
922 Object[] values = orderByComparator.getOrderByConditionValues(contact);
923
924 for (Object value : values) {
925 qPos.add(value);
926 }
927 }
928
929 List<Contact> list = q.list();
930
931 if (list.size() == 2) {
932 return list.get(1);
933 }
934 else {
935 return null;
936 }
937 }
938
939
946 public List<Contact> findByAccountId(long accountId)
947 throws SystemException {
948 return findByAccountId(accountId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
949 null);
950 }
951
952
965 public List<Contact> findByAccountId(long accountId, int start, int end)
966 throws SystemException {
967 return findByAccountId(accountId, start, end, null);
968 }
969
970
984 public List<Contact> findByAccountId(long accountId, int start, int end,
985 OrderByComparator orderByComparator) throws SystemException {
986 FinderPath finderPath = null;
987 Object[] finderArgs = null;
988
989 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
990 (orderByComparator == null)) {
991 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID;
992 finderArgs = new Object[] { accountId };
993 }
994 else {
995 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACCOUNTID;
996 finderArgs = new Object[] { accountId, start, end, orderByComparator };
997 }
998
999 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
1000 finderArgs, this);
1001
1002 if ((list != null) && !list.isEmpty()) {
1003 for (Contact contact : list) {
1004 if ((accountId != contact.getAccountId())) {
1005 list = null;
1006
1007 break;
1008 }
1009 }
1010 }
1011
1012 if (list == null) {
1013 StringBundler query = null;
1014
1015 if (orderByComparator != null) {
1016 query = new StringBundler(3 +
1017 (orderByComparator.getOrderByFields().length * 3));
1018 }
1019 else {
1020 query = new StringBundler(2);
1021 }
1022
1023 query.append(_SQL_SELECT_CONTACT_WHERE);
1024
1025 query.append(_FINDER_COLUMN_ACCOUNTID_ACCOUNTID_2);
1026
1027 if (orderByComparator != null) {
1028 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1029 orderByComparator);
1030 }
1031
1032 String sql = query.toString();
1033
1034 Session session = null;
1035
1036 try {
1037 session = openSession();
1038
1039 Query q = session.createQuery(sql);
1040
1041 QueryPos qPos = QueryPos.getInstance(q);
1042
1043 qPos.add(accountId);
1044
1045 list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
1046 }
1047 catch (Exception e) {
1048 throw processException(e);
1049 }
1050 finally {
1051 if (list == null) {
1052 FinderCacheUtil.removeResult(finderPath, finderArgs);
1053 }
1054 else {
1055 cacheResult(list);
1056
1057 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1058 }
1059
1060 closeSession(session);
1061 }
1062 }
1063
1064 return list;
1065 }
1066
1067
1076 public Contact findByAccountId_First(long accountId,
1077 OrderByComparator orderByComparator)
1078 throws NoSuchContactException, SystemException {
1079 Contact contact = fetchByAccountId_First(accountId, orderByComparator);
1080
1081 if (contact != null) {
1082 return contact;
1083 }
1084
1085 StringBundler msg = new StringBundler(4);
1086
1087 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1088
1089 msg.append("accountId=");
1090 msg.append(accountId);
1091
1092 msg.append(StringPool.CLOSE_CURLY_BRACE);
1093
1094 throw new NoSuchContactException(msg.toString());
1095 }
1096
1097
1105 public Contact fetchByAccountId_First(long accountId,
1106 OrderByComparator orderByComparator) throws SystemException {
1107 List<Contact> list = findByAccountId(accountId, 0, 1, orderByComparator);
1108
1109 if (!list.isEmpty()) {
1110 return list.get(0);
1111 }
1112
1113 return null;
1114 }
1115
1116
1125 public Contact findByAccountId_Last(long accountId,
1126 OrderByComparator orderByComparator)
1127 throws NoSuchContactException, SystemException {
1128 Contact contact = fetchByAccountId_Last(accountId, orderByComparator);
1129
1130 if (contact != null) {
1131 return contact;
1132 }
1133
1134 StringBundler msg = new StringBundler(4);
1135
1136 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1137
1138 msg.append("accountId=");
1139 msg.append(accountId);
1140
1141 msg.append(StringPool.CLOSE_CURLY_BRACE);
1142
1143 throw new NoSuchContactException(msg.toString());
1144 }
1145
1146
1154 public Contact fetchByAccountId_Last(long accountId,
1155 OrderByComparator orderByComparator) throws SystemException {
1156 int count = countByAccountId(accountId);
1157
1158 List<Contact> list = findByAccountId(accountId, count - 1, count,
1159 orderByComparator);
1160
1161 if (!list.isEmpty()) {
1162 return list.get(0);
1163 }
1164
1165 return null;
1166 }
1167
1168
1178 public Contact[] findByAccountId_PrevAndNext(long contactId,
1179 long accountId, OrderByComparator orderByComparator)
1180 throws NoSuchContactException, SystemException {
1181 Contact contact = findByPrimaryKey(contactId);
1182
1183 Session session = null;
1184
1185 try {
1186 session = openSession();
1187
1188 Contact[] array = new ContactImpl[3];
1189
1190 array[0] = getByAccountId_PrevAndNext(session, contact, accountId,
1191 orderByComparator, true);
1192
1193 array[1] = contact;
1194
1195 array[2] = getByAccountId_PrevAndNext(session, contact, accountId,
1196 orderByComparator, false);
1197
1198 return array;
1199 }
1200 catch (Exception e) {
1201 throw processException(e);
1202 }
1203 finally {
1204 closeSession(session);
1205 }
1206 }
1207
1208 protected Contact getByAccountId_PrevAndNext(Session session,
1209 Contact contact, long accountId, OrderByComparator orderByComparator,
1210 boolean previous) {
1211 StringBundler query = null;
1212
1213 if (orderByComparator != null) {
1214 query = new StringBundler(6 +
1215 (orderByComparator.getOrderByFields().length * 6));
1216 }
1217 else {
1218 query = new StringBundler(3);
1219 }
1220
1221 query.append(_SQL_SELECT_CONTACT_WHERE);
1222
1223 query.append(_FINDER_COLUMN_ACCOUNTID_ACCOUNTID_2);
1224
1225 if (orderByComparator != null) {
1226 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1227
1228 if (orderByConditionFields.length > 0) {
1229 query.append(WHERE_AND);
1230 }
1231
1232 for (int i = 0; i < orderByConditionFields.length; i++) {
1233 query.append(_ORDER_BY_ENTITY_ALIAS);
1234 query.append(orderByConditionFields[i]);
1235
1236 if ((i + 1) < orderByConditionFields.length) {
1237 if (orderByComparator.isAscending() ^ previous) {
1238 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1239 }
1240 else {
1241 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1242 }
1243 }
1244 else {
1245 if (orderByComparator.isAscending() ^ previous) {
1246 query.append(WHERE_GREATER_THAN);
1247 }
1248 else {
1249 query.append(WHERE_LESSER_THAN);
1250 }
1251 }
1252 }
1253
1254 query.append(ORDER_BY_CLAUSE);
1255
1256 String[] orderByFields = orderByComparator.getOrderByFields();
1257
1258 for (int i = 0; i < orderByFields.length; i++) {
1259 query.append(_ORDER_BY_ENTITY_ALIAS);
1260 query.append(orderByFields[i]);
1261
1262 if ((i + 1) < orderByFields.length) {
1263 if (orderByComparator.isAscending() ^ previous) {
1264 query.append(ORDER_BY_ASC_HAS_NEXT);
1265 }
1266 else {
1267 query.append(ORDER_BY_DESC_HAS_NEXT);
1268 }
1269 }
1270 else {
1271 if (orderByComparator.isAscending() ^ previous) {
1272 query.append(ORDER_BY_ASC);
1273 }
1274 else {
1275 query.append(ORDER_BY_DESC);
1276 }
1277 }
1278 }
1279 }
1280
1281 String sql = query.toString();
1282
1283 Query q = session.createQuery(sql);
1284
1285 q.setFirstResult(0);
1286 q.setMaxResults(2);
1287
1288 QueryPos qPos = QueryPos.getInstance(q);
1289
1290 qPos.add(accountId);
1291
1292 if (orderByComparator != null) {
1293 Object[] values = orderByComparator.getOrderByConditionValues(contact);
1294
1295 for (Object value : values) {
1296 qPos.add(value);
1297 }
1298 }
1299
1300 List<Contact> list = q.list();
1301
1302 if (list.size() == 2) {
1303 return list.get(1);
1304 }
1305 else {
1306 return null;
1307 }
1308 }
1309
1310
1318 public List<Contact> findByC_C(long classNameId, long classPK)
1319 throws SystemException {
1320 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
1321 QueryUtil.ALL_POS, null);
1322 }
1323
1324
1338 public List<Contact> findByC_C(long classNameId, long classPK, int start,
1339 int end) throws SystemException {
1340 return findByC_C(classNameId, classPK, start, end, null);
1341 }
1342
1343
1358 public List<Contact> findByC_C(long classNameId, long classPK, int start,
1359 int end, OrderByComparator orderByComparator) throws SystemException {
1360 FinderPath finderPath = null;
1361 Object[] finderArgs = null;
1362
1363 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1364 (orderByComparator == null)) {
1365 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
1366 finderArgs = new Object[] { classNameId, classPK };
1367 }
1368 else {
1369 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
1370 finderArgs = new Object[] {
1371 classNameId, classPK,
1372
1373 start, end, orderByComparator
1374 };
1375 }
1376
1377 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
1378 finderArgs, this);
1379
1380 if ((list != null) && !list.isEmpty()) {
1381 for (Contact contact : list) {
1382 if ((classNameId != contact.getClassNameId()) ||
1383 (classPK != contact.getClassPK())) {
1384 list = null;
1385
1386 break;
1387 }
1388 }
1389 }
1390
1391 if (list == null) {
1392 StringBundler query = null;
1393
1394 if (orderByComparator != null) {
1395 query = new StringBundler(4 +
1396 (orderByComparator.getOrderByFields().length * 3));
1397 }
1398 else {
1399 query = new StringBundler(3);
1400 }
1401
1402 query.append(_SQL_SELECT_CONTACT_WHERE);
1403
1404 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1405
1406 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1407
1408 if (orderByComparator != null) {
1409 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1410 orderByComparator);
1411 }
1412
1413 String sql = query.toString();
1414
1415 Session session = null;
1416
1417 try {
1418 session = openSession();
1419
1420 Query q = session.createQuery(sql);
1421
1422 QueryPos qPos = QueryPos.getInstance(q);
1423
1424 qPos.add(classNameId);
1425
1426 qPos.add(classPK);
1427
1428 list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
1429 }
1430 catch (Exception e) {
1431 throw processException(e);
1432 }
1433 finally {
1434 if (list == null) {
1435 FinderCacheUtil.removeResult(finderPath, finderArgs);
1436 }
1437 else {
1438 cacheResult(list);
1439
1440 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1441 }
1442
1443 closeSession(session);
1444 }
1445 }
1446
1447 return list;
1448 }
1449
1450
1460 public Contact findByC_C_First(long classNameId, long classPK,
1461 OrderByComparator orderByComparator)
1462 throws NoSuchContactException, SystemException {
1463 Contact contact = fetchByC_C_First(classNameId, classPK,
1464 orderByComparator);
1465
1466 if (contact != null) {
1467 return contact;
1468 }
1469
1470 StringBundler msg = new StringBundler(6);
1471
1472 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1473
1474 msg.append("classNameId=");
1475 msg.append(classNameId);
1476
1477 msg.append(", classPK=");
1478 msg.append(classPK);
1479
1480 msg.append(StringPool.CLOSE_CURLY_BRACE);
1481
1482 throw new NoSuchContactException(msg.toString());
1483 }
1484
1485
1494 public Contact fetchByC_C_First(long classNameId, long classPK,
1495 OrderByComparator orderByComparator) throws SystemException {
1496 List<Contact> list = findByC_C(classNameId, classPK, 0, 1,
1497 orderByComparator);
1498
1499 if (!list.isEmpty()) {
1500 return list.get(0);
1501 }
1502
1503 return null;
1504 }
1505
1506
1516 public Contact findByC_C_Last(long classNameId, long classPK,
1517 OrderByComparator orderByComparator)
1518 throws NoSuchContactException, SystemException {
1519 Contact contact = fetchByC_C_Last(classNameId, classPK,
1520 orderByComparator);
1521
1522 if (contact != null) {
1523 return contact;
1524 }
1525
1526 StringBundler msg = new StringBundler(6);
1527
1528 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1529
1530 msg.append("classNameId=");
1531 msg.append(classNameId);
1532
1533 msg.append(", classPK=");
1534 msg.append(classPK);
1535
1536 msg.append(StringPool.CLOSE_CURLY_BRACE);
1537
1538 throw new NoSuchContactException(msg.toString());
1539 }
1540
1541
1550 public Contact fetchByC_C_Last(long classNameId, long classPK,
1551 OrderByComparator orderByComparator) throws SystemException {
1552 int count = countByC_C(classNameId, classPK);
1553
1554 List<Contact> list = findByC_C(classNameId, classPK, count - 1, count,
1555 orderByComparator);
1556
1557 if (!list.isEmpty()) {
1558 return list.get(0);
1559 }
1560
1561 return null;
1562 }
1563
1564
1575 public Contact[] findByC_C_PrevAndNext(long contactId, long classNameId,
1576 long classPK, OrderByComparator orderByComparator)
1577 throws NoSuchContactException, SystemException {
1578 Contact contact = findByPrimaryKey(contactId);
1579
1580 Session session = null;
1581
1582 try {
1583 session = openSession();
1584
1585 Contact[] array = new ContactImpl[3];
1586
1587 array[0] = getByC_C_PrevAndNext(session, contact, classNameId,
1588 classPK, orderByComparator, true);
1589
1590 array[1] = contact;
1591
1592 array[2] = getByC_C_PrevAndNext(session, contact, classNameId,
1593 classPK, orderByComparator, false);
1594
1595 return array;
1596 }
1597 catch (Exception e) {
1598 throw processException(e);
1599 }
1600 finally {
1601 closeSession(session);
1602 }
1603 }
1604
1605 protected Contact getByC_C_PrevAndNext(Session session, Contact contact,
1606 long classNameId, long classPK, OrderByComparator orderByComparator,
1607 boolean previous) {
1608 StringBundler query = null;
1609
1610 if (orderByComparator != null) {
1611 query = new StringBundler(6 +
1612 (orderByComparator.getOrderByFields().length * 6));
1613 }
1614 else {
1615 query = new StringBundler(3);
1616 }
1617
1618 query.append(_SQL_SELECT_CONTACT_WHERE);
1619
1620 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1621
1622 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1623
1624 if (orderByComparator != null) {
1625 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1626
1627 if (orderByConditionFields.length > 0) {
1628 query.append(WHERE_AND);
1629 }
1630
1631 for (int i = 0; i < orderByConditionFields.length; i++) {
1632 query.append(_ORDER_BY_ENTITY_ALIAS);
1633 query.append(orderByConditionFields[i]);
1634
1635 if ((i + 1) < orderByConditionFields.length) {
1636 if (orderByComparator.isAscending() ^ previous) {
1637 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1638 }
1639 else {
1640 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1641 }
1642 }
1643 else {
1644 if (orderByComparator.isAscending() ^ previous) {
1645 query.append(WHERE_GREATER_THAN);
1646 }
1647 else {
1648 query.append(WHERE_LESSER_THAN);
1649 }
1650 }
1651 }
1652
1653 query.append(ORDER_BY_CLAUSE);
1654
1655 String[] orderByFields = orderByComparator.getOrderByFields();
1656
1657 for (int i = 0; i < orderByFields.length; i++) {
1658 query.append(_ORDER_BY_ENTITY_ALIAS);
1659 query.append(orderByFields[i]);
1660
1661 if ((i + 1) < orderByFields.length) {
1662 if (orderByComparator.isAscending() ^ previous) {
1663 query.append(ORDER_BY_ASC_HAS_NEXT);
1664 }
1665 else {
1666 query.append(ORDER_BY_DESC_HAS_NEXT);
1667 }
1668 }
1669 else {
1670 if (orderByComparator.isAscending() ^ previous) {
1671 query.append(ORDER_BY_ASC);
1672 }
1673 else {
1674 query.append(ORDER_BY_DESC);
1675 }
1676 }
1677 }
1678 }
1679
1680 String sql = query.toString();
1681
1682 Query q = session.createQuery(sql);
1683
1684 q.setFirstResult(0);
1685 q.setMaxResults(2);
1686
1687 QueryPos qPos = QueryPos.getInstance(q);
1688
1689 qPos.add(classNameId);
1690
1691 qPos.add(classPK);
1692
1693 if (orderByComparator != null) {
1694 Object[] values = orderByComparator.getOrderByConditionValues(contact);
1695
1696 for (Object value : values) {
1697 qPos.add(value);
1698 }
1699 }
1700
1701 List<Contact> list = q.list();
1702
1703 if (list.size() == 2) {
1704 return list.get(1);
1705 }
1706 else {
1707 return null;
1708 }
1709 }
1710
1711
1717 public List<Contact> findAll() throws SystemException {
1718 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1719 }
1720
1721
1733 public List<Contact> findAll(int start, int end) throws SystemException {
1734 return findAll(start, end, null);
1735 }
1736
1737
1750 public List<Contact> findAll(int start, int end,
1751 OrderByComparator orderByComparator) throws SystemException {
1752 FinderPath finderPath = null;
1753 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1754
1755 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1756 (orderByComparator == null)) {
1757 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1758 finderArgs = FINDER_ARGS_EMPTY;
1759 }
1760 else {
1761 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1762 finderArgs = new Object[] { start, end, orderByComparator };
1763 }
1764
1765 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
1766 finderArgs, this);
1767
1768 if (list == null) {
1769 StringBundler query = null;
1770 String sql = null;
1771
1772 if (orderByComparator != null) {
1773 query = new StringBundler(2 +
1774 (orderByComparator.getOrderByFields().length * 3));
1775
1776 query.append(_SQL_SELECT_CONTACT);
1777
1778 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1779 orderByComparator);
1780
1781 sql = query.toString();
1782 }
1783 else {
1784 sql = _SQL_SELECT_CONTACT;
1785 }
1786
1787 Session session = null;
1788
1789 try {
1790 session = openSession();
1791
1792 Query q = session.createQuery(sql);
1793
1794 if (orderByComparator == null) {
1795 list = (List<Contact>)QueryUtil.list(q, getDialect(),
1796 start, end, false);
1797
1798 Collections.sort(list);
1799 }
1800 else {
1801 list = (List<Contact>)QueryUtil.list(q, getDialect(),
1802 start, end);
1803 }
1804 }
1805 catch (Exception e) {
1806 throw processException(e);
1807 }
1808 finally {
1809 if (list == null) {
1810 FinderCacheUtil.removeResult(finderPath, finderArgs);
1811 }
1812 else {
1813 cacheResult(list);
1814
1815 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1816 }
1817
1818 closeSession(session);
1819 }
1820 }
1821
1822 return list;
1823 }
1824
1825
1831 public void removeByCompanyId(long companyId) throws SystemException {
1832 for (Contact contact : findByCompanyId(companyId)) {
1833 remove(contact);
1834 }
1835 }
1836
1837
1843 public void removeByAccountId(long accountId) throws SystemException {
1844 for (Contact contact : findByAccountId(accountId)) {
1845 remove(contact);
1846 }
1847 }
1848
1849
1856 public void removeByC_C(long classNameId, long classPK)
1857 throws SystemException {
1858 for (Contact contact : findByC_C(classNameId, classPK)) {
1859 remove(contact);
1860 }
1861 }
1862
1863
1868 public void removeAll() throws SystemException {
1869 for (Contact contact : findAll()) {
1870 remove(contact);
1871 }
1872 }
1873
1874
1881 public int countByCompanyId(long companyId) throws SystemException {
1882 Object[] finderArgs = new Object[] { companyId };
1883
1884 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1885 finderArgs, this);
1886
1887 if (count == null) {
1888 StringBundler query = new StringBundler(2);
1889
1890 query.append(_SQL_COUNT_CONTACT_WHERE);
1891
1892 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1893
1894 String sql = query.toString();
1895
1896 Session session = null;
1897
1898 try {
1899 session = openSession();
1900
1901 Query q = session.createQuery(sql);
1902
1903 QueryPos qPos = QueryPos.getInstance(q);
1904
1905 qPos.add(companyId);
1906
1907 count = (Long)q.uniqueResult();
1908 }
1909 catch (Exception e) {
1910 throw processException(e);
1911 }
1912 finally {
1913 if (count == null) {
1914 count = Long.valueOf(0);
1915 }
1916
1917 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1918 finderArgs, count);
1919
1920 closeSession(session);
1921 }
1922 }
1923
1924 return count.intValue();
1925 }
1926
1927
1934 public int countByAccountId(long accountId) throws SystemException {
1935 Object[] finderArgs = new Object[] { accountId };
1936
1937 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACCOUNTID,
1938 finderArgs, this);
1939
1940 if (count == null) {
1941 StringBundler query = new StringBundler(2);
1942
1943 query.append(_SQL_COUNT_CONTACT_WHERE);
1944
1945 query.append(_FINDER_COLUMN_ACCOUNTID_ACCOUNTID_2);
1946
1947 String sql = query.toString();
1948
1949 Session session = null;
1950
1951 try {
1952 session = openSession();
1953
1954 Query q = session.createQuery(sql);
1955
1956 QueryPos qPos = QueryPos.getInstance(q);
1957
1958 qPos.add(accountId);
1959
1960 count = (Long)q.uniqueResult();
1961 }
1962 catch (Exception e) {
1963 throw processException(e);
1964 }
1965 finally {
1966 if (count == null) {
1967 count = Long.valueOf(0);
1968 }
1969
1970 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACCOUNTID,
1971 finderArgs, count);
1972
1973 closeSession(session);
1974 }
1975 }
1976
1977 return count.intValue();
1978 }
1979
1980
1988 public int countByC_C(long classNameId, long classPK)
1989 throws SystemException {
1990 Object[] finderArgs = new Object[] { classNameId, classPK };
1991
1992 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1993 finderArgs, this);
1994
1995 if (count == null) {
1996 StringBundler query = new StringBundler(3);
1997
1998 query.append(_SQL_COUNT_CONTACT_WHERE);
1999
2000 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2001
2002 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2003
2004 String sql = query.toString();
2005
2006 Session session = null;
2007
2008 try {
2009 session = openSession();
2010
2011 Query q = session.createQuery(sql);
2012
2013 QueryPos qPos = QueryPos.getInstance(q);
2014
2015 qPos.add(classNameId);
2016
2017 qPos.add(classPK);
2018
2019 count = (Long)q.uniqueResult();
2020 }
2021 catch (Exception e) {
2022 throw processException(e);
2023 }
2024 finally {
2025 if (count == null) {
2026 count = Long.valueOf(0);
2027 }
2028
2029 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2030 count);
2031
2032 closeSession(session);
2033 }
2034 }
2035
2036 return count.intValue();
2037 }
2038
2039
2045 public int countAll() throws SystemException {
2046 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2047 FINDER_ARGS_EMPTY, this);
2048
2049 if (count == null) {
2050 Session session = null;
2051
2052 try {
2053 session = openSession();
2054
2055 Query q = session.createQuery(_SQL_COUNT_CONTACT);
2056
2057 count = (Long)q.uniqueResult();
2058 }
2059 catch (Exception e) {
2060 throw processException(e);
2061 }
2062 finally {
2063 if (count == null) {
2064 count = Long.valueOf(0);
2065 }
2066
2067 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2068 FINDER_ARGS_EMPTY, count);
2069
2070 closeSession(session);
2071 }
2072 }
2073
2074 return count.intValue();
2075 }
2076
2077
2080 public void afterPropertiesSet() {
2081 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2082 com.liferay.portal.util.PropsUtil.get(
2083 "value.object.listener.com.liferay.portal.model.Contact")));
2084
2085 if (listenerClassNames.length > 0) {
2086 try {
2087 List<ModelListener<Contact>> listenersList = new ArrayList<ModelListener<Contact>>();
2088
2089 for (String listenerClassName : listenerClassNames) {
2090 listenersList.add((ModelListener<Contact>)InstanceFactory.newInstance(
2091 listenerClassName));
2092 }
2093
2094 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2095 }
2096 catch (Exception e) {
2097 _log.error(e);
2098 }
2099 }
2100 }
2101
2102 public void destroy() {
2103 EntityCacheUtil.removeCache(ContactImpl.class.getName());
2104 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2105 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2106 }
2107
2108 @BeanReference(type = AccountPersistence.class)
2109 protected AccountPersistence accountPersistence;
2110 @BeanReference(type = AddressPersistence.class)
2111 protected AddressPersistence addressPersistence;
2112 @BeanReference(type = BrowserTrackerPersistence.class)
2113 protected BrowserTrackerPersistence browserTrackerPersistence;
2114 @BeanReference(type = ClassNamePersistence.class)
2115 protected ClassNamePersistence classNamePersistence;
2116 @BeanReference(type = ClusterGroupPersistence.class)
2117 protected ClusterGroupPersistence clusterGroupPersistence;
2118 @BeanReference(type = CompanyPersistence.class)
2119 protected CompanyPersistence companyPersistence;
2120 @BeanReference(type = ContactPersistence.class)
2121 protected ContactPersistence contactPersistence;
2122 @BeanReference(type = CountryPersistence.class)
2123 protected CountryPersistence countryPersistence;
2124 @BeanReference(type = EmailAddressPersistence.class)
2125 protected EmailAddressPersistence emailAddressPersistence;
2126 @BeanReference(type = GroupPersistence.class)
2127 protected GroupPersistence groupPersistence;
2128 @BeanReference(type = ImagePersistence.class)
2129 protected ImagePersistence imagePersistence;
2130 @BeanReference(type = LayoutPersistence.class)
2131 protected LayoutPersistence layoutPersistence;
2132 @BeanReference(type = LayoutBranchPersistence.class)
2133 protected LayoutBranchPersistence layoutBranchPersistence;
2134 @BeanReference(type = LayoutPrototypePersistence.class)
2135 protected LayoutPrototypePersistence layoutPrototypePersistence;
2136 @BeanReference(type = LayoutRevisionPersistence.class)
2137 protected LayoutRevisionPersistence layoutRevisionPersistence;
2138 @BeanReference(type = LayoutSetPersistence.class)
2139 protected LayoutSetPersistence layoutSetPersistence;
2140 @BeanReference(type = LayoutSetBranchPersistence.class)
2141 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2142 @BeanReference(type = LayoutSetPrototypePersistence.class)
2143 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2144 @BeanReference(type = ListTypePersistence.class)
2145 protected ListTypePersistence listTypePersistence;
2146 @BeanReference(type = LockPersistence.class)
2147 protected LockPersistence lockPersistence;
2148 @BeanReference(type = MembershipRequestPersistence.class)
2149 protected MembershipRequestPersistence membershipRequestPersistence;
2150 @BeanReference(type = OrganizationPersistence.class)
2151 protected OrganizationPersistence organizationPersistence;
2152 @BeanReference(type = OrgGroupRolePersistence.class)
2153 protected OrgGroupRolePersistence orgGroupRolePersistence;
2154 @BeanReference(type = OrgLaborPersistence.class)
2155 protected OrgLaborPersistence orgLaborPersistence;
2156 @BeanReference(type = PasswordPolicyPersistence.class)
2157 protected PasswordPolicyPersistence passwordPolicyPersistence;
2158 @BeanReference(type = PasswordPolicyRelPersistence.class)
2159 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2160 @BeanReference(type = PasswordTrackerPersistence.class)
2161 protected PasswordTrackerPersistence passwordTrackerPersistence;
2162 @BeanReference(type = PhonePersistence.class)
2163 protected PhonePersistence phonePersistence;
2164 @BeanReference(type = PluginSettingPersistence.class)
2165 protected PluginSettingPersistence pluginSettingPersistence;
2166 @BeanReference(type = PortalPreferencesPersistence.class)
2167 protected PortalPreferencesPersistence portalPreferencesPersistence;
2168 @BeanReference(type = PortletPersistence.class)
2169 protected PortletPersistence portletPersistence;
2170 @BeanReference(type = PortletItemPersistence.class)
2171 protected PortletItemPersistence portletItemPersistence;
2172 @BeanReference(type = PortletPreferencesPersistence.class)
2173 protected PortletPreferencesPersistence portletPreferencesPersistence;
2174 @BeanReference(type = RegionPersistence.class)
2175 protected RegionPersistence regionPersistence;
2176 @BeanReference(type = ReleasePersistence.class)
2177 protected ReleasePersistence releasePersistence;
2178 @BeanReference(type = RepositoryPersistence.class)
2179 protected RepositoryPersistence repositoryPersistence;
2180 @BeanReference(type = RepositoryEntryPersistence.class)
2181 protected RepositoryEntryPersistence repositoryEntryPersistence;
2182 @BeanReference(type = ResourceActionPersistence.class)
2183 protected ResourceActionPersistence resourceActionPersistence;
2184 @BeanReference(type = ResourceBlockPersistence.class)
2185 protected ResourceBlockPersistence resourceBlockPersistence;
2186 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2187 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2188 @BeanReference(type = ResourcePermissionPersistence.class)
2189 protected ResourcePermissionPersistence resourcePermissionPersistence;
2190 @BeanReference(type = ResourceTypePermissionPersistence.class)
2191 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2192 @BeanReference(type = RolePersistence.class)
2193 protected RolePersistence rolePersistence;
2194 @BeanReference(type = ServiceComponentPersistence.class)
2195 protected ServiceComponentPersistence serviceComponentPersistence;
2196 @BeanReference(type = ShardPersistence.class)
2197 protected ShardPersistence shardPersistence;
2198 @BeanReference(type = SubscriptionPersistence.class)
2199 protected SubscriptionPersistence subscriptionPersistence;
2200 @BeanReference(type = TeamPersistence.class)
2201 protected TeamPersistence teamPersistence;
2202 @BeanReference(type = TicketPersistence.class)
2203 protected TicketPersistence ticketPersistence;
2204 @BeanReference(type = UserPersistence.class)
2205 protected UserPersistence userPersistence;
2206 @BeanReference(type = UserGroupPersistence.class)
2207 protected UserGroupPersistence userGroupPersistence;
2208 @BeanReference(type = UserGroupGroupRolePersistence.class)
2209 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2210 @BeanReference(type = UserGroupRolePersistence.class)
2211 protected UserGroupRolePersistence userGroupRolePersistence;
2212 @BeanReference(type = UserIdMapperPersistence.class)
2213 protected UserIdMapperPersistence userIdMapperPersistence;
2214 @BeanReference(type = UserNotificationEventPersistence.class)
2215 protected UserNotificationEventPersistence userNotificationEventPersistence;
2216 @BeanReference(type = UserTrackerPersistence.class)
2217 protected UserTrackerPersistence userTrackerPersistence;
2218 @BeanReference(type = UserTrackerPathPersistence.class)
2219 protected UserTrackerPathPersistence userTrackerPathPersistence;
2220 @BeanReference(type = VirtualHostPersistence.class)
2221 protected VirtualHostPersistence virtualHostPersistence;
2222 @BeanReference(type = WebDAVPropsPersistence.class)
2223 protected WebDAVPropsPersistence webDAVPropsPersistence;
2224 @BeanReference(type = WebsitePersistence.class)
2225 protected WebsitePersistence websitePersistence;
2226 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2227 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2228 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2229 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2230 private static final String _SQL_SELECT_CONTACT = "SELECT contact FROM Contact contact";
2231 private static final String _SQL_SELECT_CONTACT_WHERE = "SELECT contact FROM Contact contact WHERE ";
2232 private static final String _SQL_COUNT_CONTACT = "SELECT COUNT(contact) FROM Contact contact";
2233 private static final String _SQL_COUNT_CONTACT_WHERE = "SELECT COUNT(contact) FROM Contact contact WHERE ";
2234 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "contact.companyId = ?";
2235 private static final String _FINDER_COLUMN_ACCOUNTID_ACCOUNTID_2 = "contact.accountId = ?";
2236 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "contact.classNameId = ? AND ";
2237 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "contact.classPK = ?";
2238 private static final String _ORDER_BY_ENTITY_ALIAS = "contact.";
2239 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Contact exists with the primary key ";
2240 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Contact exists with the key {";
2241 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2242 private static Log _log = LogFactoryUtil.getLog(ContactPersistenceImpl.class);
2243 private static Contact _nullContact = new ContactImpl() {
2244 @Override
2245 public Object clone() {
2246 return this;
2247 }
2248
2249 @Override
2250 public CacheModel<Contact> toCacheModel() {
2251 return _nullContactCacheModel;
2252 }
2253 };
2254
2255 private static CacheModel<Contact> _nullContactCacheModel = new CacheModel<Contact>() {
2256 public Contact toEntityModel() {
2257 return _nullContact;
2258 }
2259 };
2260 }