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 @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) {
538 StringBundler query = null;
539
540 if (orderByComparator != null) {
541 query = new StringBundler(3 +
542 (orderByComparator.getOrderByFields().length * 3));
543 }
544 else {
545 query = new StringBundler(2);
546 }
547
548 query.append(_SQL_SELECT_CONTACT_WHERE);
549
550 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
551
552 if (orderByComparator != null) {
553 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
554 orderByComparator);
555 }
556
557 String sql = query.toString();
558
559 Session session = null;
560
561 try {
562 session = openSession();
563
564 Query q = session.createQuery(sql);
565
566 QueryPos qPos = QueryPos.getInstance(q);
567
568 qPos.add(companyId);
569
570 list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
571 }
572 catch (Exception e) {
573 throw processException(e);
574 }
575 finally {
576 if (list == null) {
577 FinderCacheUtil.removeResult(finderPath, finderArgs);
578 }
579 else {
580 cacheResult(list);
581
582 FinderCacheUtil.putResult(finderPath, finderArgs, list);
583 }
584
585 closeSession(session);
586 }
587 }
588
589 return list;
590 }
591
592
605 public Contact findByCompanyId_First(long companyId,
606 OrderByComparator orderByComparator)
607 throws NoSuchContactException, SystemException {
608 List<Contact> list = findByCompanyId(companyId, 0, 1, orderByComparator);
609
610 if (list.isEmpty()) {
611 StringBundler msg = new StringBundler(4);
612
613 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
614
615 msg.append("companyId=");
616 msg.append(companyId);
617
618 msg.append(StringPool.CLOSE_CURLY_BRACE);
619
620 throw new NoSuchContactException(msg.toString());
621 }
622 else {
623 return list.get(0);
624 }
625 }
626
627
640 public Contact findByCompanyId_Last(long companyId,
641 OrderByComparator orderByComparator)
642 throws NoSuchContactException, SystemException {
643 int count = countByCompanyId(companyId);
644
645 List<Contact> list = findByCompanyId(companyId, count - 1, count,
646 orderByComparator);
647
648 if (list.isEmpty()) {
649 StringBundler msg = new StringBundler(4);
650
651 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
652
653 msg.append("companyId=");
654 msg.append(companyId);
655
656 msg.append(StringPool.CLOSE_CURLY_BRACE);
657
658 throw new NoSuchContactException(msg.toString());
659 }
660 else {
661 return list.get(0);
662 }
663 }
664
665
679 public Contact[] findByCompanyId_PrevAndNext(long contactId,
680 long companyId, OrderByComparator orderByComparator)
681 throws NoSuchContactException, SystemException {
682 Contact contact = findByPrimaryKey(contactId);
683
684 Session session = null;
685
686 try {
687 session = openSession();
688
689 Contact[] array = new ContactImpl[3];
690
691 array[0] = getByCompanyId_PrevAndNext(session, contact, companyId,
692 orderByComparator, true);
693
694 array[1] = contact;
695
696 array[2] = getByCompanyId_PrevAndNext(session, contact, companyId,
697 orderByComparator, false);
698
699 return array;
700 }
701 catch (Exception e) {
702 throw processException(e);
703 }
704 finally {
705 closeSession(session);
706 }
707 }
708
709 protected Contact getByCompanyId_PrevAndNext(Session session,
710 Contact contact, long companyId, OrderByComparator orderByComparator,
711 boolean previous) {
712 StringBundler query = null;
713
714 if (orderByComparator != null) {
715 query = new StringBundler(6 +
716 (orderByComparator.getOrderByFields().length * 6));
717 }
718 else {
719 query = new StringBundler(3);
720 }
721
722 query.append(_SQL_SELECT_CONTACT_WHERE);
723
724 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
725
726 if (orderByComparator != null) {
727 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
728
729 if (orderByConditionFields.length > 0) {
730 query.append(WHERE_AND);
731 }
732
733 for (int i = 0; i < orderByConditionFields.length; i++) {
734 query.append(_ORDER_BY_ENTITY_ALIAS);
735 query.append(orderByConditionFields[i]);
736
737 if ((i + 1) < orderByConditionFields.length) {
738 if (orderByComparator.isAscending() ^ previous) {
739 query.append(WHERE_GREATER_THAN_HAS_NEXT);
740 }
741 else {
742 query.append(WHERE_LESSER_THAN_HAS_NEXT);
743 }
744 }
745 else {
746 if (orderByComparator.isAscending() ^ previous) {
747 query.append(WHERE_GREATER_THAN);
748 }
749 else {
750 query.append(WHERE_LESSER_THAN);
751 }
752 }
753 }
754
755 query.append(ORDER_BY_CLAUSE);
756
757 String[] orderByFields = orderByComparator.getOrderByFields();
758
759 for (int i = 0; i < orderByFields.length; i++) {
760 query.append(_ORDER_BY_ENTITY_ALIAS);
761 query.append(orderByFields[i]);
762
763 if ((i + 1) < orderByFields.length) {
764 if (orderByComparator.isAscending() ^ previous) {
765 query.append(ORDER_BY_ASC_HAS_NEXT);
766 }
767 else {
768 query.append(ORDER_BY_DESC_HAS_NEXT);
769 }
770 }
771 else {
772 if (orderByComparator.isAscending() ^ previous) {
773 query.append(ORDER_BY_ASC);
774 }
775 else {
776 query.append(ORDER_BY_DESC);
777 }
778 }
779 }
780 }
781
782 String sql = query.toString();
783
784 Query q = session.createQuery(sql);
785
786 q.setFirstResult(0);
787 q.setMaxResults(2);
788
789 QueryPos qPos = QueryPos.getInstance(q);
790
791 qPos.add(companyId);
792
793 if (orderByComparator != null) {
794 Object[] values = orderByComparator.getOrderByConditionValues(contact);
795
796 for (Object value : values) {
797 qPos.add(value);
798 }
799 }
800
801 List<Contact> list = q.list();
802
803 if (list.size() == 2) {
804 return list.get(1);
805 }
806 else {
807 return null;
808 }
809 }
810
811
817 public List<Contact> findAll() throws SystemException {
818 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
819 }
820
821
833 public List<Contact> findAll(int start, int end) throws SystemException {
834 return findAll(start, end, null);
835 }
836
837
850 public List<Contact> findAll(int start, int end,
851 OrderByComparator orderByComparator) throws SystemException {
852 FinderPath finderPath = null;
853 Object[] finderArgs = new Object[] { start, end, orderByComparator };
854
855 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
856 (orderByComparator == null)) {
857 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
858 finderArgs = FINDER_ARGS_EMPTY;
859 }
860 else {
861 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
862 finderArgs = new Object[] { start, end, orderByComparator };
863 }
864
865 List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
866 finderArgs, this);
867
868 if (list == null) {
869 StringBundler query = null;
870 String sql = null;
871
872 if (orderByComparator != null) {
873 query = new StringBundler(2 +
874 (orderByComparator.getOrderByFields().length * 3));
875
876 query.append(_SQL_SELECT_CONTACT);
877
878 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
879 orderByComparator);
880
881 sql = query.toString();
882 }
883 else {
884 sql = _SQL_SELECT_CONTACT;
885 }
886
887 Session session = null;
888
889 try {
890 session = openSession();
891
892 Query q = session.createQuery(sql);
893
894 if (orderByComparator == null) {
895 list = (List<Contact>)QueryUtil.list(q, getDialect(),
896 start, end, false);
897
898 Collections.sort(list);
899 }
900 else {
901 list = (List<Contact>)QueryUtil.list(q, getDialect(),
902 start, end);
903 }
904 }
905 catch (Exception e) {
906 throw processException(e);
907 }
908 finally {
909 if (list == null) {
910 FinderCacheUtil.removeResult(finderPath, finderArgs);
911 }
912 else {
913 cacheResult(list);
914
915 FinderCacheUtil.putResult(finderPath, finderArgs, list);
916 }
917
918 closeSession(session);
919 }
920 }
921
922 return list;
923 }
924
925
931 public void removeByCompanyId(long companyId) throws SystemException {
932 for (Contact contact : findByCompanyId(companyId)) {
933 remove(contact);
934 }
935 }
936
937
942 public void removeAll() throws SystemException {
943 for (Contact contact : findAll()) {
944 remove(contact);
945 }
946 }
947
948
955 public int countByCompanyId(long companyId) throws SystemException {
956 Object[] finderArgs = new Object[] { companyId };
957
958 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
959 finderArgs, this);
960
961 if (count == null) {
962 StringBundler query = new StringBundler(2);
963
964 query.append(_SQL_COUNT_CONTACT_WHERE);
965
966 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
967
968 String sql = query.toString();
969
970 Session session = null;
971
972 try {
973 session = openSession();
974
975 Query q = session.createQuery(sql);
976
977 QueryPos qPos = QueryPos.getInstance(q);
978
979 qPos.add(companyId);
980
981 count = (Long)q.uniqueResult();
982 }
983 catch (Exception e) {
984 throw processException(e);
985 }
986 finally {
987 if (count == null) {
988 count = Long.valueOf(0);
989 }
990
991 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
992 finderArgs, count);
993
994 closeSession(session);
995 }
996 }
997
998 return count.intValue();
999 }
1000
1001
1007 public int countAll() throws SystemException {
1008 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1009 FINDER_ARGS_EMPTY, this);
1010
1011 if (count == null) {
1012 Session session = null;
1013
1014 try {
1015 session = openSession();
1016
1017 Query q = session.createQuery(_SQL_COUNT_CONTACT);
1018
1019 count = (Long)q.uniqueResult();
1020 }
1021 catch (Exception e) {
1022 throw processException(e);
1023 }
1024 finally {
1025 if (count == null) {
1026 count = Long.valueOf(0);
1027 }
1028
1029 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1030 FINDER_ARGS_EMPTY, count);
1031
1032 closeSession(session);
1033 }
1034 }
1035
1036 return count.intValue();
1037 }
1038
1039
1042 public void afterPropertiesSet() {
1043 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1044 com.liferay.portal.util.PropsUtil.get(
1045 "value.object.listener.com.liferay.portal.model.Contact")));
1046
1047 if (listenerClassNames.length > 0) {
1048 try {
1049 List<ModelListener<Contact>> listenersList = new ArrayList<ModelListener<Contact>>();
1050
1051 for (String listenerClassName : listenerClassNames) {
1052 listenersList.add((ModelListener<Contact>)InstanceFactory.newInstance(
1053 listenerClassName));
1054 }
1055
1056 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1057 }
1058 catch (Exception e) {
1059 _log.error(e);
1060 }
1061 }
1062 }
1063
1064 public void destroy() {
1065 EntityCacheUtil.removeCache(ContactImpl.class.getName());
1066 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1067 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1068 }
1069
1070 @BeanReference(type = AccountPersistence.class)
1071 protected AccountPersistence accountPersistence;
1072 @BeanReference(type = AddressPersistence.class)
1073 protected AddressPersistence addressPersistence;
1074 @BeanReference(type = BrowserTrackerPersistence.class)
1075 protected BrowserTrackerPersistence browserTrackerPersistence;
1076 @BeanReference(type = ClassNamePersistence.class)
1077 protected ClassNamePersistence classNamePersistence;
1078 @BeanReference(type = ClusterGroupPersistence.class)
1079 protected ClusterGroupPersistence clusterGroupPersistence;
1080 @BeanReference(type = CompanyPersistence.class)
1081 protected CompanyPersistence companyPersistence;
1082 @BeanReference(type = ContactPersistence.class)
1083 protected ContactPersistence contactPersistence;
1084 @BeanReference(type = CountryPersistence.class)
1085 protected CountryPersistence countryPersistence;
1086 @BeanReference(type = EmailAddressPersistence.class)
1087 protected EmailAddressPersistence emailAddressPersistence;
1088 @BeanReference(type = GroupPersistence.class)
1089 protected GroupPersistence groupPersistence;
1090 @BeanReference(type = ImagePersistence.class)
1091 protected ImagePersistence imagePersistence;
1092 @BeanReference(type = LayoutPersistence.class)
1093 protected LayoutPersistence layoutPersistence;
1094 @BeanReference(type = LayoutBranchPersistence.class)
1095 protected LayoutBranchPersistence layoutBranchPersistence;
1096 @BeanReference(type = LayoutPrototypePersistence.class)
1097 protected LayoutPrototypePersistence layoutPrototypePersistence;
1098 @BeanReference(type = LayoutRevisionPersistence.class)
1099 protected LayoutRevisionPersistence layoutRevisionPersistence;
1100 @BeanReference(type = LayoutSetPersistence.class)
1101 protected LayoutSetPersistence layoutSetPersistence;
1102 @BeanReference(type = LayoutSetBranchPersistence.class)
1103 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1104 @BeanReference(type = LayoutSetPrototypePersistence.class)
1105 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1106 @BeanReference(type = ListTypePersistence.class)
1107 protected ListTypePersistence listTypePersistence;
1108 @BeanReference(type = LockPersistence.class)
1109 protected LockPersistence lockPersistence;
1110 @BeanReference(type = MembershipRequestPersistence.class)
1111 protected MembershipRequestPersistence membershipRequestPersistence;
1112 @BeanReference(type = OrganizationPersistence.class)
1113 protected OrganizationPersistence organizationPersistence;
1114 @BeanReference(type = OrgGroupPermissionPersistence.class)
1115 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1116 @BeanReference(type = OrgGroupRolePersistence.class)
1117 protected OrgGroupRolePersistence orgGroupRolePersistence;
1118 @BeanReference(type = OrgLaborPersistence.class)
1119 protected OrgLaborPersistence orgLaborPersistence;
1120 @BeanReference(type = PasswordPolicyPersistence.class)
1121 protected PasswordPolicyPersistence passwordPolicyPersistence;
1122 @BeanReference(type = PasswordPolicyRelPersistence.class)
1123 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1124 @BeanReference(type = PasswordTrackerPersistence.class)
1125 protected PasswordTrackerPersistence passwordTrackerPersistence;
1126 @BeanReference(type = PermissionPersistence.class)
1127 protected PermissionPersistence permissionPersistence;
1128 @BeanReference(type = PhonePersistence.class)
1129 protected PhonePersistence phonePersistence;
1130 @BeanReference(type = PluginSettingPersistence.class)
1131 protected PluginSettingPersistence pluginSettingPersistence;
1132 @BeanReference(type = PortalPreferencesPersistence.class)
1133 protected PortalPreferencesPersistence portalPreferencesPersistence;
1134 @BeanReference(type = PortletPersistence.class)
1135 protected PortletPersistence portletPersistence;
1136 @BeanReference(type = PortletItemPersistence.class)
1137 protected PortletItemPersistence portletItemPersistence;
1138 @BeanReference(type = PortletPreferencesPersistence.class)
1139 protected PortletPreferencesPersistence portletPreferencesPersistence;
1140 @BeanReference(type = RegionPersistence.class)
1141 protected RegionPersistence regionPersistence;
1142 @BeanReference(type = ReleasePersistence.class)
1143 protected ReleasePersistence releasePersistence;
1144 @BeanReference(type = RepositoryPersistence.class)
1145 protected RepositoryPersistence repositoryPersistence;
1146 @BeanReference(type = RepositoryEntryPersistence.class)
1147 protected RepositoryEntryPersistence repositoryEntryPersistence;
1148 @BeanReference(type = ResourcePersistence.class)
1149 protected ResourcePersistence resourcePersistence;
1150 @BeanReference(type = ResourceActionPersistence.class)
1151 protected ResourceActionPersistence resourceActionPersistence;
1152 @BeanReference(type = ResourceBlockPersistence.class)
1153 protected ResourceBlockPersistence resourceBlockPersistence;
1154 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1155 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1156 @BeanReference(type = ResourceCodePersistence.class)
1157 protected ResourceCodePersistence resourceCodePersistence;
1158 @BeanReference(type = ResourcePermissionPersistence.class)
1159 protected ResourcePermissionPersistence resourcePermissionPersistence;
1160 @BeanReference(type = ResourceTypePermissionPersistence.class)
1161 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1162 @BeanReference(type = RolePersistence.class)
1163 protected RolePersistence rolePersistence;
1164 @BeanReference(type = ServiceComponentPersistence.class)
1165 protected ServiceComponentPersistence serviceComponentPersistence;
1166 @BeanReference(type = ShardPersistence.class)
1167 protected ShardPersistence shardPersistence;
1168 @BeanReference(type = SubscriptionPersistence.class)
1169 protected SubscriptionPersistence subscriptionPersistence;
1170 @BeanReference(type = TeamPersistence.class)
1171 protected TeamPersistence teamPersistence;
1172 @BeanReference(type = TicketPersistence.class)
1173 protected TicketPersistence ticketPersistence;
1174 @BeanReference(type = UserPersistence.class)
1175 protected UserPersistence userPersistence;
1176 @BeanReference(type = UserGroupPersistence.class)
1177 protected UserGroupPersistence userGroupPersistence;
1178 @BeanReference(type = UserGroupGroupRolePersistence.class)
1179 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1180 @BeanReference(type = UserGroupRolePersistence.class)
1181 protected UserGroupRolePersistence userGroupRolePersistence;
1182 @BeanReference(type = UserIdMapperPersistence.class)
1183 protected UserIdMapperPersistence userIdMapperPersistence;
1184 @BeanReference(type = UserNotificationEventPersistence.class)
1185 protected UserNotificationEventPersistence userNotificationEventPersistence;
1186 @BeanReference(type = UserTrackerPersistence.class)
1187 protected UserTrackerPersistence userTrackerPersistence;
1188 @BeanReference(type = UserTrackerPathPersistence.class)
1189 protected UserTrackerPathPersistence userTrackerPathPersistence;
1190 @BeanReference(type = VirtualHostPersistence.class)
1191 protected VirtualHostPersistence virtualHostPersistence;
1192 @BeanReference(type = WebDAVPropsPersistence.class)
1193 protected WebDAVPropsPersistence webDAVPropsPersistence;
1194 @BeanReference(type = WebsitePersistence.class)
1195 protected WebsitePersistence websitePersistence;
1196 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1197 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1198 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1199 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1200 private static final String _SQL_SELECT_CONTACT = "SELECT contact FROM Contact contact";
1201 private static final String _SQL_SELECT_CONTACT_WHERE = "SELECT contact FROM Contact contact WHERE ";
1202 private static final String _SQL_COUNT_CONTACT = "SELECT COUNT(contact) FROM Contact contact";
1203 private static final String _SQL_COUNT_CONTACT_WHERE = "SELECT COUNT(contact) FROM Contact contact WHERE ";
1204 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "contact.companyId = ?";
1205 private static final String _ORDER_BY_ENTITY_ALIAS = "contact.";
1206 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Contact exists with the primary key ";
1207 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Contact exists with the key {";
1208 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1209 private static Log _log = LogFactoryUtil.getLog(ContactPersistenceImpl.class);
1210 private static Contact _nullContact = new ContactImpl() {
1211 @Override
1212 public Object clone() {
1213 return this;
1214 }
1215
1216 @Override
1217 public CacheModel<Contact> toCacheModel() {
1218 return _nullContactCacheModel;
1219 }
1220 };
1221
1222 private static CacheModel<Contact> _nullContactCacheModel = new CacheModel<Contact>() {
1223 public Contact toEntityModel() {
1224 return _nullContact;
1225 }
1226 };
1227 }