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_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
095 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
098 ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
099 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
100 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
101 ContactModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
103
104
109 public void cacheResult(Contact contact) {
110 EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
111 ContactImpl.class, contact.getPrimaryKey(), contact);
112
113 contact.resetOriginalValues();
114 }
115
116
121 public void cacheResult(List<Contact> contacts) {
122 for (Contact contact : contacts) {
123 if (EntityCacheUtil.getResult(
124 ContactModelImpl.ENTITY_CACHE_ENABLED,
125 ContactImpl.class, contact.getPrimaryKey()) == null) {
126 cacheResult(contact);
127 }
128 else {
129 contact.resetOriginalValues();
130 }
131 }
132 }
133
134
141 @Override
142 public void clearCache() {
143 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
144 CacheRegistryUtil.clear(ContactImpl.class.getName());
145 }
146
147 EntityCacheUtil.clearCache(ContactImpl.class.getName());
148
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
151 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
152 }
153
154
161 @Override
162 public void clearCache(Contact contact) {
163 EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
164 ContactImpl.class, contact.getPrimaryKey());
165
166 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
167 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
168 }
169
170
176 public Contact create(long contactId) {
177 Contact contact = new ContactImpl();
178
179 contact.setNew(true);
180 contact.setPrimaryKey(contactId);
181
182 return contact;
183 }
184
185
193 @Override
194 public Contact remove(Serializable primaryKey)
195 throws NoSuchModelException, SystemException {
196 return remove(((Long)primaryKey).longValue());
197 }
198
199
207 public Contact remove(long contactId)
208 throws NoSuchContactException, SystemException {
209 Session session = null;
210
211 try {
212 session = openSession();
213
214 Contact contact = (Contact)session.get(ContactImpl.class,
215 Long.valueOf(contactId));
216
217 if (contact == null) {
218 if (_log.isWarnEnabled()) {
219 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
220 }
221
222 throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
223 contactId);
224 }
225
226 return contactPersistence.remove(contact);
227 }
228 catch (NoSuchContactException nsee) {
229 throw nsee;
230 }
231 catch (Exception e) {
232 throw processException(e);
233 }
234 finally {
235 closeSession(session);
236 }
237 }
238
239
246 @Override
247 public Contact remove(Contact contact) throws SystemException {
248 return super.remove(contact);
249 }
250
251 @Override
252 protected Contact removeImpl(Contact contact) throws SystemException {
253 contact = toUnwrappedModel(contact);
254
255 Session session = null;
256
257 try {
258 session = openSession();
259
260 BatchSessionUtil.delete(session, contact);
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 closeSession(session);
267 }
268
269 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
270 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
271
272 EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
273 ContactImpl.class, contact.getPrimaryKey());
274
275 return contact;
276 }
277
278 @Override
279 public Contact updateImpl(com.liferay.portal.model.Contact contact,
280 boolean merge) throws SystemException {
281 contact = toUnwrappedModel(contact);
282
283 boolean isNew = contact.isNew();
284
285 ContactModelImpl contactModelImpl = (ContactModelImpl)contact;
286
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 BatchSessionUtil.update(session, contact, merge);
293
294 contact.setNew(false);
295 }
296 catch (Exception e) {
297 throw processException(e);
298 }
299 finally {
300 closeSession(session);
301 }
302
303 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
304
305 if (isNew || !ContactModelImpl.COLUMN_BITMASK_ENABLED) {
306 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
307 }
308
309 else {
310 if ((contactModelImpl.getColumnBitmask() &
311 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
312 Object[] args = new Object[] {
313 Long.valueOf(contactModelImpl.getOriginalCompanyId())
314 };
315
316 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
317 args);
318 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
319 args);
320
321 args = new Object[] {
322 Long.valueOf(contactModelImpl.getCompanyId())
323 };
324
325 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
326 args);
327 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
328 args);
329 }
330 }
331
332 EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
333 ContactImpl.class, contact.getPrimaryKey(), contact);
334
335 return contact;
336 }
337
338 protected Contact toUnwrappedModel(Contact contact) {
339 if (contact instanceof ContactImpl) {
340 return contact;
341 }
342
343 ContactImpl contactImpl = new ContactImpl();
344
345 contactImpl.setNew(contact.isNew());
346 contactImpl.setPrimaryKey(contact.getPrimaryKey());
347
348 contactImpl.setContactId(contact.getContactId());
349 contactImpl.setCompanyId(contact.getCompanyId());
350 contactImpl.setUserId(contact.getUserId());
351 contactImpl.setUserName(contact.getUserName());
352 contactImpl.setCreateDate(contact.getCreateDate());
353 contactImpl.setModifiedDate(contact.getModifiedDate());
354 contactImpl.setAccountId(contact.getAccountId());
355 contactImpl.setParentContactId(contact.getParentContactId());
356 contactImpl.setFirstName(contact.getFirstName());
357 contactImpl.setMiddleName(contact.getMiddleName());
358 contactImpl.setLastName(contact.getLastName());
359 contactImpl.setPrefixId(contact.getPrefixId());
360 contactImpl.setSuffixId(contact.getSuffixId());
361 contactImpl.setMale(contact.isMale());
362 contactImpl.setBirthday(contact.getBirthday());
363 contactImpl.setSmsSn(contact.getSmsSn());
364 contactImpl.setAimSn(contact.getAimSn());
365 contactImpl.setFacebookSn(contact.getFacebookSn());
366 contactImpl.setIcqSn(contact.getIcqSn());
367 contactImpl.setJabberSn(contact.getJabberSn());
368 contactImpl.setMsnSn(contact.getMsnSn());
369 contactImpl.setMySpaceSn(contact.getMySpaceSn());
370 contactImpl.setSkypeSn(contact.getSkypeSn());
371 contactImpl.setTwitterSn(contact.getTwitterSn());
372 contactImpl.setYmSn(contact.getYmSn());
373 contactImpl.setEmployeeStatusId(contact.getEmployeeStatusId());
374 contactImpl.setEmployeeNumber(contact.getEmployeeNumber());
375 contactImpl.setJobTitle(contact.getJobTitle());
376 contactImpl.setJobClass(contact.getJobClass());
377 contactImpl.setHoursOfOperation(contact.getHoursOfOperation());
378
379 return contactImpl;
380 }
381
382
390 @Override
391 public Contact findByPrimaryKey(Serializable primaryKey)
392 throws NoSuchModelException, SystemException {
393 return findByPrimaryKey(((Long)primaryKey).longValue());
394 }
395
396
404 public Contact findByPrimaryKey(long contactId)
405 throws NoSuchContactException, SystemException {
406 Contact contact = fetchByPrimaryKey(contactId);
407
408 if (contact == null) {
409 if (_log.isWarnEnabled()) {
410 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
411 }
412
413 throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
414 contactId);
415 }
416
417 return contact;
418 }
419
420
427 @Override
428 public Contact fetchByPrimaryKey(Serializable primaryKey)
429 throws SystemException {
430 return fetchByPrimaryKey(((Long)primaryKey).longValue());
431 }
432
433
440 public Contact fetchByPrimaryKey(long contactId) throws SystemException {
441 Contact contact = (Contact)EntityCacheUtil.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
442 ContactImpl.class, contactId);
443
444 if (contact == _nullContact) {
445 return null;
446 }
447
448 if (contact == null) {
449 Session session = null;
450
451 boolean hasException = false;
452
453 try {
454 session = openSession();
455
456 contact = (Contact)session.get(ContactImpl.class,
457 Long.valueOf(contactId));
458 }
459 catch (Exception e) {
460 hasException = true;
461
462 throw processException(e);
463 }
464 finally {
465 if (contact != null) {
466 cacheResult(contact);
467 }
468 else if (!hasException) {
469 EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
470 ContactImpl.class, contactId, _nullContact);
471 }
472
473 closeSession(session);
474 }
475 }
476
477 return contact;
478 }
479
480
487 public List<Contact> findByCompanyId(long companyId)
488 throws SystemException {
489 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
490 null);
491 }
492
493
506 public List<Contact> findByCompanyId(long companyId, int start, int end)
507 throws SystemException {
508 return findByCompanyId(companyId, start, end, null);
509 }
510
511
525 public List<Contact> findByCompanyId(long companyId, int start, int end,
526 OrderByComparator orderByComparator) throws SystemException {
527 FinderPath finderPath = null;
528 Object[] finderArgs = null;
529
530 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
531 (orderByComparator == null)) {
532 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
533 finderArgs = new Object[] { companyId };
534 }
535 else {
536 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
537 finderArgs = new Object[] { companyId, start, end, orderByComparator };
538 }
539
540 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
541 finderArgs, this);
542
543 if (list == null) {
544 StringBundler query = null;
545
546 if (orderByComparator != null) {
547 query = new StringBundler(3 +
548 (orderByComparator.getOrderByFields().length * 3));
549 }
550 else {
551 query = new StringBundler(2);
552 }
553
554 query.append(_SQL_SELECT_CONTACT_WHERE);
555
556 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
557
558 if (orderByComparator != null) {
559 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
560 orderByComparator);
561 }
562
563 String sql = query.toString();
564
565 Session session = null;
566
567 try {
568 session = openSession();
569
570 Query q = session.createQuery(sql);
571
572 QueryPos qPos = QueryPos.getInstance(q);
573
574 qPos.add(companyId);
575
576 list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
577 }
578 catch (Exception e) {
579 throw processException(e);
580 }
581 finally {
582 if (list == null) {
583 FinderCacheUtil.removeResult(finderPath, finderArgs);
584 }
585 else {
586 cacheResult(list);
587
588 FinderCacheUtil.putResult(finderPath, finderArgs, list);
589 }
590
591 closeSession(session);
592 }
593 }
594
595 return list;
596 }
597
598
611 public Contact findByCompanyId_First(long companyId,
612 OrderByComparator orderByComparator)
613 throws NoSuchContactException, SystemException {
614 List<Contact> list = findByCompanyId(companyId, 0, 1, orderByComparator);
615
616 if (list.isEmpty()) {
617 StringBundler msg = new StringBundler(4);
618
619 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
620
621 msg.append("companyId=");
622 msg.append(companyId);
623
624 msg.append(StringPool.CLOSE_CURLY_BRACE);
625
626 throw new NoSuchContactException(msg.toString());
627 }
628 else {
629 return list.get(0);
630 }
631 }
632
633
646 public Contact findByCompanyId_Last(long companyId,
647 OrderByComparator orderByComparator)
648 throws NoSuchContactException, SystemException {
649 int count = countByCompanyId(companyId);
650
651 List<Contact> list = findByCompanyId(companyId, count - 1, count,
652 orderByComparator);
653
654 if (list.isEmpty()) {
655 StringBundler msg = new StringBundler(4);
656
657 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
658
659 msg.append("companyId=");
660 msg.append(companyId);
661
662 msg.append(StringPool.CLOSE_CURLY_BRACE);
663
664 throw new NoSuchContactException(msg.toString());
665 }
666 else {
667 return list.get(0);
668 }
669 }
670
671
685 public Contact[] findByCompanyId_PrevAndNext(long contactId,
686 long companyId, OrderByComparator orderByComparator)
687 throws NoSuchContactException, SystemException {
688 Contact contact = findByPrimaryKey(contactId);
689
690 Session session = null;
691
692 try {
693 session = openSession();
694
695 Contact[] array = new ContactImpl[3];
696
697 array[0] = getByCompanyId_PrevAndNext(session, contact, companyId,
698 orderByComparator, true);
699
700 array[1] = contact;
701
702 array[2] = getByCompanyId_PrevAndNext(session, contact, companyId,
703 orderByComparator, false);
704
705 return array;
706 }
707 catch (Exception e) {
708 throw processException(e);
709 }
710 finally {
711 closeSession(session);
712 }
713 }
714
715 protected Contact getByCompanyId_PrevAndNext(Session session,
716 Contact contact, long companyId, OrderByComparator orderByComparator,
717 boolean previous) {
718 StringBundler query = null;
719
720 if (orderByComparator != null) {
721 query = new StringBundler(6 +
722 (orderByComparator.getOrderByFields().length * 6));
723 }
724 else {
725 query = new StringBundler(3);
726 }
727
728 query.append(_SQL_SELECT_CONTACT_WHERE);
729
730 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
731
732 if (orderByComparator != null) {
733 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
734
735 if (orderByConditionFields.length > 0) {
736 query.append(WHERE_AND);
737 }
738
739 for (int i = 0; i < orderByConditionFields.length; i++) {
740 query.append(_ORDER_BY_ENTITY_ALIAS);
741 query.append(orderByConditionFields[i]);
742
743 if ((i + 1) < orderByConditionFields.length) {
744 if (orderByComparator.isAscending() ^ previous) {
745 query.append(WHERE_GREATER_THAN_HAS_NEXT);
746 }
747 else {
748 query.append(WHERE_LESSER_THAN_HAS_NEXT);
749 }
750 }
751 else {
752 if (orderByComparator.isAscending() ^ previous) {
753 query.append(WHERE_GREATER_THAN);
754 }
755 else {
756 query.append(WHERE_LESSER_THAN);
757 }
758 }
759 }
760
761 query.append(ORDER_BY_CLAUSE);
762
763 String[] orderByFields = orderByComparator.getOrderByFields();
764
765 for (int i = 0; i < orderByFields.length; i++) {
766 query.append(_ORDER_BY_ENTITY_ALIAS);
767 query.append(orderByFields[i]);
768
769 if ((i + 1) < orderByFields.length) {
770 if (orderByComparator.isAscending() ^ previous) {
771 query.append(ORDER_BY_ASC_HAS_NEXT);
772 }
773 else {
774 query.append(ORDER_BY_DESC_HAS_NEXT);
775 }
776 }
777 else {
778 if (orderByComparator.isAscending() ^ previous) {
779 query.append(ORDER_BY_ASC);
780 }
781 else {
782 query.append(ORDER_BY_DESC);
783 }
784 }
785 }
786 }
787
788 String sql = query.toString();
789
790 Query q = session.createQuery(sql);
791
792 q.setFirstResult(0);
793 q.setMaxResults(2);
794
795 QueryPos qPos = QueryPos.getInstance(q);
796
797 qPos.add(companyId);
798
799 if (orderByComparator != null) {
800 Object[] values = orderByComparator.getOrderByConditionValues(contact);
801
802 for (Object value : values) {
803 qPos.add(value);
804 }
805 }
806
807 List<Contact> list = q.list();
808
809 if (list.size() == 2) {
810 return list.get(1);
811 }
812 else {
813 return null;
814 }
815 }
816
817
823 public List<Contact> findAll() throws SystemException {
824 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
825 }
826
827
839 public List<Contact> findAll(int start, int end) throws SystemException {
840 return findAll(start, end, null);
841 }
842
843
856 public List<Contact> findAll(int start, int end,
857 OrderByComparator orderByComparator) throws SystemException {
858 FinderPath finderPath = null;
859 Object[] finderArgs = new Object[] { start, end, orderByComparator };
860
861 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
862 (orderByComparator == null)) {
863 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
864 finderArgs = FINDER_ARGS_EMPTY;
865 }
866 else {
867 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
868 finderArgs = new Object[] { start, end, orderByComparator };
869 }
870
871 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
872 finderArgs, this);
873
874 if (list == null) {
875 StringBundler query = null;
876 String sql = null;
877
878 if (orderByComparator != null) {
879 query = new StringBundler(2 +
880 (orderByComparator.getOrderByFields().length * 3));
881
882 query.append(_SQL_SELECT_CONTACT);
883
884 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
885 orderByComparator);
886
887 sql = query.toString();
888 }
889 else {
890 sql = _SQL_SELECT_CONTACT;
891 }
892
893 Session session = null;
894
895 try {
896 session = openSession();
897
898 Query q = session.createQuery(sql);
899
900 if (orderByComparator == null) {
901 list = (List<Contact>)QueryUtil.list(q, getDialect(),
902 start, end, false);
903
904 Collections.sort(list);
905 }
906 else {
907 list = (List<Contact>)QueryUtil.list(q, getDialect(),
908 start, end);
909 }
910 }
911 catch (Exception e) {
912 throw processException(e);
913 }
914 finally {
915 if (list == null) {
916 FinderCacheUtil.removeResult(finderPath, finderArgs);
917 }
918 else {
919 cacheResult(list);
920
921 FinderCacheUtil.putResult(finderPath, finderArgs, list);
922 }
923
924 closeSession(session);
925 }
926 }
927
928 return list;
929 }
930
931
937 public void removeByCompanyId(long companyId) throws SystemException {
938 for (Contact contact : findByCompanyId(companyId)) {
939 contactPersistence.remove(contact);
940 }
941 }
942
943
948 public void removeAll() throws SystemException {
949 for (Contact contact : findAll()) {
950 contactPersistence.remove(contact);
951 }
952 }
953
954
961 public int countByCompanyId(long companyId) throws SystemException {
962 Object[] finderArgs = new Object[] { companyId };
963
964 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
965 finderArgs, this);
966
967 if (count == null) {
968 StringBundler query = new StringBundler(2);
969
970 query.append(_SQL_COUNT_CONTACT_WHERE);
971
972 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
973
974 String sql = query.toString();
975
976 Session session = null;
977
978 try {
979 session = openSession();
980
981 Query q = session.createQuery(sql);
982
983 QueryPos qPos = QueryPos.getInstance(q);
984
985 qPos.add(companyId);
986
987 count = (Long)q.uniqueResult();
988 }
989 catch (Exception e) {
990 throw processException(e);
991 }
992 finally {
993 if (count == null) {
994 count = Long.valueOf(0);
995 }
996
997 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
998 finderArgs, count);
999
1000 closeSession(session);
1001 }
1002 }
1003
1004 return count.intValue();
1005 }
1006
1007
1013 public int countAll() throws SystemException {
1014 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1015 FINDER_ARGS_EMPTY, this);
1016
1017 if (count == null) {
1018 Session session = null;
1019
1020 try {
1021 session = openSession();
1022
1023 Query q = session.createQuery(_SQL_COUNT_CONTACT);
1024
1025 count = (Long)q.uniqueResult();
1026 }
1027 catch (Exception e) {
1028 throw processException(e);
1029 }
1030 finally {
1031 if (count == null) {
1032 count = Long.valueOf(0);
1033 }
1034
1035 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1036 FINDER_ARGS_EMPTY, count);
1037
1038 closeSession(session);
1039 }
1040 }
1041
1042 return count.intValue();
1043 }
1044
1045
1048 public void afterPropertiesSet() {
1049 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1050 com.liferay.portal.util.PropsUtil.get(
1051 "value.object.listener.com.liferay.portal.model.Contact")));
1052
1053 if (listenerClassNames.length > 0) {
1054 try {
1055 List<ModelListener<Contact>> listenersList = new ArrayList<ModelListener<Contact>>();
1056
1057 for (String listenerClassName : listenerClassNames) {
1058 listenersList.add((ModelListener<Contact>)InstanceFactory.newInstance(
1059 listenerClassName));
1060 }
1061
1062 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1063 }
1064 catch (Exception e) {
1065 _log.error(e);
1066 }
1067 }
1068 }
1069
1070 public void destroy() {
1071 EntityCacheUtil.removeCache(ContactImpl.class.getName());
1072 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1073 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1074 }
1075
1076 @BeanReference(type = AccountPersistence.class)
1077 protected AccountPersistence accountPersistence;
1078 @BeanReference(type = AddressPersistence.class)
1079 protected AddressPersistence addressPersistence;
1080 @BeanReference(type = BrowserTrackerPersistence.class)
1081 protected BrowserTrackerPersistence browserTrackerPersistence;
1082 @BeanReference(type = ClassNamePersistence.class)
1083 protected ClassNamePersistence classNamePersistence;
1084 @BeanReference(type = ClusterGroupPersistence.class)
1085 protected ClusterGroupPersistence clusterGroupPersistence;
1086 @BeanReference(type = CompanyPersistence.class)
1087 protected CompanyPersistence companyPersistence;
1088 @BeanReference(type = ContactPersistence.class)
1089 protected ContactPersistence contactPersistence;
1090 @BeanReference(type = CountryPersistence.class)
1091 protected CountryPersistence countryPersistence;
1092 @BeanReference(type = EmailAddressPersistence.class)
1093 protected EmailAddressPersistence emailAddressPersistence;
1094 @BeanReference(type = GroupPersistence.class)
1095 protected GroupPersistence groupPersistence;
1096 @BeanReference(type = ImagePersistence.class)
1097 protected ImagePersistence imagePersistence;
1098 @BeanReference(type = LayoutPersistence.class)
1099 protected LayoutPersistence layoutPersistence;
1100 @BeanReference(type = LayoutBranchPersistence.class)
1101 protected LayoutBranchPersistence layoutBranchPersistence;
1102 @BeanReference(type = LayoutPrototypePersistence.class)
1103 protected LayoutPrototypePersistence layoutPrototypePersistence;
1104 @BeanReference(type = LayoutRevisionPersistence.class)
1105 protected LayoutRevisionPersistence layoutRevisionPersistence;
1106 @BeanReference(type = LayoutSetPersistence.class)
1107 protected LayoutSetPersistence layoutSetPersistence;
1108 @BeanReference(type = LayoutSetBranchPersistence.class)
1109 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1110 @BeanReference(type = LayoutSetPrototypePersistence.class)
1111 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1112 @BeanReference(type = ListTypePersistence.class)
1113 protected ListTypePersistence listTypePersistence;
1114 @BeanReference(type = LockPersistence.class)
1115 protected LockPersistence lockPersistence;
1116 @BeanReference(type = MembershipRequestPersistence.class)
1117 protected MembershipRequestPersistence membershipRequestPersistence;
1118 @BeanReference(type = OrganizationPersistence.class)
1119 protected OrganizationPersistence organizationPersistence;
1120 @BeanReference(type = OrgGroupPermissionPersistence.class)
1121 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1122 @BeanReference(type = OrgGroupRolePersistence.class)
1123 protected OrgGroupRolePersistence orgGroupRolePersistence;
1124 @BeanReference(type = OrgLaborPersistence.class)
1125 protected OrgLaborPersistence orgLaborPersistence;
1126 @BeanReference(type = PasswordPolicyPersistence.class)
1127 protected PasswordPolicyPersistence passwordPolicyPersistence;
1128 @BeanReference(type = PasswordPolicyRelPersistence.class)
1129 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1130 @BeanReference(type = PasswordTrackerPersistence.class)
1131 protected PasswordTrackerPersistence passwordTrackerPersistence;
1132 @BeanReference(type = PermissionPersistence.class)
1133 protected PermissionPersistence permissionPersistence;
1134 @BeanReference(type = PhonePersistence.class)
1135 protected PhonePersistence phonePersistence;
1136 @BeanReference(type = PluginSettingPersistence.class)
1137 protected PluginSettingPersistence pluginSettingPersistence;
1138 @BeanReference(type = PortalPreferencesPersistence.class)
1139 protected PortalPreferencesPersistence portalPreferencesPersistence;
1140 @BeanReference(type = PortletPersistence.class)
1141 protected PortletPersistence portletPersistence;
1142 @BeanReference(type = PortletItemPersistence.class)
1143 protected PortletItemPersistence portletItemPersistence;
1144 @BeanReference(type = PortletPreferencesPersistence.class)
1145 protected PortletPreferencesPersistence portletPreferencesPersistence;
1146 @BeanReference(type = RegionPersistence.class)
1147 protected RegionPersistence regionPersistence;
1148 @BeanReference(type = ReleasePersistence.class)
1149 protected ReleasePersistence releasePersistence;
1150 @BeanReference(type = RepositoryPersistence.class)
1151 protected RepositoryPersistence repositoryPersistence;
1152 @BeanReference(type = RepositoryEntryPersistence.class)
1153 protected RepositoryEntryPersistence repositoryEntryPersistence;
1154 @BeanReference(type = ResourcePersistence.class)
1155 protected ResourcePersistence resourcePersistence;
1156 @BeanReference(type = ResourceActionPersistence.class)
1157 protected ResourceActionPersistence resourceActionPersistence;
1158 @BeanReference(type = ResourceBlockPersistence.class)
1159 protected ResourceBlockPersistence resourceBlockPersistence;
1160 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1161 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1162 @BeanReference(type = ResourceCodePersistence.class)
1163 protected ResourceCodePersistence resourceCodePersistence;
1164 @BeanReference(type = ResourcePermissionPersistence.class)
1165 protected ResourcePermissionPersistence resourcePermissionPersistence;
1166 @BeanReference(type = ResourceTypePermissionPersistence.class)
1167 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1168 @BeanReference(type = RolePersistence.class)
1169 protected RolePersistence rolePersistence;
1170 @BeanReference(type = ServiceComponentPersistence.class)
1171 protected ServiceComponentPersistence serviceComponentPersistence;
1172 @BeanReference(type = ShardPersistence.class)
1173 protected ShardPersistence shardPersistence;
1174 @BeanReference(type = SubscriptionPersistence.class)
1175 protected SubscriptionPersistence subscriptionPersistence;
1176 @BeanReference(type = TeamPersistence.class)
1177 protected TeamPersistence teamPersistence;
1178 @BeanReference(type = TicketPersistence.class)
1179 protected TicketPersistence ticketPersistence;
1180 @BeanReference(type = UserPersistence.class)
1181 protected UserPersistence userPersistence;
1182 @BeanReference(type = UserGroupPersistence.class)
1183 protected UserGroupPersistence userGroupPersistence;
1184 @BeanReference(type = UserGroupGroupRolePersistence.class)
1185 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1186 @BeanReference(type = UserGroupRolePersistence.class)
1187 protected UserGroupRolePersistence userGroupRolePersistence;
1188 @BeanReference(type = UserIdMapperPersistence.class)
1189 protected UserIdMapperPersistence userIdMapperPersistence;
1190 @BeanReference(type = UserNotificationEventPersistence.class)
1191 protected UserNotificationEventPersistence userNotificationEventPersistence;
1192 @BeanReference(type = UserTrackerPersistence.class)
1193 protected UserTrackerPersistence userTrackerPersistence;
1194 @BeanReference(type = UserTrackerPathPersistence.class)
1195 protected UserTrackerPathPersistence userTrackerPathPersistence;
1196 @BeanReference(type = VirtualHostPersistence.class)
1197 protected VirtualHostPersistence virtualHostPersistence;
1198 @BeanReference(type = WebDAVPropsPersistence.class)
1199 protected WebDAVPropsPersistence webDAVPropsPersistence;
1200 @BeanReference(type = WebsitePersistence.class)
1201 protected WebsitePersistence websitePersistence;
1202 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1203 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1204 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1205 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1206 private static final String _SQL_SELECT_CONTACT = "SELECT contact FROM Contact contact";
1207 private static final String _SQL_SELECT_CONTACT_WHERE = "SELECT contact FROM Contact contact WHERE ";
1208 private static final String _SQL_COUNT_CONTACT = "SELECT COUNT(contact) FROM Contact contact";
1209 private static final String _SQL_COUNT_CONTACT_WHERE = "SELECT COUNT(contact) FROM Contact contact WHERE ";
1210 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "contact.companyId = ?";
1211 private static final String _ORDER_BY_ENTITY_ALIAS = "contact.";
1212 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Contact exists with the primary key ";
1213 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Contact exists with the key {";
1214 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1215 private static Log _log = LogFactoryUtil.getLog(ContactPersistenceImpl.class);
1216 private static Contact _nullContact = new ContactImpl() {
1217 @Override
1218 public Object clone() {
1219 return this;
1220 }
1221
1222 @Override
1223 public CacheModel<Contact> toCacheModel() {
1224 return _nullContactCacheModel;
1225 }
1226 };
1227
1228 private static CacheModel<Contact> _nullContactCacheModel = new CacheModel<Contact>() {
1229 public Contact toEntityModel() {
1230 return _nullContact;
1231 }
1232 };
1233 }