001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchPhoneException;
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.ModelListener;
038    import com.liferay.portal.model.Phone;
039    import com.liferay.portal.model.impl.PhoneImpl;
040    import com.liferay.portal.model.impl.PhoneModelImpl;
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     * The persistence implementation for the phone service.
051     *
052     * <p>
053     * Never modify or reference this class directly. Always use {@link PhoneUtil} to access the phone persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
054     * </p>
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see PhonePersistence
062     * @see PhoneUtil
063     * @generated
064     */
065    public class PhonePersistenceImpl extends BasePersistenceImpl<Phone>
066            implements PhonePersistence {
067            public static final String FINDER_CLASS_NAME_ENTITY = PhoneImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069                    ".List";
070            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
071                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
072                            "findByCompanyId",
073                            new String[] {
074                                    Long.class.getName(),
075                                    
076                            "java.lang.Integer", "java.lang.Integer",
077                                    "com.liferay.portal.kernel.util.OrderByComparator"
078                            });
079            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
080                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081                            "countByCompanyId", new String[] { Long.class.getName() });
082            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
083                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084                            "findByUserId",
085                            new String[] {
086                                    Long.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
092                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093                            "countByUserId", new String[] { Long.class.getName() });
094            public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
095                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
096                            "findByC_C",
097                            new String[] {
098                                    Long.class.getName(), Long.class.getName(),
099                                    
100                            "java.lang.Integer", "java.lang.Integer",
101                                    "com.liferay.portal.kernel.util.OrderByComparator"
102                            });
103            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
104                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105                            "countByC_C",
106                            new String[] { Long.class.getName(), Long.class.getName() });
107            public static final FinderPath FINDER_PATH_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
108                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109                            "findByC_C_C",
110                            new String[] {
111                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
112                                    
113                            "java.lang.Integer", "java.lang.Integer",
114                                    "com.liferay.portal.kernel.util.OrderByComparator"
115                            });
116            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
117                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
118                            "countByC_C_C",
119                            new String[] {
120                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
121                            });
122            public static final FinderPath FINDER_PATH_FIND_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
123                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124                            "findByC_C_C_P",
125                            new String[] {
126                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
127                                    Boolean.class.getName(),
128                                    
129                            "java.lang.Integer", "java.lang.Integer",
130                                    "com.liferay.portal.kernel.util.OrderByComparator"
131                            });
132            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
133                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134                            "countByC_C_C_P",
135                            new String[] {
136                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
137                                    Boolean.class.getName()
138                            });
139            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
140                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
141                            "findAll", new String[0]);
142            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
143                            PhoneModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
144                            "countAll", new String[0]);
145    
146            /**
147             * Caches the phone in the entity cache if it is enabled.
148             *
149             * @param phone the phone to cache
150             */
151            public void cacheResult(Phone phone) {
152                    EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
153                            PhoneImpl.class, phone.getPrimaryKey(), phone);
154            }
155    
156            /**
157             * Caches the phones in the entity cache if it is enabled.
158             *
159             * @param phones the phones to cache
160             */
161            public void cacheResult(List<Phone> phones) {
162                    for (Phone phone : phones) {
163                            if (EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
164                                                    PhoneImpl.class, phone.getPrimaryKey(), this) == null) {
165                                    cacheResult(phone);
166                            }
167                    }
168            }
169    
170            /**
171             * Clears the cache for all phones.
172             *
173             * <p>
174             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
175             * </p>
176             */
177            public void clearCache() {
178                    CacheRegistryUtil.clear(PhoneImpl.class.getName());
179                    EntityCacheUtil.clearCache(PhoneImpl.class.getName());
180                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
181                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
182            }
183    
184            /**
185             * Clears the cache for the phone.
186             *
187             * <p>
188             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
189             * </p>
190             */
191            public void clearCache(Phone phone) {
192                    EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
193                            PhoneImpl.class, phone.getPrimaryKey());
194            }
195    
196            /**
197             * Creates a new phone with the primary key. Does not add the phone to the database.
198             *
199             * @param phoneId the primary key for the new phone
200             * @return the new phone
201             */
202            public Phone create(long phoneId) {
203                    Phone phone = new PhoneImpl();
204    
205                    phone.setNew(true);
206                    phone.setPrimaryKey(phoneId);
207    
208                    return phone;
209            }
210    
211            /**
212             * Removes the phone with the primary key from the database. Also notifies the appropriate model listeners.
213             *
214             * @param primaryKey the primary key of the phone to remove
215             * @return the phone that was removed
216             * @throws com.liferay.portal.NoSuchModelException if a phone with the primary key could not be found
217             * @throws SystemException if a system exception occurred
218             */
219            public Phone remove(Serializable primaryKey)
220                    throws NoSuchModelException, SystemException {
221                    return remove(((Long)primaryKey).longValue());
222            }
223    
224            /**
225             * Removes the phone with the primary key from the database. Also notifies the appropriate model listeners.
226             *
227             * @param phoneId the primary key of the phone to remove
228             * @return the phone that was removed
229             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
230             * @throws SystemException if a system exception occurred
231             */
232            public Phone remove(long phoneId)
233                    throws NoSuchPhoneException, SystemException {
234                    Session session = null;
235    
236                    try {
237                            session = openSession();
238    
239                            Phone phone = (Phone)session.get(PhoneImpl.class, new Long(phoneId));
240    
241                            if (phone == null) {
242                                    if (_log.isWarnEnabled()) {
243                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + phoneId);
244                                    }
245    
246                                    throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
247                                            phoneId);
248                            }
249    
250                            return remove(phone);
251                    }
252                    catch (NoSuchPhoneException nsee) {
253                            throw nsee;
254                    }
255                    catch (Exception e) {
256                            throw processException(e);
257                    }
258                    finally {
259                            closeSession(session);
260                    }
261            }
262    
263            protected Phone removeImpl(Phone phone) throws SystemException {
264                    phone = toUnwrappedModel(phone);
265    
266                    Session session = null;
267    
268                    try {
269                            session = openSession();
270    
271                            BatchSessionUtil.delete(session, phone);
272                    }
273                    catch (Exception e) {
274                            throw processException(e);
275                    }
276                    finally {
277                            closeSession(session);
278                    }
279    
280                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
281    
282                    EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
283                            PhoneImpl.class, phone.getPrimaryKey());
284    
285                    return phone;
286            }
287    
288            public Phone updateImpl(com.liferay.portal.model.Phone phone, boolean merge)
289                    throws SystemException {
290                    phone = toUnwrappedModel(phone);
291    
292                    Session session = null;
293    
294                    try {
295                            session = openSession();
296    
297                            BatchSessionUtil.update(session, phone, merge);
298    
299                            phone.setNew(false);
300                    }
301                    catch (Exception e) {
302                            throw processException(e);
303                    }
304                    finally {
305                            closeSession(session);
306                    }
307    
308                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
309    
310                    EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
311                            PhoneImpl.class, phone.getPrimaryKey(), phone);
312    
313                    return phone;
314            }
315    
316            protected Phone toUnwrappedModel(Phone phone) {
317                    if (phone instanceof PhoneImpl) {
318                            return phone;
319                    }
320    
321                    PhoneImpl phoneImpl = new PhoneImpl();
322    
323                    phoneImpl.setNew(phone.isNew());
324                    phoneImpl.setPrimaryKey(phone.getPrimaryKey());
325    
326                    phoneImpl.setPhoneId(phone.getPhoneId());
327                    phoneImpl.setCompanyId(phone.getCompanyId());
328                    phoneImpl.setUserId(phone.getUserId());
329                    phoneImpl.setUserName(phone.getUserName());
330                    phoneImpl.setCreateDate(phone.getCreateDate());
331                    phoneImpl.setModifiedDate(phone.getModifiedDate());
332                    phoneImpl.setClassNameId(phone.getClassNameId());
333                    phoneImpl.setClassPK(phone.getClassPK());
334                    phoneImpl.setNumber(phone.getNumber());
335                    phoneImpl.setExtension(phone.getExtension());
336                    phoneImpl.setTypeId(phone.getTypeId());
337                    phoneImpl.setPrimary(phone.isPrimary());
338    
339                    return phoneImpl;
340            }
341    
342            /**
343             * Finds the phone with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
344             *
345             * @param primaryKey the primary key of the phone to find
346             * @return the phone
347             * @throws com.liferay.portal.NoSuchModelException if a phone with the primary key could not be found
348             * @throws SystemException if a system exception occurred
349             */
350            public Phone findByPrimaryKey(Serializable primaryKey)
351                    throws NoSuchModelException, SystemException {
352                    return findByPrimaryKey(((Long)primaryKey).longValue());
353            }
354    
355            /**
356             * Finds the phone with the primary key or throws a {@link com.liferay.portal.NoSuchPhoneException} if it could not be found.
357             *
358             * @param phoneId the primary key of the phone to find
359             * @return the phone
360             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
361             * @throws SystemException if a system exception occurred
362             */
363            public Phone findByPrimaryKey(long phoneId)
364                    throws NoSuchPhoneException, SystemException {
365                    Phone phone = fetchByPrimaryKey(phoneId);
366    
367                    if (phone == null) {
368                            if (_log.isWarnEnabled()) {
369                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + phoneId);
370                            }
371    
372                            throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
373                                    phoneId);
374                    }
375    
376                    return phone;
377            }
378    
379            /**
380             * Finds the phone with the primary key or returns <code>null</code> if it could not be found.
381             *
382             * @param primaryKey the primary key of the phone to find
383             * @return the phone, or <code>null</code> if a phone with the primary key could not be found
384             * @throws SystemException if a system exception occurred
385             */
386            public Phone fetchByPrimaryKey(Serializable primaryKey)
387                    throws SystemException {
388                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
389            }
390    
391            /**
392             * Finds the phone with the primary key or returns <code>null</code> if it could not be found.
393             *
394             * @param phoneId the primary key of the phone to find
395             * @return the phone, or <code>null</code> if a phone with the primary key could not be found
396             * @throws SystemException if a system exception occurred
397             */
398            public Phone fetchByPrimaryKey(long phoneId) throws SystemException {
399                    Phone phone = (Phone)EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
400                                    PhoneImpl.class, phoneId, this);
401    
402                    if (phone == null) {
403                            Session session = null;
404    
405                            try {
406                                    session = openSession();
407    
408                                    phone = (Phone)session.get(PhoneImpl.class, new Long(phoneId));
409                            }
410                            catch (Exception e) {
411                                    throw processException(e);
412                            }
413                            finally {
414                                    if (phone != null) {
415                                            cacheResult(phone);
416                                    }
417    
418                                    closeSession(session);
419                            }
420                    }
421    
422                    return phone;
423            }
424    
425            /**
426             * Finds all the phones where companyId = &#63;.
427             *
428             * @param companyId the company id to search with
429             * @return the matching phones
430             * @throws SystemException if a system exception occurred
431             */
432            public List<Phone> findByCompanyId(long companyId)
433                    throws SystemException {
434                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
435                            null);
436            }
437    
438            /**
439             * Finds a range of all the phones where companyId = &#63;.
440             *
441             * <p>
442             * 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.
443             * </p>
444             *
445             * @param companyId the company id to search with
446             * @param start the lower bound of the range of phones to return
447             * @param end the upper bound of the range of phones to return (not inclusive)
448             * @return the range of matching phones
449             * @throws SystemException if a system exception occurred
450             */
451            public List<Phone> findByCompanyId(long companyId, int start, int end)
452                    throws SystemException {
453                    return findByCompanyId(companyId, start, end, null);
454            }
455    
456            /**
457             * Finds an ordered range of all the phones where companyId = &#63;.
458             *
459             * <p>
460             * 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.
461             * </p>
462             *
463             * @param companyId the company id to search with
464             * @param start the lower bound of the range of phones to return
465             * @param end the upper bound of the range of phones to return (not inclusive)
466             * @param orderByComparator the comparator to order the results by
467             * @return the ordered range of matching phones
468             * @throws SystemException if a system exception occurred
469             */
470            public List<Phone> findByCompanyId(long companyId, int start, int end,
471                    OrderByComparator orderByComparator) throws SystemException {
472                    Object[] finderArgs = new Object[] {
473                                    companyId,
474                                    
475                                    String.valueOf(start), String.valueOf(end),
476                                    String.valueOf(orderByComparator)
477                            };
478    
479                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
480                                    finderArgs, this);
481    
482                    if (list == null) {
483                            Session session = null;
484    
485                            try {
486                                    session = openSession();
487    
488                                    StringBundler query = null;
489    
490                                    if (orderByComparator != null) {
491                                            query = new StringBundler(3 +
492                                                            (orderByComparator.getOrderByFields().length * 3));
493                                    }
494                                    else {
495                                            query = new StringBundler(3);
496                                    }
497    
498                                    query.append(_SQL_SELECT_PHONE_WHERE);
499    
500                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
501    
502                                    if (orderByComparator != null) {
503                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
504                                                    orderByComparator);
505                                    }
506    
507                                    else {
508                                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
509                                    }
510    
511                                    String sql = query.toString();
512    
513                                    Query q = session.createQuery(sql);
514    
515                                    QueryPos qPos = QueryPos.getInstance(q);
516    
517                                    qPos.add(companyId);
518    
519                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
520                            }
521                            catch (Exception e) {
522                                    throw processException(e);
523                            }
524                            finally {
525                                    if (list == null) {
526                                            list = new ArrayList<Phone>();
527                                    }
528    
529                                    cacheResult(list);
530    
531                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
532                                            finderArgs, list);
533    
534                                    closeSession(session);
535                            }
536                    }
537    
538                    return list;
539            }
540    
541            /**
542             * Finds the first phone in the ordered set where companyId = &#63;.
543             *
544             * <p>
545             * 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.
546             * </p>
547             *
548             * @param companyId the company id to search with
549             * @param orderByComparator the comparator to order the set by
550             * @return the first matching phone
551             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
552             * @throws SystemException if a system exception occurred
553             */
554            public Phone findByCompanyId_First(long companyId,
555                    OrderByComparator orderByComparator)
556                    throws NoSuchPhoneException, SystemException {
557                    List<Phone> list = findByCompanyId(companyId, 0, 1, orderByComparator);
558    
559                    if (list.isEmpty()) {
560                            StringBundler msg = new StringBundler(4);
561    
562                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
563    
564                            msg.append("companyId=");
565                            msg.append(companyId);
566    
567                            msg.append(StringPool.CLOSE_CURLY_BRACE);
568    
569                            throw new NoSuchPhoneException(msg.toString());
570                    }
571                    else {
572                            return list.get(0);
573                    }
574            }
575    
576            /**
577             * Finds the last phone in the ordered set where companyId = &#63;.
578             *
579             * <p>
580             * 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.
581             * </p>
582             *
583             * @param companyId the company id to search with
584             * @param orderByComparator the comparator to order the set by
585             * @return the last matching phone
586             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
587             * @throws SystemException if a system exception occurred
588             */
589            public Phone findByCompanyId_Last(long companyId,
590                    OrderByComparator orderByComparator)
591                    throws NoSuchPhoneException, SystemException {
592                    int count = countByCompanyId(companyId);
593    
594                    List<Phone> list = findByCompanyId(companyId, count - 1, count,
595                                    orderByComparator);
596    
597                    if (list.isEmpty()) {
598                            StringBundler msg = new StringBundler(4);
599    
600                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
601    
602                            msg.append("companyId=");
603                            msg.append(companyId);
604    
605                            msg.append(StringPool.CLOSE_CURLY_BRACE);
606    
607                            throw new NoSuchPhoneException(msg.toString());
608                    }
609                    else {
610                            return list.get(0);
611                    }
612            }
613    
614            /**
615             * Finds the phones before and after the current phone in the ordered set where companyId = &#63;.
616             *
617             * <p>
618             * 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.
619             * </p>
620             *
621             * @param phoneId the primary key of the current phone
622             * @param companyId the company id to search with
623             * @param orderByComparator the comparator to order the set by
624             * @return the previous, current, and next phone
625             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
626             * @throws SystemException if a system exception occurred
627             */
628            public Phone[] findByCompanyId_PrevAndNext(long phoneId, long companyId,
629                    OrderByComparator orderByComparator)
630                    throws NoSuchPhoneException, SystemException {
631                    Phone phone = findByPrimaryKey(phoneId);
632    
633                    Session session = null;
634    
635                    try {
636                            session = openSession();
637    
638                            Phone[] array = new PhoneImpl[3];
639    
640                            array[0] = getByCompanyId_PrevAndNext(session, phone, companyId,
641                                            orderByComparator, true);
642    
643                            array[1] = phone;
644    
645                            array[2] = getByCompanyId_PrevAndNext(session, phone, companyId,
646                                            orderByComparator, false);
647    
648                            return array;
649                    }
650                    catch (Exception e) {
651                            throw processException(e);
652                    }
653                    finally {
654                            closeSession(session);
655                    }
656            }
657    
658            protected Phone getByCompanyId_PrevAndNext(Session session, Phone phone,
659                    long companyId, OrderByComparator orderByComparator, boolean previous) {
660                    StringBundler query = null;
661    
662                    if (orderByComparator != null) {
663                            query = new StringBundler(6 +
664                                            (orderByComparator.getOrderByFields().length * 6));
665                    }
666                    else {
667                            query = new StringBundler(3);
668                    }
669    
670                    query.append(_SQL_SELECT_PHONE_WHERE);
671    
672                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
673    
674                    if (orderByComparator != null) {
675                            String[] orderByFields = orderByComparator.getOrderByFields();
676    
677                            if (orderByFields.length > 0) {
678                                    query.append(WHERE_AND);
679                            }
680    
681                            for (int i = 0; i < orderByFields.length; i++) {
682                                    query.append(_ORDER_BY_ENTITY_ALIAS);
683                                    query.append(orderByFields[i]);
684    
685                                    if ((i + 1) < orderByFields.length) {
686                                            if (orderByComparator.isAscending() ^ previous) {
687                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
688                                            }
689                                            else {
690                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
691                                            }
692                                    }
693                                    else {
694                                            if (orderByComparator.isAscending() ^ previous) {
695                                                    query.append(WHERE_GREATER_THAN);
696                                            }
697                                            else {
698                                                    query.append(WHERE_LESSER_THAN);
699                                            }
700                                    }
701                            }
702    
703                            query.append(ORDER_BY_CLAUSE);
704    
705                            for (int i = 0; i < orderByFields.length; i++) {
706                                    query.append(_ORDER_BY_ENTITY_ALIAS);
707                                    query.append(orderByFields[i]);
708    
709                                    if ((i + 1) < orderByFields.length) {
710                                            if (orderByComparator.isAscending() ^ previous) {
711                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
712                                            }
713                                            else {
714                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
715                                            }
716                                    }
717                                    else {
718                                            if (orderByComparator.isAscending() ^ previous) {
719                                                    query.append(ORDER_BY_ASC);
720                                            }
721                                            else {
722                                                    query.append(ORDER_BY_DESC);
723                                            }
724                                    }
725                            }
726                    }
727    
728                    else {
729                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
730                    }
731    
732                    String sql = query.toString();
733    
734                    Query q = session.createQuery(sql);
735    
736                    q.setFirstResult(0);
737                    q.setMaxResults(2);
738    
739                    QueryPos qPos = QueryPos.getInstance(q);
740    
741                    qPos.add(companyId);
742    
743                    if (orderByComparator != null) {
744                            Object[] values = orderByComparator.getOrderByValues(phone);
745    
746                            for (Object value : values) {
747                                    qPos.add(value);
748                            }
749                    }
750    
751                    List<Phone> list = q.list();
752    
753                    if (list.size() == 2) {
754                            return list.get(1);
755                    }
756                    else {
757                            return null;
758                    }
759            }
760    
761            /**
762             * Finds all the phones where userId = &#63;.
763             *
764             * @param userId the user id to search with
765             * @return the matching phones
766             * @throws SystemException if a system exception occurred
767             */
768            public List<Phone> findByUserId(long userId) throws SystemException {
769                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
770            }
771    
772            /**
773             * Finds a range of all the phones where userId = &#63;.
774             *
775             * <p>
776             * 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.
777             * </p>
778             *
779             * @param userId the user id to search with
780             * @param start the lower bound of the range of phones to return
781             * @param end the upper bound of the range of phones to return (not inclusive)
782             * @return the range of matching phones
783             * @throws SystemException if a system exception occurred
784             */
785            public List<Phone> findByUserId(long userId, int start, int end)
786                    throws SystemException {
787                    return findByUserId(userId, start, end, null);
788            }
789    
790            /**
791             * Finds an ordered range of all the phones where userId = &#63;.
792             *
793             * <p>
794             * 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.
795             * </p>
796             *
797             * @param userId the user id to search with
798             * @param start the lower bound of the range of phones to return
799             * @param end the upper bound of the range of phones to return (not inclusive)
800             * @param orderByComparator the comparator to order the results by
801             * @return the ordered range of matching phones
802             * @throws SystemException if a system exception occurred
803             */
804            public List<Phone> findByUserId(long userId, int start, int end,
805                    OrderByComparator orderByComparator) throws SystemException {
806                    Object[] finderArgs = new Object[] {
807                                    userId,
808                                    
809                                    String.valueOf(start), String.valueOf(end),
810                                    String.valueOf(orderByComparator)
811                            };
812    
813                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
814                                    finderArgs, this);
815    
816                    if (list == null) {
817                            Session session = null;
818    
819                            try {
820                                    session = openSession();
821    
822                                    StringBundler query = null;
823    
824                                    if (orderByComparator != null) {
825                                            query = new StringBundler(3 +
826                                                            (orderByComparator.getOrderByFields().length * 3));
827                                    }
828                                    else {
829                                            query = new StringBundler(3);
830                                    }
831    
832                                    query.append(_SQL_SELECT_PHONE_WHERE);
833    
834                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
835    
836                                    if (orderByComparator != null) {
837                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
838                                                    orderByComparator);
839                                    }
840    
841                                    else {
842                                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
843                                    }
844    
845                                    String sql = query.toString();
846    
847                                    Query q = session.createQuery(sql);
848    
849                                    QueryPos qPos = QueryPos.getInstance(q);
850    
851                                    qPos.add(userId);
852    
853                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
854                            }
855                            catch (Exception e) {
856                                    throw processException(e);
857                            }
858                            finally {
859                                    if (list == null) {
860                                            list = new ArrayList<Phone>();
861                                    }
862    
863                                    cacheResult(list);
864    
865                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
866                                            finderArgs, list);
867    
868                                    closeSession(session);
869                            }
870                    }
871    
872                    return list;
873            }
874    
875            /**
876             * Finds the first phone in the ordered set where userId = &#63;.
877             *
878             * <p>
879             * 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.
880             * </p>
881             *
882             * @param userId the user id to search with
883             * @param orderByComparator the comparator to order the set by
884             * @return the first matching phone
885             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
886             * @throws SystemException if a system exception occurred
887             */
888            public Phone findByUserId_First(long userId,
889                    OrderByComparator orderByComparator)
890                    throws NoSuchPhoneException, SystemException {
891                    List<Phone> list = findByUserId(userId, 0, 1, orderByComparator);
892    
893                    if (list.isEmpty()) {
894                            StringBundler msg = new StringBundler(4);
895    
896                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
897    
898                            msg.append("userId=");
899                            msg.append(userId);
900    
901                            msg.append(StringPool.CLOSE_CURLY_BRACE);
902    
903                            throw new NoSuchPhoneException(msg.toString());
904                    }
905                    else {
906                            return list.get(0);
907                    }
908            }
909    
910            /**
911             * Finds the last phone in the ordered set where userId = &#63;.
912             *
913             * <p>
914             * 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.
915             * </p>
916             *
917             * @param userId the user id to search with
918             * @param orderByComparator the comparator to order the set by
919             * @return the last matching phone
920             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
921             * @throws SystemException if a system exception occurred
922             */
923            public Phone findByUserId_Last(long userId,
924                    OrderByComparator orderByComparator)
925                    throws NoSuchPhoneException, SystemException {
926                    int count = countByUserId(userId);
927    
928                    List<Phone> list = findByUserId(userId, count - 1, count,
929                                    orderByComparator);
930    
931                    if (list.isEmpty()) {
932                            StringBundler msg = new StringBundler(4);
933    
934                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
935    
936                            msg.append("userId=");
937                            msg.append(userId);
938    
939                            msg.append(StringPool.CLOSE_CURLY_BRACE);
940    
941                            throw new NoSuchPhoneException(msg.toString());
942                    }
943                    else {
944                            return list.get(0);
945                    }
946            }
947    
948            /**
949             * Finds the phones before and after the current phone in the ordered set where userId = &#63;.
950             *
951             * <p>
952             * 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.
953             * </p>
954             *
955             * @param phoneId the primary key of the current phone
956             * @param userId the user id to search with
957             * @param orderByComparator the comparator to order the set by
958             * @return the previous, current, and next phone
959             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
960             * @throws SystemException if a system exception occurred
961             */
962            public Phone[] findByUserId_PrevAndNext(long phoneId, long userId,
963                    OrderByComparator orderByComparator)
964                    throws NoSuchPhoneException, SystemException {
965                    Phone phone = findByPrimaryKey(phoneId);
966    
967                    Session session = null;
968    
969                    try {
970                            session = openSession();
971    
972                            Phone[] array = new PhoneImpl[3];
973    
974                            array[0] = getByUserId_PrevAndNext(session, phone, userId,
975                                            orderByComparator, true);
976    
977                            array[1] = phone;
978    
979                            array[2] = getByUserId_PrevAndNext(session, phone, userId,
980                                            orderByComparator, false);
981    
982                            return array;
983                    }
984                    catch (Exception e) {
985                            throw processException(e);
986                    }
987                    finally {
988                            closeSession(session);
989                    }
990            }
991    
992            protected Phone getByUserId_PrevAndNext(Session session, Phone phone,
993                    long userId, OrderByComparator orderByComparator, boolean previous) {
994                    StringBundler query = null;
995    
996                    if (orderByComparator != null) {
997                            query = new StringBundler(6 +
998                                            (orderByComparator.getOrderByFields().length * 6));
999                    }
1000                    else {
1001                            query = new StringBundler(3);
1002                    }
1003    
1004                    query.append(_SQL_SELECT_PHONE_WHERE);
1005    
1006                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1007    
1008                    if (orderByComparator != null) {
1009                            String[] orderByFields = orderByComparator.getOrderByFields();
1010    
1011                            if (orderByFields.length > 0) {
1012                                    query.append(WHERE_AND);
1013                            }
1014    
1015                            for (int i = 0; i < orderByFields.length; i++) {
1016                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1017                                    query.append(orderByFields[i]);
1018    
1019                                    if ((i + 1) < orderByFields.length) {
1020                                            if (orderByComparator.isAscending() ^ previous) {
1021                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1022                                            }
1023                                            else {
1024                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1025                                            }
1026                                    }
1027                                    else {
1028                                            if (orderByComparator.isAscending() ^ previous) {
1029                                                    query.append(WHERE_GREATER_THAN);
1030                                            }
1031                                            else {
1032                                                    query.append(WHERE_LESSER_THAN);
1033                                            }
1034                                    }
1035                            }
1036    
1037                            query.append(ORDER_BY_CLAUSE);
1038    
1039                            for (int i = 0; i < orderByFields.length; i++) {
1040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1041                                    query.append(orderByFields[i]);
1042    
1043                                    if ((i + 1) < orderByFields.length) {
1044                                            if (orderByComparator.isAscending() ^ previous) {
1045                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1046                                            }
1047                                            else {
1048                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1049                                            }
1050                                    }
1051                                    else {
1052                                            if (orderByComparator.isAscending() ^ previous) {
1053                                                    query.append(ORDER_BY_ASC);
1054                                            }
1055                                            else {
1056                                                    query.append(ORDER_BY_DESC);
1057                                            }
1058                                    }
1059                            }
1060                    }
1061    
1062                    else {
1063                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1064                    }
1065    
1066                    String sql = query.toString();
1067    
1068                    Query q = session.createQuery(sql);
1069    
1070                    q.setFirstResult(0);
1071                    q.setMaxResults(2);
1072    
1073                    QueryPos qPos = QueryPos.getInstance(q);
1074    
1075                    qPos.add(userId);
1076    
1077                    if (orderByComparator != null) {
1078                            Object[] values = orderByComparator.getOrderByValues(phone);
1079    
1080                            for (Object value : values) {
1081                                    qPos.add(value);
1082                            }
1083                    }
1084    
1085                    List<Phone> list = q.list();
1086    
1087                    if (list.size() == 2) {
1088                            return list.get(1);
1089                    }
1090                    else {
1091                            return null;
1092                    }
1093            }
1094    
1095            /**
1096             * Finds all the phones where companyId = &#63; and classNameId = &#63;.
1097             *
1098             * @param companyId the company id to search with
1099             * @param classNameId the class name id to search with
1100             * @return the matching phones
1101             * @throws SystemException if a system exception occurred
1102             */
1103            public List<Phone> findByC_C(long companyId, long classNameId)
1104                    throws SystemException {
1105                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
1106                            QueryUtil.ALL_POS, null);
1107            }
1108    
1109            /**
1110             * Finds a range of all the phones where companyId = &#63; and classNameId = &#63;.
1111             *
1112             * <p>
1113             * 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.
1114             * </p>
1115             *
1116             * @param companyId the company id to search with
1117             * @param classNameId the class name id to search with
1118             * @param start the lower bound of the range of phones to return
1119             * @param end the upper bound of the range of phones to return (not inclusive)
1120             * @return the range of matching phones
1121             * @throws SystemException if a system exception occurred
1122             */
1123            public List<Phone> findByC_C(long companyId, long classNameId, int start,
1124                    int end) throws SystemException {
1125                    return findByC_C(companyId, classNameId, start, end, null);
1126            }
1127    
1128            /**
1129             * Finds an ordered range of all the phones where companyId = &#63; and classNameId = &#63;.
1130             *
1131             * <p>
1132             * 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.
1133             * </p>
1134             *
1135             * @param companyId the company id to search with
1136             * @param classNameId the class name id to search with
1137             * @param start the lower bound of the range of phones to return
1138             * @param end the upper bound of the range of phones to return (not inclusive)
1139             * @param orderByComparator the comparator to order the results by
1140             * @return the ordered range of matching phones
1141             * @throws SystemException if a system exception occurred
1142             */
1143            public List<Phone> findByC_C(long companyId, long classNameId, int start,
1144                    int end, OrderByComparator orderByComparator) throws SystemException {
1145                    Object[] finderArgs = new Object[] {
1146                                    companyId, classNameId,
1147                                    
1148                                    String.valueOf(start), String.valueOf(end),
1149                                    String.valueOf(orderByComparator)
1150                            };
1151    
1152                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
1153                                    finderArgs, this);
1154    
1155                    if (list == null) {
1156                            Session session = null;
1157    
1158                            try {
1159                                    session = openSession();
1160    
1161                                    StringBundler query = null;
1162    
1163                                    if (orderByComparator != null) {
1164                                            query = new StringBundler(4 +
1165                                                            (orderByComparator.getOrderByFields().length * 3));
1166                                    }
1167                                    else {
1168                                            query = new StringBundler(4);
1169                                    }
1170    
1171                                    query.append(_SQL_SELECT_PHONE_WHERE);
1172    
1173                                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1174    
1175                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1176    
1177                                    if (orderByComparator != null) {
1178                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1179                                                    orderByComparator);
1180                                    }
1181    
1182                                    else {
1183                                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1184                                    }
1185    
1186                                    String sql = query.toString();
1187    
1188                                    Query q = session.createQuery(sql);
1189    
1190                                    QueryPos qPos = QueryPos.getInstance(q);
1191    
1192                                    qPos.add(companyId);
1193    
1194                                    qPos.add(classNameId);
1195    
1196                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
1197                            }
1198                            catch (Exception e) {
1199                                    throw processException(e);
1200                            }
1201                            finally {
1202                                    if (list == null) {
1203                                            list = new ArrayList<Phone>();
1204                                    }
1205    
1206                                    cacheResult(list);
1207    
1208                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
1209                                            list);
1210    
1211                                    closeSession(session);
1212                            }
1213                    }
1214    
1215                    return list;
1216            }
1217    
1218            /**
1219             * Finds the first phone in the ordered set where companyId = &#63; and classNameId = &#63;.
1220             *
1221             * <p>
1222             * 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.
1223             * </p>
1224             *
1225             * @param companyId the company id to search with
1226             * @param classNameId the class name id to search with
1227             * @param orderByComparator the comparator to order the set by
1228             * @return the first matching phone
1229             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1230             * @throws SystemException if a system exception occurred
1231             */
1232            public Phone findByC_C_First(long companyId, long classNameId,
1233                    OrderByComparator orderByComparator)
1234                    throws NoSuchPhoneException, SystemException {
1235                    List<Phone> list = findByC_C(companyId, classNameId, 0, 1,
1236                                    orderByComparator);
1237    
1238                    if (list.isEmpty()) {
1239                            StringBundler msg = new StringBundler(6);
1240    
1241                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1242    
1243                            msg.append("companyId=");
1244                            msg.append(companyId);
1245    
1246                            msg.append(", classNameId=");
1247                            msg.append(classNameId);
1248    
1249                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1250    
1251                            throw new NoSuchPhoneException(msg.toString());
1252                    }
1253                    else {
1254                            return list.get(0);
1255                    }
1256            }
1257    
1258            /**
1259             * Finds the last phone in the ordered set where companyId = &#63; and classNameId = &#63;.
1260             *
1261             * <p>
1262             * 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.
1263             * </p>
1264             *
1265             * @param companyId the company id to search with
1266             * @param classNameId the class name id to search with
1267             * @param orderByComparator the comparator to order the set by
1268             * @return the last matching phone
1269             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1270             * @throws SystemException if a system exception occurred
1271             */
1272            public Phone findByC_C_Last(long companyId, long classNameId,
1273                    OrderByComparator orderByComparator)
1274                    throws NoSuchPhoneException, SystemException {
1275                    int count = countByC_C(companyId, classNameId);
1276    
1277                    List<Phone> list = findByC_C(companyId, classNameId, count - 1, count,
1278                                    orderByComparator);
1279    
1280                    if (list.isEmpty()) {
1281                            StringBundler msg = new StringBundler(6);
1282    
1283                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1284    
1285                            msg.append("companyId=");
1286                            msg.append(companyId);
1287    
1288                            msg.append(", classNameId=");
1289                            msg.append(classNameId);
1290    
1291                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1292    
1293                            throw new NoSuchPhoneException(msg.toString());
1294                    }
1295                    else {
1296                            return list.get(0);
1297                    }
1298            }
1299    
1300            /**
1301             * Finds the phones before and after the current phone in the ordered set where companyId = &#63; and classNameId = &#63;.
1302             *
1303             * <p>
1304             * 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.
1305             * </p>
1306             *
1307             * @param phoneId the primary key of the current phone
1308             * @param companyId the company id to search with
1309             * @param classNameId the class name id to search with
1310             * @param orderByComparator the comparator to order the set by
1311             * @return the previous, current, and next phone
1312             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
1313             * @throws SystemException if a system exception occurred
1314             */
1315            public Phone[] findByC_C_PrevAndNext(long phoneId, long companyId,
1316                    long classNameId, OrderByComparator orderByComparator)
1317                    throws NoSuchPhoneException, SystemException {
1318                    Phone phone = findByPrimaryKey(phoneId);
1319    
1320                    Session session = null;
1321    
1322                    try {
1323                            session = openSession();
1324    
1325                            Phone[] array = new PhoneImpl[3];
1326    
1327                            array[0] = getByC_C_PrevAndNext(session, phone, companyId,
1328                                            classNameId, orderByComparator, true);
1329    
1330                            array[1] = phone;
1331    
1332                            array[2] = getByC_C_PrevAndNext(session, phone, companyId,
1333                                            classNameId, orderByComparator, false);
1334    
1335                            return array;
1336                    }
1337                    catch (Exception e) {
1338                            throw processException(e);
1339                    }
1340                    finally {
1341                            closeSession(session);
1342                    }
1343            }
1344    
1345            protected Phone getByC_C_PrevAndNext(Session session, Phone phone,
1346                    long companyId, long classNameId, OrderByComparator orderByComparator,
1347                    boolean previous) {
1348                    StringBundler query = null;
1349    
1350                    if (orderByComparator != null) {
1351                            query = new StringBundler(6 +
1352                                            (orderByComparator.getOrderByFields().length * 6));
1353                    }
1354                    else {
1355                            query = new StringBundler(3);
1356                    }
1357    
1358                    query.append(_SQL_SELECT_PHONE_WHERE);
1359    
1360                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1361    
1362                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1363    
1364                    if (orderByComparator != null) {
1365                            String[] orderByFields = orderByComparator.getOrderByFields();
1366    
1367                            if (orderByFields.length > 0) {
1368                                    query.append(WHERE_AND);
1369                            }
1370    
1371                            for (int i = 0; i < orderByFields.length; i++) {
1372                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1373                                    query.append(orderByFields[i]);
1374    
1375                                    if ((i + 1) < orderByFields.length) {
1376                                            if (orderByComparator.isAscending() ^ previous) {
1377                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1378                                            }
1379                                            else {
1380                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1381                                            }
1382                                    }
1383                                    else {
1384                                            if (orderByComparator.isAscending() ^ previous) {
1385                                                    query.append(WHERE_GREATER_THAN);
1386                                            }
1387                                            else {
1388                                                    query.append(WHERE_LESSER_THAN);
1389                                            }
1390                                    }
1391                            }
1392    
1393                            query.append(ORDER_BY_CLAUSE);
1394    
1395                            for (int i = 0; i < orderByFields.length; i++) {
1396                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1397                                    query.append(orderByFields[i]);
1398    
1399                                    if ((i + 1) < orderByFields.length) {
1400                                            if (orderByComparator.isAscending() ^ previous) {
1401                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1402                                            }
1403                                            else {
1404                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1405                                            }
1406                                    }
1407                                    else {
1408                                            if (orderByComparator.isAscending() ^ previous) {
1409                                                    query.append(ORDER_BY_ASC);
1410                                            }
1411                                            else {
1412                                                    query.append(ORDER_BY_DESC);
1413                                            }
1414                                    }
1415                            }
1416                    }
1417    
1418                    else {
1419                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1420                    }
1421    
1422                    String sql = query.toString();
1423    
1424                    Query q = session.createQuery(sql);
1425    
1426                    q.setFirstResult(0);
1427                    q.setMaxResults(2);
1428    
1429                    QueryPos qPos = QueryPos.getInstance(q);
1430    
1431                    qPos.add(companyId);
1432    
1433                    qPos.add(classNameId);
1434    
1435                    if (orderByComparator != null) {
1436                            Object[] values = orderByComparator.getOrderByValues(phone);
1437    
1438                            for (Object value : values) {
1439                                    qPos.add(value);
1440                            }
1441                    }
1442    
1443                    List<Phone> list = q.list();
1444    
1445                    if (list.size() == 2) {
1446                            return list.get(1);
1447                    }
1448                    else {
1449                            return null;
1450                    }
1451            }
1452    
1453            /**
1454             * Finds all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1455             *
1456             * @param companyId the company id to search with
1457             * @param classNameId the class name id to search with
1458             * @param classPK the class p k to search with
1459             * @return the matching phones
1460             * @throws SystemException if a system exception occurred
1461             */
1462            public List<Phone> findByC_C_C(long companyId, long classNameId,
1463                    long classPK) throws SystemException {
1464                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1465                            QueryUtil.ALL_POS, null);
1466            }
1467    
1468            /**
1469             * Finds a range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1470             *
1471             * <p>
1472             * 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.
1473             * </p>
1474             *
1475             * @param companyId the company id to search with
1476             * @param classNameId the class name id to search with
1477             * @param classPK the class p k to search with
1478             * @param start the lower bound of the range of phones to return
1479             * @param end the upper bound of the range of phones to return (not inclusive)
1480             * @return the range of matching phones
1481             * @throws SystemException if a system exception occurred
1482             */
1483            public List<Phone> findByC_C_C(long companyId, long classNameId,
1484                    long classPK, int start, int end) throws SystemException {
1485                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1486            }
1487    
1488            /**
1489             * Finds an ordered range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1490             *
1491             * <p>
1492             * 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.
1493             * </p>
1494             *
1495             * @param companyId the company id to search with
1496             * @param classNameId the class name id to search with
1497             * @param classPK the class p k to search with
1498             * @param start the lower bound of the range of phones to return
1499             * @param end the upper bound of the range of phones to return (not inclusive)
1500             * @param orderByComparator the comparator to order the results by
1501             * @return the ordered range of matching phones
1502             * @throws SystemException if a system exception occurred
1503             */
1504            public List<Phone> findByC_C_C(long companyId, long classNameId,
1505                    long classPK, int start, int end, OrderByComparator orderByComparator)
1506                    throws SystemException {
1507                    Object[] finderArgs = new Object[] {
1508                                    companyId, classNameId, classPK,
1509                                    
1510                                    String.valueOf(start), String.valueOf(end),
1511                                    String.valueOf(orderByComparator)
1512                            };
1513    
1514                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C,
1515                                    finderArgs, this);
1516    
1517                    if (list == null) {
1518                            Session session = null;
1519    
1520                            try {
1521                                    session = openSession();
1522    
1523                                    StringBundler query = null;
1524    
1525                                    if (orderByComparator != null) {
1526                                            query = new StringBundler(5 +
1527                                                            (orderByComparator.getOrderByFields().length * 3));
1528                                    }
1529                                    else {
1530                                            query = new StringBundler(5);
1531                                    }
1532    
1533                                    query.append(_SQL_SELECT_PHONE_WHERE);
1534    
1535                                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1536    
1537                                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1538    
1539                                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1540    
1541                                    if (orderByComparator != null) {
1542                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1543                                                    orderByComparator);
1544                                    }
1545    
1546                                    else {
1547                                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1548                                    }
1549    
1550                                    String sql = query.toString();
1551    
1552                                    Query q = session.createQuery(sql);
1553    
1554                                    QueryPos qPos = QueryPos.getInstance(q);
1555    
1556                                    qPos.add(companyId);
1557    
1558                                    qPos.add(classNameId);
1559    
1560                                    qPos.add(classPK);
1561    
1562                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
1563                            }
1564                            catch (Exception e) {
1565                                    throw processException(e);
1566                            }
1567                            finally {
1568                                    if (list == null) {
1569                                            list = new ArrayList<Phone>();
1570                                    }
1571    
1572                                    cacheResult(list);
1573    
1574                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C,
1575                                            finderArgs, list);
1576    
1577                                    closeSession(session);
1578                            }
1579                    }
1580    
1581                    return list;
1582            }
1583    
1584            /**
1585             * Finds the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1586             *
1587             * <p>
1588             * 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.
1589             * </p>
1590             *
1591             * @param companyId the company id to search with
1592             * @param classNameId the class name id to search with
1593             * @param classPK the class p k to search with
1594             * @param orderByComparator the comparator to order the set by
1595             * @return the first matching phone
1596             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1597             * @throws SystemException if a system exception occurred
1598             */
1599            public Phone findByC_C_C_First(long companyId, long classNameId,
1600                    long classPK, OrderByComparator orderByComparator)
1601                    throws NoSuchPhoneException, SystemException {
1602                    List<Phone> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
1603                                    orderByComparator);
1604    
1605                    if (list.isEmpty()) {
1606                            StringBundler msg = new StringBundler(8);
1607    
1608                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1609    
1610                            msg.append("companyId=");
1611                            msg.append(companyId);
1612    
1613                            msg.append(", classNameId=");
1614                            msg.append(classNameId);
1615    
1616                            msg.append(", classPK=");
1617                            msg.append(classPK);
1618    
1619                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1620    
1621                            throw new NoSuchPhoneException(msg.toString());
1622                    }
1623                    else {
1624                            return list.get(0);
1625                    }
1626            }
1627    
1628            /**
1629             * Finds the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1630             *
1631             * <p>
1632             * 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.
1633             * </p>
1634             *
1635             * @param companyId the company id to search with
1636             * @param classNameId the class name id to search with
1637             * @param classPK the class p k to search with
1638             * @param orderByComparator the comparator to order the set by
1639             * @return the last matching phone
1640             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1641             * @throws SystemException if a system exception occurred
1642             */
1643            public Phone findByC_C_C_Last(long companyId, long classNameId,
1644                    long classPK, OrderByComparator orderByComparator)
1645                    throws NoSuchPhoneException, SystemException {
1646                    int count = countByC_C_C(companyId, classNameId, classPK);
1647    
1648                    List<Phone> list = findByC_C_C(companyId, classNameId, classPK,
1649                                    count - 1, count, orderByComparator);
1650    
1651                    if (list.isEmpty()) {
1652                            StringBundler msg = new StringBundler(8);
1653    
1654                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1655    
1656                            msg.append("companyId=");
1657                            msg.append(companyId);
1658    
1659                            msg.append(", classNameId=");
1660                            msg.append(classNameId);
1661    
1662                            msg.append(", classPK=");
1663                            msg.append(classPK);
1664    
1665                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1666    
1667                            throw new NoSuchPhoneException(msg.toString());
1668                    }
1669                    else {
1670                            return list.get(0);
1671                    }
1672            }
1673    
1674            /**
1675             * Finds the phones before and after the current phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1676             *
1677             * <p>
1678             * 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.
1679             * </p>
1680             *
1681             * @param phoneId the primary key of the current phone
1682             * @param companyId the company id to search with
1683             * @param classNameId the class name id to search with
1684             * @param classPK the class p k to search with
1685             * @param orderByComparator the comparator to order the set by
1686             * @return the previous, current, and next phone
1687             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
1688             * @throws SystemException if a system exception occurred
1689             */
1690            public Phone[] findByC_C_C_PrevAndNext(long phoneId, long companyId,
1691                    long classNameId, long classPK, OrderByComparator orderByComparator)
1692                    throws NoSuchPhoneException, SystemException {
1693                    Phone phone = findByPrimaryKey(phoneId);
1694    
1695                    Session session = null;
1696    
1697                    try {
1698                            session = openSession();
1699    
1700                            Phone[] array = new PhoneImpl[3];
1701    
1702                            array[0] = getByC_C_C_PrevAndNext(session, phone, companyId,
1703                                            classNameId, classPK, orderByComparator, true);
1704    
1705                            array[1] = phone;
1706    
1707                            array[2] = getByC_C_C_PrevAndNext(session, phone, companyId,
1708                                            classNameId, classPK, orderByComparator, false);
1709    
1710                            return array;
1711                    }
1712                    catch (Exception e) {
1713                            throw processException(e);
1714                    }
1715                    finally {
1716                            closeSession(session);
1717                    }
1718            }
1719    
1720            protected Phone getByC_C_C_PrevAndNext(Session session, Phone phone,
1721                    long companyId, long classNameId, long classPK,
1722                    OrderByComparator orderByComparator, boolean previous) {
1723                    StringBundler query = null;
1724    
1725                    if (orderByComparator != null) {
1726                            query = new StringBundler(6 +
1727                                            (orderByComparator.getOrderByFields().length * 6));
1728                    }
1729                    else {
1730                            query = new StringBundler(3);
1731                    }
1732    
1733                    query.append(_SQL_SELECT_PHONE_WHERE);
1734    
1735                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1736    
1737                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1738    
1739                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1740    
1741                    if (orderByComparator != null) {
1742                            String[] orderByFields = orderByComparator.getOrderByFields();
1743    
1744                            if (orderByFields.length > 0) {
1745                                    query.append(WHERE_AND);
1746                            }
1747    
1748                            for (int i = 0; i < orderByFields.length; i++) {
1749                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1750                                    query.append(orderByFields[i]);
1751    
1752                                    if ((i + 1) < orderByFields.length) {
1753                                            if (orderByComparator.isAscending() ^ previous) {
1754                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1755                                            }
1756                                            else {
1757                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1758                                            }
1759                                    }
1760                                    else {
1761                                            if (orderByComparator.isAscending() ^ previous) {
1762                                                    query.append(WHERE_GREATER_THAN);
1763                                            }
1764                                            else {
1765                                                    query.append(WHERE_LESSER_THAN);
1766                                            }
1767                                    }
1768                            }
1769    
1770                            query.append(ORDER_BY_CLAUSE);
1771    
1772                            for (int i = 0; i < orderByFields.length; i++) {
1773                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1774                                    query.append(orderByFields[i]);
1775    
1776                                    if ((i + 1) < orderByFields.length) {
1777                                            if (orderByComparator.isAscending() ^ previous) {
1778                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1779                                            }
1780                                            else {
1781                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1782                                            }
1783                                    }
1784                                    else {
1785                                            if (orderByComparator.isAscending() ^ previous) {
1786                                                    query.append(ORDER_BY_ASC);
1787                                            }
1788                                            else {
1789                                                    query.append(ORDER_BY_DESC);
1790                                            }
1791                                    }
1792                            }
1793                    }
1794    
1795                    else {
1796                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1797                    }
1798    
1799                    String sql = query.toString();
1800    
1801                    Query q = session.createQuery(sql);
1802    
1803                    q.setFirstResult(0);
1804                    q.setMaxResults(2);
1805    
1806                    QueryPos qPos = QueryPos.getInstance(q);
1807    
1808                    qPos.add(companyId);
1809    
1810                    qPos.add(classNameId);
1811    
1812                    qPos.add(classPK);
1813    
1814                    if (orderByComparator != null) {
1815                            Object[] values = orderByComparator.getOrderByValues(phone);
1816    
1817                            for (Object value : values) {
1818                                    qPos.add(value);
1819                            }
1820                    }
1821    
1822                    List<Phone> list = q.list();
1823    
1824                    if (list.size() == 2) {
1825                            return list.get(1);
1826                    }
1827                    else {
1828                            return null;
1829                    }
1830            }
1831    
1832            /**
1833             * Finds all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
1834             *
1835             * @param companyId the company id to search with
1836             * @param classNameId the class name id to search with
1837             * @param classPK the class p k to search with
1838             * @param primary the primary to search with
1839             * @return the matching phones
1840             * @throws SystemException if a system exception occurred
1841             */
1842            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
1843                    long classPK, boolean primary) throws SystemException {
1844                    return findByC_C_C_P(companyId, classNameId, classPK, primary,
1845                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1846            }
1847    
1848            /**
1849             * Finds a range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
1850             *
1851             * <p>
1852             * 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.
1853             * </p>
1854             *
1855             * @param companyId the company id to search with
1856             * @param classNameId the class name id to search with
1857             * @param classPK the class p k to search with
1858             * @param primary the primary to search with
1859             * @param start the lower bound of the range of phones to return
1860             * @param end the upper bound of the range of phones to return (not inclusive)
1861             * @return the range of matching phones
1862             * @throws SystemException if a system exception occurred
1863             */
1864            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
1865                    long classPK, boolean primary, int start, int end)
1866                    throws SystemException {
1867                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
1868                            end, null);
1869            }
1870    
1871            /**
1872             * Finds an ordered range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
1873             *
1874             * <p>
1875             * 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.
1876             * </p>
1877             *
1878             * @param companyId the company id to search with
1879             * @param classNameId the class name id to search with
1880             * @param classPK the class p k to search with
1881             * @param primary the primary to search with
1882             * @param start the lower bound of the range of phones to return
1883             * @param end the upper bound of the range of phones to return (not inclusive)
1884             * @param orderByComparator the comparator to order the results by
1885             * @return the ordered range of matching phones
1886             * @throws SystemException if a system exception occurred
1887             */
1888            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
1889                    long classPK, boolean primary, int start, int end,
1890                    OrderByComparator orderByComparator) throws SystemException {
1891                    Object[] finderArgs = new Object[] {
1892                                    companyId, classNameId, classPK, primary,
1893                                    
1894                                    String.valueOf(start), String.valueOf(end),
1895                                    String.valueOf(orderByComparator)
1896                            };
1897    
1898                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C_P,
1899                                    finderArgs, this);
1900    
1901                    if (list == null) {
1902                            Session session = null;
1903    
1904                            try {
1905                                    session = openSession();
1906    
1907                                    StringBundler query = null;
1908    
1909                                    if (orderByComparator != null) {
1910                                            query = new StringBundler(6 +
1911                                                            (orderByComparator.getOrderByFields().length * 3));
1912                                    }
1913                                    else {
1914                                            query = new StringBundler(6);
1915                                    }
1916    
1917                                    query.append(_SQL_SELECT_PHONE_WHERE);
1918    
1919                                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
1920    
1921                                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
1922    
1923                                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
1924    
1925                                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
1926    
1927                                    if (orderByComparator != null) {
1928                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1929                                                    orderByComparator);
1930                                    }
1931    
1932                                    else {
1933                                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1934                                    }
1935    
1936                                    String sql = query.toString();
1937    
1938                                    Query q = session.createQuery(sql);
1939    
1940                                    QueryPos qPos = QueryPos.getInstance(q);
1941    
1942                                    qPos.add(companyId);
1943    
1944                                    qPos.add(classNameId);
1945    
1946                                    qPos.add(classPK);
1947    
1948                                    qPos.add(primary);
1949    
1950                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
1951                            }
1952                            catch (Exception e) {
1953                                    throw processException(e);
1954                            }
1955                            finally {
1956                                    if (list == null) {
1957                                            list = new ArrayList<Phone>();
1958                                    }
1959    
1960                                    cacheResult(list);
1961    
1962                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C_P,
1963                                            finderArgs, list);
1964    
1965                                    closeSession(session);
1966                            }
1967                    }
1968    
1969                    return list;
1970            }
1971    
1972            /**
1973             * Finds the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
1974             *
1975             * <p>
1976             * 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.
1977             * </p>
1978             *
1979             * @param companyId the company id to search with
1980             * @param classNameId the class name id to search with
1981             * @param classPK the class p k to search with
1982             * @param primary the primary to search with
1983             * @param orderByComparator the comparator to order the set by
1984             * @return the first matching phone
1985             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1986             * @throws SystemException if a system exception occurred
1987             */
1988            public Phone findByC_C_C_P_First(long companyId, long classNameId,
1989                    long classPK, boolean primary, OrderByComparator orderByComparator)
1990                    throws NoSuchPhoneException, SystemException {
1991                    List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
1992                                    primary, 0, 1, orderByComparator);
1993    
1994                    if (list.isEmpty()) {
1995                            StringBundler msg = new StringBundler(10);
1996    
1997                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1998    
1999                            msg.append("companyId=");
2000                            msg.append(companyId);
2001    
2002                            msg.append(", classNameId=");
2003                            msg.append(classNameId);
2004    
2005                            msg.append(", classPK=");
2006                            msg.append(classPK);
2007    
2008                            msg.append(", primary=");
2009                            msg.append(primary);
2010    
2011                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2012    
2013                            throw new NoSuchPhoneException(msg.toString());
2014                    }
2015                    else {
2016                            return list.get(0);
2017                    }
2018            }
2019    
2020            /**
2021             * Finds the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2022             *
2023             * <p>
2024             * 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.
2025             * </p>
2026             *
2027             * @param companyId the company id to search with
2028             * @param classNameId the class name id to search with
2029             * @param classPK the class p k to search with
2030             * @param primary the primary to search with
2031             * @param orderByComparator the comparator to order the set by
2032             * @return the last matching phone
2033             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
2034             * @throws SystemException if a system exception occurred
2035             */
2036            public Phone findByC_C_C_P_Last(long companyId, long classNameId,
2037                    long classPK, boolean primary, OrderByComparator orderByComparator)
2038                    throws NoSuchPhoneException, SystemException {
2039                    int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
2040    
2041                    List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
2042                                    primary, count - 1, count, orderByComparator);
2043    
2044                    if (list.isEmpty()) {
2045                            StringBundler msg = new StringBundler(10);
2046    
2047                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2048    
2049                            msg.append("companyId=");
2050                            msg.append(companyId);
2051    
2052                            msg.append(", classNameId=");
2053                            msg.append(classNameId);
2054    
2055                            msg.append(", classPK=");
2056                            msg.append(classPK);
2057    
2058                            msg.append(", primary=");
2059                            msg.append(primary);
2060    
2061                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2062    
2063                            throw new NoSuchPhoneException(msg.toString());
2064                    }
2065                    else {
2066                            return list.get(0);
2067                    }
2068            }
2069    
2070            /**
2071             * Finds the phones before and after the current phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2072             *
2073             * <p>
2074             * 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.
2075             * </p>
2076             *
2077             * @param phoneId the primary key of the current phone
2078             * @param companyId the company id to search with
2079             * @param classNameId the class name id to search with
2080             * @param classPK the class p k to search with
2081             * @param primary the primary to search with
2082             * @param orderByComparator the comparator to order the set by
2083             * @return the previous, current, and next phone
2084             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
2085             * @throws SystemException if a system exception occurred
2086             */
2087            public Phone[] findByC_C_C_P_PrevAndNext(long phoneId, long companyId,
2088                    long classNameId, long classPK, boolean primary,
2089                    OrderByComparator orderByComparator)
2090                    throws NoSuchPhoneException, SystemException {
2091                    Phone phone = findByPrimaryKey(phoneId);
2092    
2093                    Session session = null;
2094    
2095                    try {
2096                            session = openSession();
2097    
2098                            Phone[] array = new PhoneImpl[3];
2099    
2100                            array[0] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
2101                                            classNameId, classPK, primary, orderByComparator, true);
2102    
2103                            array[1] = phone;
2104    
2105                            array[2] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
2106                                            classNameId, classPK, primary, orderByComparator, false);
2107    
2108                            return array;
2109                    }
2110                    catch (Exception e) {
2111                            throw processException(e);
2112                    }
2113                    finally {
2114                            closeSession(session);
2115                    }
2116            }
2117    
2118            protected Phone getByC_C_C_P_PrevAndNext(Session session, Phone phone,
2119                    long companyId, long classNameId, long classPK, boolean primary,
2120                    OrderByComparator orderByComparator, boolean previous) {
2121                    StringBundler query = null;
2122    
2123                    if (orderByComparator != null) {
2124                            query = new StringBundler(6 +
2125                                            (orderByComparator.getOrderByFields().length * 6));
2126                    }
2127                    else {
2128                            query = new StringBundler(3);
2129                    }
2130    
2131                    query.append(_SQL_SELECT_PHONE_WHERE);
2132    
2133                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2134    
2135                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2136    
2137                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2138    
2139                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2140    
2141                    if (orderByComparator != null) {
2142                            String[] orderByFields = orderByComparator.getOrderByFields();
2143    
2144                            if (orderByFields.length > 0) {
2145                                    query.append(WHERE_AND);
2146                            }
2147    
2148                            for (int i = 0; i < orderByFields.length; i++) {
2149                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2150                                    query.append(orderByFields[i]);
2151    
2152                                    if ((i + 1) < orderByFields.length) {
2153                                            if (orderByComparator.isAscending() ^ previous) {
2154                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2155                                            }
2156                                            else {
2157                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2158                                            }
2159                                    }
2160                                    else {
2161                                            if (orderByComparator.isAscending() ^ previous) {
2162                                                    query.append(WHERE_GREATER_THAN);
2163                                            }
2164                                            else {
2165                                                    query.append(WHERE_LESSER_THAN);
2166                                            }
2167                                    }
2168                            }
2169    
2170                            query.append(ORDER_BY_CLAUSE);
2171    
2172                            for (int i = 0; i < orderByFields.length; i++) {
2173                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2174                                    query.append(orderByFields[i]);
2175    
2176                                    if ((i + 1) < orderByFields.length) {
2177                                            if (orderByComparator.isAscending() ^ previous) {
2178                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2179                                            }
2180                                            else {
2181                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2182                                            }
2183                                    }
2184                                    else {
2185                                            if (orderByComparator.isAscending() ^ previous) {
2186                                                    query.append(ORDER_BY_ASC);
2187                                            }
2188                                            else {
2189                                                    query.append(ORDER_BY_DESC);
2190                                            }
2191                                    }
2192                            }
2193                    }
2194    
2195                    else {
2196                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
2197                    }
2198    
2199                    String sql = query.toString();
2200    
2201                    Query q = session.createQuery(sql);
2202    
2203                    q.setFirstResult(0);
2204                    q.setMaxResults(2);
2205    
2206                    QueryPos qPos = QueryPos.getInstance(q);
2207    
2208                    qPos.add(companyId);
2209    
2210                    qPos.add(classNameId);
2211    
2212                    qPos.add(classPK);
2213    
2214                    qPos.add(primary);
2215    
2216                    if (orderByComparator != null) {
2217                            Object[] values = orderByComparator.getOrderByValues(phone);
2218    
2219                            for (Object value : values) {
2220                                    qPos.add(value);
2221                            }
2222                    }
2223    
2224                    List<Phone> list = q.list();
2225    
2226                    if (list.size() == 2) {
2227                            return list.get(1);
2228                    }
2229                    else {
2230                            return null;
2231                    }
2232            }
2233    
2234            /**
2235             * Finds all the phones.
2236             *
2237             * @return the phones
2238             * @throws SystemException if a system exception occurred
2239             */
2240            public List<Phone> findAll() throws SystemException {
2241                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2242            }
2243    
2244            /**
2245             * Finds a range of all the phones.
2246             *
2247             * <p>
2248             * 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.
2249             * </p>
2250             *
2251             * @param start the lower bound of the range of phones to return
2252             * @param end the upper bound of the range of phones to return (not inclusive)
2253             * @return the range of phones
2254             * @throws SystemException if a system exception occurred
2255             */
2256            public List<Phone> findAll(int start, int end) throws SystemException {
2257                    return findAll(start, end, null);
2258            }
2259    
2260            /**
2261             * Finds an ordered range of all the phones.
2262             *
2263             * <p>
2264             * 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.
2265             * </p>
2266             *
2267             * @param start the lower bound of the range of phones to return
2268             * @param end the upper bound of the range of phones to return (not inclusive)
2269             * @param orderByComparator the comparator to order the results by
2270             * @return the ordered range of phones
2271             * @throws SystemException if a system exception occurred
2272             */
2273            public List<Phone> findAll(int start, int end,
2274                    OrderByComparator orderByComparator) throws SystemException {
2275                    Object[] finderArgs = new Object[] {
2276                                    String.valueOf(start), String.valueOf(end),
2277                                    String.valueOf(orderByComparator)
2278                            };
2279    
2280                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2281                                    finderArgs, this);
2282    
2283                    if (list == null) {
2284                            Session session = null;
2285    
2286                            try {
2287                                    session = openSession();
2288    
2289                                    StringBundler query = null;
2290                                    String sql = null;
2291    
2292                                    if (orderByComparator != null) {
2293                                            query = new StringBundler(2 +
2294                                                            (orderByComparator.getOrderByFields().length * 3));
2295    
2296                                            query.append(_SQL_SELECT_PHONE);
2297    
2298                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2299                                                    orderByComparator);
2300    
2301                                            sql = query.toString();
2302                                    }
2303                                    else {
2304                                            sql = _SQL_SELECT_PHONE.concat(PhoneModelImpl.ORDER_BY_JPQL);
2305                                    }
2306    
2307                                    Query q = session.createQuery(sql);
2308    
2309                                    if (orderByComparator == null) {
2310                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2311                                                            end, false);
2312    
2313                                            Collections.sort(list);
2314                                    }
2315                                    else {
2316                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2317                                                            end);
2318                                    }
2319                            }
2320                            catch (Exception e) {
2321                                    throw processException(e);
2322                            }
2323                            finally {
2324                                    if (list == null) {
2325                                            list = new ArrayList<Phone>();
2326                                    }
2327    
2328                                    cacheResult(list);
2329    
2330                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2331    
2332                                    closeSession(session);
2333                            }
2334                    }
2335    
2336                    return list;
2337            }
2338    
2339            /**
2340             * Removes all the phones where companyId = &#63; from the database.
2341             *
2342             * @param companyId the company id to search with
2343             * @throws SystemException if a system exception occurred
2344             */
2345            public void removeByCompanyId(long companyId) throws SystemException {
2346                    for (Phone phone : findByCompanyId(companyId)) {
2347                            remove(phone);
2348                    }
2349            }
2350    
2351            /**
2352             * Removes all the phones where userId = &#63; from the database.
2353             *
2354             * @param userId the user id to search with
2355             * @throws SystemException if a system exception occurred
2356             */
2357            public void removeByUserId(long userId) throws SystemException {
2358                    for (Phone phone : findByUserId(userId)) {
2359                            remove(phone);
2360                    }
2361            }
2362    
2363            /**
2364             * Removes all the phones where companyId = &#63; and classNameId = &#63; from the database.
2365             *
2366             * @param companyId the company id to search with
2367             * @param classNameId the class name id to search with
2368             * @throws SystemException if a system exception occurred
2369             */
2370            public void removeByC_C(long companyId, long classNameId)
2371                    throws SystemException {
2372                    for (Phone phone : findByC_C(companyId, classNameId)) {
2373                            remove(phone);
2374                    }
2375            }
2376    
2377            /**
2378             * Removes all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2379             *
2380             * @param companyId the company id to search with
2381             * @param classNameId the class name id to search with
2382             * @param classPK the class p k to search with
2383             * @throws SystemException if a system exception occurred
2384             */
2385            public void removeByC_C_C(long companyId, long classNameId, long classPK)
2386                    throws SystemException {
2387                    for (Phone phone : findByC_C_C(companyId, classNameId, classPK)) {
2388                            remove(phone);
2389                    }
2390            }
2391    
2392            /**
2393             * Removes all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63; from the database.
2394             *
2395             * @param companyId the company id to search with
2396             * @param classNameId the class name id to search with
2397             * @param classPK the class p k to search with
2398             * @param primary the primary to search with
2399             * @throws SystemException if a system exception occurred
2400             */
2401            public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
2402                    boolean primary) throws SystemException {
2403                    for (Phone phone : findByC_C_C_P(companyId, classNameId, classPK,
2404                                    primary)) {
2405                            remove(phone);
2406                    }
2407            }
2408    
2409            /**
2410             * Removes all the phones from the database.
2411             *
2412             * @throws SystemException if a system exception occurred
2413             */
2414            public void removeAll() throws SystemException {
2415                    for (Phone phone : findAll()) {
2416                            remove(phone);
2417                    }
2418            }
2419    
2420            /**
2421             * Counts all the phones where companyId = &#63;.
2422             *
2423             * @param companyId the company id to search with
2424             * @return the number of matching phones
2425             * @throws SystemException if a system exception occurred
2426             */
2427            public int countByCompanyId(long companyId) throws SystemException {
2428                    Object[] finderArgs = new Object[] { companyId };
2429    
2430                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2431                                    finderArgs, this);
2432    
2433                    if (count == null) {
2434                            Session session = null;
2435    
2436                            try {
2437                                    session = openSession();
2438    
2439                                    StringBundler query = new StringBundler(2);
2440    
2441                                    query.append(_SQL_COUNT_PHONE_WHERE);
2442    
2443                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2444    
2445                                    String sql = query.toString();
2446    
2447                                    Query q = session.createQuery(sql);
2448    
2449                                    QueryPos qPos = QueryPos.getInstance(q);
2450    
2451                                    qPos.add(companyId);
2452    
2453                                    count = (Long)q.uniqueResult();
2454                            }
2455                            catch (Exception e) {
2456                                    throw processException(e);
2457                            }
2458                            finally {
2459                                    if (count == null) {
2460                                            count = Long.valueOf(0);
2461                                    }
2462    
2463                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2464                                            finderArgs, count);
2465    
2466                                    closeSession(session);
2467                            }
2468                    }
2469    
2470                    return count.intValue();
2471            }
2472    
2473            /**
2474             * Counts all the phones where userId = &#63;.
2475             *
2476             * @param userId the user id to search with
2477             * @return the number of matching phones
2478             * @throws SystemException if a system exception occurred
2479             */
2480            public int countByUserId(long userId) throws SystemException {
2481                    Object[] finderArgs = new Object[] { userId };
2482    
2483                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2484                                    finderArgs, this);
2485    
2486                    if (count == null) {
2487                            Session session = null;
2488    
2489                            try {
2490                                    session = openSession();
2491    
2492                                    StringBundler query = new StringBundler(2);
2493    
2494                                    query.append(_SQL_COUNT_PHONE_WHERE);
2495    
2496                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2497    
2498                                    String sql = query.toString();
2499    
2500                                    Query q = session.createQuery(sql);
2501    
2502                                    QueryPos qPos = QueryPos.getInstance(q);
2503    
2504                                    qPos.add(userId);
2505    
2506                                    count = (Long)q.uniqueResult();
2507                            }
2508                            catch (Exception e) {
2509                                    throw processException(e);
2510                            }
2511                            finally {
2512                                    if (count == null) {
2513                                            count = Long.valueOf(0);
2514                                    }
2515    
2516                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2517                                            finderArgs, count);
2518    
2519                                    closeSession(session);
2520                            }
2521                    }
2522    
2523                    return count.intValue();
2524            }
2525    
2526            /**
2527             * Counts all the phones where companyId = &#63; and classNameId = &#63;.
2528             *
2529             * @param companyId the company id to search with
2530             * @param classNameId the class name id to search with
2531             * @return the number of matching phones
2532             * @throws SystemException if a system exception occurred
2533             */
2534            public int countByC_C(long companyId, long classNameId)
2535                    throws SystemException {
2536                    Object[] finderArgs = new Object[] { companyId, classNameId };
2537    
2538                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
2539                                    finderArgs, this);
2540    
2541                    if (count == null) {
2542                            Session session = null;
2543    
2544                            try {
2545                                    session = openSession();
2546    
2547                                    StringBundler query = new StringBundler(3);
2548    
2549                                    query.append(_SQL_COUNT_PHONE_WHERE);
2550    
2551                                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2552    
2553                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2554    
2555                                    String sql = query.toString();
2556    
2557                                    Query q = session.createQuery(sql);
2558    
2559                                    QueryPos qPos = QueryPos.getInstance(q);
2560    
2561                                    qPos.add(companyId);
2562    
2563                                    qPos.add(classNameId);
2564    
2565                                    count = (Long)q.uniqueResult();
2566                            }
2567                            catch (Exception e) {
2568                                    throw processException(e);
2569                            }
2570                            finally {
2571                                    if (count == null) {
2572                                            count = Long.valueOf(0);
2573                                    }
2574    
2575                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2576                                            count);
2577    
2578                                    closeSession(session);
2579                            }
2580                    }
2581    
2582                    return count.intValue();
2583            }
2584    
2585            /**
2586             * Counts all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2587             *
2588             * @param companyId the company id to search with
2589             * @param classNameId the class name id to search with
2590             * @param classPK the class p k to search with
2591             * @return the number of matching phones
2592             * @throws SystemException if a system exception occurred
2593             */
2594            public int countByC_C_C(long companyId, long classNameId, long classPK)
2595                    throws SystemException {
2596                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2597    
2598                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
2599                                    finderArgs, this);
2600    
2601                    if (count == null) {
2602                            Session session = null;
2603    
2604                            try {
2605                                    session = openSession();
2606    
2607                                    StringBundler query = new StringBundler(4);
2608    
2609                                    query.append(_SQL_COUNT_PHONE_WHERE);
2610    
2611                                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2612    
2613                                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2614    
2615                                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2616    
2617                                    String sql = query.toString();
2618    
2619                                    Query q = session.createQuery(sql);
2620    
2621                                    QueryPos qPos = QueryPos.getInstance(q);
2622    
2623                                    qPos.add(companyId);
2624    
2625                                    qPos.add(classNameId);
2626    
2627                                    qPos.add(classPK);
2628    
2629                                    count = (Long)q.uniqueResult();
2630                            }
2631                            catch (Exception e) {
2632                                    throw processException(e);
2633                            }
2634                            finally {
2635                                    if (count == null) {
2636                                            count = Long.valueOf(0);
2637                                    }
2638    
2639                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2640                                            finderArgs, count);
2641    
2642                                    closeSession(session);
2643                            }
2644                    }
2645    
2646                    return count.intValue();
2647            }
2648    
2649            /**
2650             * Counts all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2651             *
2652             * @param companyId the company id to search with
2653             * @param classNameId the class name id to search with
2654             * @param classPK the class p k to search with
2655             * @param primary the primary to search with
2656             * @return the number of matching phones
2657             * @throws SystemException if a system exception occurred
2658             */
2659            public int countByC_C_C_P(long companyId, long classNameId, long classPK,
2660                    boolean primary) throws SystemException {
2661                    Object[] finderArgs = new Object[] {
2662                                    companyId, classNameId, classPK, primary
2663                            };
2664    
2665                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C_P,
2666                                    finderArgs, this);
2667    
2668                    if (count == null) {
2669                            Session session = null;
2670    
2671                            try {
2672                                    session = openSession();
2673    
2674                                    StringBundler query = new StringBundler(5);
2675    
2676                                    query.append(_SQL_COUNT_PHONE_WHERE);
2677    
2678                                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2679    
2680                                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2681    
2682                                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2683    
2684                                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2685    
2686                                    String sql = query.toString();
2687    
2688                                    Query q = session.createQuery(sql);
2689    
2690                                    QueryPos qPos = QueryPos.getInstance(q);
2691    
2692                                    qPos.add(companyId);
2693    
2694                                    qPos.add(classNameId);
2695    
2696                                    qPos.add(classPK);
2697    
2698                                    qPos.add(primary);
2699    
2700                                    count = (Long)q.uniqueResult();
2701                            }
2702                            catch (Exception e) {
2703                                    throw processException(e);
2704                            }
2705                            finally {
2706                                    if (count == null) {
2707                                            count = Long.valueOf(0);
2708                                    }
2709    
2710                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C_P,
2711                                            finderArgs, count);
2712    
2713                                    closeSession(session);
2714                            }
2715                    }
2716    
2717                    return count.intValue();
2718            }
2719    
2720            /**
2721             * Counts all the phones.
2722             *
2723             * @return the number of phones
2724             * @throws SystemException if a system exception occurred
2725             */
2726            public int countAll() throws SystemException {
2727                    Object[] finderArgs = new Object[0];
2728    
2729                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2730                                    finderArgs, this);
2731    
2732                    if (count == null) {
2733                            Session session = null;
2734    
2735                            try {
2736                                    session = openSession();
2737    
2738                                    Query q = session.createQuery(_SQL_COUNT_PHONE);
2739    
2740                                    count = (Long)q.uniqueResult();
2741                            }
2742                            catch (Exception e) {
2743                                    throw processException(e);
2744                            }
2745                            finally {
2746                                    if (count == null) {
2747                                            count = Long.valueOf(0);
2748                                    }
2749    
2750                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2751                                            count);
2752    
2753                                    closeSession(session);
2754                            }
2755                    }
2756    
2757                    return count.intValue();
2758            }
2759    
2760            /**
2761             * Initializes the phone persistence.
2762             */
2763            public void afterPropertiesSet() {
2764                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2765                                            com.liferay.portal.util.PropsUtil.get(
2766                                                    "value.object.listener.com.liferay.portal.model.Phone")));
2767    
2768                    if (listenerClassNames.length > 0) {
2769                            try {
2770                                    List<ModelListener<Phone>> listenersList = new ArrayList<ModelListener<Phone>>();
2771    
2772                                    for (String listenerClassName : listenerClassNames) {
2773                                            listenersList.add((ModelListener<Phone>)InstanceFactory.newInstance(
2774                                                            listenerClassName));
2775                                    }
2776    
2777                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2778                            }
2779                            catch (Exception e) {
2780                                    _log.error(e);
2781                            }
2782                    }
2783            }
2784    
2785            public void destroy() {
2786                    EntityCacheUtil.removeCache(PhoneImpl.class.getName());
2787                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2788                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2789            }
2790    
2791            @BeanReference(type = AccountPersistence.class)
2792            protected AccountPersistence accountPersistence;
2793            @BeanReference(type = AddressPersistence.class)
2794            protected AddressPersistence addressPersistence;
2795            @BeanReference(type = BrowserTrackerPersistence.class)
2796            protected BrowserTrackerPersistence browserTrackerPersistence;
2797            @BeanReference(type = ClassNamePersistence.class)
2798            protected ClassNamePersistence classNamePersistence;
2799            @BeanReference(type = ClusterGroupPersistence.class)
2800            protected ClusterGroupPersistence clusterGroupPersistence;
2801            @BeanReference(type = CompanyPersistence.class)
2802            protected CompanyPersistence companyPersistence;
2803            @BeanReference(type = ContactPersistence.class)
2804            protected ContactPersistence contactPersistence;
2805            @BeanReference(type = CountryPersistence.class)
2806            protected CountryPersistence countryPersistence;
2807            @BeanReference(type = EmailAddressPersistence.class)
2808            protected EmailAddressPersistence emailAddressPersistence;
2809            @BeanReference(type = GroupPersistence.class)
2810            protected GroupPersistence groupPersistence;
2811            @BeanReference(type = ImagePersistence.class)
2812            protected ImagePersistence imagePersistence;
2813            @BeanReference(type = LayoutPersistence.class)
2814            protected LayoutPersistence layoutPersistence;
2815            @BeanReference(type = LayoutPrototypePersistence.class)
2816            protected LayoutPrototypePersistence layoutPrototypePersistence;
2817            @BeanReference(type = LayoutSetPersistence.class)
2818            protected LayoutSetPersistence layoutSetPersistence;
2819            @BeanReference(type = LayoutSetPrototypePersistence.class)
2820            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2821            @BeanReference(type = ListTypePersistence.class)
2822            protected ListTypePersistence listTypePersistence;
2823            @BeanReference(type = LockPersistence.class)
2824            protected LockPersistence lockPersistence;
2825            @BeanReference(type = MembershipRequestPersistence.class)
2826            protected MembershipRequestPersistence membershipRequestPersistence;
2827            @BeanReference(type = OrganizationPersistence.class)
2828            protected OrganizationPersistence organizationPersistence;
2829            @BeanReference(type = OrgGroupPermissionPersistence.class)
2830            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2831            @BeanReference(type = OrgGroupRolePersistence.class)
2832            protected OrgGroupRolePersistence orgGroupRolePersistence;
2833            @BeanReference(type = OrgLaborPersistence.class)
2834            protected OrgLaborPersistence orgLaborPersistence;
2835            @BeanReference(type = PasswordPolicyPersistence.class)
2836            protected PasswordPolicyPersistence passwordPolicyPersistence;
2837            @BeanReference(type = PasswordPolicyRelPersistence.class)
2838            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2839            @BeanReference(type = PasswordTrackerPersistence.class)
2840            protected PasswordTrackerPersistence passwordTrackerPersistence;
2841            @BeanReference(type = PermissionPersistence.class)
2842            protected PermissionPersistence permissionPersistence;
2843            @BeanReference(type = PhonePersistence.class)
2844            protected PhonePersistence phonePersistence;
2845            @BeanReference(type = PluginSettingPersistence.class)
2846            protected PluginSettingPersistence pluginSettingPersistence;
2847            @BeanReference(type = PortletPersistence.class)
2848            protected PortletPersistence portletPersistence;
2849            @BeanReference(type = PortletItemPersistence.class)
2850            protected PortletItemPersistence portletItemPersistence;
2851            @BeanReference(type = PortletPreferencesPersistence.class)
2852            protected PortletPreferencesPersistence portletPreferencesPersistence;
2853            @BeanReference(type = RegionPersistence.class)
2854            protected RegionPersistence regionPersistence;
2855            @BeanReference(type = ReleasePersistence.class)
2856            protected ReleasePersistence releasePersistence;
2857            @BeanReference(type = ResourcePersistence.class)
2858            protected ResourcePersistence resourcePersistence;
2859            @BeanReference(type = ResourceActionPersistence.class)
2860            protected ResourceActionPersistence resourceActionPersistence;
2861            @BeanReference(type = ResourceCodePersistence.class)
2862            protected ResourceCodePersistence resourceCodePersistence;
2863            @BeanReference(type = ResourcePermissionPersistence.class)
2864            protected ResourcePermissionPersistence resourcePermissionPersistence;
2865            @BeanReference(type = RolePersistence.class)
2866            protected RolePersistence rolePersistence;
2867            @BeanReference(type = ServiceComponentPersistence.class)
2868            protected ServiceComponentPersistence serviceComponentPersistence;
2869            @BeanReference(type = ShardPersistence.class)
2870            protected ShardPersistence shardPersistence;
2871            @BeanReference(type = SubscriptionPersistence.class)
2872            protected SubscriptionPersistence subscriptionPersistence;
2873            @BeanReference(type = TicketPersistence.class)
2874            protected TicketPersistence ticketPersistence;
2875            @BeanReference(type = TeamPersistence.class)
2876            protected TeamPersistence teamPersistence;
2877            @BeanReference(type = UserPersistence.class)
2878            protected UserPersistence userPersistence;
2879            @BeanReference(type = UserGroupPersistence.class)
2880            protected UserGroupPersistence userGroupPersistence;
2881            @BeanReference(type = UserGroupGroupRolePersistence.class)
2882            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2883            @BeanReference(type = UserGroupRolePersistence.class)
2884            protected UserGroupRolePersistence userGroupRolePersistence;
2885            @BeanReference(type = UserIdMapperPersistence.class)
2886            protected UserIdMapperPersistence userIdMapperPersistence;
2887            @BeanReference(type = UserTrackerPersistence.class)
2888            protected UserTrackerPersistence userTrackerPersistence;
2889            @BeanReference(type = UserTrackerPathPersistence.class)
2890            protected UserTrackerPathPersistence userTrackerPathPersistence;
2891            @BeanReference(type = WebDAVPropsPersistence.class)
2892            protected WebDAVPropsPersistence webDAVPropsPersistence;
2893            @BeanReference(type = WebsitePersistence.class)
2894            protected WebsitePersistence websitePersistence;
2895            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2896            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2897            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2898            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2899            private static final String _SQL_SELECT_PHONE = "SELECT phone FROM Phone phone";
2900            private static final String _SQL_SELECT_PHONE_WHERE = "SELECT phone FROM Phone phone WHERE ";
2901            private static final String _SQL_COUNT_PHONE = "SELECT COUNT(phone) FROM Phone phone";
2902            private static final String _SQL_COUNT_PHONE_WHERE = "SELECT COUNT(phone) FROM Phone phone WHERE ";
2903            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "phone.companyId = ?";
2904            private static final String _FINDER_COLUMN_USERID_USERID_2 = "phone.userId = ?";
2905            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
2906            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "phone.classNameId = ?";
2907            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
2908            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
2909            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "phone.classPK = ?";
2910            private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "phone.companyId = ? AND ";
2911            private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
2912            private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "phone.classPK = ? AND ";
2913            private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "phone.primary = ?";
2914            private static final String _ORDER_BY_ENTITY_ALIAS = "phone.";
2915            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Phone exists with the primary key ";
2916            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Phone exists with the key {";
2917            private static Log _log = LogFactoryUtil.getLog(PhonePersistenceImpl.class);
2918    }