1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchContactException;
26  import com.liferay.portal.NoSuchModelException;
27  import com.liferay.portal.SystemException;
28  import com.liferay.portal.kernel.annotation.BeanReference;
29  import com.liferay.portal.kernel.cache.CacheRegistry;
30  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
31  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
32  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
33  import com.liferay.portal.kernel.dao.orm.FinderPath;
34  import com.liferay.portal.kernel.dao.orm.Query;
35  import com.liferay.portal.kernel.dao.orm.QueryPos;
36  import com.liferay.portal.kernel.dao.orm.QueryUtil;
37  import com.liferay.portal.kernel.dao.orm.Session;
38  import com.liferay.portal.kernel.log.Log;
39  import com.liferay.portal.kernel.log.LogFactoryUtil;
40  import com.liferay.portal.kernel.util.GetterUtil;
41  import com.liferay.portal.kernel.util.OrderByComparator;
42  import com.liferay.portal.kernel.util.StringBundler;
43  import com.liferay.portal.kernel.util.StringPool;
44  import com.liferay.portal.kernel.util.StringUtil;
45  import com.liferay.portal.model.Contact;
46  import com.liferay.portal.model.ModelListener;
47  import com.liferay.portal.model.impl.ContactImpl;
48  import com.liferay.portal.model.impl.ContactModelImpl;
49  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
50  
51  import java.io.Serializable;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.List;
56  
57  /**
58   * <a href="ContactPersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * <p>
61   * ServiceBuilder generated this class. Modifications in this class will be
62   * overwritten the next time is generated.
63   * </p>
64   *
65   * @author    Brian Wing Shun Chan
66   * @see       ContactPersistence
67   * @see       ContactUtil
68   * @generated
69   */
70  public class ContactPersistenceImpl extends BasePersistenceImpl<Contact>
71      implements ContactPersistence {
72      public static final String FINDER_CLASS_NAME_ENTITY = ContactImpl.class.getName();
73      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
74          ".List";
75      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
76              ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
77              "findByCompanyId", new String[] { Long.class.getName() });
78      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
79              ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
80              "findByCompanyId",
81              new String[] {
82                  Long.class.getName(),
83                  
84              "java.lang.Integer", "java.lang.Integer",
85                  "com.liferay.portal.kernel.util.OrderByComparator"
86              });
87      public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
88              ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89              "countByCompanyId", new String[] { Long.class.getName() });
90      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
91              ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
92              "findAll", new String[0]);
93      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
94              ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
95              "countAll", new String[0]);
96  
97      public void cacheResult(Contact contact) {
98          EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
99              ContactImpl.class, contact.getPrimaryKey(), contact);
100     }
101 
102     public void cacheResult(List<Contact> contacts) {
103         for (Contact contact : contacts) {
104             if (EntityCacheUtil.getResult(
105                         ContactModelImpl.ENTITY_CACHE_ENABLED,
106                         ContactImpl.class, contact.getPrimaryKey(), this) == null) {
107                 cacheResult(contact);
108             }
109         }
110     }
111 
112     public void clearCache() {
113         CacheRegistry.clear(ContactImpl.class.getName());
114         EntityCacheUtil.clearCache(ContactImpl.class.getName());
115         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
116         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
117     }
118 
119     public Contact create(long contactId) {
120         Contact contact = new ContactImpl();
121 
122         contact.setNew(true);
123         contact.setPrimaryKey(contactId);
124 
125         return contact;
126     }
127 
128     public Contact remove(Serializable primaryKey)
129         throws NoSuchModelException, SystemException {
130         return remove(((Long)primaryKey).longValue());
131     }
132 
133     public Contact remove(long contactId)
134         throws NoSuchContactException, SystemException {
135         Session session = null;
136 
137         try {
138             session = openSession();
139 
140             Contact contact = (Contact)session.get(ContactImpl.class,
141                     new Long(contactId));
142 
143             if (contact == null) {
144                 if (_log.isWarnEnabled()) {
145                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
146                 }
147 
148                 throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
149                     contactId);
150             }
151 
152             return remove(contact);
153         }
154         catch (NoSuchContactException nsee) {
155             throw nsee;
156         }
157         catch (Exception e) {
158             throw processException(e);
159         }
160         finally {
161             closeSession(session);
162         }
163     }
164 
165     public Contact remove(Contact contact) throws SystemException {
166         for (ModelListener<Contact> listener : listeners) {
167             listener.onBeforeRemove(contact);
168         }
169 
170         contact = removeImpl(contact);
171 
172         for (ModelListener<Contact> listener : listeners) {
173             listener.onAfterRemove(contact);
174         }
175 
176         return contact;
177     }
178 
179     protected Contact removeImpl(Contact contact) throws SystemException {
180         contact = toUnwrappedModel(contact);
181 
182         Session session = null;
183 
184         try {
185             session = openSession();
186 
187             if (contact.isCachedModel() || BatchSessionUtil.isEnabled()) {
188                 Object staleObject = session.get(ContactImpl.class,
189                         contact.getPrimaryKeyObj());
190 
191                 if (staleObject != null) {
192                     session.evict(staleObject);
193                 }
194             }
195 
196             session.delete(contact);
197 
198             session.flush();
199         }
200         catch (Exception e) {
201             throw processException(e);
202         }
203         finally {
204             closeSession(session);
205         }
206 
207         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
208 
209         EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
210             ContactImpl.class, contact.getPrimaryKey());
211 
212         return contact;
213     }
214 
215     /**
216      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
217      */
218     public Contact update(Contact contact) throws SystemException {
219         if (_log.isWarnEnabled()) {
220             _log.warn(
221                 "Using the deprecated update(Contact contact) method. Use update(Contact contact, boolean merge) instead.");
222         }
223 
224         return update(contact, false);
225     }
226 
227     public Contact updateImpl(com.liferay.portal.model.Contact contact,
228         boolean merge) throws SystemException {
229         contact = toUnwrappedModel(contact);
230 
231         Session session = null;
232 
233         try {
234             session = openSession();
235 
236             BatchSessionUtil.update(session, contact, merge);
237 
238             contact.setNew(false);
239         }
240         catch (Exception e) {
241             throw processException(e);
242         }
243         finally {
244             closeSession(session);
245         }
246 
247         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
248 
249         EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
250             ContactImpl.class, contact.getPrimaryKey(), contact);
251 
252         return contact;
253     }
254 
255     protected Contact toUnwrappedModel(Contact contact) {
256         if (contact instanceof ContactImpl) {
257             return contact;
258         }
259 
260         ContactImpl contactImpl = new ContactImpl();
261 
262         contactImpl.setNew(contact.isNew());
263         contactImpl.setPrimaryKey(contact.getPrimaryKey());
264 
265         contactImpl.setContactId(contact.getContactId());
266         contactImpl.setCompanyId(contact.getCompanyId());
267         contactImpl.setUserId(contact.getUserId());
268         contactImpl.setUserName(contact.getUserName());
269         contactImpl.setCreateDate(contact.getCreateDate());
270         contactImpl.setModifiedDate(contact.getModifiedDate());
271         contactImpl.setAccountId(contact.getAccountId());
272         contactImpl.setParentContactId(contact.getParentContactId());
273         contactImpl.setFirstName(contact.getFirstName());
274         contactImpl.setMiddleName(contact.getMiddleName());
275         contactImpl.setLastName(contact.getLastName());
276         contactImpl.setPrefixId(contact.getPrefixId());
277         contactImpl.setSuffixId(contact.getSuffixId());
278         contactImpl.setMale(contact.isMale());
279         contactImpl.setBirthday(contact.getBirthday());
280         contactImpl.setSmsSn(contact.getSmsSn());
281         contactImpl.setAimSn(contact.getAimSn());
282         contactImpl.setFacebookSn(contact.getFacebookSn());
283         contactImpl.setIcqSn(contact.getIcqSn());
284         contactImpl.setJabberSn(contact.getJabberSn());
285         contactImpl.setMsnSn(contact.getMsnSn());
286         contactImpl.setMySpaceSn(contact.getMySpaceSn());
287         contactImpl.setSkypeSn(contact.getSkypeSn());
288         contactImpl.setTwitterSn(contact.getTwitterSn());
289         contactImpl.setYmSn(contact.getYmSn());
290         contactImpl.setEmployeeStatusId(contact.getEmployeeStatusId());
291         contactImpl.setEmployeeNumber(contact.getEmployeeNumber());
292         contactImpl.setJobTitle(contact.getJobTitle());
293         contactImpl.setJobClass(contact.getJobClass());
294         contactImpl.setHoursOfOperation(contact.getHoursOfOperation());
295 
296         return contactImpl;
297     }
298 
299     public Contact findByPrimaryKey(Serializable primaryKey)
300         throws NoSuchModelException, SystemException {
301         return findByPrimaryKey(((Long)primaryKey).longValue());
302     }
303 
304     public Contact findByPrimaryKey(long contactId)
305         throws NoSuchContactException, SystemException {
306         Contact contact = fetchByPrimaryKey(contactId);
307 
308         if (contact == null) {
309             if (_log.isWarnEnabled()) {
310                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
311             }
312 
313             throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
314                 contactId);
315         }
316 
317         return contact;
318     }
319 
320     public Contact fetchByPrimaryKey(Serializable primaryKey)
321         throws SystemException {
322         return fetchByPrimaryKey(((Long)primaryKey).longValue());
323     }
324 
325     public Contact fetchByPrimaryKey(long contactId) throws SystemException {
326         Contact contact = (Contact)EntityCacheUtil.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
327                 ContactImpl.class, contactId, this);
328 
329         if (contact == null) {
330             Session session = null;
331 
332             try {
333                 session = openSession();
334 
335                 contact = (Contact)session.get(ContactImpl.class,
336                         new Long(contactId));
337             }
338             catch (Exception e) {
339                 throw processException(e);
340             }
341             finally {
342                 if (contact != null) {
343                     cacheResult(contact);
344                 }
345 
346                 closeSession(session);
347             }
348         }
349 
350         return contact;
351     }
352 
353     public List<Contact> findByCompanyId(long companyId)
354         throws SystemException {
355         Object[] finderArgs = new Object[] { new Long(companyId) };
356 
357         List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
358                 finderArgs, this);
359 
360         if (list == null) {
361             Session session = null;
362 
363             try {
364                 session = openSession();
365 
366                 StringBundler query = new StringBundler(2);
367 
368                 query.append(_SQL_SELECT_CONTACT_WHERE);
369 
370                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
371 
372                 String sql = query.toString();
373 
374                 Query q = session.createQuery(sql);
375 
376                 QueryPos qPos = QueryPos.getInstance(q);
377 
378                 qPos.add(companyId);
379 
380                 list = q.list();
381             }
382             catch (Exception e) {
383                 throw processException(e);
384             }
385             finally {
386                 if (list == null) {
387                     list = new ArrayList<Contact>();
388                 }
389 
390                 cacheResult(list);
391 
392                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
393                     finderArgs, list);
394 
395                 closeSession(session);
396             }
397         }
398 
399         return list;
400     }
401 
402     public List<Contact> findByCompanyId(long companyId, int start, int end)
403         throws SystemException {
404         return findByCompanyId(companyId, start, end, null);
405     }
406 
407     public List<Contact> findByCompanyId(long companyId, int start, int end,
408         OrderByComparator obc) throws SystemException {
409         Object[] finderArgs = new Object[] {
410                 new Long(companyId),
411                 
412                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
413             };
414 
415         List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
416                 finderArgs, this);
417 
418         if (list == null) {
419             Session session = null;
420 
421             try {
422                 session = openSession();
423 
424                 StringBundler query = null;
425 
426                 if (obc != null) {
427                     query = new StringBundler(3 +
428                             (obc.getOrderByFields().length * 3));
429                 }
430                 else {
431                     query = new StringBundler(2);
432                 }
433 
434                 query.append(_SQL_SELECT_CONTACT_WHERE);
435 
436                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
437 
438                 if (obc != null) {
439                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
440                 }
441 
442                 String sql = query.toString();
443 
444                 Query q = session.createQuery(sql);
445 
446                 QueryPos qPos = QueryPos.getInstance(q);
447 
448                 qPos.add(companyId);
449 
450                 list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
451             }
452             catch (Exception e) {
453                 throw processException(e);
454             }
455             finally {
456                 if (list == null) {
457                     list = new ArrayList<Contact>();
458                 }
459 
460                 cacheResult(list);
461 
462                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
463                     finderArgs, list);
464 
465                 closeSession(session);
466             }
467         }
468 
469         return list;
470     }
471 
472     public Contact findByCompanyId_First(long companyId, OrderByComparator obc)
473         throws NoSuchContactException, SystemException {
474         List<Contact> list = findByCompanyId(companyId, 0, 1, obc);
475 
476         if (list.isEmpty()) {
477             StringBundler msg = new StringBundler(4);
478 
479             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
480 
481             msg.append("companyId=");
482             msg.append(companyId);
483 
484             msg.append(StringPool.CLOSE_CURLY_BRACE);
485 
486             throw new NoSuchContactException(msg.toString());
487         }
488         else {
489             return list.get(0);
490         }
491     }
492 
493     public Contact findByCompanyId_Last(long companyId, OrderByComparator obc)
494         throws NoSuchContactException, SystemException {
495         int count = countByCompanyId(companyId);
496 
497         List<Contact> list = findByCompanyId(companyId, count - 1, count, obc);
498 
499         if (list.isEmpty()) {
500             StringBundler msg = new StringBundler(4);
501 
502             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
503 
504             msg.append("companyId=");
505             msg.append(companyId);
506 
507             msg.append(StringPool.CLOSE_CURLY_BRACE);
508 
509             throw new NoSuchContactException(msg.toString());
510         }
511         else {
512             return list.get(0);
513         }
514     }
515 
516     public Contact[] findByCompanyId_PrevAndNext(long contactId,
517         long companyId, OrderByComparator obc)
518         throws NoSuchContactException, SystemException {
519         Contact contact = findByPrimaryKey(contactId);
520 
521         int count = countByCompanyId(companyId);
522 
523         Session session = null;
524 
525         try {
526             session = openSession();
527 
528             StringBundler query = null;
529 
530             if (obc != null) {
531                 query = new StringBundler(3 +
532                         (obc.getOrderByFields().length * 3));
533             }
534             else {
535                 query = new StringBundler(2);
536             }
537 
538             query.append(_SQL_SELECT_CONTACT_WHERE);
539 
540             query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
541 
542             if (obc != null) {
543                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
544             }
545 
546             String sql = query.toString();
547 
548             Query q = session.createQuery(sql);
549 
550             QueryPos qPos = QueryPos.getInstance(q);
551 
552             qPos.add(companyId);
553 
554             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, contact);
555 
556             Contact[] array = new ContactImpl[3];
557 
558             array[0] = (Contact)objArray[0];
559             array[1] = (Contact)objArray[1];
560             array[2] = (Contact)objArray[2];
561 
562             return array;
563         }
564         catch (Exception e) {
565             throw processException(e);
566         }
567         finally {
568             closeSession(session);
569         }
570     }
571 
572     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
573         throws SystemException {
574         Session session = null;
575 
576         try {
577             session = openSession();
578 
579             dynamicQuery.compile(session);
580 
581             return dynamicQuery.list();
582         }
583         catch (Exception e) {
584             throw processException(e);
585         }
586         finally {
587             closeSession(session);
588         }
589     }
590 
591     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
592         int start, int end) throws SystemException {
593         Session session = null;
594 
595         try {
596             session = openSession();
597 
598             dynamicQuery.setLimit(start, end);
599 
600             dynamicQuery.compile(session);
601 
602             return dynamicQuery.list();
603         }
604         catch (Exception e) {
605             throw processException(e);
606         }
607         finally {
608             closeSession(session);
609         }
610     }
611 
612     public List<Contact> findAll() throws SystemException {
613         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
614     }
615 
616     public List<Contact> findAll(int start, int end) throws SystemException {
617         return findAll(start, end, null);
618     }
619 
620     public List<Contact> findAll(int start, int end, OrderByComparator obc)
621         throws SystemException {
622         Object[] finderArgs = new Object[] {
623                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
624             };
625 
626         List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
627                 finderArgs, this);
628 
629         if (list == null) {
630             Session session = null;
631 
632             try {
633                 session = openSession();
634 
635                 StringBundler query = null;
636                 String sql = null;
637 
638                 if (obc != null) {
639                     query = new StringBundler(2 +
640                             (obc.getOrderByFields().length * 3));
641 
642                     query.append(_SQL_SELECT_CONTACT);
643 
644                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
645 
646                     sql = query.toString();
647                 }
648 
649                 sql = _SQL_SELECT_CONTACT;
650 
651                 Query q = session.createQuery(sql);
652 
653                 if (obc == null) {
654                     list = (List<Contact>)QueryUtil.list(q, getDialect(),
655                             start, end, false);
656 
657                     Collections.sort(list);
658                 }
659                 else {
660                     list = (List<Contact>)QueryUtil.list(q, getDialect(),
661                             start, end);
662                 }
663             }
664             catch (Exception e) {
665                 throw processException(e);
666             }
667             finally {
668                 if (list == null) {
669                     list = new ArrayList<Contact>();
670                 }
671 
672                 cacheResult(list);
673 
674                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
675 
676                 closeSession(session);
677             }
678         }
679 
680         return list;
681     }
682 
683     public void removeByCompanyId(long companyId) throws SystemException {
684         for (Contact contact : findByCompanyId(companyId)) {
685             remove(contact);
686         }
687     }
688 
689     public void removeAll() throws SystemException {
690         for (Contact contact : findAll()) {
691             remove(contact);
692         }
693     }
694 
695     public int countByCompanyId(long companyId) throws SystemException {
696         Object[] finderArgs = new Object[] { new Long(companyId) };
697 
698         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
699                 finderArgs, this);
700 
701         if (count == null) {
702             Session session = null;
703 
704             try {
705                 session = openSession();
706 
707                 StringBundler query = new StringBundler(2);
708 
709                 query.append(_SQL_COUNT_CONTACT_WHERE);
710 
711                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
712 
713                 String sql = query.toString();
714 
715                 Query q = session.createQuery(sql);
716 
717                 QueryPos qPos = QueryPos.getInstance(q);
718 
719                 qPos.add(companyId);
720 
721                 count = (Long)q.uniqueResult();
722             }
723             catch (Exception e) {
724                 throw processException(e);
725             }
726             finally {
727                 if (count == null) {
728                     count = Long.valueOf(0);
729                 }
730 
731                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
732                     finderArgs, count);
733 
734                 closeSession(session);
735             }
736         }
737 
738         return count.intValue();
739     }
740 
741     public int countAll() throws SystemException {
742         Object[] finderArgs = new Object[0];
743 
744         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
745                 finderArgs, this);
746 
747         if (count == null) {
748             Session session = null;
749 
750             try {
751                 session = openSession();
752 
753                 Query q = session.createQuery(_SQL_COUNT_CONTACT);
754 
755                 count = (Long)q.uniqueResult();
756             }
757             catch (Exception e) {
758                 throw processException(e);
759             }
760             finally {
761                 if (count == null) {
762                     count = Long.valueOf(0);
763                 }
764 
765                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
766                     count);
767 
768                 closeSession(session);
769             }
770         }
771 
772         return count.intValue();
773     }
774 
775     public void afterPropertiesSet() {
776         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
777                     com.liferay.portal.util.PropsUtil.get(
778                         "value.object.listener.com.liferay.portal.model.Contact")));
779 
780         if (listenerClassNames.length > 0) {
781             try {
782                 List<ModelListener<Contact>> listenersList = new ArrayList<ModelListener<Contact>>();
783 
784                 for (String listenerClassName : listenerClassNames) {
785                     listenersList.add((ModelListener<Contact>)Class.forName(
786                             listenerClassName).newInstance());
787                 }
788 
789                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
790             }
791             catch (Exception e) {
792                 _log.error(e);
793             }
794         }
795     }
796 
797     @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
798     protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
799     @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
800     protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
801     @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
802     protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
803     @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
804     protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
805     @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
806     protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
807     @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
808     protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
809     @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
810     protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
811     @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
812     protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
813     @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
814     protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
815     @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
816     protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
817     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
818     protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
819     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
820     protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
821     @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
822     protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
823     @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
824     protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
825     @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
826     protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
827     @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
828     protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
829     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
830     protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
831     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
832     protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
833     @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
834     protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
835     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
836     protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
837     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
838     protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
839     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
840     protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
841     @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
842     protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
843     @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
844     protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
845     @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
846     protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
847     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
848     protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
849     @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
850     protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
851     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
852     protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
853     @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
854     protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
855     @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
856     protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
857     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
858     protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
859     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
860     protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
861     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
862     protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
863     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
864     protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
865     @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
866     protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
867     @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
868     protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
869     @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
870     protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
871     @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
872     protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
873     @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
874     protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
875     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
876     protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
877     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence")
878     protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
879     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
880     protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
881     @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
882     protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
883     @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
884     protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
885     @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
886     protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
887     @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
888     protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
889     @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
890     protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
891     private static final String _SQL_SELECT_CONTACT = "SELECT contact FROM Contact contact";
892     private static final String _SQL_SELECT_CONTACT_WHERE = "SELECT contact FROM Contact contact WHERE ";
893     private static final String _SQL_COUNT_CONTACT = "SELECT COUNT(contact) FROM Contact contact";
894     private static final String _SQL_COUNT_CONTACT_WHERE = "SELECT COUNT(contact) FROM Contact contact WHERE ";
895     private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "contact.companyId = ?";
896     private static final String _ORDER_BY_ENTITY_ALIAS = "contact.";
897     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Contact exists with the primary key ";
898     private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Contact exists with the key {";
899     private static Log _log = LogFactoryUtil.getLog(ContactPersistenceImpl.class);
900 }