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