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