001    /**
002     * Copyright (c) 2000-2012 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.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.Contact;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.impl.ContactImpl;
041    import com.liferay.portal.model.impl.ContactModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the contact service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see ContactPersistence
059     * @see ContactUtil
060     * @generated
061     */
062    public class ContactPersistenceImpl extends BasePersistenceImpl<Contact>
063            implements ContactPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link ContactUtil} to access the contact persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = ContactImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
075                    new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
076                            ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
078                            new String[] {
079                                    Long.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
085                    new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
086                            ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
088                            new String[] { Long.class.getName() },
089                            ContactModelImpl.COMPANYID_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
091                            ContactModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
093                            new String[] { Long.class.getName() });
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
095                            ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
098                            ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
100            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED,
101                            ContactModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
103    
104            /**
105             * Caches the contact in the entity cache if it is enabled.
106             *
107             * @param contact the contact
108             */
109            public void cacheResult(Contact contact) {
110                    EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
111                            ContactImpl.class, contact.getPrimaryKey(), contact);
112    
113                    contact.resetOriginalValues();
114            }
115    
116            /**
117             * Caches the contacts in the entity cache if it is enabled.
118             *
119             * @param contacts the contacts
120             */
121            public void cacheResult(List<Contact> contacts) {
122                    for (Contact contact : contacts) {
123                            if (EntityCacheUtil.getResult(
124                                                    ContactModelImpl.ENTITY_CACHE_ENABLED,
125                                                    ContactImpl.class, contact.getPrimaryKey()) == null) {
126                                    cacheResult(contact);
127                            }
128                            else {
129                                    contact.resetOriginalValues();
130                            }
131                    }
132            }
133    
134            /**
135             * Clears the cache for all contacts.
136             *
137             * <p>
138             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
139             * </p>
140             */
141            @Override
142            public void clearCache() {
143                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
144                            CacheRegistryUtil.clear(ContactImpl.class.getName());
145                    }
146    
147                    EntityCacheUtil.clearCache(ContactImpl.class.getName());
148    
149                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
150                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
151                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
152            }
153    
154            /**
155             * Clears the cache for the contact.
156             *
157             * <p>
158             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
159             * </p>
160             */
161            @Override
162            public void clearCache(Contact contact) {
163                    EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
164                            ContactImpl.class, contact.getPrimaryKey());
165    
166                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
168            }
169    
170            @Override
171            public void clearCache(List<Contact> contacts) {
172                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
173                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
174    
175                    for (Contact contact : contacts) {
176                            EntityCacheUtil.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
177                                    ContactImpl.class, contact.getPrimaryKey());
178                    }
179            }
180    
181            /**
182             * Creates a new contact with the primary key. Does not add the contact to the database.
183             *
184             * @param contactId the primary key for the new contact
185             * @return the new contact
186             */
187            public Contact create(long contactId) {
188                    Contact contact = new ContactImpl();
189    
190                    contact.setNew(true);
191                    contact.setPrimaryKey(contactId);
192    
193                    return contact;
194            }
195    
196            /**
197             * Removes the contact with the primary key from the database. Also notifies the appropriate model listeners.
198             *
199             * @param contactId the primary key of the contact
200             * @return the contact that was removed
201             * @throws com.liferay.portal.NoSuchContactException if a contact with the primary key could not be found
202             * @throws SystemException if a system exception occurred
203             */
204            public Contact remove(long contactId)
205                    throws NoSuchContactException, SystemException {
206                    return remove(Long.valueOf(contactId));
207            }
208    
209            /**
210             * Removes the contact with the primary key from the database. Also notifies the appropriate model listeners.
211             *
212             * @param primaryKey the primary key of the contact
213             * @return the contact that was removed
214             * @throws com.liferay.portal.NoSuchContactException if a contact with the primary key could not be found
215             * @throws SystemException if a system exception occurred
216             */
217            @Override
218            public Contact remove(Serializable primaryKey)
219                    throws NoSuchContactException, SystemException {
220                    Session session = null;
221    
222                    try {
223                            session = openSession();
224    
225                            Contact contact = (Contact)session.get(ContactImpl.class, primaryKey);
226    
227                            if (contact == null) {
228                                    if (_log.isWarnEnabled()) {
229                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
230                                    }
231    
232                                    throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
233                                            primaryKey);
234                            }
235    
236                            return remove(contact);
237                    }
238                    catch (NoSuchContactException nsee) {
239                            throw nsee;
240                    }
241                    catch (Exception e) {
242                            throw processException(e);
243                    }
244                    finally {
245                            closeSession(session);
246                    }
247            }
248    
249            @Override
250            protected Contact removeImpl(Contact contact) throws SystemException {
251                    contact = toUnwrappedModel(contact);
252    
253                    Session session = null;
254    
255                    try {
256                            session = openSession();
257    
258                            BatchSessionUtil.delete(session, contact);
259                    }
260                    catch (Exception e) {
261                            throw processException(e);
262                    }
263                    finally {
264                            closeSession(session);
265                    }
266    
267                    clearCache(contact);
268    
269                    return contact;
270            }
271    
272            @Override
273            public Contact updateImpl(com.liferay.portal.model.Contact contact,
274                    boolean merge) throws SystemException {
275                    contact = toUnwrappedModel(contact);
276    
277                    boolean isNew = contact.isNew();
278    
279                    ContactModelImpl contactModelImpl = (ContactModelImpl)contact;
280    
281                    Session session = null;
282    
283                    try {
284                            session = openSession();
285    
286                            BatchSessionUtil.update(session, contact, merge);
287    
288                            contact.setNew(false);
289                    }
290                    catch (Exception e) {
291                            throw processException(e);
292                    }
293                    finally {
294                            closeSession(session);
295                    }
296    
297                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
298    
299                    if (isNew || !ContactModelImpl.COLUMN_BITMASK_ENABLED) {
300                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
301                    }
302                    else {
303                            if ((contactModelImpl.getColumnBitmask() &
304                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
305                                    Object[] args = new Object[] {
306                                                    Long.valueOf(contactModelImpl.getOriginalCompanyId())
307                                            };
308    
309                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
310                                            args);
311                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
312                                            args);
313    
314                                    args = new Object[] {
315                                                    Long.valueOf(contactModelImpl.getCompanyId())
316                                            };
317    
318                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
319                                            args);
320                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
321                                            args);
322                            }
323                    }
324    
325                    EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
326                            ContactImpl.class, contact.getPrimaryKey(), contact);
327    
328                    return contact;
329            }
330    
331            protected Contact toUnwrappedModel(Contact contact) {
332                    if (contact instanceof ContactImpl) {
333                            return contact;
334                    }
335    
336                    ContactImpl contactImpl = new ContactImpl();
337    
338                    contactImpl.setNew(contact.isNew());
339                    contactImpl.setPrimaryKey(contact.getPrimaryKey());
340    
341                    contactImpl.setContactId(contact.getContactId());
342                    contactImpl.setCompanyId(contact.getCompanyId());
343                    contactImpl.setUserId(contact.getUserId());
344                    contactImpl.setUserName(contact.getUserName());
345                    contactImpl.setCreateDate(contact.getCreateDate());
346                    contactImpl.setModifiedDate(contact.getModifiedDate());
347                    contactImpl.setAccountId(contact.getAccountId());
348                    contactImpl.setParentContactId(contact.getParentContactId());
349                    contactImpl.setFirstName(contact.getFirstName());
350                    contactImpl.setMiddleName(contact.getMiddleName());
351                    contactImpl.setLastName(contact.getLastName());
352                    contactImpl.setPrefixId(contact.getPrefixId());
353                    contactImpl.setSuffixId(contact.getSuffixId());
354                    contactImpl.setMale(contact.isMale());
355                    contactImpl.setBirthday(contact.getBirthday());
356                    contactImpl.setSmsSn(contact.getSmsSn());
357                    contactImpl.setAimSn(contact.getAimSn());
358                    contactImpl.setFacebookSn(contact.getFacebookSn());
359                    contactImpl.setIcqSn(contact.getIcqSn());
360                    contactImpl.setJabberSn(contact.getJabberSn());
361                    contactImpl.setMsnSn(contact.getMsnSn());
362                    contactImpl.setMySpaceSn(contact.getMySpaceSn());
363                    contactImpl.setSkypeSn(contact.getSkypeSn());
364                    contactImpl.setTwitterSn(contact.getTwitterSn());
365                    contactImpl.setYmSn(contact.getYmSn());
366                    contactImpl.setEmployeeStatusId(contact.getEmployeeStatusId());
367                    contactImpl.setEmployeeNumber(contact.getEmployeeNumber());
368                    contactImpl.setJobTitle(contact.getJobTitle());
369                    contactImpl.setJobClass(contact.getJobClass());
370                    contactImpl.setHoursOfOperation(contact.getHoursOfOperation());
371    
372                    return contactImpl;
373            }
374    
375            /**
376             * Returns the contact with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
377             *
378             * @param primaryKey the primary key of the contact
379             * @return the contact
380             * @throws com.liferay.portal.NoSuchModelException if a contact with the primary key could not be found
381             * @throws SystemException if a system exception occurred
382             */
383            @Override
384            public Contact findByPrimaryKey(Serializable primaryKey)
385                    throws NoSuchModelException, SystemException {
386                    return findByPrimaryKey(((Long)primaryKey).longValue());
387            }
388    
389            /**
390             * Returns the contact with the primary key or throws a {@link com.liferay.portal.NoSuchContactException} if it could not be found.
391             *
392             * @param contactId the primary key of the contact
393             * @return the contact
394             * @throws com.liferay.portal.NoSuchContactException if a contact with the primary key could not be found
395             * @throws SystemException if a system exception occurred
396             */
397            public Contact findByPrimaryKey(long contactId)
398                    throws NoSuchContactException, SystemException {
399                    Contact contact = fetchByPrimaryKey(contactId);
400    
401                    if (contact == null) {
402                            if (_log.isWarnEnabled()) {
403                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contactId);
404                            }
405    
406                            throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
407                                    contactId);
408                    }
409    
410                    return contact;
411            }
412    
413            /**
414             * Returns the contact with the primary key or returns <code>null</code> if it could not be found.
415             *
416             * @param primaryKey the primary key of the contact
417             * @return the contact, or <code>null</code> if a contact with the primary key could not be found
418             * @throws SystemException if a system exception occurred
419             */
420            @Override
421            public Contact fetchByPrimaryKey(Serializable primaryKey)
422                    throws SystemException {
423                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
424            }
425    
426            /**
427             * Returns the contact with the primary key or returns <code>null</code> if it could not be found.
428             *
429             * @param contactId the primary key of the contact
430             * @return the contact, or <code>null</code> if a contact with the primary key could not be found
431             * @throws SystemException if a system exception occurred
432             */
433            public Contact fetchByPrimaryKey(long contactId) throws SystemException {
434                    Contact contact = (Contact)EntityCacheUtil.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
435                                    ContactImpl.class, contactId);
436    
437                    if (contact == _nullContact) {
438                            return null;
439                    }
440    
441                    if (contact == null) {
442                            Session session = null;
443    
444                            boolean hasException = false;
445    
446                            try {
447                                    session = openSession();
448    
449                                    contact = (Contact)session.get(ContactImpl.class,
450                                                    Long.valueOf(contactId));
451                            }
452                            catch (Exception e) {
453                                    hasException = true;
454    
455                                    throw processException(e);
456                            }
457                            finally {
458                                    if (contact != null) {
459                                            cacheResult(contact);
460                                    }
461                                    else if (!hasException) {
462                                            EntityCacheUtil.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED,
463                                                    ContactImpl.class, contactId, _nullContact);
464                                    }
465    
466                                    closeSession(session);
467                            }
468                    }
469    
470                    return contact;
471            }
472    
473            /**
474             * Returns all the contacts where companyId = &#63;.
475             *
476             * @param companyId the company ID
477             * @return the matching contacts
478             * @throws SystemException if a system exception occurred
479             */
480            public List<Contact> findByCompanyId(long companyId)
481                    throws SystemException {
482                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
483                            null);
484            }
485    
486            /**
487             * Returns a range of all the contacts where companyId = &#63;.
488             *
489             * <p>
490             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
491             * </p>
492             *
493             * @param companyId the company ID
494             * @param start the lower bound of the range of contacts
495             * @param end the upper bound of the range of contacts (not inclusive)
496             * @return the range of matching contacts
497             * @throws SystemException if a system exception occurred
498             */
499            public List<Contact> findByCompanyId(long companyId, int start, int end)
500                    throws SystemException {
501                    return findByCompanyId(companyId, start, end, null);
502            }
503    
504            /**
505             * Returns an ordered range of all the contacts where companyId = &#63;.
506             *
507             * <p>
508             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
509             * </p>
510             *
511             * @param companyId the company ID
512             * @param start the lower bound of the range of contacts
513             * @param end the upper bound of the range of contacts (not inclusive)
514             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
515             * @return the ordered range of matching contacts
516             * @throws SystemException if a system exception occurred
517             */
518            public List<Contact> findByCompanyId(long companyId, int start, int end,
519                    OrderByComparator orderByComparator) throws SystemException {
520                    FinderPath finderPath = null;
521                    Object[] finderArgs = null;
522    
523                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
524                                    (orderByComparator == null)) {
525                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
526                            finderArgs = new Object[] { companyId };
527                    }
528                    else {
529                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
530                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
531                    }
532    
533                    List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
534                                    finderArgs, this);
535    
536                    if ((list != null) && !list.isEmpty()) {
537                            for (Contact contact : list) {
538                                    if ((companyId != contact.getCompanyId())) {
539                                            list = null;
540    
541                                            break;
542                                    }
543                            }
544                    }
545    
546                    if (list == null) {
547                            StringBundler query = null;
548    
549                            if (orderByComparator != null) {
550                                    query = new StringBundler(3 +
551                                                    (orderByComparator.getOrderByFields().length * 3));
552                            }
553                            else {
554                                    query = new StringBundler(2);
555                            }
556    
557                            query.append(_SQL_SELECT_CONTACT_WHERE);
558    
559                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
560    
561                            if (orderByComparator != null) {
562                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
563                                            orderByComparator);
564                            }
565    
566                            String sql = query.toString();
567    
568                            Session session = null;
569    
570                            try {
571                                    session = openSession();
572    
573                                    Query q = session.createQuery(sql);
574    
575                                    QueryPos qPos = QueryPos.getInstance(q);
576    
577                                    qPos.add(companyId);
578    
579                                    list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end);
580                            }
581                            catch (Exception e) {
582                                    throw processException(e);
583                            }
584                            finally {
585                                    if (list == null) {
586                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
587                                    }
588                                    else {
589                                            cacheResult(list);
590    
591                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
592                                    }
593    
594                                    closeSession(session);
595                            }
596                    }
597    
598                    return list;
599            }
600    
601            /**
602             * Returns the first contact in the ordered set where companyId = &#63;.
603             *
604             * <p>
605             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
606             * </p>
607             *
608             * @param companyId the company ID
609             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
610             * @return the first matching contact
611             * @throws com.liferay.portal.NoSuchContactException if a matching contact could not be found
612             * @throws SystemException if a system exception occurred
613             */
614            public Contact findByCompanyId_First(long companyId,
615                    OrderByComparator orderByComparator)
616                    throws NoSuchContactException, SystemException {
617                    List<Contact> list = findByCompanyId(companyId, 0, 1, orderByComparator);
618    
619                    if (list.isEmpty()) {
620                            StringBundler msg = new StringBundler(4);
621    
622                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
623    
624                            msg.append("companyId=");
625                            msg.append(companyId);
626    
627                            msg.append(StringPool.CLOSE_CURLY_BRACE);
628    
629                            throw new NoSuchContactException(msg.toString());
630                    }
631                    else {
632                            return list.get(0);
633                    }
634            }
635    
636            /**
637             * Returns the last contact in the ordered set where companyId = &#63;.
638             *
639             * <p>
640             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
641             * </p>
642             *
643             * @param companyId the company ID
644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
645             * @return the last matching contact
646             * @throws com.liferay.portal.NoSuchContactException if a matching contact could not be found
647             * @throws SystemException if a system exception occurred
648             */
649            public Contact findByCompanyId_Last(long companyId,
650                    OrderByComparator orderByComparator)
651                    throws NoSuchContactException, SystemException {
652                    int count = countByCompanyId(companyId);
653    
654                    List<Contact> list = findByCompanyId(companyId, count - 1, count,
655                                    orderByComparator);
656    
657                    if (list.isEmpty()) {
658                            StringBundler msg = new StringBundler(4);
659    
660                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
661    
662                            msg.append("companyId=");
663                            msg.append(companyId);
664    
665                            msg.append(StringPool.CLOSE_CURLY_BRACE);
666    
667                            throw new NoSuchContactException(msg.toString());
668                    }
669                    else {
670                            return list.get(0);
671                    }
672            }
673    
674            /**
675             * Returns the contacts before and after the current contact in the ordered set where companyId = &#63;.
676             *
677             * <p>
678             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
679             * </p>
680             *
681             * @param contactId the primary key of the current contact
682             * @param companyId the company ID
683             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
684             * @return the previous, current, and next contact
685             * @throws com.liferay.portal.NoSuchContactException if a contact with the primary key could not be found
686             * @throws SystemException if a system exception occurred
687             */
688            public Contact[] findByCompanyId_PrevAndNext(long contactId,
689                    long companyId, OrderByComparator orderByComparator)
690                    throws NoSuchContactException, SystemException {
691                    Contact contact = findByPrimaryKey(contactId);
692    
693                    Session session = null;
694    
695                    try {
696                            session = openSession();
697    
698                            Contact[] array = new ContactImpl[3];
699    
700                            array[0] = getByCompanyId_PrevAndNext(session, contact, companyId,
701                                            orderByComparator, true);
702    
703                            array[1] = contact;
704    
705                            array[2] = getByCompanyId_PrevAndNext(session, contact, companyId,
706                                            orderByComparator, false);
707    
708                            return array;
709                    }
710                    catch (Exception e) {
711                            throw processException(e);
712                    }
713                    finally {
714                            closeSession(session);
715                    }
716            }
717    
718            protected Contact getByCompanyId_PrevAndNext(Session session,
719                    Contact contact, long companyId, OrderByComparator orderByComparator,
720                    boolean previous) {
721                    StringBundler query = null;
722    
723                    if (orderByComparator != null) {
724                            query = new StringBundler(6 +
725                                            (orderByComparator.getOrderByFields().length * 6));
726                    }
727                    else {
728                            query = new StringBundler(3);
729                    }
730    
731                    query.append(_SQL_SELECT_CONTACT_WHERE);
732    
733                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
734    
735                    if (orderByComparator != null) {
736                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
737    
738                            if (orderByConditionFields.length > 0) {
739                                    query.append(WHERE_AND);
740                            }
741    
742                            for (int i = 0; i < orderByConditionFields.length; i++) {
743                                    query.append(_ORDER_BY_ENTITY_ALIAS);
744                                    query.append(orderByConditionFields[i]);
745    
746                                    if ((i + 1) < orderByConditionFields.length) {
747                                            if (orderByComparator.isAscending() ^ previous) {
748                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
749                                            }
750                                            else {
751                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
752                                            }
753                                    }
754                                    else {
755                                            if (orderByComparator.isAscending() ^ previous) {
756                                                    query.append(WHERE_GREATER_THAN);
757                                            }
758                                            else {
759                                                    query.append(WHERE_LESSER_THAN);
760                                            }
761                                    }
762                            }
763    
764                            query.append(ORDER_BY_CLAUSE);
765    
766                            String[] orderByFields = orderByComparator.getOrderByFields();
767    
768                            for (int i = 0; i < orderByFields.length; i++) {
769                                    query.append(_ORDER_BY_ENTITY_ALIAS);
770                                    query.append(orderByFields[i]);
771    
772                                    if ((i + 1) < orderByFields.length) {
773                                            if (orderByComparator.isAscending() ^ previous) {
774                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
775                                            }
776                                            else {
777                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
778                                            }
779                                    }
780                                    else {
781                                            if (orderByComparator.isAscending() ^ previous) {
782                                                    query.append(ORDER_BY_ASC);
783                                            }
784                                            else {
785                                                    query.append(ORDER_BY_DESC);
786                                            }
787                                    }
788                            }
789                    }
790    
791                    String sql = query.toString();
792    
793                    Query q = session.createQuery(sql);
794    
795                    q.setFirstResult(0);
796                    q.setMaxResults(2);
797    
798                    QueryPos qPos = QueryPos.getInstance(q);
799    
800                    qPos.add(companyId);
801    
802                    if (orderByComparator != null) {
803                            Object[] values = orderByComparator.getOrderByConditionValues(contact);
804    
805                            for (Object value : values) {
806                                    qPos.add(value);
807                            }
808                    }
809    
810                    List<Contact> list = q.list();
811    
812                    if (list.size() == 2) {
813                            return list.get(1);
814                    }
815                    else {
816                            return null;
817                    }
818            }
819    
820            /**
821             * Returns all the contacts.
822             *
823             * @return the contacts
824             * @throws SystemException if a system exception occurred
825             */
826            public List<Contact> findAll() throws SystemException {
827                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
828            }
829    
830            /**
831             * Returns a range of all the contacts.
832             *
833             * <p>
834             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
835             * </p>
836             *
837             * @param start the lower bound of the range of contacts
838             * @param end the upper bound of the range of contacts (not inclusive)
839             * @return the range of contacts
840             * @throws SystemException if a system exception occurred
841             */
842            public List<Contact> findAll(int start, int end) throws SystemException {
843                    return findAll(start, end, null);
844            }
845    
846            /**
847             * Returns an ordered range of all the contacts.
848             *
849             * <p>
850             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
851             * </p>
852             *
853             * @param start the lower bound of the range of contacts
854             * @param end the upper bound of the range of contacts (not inclusive)
855             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
856             * @return the ordered range of contacts
857             * @throws SystemException if a system exception occurred
858             */
859            public List<Contact> findAll(int start, int end,
860                    OrderByComparator orderByComparator) throws SystemException {
861                    FinderPath finderPath = null;
862                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
863    
864                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
865                                    (orderByComparator == null)) {
866                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
867                            finderArgs = FINDER_ARGS_EMPTY;
868                    }
869                    else {
870                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
871                            finderArgs = new Object[] { start, end, orderByComparator };
872                    }
873    
874                    List<Contact> list = (List<Contact>)FinderCacheUtil.getResult(finderPath,
875                                    finderArgs, this);
876    
877                    if (list == null) {
878                            StringBundler query = null;
879                            String sql = null;
880    
881                            if (orderByComparator != null) {
882                                    query = new StringBundler(2 +
883                                                    (orderByComparator.getOrderByFields().length * 3));
884    
885                                    query.append(_SQL_SELECT_CONTACT);
886    
887                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
888                                            orderByComparator);
889    
890                                    sql = query.toString();
891                            }
892                            else {
893                                    sql = _SQL_SELECT_CONTACT;
894                            }
895    
896                            Session session = null;
897    
898                            try {
899                                    session = openSession();
900    
901                                    Query q = session.createQuery(sql);
902    
903                                    if (orderByComparator == null) {
904                                            list = (List<Contact>)QueryUtil.list(q, getDialect(),
905                                                            start, end, false);
906    
907                                            Collections.sort(list);
908                                    }
909                                    else {
910                                            list = (List<Contact>)QueryUtil.list(q, getDialect(),
911                                                            start, end);
912                                    }
913                            }
914                            catch (Exception e) {
915                                    throw processException(e);
916                            }
917                            finally {
918                                    if (list == null) {
919                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
920                                    }
921                                    else {
922                                            cacheResult(list);
923    
924                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
925                                    }
926    
927                                    closeSession(session);
928                            }
929                    }
930    
931                    return list;
932            }
933    
934            /**
935             * Removes all the contacts where companyId = &#63; from the database.
936             *
937             * @param companyId the company ID
938             * @throws SystemException if a system exception occurred
939             */
940            public void removeByCompanyId(long companyId) throws SystemException {
941                    for (Contact contact : findByCompanyId(companyId)) {
942                            remove(contact);
943                    }
944            }
945    
946            /**
947             * Removes all the contacts from the database.
948             *
949             * @throws SystemException if a system exception occurred
950             */
951            public void removeAll() throws SystemException {
952                    for (Contact contact : findAll()) {
953                            remove(contact);
954                    }
955            }
956    
957            /**
958             * Returns the number of contacts where companyId = &#63;.
959             *
960             * @param companyId the company ID
961             * @return the number of matching contacts
962             * @throws SystemException if a system exception occurred
963             */
964            public int countByCompanyId(long companyId) throws SystemException {
965                    Object[] finderArgs = new Object[] { companyId };
966    
967                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
968                                    finderArgs, this);
969    
970                    if (count == null) {
971                            StringBundler query = new StringBundler(2);
972    
973                            query.append(_SQL_COUNT_CONTACT_WHERE);
974    
975                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
976    
977                            String sql = query.toString();
978    
979                            Session session = null;
980    
981                            try {
982                                    session = openSession();
983    
984                                    Query q = session.createQuery(sql);
985    
986                                    QueryPos qPos = QueryPos.getInstance(q);
987    
988                                    qPos.add(companyId);
989    
990                                    count = (Long)q.uniqueResult();
991                            }
992                            catch (Exception e) {
993                                    throw processException(e);
994                            }
995                            finally {
996                                    if (count == null) {
997                                            count = Long.valueOf(0);
998                                    }
999    
1000                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1001                                            finderArgs, count);
1002    
1003                                    closeSession(session);
1004                            }
1005                    }
1006    
1007                    return count.intValue();
1008            }
1009    
1010            /**
1011             * Returns the number of contacts.
1012             *
1013             * @return the number of contacts
1014             * @throws SystemException if a system exception occurred
1015             */
1016            public int countAll() throws SystemException {
1017                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1018                                    FINDER_ARGS_EMPTY, this);
1019    
1020                    if (count == null) {
1021                            Session session = null;
1022    
1023                            try {
1024                                    session = openSession();
1025    
1026                                    Query q = session.createQuery(_SQL_COUNT_CONTACT);
1027    
1028                                    count = (Long)q.uniqueResult();
1029                            }
1030                            catch (Exception e) {
1031                                    throw processException(e);
1032                            }
1033                            finally {
1034                                    if (count == null) {
1035                                            count = Long.valueOf(0);
1036                                    }
1037    
1038                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1039                                            FINDER_ARGS_EMPTY, count);
1040    
1041                                    closeSession(session);
1042                            }
1043                    }
1044    
1045                    return count.intValue();
1046            }
1047    
1048            /**
1049             * Initializes the contact persistence.
1050             */
1051            public void afterPropertiesSet() {
1052                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1053                                            com.liferay.portal.util.PropsUtil.get(
1054                                                    "value.object.listener.com.liferay.portal.model.Contact")));
1055    
1056                    if (listenerClassNames.length > 0) {
1057                            try {
1058                                    List<ModelListener<Contact>> listenersList = new ArrayList<ModelListener<Contact>>();
1059    
1060                                    for (String listenerClassName : listenerClassNames) {
1061                                            listenersList.add((ModelListener<Contact>)InstanceFactory.newInstance(
1062                                                            listenerClassName));
1063                                    }
1064    
1065                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1066                            }
1067                            catch (Exception e) {
1068                                    _log.error(e);
1069                            }
1070                    }
1071            }
1072    
1073            public void destroy() {
1074                    EntityCacheUtil.removeCache(ContactImpl.class.getName());
1075                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1076                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1077            }
1078    
1079            @BeanReference(type = AccountPersistence.class)
1080            protected AccountPersistence accountPersistence;
1081            @BeanReference(type = AddressPersistence.class)
1082            protected AddressPersistence addressPersistence;
1083            @BeanReference(type = BrowserTrackerPersistence.class)
1084            protected BrowserTrackerPersistence browserTrackerPersistence;
1085            @BeanReference(type = ClassNamePersistence.class)
1086            protected ClassNamePersistence classNamePersistence;
1087            @BeanReference(type = ClusterGroupPersistence.class)
1088            protected ClusterGroupPersistence clusterGroupPersistence;
1089            @BeanReference(type = CompanyPersistence.class)
1090            protected CompanyPersistence companyPersistence;
1091            @BeanReference(type = ContactPersistence.class)
1092            protected ContactPersistence contactPersistence;
1093            @BeanReference(type = CountryPersistence.class)
1094            protected CountryPersistence countryPersistence;
1095            @BeanReference(type = EmailAddressPersistence.class)
1096            protected EmailAddressPersistence emailAddressPersistence;
1097            @BeanReference(type = GroupPersistence.class)
1098            protected GroupPersistence groupPersistence;
1099            @BeanReference(type = ImagePersistence.class)
1100            protected ImagePersistence imagePersistence;
1101            @BeanReference(type = LayoutPersistence.class)
1102            protected LayoutPersistence layoutPersistence;
1103            @BeanReference(type = LayoutBranchPersistence.class)
1104            protected LayoutBranchPersistence layoutBranchPersistence;
1105            @BeanReference(type = LayoutPrototypePersistence.class)
1106            protected LayoutPrototypePersistence layoutPrototypePersistence;
1107            @BeanReference(type = LayoutRevisionPersistence.class)
1108            protected LayoutRevisionPersistence layoutRevisionPersistence;
1109            @BeanReference(type = LayoutSetPersistence.class)
1110            protected LayoutSetPersistence layoutSetPersistence;
1111            @BeanReference(type = LayoutSetBranchPersistence.class)
1112            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1113            @BeanReference(type = LayoutSetPrototypePersistence.class)
1114            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1115            @BeanReference(type = ListTypePersistence.class)
1116            protected ListTypePersistence listTypePersistence;
1117            @BeanReference(type = LockPersistence.class)
1118            protected LockPersistence lockPersistence;
1119            @BeanReference(type = MembershipRequestPersistence.class)
1120            protected MembershipRequestPersistence membershipRequestPersistence;
1121            @BeanReference(type = OrganizationPersistence.class)
1122            protected OrganizationPersistence organizationPersistence;
1123            @BeanReference(type = OrgGroupPermissionPersistence.class)
1124            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1125            @BeanReference(type = OrgGroupRolePersistence.class)
1126            protected OrgGroupRolePersistence orgGroupRolePersistence;
1127            @BeanReference(type = OrgLaborPersistence.class)
1128            protected OrgLaborPersistence orgLaborPersistence;
1129            @BeanReference(type = PasswordPolicyPersistence.class)
1130            protected PasswordPolicyPersistence passwordPolicyPersistence;
1131            @BeanReference(type = PasswordPolicyRelPersistence.class)
1132            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1133            @BeanReference(type = PasswordTrackerPersistence.class)
1134            protected PasswordTrackerPersistence passwordTrackerPersistence;
1135            @BeanReference(type = PermissionPersistence.class)
1136            protected PermissionPersistence permissionPersistence;
1137            @BeanReference(type = PhonePersistence.class)
1138            protected PhonePersistence phonePersistence;
1139            @BeanReference(type = PluginSettingPersistence.class)
1140            protected PluginSettingPersistence pluginSettingPersistence;
1141            @BeanReference(type = PortalPreferencesPersistence.class)
1142            protected PortalPreferencesPersistence portalPreferencesPersistence;
1143            @BeanReference(type = PortletPersistence.class)
1144            protected PortletPersistence portletPersistence;
1145            @BeanReference(type = PortletItemPersistence.class)
1146            protected PortletItemPersistence portletItemPersistence;
1147            @BeanReference(type = PortletPreferencesPersistence.class)
1148            protected PortletPreferencesPersistence portletPreferencesPersistence;
1149            @BeanReference(type = RegionPersistence.class)
1150            protected RegionPersistence regionPersistence;
1151            @BeanReference(type = ReleasePersistence.class)
1152            protected ReleasePersistence releasePersistence;
1153            @BeanReference(type = RepositoryPersistence.class)
1154            protected RepositoryPersistence repositoryPersistence;
1155            @BeanReference(type = RepositoryEntryPersistence.class)
1156            protected RepositoryEntryPersistence repositoryEntryPersistence;
1157            @BeanReference(type = ResourcePersistence.class)
1158            protected ResourcePersistence resourcePersistence;
1159            @BeanReference(type = ResourceActionPersistence.class)
1160            protected ResourceActionPersistence resourceActionPersistence;
1161            @BeanReference(type = ResourceBlockPersistence.class)
1162            protected ResourceBlockPersistence resourceBlockPersistence;
1163            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1164            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1165            @BeanReference(type = ResourceCodePersistence.class)
1166            protected ResourceCodePersistence resourceCodePersistence;
1167            @BeanReference(type = ResourcePermissionPersistence.class)
1168            protected ResourcePermissionPersistence resourcePermissionPersistence;
1169            @BeanReference(type = ResourceTypePermissionPersistence.class)
1170            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1171            @BeanReference(type = RolePersistence.class)
1172            protected RolePersistence rolePersistence;
1173            @BeanReference(type = ServiceComponentPersistence.class)
1174            protected ServiceComponentPersistence serviceComponentPersistence;
1175            @BeanReference(type = ShardPersistence.class)
1176            protected ShardPersistence shardPersistence;
1177            @BeanReference(type = SubscriptionPersistence.class)
1178            protected SubscriptionPersistence subscriptionPersistence;
1179            @BeanReference(type = TeamPersistence.class)
1180            protected TeamPersistence teamPersistence;
1181            @BeanReference(type = TicketPersistence.class)
1182            protected TicketPersistence ticketPersistence;
1183            @BeanReference(type = UserPersistence.class)
1184            protected UserPersistence userPersistence;
1185            @BeanReference(type = UserGroupPersistence.class)
1186            protected UserGroupPersistence userGroupPersistence;
1187            @BeanReference(type = UserGroupGroupRolePersistence.class)
1188            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1189            @BeanReference(type = UserGroupRolePersistence.class)
1190            protected UserGroupRolePersistence userGroupRolePersistence;
1191            @BeanReference(type = UserIdMapperPersistence.class)
1192            protected UserIdMapperPersistence userIdMapperPersistence;
1193            @BeanReference(type = UserNotificationEventPersistence.class)
1194            protected UserNotificationEventPersistence userNotificationEventPersistence;
1195            @BeanReference(type = UserTrackerPersistence.class)
1196            protected UserTrackerPersistence userTrackerPersistence;
1197            @BeanReference(type = UserTrackerPathPersistence.class)
1198            protected UserTrackerPathPersistence userTrackerPathPersistence;
1199            @BeanReference(type = VirtualHostPersistence.class)
1200            protected VirtualHostPersistence virtualHostPersistence;
1201            @BeanReference(type = WebDAVPropsPersistence.class)
1202            protected WebDAVPropsPersistence webDAVPropsPersistence;
1203            @BeanReference(type = WebsitePersistence.class)
1204            protected WebsitePersistence websitePersistence;
1205            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1206            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1207            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1208            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1209            private static final String _SQL_SELECT_CONTACT = "SELECT contact FROM Contact contact";
1210            private static final String _SQL_SELECT_CONTACT_WHERE = "SELECT contact FROM Contact contact WHERE ";
1211            private static final String _SQL_COUNT_CONTACT = "SELECT COUNT(contact) FROM Contact contact";
1212            private static final String _SQL_COUNT_CONTACT_WHERE = "SELECT COUNT(contact) FROM Contact contact WHERE ";
1213            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "contact.companyId = ?";
1214            private static final String _ORDER_BY_ENTITY_ALIAS = "contact.";
1215            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Contact exists with the primary key ";
1216            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Contact exists with the key {";
1217            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1218            private static Log _log = LogFactoryUtil.getLog(ContactPersistenceImpl.class);
1219            private static Contact _nullContact = new ContactImpl() {
1220                            @Override
1221                            public Object clone() {
1222                                    return this;
1223                            }
1224    
1225                            @Override
1226                            public CacheModel<Contact> toCacheModel() {
1227                                    return _nullContactCacheModel;
1228                            }
1229                    };
1230    
1231            private static CacheModel<Contact> _nullContactCacheModel = new CacheModel<Contact>() {
1232                            public Contact toEntityModel() {
1233                                    return _nullContact;
1234                            }
1235                    };
1236    }