001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.annotation.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.Contact;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.impl.ContactImpl;
040    import com.liferay.portal.model.impl.ContactModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * @author    Brian Wing Shun Chan
051     * @see       ContactPersistence
052     * @see       ContactUtil
053     * @generated
054     */
055    public class ContactPersistenceImpl extends BasePersistenceImpl<Contact>
056            implements ContactPersistence {
057            public static final String FINDER_CLASS_NAME_ENTITY = ContactImpl.class.getName();
058            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
059                    ".List";
060            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
061                            ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
062                            "findByCompanyId",
063                            new String[] {
064                                    Long.class.getName(),
065                                    
066                            "java.lang.Integer", "java.lang.Integer",
067                                    "com.liferay.portal.kernel.util.OrderByComparator"
068                            });
069            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
070                            ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
071                            "countByCompanyId", new String[] { Long.class.getName() });
072            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
073                            ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
074                            "findAll", new String[0]);
075            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
076                            ContactModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
077                            "countAll", new String[0]);
078    
079            public void cacheResult(Contact contact) {
080                    EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
081                            ContactImpl.class, contact.getPrimaryKey(), contact);
082            }
083    
084            public void cacheResult(List<Contact> contacts) {
085                    for (Contact contact : contacts) {
086                            if (EntityCacheUtil.getResult(
087                                                    ContactModelImpl.ENTITY_CACHE_ENABLED,
088                                                    ContactImpl.class, contact.getPrimaryKey(), this) == null) {
089                                    cacheResult(contact);
090                            }
091                    }
092            }
093    
094            public void clearCache() {
095                    CacheRegistryUtil.clear(ContactImpl.class.getName());
096                    EntityCacheUtil.clearCache(ContactImpl.class.getName());
097                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
098                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
099            }
100    
101            public void clearCache(Contact contact) {
102                    EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
103                            ContactImpl.class, contact.getPrimaryKey());
104            }
105    
106            public Contact create(long contactId) {
107                    Contact contact = new ContactImpl();
108    
109                    contact.setNew(true);
110                    contact.setPrimaryKey(contactId);
111    
112                    return contact;
113            }
114    
115            public Contact remove(Serializable primaryKey)
116                    throws NoSuchModelException, SystemException {
117                    return remove(((Long)primaryKey).longValue());
118            }
119    
120            public Contact remove(long contactId)
121                    throws NoSuchContactException, SystemException {
122                    Session session = null;
123    
124                    try {
125                            session = openSession();
126    
127                            Contact contact = (Contact)session.get(ContactImpl.class,
128                                            new Long(contactId));
129    
130                            if (contact == null) {
131                                    if (_log.isWarnEnabled()) {
132                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
133                                    }
134    
135                                    throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
136                                            contactId);
137                            }
138    
139                            return remove(contact);
140                    }
141                    catch (NoSuchContactException nsee) {
142                            throw nsee;
143                    }
144                    catch (Exception e) {
145                            throw processException(e);
146                    }
147                    finally {
148                            closeSession(session);
149                    }
150            }
151    
152            protected Contact removeImpl(Contact contact) throws SystemException {
153                    contact = toUnwrappedModel(contact);
154    
155                    Session session = null;
156    
157                    try {
158                            session = openSession();
159    
160                            if (contact.isCachedModel() || BatchSessionUtil.isEnabled()) {
161                                    Object staleObject = session.get(ContactImpl.class,
162                                                    contact.getPrimaryKeyObj());
163    
164                                    if (staleObject != null) {
165                                            session.evict(staleObject);
166                                    }
167                            }
168    
169                            session.delete(contact);
170    
171                            session.flush();
172                    }
173                    catch (Exception e) {
174                            throw processException(e);
175                    }
176                    finally {
177                            closeSession(session);
178                    }
179    
180                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
181    
182                    EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
183                            ContactImpl.class, contact.getPrimaryKey());
184    
185                    return contact;
186            }
187    
188            public Contact updateImpl(com.liferay.portal.model.Contact contact,
189                    boolean merge) throws SystemException {
190                    contact = toUnwrappedModel(contact);
191    
192                    Session session = null;
193    
194                    try {
195                            session = openSession();
196    
197                            BatchSessionUtil.update(session, contact, merge);
198    
199                            contact.setNew(false);
200                    }
201                    catch (Exception e) {
202                            throw processException(e);
203                    }
204                    finally {
205                            closeSession(session);
206                    }
207    
208                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
209    
210                    EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
211                            ContactImpl.class, contact.getPrimaryKey(), contact);
212    
213                    return contact;
214            }
215    
216            protected Contact toUnwrappedModel(Contact contact) {
217                    if (contact instanceof ContactImpl) {
218                            return contact;
219                    }
220    
221                    ContactImpl contactImpl = new ContactImpl();
222    
223                    contactImpl.setNew(contact.isNew());
224                    contactImpl.setPrimaryKey(contact.getPrimaryKey());
225    
226                    contactImpl.setContactId(contact.getContactId());
227                    contactImpl.setCompanyId(contact.getCompanyId());
228                    contactImpl.setUserId(contact.getUserId());
229                    contactImpl.setUserName(contact.getUserName());
230                    contactImpl.setCreateDate(contact.getCreateDate());
231                    contactImpl.setModifiedDate(contact.getModifiedDate());
232                    contactImpl.setAccountId(contact.getAccountId());
233                    contactImpl.setParentContactId(contact.getParentContactId());
234                    contactImpl.setFirstName(contact.getFirstName());
235                    contactImpl.setMiddleName(contact.getMiddleName());
236                    contactImpl.setLastName(contact.getLastName());
237                    contactImpl.setPrefixId(contact.getPrefixId());
238                    contactImpl.setSuffixId(contact.getSuffixId());
239                    contactImpl.setMale(contact.isMale());
240                    contactImpl.setBirthday(contact.getBirthday());
241                    contactImpl.setSmsSn(contact.getSmsSn());
242                    contactImpl.setAimSn(contact.getAimSn());
243                    contactImpl.setFacebookSn(contact.getFacebookSn());
244                    contactImpl.setIcqSn(contact.getIcqSn());
245                    contactImpl.setJabberSn(contact.getJabberSn());
246                    contactImpl.setMsnSn(contact.getMsnSn());
247                    contactImpl.setMySpaceSn(contact.getMySpaceSn());
248                    contactImpl.setSkypeSn(contact.getSkypeSn());
249                    contactImpl.setTwitterSn(contact.getTwitterSn());
250                    contactImpl.setYmSn(contact.getYmSn());
251                    contactImpl.setEmployeeStatusId(contact.getEmployeeStatusId());
252                    contactImpl.setEmployeeNumber(contact.getEmployeeNumber());
253                    contactImpl.setJobTitle(contact.getJobTitle());
254                    contactImpl.setJobClass(contact.getJobClass());
255                    contactImpl.setHoursOfOperation(contact.getHoursOfOperation());
256    
257                    return contactImpl;
258            }
259    
260            public Contact findByPrimaryKey(Serializable primaryKey)
261                    throws NoSuchModelException, SystemException {
262                    return findByPrimaryKey(((Long)primaryKey).longValue());
263            }
264    
265            public Contact findByPrimaryKey(long contactId)
266                    throws NoSuchContactException, SystemException {
267                    Contact contact = fetchByPrimaryKey(contactId);
268    
269                    if (contact == null) {
270                            if (_log.isWarnEnabled()) {
271                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
272                            }
273    
274                            throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
275                                    contactId);
276                    }
277    
278                    return contact;
279            }
280    
281            public Contact fetchByPrimaryKey(Serializable primaryKey)
282                    throws SystemException {
283                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
284            }
285    
286            public Contact fetchByPrimaryKey(long contactId) throws SystemException {
287                    Contact contact = (Contact)EntityCacheUtil.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
288                                    ContactImpl.class, contactId, this);
289    
290                    if (contact == null) {
291                            Session session = null;
292    
293                            try {
294                                    session = openSession();
295    
296                                    contact = (Contact)session.get(ContactImpl.class,
297                                                    new Long(contactId));
298                            }
299                            catch (Exception e) {
300                                    throw processException(e);
301                            }
302                            finally {
303                                    if (contact != null) {
304                                            cacheResult(contact);
305                                    }
306    
307                                    closeSession(session);
308                            }
309                    }
310    
311                    return contact;
312            }
313    
314            public List<Contact> findByCompanyId(long companyId)
315                    throws SystemException {
316                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
317                            null);
318            }
319    
320            public List<Contact> findByCompanyId(long companyId, int start, int end)
321                    throws SystemException {
322                    return findByCompanyId(companyId, start, end, null);
323            }
324    
325            public List<Contact> findByCompanyId(long companyId, int start, int end,
326                    OrderByComparator orderByComparator) throws SystemException {
327                    Object[] finderArgs = new Object[] {
328                                    companyId,
329                                    
330                                    String.valueOf(start), String.valueOf(end),
331                                    String.valueOf(orderByComparator)
332                            };
333    
334                    List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
335                                    finderArgs, this);
336    
337                    if (list == null) {
338                            Session session = null;
339    
340                            try {
341                                    session = openSession();
342    
343                                    StringBundler query = null;
344    
345                                    if (orderByComparator != null) {
346                                            query = new StringBundler(3 +
347                                                            (orderByComparator.getOrderByFields().length * 3));
348                                    }
349                                    else {
350                                            query = new StringBundler(2);
351                                    }
352    
353                                    query.append(_SQL_SELECT_CONTACT_WHERE);
354    
355                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
356    
357                                    if (orderByComparator != null) {
358                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
359                                                    orderByComparator);
360                                    }
361    
362                                    String sql = query.toString();
363    
364                                    Query q = session.createQuery(sql);
365    
366                                    QueryPos qPos = QueryPos.getInstance(q);
367    
368                                    qPos.add(companyId);
369    
370                                    list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
371                            }
372                            catch (Exception e) {
373                                    throw processException(e);
374                            }
375                            finally {
376                                    if (list == null) {
377                                            list = new ArrayList<Contact>();
378                                    }
379    
380                                    cacheResult(list);
381    
382                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
383                                            finderArgs, list);
384    
385                                    closeSession(session);
386                            }
387                    }
388    
389                    return list;
390            }
391    
392            public Contact findByCompanyId_First(long companyId,
393                    OrderByComparator orderByComparator)
394                    throws NoSuchContactException, SystemException {
395                    List<Contact> list = findByCompanyId(companyId, 0, 1, orderByComparator);
396    
397                    if (list.isEmpty()) {
398                            StringBundler msg = new StringBundler(4);
399    
400                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
401    
402                            msg.append("companyId=");
403                            msg.append(companyId);
404    
405                            msg.append(StringPool.CLOSE_CURLY_BRACE);
406    
407                            throw new NoSuchContactException(msg.toString());
408                    }
409                    else {
410                            return list.get(0);
411                    }
412            }
413    
414            public Contact findByCompanyId_Last(long companyId,
415                    OrderByComparator orderByComparator)
416                    throws NoSuchContactException, SystemException {
417                    int count = countByCompanyId(companyId);
418    
419                    List<Contact> list = findByCompanyId(companyId, count - 1, count,
420                                    orderByComparator);
421    
422                    if (list.isEmpty()) {
423                            StringBundler msg = new StringBundler(4);
424    
425                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
426    
427                            msg.append("companyId=");
428                            msg.append(companyId);
429    
430                            msg.append(StringPool.CLOSE_CURLY_BRACE);
431    
432                            throw new NoSuchContactException(msg.toString());
433                    }
434                    else {
435                            return list.get(0);
436                    }
437            }
438    
439            public Contact[] findByCompanyId_PrevAndNext(long contactId,
440                    long companyId, OrderByComparator orderByComparator)
441                    throws NoSuchContactException, SystemException {
442                    Contact contact = findByPrimaryKey(contactId);
443    
444                    Session session = null;
445    
446                    try {
447                            session = openSession();
448    
449                            Contact[] array = new ContactImpl[3];
450    
451                            array[0] = getByCompanyId_PrevAndNext(session, contact, companyId,
452                                            orderByComparator, true);
453    
454                            array[1] = contact;
455    
456                            array[2] = getByCompanyId_PrevAndNext(session, contact, companyId,
457                                            orderByComparator, false);
458    
459                            return array;
460                    }
461                    catch (Exception e) {
462                            throw processException(e);
463                    }
464                    finally {
465                            closeSession(session);
466                    }
467            }
468    
469            protected Contact getByCompanyId_PrevAndNext(Session session,
470                    Contact contact, long companyId, OrderByComparator orderByComparator,
471                    boolean previous) {
472                    StringBundler query = null;
473    
474                    if (orderByComparator != null) {
475                            query = new StringBundler(6 +
476                                            (orderByComparator.getOrderByFields().length * 6));
477                    }
478                    else {
479                            query = new StringBundler(3);
480                    }
481    
482                    query.append(_SQL_SELECT_CONTACT_WHERE);
483    
484                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
485    
486                    if (orderByComparator != null) {
487                            String[] orderByFields = orderByComparator.getOrderByFields();
488    
489                            if (orderByFields.length > 0) {
490                                    query.append(WHERE_AND);
491                            }
492    
493                            for (int i = 0; i < orderByFields.length; i++) {
494                                    query.append(_ORDER_BY_ENTITY_ALIAS);
495                                    query.append(orderByFields[i]);
496    
497                                    if ((i + 1) < orderByFields.length) {
498                                            if (orderByComparator.isAscending() ^ previous) {
499                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
500                                            }
501                                            else {
502                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
503                                            }
504                                    }
505                                    else {
506                                            if (orderByComparator.isAscending() ^ previous) {
507                                                    query.append(WHERE_GREATER_THAN);
508                                            }
509                                            else {
510                                                    query.append(WHERE_LESSER_THAN);
511                                            }
512                                    }
513                            }
514    
515                            query.append(ORDER_BY_CLAUSE);
516    
517                            for (int i = 0; i < orderByFields.length; i++) {
518                                    query.append(_ORDER_BY_ENTITY_ALIAS);
519                                    query.append(orderByFields[i]);
520    
521                                    if ((i + 1) < orderByFields.length) {
522                                            if (orderByComparator.isAscending() ^ previous) {
523                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
524                                            }
525                                            else {
526                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
527                                            }
528                                    }
529                                    else {
530                                            if (orderByComparator.isAscending() ^ previous) {
531                                                    query.append(ORDER_BY_ASC);
532                                            }
533                                            else {
534                                                    query.append(ORDER_BY_DESC);
535                                            }
536                                    }
537                            }
538                    }
539    
540                    String sql = query.toString();
541    
542                    Query q = session.createQuery(sql);
543    
544                    q.setFirstResult(0);
545                    q.setMaxResults(2);
546    
547                    QueryPos qPos = QueryPos.getInstance(q);
548    
549                    qPos.add(companyId);
550    
551                    if (orderByComparator != null) {
552                            Object[] values = orderByComparator.getOrderByValues(contact);
553    
554                            for (Object value : values) {
555                                    qPos.add(value);
556                            }
557                    }
558    
559                    List<Contact> list = q.list();
560    
561                    if (list.size() == 2) {
562                            return list.get(1);
563                    }
564                    else {
565                            return null;
566                    }
567            }
568    
569            public List<Contact> findAll() throws SystemException {
570                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
571            }
572    
573            public List<Contact> findAll(int start, int end) throws SystemException {
574                    return findAll(start, end, null);
575            }
576    
577            public List<Contact> findAll(int start, int end,
578                    OrderByComparator orderByComparator) throws SystemException {
579                    Object[] finderArgs = new Object[] {
580                                    String.valueOf(start), String.valueOf(end),
581                                    String.valueOf(orderByComparator)
582                            };
583    
584                    List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
585                                    finderArgs, this);
586    
587                    if (list == null) {
588                            Session session = null;
589    
590                            try {
591                                    session = openSession();
592    
593                                    StringBundler query = null;
594                                    String sql = null;
595    
596                                    if (orderByComparator != null) {
597                                            query = new StringBundler(2 +
598                                                            (orderByComparator.getOrderByFields().length * 3));
599    
600                                            query.append(_SQL_SELECT_CONTACT);
601    
602                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
603                                                    orderByComparator);
604    
605                                            sql = query.toString();
606                                    }
607                                    else {
608                                            sql = _SQL_SELECT_CONTACT;
609                                    }
610    
611                                    Query q = session.createQuery(sql);
612    
613                                    if (orderByComparator == null) {
614                                            list = (List<Contact>)QueryUtil.list(q, getDialect(),
615                                                            start, end, false);
616    
617                                            Collections.sort(list);
618                                    }
619                                    else {
620                                            list = (List<Contact>)QueryUtil.list(q, getDialect(),
621                                                            start, end);
622                                    }
623                            }
624                            catch (Exception e) {
625                                    throw processException(e);
626                            }
627                            finally {
628                                    if (list == null) {
629                                            list = new ArrayList<Contact>();
630                                    }
631    
632                                    cacheResult(list);
633    
634                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
635    
636                                    closeSession(session);
637                            }
638                    }
639    
640                    return list;
641            }
642    
643            public void removeByCompanyId(long companyId) throws SystemException {
644                    for (Contact contact : findByCompanyId(companyId)) {
645                            remove(contact);
646                    }
647            }
648    
649            public void removeAll() throws SystemException {
650                    for (Contact contact : findAll()) {
651                            remove(contact);
652                    }
653            }
654    
655            public int countByCompanyId(long companyId) throws SystemException {
656                    Object[] finderArgs = new Object[] { companyId };
657    
658                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
659                                    finderArgs, this);
660    
661                    if (count == null) {
662                            Session session = null;
663    
664                            try {
665                                    session = openSession();
666    
667                                    StringBundler query = new StringBundler(2);
668    
669                                    query.append(_SQL_COUNT_CONTACT_WHERE);
670    
671                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
672    
673                                    String sql = query.toString();
674    
675                                    Query q = session.createQuery(sql);
676    
677                                    QueryPos qPos = QueryPos.getInstance(q);
678    
679                                    qPos.add(companyId);
680    
681                                    count = (Long)q.uniqueResult();
682                            }
683                            catch (Exception e) {
684                                    throw processException(e);
685                            }
686                            finally {
687                                    if (count == null) {
688                                            count = Long.valueOf(0);
689                                    }
690    
691                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
692                                            finderArgs, count);
693    
694                                    closeSession(session);
695                            }
696                    }
697    
698                    return count.intValue();
699            }
700    
701            public int countAll() throws SystemException {
702                    Object[] finderArgs = new Object[0];
703    
704                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
705                                    finderArgs, this);
706    
707                    if (count == null) {
708                            Session session = null;
709    
710                            try {
711                                    session = openSession();
712    
713                                    Query q = session.createQuery(_SQL_COUNT_CONTACT);
714    
715                                    count = (Long)q.uniqueResult();
716                            }
717                            catch (Exception e) {
718                                    throw processException(e);
719                            }
720                            finally {
721                                    if (count == null) {
722                                            count = Long.valueOf(0);
723                                    }
724    
725                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
726                                            count);
727    
728                                    closeSession(session);
729                            }
730                    }
731    
732                    return count.intValue();
733            }
734    
735            public void afterPropertiesSet() {
736                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
737                                            com.liferay.portal.util.PropsUtil.get(
738                                                    "value.object.listener.com.liferay.portal.model.Contact")));
739    
740                    if (listenerClassNames.length > 0) {
741                            try {
742                                    List<ModelListener<Contact>> listenersList = new ArrayList<ModelListener<Contact>>();
743    
744                                    for (String listenerClassName : listenerClassNames) {
745                                            listenersList.add((ModelListener<Contact>)InstanceFactory.newInstance(
746                                                            listenerClassName));
747                                    }
748    
749                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
750                            }
751                            catch (Exception e) {
752                                    _log.error(e);
753                            }
754                    }
755            }
756    
757            @BeanReference(type = AccountPersistence.class)
758            protected AccountPersistence accountPersistence;
759            @BeanReference(type = AddressPersistence.class)
760            protected AddressPersistence addressPersistence;
761            @BeanReference(type = BrowserTrackerPersistence.class)
762            protected BrowserTrackerPersistence browserTrackerPersistence;
763            @BeanReference(type = ClassNamePersistence.class)
764            protected ClassNamePersistence classNamePersistence;
765            @BeanReference(type = CompanyPersistence.class)
766            protected CompanyPersistence companyPersistence;
767            @BeanReference(type = ContactPersistence.class)
768            protected ContactPersistence contactPersistence;
769            @BeanReference(type = CountryPersistence.class)
770            protected CountryPersistence countryPersistence;
771            @BeanReference(type = EmailAddressPersistence.class)
772            protected EmailAddressPersistence emailAddressPersistence;
773            @BeanReference(type = GroupPersistence.class)
774            protected GroupPersistence groupPersistence;
775            @BeanReference(type = ImagePersistence.class)
776            protected ImagePersistence imagePersistence;
777            @BeanReference(type = LayoutPersistence.class)
778            protected LayoutPersistence layoutPersistence;
779            @BeanReference(type = LayoutPrototypePersistence.class)
780            protected LayoutPrototypePersistence layoutPrototypePersistence;
781            @BeanReference(type = LayoutSetPersistence.class)
782            protected LayoutSetPersistence layoutSetPersistence;
783            @BeanReference(type = LayoutSetPrototypePersistence.class)
784            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
785            @BeanReference(type = ListTypePersistence.class)
786            protected ListTypePersistence listTypePersistence;
787            @BeanReference(type = LockPersistence.class)
788            protected LockPersistence lockPersistence;
789            @BeanReference(type = MembershipRequestPersistence.class)
790            protected MembershipRequestPersistence membershipRequestPersistence;
791            @BeanReference(type = OrganizationPersistence.class)
792            protected OrganizationPersistence organizationPersistence;
793            @BeanReference(type = OrgGroupPermissionPersistence.class)
794            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
795            @BeanReference(type = OrgGroupRolePersistence.class)
796            protected OrgGroupRolePersistence orgGroupRolePersistence;
797            @BeanReference(type = OrgLaborPersistence.class)
798            protected OrgLaborPersistence orgLaborPersistence;
799            @BeanReference(type = PasswordPolicyPersistence.class)
800            protected PasswordPolicyPersistence passwordPolicyPersistence;
801            @BeanReference(type = PasswordPolicyRelPersistence.class)
802            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
803            @BeanReference(type = PasswordTrackerPersistence.class)
804            protected PasswordTrackerPersistence passwordTrackerPersistence;
805            @BeanReference(type = PermissionPersistence.class)
806            protected PermissionPersistence permissionPersistence;
807            @BeanReference(type = PhonePersistence.class)
808            protected PhonePersistence phonePersistence;
809            @BeanReference(type = PluginSettingPersistence.class)
810            protected PluginSettingPersistence pluginSettingPersistence;
811            @BeanReference(type = PortletPersistence.class)
812            protected PortletPersistence portletPersistence;
813            @BeanReference(type = PortletItemPersistence.class)
814            protected PortletItemPersistence portletItemPersistence;
815            @BeanReference(type = PortletPreferencesPersistence.class)
816            protected PortletPreferencesPersistence portletPreferencesPersistence;
817            @BeanReference(type = RegionPersistence.class)
818            protected RegionPersistence regionPersistence;
819            @BeanReference(type = ReleasePersistence.class)
820            protected ReleasePersistence releasePersistence;
821            @BeanReference(type = ResourcePersistence.class)
822            protected ResourcePersistence resourcePersistence;
823            @BeanReference(type = ResourceActionPersistence.class)
824            protected ResourceActionPersistence resourceActionPersistence;
825            @BeanReference(type = ResourceCodePersistence.class)
826            protected ResourceCodePersistence resourceCodePersistence;
827            @BeanReference(type = ResourcePermissionPersistence.class)
828            protected ResourcePermissionPersistence resourcePermissionPersistence;
829            @BeanReference(type = RolePersistence.class)
830            protected RolePersistence rolePersistence;
831            @BeanReference(type = ServiceComponentPersistence.class)
832            protected ServiceComponentPersistence serviceComponentPersistence;
833            @BeanReference(type = ShardPersistence.class)
834            protected ShardPersistence shardPersistence;
835            @BeanReference(type = SubscriptionPersistence.class)
836            protected SubscriptionPersistence subscriptionPersistence;
837            @BeanReference(type = TicketPersistence.class)
838            protected TicketPersistence ticketPersistence;
839            @BeanReference(type = TeamPersistence.class)
840            protected TeamPersistence teamPersistence;
841            @BeanReference(type = UserPersistence.class)
842            protected UserPersistence userPersistence;
843            @BeanReference(type = UserGroupPersistence.class)
844            protected UserGroupPersistence userGroupPersistence;
845            @BeanReference(type = UserGroupGroupRolePersistence.class)
846            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
847            @BeanReference(type = UserGroupRolePersistence.class)
848            protected UserGroupRolePersistence userGroupRolePersistence;
849            @BeanReference(type = UserIdMapperPersistence.class)
850            protected UserIdMapperPersistence userIdMapperPersistence;
851            @BeanReference(type = UserTrackerPersistence.class)
852            protected UserTrackerPersistence userTrackerPersistence;
853            @BeanReference(type = UserTrackerPathPersistence.class)
854            protected UserTrackerPathPersistence userTrackerPathPersistence;
855            @BeanReference(type = WebDAVPropsPersistence.class)
856            protected WebDAVPropsPersistence webDAVPropsPersistence;
857            @BeanReference(type = WebsitePersistence.class)
858            protected WebsitePersistence websitePersistence;
859            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
860            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
861            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
862            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
863            private static final String _SQL_SELECT_CONTACT = "SELECT contact FROM Contact contact";
864            private static final String _SQL_SELECT_CONTACT_WHERE = "SELECT contact FROM Contact contact WHERE ";
865            private static final String _SQL_COUNT_CONTACT = "SELECT COUNT(contact) FROM Contact contact";
866            private static final String _SQL_COUNT_CONTACT_WHERE = "SELECT COUNT(contact) FROM Contact contact WHERE ";
867            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "contact.companyId = ?";
868            private static final String _ORDER_BY_ENTITY_ALIAS = "contact.";
869            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Contact exists with the primary key ";
870            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Contact exists with the key {";
871            private static Log _log = LogFactoryUtil.getLog(ContactPersistenceImpl.class);
872    }