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
303 else {
304 if ((contactModelImpl.getColumnBitmask() &
305 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
306 Object[] args = new Object[] {
307 Long.valueOf(contactModelImpl.getOriginalCompanyId())
308 };
309
310 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
311 args);
312 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
313 args);
314
315 args = new Object[] {
316 Long.valueOf(contactModelImpl.getCompanyId())
317 };
318
319 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
320 args);
321 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
322 args);
323 }
324 }
325
326 EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
327 ContactImpl.class, contact.getPrimaryKey(), contact);
328
329 return contact;
330 }
331
332 protected Contact toUnwrappedModel(Contact contact) {
333 if (contact instanceof ContactImpl) {
334 return contact;
335 }
336
337 ContactImpl contactImpl = new ContactImpl();
338
339 contactImpl.setNew(contact.isNew());
340 contactImpl.setPrimaryKey(contact.getPrimaryKey());
341
342 contactImpl.setContactId(contact.getContactId());
343 contactImpl.setCompanyId(contact.getCompanyId());
344 contactImpl.setUserId(contact.getUserId());
345 contactImpl.setUserName(contact.getUserName());
346 contactImpl.setCreateDate(contact.getCreateDate());
347 contactImpl.setModifiedDate(contact.getModifiedDate());
348 contactImpl.setAccountId(contact.getAccountId());
349 contactImpl.setParentContactId(contact.getParentContactId());
350 contactImpl.setFirstName(contact.getFirstName());
351 contactImpl.setMiddleName(contact.getMiddleName());
352 contactImpl.setLastName(contact.getLastName());
353 contactImpl.setPrefixId(contact.getPrefixId());
354 contactImpl.setSuffixId(contact.getSuffixId());
355 contactImpl.setMale(contact.isMale());
356 contactImpl.setBirthday(contact.getBirthday());
357 contactImpl.setSmsSn(contact.getSmsSn());
358 contactImpl.setAimSn(contact.getAimSn());
359 contactImpl.setFacebookSn(contact.getFacebookSn());
360 contactImpl.setIcqSn(contact.getIcqSn());
361 contactImpl.setJabberSn(contact.getJabberSn());
362 contactImpl.setMsnSn(contact.getMsnSn());
363 contactImpl.setMySpaceSn(contact.getMySpaceSn());
364 contactImpl.setSkypeSn(contact.getSkypeSn());
365 contactImpl.setTwitterSn(contact.getTwitterSn());
366 contactImpl.setYmSn(contact.getYmSn());
367 contactImpl.setEmployeeStatusId(contact.getEmployeeStatusId());
368 contactImpl.setEmployeeNumber(contact.getEmployeeNumber());
369 contactImpl.setJobTitle(contact.getJobTitle());
370 contactImpl.setJobClass(contact.getJobClass());
371 contactImpl.setHoursOfOperation(contact.getHoursOfOperation());
372
373 return contactImpl;
374 }
375
376
384 @Override
385 public Contact findByPrimaryKey(Serializable primaryKey)
386 throws NoSuchModelException, SystemException {
387 return findByPrimaryKey(((Long)primaryKey).longValue());
388 }
389
390
398 public Contact findByPrimaryKey(long contactId)
399 throws NoSuchContactException, SystemException {
400 Contact contact = fetchByPrimaryKey(contactId);
401
402 if (contact == null) {
403 if (_log.isWarnEnabled()) {
404 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
405 }
406
407 throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
408 contactId);
409 }
410
411 return contact;
412 }
413
414
421 @Override
422 public Contact fetchByPrimaryKey(Serializable primaryKey)
423 throws SystemException {
424 return fetchByPrimaryKey(((Long)primaryKey).longValue());
425 }
426
427
434 public Contact fetchByPrimaryKey(long contactId) throws SystemException {
435 Contact contact = (Contact)EntityCacheUtil.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
436 ContactImpl.class, contactId);
437
438 if (contact == _nullContact) {
439 return null;
440 }
441
442 if (contact == null) {
443 Session session = null;
444
445 boolean hasException = false;
446
447 try {
448 session = openSession();
449
450 contact = (Contact)session.get(ContactImpl.class,
451 Long.valueOf(contactId));
452 }
453 catch (Exception e) {
454 hasException = true;
455
456 throw processException(e);
457 }
458 finally {
459 if (contact != null) {
460 cacheResult(contact);
461 }
462 else if (!hasException) {
463 EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
464 ContactImpl.class, contactId, _nullContact);
465 }
466
467 closeSession(session);
468 }
469 }
470
471 return contact;
472 }
473
474
481 public List<Contact> findByCompanyId(long companyId)
482 throws SystemException {
483 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
484 null);
485 }
486
487
500 public List<Contact> findByCompanyId(long companyId, int start, int end)
501 throws SystemException {
502 return findByCompanyId(companyId, start, end, null);
503 }
504
505
519 public List<Contact> findByCompanyId(long companyId, int start, int end,
520 OrderByComparator orderByComparator) throws SystemException {
521 FinderPath finderPath = null;
522 Object[] finderArgs = null;
523
524 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
525 (orderByComparator == null)) {
526 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
527 finderArgs = new Object[] { companyId };
528 }
529 else {
530 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
531 finderArgs = new Object[] { companyId, start, end, orderByComparator };
532 }
533
534 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
535 finderArgs, this);
536
537 if ((list != null) && !list.isEmpty()) {
538 for (Contact contact : list) {
539 if ((companyId != contact.getCompanyId())) {
540 list = null;
541
542 break;
543 }
544 }
545 }
546
547 if (list == null) {
548 StringBundler query = null;
549
550 if (orderByComparator != null) {
551 query = new StringBundler(3 +
552 (orderByComparator.getOrderByFields().length * 3));
553 }
554 else {
555 query = new StringBundler(2);
556 }
557
558 query.append(_SQL_SELECT_CONTACT_WHERE);
559
560 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
561
562 if (orderByComparator != null) {
563 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
564 orderByComparator);
565 }
566
567 String sql = query.toString();
568
569 Session session = null;
570
571 try {
572 session = openSession();
573
574 Query q = session.createQuery(sql);
575
576 QueryPos qPos = QueryPos.getInstance(q);
577
578 qPos.add(companyId);
579
580 list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
581 }
582 catch (Exception e) {
583 throw processException(e);
584 }
585 finally {
586 if (list == null) {
587 FinderCacheUtil.removeResult(finderPath, finderArgs);
588 }
589 else {
590 cacheResult(list);
591
592 FinderCacheUtil.putResult(finderPath, finderArgs, list);
593 }
594
595 closeSession(session);
596 }
597 }
598
599 return list;
600 }
601
602
611 public Contact findByCompanyId_First(long companyId,
612 OrderByComparator orderByComparator)
613 throws NoSuchContactException, SystemException {
614 Contact contact = fetchByCompanyId_First(companyId, orderByComparator);
615
616 if (contact != null) {
617 return contact;
618 }
619
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
632
640 public Contact fetchByCompanyId_First(long companyId,
641 OrderByComparator orderByComparator) throws SystemException {
642 List<Contact> list = findByCompanyId(companyId, 0, 1, orderByComparator);
643
644 if (!list.isEmpty()) {
645 return list.get(0);
646 }
647
648 return null;
649 }
650
651
660 public Contact findByCompanyId_Last(long companyId,
661 OrderByComparator orderByComparator)
662 throws NoSuchContactException, SystemException {
663 Contact contact = fetchByCompanyId_Last(companyId, orderByComparator);
664
665 if (contact != null) {
666 return contact;
667 }
668
669 StringBundler msg = new StringBundler(4);
670
671 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
672
673 msg.append("companyId=");
674 msg.append(companyId);
675
676 msg.append(StringPool.CLOSE_CURLY_BRACE);
677
678 throw new NoSuchContactException(msg.toString());
679 }
680
681
689 public Contact fetchByCompanyId_Last(long companyId,
690 OrderByComparator orderByComparator) throws SystemException {
691 int count = countByCompanyId(companyId);
692
693 List<Contact> list = findByCompanyId(companyId, count - 1, count,
694 orderByComparator);
695
696 if (!list.isEmpty()) {
697 return list.get(0);
698 }
699
700 return null;
701 }
702
703
713 public Contact[] findByCompanyId_PrevAndNext(long contactId,
714 long companyId, OrderByComparator orderByComparator)
715 throws NoSuchContactException, SystemException {
716 Contact contact = findByPrimaryKey(contactId);
717
718 Session session = null;
719
720 try {
721 session = openSession();
722
723 Contact[] array = new ContactImpl[3];
724
725 array[0] = getByCompanyId_PrevAndNext(session, contact, companyId,
726 orderByComparator, true);
727
728 array[1] = contact;
729
730 array[2] = getByCompanyId_PrevAndNext(session, contact, companyId,
731 orderByComparator, false);
732
733 return array;
734 }
735 catch (Exception e) {
736 throw processException(e);
737 }
738 finally {
739 closeSession(session);
740 }
741 }
742
743 protected Contact getByCompanyId_PrevAndNext(Session session,
744 Contact contact, long companyId, OrderByComparator orderByComparator,
745 boolean previous) {
746 StringBundler query = null;
747
748 if (orderByComparator != null) {
749 query = new StringBundler(6 +
750 (orderByComparator.getOrderByFields().length * 6));
751 }
752 else {
753 query = new StringBundler(3);
754 }
755
756 query.append(_SQL_SELECT_CONTACT_WHERE);
757
758 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
759
760 if (orderByComparator != null) {
761 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
762
763 if (orderByConditionFields.length > 0) {
764 query.append(WHERE_AND);
765 }
766
767 for (int i = 0; i < orderByConditionFields.length; i++) {
768 query.append(_ORDER_BY_ENTITY_ALIAS);
769 query.append(orderByConditionFields[i]);
770
771 if ((i + 1) < orderByConditionFields.length) {
772 if (orderByComparator.isAscending() ^ previous) {
773 query.append(WHERE_GREATER_THAN_HAS_NEXT);
774 }
775 else {
776 query.append(WHERE_LESSER_THAN_HAS_NEXT);
777 }
778 }
779 else {
780 if (orderByComparator.isAscending() ^ previous) {
781 query.append(WHERE_GREATER_THAN);
782 }
783 else {
784 query.append(WHERE_LESSER_THAN);
785 }
786 }
787 }
788
789 query.append(ORDER_BY_CLAUSE);
790
791 String[] orderByFields = orderByComparator.getOrderByFields();
792
793 for (int i = 0; i < orderByFields.length; i++) {
794 query.append(_ORDER_BY_ENTITY_ALIAS);
795 query.append(orderByFields[i]);
796
797 if ((i + 1) < orderByFields.length) {
798 if (orderByComparator.isAscending() ^ previous) {
799 query.append(ORDER_BY_ASC_HAS_NEXT);
800 }
801 else {
802 query.append(ORDER_BY_DESC_HAS_NEXT);
803 }
804 }
805 else {
806 if (orderByComparator.isAscending() ^ previous) {
807 query.append(ORDER_BY_ASC);
808 }
809 else {
810 query.append(ORDER_BY_DESC);
811 }
812 }
813 }
814 }
815
816 String sql = query.toString();
817
818 Query q = session.createQuery(sql);
819
820 q.setFirstResult(0);
821 q.setMaxResults(2);
822
823 QueryPos qPos = QueryPos.getInstance(q);
824
825 qPos.add(companyId);
826
827 if (orderByComparator != null) {
828 Object[] values = orderByComparator.getOrderByConditionValues(contact);
829
830 for (Object value : values) {
831 qPos.add(value);
832 }
833 }
834
835 List<Contact> list = q.list();
836
837 if (list.size() == 2) {
838 return list.get(1);
839 }
840 else {
841 return null;
842 }
843 }
844
845
851 public List<Contact> findAll() throws SystemException {
852 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
853 }
854
855
867 public List<Contact> findAll(int start, int end) throws SystemException {
868 return findAll(start, end, null);
869 }
870
871
884 public List<Contact> findAll(int start, int end,
885 OrderByComparator orderByComparator) throws SystemException {
886 FinderPath finderPath = null;
887 Object[] finderArgs = new Object[] { start, end, orderByComparator };
888
889 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
890 (orderByComparator == null)) {
891 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
892 finderArgs = FINDER_ARGS_EMPTY;
893 }
894 else {
895 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
896 finderArgs = new Object[] { start, end, orderByComparator };
897 }
898
899 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
900 finderArgs, this);
901
902 if (list == null) {
903 StringBundler query = null;
904 String sql = null;
905
906 if (orderByComparator != null) {
907 query = new StringBundler(2 +
908 (orderByComparator.getOrderByFields().length * 3));
909
910 query.append(_SQL_SELECT_CONTACT);
911
912 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
913 orderByComparator);
914
915 sql = query.toString();
916 }
917 else {
918 sql = _SQL_SELECT_CONTACT;
919 }
920
921 Session session = null;
922
923 try {
924 session = openSession();
925
926 Query q = session.createQuery(sql);
927
928 if (orderByComparator == null) {
929 list = (List<Contact>)QueryUtil.list(q, getDialect(),
930 start, end, false);
931
932 Collections.sort(list);
933 }
934 else {
935 list = (List<Contact>)QueryUtil.list(q, getDialect(),
936 start, end);
937 }
938 }
939 catch (Exception e) {
940 throw processException(e);
941 }
942 finally {
943 if (list == null) {
944 FinderCacheUtil.removeResult(finderPath, finderArgs);
945 }
946 else {
947 cacheResult(list);
948
949 FinderCacheUtil.putResult(finderPath, finderArgs, list);
950 }
951
952 closeSession(session);
953 }
954 }
955
956 return list;
957 }
958
959
965 public void removeByCompanyId(long companyId) throws SystemException {
966 for (Contact contact : findByCompanyId(companyId)) {
967 remove(contact);
968 }
969 }
970
971
976 public void removeAll() throws SystemException {
977 for (Contact contact : findAll()) {
978 remove(contact);
979 }
980 }
981
982
989 public int countByCompanyId(long companyId) throws SystemException {
990 Object[] finderArgs = new Object[] { companyId };
991
992 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
993 finderArgs, this);
994
995 if (count == null) {
996 StringBundler query = new StringBundler(2);
997
998 query.append(_SQL_COUNT_CONTACT_WHERE);
999
1000 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1001
1002 String sql = query.toString();
1003
1004 Session session = null;
1005
1006 try {
1007 session = openSession();
1008
1009 Query q = session.createQuery(sql);
1010
1011 QueryPos qPos = QueryPos.getInstance(q);
1012
1013 qPos.add(companyId);
1014
1015 count = (Long)q.uniqueResult();
1016 }
1017 catch (Exception e) {
1018 throw processException(e);
1019 }
1020 finally {
1021 if (count == null) {
1022 count = Long.valueOf(0);
1023 }
1024
1025 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1026 finderArgs, count);
1027
1028 closeSession(session);
1029 }
1030 }
1031
1032 return count.intValue();
1033 }
1034
1035
1041 public int countAll() throws SystemException {
1042 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1043 FINDER_ARGS_EMPTY, this);
1044
1045 if (count == null) {
1046 Session session = null;
1047
1048 try {
1049 session = openSession();
1050
1051 Query q = session.createQuery(_SQL_COUNT_CONTACT);
1052
1053 count = (Long)q.uniqueResult();
1054 }
1055 catch (Exception e) {
1056 throw processException(e);
1057 }
1058 finally {
1059 if (count == null) {
1060 count = Long.valueOf(0);
1061 }
1062
1063 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1064 FINDER_ARGS_EMPTY, count);
1065
1066 closeSession(session);
1067 }
1068 }
1069
1070 return count.intValue();
1071 }
1072
1073
1076 public void afterPropertiesSet() {
1077 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1078 com.liferay.portal.util.PropsUtil.get(
1079 "value.object.listener.com.liferay.portal.model.Contact")));
1080
1081 if (listenerClassNames.length > 0) {
1082 try {
1083 List<ModelListener<Contact>> listenersList = new ArrayList<ModelListener<Contact>>();
1084
1085 for (String listenerClassName : listenerClassNames) {
1086 Class<?> clazz = getClass();
1087
1088 listenersList.add((ModelListener<Contact>)InstanceFactory.newInstance(
1089 clazz.getClassLoader(), listenerClassName));
1090 }
1091
1092 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1093 }
1094 catch (Exception e) {
1095 _log.error(e);
1096 }
1097 }
1098 }
1099
1100 public void destroy() {
1101 EntityCacheUtil.removeCache(ContactImpl.class.getName());
1102 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1103 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1104 }
1105
1106 @BeanReference(type = AccountPersistence.class)
1107 protected AccountPersistence accountPersistence;
1108 @BeanReference(type = AddressPersistence.class)
1109 protected AddressPersistence addressPersistence;
1110 @BeanReference(type = BrowserTrackerPersistence.class)
1111 protected BrowserTrackerPersistence browserTrackerPersistence;
1112 @BeanReference(type = ClassNamePersistence.class)
1113 protected ClassNamePersistence classNamePersistence;
1114 @BeanReference(type = ClusterGroupPersistence.class)
1115 protected ClusterGroupPersistence clusterGroupPersistence;
1116 @BeanReference(type = CompanyPersistence.class)
1117 protected CompanyPersistence companyPersistence;
1118 @BeanReference(type = ContactPersistence.class)
1119 protected ContactPersistence contactPersistence;
1120 @BeanReference(type = CountryPersistence.class)
1121 protected CountryPersistence countryPersistence;
1122 @BeanReference(type = EmailAddressPersistence.class)
1123 protected EmailAddressPersistence emailAddressPersistence;
1124 @BeanReference(type = GroupPersistence.class)
1125 protected GroupPersistence groupPersistence;
1126 @BeanReference(type = ImagePersistence.class)
1127 protected ImagePersistence imagePersistence;
1128 @BeanReference(type = LayoutPersistence.class)
1129 protected LayoutPersistence layoutPersistence;
1130 @BeanReference(type = LayoutBranchPersistence.class)
1131 protected LayoutBranchPersistence layoutBranchPersistence;
1132 @BeanReference(type = LayoutPrototypePersistence.class)
1133 protected LayoutPrototypePersistence layoutPrototypePersistence;
1134 @BeanReference(type = LayoutRevisionPersistence.class)
1135 protected LayoutRevisionPersistence layoutRevisionPersistence;
1136 @BeanReference(type = LayoutSetPersistence.class)
1137 protected LayoutSetPersistence layoutSetPersistence;
1138 @BeanReference(type = LayoutSetBranchPersistence.class)
1139 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1140 @BeanReference(type = LayoutSetPrototypePersistence.class)
1141 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1142 @BeanReference(type = ListTypePersistence.class)
1143 protected ListTypePersistence listTypePersistence;
1144 @BeanReference(type = LockPersistence.class)
1145 protected LockPersistence lockPersistence;
1146 @BeanReference(type = MembershipRequestPersistence.class)
1147 protected MembershipRequestPersistence membershipRequestPersistence;
1148 @BeanReference(type = OrganizationPersistence.class)
1149 protected OrganizationPersistence organizationPersistence;
1150 @BeanReference(type = OrgGroupPermissionPersistence.class)
1151 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1152 @BeanReference(type = OrgGroupRolePersistence.class)
1153 protected OrgGroupRolePersistence orgGroupRolePersistence;
1154 @BeanReference(type = OrgLaborPersistence.class)
1155 protected OrgLaborPersistence orgLaborPersistence;
1156 @BeanReference(type = PasswordPolicyPersistence.class)
1157 protected PasswordPolicyPersistence passwordPolicyPersistence;
1158 @BeanReference(type = PasswordPolicyRelPersistence.class)
1159 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1160 @BeanReference(type = PasswordTrackerPersistence.class)
1161 protected PasswordTrackerPersistence passwordTrackerPersistence;
1162 @BeanReference(type = PermissionPersistence.class)
1163 protected PermissionPersistence permissionPersistence;
1164 @BeanReference(type = PhonePersistence.class)
1165 protected PhonePersistence phonePersistence;
1166 @BeanReference(type = PluginSettingPersistence.class)
1167 protected PluginSettingPersistence pluginSettingPersistence;
1168 @BeanReference(type = PortalPreferencesPersistence.class)
1169 protected PortalPreferencesPersistence portalPreferencesPersistence;
1170 @BeanReference(type = PortletPersistence.class)
1171 protected PortletPersistence portletPersistence;
1172 @BeanReference(type = PortletItemPersistence.class)
1173 protected PortletItemPersistence portletItemPersistence;
1174 @BeanReference(type = PortletPreferencesPersistence.class)
1175 protected PortletPreferencesPersistence portletPreferencesPersistence;
1176 @BeanReference(type = RegionPersistence.class)
1177 protected RegionPersistence regionPersistence;
1178 @BeanReference(type = ReleasePersistence.class)
1179 protected ReleasePersistence releasePersistence;
1180 @BeanReference(type = RepositoryPersistence.class)
1181 protected RepositoryPersistence repositoryPersistence;
1182 @BeanReference(type = RepositoryEntryPersistence.class)
1183 protected RepositoryEntryPersistence repositoryEntryPersistence;
1184 @BeanReference(type = ResourcePersistence.class)
1185 protected ResourcePersistence resourcePersistence;
1186 @BeanReference(type = ResourceActionPersistence.class)
1187 protected ResourceActionPersistence resourceActionPersistence;
1188 @BeanReference(type = ResourceBlockPersistence.class)
1189 protected ResourceBlockPersistence resourceBlockPersistence;
1190 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1191 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1192 @BeanReference(type = ResourceCodePersistence.class)
1193 protected ResourceCodePersistence resourceCodePersistence;
1194 @BeanReference(type = ResourcePermissionPersistence.class)
1195 protected ResourcePermissionPersistence resourcePermissionPersistence;
1196 @BeanReference(type = ResourceTypePermissionPersistence.class)
1197 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1198 @BeanReference(type = RolePersistence.class)
1199 protected RolePersistence rolePersistence;
1200 @BeanReference(type = ServiceComponentPersistence.class)
1201 protected ServiceComponentPersistence serviceComponentPersistence;
1202 @BeanReference(type = ShardPersistence.class)
1203 protected ShardPersistence shardPersistence;
1204 @BeanReference(type = SubscriptionPersistence.class)
1205 protected SubscriptionPersistence subscriptionPersistence;
1206 @BeanReference(type = TeamPersistence.class)
1207 protected TeamPersistence teamPersistence;
1208 @BeanReference(type = TicketPersistence.class)
1209 protected TicketPersistence ticketPersistence;
1210 @BeanReference(type = UserPersistence.class)
1211 protected UserPersistence userPersistence;
1212 @BeanReference(type = UserGroupPersistence.class)
1213 protected UserGroupPersistence userGroupPersistence;
1214 @BeanReference(type = UserGroupGroupRolePersistence.class)
1215 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1216 @BeanReference(type = UserGroupRolePersistence.class)
1217 protected UserGroupRolePersistence userGroupRolePersistence;
1218 @BeanReference(type = UserIdMapperPersistence.class)
1219 protected UserIdMapperPersistence userIdMapperPersistence;
1220 @BeanReference(type = UserNotificationEventPersistence.class)
1221 protected UserNotificationEventPersistence userNotificationEventPersistence;
1222 @BeanReference(type = UserTrackerPersistence.class)
1223 protected UserTrackerPersistence userTrackerPersistence;
1224 @BeanReference(type = UserTrackerPathPersistence.class)
1225 protected UserTrackerPathPersistence userTrackerPathPersistence;
1226 @BeanReference(type = VirtualHostPersistence.class)
1227 protected VirtualHostPersistence virtualHostPersistence;
1228 @BeanReference(type = WebDAVPropsPersistence.class)
1229 protected WebDAVPropsPersistence webDAVPropsPersistence;
1230 @BeanReference(type = WebsitePersistence.class)
1231 protected WebsitePersistence websitePersistence;
1232 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1233 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1234 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1235 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1236 private static final String _SQL_SELECT_CONTACT = "SELECT contact FROM Contact contact";
1237 private static final String _SQL_SELECT_CONTACT_WHERE = "SELECT contact FROM Contact contact WHERE ";
1238 private static final String _SQL_COUNT_CONTACT = "SELECT COUNT(contact) FROM Contact contact";
1239 private static final String _SQL_COUNT_CONTACT_WHERE = "SELECT COUNT(contact) FROM Contact contact WHERE ";
1240 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "contact.companyId = ?";
1241 private static final String _ORDER_BY_ENTITY_ALIAS = "contact.";
1242 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Contact exists with the primary key ";
1243 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Contact exists with the key {";
1244 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1245 private static Log _log = LogFactoryUtil.getLog(ContactPersistenceImpl.class);
1246 private static Contact _nullContact = new ContactImpl() {
1247 @Override
1248 public Object clone() {
1249 return this;
1250 }
1251
1252 @Override
1253 public CacheModel<Contact> toCacheModel() {
1254 return _nullContactCacheModel;
1255 }
1256 };
1257
1258 private static CacheModel<Contact> _nullContactCacheModel = new CacheModel<Contact>() {
1259 public Contact toEntityModel() {
1260 return _nullContact;
1261 }
1262 };
1263 }