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