001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchPhoneException;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
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.Validator;
036    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.MVCCModel;
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.ServiceContext;
043    import com.liferay.portal.service.ServiceContextThreadLocal;
044    import com.liferay.portal.service.persistence.PhonePersistence;
045    
046    import java.io.Serializable;
047    
048    import java.util.Collections;
049    import java.util.Date;
050    import java.util.HashMap;
051    import java.util.HashSet;
052    import java.util.Iterator;
053    import java.util.List;
054    import java.util.Map;
055    import java.util.Set;
056    
057    /**
058     * The persistence implementation for the phone service.
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see PhonePersistence
066     * @see com.liferay.portal.service.persistence.PhoneUtil
067     * @generated
068     */
069    @ProviderType
070    public class PhonePersistenceImpl extends BasePersistenceImpl<Phone>
071            implements PhonePersistence {
072            /*
073             * NOTE FOR DEVELOPERS:
074             *
075             * 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.
076             */
077            public static final String FINDER_CLASS_NAME_ENTITY = PhoneImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List1";
080            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List2";
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
083                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
086                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
089                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
092                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
094                            new String[] {
095                                    String.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
101                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
103                            new String[] { String.class.getName() },
104                            PhoneModelImpl.UUID_COLUMN_BITMASK |
105                            PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
107                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
109                            new String[] { String.class.getName() });
110    
111            /**
112             * Returns all the phones where uuid = &#63;.
113             *
114             * @param uuid the uuid
115             * @return the matching phones
116             */
117            @Override
118            public List<Phone> findByUuid(String uuid) {
119                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
120            }
121    
122            /**
123             * Returns a range of all the phones where uuid = &#63;.
124             *
125             * <p>
126             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
127             * </p>
128             *
129             * @param uuid the uuid
130             * @param start the lower bound of the range of phones
131             * @param end the upper bound of the range of phones (not inclusive)
132             * @return the range of matching phones
133             */
134            @Override
135            public List<Phone> findByUuid(String uuid, int start, int end) {
136                    return findByUuid(uuid, start, end, null);
137            }
138    
139            /**
140             * Returns an ordered range of all the phones where uuid = &#63;.
141             *
142             * <p>
143             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
144             * </p>
145             *
146             * @param uuid the uuid
147             * @param start the lower bound of the range of phones
148             * @param end the upper bound of the range of phones (not inclusive)
149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
150             * @return the ordered range of matching phones
151             */
152            @Override
153            public List<Phone> findByUuid(String uuid, int start, int end,
154                    OrderByComparator<Phone> orderByComparator) {
155                    return findByUuid(uuid, start, end, orderByComparator, true);
156            }
157    
158            /**
159             * Returns an ordered range of all the phones where uuid = &#63;.
160             *
161             * <p>
162             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
163             * </p>
164             *
165             * @param uuid the uuid
166             * @param start the lower bound of the range of phones
167             * @param end the upper bound of the range of phones (not inclusive)
168             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
169             * @param retrieveFromCache whether to retrieve from the finder cache
170             * @return the ordered range of matching phones
171             */
172            @Override
173            public List<Phone> findByUuid(String uuid, int start, int end,
174                    OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
175                    boolean pagination = true;
176                    FinderPath finderPath = null;
177                    Object[] finderArgs = null;
178    
179                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
180                                    (orderByComparator == null)) {
181                            pagination = false;
182                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
183                            finderArgs = new Object[] { uuid };
184                    }
185                    else {
186                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
187                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
188                    }
189    
190                    List<Phone> list = null;
191    
192                    if (retrieveFromCache) {
193                            list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
194                                            this);
195    
196                            if ((list != null) && !list.isEmpty()) {
197                                    for (Phone phone : list) {
198                                            if (!Validator.equals(uuid, phone.getUuid())) {
199                                                    list = null;
200    
201                                                    break;
202                                            }
203                                    }
204                            }
205                    }
206    
207                    if (list == null) {
208                            StringBundler query = null;
209    
210                            if (orderByComparator != null) {
211                                    query = new StringBundler(3 +
212                                                    (orderByComparator.getOrderByFields().length * 3));
213                            }
214                            else {
215                                    query = new StringBundler(3);
216                            }
217    
218                            query.append(_SQL_SELECT_PHONE_WHERE);
219    
220                            boolean bindUuid = false;
221    
222                            if (uuid == null) {
223                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
224                            }
225                            else if (uuid.equals(StringPool.BLANK)) {
226                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
227                            }
228                            else {
229                                    bindUuid = true;
230    
231                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
232                            }
233    
234                            if (orderByComparator != null) {
235                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
236                                            orderByComparator);
237                            }
238                            else
239                             if (pagination) {
240                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
241                            }
242    
243                            String sql = query.toString();
244    
245                            Session session = null;
246    
247                            try {
248                                    session = openSession();
249    
250                                    Query q = session.createQuery(sql);
251    
252                                    QueryPos qPos = QueryPos.getInstance(q);
253    
254                                    if (bindUuid) {
255                                            qPos.add(uuid);
256                                    }
257    
258                                    if (!pagination) {
259                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
260                                                            end, false);
261    
262                                            Collections.sort(list);
263    
264                                            list = Collections.unmodifiableList(list);
265                                    }
266                                    else {
267                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
268                                                            end);
269                                    }
270    
271                                    cacheResult(list);
272    
273                                    finderCache.putResult(finderPath, finderArgs, list);
274                            }
275                            catch (Exception e) {
276                                    finderCache.removeResult(finderPath, finderArgs);
277    
278                                    throw processException(e);
279                            }
280                            finally {
281                                    closeSession(session);
282                            }
283                    }
284    
285                    return list;
286            }
287    
288            /**
289             * Returns the first phone in the ordered set where uuid = &#63;.
290             *
291             * @param uuid the uuid
292             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
293             * @return the first matching phone
294             * @throws NoSuchPhoneException if a matching phone could not be found
295             */
296            @Override
297            public Phone findByUuid_First(String uuid,
298                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
299                    Phone phone = fetchByUuid_First(uuid, orderByComparator);
300    
301                    if (phone != null) {
302                            return phone;
303                    }
304    
305                    StringBundler msg = new StringBundler(4);
306    
307                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
308    
309                    msg.append("uuid=");
310                    msg.append(uuid);
311    
312                    msg.append(StringPool.CLOSE_CURLY_BRACE);
313    
314                    throw new NoSuchPhoneException(msg.toString());
315            }
316    
317            /**
318             * Returns the first phone in the ordered set where uuid = &#63;.
319             *
320             * @param uuid the uuid
321             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
322             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
323             */
324            @Override
325            public Phone fetchByUuid_First(String uuid,
326                    OrderByComparator<Phone> orderByComparator) {
327                    List<Phone> list = findByUuid(uuid, 0, 1, orderByComparator);
328    
329                    if (!list.isEmpty()) {
330                            return list.get(0);
331                    }
332    
333                    return null;
334            }
335    
336            /**
337             * Returns the last phone in the ordered set where uuid = &#63;.
338             *
339             * @param uuid the uuid
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the last matching phone
342             * @throws NoSuchPhoneException if a matching phone could not be found
343             */
344            @Override
345            public Phone findByUuid_Last(String uuid,
346                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
347                    Phone phone = fetchByUuid_Last(uuid, orderByComparator);
348    
349                    if (phone != null) {
350                            return phone;
351                    }
352    
353                    StringBundler msg = new StringBundler(4);
354    
355                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
356    
357                    msg.append("uuid=");
358                    msg.append(uuid);
359    
360                    msg.append(StringPool.CLOSE_CURLY_BRACE);
361    
362                    throw new NoSuchPhoneException(msg.toString());
363            }
364    
365            /**
366             * Returns the last phone in the ordered set where uuid = &#63;.
367             *
368             * @param uuid the uuid
369             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
370             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
371             */
372            @Override
373            public Phone fetchByUuid_Last(String uuid,
374                    OrderByComparator<Phone> orderByComparator) {
375                    int count = countByUuid(uuid);
376    
377                    if (count == 0) {
378                            return null;
379                    }
380    
381                    List<Phone> list = findByUuid(uuid, count - 1, count, orderByComparator);
382    
383                    if (!list.isEmpty()) {
384                            return list.get(0);
385                    }
386    
387                    return null;
388            }
389    
390            /**
391             * Returns the phones before and after the current phone in the ordered set where uuid = &#63;.
392             *
393             * @param phoneId the primary key of the current phone
394             * @param uuid the uuid
395             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
396             * @return the previous, current, and next phone
397             * @throws NoSuchPhoneException if a phone with the primary key could not be found
398             */
399            @Override
400            public Phone[] findByUuid_PrevAndNext(long phoneId, String uuid,
401                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
402                    Phone phone = findByPrimaryKey(phoneId);
403    
404                    Session session = null;
405    
406                    try {
407                            session = openSession();
408    
409                            Phone[] array = new PhoneImpl[3];
410    
411                            array[0] = getByUuid_PrevAndNext(session, phone, uuid,
412                                            orderByComparator, true);
413    
414                            array[1] = phone;
415    
416                            array[2] = getByUuid_PrevAndNext(session, phone, uuid,
417                                            orderByComparator, false);
418    
419                            return array;
420                    }
421                    catch (Exception e) {
422                            throw processException(e);
423                    }
424                    finally {
425                            closeSession(session);
426                    }
427            }
428    
429            protected Phone getByUuid_PrevAndNext(Session session, Phone phone,
430                    String uuid, OrderByComparator<Phone> orderByComparator,
431                    boolean previous) {
432                    StringBundler query = null;
433    
434                    if (orderByComparator != null) {
435                            query = new StringBundler(6 +
436                                            (orderByComparator.getOrderByFields().length * 6));
437                    }
438                    else {
439                            query = new StringBundler(3);
440                    }
441    
442                    query.append(_SQL_SELECT_PHONE_WHERE);
443    
444                    boolean bindUuid = false;
445    
446                    if (uuid == null) {
447                            query.append(_FINDER_COLUMN_UUID_UUID_1);
448                    }
449                    else if (uuid.equals(StringPool.BLANK)) {
450                            query.append(_FINDER_COLUMN_UUID_UUID_3);
451                    }
452                    else {
453                            bindUuid = true;
454    
455                            query.append(_FINDER_COLUMN_UUID_UUID_2);
456                    }
457    
458                    if (orderByComparator != null) {
459                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
460    
461                            if (orderByConditionFields.length > 0) {
462                                    query.append(WHERE_AND);
463                            }
464    
465                            for (int i = 0; i < orderByConditionFields.length; i++) {
466                                    query.append(_ORDER_BY_ENTITY_ALIAS);
467                                    query.append(orderByConditionFields[i]);
468    
469                                    if ((i + 1) < orderByConditionFields.length) {
470                                            if (orderByComparator.isAscending() ^ previous) {
471                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
472                                            }
473                                            else {
474                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
475                                            }
476                                    }
477                                    else {
478                                            if (orderByComparator.isAscending() ^ previous) {
479                                                    query.append(WHERE_GREATER_THAN);
480                                            }
481                                            else {
482                                                    query.append(WHERE_LESSER_THAN);
483                                            }
484                                    }
485                            }
486    
487                            query.append(ORDER_BY_CLAUSE);
488    
489                            String[] orderByFields = orderByComparator.getOrderByFields();
490    
491                            for (int i = 0; i < orderByFields.length; i++) {
492                                    query.append(_ORDER_BY_ENTITY_ALIAS);
493                                    query.append(orderByFields[i]);
494    
495                                    if ((i + 1) < orderByFields.length) {
496                                            if (orderByComparator.isAscending() ^ previous) {
497                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
498                                            }
499                                            else {
500                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
501                                            }
502                                    }
503                                    else {
504                                            if (orderByComparator.isAscending() ^ previous) {
505                                                    query.append(ORDER_BY_ASC);
506                                            }
507                                            else {
508                                                    query.append(ORDER_BY_DESC);
509                                            }
510                                    }
511                            }
512                    }
513                    else {
514                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
515                    }
516    
517                    String sql = query.toString();
518    
519                    Query q = session.createQuery(sql);
520    
521                    q.setFirstResult(0);
522                    q.setMaxResults(2);
523    
524                    QueryPos qPos = QueryPos.getInstance(q);
525    
526                    if (bindUuid) {
527                            qPos.add(uuid);
528                    }
529    
530                    if (orderByComparator != null) {
531                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
532    
533                            for (Object value : values) {
534                                    qPos.add(value);
535                            }
536                    }
537    
538                    List<Phone> list = q.list();
539    
540                    if (list.size() == 2) {
541                            return list.get(1);
542                    }
543                    else {
544                            return null;
545                    }
546            }
547    
548            /**
549             * Removes all the phones where uuid = &#63; from the database.
550             *
551             * @param uuid the uuid
552             */
553            @Override
554            public void removeByUuid(String uuid) {
555                    for (Phone phone : findByUuid(uuid, QueryUtil.ALL_POS,
556                                    QueryUtil.ALL_POS, null)) {
557                            remove(phone);
558                    }
559            }
560    
561            /**
562             * Returns the number of phones where uuid = &#63;.
563             *
564             * @param uuid the uuid
565             * @return the number of matching phones
566             */
567            @Override
568            public int countByUuid(String uuid) {
569                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
570    
571                    Object[] finderArgs = new Object[] { uuid };
572    
573                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
574    
575                    if (count == null) {
576                            StringBundler query = new StringBundler(2);
577    
578                            query.append(_SQL_COUNT_PHONE_WHERE);
579    
580                            boolean bindUuid = false;
581    
582                            if (uuid == null) {
583                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
584                            }
585                            else if (uuid.equals(StringPool.BLANK)) {
586                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
587                            }
588                            else {
589                                    bindUuid = true;
590    
591                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
592                            }
593    
594                            String sql = query.toString();
595    
596                            Session session = null;
597    
598                            try {
599                                    session = openSession();
600    
601                                    Query q = session.createQuery(sql);
602    
603                                    QueryPos qPos = QueryPos.getInstance(q);
604    
605                                    if (bindUuid) {
606                                            qPos.add(uuid);
607                                    }
608    
609                                    count = (Long)q.uniqueResult();
610    
611                                    finderCache.putResult(finderPath, finderArgs, count);
612                            }
613                            catch (Exception e) {
614                                    finderCache.removeResult(finderPath, finderArgs);
615    
616                                    throw processException(e);
617                            }
618                            finally {
619                                    closeSession(session);
620                            }
621                    }
622    
623                    return count.intValue();
624            }
625    
626            private static final String _FINDER_COLUMN_UUID_UUID_1 = "phone.uuid IS NULL";
627            private static final String _FINDER_COLUMN_UUID_UUID_2 = "phone.uuid = ?";
628            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(phone.uuid IS NULL OR phone.uuid = '')";
629            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
630                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
631                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
632                            new String[] {
633                                    String.class.getName(), Long.class.getName(),
634                                    
635                            Integer.class.getName(), Integer.class.getName(),
636                                    OrderByComparator.class.getName()
637                            });
638            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
639                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
640                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
641                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
642                            new String[] { String.class.getName(), Long.class.getName() },
643                            PhoneModelImpl.UUID_COLUMN_BITMASK |
644                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
645                            PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
646            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
647                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
648                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
649                            new String[] { String.class.getName(), Long.class.getName() });
650    
651            /**
652             * Returns all the phones where uuid = &#63; and companyId = &#63;.
653             *
654             * @param uuid the uuid
655             * @param companyId the company ID
656             * @return the matching phones
657             */
658            @Override
659            public List<Phone> findByUuid_C(String uuid, long companyId) {
660                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
661                            QueryUtil.ALL_POS, null);
662            }
663    
664            /**
665             * Returns a range of all the phones where uuid = &#63; and companyId = &#63;.
666             *
667             * <p>
668             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
669             * </p>
670             *
671             * @param uuid the uuid
672             * @param companyId the company ID
673             * @param start the lower bound of the range of phones
674             * @param end the upper bound of the range of phones (not inclusive)
675             * @return the range of matching phones
676             */
677            @Override
678            public List<Phone> findByUuid_C(String uuid, long companyId, int start,
679                    int end) {
680                    return findByUuid_C(uuid, companyId, start, end, null);
681            }
682    
683            /**
684             * Returns an ordered range of all the phones where uuid = &#63; and companyId = &#63;.
685             *
686             * <p>
687             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
688             * </p>
689             *
690             * @param uuid the uuid
691             * @param companyId the company ID
692             * @param start the lower bound of the range of phones
693             * @param end the upper bound of the range of phones (not inclusive)
694             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
695             * @return the ordered range of matching phones
696             */
697            @Override
698            public List<Phone> findByUuid_C(String uuid, long companyId, int start,
699                    int end, OrderByComparator<Phone> orderByComparator) {
700                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
701            }
702    
703            /**
704             * Returns an ordered range of all the phones where uuid = &#63; and companyId = &#63;.
705             *
706             * <p>
707             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
708             * </p>
709             *
710             * @param uuid the uuid
711             * @param companyId the company ID
712             * @param start the lower bound of the range of phones
713             * @param end the upper bound of the range of phones (not inclusive)
714             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
715             * @param retrieveFromCache whether to retrieve from the finder cache
716             * @return the ordered range of matching phones
717             */
718            @Override
719            public List<Phone> findByUuid_C(String uuid, long companyId, int start,
720                    int end, OrderByComparator<Phone> orderByComparator,
721                    boolean retrieveFromCache) {
722                    boolean pagination = true;
723                    FinderPath finderPath = null;
724                    Object[] finderArgs = null;
725    
726                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
727                                    (orderByComparator == null)) {
728                            pagination = false;
729                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
730                            finderArgs = new Object[] { uuid, companyId };
731                    }
732                    else {
733                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
734                            finderArgs = new Object[] {
735                                            uuid, companyId,
736                                            
737                                            start, end, orderByComparator
738                                    };
739                    }
740    
741                    List<Phone> list = null;
742    
743                    if (retrieveFromCache) {
744                            list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
745                                            this);
746    
747                            if ((list != null) && !list.isEmpty()) {
748                                    for (Phone phone : list) {
749                                            if (!Validator.equals(uuid, phone.getUuid()) ||
750                                                            (companyId != phone.getCompanyId())) {
751                                                    list = null;
752    
753                                                    break;
754                                            }
755                                    }
756                            }
757                    }
758    
759                    if (list == null) {
760                            StringBundler query = null;
761    
762                            if (orderByComparator != null) {
763                                    query = new StringBundler(4 +
764                                                    (orderByComparator.getOrderByFields().length * 3));
765                            }
766                            else {
767                                    query = new StringBundler(4);
768                            }
769    
770                            query.append(_SQL_SELECT_PHONE_WHERE);
771    
772                            boolean bindUuid = false;
773    
774                            if (uuid == null) {
775                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
776                            }
777                            else if (uuid.equals(StringPool.BLANK)) {
778                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
779                            }
780                            else {
781                                    bindUuid = true;
782    
783                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
784                            }
785    
786                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
787    
788                            if (orderByComparator != null) {
789                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
790                                            orderByComparator);
791                            }
792                            else
793                             if (pagination) {
794                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
795                            }
796    
797                            String sql = query.toString();
798    
799                            Session session = null;
800    
801                            try {
802                                    session = openSession();
803    
804                                    Query q = session.createQuery(sql);
805    
806                                    QueryPos qPos = QueryPos.getInstance(q);
807    
808                                    if (bindUuid) {
809                                            qPos.add(uuid);
810                                    }
811    
812                                    qPos.add(companyId);
813    
814                                    if (!pagination) {
815                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
816                                                            end, false);
817    
818                                            Collections.sort(list);
819    
820                                            list = Collections.unmodifiableList(list);
821                                    }
822                                    else {
823                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
824                                                            end);
825                                    }
826    
827                                    cacheResult(list);
828    
829                                    finderCache.putResult(finderPath, finderArgs, list);
830                            }
831                            catch (Exception e) {
832                                    finderCache.removeResult(finderPath, finderArgs);
833    
834                                    throw processException(e);
835                            }
836                            finally {
837                                    closeSession(session);
838                            }
839                    }
840    
841                    return list;
842            }
843    
844            /**
845             * Returns the first phone in the ordered set where uuid = &#63; and companyId = &#63;.
846             *
847             * @param uuid the uuid
848             * @param companyId the company ID
849             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
850             * @return the first matching phone
851             * @throws NoSuchPhoneException if a matching phone could not be found
852             */
853            @Override
854            public Phone findByUuid_C_First(String uuid, long companyId,
855                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
856                    Phone phone = fetchByUuid_C_First(uuid, companyId, orderByComparator);
857    
858                    if (phone != null) {
859                            return phone;
860                    }
861    
862                    StringBundler msg = new StringBundler(6);
863    
864                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
865    
866                    msg.append("uuid=");
867                    msg.append(uuid);
868    
869                    msg.append(", companyId=");
870                    msg.append(companyId);
871    
872                    msg.append(StringPool.CLOSE_CURLY_BRACE);
873    
874                    throw new NoSuchPhoneException(msg.toString());
875            }
876    
877            /**
878             * Returns the first phone in the ordered set where uuid = &#63; and companyId = &#63;.
879             *
880             * @param uuid the uuid
881             * @param companyId the company ID
882             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
883             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
884             */
885            @Override
886            public Phone fetchByUuid_C_First(String uuid, long companyId,
887                    OrderByComparator<Phone> orderByComparator) {
888                    List<Phone> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
889    
890                    if (!list.isEmpty()) {
891                            return list.get(0);
892                    }
893    
894                    return null;
895            }
896    
897            /**
898             * Returns the last phone in the ordered set where uuid = &#63; and companyId = &#63;.
899             *
900             * @param uuid the uuid
901             * @param companyId the company ID
902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
903             * @return the last matching phone
904             * @throws NoSuchPhoneException if a matching phone could not be found
905             */
906            @Override
907            public Phone findByUuid_C_Last(String uuid, long companyId,
908                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
909                    Phone phone = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
910    
911                    if (phone != null) {
912                            return phone;
913                    }
914    
915                    StringBundler msg = new StringBundler(6);
916    
917                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
918    
919                    msg.append("uuid=");
920                    msg.append(uuid);
921    
922                    msg.append(", companyId=");
923                    msg.append(companyId);
924    
925                    msg.append(StringPool.CLOSE_CURLY_BRACE);
926    
927                    throw new NoSuchPhoneException(msg.toString());
928            }
929    
930            /**
931             * Returns the last phone in the ordered set where uuid = &#63; and companyId = &#63;.
932             *
933             * @param uuid the uuid
934             * @param companyId the company ID
935             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
936             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
937             */
938            @Override
939            public Phone fetchByUuid_C_Last(String uuid, long companyId,
940                    OrderByComparator<Phone> orderByComparator) {
941                    int count = countByUuid_C(uuid, companyId);
942    
943                    if (count == 0) {
944                            return null;
945                    }
946    
947                    List<Phone> list = findByUuid_C(uuid, companyId, count - 1, count,
948                                    orderByComparator);
949    
950                    if (!list.isEmpty()) {
951                            return list.get(0);
952                    }
953    
954                    return null;
955            }
956    
957            /**
958             * Returns the phones before and after the current phone in the ordered set where uuid = &#63; and companyId = &#63;.
959             *
960             * @param phoneId the primary key of the current phone
961             * @param uuid the uuid
962             * @param companyId the company ID
963             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
964             * @return the previous, current, and next phone
965             * @throws NoSuchPhoneException if a phone with the primary key could not be found
966             */
967            @Override
968            public Phone[] findByUuid_C_PrevAndNext(long phoneId, String uuid,
969                    long companyId, OrderByComparator<Phone> orderByComparator)
970                    throws NoSuchPhoneException {
971                    Phone phone = findByPrimaryKey(phoneId);
972    
973                    Session session = null;
974    
975                    try {
976                            session = openSession();
977    
978                            Phone[] array = new PhoneImpl[3];
979    
980                            array[0] = getByUuid_C_PrevAndNext(session, phone, uuid, companyId,
981                                            orderByComparator, true);
982    
983                            array[1] = phone;
984    
985                            array[2] = getByUuid_C_PrevAndNext(session, phone, uuid, companyId,
986                                            orderByComparator, false);
987    
988                            return array;
989                    }
990                    catch (Exception e) {
991                            throw processException(e);
992                    }
993                    finally {
994                            closeSession(session);
995                    }
996            }
997    
998            protected Phone getByUuid_C_PrevAndNext(Session session, Phone phone,
999                    String uuid, long companyId,
1000                    OrderByComparator<Phone> orderByComparator, boolean previous) {
1001                    StringBundler query = null;
1002    
1003                    if (orderByComparator != null) {
1004                            query = new StringBundler(6 +
1005                                            (orderByComparator.getOrderByFields().length * 6));
1006                    }
1007                    else {
1008                            query = new StringBundler(3);
1009                    }
1010    
1011                    query.append(_SQL_SELECT_PHONE_WHERE);
1012    
1013                    boolean bindUuid = false;
1014    
1015                    if (uuid == null) {
1016                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1017                    }
1018                    else if (uuid.equals(StringPool.BLANK)) {
1019                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1020                    }
1021                    else {
1022                            bindUuid = true;
1023    
1024                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1025                    }
1026    
1027                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1028    
1029                    if (orderByComparator != null) {
1030                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1031    
1032                            if (orderByConditionFields.length > 0) {
1033                                    query.append(WHERE_AND);
1034                            }
1035    
1036                            for (int i = 0; i < orderByConditionFields.length; i++) {
1037                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1038                                    query.append(orderByConditionFields[i]);
1039    
1040                                    if ((i + 1) < orderByConditionFields.length) {
1041                                            if (orderByComparator.isAscending() ^ previous) {
1042                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1043                                            }
1044                                            else {
1045                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1046                                            }
1047                                    }
1048                                    else {
1049                                            if (orderByComparator.isAscending() ^ previous) {
1050                                                    query.append(WHERE_GREATER_THAN);
1051                                            }
1052                                            else {
1053                                                    query.append(WHERE_LESSER_THAN);
1054                                            }
1055                                    }
1056                            }
1057    
1058                            query.append(ORDER_BY_CLAUSE);
1059    
1060                            String[] orderByFields = orderByComparator.getOrderByFields();
1061    
1062                            for (int i = 0; i < orderByFields.length; i++) {
1063                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1064                                    query.append(orderByFields[i]);
1065    
1066                                    if ((i + 1) < orderByFields.length) {
1067                                            if (orderByComparator.isAscending() ^ previous) {
1068                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1069                                            }
1070                                            else {
1071                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1072                                            }
1073                                    }
1074                                    else {
1075                                            if (orderByComparator.isAscending() ^ previous) {
1076                                                    query.append(ORDER_BY_ASC);
1077                                            }
1078                                            else {
1079                                                    query.append(ORDER_BY_DESC);
1080                                            }
1081                                    }
1082                            }
1083                    }
1084                    else {
1085                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1086                    }
1087    
1088                    String sql = query.toString();
1089    
1090                    Query q = session.createQuery(sql);
1091    
1092                    q.setFirstResult(0);
1093                    q.setMaxResults(2);
1094    
1095                    QueryPos qPos = QueryPos.getInstance(q);
1096    
1097                    if (bindUuid) {
1098                            qPos.add(uuid);
1099                    }
1100    
1101                    qPos.add(companyId);
1102    
1103                    if (orderByComparator != null) {
1104                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
1105    
1106                            for (Object value : values) {
1107                                    qPos.add(value);
1108                            }
1109                    }
1110    
1111                    List<Phone> list = q.list();
1112    
1113                    if (list.size() == 2) {
1114                            return list.get(1);
1115                    }
1116                    else {
1117                            return null;
1118                    }
1119            }
1120    
1121            /**
1122             * Removes all the phones where uuid = &#63; and companyId = &#63; from the database.
1123             *
1124             * @param uuid the uuid
1125             * @param companyId the company ID
1126             */
1127            @Override
1128            public void removeByUuid_C(String uuid, long companyId) {
1129                    for (Phone phone : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1130                                    QueryUtil.ALL_POS, null)) {
1131                            remove(phone);
1132                    }
1133            }
1134    
1135            /**
1136             * Returns the number of phones where uuid = &#63; and companyId = &#63;.
1137             *
1138             * @param uuid the uuid
1139             * @param companyId the company ID
1140             * @return the number of matching phones
1141             */
1142            @Override
1143            public int countByUuid_C(String uuid, long companyId) {
1144                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1145    
1146                    Object[] finderArgs = new Object[] { uuid, companyId };
1147    
1148                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1149    
1150                    if (count == null) {
1151                            StringBundler query = new StringBundler(3);
1152    
1153                            query.append(_SQL_COUNT_PHONE_WHERE);
1154    
1155                            boolean bindUuid = false;
1156    
1157                            if (uuid == null) {
1158                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1159                            }
1160                            else if (uuid.equals(StringPool.BLANK)) {
1161                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1162                            }
1163                            else {
1164                                    bindUuid = true;
1165    
1166                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1167                            }
1168    
1169                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1170    
1171                            String sql = query.toString();
1172    
1173                            Session session = null;
1174    
1175                            try {
1176                                    session = openSession();
1177    
1178                                    Query q = session.createQuery(sql);
1179    
1180                                    QueryPos qPos = QueryPos.getInstance(q);
1181    
1182                                    if (bindUuid) {
1183                                            qPos.add(uuid);
1184                                    }
1185    
1186                                    qPos.add(companyId);
1187    
1188                                    count = (Long)q.uniqueResult();
1189    
1190                                    finderCache.putResult(finderPath, finderArgs, count);
1191                            }
1192                            catch (Exception e) {
1193                                    finderCache.removeResult(finderPath, finderArgs);
1194    
1195                                    throw processException(e);
1196                            }
1197                            finally {
1198                                    closeSession(session);
1199                            }
1200                    }
1201    
1202                    return count.intValue();
1203            }
1204    
1205            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "phone.uuid IS NULL AND ";
1206            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "phone.uuid = ? AND ";
1207            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(phone.uuid IS NULL OR phone.uuid = '') AND ";
1208            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "phone.companyId = ?";
1209            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1210                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1211                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1212                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1213                            new String[] {
1214                                    Long.class.getName(),
1215                                    
1216                            Integer.class.getName(), Integer.class.getName(),
1217                                    OrderByComparator.class.getName()
1218                            });
1219            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1220                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1221                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1222                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1223                            new String[] { Long.class.getName() },
1224                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
1225                            PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
1226            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1227                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
1228                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1229                            new String[] { Long.class.getName() });
1230    
1231            /**
1232             * Returns all the phones where companyId = &#63;.
1233             *
1234             * @param companyId the company ID
1235             * @return the matching phones
1236             */
1237            @Override
1238            public List<Phone> findByCompanyId(long companyId) {
1239                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1240                            null);
1241            }
1242    
1243            /**
1244             * Returns a range of all the phones where companyId = &#63;.
1245             *
1246             * <p>
1247             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1248             * </p>
1249             *
1250             * @param companyId the company ID
1251             * @param start the lower bound of the range of phones
1252             * @param end the upper bound of the range of phones (not inclusive)
1253             * @return the range of matching phones
1254             */
1255            @Override
1256            public List<Phone> findByCompanyId(long companyId, int start, int end) {
1257                    return findByCompanyId(companyId, start, end, null);
1258            }
1259    
1260            /**
1261             * Returns an ordered range of all the phones where companyId = &#63;.
1262             *
1263             * <p>
1264             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1265             * </p>
1266             *
1267             * @param companyId the company ID
1268             * @param start the lower bound of the range of phones
1269             * @param end the upper bound of the range of phones (not inclusive)
1270             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1271             * @return the ordered range of matching phones
1272             */
1273            @Override
1274            public List<Phone> findByCompanyId(long companyId, int start, int end,
1275                    OrderByComparator<Phone> orderByComparator) {
1276                    return findByCompanyId(companyId, start, end, orderByComparator, true);
1277            }
1278    
1279            /**
1280             * Returns an ordered range of all the phones where companyId = &#63;.
1281             *
1282             * <p>
1283             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1284             * </p>
1285             *
1286             * @param companyId the company ID
1287             * @param start the lower bound of the range of phones
1288             * @param end the upper bound of the range of phones (not inclusive)
1289             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1290             * @param retrieveFromCache whether to retrieve from the finder cache
1291             * @return the ordered range of matching phones
1292             */
1293            @Override
1294            public List<Phone> findByCompanyId(long companyId, int start, int end,
1295                    OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
1296                    boolean pagination = true;
1297                    FinderPath finderPath = null;
1298                    Object[] finderArgs = null;
1299    
1300                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1301                                    (orderByComparator == null)) {
1302                            pagination = false;
1303                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1304                            finderArgs = new Object[] { companyId };
1305                    }
1306                    else {
1307                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1308                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1309                    }
1310    
1311                    List<Phone> list = null;
1312    
1313                    if (retrieveFromCache) {
1314                            list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
1315                                            this);
1316    
1317                            if ((list != null) && !list.isEmpty()) {
1318                                    for (Phone phone : list) {
1319                                            if ((companyId != phone.getCompanyId())) {
1320                                                    list = null;
1321    
1322                                                    break;
1323                                            }
1324                                    }
1325                            }
1326                    }
1327    
1328                    if (list == null) {
1329                            StringBundler query = null;
1330    
1331                            if (orderByComparator != null) {
1332                                    query = new StringBundler(3 +
1333                                                    (orderByComparator.getOrderByFields().length * 3));
1334                            }
1335                            else {
1336                                    query = new StringBundler(3);
1337                            }
1338    
1339                            query.append(_SQL_SELECT_PHONE_WHERE);
1340    
1341                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1342    
1343                            if (orderByComparator != null) {
1344                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1345                                            orderByComparator);
1346                            }
1347                            else
1348                             if (pagination) {
1349                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
1350                            }
1351    
1352                            String sql = query.toString();
1353    
1354                            Session session = null;
1355    
1356                            try {
1357                                    session = openSession();
1358    
1359                                    Query q = session.createQuery(sql);
1360    
1361                                    QueryPos qPos = QueryPos.getInstance(q);
1362    
1363                                    qPos.add(companyId);
1364    
1365                                    if (!pagination) {
1366                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1367                                                            end, false);
1368    
1369                                            Collections.sort(list);
1370    
1371                                            list = Collections.unmodifiableList(list);
1372                                    }
1373                                    else {
1374                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1375                                                            end);
1376                                    }
1377    
1378                                    cacheResult(list);
1379    
1380                                    finderCache.putResult(finderPath, finderArgs, list);
1381                            }
1382                            catch (Exception e) {
1383                                    finderCache.removeResult(finderPath, finderArgs);
1384    
1385                                    throw processException(e);
1386                            }
1387                            finally {
1388                                    closeSession(session);
1389                            }
1390                    }
1391    
1392                    return list;
1393            }
1394    
1395            /**
1396             * Returns the first phone in the ordered set where companyId = &#63;.
1397             *
1398             * @param companyId the company ID
1399             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1400             * @return the first matching phone
1401             * @throws NoSuchPhoneException if a matching phone could not be found
1402             */
1403            @Override
1404            public Phone findByCompanyId_First(long companyId,
1405                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1406                    Phone phone = fetchByCompanyId_First(companyId, orderByComparator);
1407    
1408                    if (phone != null) {
1409                            return phone;
1410                    }
1411    
1412                    StringBundler msg = new StringBundler(4);
1413    
1414                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1415    
1416                    msg.append("companyId=");
1417                    msg.append(companyId);
1418    
1419                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1420    
1421                    throw new NoSuchPhoneException(msg.toString());
1422            }
1423    
1424            /**
1425             * Returns the first phone in the ordered set where companyId = &#63;.
1426             *
1427             * @param companyId the company ID
1428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1429             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
1430             */
1431            @Override
1432            public Phone fetchByCompanyId_First(long companyId,
1433                    OrderByComparator<Phone> orderByComparator) {
1434                    List<Phone> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1435    
1436                    if (!list.isEmpty()) {
1437                            return list.get(0);
1438                    }
1439    
1440                    return null;
1441            }
1442    
1443            /**
1444             * Returns the last phone in the ordered set where companyId = &#63;.
1445             *
1446             * @param companyId the company ID
1447             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1448             * @return the last matching phone
1449             * @throws NoSuchPhoneException if a matching phone could not be found
1450             */
1451            @Override
1452            public Phone findByCompanyId_Last(long companyId,
1453                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1454                    Phone phone = fetchByCompanyId_Last(companyId, orderByComparator);
1455    
1456                    if (phone != null) {
1457                            return phone;
1458                    }
1459    
1460                    StringBundler msg = new StringBundler(4);
1461    
1462                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1463    
1464                    msg.append("companyId=");
1465                    msg.append(companyId);
1466    
1467                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1468    
1469                    throw new NoSuchPhoneException(msg.toString());
1470            }
1471    
1472            /**
1473             * Returns the last phone in the ordered set where companyId = &#63;.
1474             *
1475             * @param companyId the company ID
1476             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1477             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
1478             */
1479            @Override
1480            public Phone fetchByCompanyId_Last(long companyId,
1481                    OrderByComparator<Phone> orderByComparator) {
1482                    int count = countByCompanyId(companyId);
1483    
1484                    if (count == 0) {
1485                            return null;
1486                    }
1487    
1488                    List<Phone> list = findByCompanyId(companyId, count - 1, count,
1489                                    orderByComparator);
1490    
1491                    if (!list.isEmpty()) {
1492                            return list.get(0);
1493                    }
1494    
1495                    return null;
1496            }
1497    
1498            /**
1499             * Returns the phones before and after the current phone in the ordered set where companyId = &#63;.
1500             *
1501             * @param phoneId the primary key of the current phone
1502             * @param companyId the company ID
1503             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1504             * @return the previous, current, and next phone
1505             * @throws NoSuchPhoneException if a phone with the primary key could not be found
1506             */
1507            @Override
1508            public Phone[] findByCompanyId_PrevAndNext(long phoneId, long companyId,
1509                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1510                    Phone phone = findByPrimaryKey(phoneId);
1511    
1512                    Session session = null;
1513    
1514                    try {
1515                            session = openSession();
1516    
1517                            Phone[] array = new PhoneImpl[3];
1518    
1519                            array[0] = getByCompanyId_PrevAndNext(session, phone, companyId,
1520                                            orderByComparator, true);
1521    
1522                            array[1] = phone;
1523    
1524                            array[2] = getByCompanyId_PrevAndNext(session, phone, companyId,
1525                                            orderByComparator, false);
1526    
1527                            return array;
1528                    }
1529                    catch (Exception e) {
1530                            throw processException(e);
1531                    }
1532                    finally {
1533                            closeSession(session);
1534                    }
1535            }
1536    
1537            protected Phone getByCompanyId_PrevAndNext(Session session, Phone phone,
1538                    long companyId, OrderByComparator<Phone> orderByComparator,
1539                    boolean previous) {
1540                    StringBundler query = null;
1541    
1542                    if (orderByComparator != null) {
1543                            query = new StringBundler(6 +
1544                                            (orderByComparator.getOrderByFields().length * 6));
1545                    }
1546                    else {
1547                            query = new StringBundler(3);
1548                    }
1549    
1550                    query.append(_SQL_SELECT_PHONE_WHERE);
1551    
1552                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1553    
1554                    if (orderByComparator != null) {
1555                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1556    
1557                            if (orderByConditionFields.length > 0) {
1558                                    query.append(WHERE_AND);
1559                            }
1560    
1561                            for (int i = 0; i < orderByConditionFields.length; i++) {
1562                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1563                                    query.append(orderByConditionFields[i]);
1564    
1565                                    if ((i + 1) < orderByConditionFields.length) {
1566                                            if (orderByComparator.isAscending() ^ previous) {
1567                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1568                                            }
1569                                            else {
1570                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1571                                            }
1572                                    }
1573                                    else {
1574                                            if (orderByComparator.isAscending() ^ previous) {
1575                                                    query.append(WHERE_GREATER_THAN);
1576                                            }
1577                                            else {
1578                                                    query.append(WHERE_LESSER_THAN);
1579                                            }
1580                                    }
1581                            }
1582    
1583                            query.append(ORDER_BY_CLAUSE);
1584    
1585                            String[] orderByFields = orderByComparator.getOrderByFields();
1586    
1587                            for (int i = 0; i < orderByFields.length; i++) {
1588                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1589                                    query.append(orderByFields[i]);
1590    
1591                                    if ((i + 1) < orderByFields.length) {
1592                                            if (orderByComparator.isAscending() ^ previous) {
1593                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1594                                            }
1595                                            else {
1596                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1597                                            }
1598                                    }
1599                                    else {
1600                                            if (orderByComparator.isAscending() ^ previous) {
1601                                                    query.append(ORDER_BY_ASC);
1602                                            }
1603                                            else {
1604                                                    query.append(ORDER_BY_DESC);
1605                                            }
1606                                    }
1607                            }
1608                    }
1609                    else {
1610                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1611                    }
1612    
1613                    String sql = query.toString();
1614    
1615                    Query q = session.createQuery(sql);
1616    
1617                    q.setFirstResult(0);
1618                    q.setMaxResults(2);
1619    
1620                    QueryPos qPos = QueryPos.getInstance(q);
1621    
1622                    qPos.add(companyId);
1623    
1624                    if (orderByComparator != null) {
1625                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
1626    
1627                            for (Object value : values) {
1628                                    qPos.add(value);
1629                            }
1630                    }
1631    
1632                    List<Phone> list = q.list();
1633    
1634                    if (list.size() == 2) {
1635                            return list.get(1);
1636                    }
1637                    else {
1638                            return null;
1639                    }
1640            }
1641    
1642            /**
1643             * Removes all the phones where companyId = &#63; from the database.
1644             *
1645             * @param companyId the company ID
1646             */
1647            @Override
1648            public void removeByCompanyId(long companyId) {
1649                    for (Phone phone : findByCompanyId(companyId, QueryUtil.ALL_POS,
1650                                    QueryUtil.ALL_POS, null)) {
1651                            remove(phone);
1652                    }
1653            }
1654    
1655            /**
1656             * Returns the number of phones where companyId = &#63;.
1657             *
1658             * @param companyId the company ID
1659             * @return the number of matching phones
1660             */
1661            @Override
1662            public int countByCompanyId(long companyId) {
1663                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1664    
1665                    Object[] finderArgs = new Object[] { companyId };
1666    
1667                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1668    
1669                    if (count == null) {
1670                            StringBundler query = new StringBundler(2);
1671    
1672                            query.append(_SQL_COUNT_PHONE_WHERE);
1673    
1674                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1675    
1676                            String sql = query.toString();
1677    
1678                            Session session = null;
1679    
1680                            try {
1681                                    session = openSession();
1682    
1683                                    Query q = session.createQuery(sql);
1684    
1685                                    QueryPos qPos = QueryPos.getInstance(q);
1686    
1687                                    qPos.add(companyId);
1688    
1689                                    count = (Long)q.uniqueResult();
1690    
1691                                    finderCache.putResult(finderPath, finderArgs, count);
1692                            }
1693                            catch (Exception e) {
1694                                    finderCache.removeResult(finderPath, finderArgs);
1695    
1696                                    throw processException(e);
1697                            }
1698                            finally {
1699                                    closeSession(session);
1700                            }
1701                    }
1702    
1703                    return count.intValue();
1704            }
1705    
1706            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "phone.companyId = ?";
1707            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1708                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1709                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1710                            new String[] {
1711                                    Long.class.getName(),
1712                                    
1713                            Integer.class.getName(), Integer.class.getName(),
1714                                    OrderByComparator.class.getName()
1715                            });
1716            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1717                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1718                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
1719                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1720                            new String[] { Long.class.getName() },
1721                            PhoneModelImpl.USERID_COLUMN_BITMASK |
1722                            PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
1723            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
1724                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
1725                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1726                            new String[] { Long.class.getName() });
1727    
1728            /**
1729             * Returns all the phones where userId = &#63;.
1730             *
1731             * @param userId the user ID
1732             * @return the matching phones
1733             */
1734            @Override
1735            public List<Phone> findByUserId(long userId) {
1736                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1737            }
1738    
1739            /**
1740             * Returns a range of all the phones where userId = &#63;.
1741             *
1742             * <p>
1743             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1744             * </p>
1745             *
1746             * @param userId the user ID
1747             * @param start the lower bound of the range of phones
1748             * @param end the upper bound of the range of phones (not inclusive)
1749             * @return the range of matching phones
1750             */
1751            @Override
1752            public List<Phone> findByUserId(long userId, int start, int end) {
1753                    return findByUserId(userId, start, end, null);
1754            }
1755    
1756            /**
1757             * Returns an ordered range of all the phones where userId = &#63;.
1758             *
1759             * <p>
1760             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1761             * </p>
1762             *
1763             * @param userId the user ID
1764             * @param start the lower bound of the range of phones
1765             * @param end the upper bound of the range of phones (not inclusive)
1766             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1767             * @return the ordered range of matching phones
1768             */
1769            @Override
1770            public List<Phone> findByUserId(long userId, int start, int end,
1771                    OrderByComparator<Phone> orderByComparator) {
1772                    return findByUserId(userId, start, end, orderByComparator, true);
1773            }
1774    
1775            /**
1776             * Returns an ordered range of all the phones where userId = &#63;.
1777             *
1778             * <p>
1779             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1780             * </p>
1781             *
1782             * @param userId the user ID
1783             * @param start the lower bound of the range of phones
1784             * @param end the upper bound of the range of phones (not inclusive)
1785             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1786             * @param retrieveFromCache whether to retrieve from the finder cache
1787             * @return the ordered range of matching phones
1788             */
1789            @Override
1790            public List<Phone> findByUserId(long userId, int start, int end,
1791                    OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
1792                    boolean pagination = true;
1793                    FinderPath finderPath = null;
1794                    Object[] finderArgs = null;
1795    
1796                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1797                                    (orderByComparator == null)) {
1798                            pagination = false;
1799                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1800                            finderArgs = new Object[] { userId };
1801                    }
1802                    else {
1803                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1804                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1805                    }
1806    
1807                    List<Phone> list = null;
1808    
1809                    if (retrieveFromCache) {
1810                            list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
1811                                            this);
1812    
1813                            if ((list != null) && !list.isEmpty()) {
1814                                    for (Phone phone : list) {
1815                                            if ((userId != phone.getUserId())) {
1816                                                    list = null;
1817    
1818                                                    break;
1819                                            }
1820                                    }
1821                            }
1822                    }
1823    
1824                    if (list == null) {
1825                            StringBundler query = null;
1826    
1827                            if (orderByComparator != null) {
1828                                    query = new StringBundler(3 +
1829                                                    (orderByComparator.getOrderByFields().length * 3));
1830                            }
1831                            else {
1832                                    query = new StringBundler(3);
1833                            }
1834    
1835                            query.append(_SQL_SELECT_PHONE_WHERE);
1836    
1837                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1838    
1839                            if (orderByComparator != null) {
1840                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1841                                            orderByComparator);
1842                            }
1843                            else
1844                             if (pagination) {
1845                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
1846                            }
1847    
1848                            String sql = query.toString();
1849    
1850                            Session session = null;
1851    
1852                            try {
1853                                    session = openSession();
1854    
1855                                    Query q = session.createQuery(sql);
1856    
1857                                    QueryPos qPos = QueryPos.getInstance(q);
1858    
1859                                    qPos.add(userId);
1860    
1861                                    if (!pagination) {
1862                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1863                                                            end, false);
1864    
1865                                            Collections.sort(list);
1866    
1867                                            list = Collections.unmodifiableList(list);
1868                                    }
1869                                    else {
1870                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
1871                                                            end);
1872                                    }
1873    
1874                                    cacheResult(list);
1875    
1876                                    finderCache.putResult(finderPath, finderArgs, list);
1877                            }
1878                            catch (Exception e) {
1879                                    finderCache.removeResult(finderPath, finderArgs);
1880    
1881                                    throw processException(e);
1882                            }
1883                            finally {
1884                                    closeSession(session);
1885                            }
1886                    }
1887    
1888                    return list;
1889            }
1890    
1891            /**
1892             * Returns the first phone in the ordered set where userId = &#63;.
1893             *
1894             * @param userId the user ID
1895             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1896             * @return the first matching phone
1897             * @throws NoSuchPhoneException if a matching phone could not be found
1898             */
1899            @Override
1900            public Phone findByUserId_First(long userId,
1901                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1902                    Phone phone = fetchByUserId_First(userId, orderByComparator);
1903    
1904                    if (phone != null) {
1905                            return phone;
1906                    }
1907    
1908                    StringBundler msg = new StringBundler(4);
1909    
1910                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1911    
1912                    msg.append("userId=");
1913                    msg.append(userId);
1914    
1915                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1916    
1917                    throw new NoSuchPhoneException(msg.toString());
1918            }
1919    
1920            /**
1921             * Returns the first phone in the ordered set where userId = &#63;.
1922             *
1923             * @param userId the user ID
1924             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1925             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
1926             */
1927            @Override
1928            public Phone fetchByUserId_First(long userId,
1929                    OrderByComparator<Phone> orderByComparator) {
1930                    List<Phone> list = findByUserId(userId, 0, 1, orderByComparator);
1931    
1932                    if (!list.isEmpty()) {
1933                            return list.get(0);
1934                    }
1935    
1936                    return null;
1937            }
1938    
1939            /**
1940             * Returns the last phone in the ordered set where userId = &#63;.
1941             *
1942             * @param userId the user ID
1943             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1944             * @return the last matching phone
1945             * @throws NoSuchPhoneException if a matching phone could not be found
1946             */
1947            @Override
1948            public Phone findByUserId_Last(long userId,
1949                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
1950                    Phone phone = fetchByUserId_Last(userId, orderByComparator);
1951    
1952                    if (phone != null) {
1953                            return phone;
1954                    }
1955    
1956                    StringBundler msg = new StringBundler(4);
1957    
1958                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1959    
1960                    msg.append("userId=");
1961                    msg.append(userId);
1962    
1963                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1964    
1965                    throw new NoSuchPhoneException(msg.toString());
1966            }
1967    
1968            /**
1969             * Returns the last phone in the ordered set where userId = &#63;.
1970             *
1971             * @param userId the user ID
1972             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1973             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
1974             */
1975            @Override
1976            public Phone fetchByUserId_Last(long userId,
1977                    OrderByComparator<Phone> orderByComparator) {
1978                    int count = countByUserId(userId);
1979    
1980                    if (count == 0) {
1981                            return null;
1982                    }
1983    
1984                    List<Phone> list = findByUserId(userId, count - 1, count,
1985                                    orderByComparator);
1986    
1987                    if (!list.isEmpty()) {
1988                            return list.get(0);
1989                    }
1990    
1991                    return null;
1992            }
1993    
1994            /**
1995             * Returns the phones before and after the current phone in the ordered set where userId = &#63;.
1996             *
1997             * @param phoneId the primary key of the current phone
1998             * @param userId the user ID
1999             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2000             * @return the previous, current, and next phone
2001             * @throws NoSuchPhoneException if a phone with the primary key could not be found
2002             */
2003            @Override
2004            public Phone[] findByUserId_PrevAndNext(long phoneId, long userId,
2005                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2006                    Phone phone = findByPrimaryKey(phoneId);
2007    
2008                    Session session = null;
2009    
2010                    try {
2011                            session = openSession();
2012    
2013                            Phone[] array = new PhoneImpl[3];
2014    
2015                            array[0] = getByUserId_PrevAndNext(session, phone, userId,
2016                                            orderByComparator, true);
2017    
2018                            array[1] = phone;
2019    
2020                            array[2] = getByUserId_PrevAndNext(session, phone, userId,
2021                                            orderByComparator, false);
2022    
2023                            return array;
2024                    }
2025                    catch (Exception e) {
2026                            throw processException(e);
2027                    }
2028                    finally {
2029                            closeSession(session);
2030                    }
2031            }
2032    
2033            protected Phone getByUserId_PrevAndNext(Session session, Phone phone,
2034                    long userId, OrderByComparator<Phone> orderByComparator,
2035                    boolean previous) {
2036                    StringBundler query = null;
2037    
2038                    if (orderByComparator != null) {
2039                            query = new StringBundler(6 +
2040                                            (orderByComparator.getOrderByFields().length * 6));
2041                    }
2042                    else {
2043                            query = new StringBundler(3);
2044                    }
2045    
2046                    query.append(_SQL_SELECT_PHONE_WHERE);
2047    
2048                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2049    
2050                    if (orderByComparator != null) {
2051                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2052    
2053                            if (orderByConditionFields.length > 0) {
2054                                    query.append(WHERE_AND);
2055                            }
2056    
2057                            for (int i = 0; i < orderByConditionFields.length; i++) {
2058                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2059                                    query.append(orderByConditionFields[i]);
2060    
2061                                    if ((i + 1) < orderByConditionFields.length) {
2062                                            if (orderByComparator.isAscending() ^ previous) {
2063                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2064                                            }
2065                                            else {
2066                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2067                                            }
2068                                    }
2069                                    else {
2070                                            if (orderByComparator.isAscending() ^ previous) {
2071                                                    query.append(WHERE_GREATER_THAN);
2072                                            }
2073                                            else {
2074                                                    query.append(WHERE_LESSER_THAN);
2075                                            }
2076                                    }
2077                            }
2078    
2079                            query.append(ORDER_BY_CLAUSE);
2080    
2081                            String[] orderByFields = orderByComparator.getOrderByFields();
2082    
2083                            for (int i = 0; i < orderByFields.length; i++) {
2084                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2085                                    query.append(orderByFields[i]);
2086    
2087                                    if ((i + 1) < orderByFields.length) {
2088                                            if (orderByComparator.isAscending() ^ previous) {
2089                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2090                                            }
2091                                            else {
2092                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2093                                            }
2094                                    }
2095                                    else {
2096                                            if (orderByComparator.isAscending() ^ previous) {
2097                                                    query.append(ORDER_BY_ASC);
2098                                            }
2099                                            else {
2100                                                    query.append(ORDER_BY_DESC);
2101                                            }
2102                                    }
2103                            }
2104                    }
2105                    else {
2106                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
2107                    }
2108    
2109                    String sql = query.toString();
2110    
2111                    Query q = session.createQuery(sql);
2112    
2113                    q.setFirstResult(0);
2114                    q.setMaxResults(2);
2115    
2116                    QueryPos qPos = QueryPos.getInstance(q);
2117    
2118                    qPos.add(userId);
2119    
2120                    if (orderByComparator != null) {
2121                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
2122    
2123                            for (Object value : values) {
2124                                    qPos.add(value);
2125                            }
2126                    }
2127    
2128                    List<Phone> list = q.list();
2129    
2130                    if (list.size() == 2) {
2131                            return list.get(1);
2132                    }
2133                    else {
2134                            return null;
2135                    }
2136            }
2137    
2138            /**
2139             * Removes all the phones where userId = &#63; from the database.
2140             *
2141             * @param userId the user ID
2142             */
2143            @Override
2144            public void removeByUserId(long userId) {
2145                    for (Phone phone : findByUserId(userId, QueryUtil.ALL_POS,
2146                                    QueryUtil.ALL_POS, null)) {
2147                            remove(phone);
2148                    }
2149            }
2150    
2151            /**
2152             * Returns the number of phones where userId = &#63;.
2153             *
2154             * @param userId the user ID
2155             * @return the number of matching phones
2156             */
2157            @Override
2158            public int countByUserId(long userId) {
2159                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2160    
2161                    Object[] finderArgs = new Object[] { userId };
2162    
2163                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2164    
2165                    if (count == null) {
2166                            StringBundler query = new StringBundler(2);
2167    
2168                            query.append(_SQL_COUNT_PHONE_WHERE);
2169    
2170                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2171    
2172                            String sql = query.toString();
2173    
2174                            Session session = null;
2175    
2176                            try {
2177                                    session = openSession();
2178    
2179                                    Query q = session.createQuery(sql);
2180    
2181                                    QueryPos qPos = QueryPos.getInstance(q);
2182    
2183                                    qPos.add(userId);
2184    
2185                                    count = (Long)q.uniqueResult();
2186    
2187                                    finderCache.putResult(finderPath, finderArgs, count);
2188                            }
2189                            catch (Exception e) {
2190                                    finderCache.removeResult(finderPath, finderArgs);
2191    
2192                                    throw processException(e);
2193                            }
2194                            finally {
2195                                    closeSession(session);
2196                            }
2197                    }
2198    
2199                    return count.intValue();
2200            }
2201    
2202            private static final String _FINDER_COLUMN_USERID_USERID_2 = "phone.userId = ?";
2203            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2204                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2205                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
2206                            new String[] {
2207                                    Long.class.getName(), Long.class.getName(),
2208                                    
2209                            Integer.class.getName(), Integer.class.getName(),
2210                                    OrderByComparator.class.getName()
2211                            });
2212            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2213                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2214                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
2215                            new String[] { Long.class.getName(), Long.class.getName() },
2216                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
2217                            PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2218                            PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
2219            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2220                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
2221                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2222                            new String[] { Long.class.getName(), Long.class.getName() });
2223    
2224            /**
2225             * Returns all the phones where companyId = &#63; and classNameId = &#63;.
2226             *
2227             * @param companyId the company ID
2228             * @param classNameId the class name ID
2229             * @return the matching phones
2230             */
2231            @Override
2232            public List<Phone> findByC_C(long companyId, long classNameId) {
2233                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
2234                            QueryUtil.ALL_POS, null);
2235            }
2236    
2237            /**
2238             * Returns a range of all the phones where companyId = &#63; and classNameId = &#63;.
2239             *
2240             * <p>
2241             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2242             * </p>
2243             *
2244             * @param companyId the company ID
2245             * @param classNameId the class name ID
2246             * @param start the lower bound of the range of phones
2247             * @param end the upper bound of the range of phones (not inclusive)
2248             * @return the range of matching phones
2249             */
2250            @Override
2251            public List<Phone> findByC_C(long companyId, long classNameId, int start,
2252                    int end) {
2253                    return findByC_C(companyId, classNameId, start, end, null);
2254            }
2255    
2256            /**
2257             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63;.
2258             *
2259             * <p>
2260             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2261             * </p>
2262             *
2263             * @param companyId the company ID
2264             * @param classNameId the class name ID
2265             * @param start the lower bound of the range of phones
2266             * @param end the upper bound of the range of phones (not inclusive)
2267             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2268             * @return the ordered range of matching phones
2269             */
2270            @Override
2271            public List<Phone> findByC_C(long companyId, long classNameId, int start,
2272                    int end, OrderByComparator<Phone> orderByComparator) {
2273                    return findByC_C(companyId, classNameId, start, end, orderByComparator,
2274                            true);
2275            }
2276    
2277            /**
2278             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63;.
2279             *
2280             * <p>
2281             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2282             * </p>
2283             *
2284             * @param companyId the company ID
2285             * @param classNameId the class name ID
2286             * @param start the lower bound of the range of phones
2287             * @param end the upper bound of the range of phones (not inclusive)
2288             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2289             * @param retrieveFromCache whether to retrieve from the finder cache
2290             * @return the ordered range of matching phones
2291             */
2292            @Override
2293            public List<Phone> findByC_C(long companyId, long classNameId, int start,
2294                    int end, OrderByComparator<Phone> orderByComparator,
2295                    boolean retrieveFromCache) {
2296                    boolean pagination = true;
2297                    FinderPath finderPath = null;
2298                    Object[] finderArgs = null;
2299    
2300                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2301                                    (orderByComparator == null)) {
2302                            pagination = false;
2303                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2304                            finderArgs = new Object[] { companyId, classNameId };
2305                    }
2306                    else {
2307                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2308                            finderArgs = new Object[] {
2309                                            companyId, classNameId,
2310                                            
2311                                            start, end, orderByComparator
2312                                    };
2313                    }
2314    
2315                    List<Phone> list = null;
2316    
2317                    if (retrieveFromCache) {
2318                            list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
2319                                            this);
2320    
2321                            if ((list != null) && !list.isEmpty()) {
2322                                    for (Phone phone : list) {
2323                                            if ((companyId != phone.getCompanyId()) ||
2324                                                            (classNameId != phone.getClassNameId())) {
2325                                                    list = null;
2326    
2327                                                    break;
2328                                            }
2329                                    }
2330                            }
2331                    }
2332    
2333                    if (list == null) {
2334                            StringBundler query = null;
2335    
2336                            if (orderByComparator != null) {
2337                                    query = new StringBundler(4 +
2338                                                    (orderByComparator.getOrderByFields().length * 3));
2339                            }
2340                            else {
2341                                    query = new StringBundler(4);
2342                            }
2343    
2344                            query.append(_SQL_SELECT_PHONE_WHERE);
2345    
2346                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2347    
2348                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2349    
2350                            if (orderByComparator != null) {
2351                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2352                                            orderByComparator);
2353                            }
2354                            else
2355                             if (pagination) {
2356                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
2357                            }
2358    
2359                            String sql = query.toString();
2360    
2361                            Session session = null;
2362    
2363                            try {
2364                                    session = openSession();
2365    
2366                                    Query q = session.createQuery(sql);
2367    
2368                                    QueryPos qPos = QueryPos.getInstance(q);
2369    
2370                                    qPos.add(companyId);
2371    
2372                                    qPos.add(classNameId);
2373    
2374                                    if (!pagination) {
2375                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2376                                                            end, false);
2377    
2378                                            Collections.sort(list);
2379    
2380                                            list = Collections.unmodifiableList(list);
2381                                    }
2382                                    else {
2383                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2384                                                            end);
2385                                    }
2386    
2387                                    cacheResult(list);
2388    
2389                                    finderCache.putResult(finderPath, finderArgs, list);
2390                            }
2391                            catch (Exception e) {
2392                                    finderCache.removeResult(finderPath, finderArgs);
2393    
2394                                    throw processException(e);
2395                            }
2396                            finally {
2397                                    closeSession(session);
2398                            }
2399                    }
2400    
2401                    return list;
2402            }
2403    
2404            /**
2405             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63;.
2406             *
2407             * @param companyId the company ID
2408             * @param classNameId the class name ID
2409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2410             * @return the first matching phone
2411             * @throws NoSuchPhoneException if a matching phone could not be found
2412             */
2413            @Override
2414            public Phone findByC_C_First(long companyId, long classNameId,
2415                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2416                    Phone phone = fetchByC_C_First(companyId, classNameId, orderByComparator);
2417    
2418                    if (phone != null) {
2419                            return phone;
2420                    }
2421    
2422                    StringBundler msg = new StringBundler(6);
2423    
2424                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2425    
2426                    msg.append("companyId=");
2427                    msg.append(companyId);
2428    
2429                    msg.append(", classNameId=");
2430                    msg.append(classNameId);
2431    
2432                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2433    
2434                    throw new NoSuchPhoneException(msg.toString());
2435            }
2436    
2437            /**
2438             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63;.
2439             *
2440             * @param companyId the company ID
2441             * @param classNameId the class name ID
2442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2443             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
2444             */
2445            @Override
2446            public Phone fetchByC_C_First(long companyId, long classNameId,
2447                    OrderByComparator<Phone> orderByComparator) {
2448                    List<Phone> list = findByC_C(companyId, classNameId, 0, 1,
2449                                    orderByComparator);
2450    
2451                    if (!list.isEmpty()) {
2452                            return list.get(0);
2453                    }
2454    
2455                    return null;
2456            }
2457    
2458            /**
2459             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63;.
2460             *
2461             * @param companyId the company ID
2462             * @param classNameId the class name ID
2463             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2464             * @return the last matching phone
2465             * @throws NoSuchPhoneException if a matching phone could not be found
2466             */
2467            @Override
2468            public Phone findByC_C_Last(long companyId, long classNameId,
2469                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
2470                    Phone phone = fetchByC_C_Last(companyId, classNameId, orderByComparator);
2471    
2472                    if (phone != null) {
2473                            return phone;
2474                    }
2475    
2476                    StringBundler msg = new StringBundler(6);
2477    
2478                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2479    
2480                    msg.append("companyId=");
2481                    msg.append(companyId);
2482    
2483                    msg.append(", classNameId=");
2484                    msg.append(classNameId);
2485    
2486                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2487    
2488                    throw new NoSuchPhoneException(msg.toString());
2489            }
2490    
2491            /**
2492             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63;.
2493             *
2494             * @param companyId the company ID
2495             * @param classNameId the class name ID
2496             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2497             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
2498             */
2499            @Override
2500            public Phone fetchByC_C_Last(long companyId, long classNameId,
2501                    OrderByComparator<Phone> orderByComparator) {
2502                    int count = countByC_C(companyId, classNameId);
2503    
2504                    if (count == 0) {
2505                            return null;
2506                    }
2507    
2508                    List<Phone> list = findByC_C(companyId, classNameId, count - 1, count,
2509                                    orderByComparator);
2510    
2511                    if (!list.isEmpty()) {
2512                            return list.get(0);
2513                    }
2514    
2515                    return null;
2516            }
2517    
2518            /**
2519             * Returns the phones before and after the current phone in the ordered set where companyId = &#63; and classNameId = &#63;.
2520             *
2521             * @param phoneId the primary key of the current phone
2522             * @param companyId the company ID
2523             * @param classNameId the class name ID
2524             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2525             * @return the previous, current, and next phone
2526             * @throws NoSuchPhoneException if a phone with the primary key could not be found
2527             */
2528            @Override
2529            public Phone[] findByC_C_PrevAndNext(long phoneId, long companyId,
2530                    long classNameId, OrderByComparator<Phone> orderByComparator)
2531                    throws NoSuchPhoneException {
2532                    Phone phone = findByPrimaryKey(phoneId);
2533    
2534                    Session session = null;
2535    
2536                    try {
2537                            session = openSession();
2538    
2539                            Phone[] array = new PhoneImpl[3];
2540    
2541                            array[0] = getByC_C_PrevAndNext(session, phone, companyId,
2542                                            classNameId, orderByComparator, true);
2543    
2544                            array[1] = phone;
2545    
2546                            array[2] = getByC_C_PrevAndNext(session, phone, companyId,
2547                                            classNameId, orderByComparator, false);
2548    
2549                            return array;
2550                    }
2551                    catch (Exception e) {
2552                            throw processException(e);
2553                    }
2554                    finally {
2555                            closeSession(session);
2556                    }
2557            }
2558    
2559            protected Phone getByC_C_PrevAndNext(Session session, Phone phone,
2560                    long companyId, long classNameId,
2561                    OrderByComparator<Phone> orderByComparator, boolean previous) {
2562                    StringBundler query = null;
2563    
2564                    if (orderByComparator != null) {
2565                            query = new StringBundler(6 +
2566                                            (orderByComparator.getOrderByFields().length * 6));
2567                    }
2568                    else {
2569                            query = new StringBundler(3);
2570                    }
2571    
2572                    query.append(_SQL_SELECT_PHONE_WHERE);
2573    
2574                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2575    
2576                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2577    
2578                    if (orderByComparator != null) {
2579                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2580    
2581                            if (orderByConditionFields.length > 0) {
2582                                    query.append(WHERE_AND);
2583                            }
2584    
2585                            for (int i = 0; i < orderByConditionFields.length; i++) {
2586                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2587                                    query.append(orderByConditionFields[i]);
2588    
2589                                    if ((i + 1) < orderByConditionFields.length) {
2590                                            if (orderByComparator.isAscending() ^ previous) {
2591                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2592                                            }
2593                                            else {
2594                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2595                                            }
2596                                    }
2597                                    else {
2598                                            if (orderByComparator.isAscending() ^ previous) {
2599                                                    query.append(WHERE_GREATER_THAN);
2600                                            }
2601                                            else {
2602                                                    query.append(WHERE_LESSER_THAN);
2603                                            }
2604                                    }
2605                            }
2606    
2607                            query.append(ORDER_BY_CLAUSE);
2608    
2609                            String[] orderByFields = orderByComparator.getOrderByFields();
2610    
2611                            for (int i = 0; i < orderByFields.length; i++) {
2612                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2613                                    query.append(orderByFields[i]);
2614    
2615                                    if ((i + 1) < orderByFields.length) {
2616                                            if (orderByComparator.isAscending() ^ previous) {
2617                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2618                                            }
2619                                            else {
2620                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2621                                            }
2622                                    }
2623                                    else {
2624                                            if (orderByComparator.isAscending() ^ previous) {
2625                                                    query.append(ORDER_BY_ASC);
2626                                            }
2627                                            else {
2628                                                    query.append(ORDER_BY_DESC);
2629                                            }
2630                                    }
2631                            }
2632                    }
2633                    else {
2634                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
2635                    }
2636    
2637                    String sql = query.toString();
2638    
2639                    Query q = session.createQuery(sql);
2640    
2641                    q.setFirstResult(0);
2642                    q.setMaxResults(2);
2643    
2644                    QueryPos qPos = QueryPos.getInstance(q);
2645    
2646                    qPos.add(companyId);
2647    
2648                    qPos.add(classNameId);
2649    
2650                    if (orderByComparator != null) {
2651                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
2652    
2653                            for (Object value : values) {
2654                                    qPos.add(value);
2655                            }
2656                    }
2657    
2658                    List<Phone> list = q.list();
2659    
2660                    if (list.size() == 2) {
2661                            return list.get(1);
2662                    }
2663                    else {
2664                            return null;
2665                    }
2666            }
2667    
2668            /**
2669             * Removes all the phones where companyId = &#63; and classNameId = &#63; from the database.
2670             *
2671             * @param companyId the company ID
2672             * @param classNameId the class name ID
2673             */
2674            @Override
2675            public void removeByC_C(long companyId, long classNameId) {
2676                    for (Phone phone : findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
2677                                    QueryUtil.ALL_POS, null)) {
2678                            remove(phone);
2679                    }
2680            }
2681    
2682            /**
2683             * Returns the number of phones where companyId = &#63; and classNameId = &#63;.
2684             *
2685             * @param companyId the company ID
2686             * @param classNameId the class name ID
2687             * @return the number of matching phones
2688             */
2689            @Override
2690            public int countByC_C(long companyId, long classNameId) {
2691                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
2692    
2693                    Object[] finderArgs = new Object[] { companyId, classNameId };
2694    
2695                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2696    
2697                    if (count == null) {
2698                            StringBundler query = new StringBundler(3);
2699    
2700                            query.append(_SQL_COUNT_PHONE_WHERE);
2701    
2702                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2703    
2704                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2705    
2706                            String sql = query.toString();
2707    
2708                            Session session = null;
2709    
2710                            try {
2711                                    session = openSession();
2712    
2713                                    Query q = session.createQuery(sql);
2714    
2715                                    QueryPos qPos = QueryPos.getInstance(q);
2716    
2717                                    qPos.add(companyId);
2718    
2719                                    qPos.add(classNameId);
2720    
2721                                    count = (Long)q.uniqueResult();
2722    
2723                                    finderCache.putResult(finderPath, finderArgs, count);
2724                            }
2725                            catch (Exception e) {
2726                                    finderCache.removeResult(finderPath, finderArgs);
2727    
2728                                    throw processException(e);
2729                            }
2730                            finally {
2731                                    closeSession(session);
2732                            }
2733                    }
2734    
2735                    return count.intValue();
2736            }
2737    
2738            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
2739            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "phone.classNameId = ?";
2740            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2741                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2742                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
2743                            new String[] {
2744                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2745                                    
2746                            Integer.class.getName(), Integer.class.getName(),
2747                                    OrderByComparator.class.getName()
2748                            });
2749            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2750                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
2751                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
2752                            new String[] {
2753                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
2754                            },
2755                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
2756                            PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2757                            PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
2758                            PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
2759            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
2760                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
2761                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
2762                            new String[] {
2763                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
2764                            });
2765    
2766            /**
2767             * Returns all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2768             *
2769             * @param companyId the company ID
2770             * @param classNameId the class name ID
2771             * @param classPK the class p k
2772             * @return the matching phones
2773             */
2774            @Override
2775            public List<Phone> findByC_C_C(long companyId, long classNameId,
2776                    long classPK) {
2777                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
2778                            QueryUtil.ALL_POS, null);
2779            }
2780    
2781            /**
2782             * Returns a range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2783             *
2784             * <p>
2785             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2786             * </p>
2787             *
2788             * @param companyId the company ID
2789             * @param classNameId the class name ID
2790             * @param classPK the class p k
2791             * @param start the lower bound of the range of phones
2792             * @param end the upper bound of the range of phones (not inclusive)
2793             * @return the range of matching phones
2794             */
2795            @Override
2796            public List<Phone> findByC_C_C(long companyId, long classNameId,
2797                    long classPK, int start, int end) {
2798                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
2799            }
2800    
2801            /**
2802             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2803             *
2804             * <p>
2805             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2806             * </p>
2807             *
2808             * @param companyId the company ID
2809             * @param classNameId the class name ID
2810             * @param classPK the class p k
2811             * @param start the lower bound of the range of phones
2812             * @param end the upper bound of the range of phones (not inclusive)
2813             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2814             * @return the ordered range of matching phones
2815             */
2816            @Override
2817            public List<Phone> findByC_C_C(long companyId, long classNameId,
2818                    long classPK, int start, int end,
2819                    OrderByComparator<Phone> orderByComparator) {
2820                    return findByC_C_C(companyId, classNameId, classPK, start, end,
2821                            orderByComparator, true);
2822            }
2823    
2824            /**
2825             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2826             *
2827             * <p>
2828             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2829             * </p>
2830             *
2831             * @param companyId the company ID
2832             * @param classNameId the class name ID
2833             * @param classPK the class p k
2834             * @param start the lower bound of the range of phones
2835             * @param end the upper bound of the range of phones (not inclusive)
2836             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2837             * @param retrieveFromCache whether to retrieve from the finder cache
2838             * @return the ordered range of matching phones
2839             */
2840            @Override
2841            public List<Phone> findByC_C_C(long companyId, long classNameId,
2842                    long classPK, int start, int end,
2843                    OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
2844                    boolean pagination = true;
2845                    FinderPath finderPath = null;
2846                    Object[] finderArgs = null;
2847    
2848                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2849                                    (orderByComparator == null)) {
2850                            pagination = false;
2851                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
2852                            finderArgs = new Object[] { companyId, classNameId, classPK };
2853                    }
2854                    else {
2855                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
2856                            finderArgs = new Object[] {
2857                                            companyId, classNameId, classPK,
2858                                            
2859                                            start, end, orderByComparator
2860                                    };
2861                    }
2862    
2863                    List<Phone> list = null;
2864    
2865                    if (retrieveFromCache) {
2866                            list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
2867                                            this);
2868    
2869                            if ((list != null) && !list.isEmpty()) {
2870                                    for (Phone phone : list) {
2871                                            if ((companyId != phone.getCompanyId()) ||
2872                                                            (classNameId != phone.getClassNameId()) ||
2873                                                            (classPK != phone.getClassPK())) {
2874                                                    list = null;
2875    
2876                                                    break;
2877                                            }
2878                                    }
2879                            }
2880                    }
2881    
2882                    if (list == null) {
2883                            StringBundler query = null;
2884    
2885                            if (orderByComparator != null) {
2886                                    query = new StringBundler(5 +
2887                                                    (orderByComparator.getOrderByFields().length * 3));
2888                            }
2889                            else {
2890                                    query = new StringBundler(5);
2891                            }
2892    
2893                            query.append(_SQL_SELECT_PHONE_WHERE);
2894    
2895                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2896    
2897                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2898    
2899                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2900    
2901                            if (orderByComparator != null) {
2902                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2903                                            orderByComparator);
2904                            }
2905                            else
2906                             if (pagination) {
2907                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
2908                            }
2909    
2910                            String sql = query.toString();
2911    
2912                            Session session = null;
2913    
2914                            try {
2915                                    session = openSession();
2916    
2917                                    Query q = session.createQuery(sql);
2918    
2919                                    QueryPos qPos = QueryPos.getInstance(q);
2920    
2921                                    qPos.add(companyId);
2922    
2923                                    qPos.add(classNameId);
2924    
2925                                    qPos.add(classPK);
2926    
2927                                    if (!pagination) {
2928                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2929                                                            end, false);
2930    
2931                                            Collections.sort(list);
2932    
2933                                            list = Collections.unmodifiableList(list);
2934                                    }
2935                                    else {
2936                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2937                                                            end);
2938                                    }
2939    
2940                                    cacheResult(list);
2941    
2942                                    finderCache.putResult(finderPath, finderArgs, list);
2943                            }
2944                            catch (Exception e) {
2945                                    finderCache.removeResult(finderPath, finderArgs);
2946    
2947                                    throw processException(e);
2948                            }
2949                            finally {
2950                                    closeSession(session);
2951                            }
2952                    }
2953    
2954                    return list;
2955            }
2956    
2957            /**
2958             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2959             *
2960             * @param companyId the company ID
2961             * @param classNameId the class name ID
2962             * @param classPK the class p k
2963             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2964             * @return the first matching phone
2965             * @throws NoSuchPhoneException if a matching phone could not be found
2966             */
2967            @Override
2968            public Phone findByC_C_C_First(long companyId, long classNameId,
2969                    long classPK, OrderByComparator<Phone> orderByComparator)
2970                    throws NoSuchPhoneException {
2971                    Phone phone = fetchByC_C_C_First(companyId, classNameId, classPK,
2972                                    orderByComparator);
2973    
2974                    if (phone != null) {
2975                            return phone;
2976                    }
2977    
2978                    StringBundler msg = new StringBundler(8);
2979    
2980                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2981    
2982                    msg.append("companyId=");
2983                    msg.append(companyId);
2984    
2985                    msg.append(", classNameId=");
2986                    msg.append(classNameId);
2987    
2988                    msg.append(", classPK=");
2989                    msg.append(classPK);
2990    
2991                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2992    
2993                    throw new NoSuchPhoneException(msg.toString());
2994            }
2995    
2996            /**
2997             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2998             *
2999             * @param companyId the company ID
3000             * @param classNameId the class name ID
3001             * @param classPK the class p k
3002             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3003             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
3004             */
3005            @Override
3006            public Phone fetchByC_C_C_First(long companyId, long classNameId,
3007                    long classPK, OrderByComparator<Phone> orderByComparator) {
3008                    List<Phone> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
3009                                    orderByComparator);
3010    
3011                    if (!list.isEmpty()) {
3012                            return list.get(0);
3013                    }
3014    
3015                    return null;
3016            }
3017    
3018            /**
3019             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3020             *
3021             * @param companyId the company ID
3022             * @param classNameId the class name ID
3023             * @param classPK the class p k
3024             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3025             * @return the last matching phone
3026             * @throws NoSuchPhoneException if a matching phone could not be found
3027             */
3028            @Override
3029            public Phone findByC_C_C_Last(long companyId, long classNameId,
3030                    long classPK, OrderByComparator<Phone> orderByComparator)
3031                    throws NoSuchPhoneException {
3032                    Phone phone = fetchByC_C_C_Last(companyId, classNameId, classPK,
3033                                    orderByComparator);
3034    
3035                    if (phone != null) {
3036                            return phone;
3037                    }
3038    
3039                    StringBundler msg = new StringBundler(8);
3040    
3041                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3042    
3043                    msg.append("companyId=");
3044                    msg.append(companyId);
3045    
3046                    msg.append(", classNameId=");
3047                    msg.append(classNameId);
3048    
3049                    msg.append(", classPK=");
3050                    msg.append(classPK);
3051    
3052                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3053    
3054                    throw new NoSuchPhoneException(msg.toString());
3055            }
3056    
3057            /**
3058             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3059             *
3060             * @param companyId the company ID
3061             * @param classNameId the class name ID
3062             * @param classPK the class p k
3063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3064             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
3065             */
3066            @Override
3067            public Phone fetchByC_C_C_Last(long companyId, long classNameId,
3068                    long classPK, OrderByComparator<Phone> orderByComparator) {
3069                    int count = countByC_C_C(companyId, classNameId, classPK);
3070    
3071                    if (count == 0) {
3072                            return null;
3073                    }
3074    
3075                    List<Phone> list = findByC_C_C(companyId, classNameId, classPK,
3076                                    count - 1, count, orderByComparator);
3077    
3078                    if (!list.isEmpty()) {
3079                            return list.get(0);
3080                    }
3081    
3082                    return null;
3083            }
3084    
3085            /**
3086             * Returns the phones before and after the current phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3087             *
3088             * @param phoneId the primary key of the current phone
3089             * @param companyId the company ID
3090             * @param classNameId the class name ID
3091             * @param classPK the class p k
3092             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3093             * @return the previous, current, and next phone
3094             * @throws NoSuchPhoneException if a phone with the primary key could not be found
3095             */
3096            @Override
3097            public Phone[] findByC_C_C_PrevAndNext(long phoneId, long companyId,
3098                    long classNameId, long classPK,
3099                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3100                    Phone phone = findByPrimaryKey(phoneId);
3101    
3102                    Session session = null;
3103    
3104                    try {
3105                            session = openSession();
3106    
3107                            Phone[] array = new PhoneImpl[3];
3108    
3109                            array[0] = getByC_C_C_PrevAndNext(session, phone, companyId,
3110                                            classNameId, classPK, orderByComparator, true);
3111    
3112                            array[1] = phone;
3113    
3114                            array[2] = getByC_C_C_PrevAndNext(session, phone, companyId,
3115                                            classNameId, classPK, orderByComparator, false);
3116    
3117                            return array;
3118                    }
3119                    catch (Exception e) {
3120                            throw processException(e);
3121                    }
3122                    finally {
3123                            closeSession(session);
3124                    }
3125            }
3126    
3127            protected Phone getByC_C_C_PrevAndNext(Session session, Phone phone,
3128                    long companyId, long classNameId, long classPK,
3129                    OrderByComparator<Phone> orderByComparator, boolean previous) {
3130                    StringBundler query = null;
3131    
3132                    if (orderByComparator != null) {
3133                            query = new StringBundler(6 +
3134                                            (orderByComparator.getOrderByFields().length * 6));
3135                    }
3136                    else {
3137                            query = new StringBundler(3);
3138                    }
3139    
3140                    query.append(_SQL_SELECT_PHONE_WHERE);
3141    
3142                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3143    
3144                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3145    
3146                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3147    
3148                    if (orderByComparator != null) {
3149                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3150    
3151                            if (orderByConditionFields.length > 0) {
3152                                    query.append(WHERE_AND);
3153                            }
3154    
3155                            for (int i = 0; i < orderByConditionFields.length; i++) {
3156                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3157                                    query.append(orderByConditionFields[i]);
3158    
3159                                    if ((i + 1) < orderByConditionFields.length) {
3160                                            if (orderByComparator.isAscending() ^ previous) {
3161                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3162                                            }
3163                                            else {
3164                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3165                                            }
3166                                    }
3167                                    else {
3168                                            if (orderByComparator.isAscending() ^ previous) {
3169                                                    query.append(WHERE_GREATER_THAN);
3170                                            }
3171                                            else {
3172                                                    query.append(WHERE_LESSER_THAN);
3173                                            }
3174                                    }
3175                            }
3176    
3177                            query.append(ORDER_BY_CLAUSE);
3178    
3179                            String[] orderByFields = orderByComparator.getOrderByFields();
3180    
3181                            for (int i = 0; i < orderByFields.length; i++) {
3182                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3183                                    query.append(orderByFields[i]);
3184    
3185                                    if ((i + 1) < orderByFields.length) {
3186                                            if (orderByComparator.isAscending() ^ previous) {
3187                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3188                                            }
3189                                            else {
3190                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3191                                            }
3192                                    }
3193                                    else {
3194                                            if (orderByComparator.isAscending() ^ previous) {
3195                                                    query.append(ORDER_BY_ASC);
3196                                            }
3197                                            else {
3198                                                    query.append(ORDER_BY_DESC);
3199                                            }
3200                                    }
3201                            }
3202                    }
3203                    else {
3204                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
3205                    }
3206    
3207                    String sql = query.toString();
3208    
3209                    Query q = session.createQuery(sql);
3210    
3211                    q.setFirstResult(0);
3212                    q.setMaxResults(2);
3213    
3214                    QueryPos qPos = QueryPos.getInstance(q);
3215    
3216                    qPos.add(companyId);
3217    
3218                    qPos.add(classNameId);
3219    
3220                    qPos.add(classPK);
3221    
3222                    if (orderByComparator != null) {
3223                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
3224    
3225                            for (Object value : values) {
3226                                    qPos.add(value);
3227                            }
3228                    }
3229    
3230                    List<Phone> list = q.list();
3231    
3232                    if (list.size() == 2) {
3233                            return list.get(1);
3234                    }
3235                    else {
3236                            return null;
3237                    }
3238            }
3239    
3240            /**
3241             * Removes all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
3242             *
3243             * @param companyId the company ID
3244             * @param classNameId the class name ID
3245             * @param classPK the class p k
3246             */
3247            @Override
3248            public void removeByC_C_C(long companyId, long classNameId, long classPK) {
3249                    for (Phone phone : findByC_C_C(companyId, classNameId, classPK,
3250                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3251                            remove(phone);
3252                    }
3253            }
3254    
3255            /**
3256             * Returns the number of phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3257             *
3258             * @param companyId the company ID
3259             * @param classNameId the class name ID
3260             * @param classPK the class p k
3261             * @return the number of matching phones
3262             */
3263            @Override
3264            public int countByC_C_C(long companyId, long classNameId, long classPK) {
3265                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
3266    
3267                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
3268    
3269                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3270    
3271                    if (count == null) {
3272                            StringBundler query = new StringBundler(4);
3273    
3274                            query.append(_SQL_COUNT_PHONE_WHERE);
3275    
3276                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3277    
3278                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3279    
3280                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3281    
3282                            String sql = query.toString();
3283    
3284                            Session session = null;
3285    
3286                            try {
3287                                    session = openSession();
3288    
3289                                    Query q = session.createQuery(sql);
3290    
3291                                    QueryPos qPos = QueryPos.getInstance(q);
3292    
3293                                    qPos.add(companyId);
3294    
3295                                    qPos.add(classNameId);
3296    
3297                                    qPos.add(classPK);
3298    
3299                                    count = (Long)q.uniqueResult();
3300    
3301                                    finderCache.putResult(finderPath, finderArgs, count);
3302                            }
3303                            catch (Exception e) {
3304                                    finderCache.removeResult(finderPath, finderArgs);
3305    
3306                                    throw processException(e);
3307                            }
3308                            finally {
3309                                    closeSession(session);
3310                            }
3311                    }
3312    
3313                    return count.intValue();
3314            }
3315    
3316            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
3317            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
3318            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "phone.classPK = ?";
3319            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3320                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
3321                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_P",
3322                            new String[] {
3323                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3324                                    Boolean.class.getName(),
3325                                    
3326                            Integer.class.getName(), Integer.class.getName(),
3327                                    OrderByComparator.class.getName()
3328                            });
3329            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P =
3330                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3331                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
3332                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_P",
3333                            new String[] {
3334                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3335                                    Boolean.class.getName()
3336                            },
3337                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
3338                            PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3339                            PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
3340                            PhoneModelImpl.PRIMARY_COLUMN_BITMASK |
3341                            PhoneModelImpl.CREATEDATE_COLUMN_BITMASK);
3342            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3343                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
3344                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_P",
3345                            new String[] {
3346                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3347                                    Boolean.class.getName()
3348                            });
3349    
3350            /**
3351             * Returns all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3352             *
3353             * @param companyId the company ID
3354             * @param classNameId the class name ID
3355             * @param classPK the class p k
3356             * @param primary the primary
3357             * @return the matching phones
3358             */
3359            @Override
3360            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3361                    long classPK, boolean primary) {
3362                    return findByC_C_C_P(companyId, classNameId, classPK, primary,
3363                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3364            }
3365    
3366            /**
3367             * Returns a range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3368             *
3369             * <p>
3370             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3371             * </p>
3372             *
3373             * @param companyId the company ID
3374             * @param classNameId the class name ID
3375             * @param classPK the class p k
3376             * @param primary the primary
3377             * @param start the lower bound of the range of phones
3378             * @param end the upper bound of the range of phones (not inclusive)
3379             * @return the range of matching phones
3380             */
3381            @Override
3382            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3383                    long classPK, boolean primary, int start, int end) {
3384                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
3385                            end, null);
3386            }
3387    
3388            /**
3389             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3390             *
3391             * <p>
3392             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3393             * </p>
3394             *
3395             * @param companyId the company ID
3396             * @param classNameId the class name ID
3397             * @param classPK the class p k
3398             * @param primary the primary
3399             * @param start the lower bound of the range of phones
3400             * @param end the upper bound of the range of phones (not inclusive)
3401             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3402             * @return the ordered range of matching phones
3403             */
3404            @Override
3405            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3406                    long classPK, boolean primary, int start, int end,
3407                    OrderByComparator<Phone> orderByComparator) {
3408                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
3409                            end, orderByComparator, true);
3410            }
3411    
3412            /**
3413             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3414             *
3415             * <p>
3416             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3417             * </p>
3418             *
3419             * @param companyId the company ID
3420             * @param classNameId the class name ID
3421             * @param classPK the class p k
3422             * @param primary the primary
3423             * @param start the lower bound of the range of phones
3424             * @param end the upper bound of the range of phones (not inclusive)
3425             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3426             * @param retrieveFromCache whether to retrieve from the finder cache
3427             * @return the ordered range of matching phones
3428             */
3429            @Override
3430            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
3431                    long classPK, boolean primary, int start, int end,
3432                    OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
3433                    boolean pagination = true;
3434                    FinderPath finderPath = null;
3435                    Object[] finderArgs = null;
3436    
3437                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3438                                    (orderByComparator == null)) {
3439                            pagination = false;
3440                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P;
3441                            finderArgs = new Object[] { companyId, classNameId, classPK, primary };
3442                    }
3443                    else {
3444                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
3445                            finderArgs = new Object[] {
3446                                            companyId, classNameId, classPK, primary,
3447                                            
3448                                            start, end, orderByComparator
3449                                    };
3450                    }
3451    
3452                    List<Phone> list = null;
3453    
3454                    if (retrieveFromCache) {
3455                            list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
3456                                            this);
3457    
3458                            if ((list != null) && !list.isEmpty()) {
3459                                    for (Phone phone : list) {
3460                                            if ((companyId != phone.getCompanyId()) ||
3461                                                            (classNameId != phone.getClassNameId()) ||
3462                                                            (classPK != phone.getClassPK()) ||
3463                                                            (primary != phone.getPrimary())) {
3464                                                    list = null;
3465    
3466                                                    break;
3467                                            }
3468                                    }
3469                            }
3470                    }
3471    
3472                    if (list == null) {
3473                            StringBundler query = null;
3474    
3475                            if (orderByComparator != null) {
3476                                    query = new StringBundler(6 +
3477                                                    (orderByComparator.getOrderByFields().length * 3));
3478                            }
3479                            else {
3480                                    query = new StringBundler(6);
3481                            }
3482    
3483                            query.append(_SQL_SELECT_PHONE_WHERE);
3484    
3485                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3486    
3487                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3488    
3489                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3490    
3491                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3492    
3493                            if (orderByComparator != null) {
3494                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3495                                            orderByComparator);
3496                            }
3497                            else
3498                             if (pagination) {
3499                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
3500                            }
3501    
3502                            String sql = query.toString();
3503    
3504                            Session session = null;
3505    
3506                            try {
3507                                    session = openSession();
3508    
3509                                    Query q = session.createQuery(sql);
3510    
3511                                    QueryPos qPos = QueryPos.getInstance(q);
3512    
3513                                    qPos.add(companyId);
3514    
3515                                    qPos.add(classNameId);
3516    
3517                                    qPos.add(classPK);
3518    
3519                                    qPos.add(primary);
3520    
3521                                    if (!pagination) {
3522                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
3523                                                            end, false);
3524    
3525                                            Collections.sort(list);
3526    
3527                                            list = Collections.unmodifiableList(list);
3528                                    }
3529                                    else {
3530                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
3531                                                            end);
3532                                    }
3533    
3534                                    cacheResult(list);
3535    
3536                                    finderCache.putResult(finderPath, finderArgs, list);
3537                            }
3538                            catch (Exception e) {
3539                                    finderCache.removeResult(finderPath, finderArgs);
3540    
3541                                    throw processException(e);
3542                            }
3543                            finally {
3544                                    closeSession(session);
3545                            }
3546                    }
3547    
3548                    return list;
3549            }
3550    
3551            /**
3552             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3553             *
3554             * @param companyId the company ID
3555             * @param classNameId the class name ID
3556             * @param classPK the class p k
3557             * @param primary the primary
3558             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3559             * @return the first matching phone
3560             * @throws NoSuchPhoneException if a matching phone could not be found
3561             */
3562            @Override
3563            public Phone findByC_C_C_P_First(long companyId, long classNameId,
3564                    long classPK, boolean primary,
3565                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3566                    Phone phone = fetchByC_C_C_P_First(companyId, classNameId, classPK,
3567                                    primary, orderByComparator);
3568    
3569                    if (phone != null) {
3570                            return phone;
3571                    }
3572    
3573                    StringBundler msg = new StringBundler(10);
3574    
3575                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3576    
3577                    msg.append("companyId=");
3578                    msg.append(companyId);
3579    
3580                    msg.append(", classNameId=");
3581                    msg.append(classNameId);
3582    
3583                    msg.append(", classPK=");
3584                    msg.append(classPK);
3585    
3586                    msg.append(", primary=");
3587                    msg.append(primary);
3588    
3589                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3590    
3591                    throw new NoSuchPhoneException(msg.toString());
3592            }
3593    
3594            /**
3595             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3596             *
3597             * @param companyId the company ID
3598             * @param classNameId the class name ID
3599             * @param classPK the class p k
3600             * @param primary the primary
3601             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3602             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
3603             */
3604            @Override
3605            public Phone fetchByC_C_C_P_First(long companyId, long classNameId,
3606                    long classPK, boolean primary,
3607                    OrderByComparator<Phone> orderByComparator) {
3608                    List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
3609                                    primary, 0, 1, orderByComparator);
3610    
3611                    if (!list.isEmpty()) {
3612                            return list.get(0);
3613                    }
3614    
3615                    return null;
3616            }
3617    
3618            /**
3619             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3620             *
3621             * @param companyId the company ID
3622             * @param classNameId the class name ID
3623             * @param classPK the class p k
3624             * @param primary the primary
3625             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3626             * @return the last matching phone
3627             * @throws NoSuchPhoneException if a matching phone could not be found
3628             */
3629            @Override
3630            public Phone findByC_C_C_P_Last(long companyId, long classNameId,
3631                    long classPK, boolean primary,
3632                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3633                    Phone phone = fetchByC_C_C_P_Last(companyId, classNameId, classPK,
3634                                    primary, orderByComparator);
3635    
3636                    if (phone != null) {
3637                            return phone;
3638                    }
3639    
3640                    StringBundler msg = new StringBundler(10);
3641    
3642                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3643    
3644                    msg.append("companyId=");
3645                    msg.append(companyId);
3646    
3647                    msg.append(", classNameId=");
3648                    msg.append(classNameId);
3649    
3650                    msg.append(", classPK=");
3651                    msg.append(classPK);
3652    
3653                    msg.append(", primary=");
3654                    msg.append(primary);
3655    
3656                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3657    
3658                    throw new NoSuchPhoneException(msg.toString());
3659            }
3660    
3661            /**
3662             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3663             *
3664             * @param companyId the company ID
3665             * @param classNameId the class name ID
3666             * @param classPK the class p k
3667             * @param primary the primary
3668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3669             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
3670             */
3671            @Override
3672            public Phone fetchByC_C_C_P_Last(long companyId, long classNameId,
3673                    long classPK, boolean primary,
3674                    OrderByComparator<Phone> orderByComparator) {
3675                    int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
3676    
3677                    if (count == 0) {
3678                            return null;
3679                    }
3680    
3681                    List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
3682                                    primary, count - 1, count, orderByComparator);
3683    
3684                    if (!list.isEmpty()) {
3685                            return list.get(0);
3686                    }
3687    
3688                    return null;
3689            }
3690    
3691            /**
3692             * 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;.
3693             *
3694             * @param phoneId the primary key of the current phone
3695             * @param companyId the company ID
3696             * @param classNameId the class name ID
3697             * @param classPK the class p k
3698             * @param primary the primary
3699             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3700             * @return the previous, current, and next phone
3701             * @throws NoSuchPhoneException if a phone with the primary key could not be found
3702             */
3703            @Override
3704            public Phone[] findByC_C_C_P_PrevAndNext(long phoneId, long companyId,
3705                    long classNameId, long classPK, boolean primary,
3706                    OrderByComparator<Phone> orderByComparator) throws NoSuchPhoneException {
3707                    Phone phone = findByPrimaryKey(phoneId);
3708    
3709                    Session session = null;
3710    
3711                    try {
3712                            session = openSession();
3713    
3714                            Phone[] array = new PhoneImpl[3];
3715    
3716                            array[0] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
3717                                            classNameId, classPK, primary, orderByComparator, true);
3718    
3719                            array[1] = phone;
3720    
3721                            array[2] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
3722                                            classNameId, classPK, primary, orderByComparator, false);
3723    
3724                            return array;
3725                    }
3726                    catch (Exception e) {
3727                            throw processException(e);
3728                    }
3729                    finally {
3730                            closeSession(session);
3731                    }
3732            }
3733    
3734            protected Phone getByC_C_C_P_PrevAndNext(Session session, Phone phone,
3735                    long companyId, long classNameId, long classPK, boolean primary,
3736                    OrderByComparator<Phone> orderByComparator, boolean previous) {
3737                    StringBundler query = null;
3738    
3739                    if (orderByComparator != null) {
3740                            query = new StringBundler(6 +
3741                                            (orderByComparator.getOrderByFields().length * 6));
3742                    }
3743                    else {
3744                            query = new StringBundler(3);
3745                    }
3746    
3747                    query.append(_SQL_SELECT_PHONE_WHERE);
3748    
3749                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3750    
3751                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3752    
3753                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3754    
3755                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3756    
3757                    if (orderByComparator != null) {
3758                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3759    
3760                            if (orderByConditionFields.length > 0) {
3761                                    query.append(WHERE_AND);
3762                            }
3763    
3764                            for (int i = 0; i < orderByConditionFields.length; i++) {
3765                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3766                                    query.append(orderByConditionFields[i]);
3767    
3768                                    if ((i + 1) < orderByConditionFields.length) {
3769                                            if (orderByComparator.isAscending() ^ previous) {
3770                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3771                                            }
3772                                            else {
3773                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3774                                            }
3775                                    }
3776                                    else {
3777                                            if (orderByComparator.isAscending() ^ previous) {
3778                                                    query.append(WHERE_GREATER_THAN);
3779                                            }
3780                                            else {
3781                                                    query.append(WHERE_LESSER_THAN);
3782                                            }
3783                                    }
3784                            }
3785    
3786                            query.append(ORDER_BY_CLAUSE);
3787    
3788                            String[] orderByFields = orderByComparator.getOrderByFields();
3789    
3790                            for (int i = 0; i < orderByFields.length; i++) {
3791                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3792                                    query.append(orderByFields[i]);
3793    
3794                                    if ((i + 1) < orderByFields.length) {
3795                                            if (orderByComparator.isAscending() ^ previous) {
3796                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3797                                            }
3798                                            else {
3799                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3800                                            }
3801                                    }
3802                                    else {
3803                                            if (orderByComparator.isAscending() ^ previous) {
3804                                                    query.append(ORDER_BY_ASC);
3805                                            }
3806                                            else {
3807                                                    query.append(ORDER_BY_DESC);
3808                                            }
3809                                    }
3810                            }
3811                    }
3812                    else {
3813                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
3814                    }
3815    
3816                    String sql = query.toString();
3817    
3818                    Query q = session.createQuery(sql);
3819    
3820                    q.setFirstResult(0);
3821                    q.setMaxResults(2);
3822    
3823                    QueryPos qPos = QueryPos.getInstance(q);
3824    
3825                    qPos.add(companyId);
3826    
3827                    qPos.add(classNameId);
3828    
3829                    qPos.add(classPK);
3830    
3831                    qPos.add(primary);
3832    
3833                    if (orderByComparator != null) {
3834                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
3835    
3836                            for (Object value : values) {
3837                                    qPos.add(value);
3838                            }
3839                    }
3840    
3841                    List<Phone> list = q.list();
3842    
3843                    if (list.size() == 2) {
3844                            return list.get(1);
3845                    }
3846                    else {
3847                            return null;
3848                    }
3849            }
3850    
3851            /**
3852             * Removes all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63; from the database.
3853             *
3854             * @param companyId the company ID
3855             * @param classNameId the class name ID
3856             * @param classPK the class p k
3857             * @param primary the primary
3858             */
3859            @Override
3860            public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
3861                    boolean primary) {
3862                    for (Phone phone : findByC_C_C_P(companyId, classNameId, classPK,
3863                                    primary, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3864                            remove(phone);
3865                    }
3866            }
3867    
3868            /**
3869             * Returns the number of phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3870             *
3871             * @param companyId the company ID
3872             * @param classNameId the class name ID
3873             * @param classPK the class p k
3874             * @param primary the primary
3875             * @return the number of matching phones
3876             */
3877            @Override
3878            public int countByC_C_C_P(long companyId, long classNameId, long classPK,
3879                    boolean primary) {
3880                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C_P;
3881    
3882                    Object[] finderArgs = new Object[] {
3883                                    companyId, classNameId, classPK, primary
3884                            };
3885    
3886                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3887    
3888                    if (count == null) {
3889                            StringBundler query = new StringBundler(5);
3890    
3891                            query.append(_SQL_COUNT_PHONE_WHERE);
3892    
3893                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3894    
3895                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3896    
3897                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3898    
3899                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3900    
3901                            String sql = query.toString();
3902    
3903                            Session session = null;
3904    
3905                            try {
3906                                    session = openSession();
3907    
3908                                    Query q = session.createQuery(sql);
3909    
3910                                    QueryPos qPos = QueryPos.getInstance(q);
3911    
3912                                    qPos.add(companyId);
3913    
3914                                    qPos.add(classNameId);
3915    
3916                                    qPos.add(classPK);
3917    
3918                                    qPos.add(primary);
3919    
3920                                    count = (Long)q.uniqueResult();
3921    
3922                                    finderCache.putResult(finderPath, finderArgs, count);
3923                            }
3924                            catch (Exception e) {
3925                                    finderCache.removeResult(finderPath, finderArgs);
3926    
3927                                    throw processException(e);
3928                            }
3929                            finally {
3930                                    closeSession(session);
3931                            }
3932                    }
3933    
3934                    return count.intValue();
3935            }
3936    
3937            private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "phone.companyId = ? AND ";
3938            private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
3939            private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "phone.classPK = ? AND ";
3940            private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "phone.primary = ?";
3941    
3942            public PhonePersistenceImpl() {
3943                    setModelClass(Phone.class);
3944            }
3945    
3946            /**
3947             * Caches the phone in the entity cache if it is enabled.
3948             *
3949             * @param phone the phone
3950             */
3951            @Override
3952            public void cacheResult(Phone phone) {
3953                    entityCache.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3954                            PhoneImpl.class, phone.getPrimaryKey(), phone);
3955    
3956                    phone.resetOriginalValues();
3957            }
3958    
3959            /**
3960             * Caches the phones in the entity cache if it is enabled.
3961             *
3962             * @param phones the phones
3963             */
3964            @Override
3965            public void cacheResult(List<Phone> phones) {
3966                    for (Phone phone : phones) {
3967                            if (entityCache.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
3968                                                    PhoneImpl.class, phone.getPrimaryKey()) == null) {
3969                                    cacheResult(phone);
3970                            }
3971                            else {
3972                                    phone.resetOriginalValues();
3973                            }
3974                    }
3975            }
3976    
3977            /**
3978             * Clears the cache for all phones.
3979             *
3980             * <p>
3981             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3982             * </p>
3983             */
3984            @Override
3985            public void clearCache() {
3986                    entityCache.clearCache(PhoneImpl.class);
3987    
3988                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
3989                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3990                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3991            }
3992    
3993            /**
3994             * Clears the cache for the phone.
3995             *
3996             * <p>
3997             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3998             * </p>
3999             */
4000            @Override
4001            public void clearCache(Phone phone) {
4002                    entityCache.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4003                            PhoneImpl.class, phone.getPrimaryKey());
4004    
4005                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4006                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4007            }
4008    
4009            @Override
4010            public void clearCache(List<Phone> phones) {
4011                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4012                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4013    
4014                    for (Phone phone : phones) {
4015                            entityCache.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4016                                    PhoneImpl.class, phone.getPrimaryKey());
4017                    }
4018            }
4019    
4020            /**
4021             * Creates a new phone with the primary key. Does not add the phone to the database.
4022             *
4023             * @param phoneId the primary key for the new phone
4024             * @return the new phone
4025             */
4026            @Override
4027            public Phone create(long phoneId) {
4028                    Phone phone = new PhoneImpl();
4029    
4030                    phone.setNew(true);
4031                    phone.setPrimaryKey(phoneId);
4032    
4033                    String uuid = PortalUUIDUtil.generate();
4034    
4035                    phone.setUuid(uuid);
4036    
4037                    return phone;
4038            }
4039    
4040            /**
4041             * Removes the phone with the primary key from the database. Also notifies the appropriate model listeners.
4042             *
4043             * @param phoneId the primary key of the phone
4044             * @return the phone that was removed
4045             * @throws NoSuchPhoneException if a phone with the primary key could not be found
4046             */
4047            @Override
4048            public Phone remove(long phoneId) throws NoSuchPhoneException {
4049                    return remove((Serializable)phoneId);
4050            }
4051    
4052            /**
4053             * Removes the phone with the primary key from the database. Also notifies the appropriate model listeners.
4054             *
4055             * @param primaryKey the primary key of the phone
4056             * @return the phone that was removed
4057             * @throws NoSuchPhoneException if a phone with the primary key could not be found
4058             */
4059            @Override
4060            public Phone remove(Serializable primaryKey) throws NoSuchPhoneException {
4061                    Session session = null;
4062    
4063                    try {
4064                            session = openSession();
4065    
4066                            Phone phone = (Phone)session.get(PhoneImpl.class, primaryKey);
4067    
4068                            if (phone == null) {
4069                                    if (_log.isWarnEnabled()) {
4070                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4071                                    }
4072    
4073                                    throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4074                                            primaryKey);
4075                            }
4076    
4077                            return remove(phone);
4078                    }
4079                    catch (NoSuchPhoneException nsee) {
4080                            throw nsee;
4081                    }
4082                    catch (Exception e) {
4083                            throw processException(e);
4084                    }
4085                    finally {
4086                            closeSession(session);
4087                    }
4088            }
4089    
4090            @Override
4091            protected Phone removeImpl(Phone phone) {
4092                    phone = toUnwrappedModel(phone);
4093    
4094                    Session session = null;
4095    
4096                    try {
4097                            session = openSession();
4098    
4099                            if (!session.contains(phone)) {
4100                                    phone = (Phone)session.get(PhoneImpl.class,
4101                                                    phone.getPrimaryKeyObj());
4102                            }
4103    
4104                            if (phone != null) {
4105                                    session.delete(phone);
4106                            }
4107                    }
4108                    catch (Exception e) {
4109                            throw processException(e);
4110                    }
4111                    finally {
4112                            closeSession(session);
4113                    }
4114    
4115                    if (phone != null) {
4116                            clearCache(phone);
4117                    }
4118    
4119                    return phone;
4120            }
4121    
4122            @Override
4123            public Phone updateImpl(Phone phone) {
4124                    phone = toUnwrappedModel(phone);
4125    
4126                    boolean isNew = phone.isNew();
4127    
4128                    PhoneModelImpl phoneModelImpl = (PhoneModelImpl)phone;
4129    
4130                    if (Validator.isNull(phone.getUuid())) {
4131                            String uuid = PortalUUIDUtil.generate();
4132    
4133                            phone.setUuid(uuid);
4134                    }
4135    
4136                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
4137    
4138                    Date now = new Date();
4139    
4140                    if (isNew && (phone.getCreateDate() == null)) {
4141                            if (serviceContext == null) {
4142                                    phone.setCreateDate(now);
4143                            }
4144                            else {
4145                                    phone.setCreateDate(serviceContext.getCreateDate(now));
4146                            }
4147                    }
4148    
4149                    if (!phoneModelImpl.hasSetModifiedDate()) {
4150                            if (serviceContext == null) {
4151                                    phone.setModifiedDate(now);
4152                            }
4153                            else {
4154                                    phone.setModifiedDate(serviceContext.getModifiedDate(now));
4155                            }
4156                    }
4157    
4158                    Session session = null;
4159    
4160                    try {
4161                            session = openSession();
4162    
4163                            if (phone.isNew()) {
4164                                    session.save(phone);
4165    
4166                                    phone.setNew(false);
4167                            }
4168                            else {
4169                                    phone = (Phone)session.merge(phone);
4170                            }
4171                    }
4172                    catch (Exception e) {
4173                            throw processException(e);
4174                    }
4175                    finally {
4176                            closeSession(session);
4177                    }
4178    
4179                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4180    
4181                    if (isNew || !PhoneModelImpl.COLUMN_BITMASK_ENABLED) {
4182                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4183                    }
4184    
4185                    else {
4186                            if ((phoneModelImpl.getColumnBitmask() &
4187                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4188                                    Object[] args = new Object[] { phoneModelImpl.getOriginalUuid() };
4189    
4190                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4191                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4192                                            args);
4193    
4194                                    args = new Object[] { phoneModelImpl.getUuid() };
4195    
4196                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4197                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4198                                            args);
4199                            }
4200    
4201                            if ((phoneModelImpl.getColumnBitmask() &
4202                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4203                                    Object[] args = new Object[] {
4204                                                    phoneModelImpl.getOriginalUuid(),
4205                                                    phoneModelImpl.getOriginalCompanyId()
4206                                            };
4207    
4208                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4209                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4210                                            args);
4211    
4212                                    args = new Object[] {
4213                                                    phoneModelImpl.getUuid(), phoneModelImpl.getCompanyId()
4214                                            };
4215    
4216                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4217                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4218                                            args);
4219                            }
4220    
4221                            if ((phoneModelImpl.getColumnBitmask() &
4222                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4223                                    Object[] args = new Object[] {
4224                                                    phoneModelImpl.getOriginalCompanyId()
4225                                            };
4226    
4227                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
4228                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4229                                            args);
4230    
4231                                    args = new Object[] { phoneModelImpl.getCompanyId() };
4232    
4233                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
4234                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4235                                            args);
4236                            }
4237    
4238                            if ((phoneModelImpl.getColumnBitmask() &
4239                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
4240                                    Object[] args = new Object[] { phoneModelImpl.getOriginalUserId() };
4241    
4242                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4243                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4244                                            args);
4245    
4246                                    args = new Object[] { phoneModelImpl.getUserId() };
4247    
4248                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4249                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4250                                            args);
4251                            }
4252    
4253                            if ((phoneModelImpl.getColumnBitmask() &
4254                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
4255                                    Object[] args = new Object[] {
4256                                                    phoneModelImpl.getOriginalCompanyId(),
4257                                                    phoneModelImpl.getOriginalClassNameId()
4258                                            };
4259    
4260                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4261                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4262                                            args);
4263    
4264                                    args = new Object[] {
4265                                                    phoneModelImpl.getCompanyId(),
4266                                                    phoneModelImpl.getClassNameId()
4267                                            };
4268    
4269                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4270                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4271                                            args);
4272                            }
4273    
4274                            if ((phoneModelImpl.getColumnBitmask() &
4275                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
4276                                    Object[] args = new Object[] {
4277                                                    phoneModelImpl.getOriginalCompanyId(),
4278                                                    phoneModelImpl.getOriginalClassNameId(),
4279                                                    phoneModelImpl.getOriginalClassPK()
4280                                            };
4281    
4282                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4283                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4284                                            args);
4285    
4286                                    args = new Object[] {
4287                                                    phoneModelImpl.getCompanyId(),
4288                                                    phoneModelImpl.getClassNameId(),
4289                                                    phoneModelImpl.getClassPK()
4290                                            };
4291    
4292                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4293                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4294                                            args);
4295                            }
4296    
4297                            if ((phoneModelImpl.getColumnBitmask() &
4298                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P.getColumnBitmask()) != 0) {
4299                                    Object[] args = new Object[] {
4300                                                    phoneModelImpl.getOriginalCompanyId(),
4301                                                    phoneModelImpl.getOriginalClassNameId(),
4302                                                    phoneModelImpl.getOriginalClassPK(),
4303                                                    phoneModelImpl.getOriginalPrimary()
4304                                            };
4305    
4306                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4307                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4308                                            args);
4309    
4310                                    args = new Object[] {
4311                                                    phoneModelImpl.getCompanyId(),
4312                                                    phoneModelImpl.getClassNameId(),
4313                                                    phoneModelImpl.getClassPK(), phoneModelImpl.getPrimary()
4314                                            };
4315    
4316                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4317                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4318                                            args);
4319                            }
4320                    }
4321    
4322                    entityCache.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4323                            PhoneImpl.class, phone.getPrimaryKey(), phone, false);
4324    
4325                    phone.resetOriginalValues();
4326    
4327                    return phone;
4328            }
4329    
4330            protected Phone toUnwrappedModel(Phone phone) {
4331                    if (phone instanceof PhoneImpl) {
4332                            return phone;
4333                    }
4334    
4335                    PhoneImpl phoneImpl = new PhoneImpl();
4336    
4337                    phoneImpl.setNew(phone.isNew());
4338                    phoneImpl.setPrimaryKey(phone.getPrimaryKey());
4339    
4340                    phoneImpl.setMvccVersion(phone.getMvccVersion());
4341                    phoneImpl.setUuid(phone.getUuid());
4342                    phoneImpl.setPhoneId(phone.getPhoneId());
4343                    phoneImpl.setCompanyId(phone.getCompanyId());
4344                    phoneImpl.setUserId(phone.getUserId());
4345                    phoneImpl.setUserName(phone.getUserName());
4346                    phoneImpl.setCreateDate(phone.getCreateDate());
4347                    phoneImpl.setModifiedDate(phone.getModifiedDate());
4348                    phoneImpl.setClassNameId(phone.getClassNameId());
4349                    phoneImpl.setClassPK(phone.getClassPK());
4350                    phoneImpl.setNumber(phone.getNumber());
4351                    phoneImpl.setExtension(phone.getExtension());
4352                    phoneImpl.setTypeId(phone.getTypeId());
4353                    phoneImpl.setPrimary(phone.isPrimary());
4354    
4355                    return phoneImpl;
4356            }
4357    
4358            /**
4359             * Returns the phone with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4360             *
4361             * @param primaryKey the primary key of the phone
4362             * @return the phone
4363             * @throws NoSuchPhoneException if a phone with the primary key could not be found
4364             */
4365            @Override
4366            public Phone findByPrimaryKey(Serializable primaryKey)
4367                    throws NoSuchPhoneException {
4368                    Phone phone = fetchByPrimaryKey(primaryKey);
4369    
4370                    if (phone == null) {
4371                            if (_log.isWarnEnabled()) {
4372                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4373                            }
4374    
4375                            throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4376                                    primaryKey);
4377                    }
4378    
4379                    return phone;
4380            }
4381    
4382            /**
4383             * Returns the phone with the primary key or throws a {@link NoSuchPhoneException} if it could not be found.
4384             *
4385             * @param phoneId the primary key of the phone
4386             * @return the phone
4387             * @throws NoSuchPhoneException if a phone with the primary key could not be found
4388             */
4389            @Override
4390            public Phone findByPrimaryKey(long phoneId) throws NoSuchPhoneException {
4391                    return findByPrimaryKey((Serializable)phoneId);
4392            }
4393    
4394            /**
4395             * Returns the phone with the primary key or returns <code>null</code> if it could not be found.
4396             *
4397             * @param primaryKey the primary key of the phone
4398             * @return the phone, or <code>null</code> if a phone with the primary key could not be found
4399             */
4400            @Override
4401            public Phone fetchByPrimaryKey(Serializable primaryKey) {
4402                    Phone phone = (Phone)entityCache.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4403                                    PhoneImpl.class, primaryKey);
4404    
4405                    if (phone == _nullPhone) {
4406                            return null;
4407                    }
4408    
4409                    if (phone == null) {
4410                            Session session = null;
4411    
4412                            try {
4413                                    session = openSession();
4414    
4415                                    phone = (Phone)session.get(PhoneImpl.class, primaryKey);
4416    
4417                                    if (phone != null) {
4418                                            cacheResult(phone);
4419                                    }
4420                                    else {
4421                                            entityCache.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4422                                                    PhoneImpl.class, primaryKey, _nullPhone);
4423                                    }
4424                            }
4425                            catch (Exception e) {
4426                                    entityCache.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4427                                            PhoneImpl.class, primaryKey);
4428    
4429                                    throw processException(e);
4430                            }
4431                            finally {
4432                                    closeSession(session);
4433                            }
4434                    }
4435    
4436                    return phone;
4437            }
4438    
4439            /**
4440             * Returns the phone with the primary key or returns <code>null</code> if it could not be found.
4441             *
4442             * @param phoneId the primary key of the phone
4443             * @return the phone, or <code>null</code> if a phone with the primary key could not be found
4444             */
4445            @Override
4446            public Phone fetchByPrimaryKey(long phoneId) {
4447                    return fetchByPrimaryKey((Serializable)phoneId);
4448            }
4449    
4450            @Override
4451            public Map<Serializable, Phone> fetchByPrimaryKeys(
4452                    Set<Serializable> primaryKeys) {
4453                    if (primaryKeys.isEmpty()) {
4454                            return Collections.emptyMap();
4455                    }
4456    
4457                    Map<Serializable, Phone> map = new HashMap<Serializable, Phone>();
4458    
4459                    if (primaryKeys.size() == 1) {
4460                            Iterator<Serializable> iterator = primaryKeys.iterator();
4461    
4462                            Serializable primaryKey = iterator.next();
4463    
4464                            Phone phone = fetchByPrimaryKey(primaryKey);
4465    
4466                            if (phone != null) {
4467                                    map.put(primaryKey, phone);
4468                            }
4469    
4470                            return map;
4471                    }
4472    
4473                    Set<Serializable> uncachedPrimaryKeys = null;
4474    
4475                    for (Serializable primaryKey : primaryKeys) {
4476                            Phone phone = (Phone)entityCache.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4477                                            PhoneImpl.class, primaryKey);
4478    
4479                            if (phone == null) {
4480                                    if (uncachedPrimaryKeys == null) {
4481                                            uncachedPrimaryKeys = new HashSet<Serializable>();
4482                                    }
4483    
4484                                    uncachedPrimaryKeys.add(primaryKey);
4485                            }
4486                            else {
4487                                    map.put(primaryKey, phone);
4488                            }
4489                    }
4490    
4491                    if (uncachedPrimaryKeys == null) {
4492                            return map;
4493                    }
4494    
4495                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
4496                                    1);
4497    
4498                    query.append(_SQL_SELECT_PHONE_WHERE_PKS_IN);
4499    
4500                    for (Serializable primaryKey : uncachedPrimaryKeys) {
4501                            query.append(String.valueOf(primaryKey));
4502    
4503                            query.append(StringPool.COMMA);
4504                    }
4505    
4506                    query.setIndex(query.index() - 1);
4507    
4508                    query.append(StringPool.CLOSE_PARENTHESIS);
4509    
4510                    String sql = query.toString();
4511    
4512                    Session session = null;
4513    
4514                    try {
4515                            session = openSession();
4516    
4517                            Query q = session.createQuery(sql);
4518    
4519                            for (Phone phone : (List<Phone>)q.list()) {
4520                                    map.put(phone.getPrimaryKeyObj(), phone);
4521    
4522                                    cacheResult(phone);
4523    
4524                                    uncachedPrimaryKeys.remove(phone.getPrimaryKeyObj());
4525                            }
4526    
4527                            for (Serializable primaryKey : uncachedPrimaryKeys) {
4528                                    entityCache.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
4529                                            PhoneImpl.class, primaryKey, _nullPhone);
4530                            }
4531                    }
4532                    catch (Exception e) {
4533                            throw processException(e);
4534                    }
4535                    finally {
4536                            closeSession(session);
4537                    }
4538    
4539                    return map;
4540            }
4541    
4542            /**
4543             * Returns all the phones.
4544             *
4545             * @return the phones
4546             */
4547            @Override
4548            public List<Phone> findAll() {
4549                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4550            }
4551    
4552            /**
4553             * Returns a range of all the phones.
4554             *
4555             * <p>
4556             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
4557             * </p>
4558             *
4559             * @param start the lower bound of the range of phones
4560             * @param end the upper bound of the range of phones (not inclusive)
4561             * @return the range of phones
4562             */
4563            @Override
4564            public List<Phone> findAll(int start, int end) {
4565                    return findAll(start, end, null);
4566            }
4567    
4568            /**
4569             * Returns an ordered range of all the phones.
4570             *
4571             * <p>
4572             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
4573             * </p>
4574             *
4575             * @param start the lower bound of the range of phones
4576             * @param end the upper bound of the range of phones (not inclusive)
4577             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4578             * @return the ordered range of phones
4579             */
4580            @Override
4581            public List<Phone> findAll(int start, int end,
4582                    OrderByComparator<Phone> orderByComparator) {
4583                    return findAll(start, end, orderByComparator, true);
4584            }
4585    
4586            /**
4587             * Returns an ordered range of all the phones.
4588             *
4589             * <p>
4590             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
4591             * </p>
4592             *
4593             * @param start the lower bound of the range of phones
4594             * @param end the upper bound of the range of phones (not inclusive)
4595             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4596             * @param retrieveFromCache whether to retrieve from the finder cache
4597             * @return the ordered range of phones
4598             */
4599            @Override
4600            public List<Phone> findAll(int start, int end,
4601                    OrderByComparator<Phone> orderByComparator, boolean retrieveFromCache) {
4602                    boolean pagination = true;
4603                    FinderPath finderPath = null;
4604                    Object[] finderArgs = null;
4605    
4606                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4607                                    (orderByComparator == null)) {
4608                            pagination = false;
4609                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4610                            finderArgs = FINDER_ARGS_EMPTY;
4611                    }
4612                    else {
4613                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4614                            finderArgs = new Object[] { start, end, orderByComparator };
4615                    }
4616    
4617                    List<Phone> list = null;
4618    
4619                    if (retrieveFromCache) {
4620                            list = (List<Phone>)finderCache.getResult(finderPath, finderArgs,
4621                                            this);
4622                    }
4623    
4624                    if (list == null) {
4625                            StringBundler query = null;
4626                            String sql = null;
4627    
4628                            if (orderByComparator != null) {
4629                                    query = new StringBundler(2 +
4630                                                    (orderByComparator.getOrderByFields().length * 3));
4631    
4632                                    query.append(_SQL_SELECT_PHONE);
4633    
4634                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4635                                            orderByComparator);
4636    
4637                                    sql = query.toString();
4638                            }
4639                            else {
4640                                    sql = _SQL_SELECT_PHONE;
4641    
4642                                    if (pagination) {
4643                                            sql = sql.concat(PhoneModelImpl.ORDER_BY_JPQL);
4644                                    }
4645                            }
4646    
4647                            Session session = null;
4648    
4649                            try {
4650                                    session = openSession();
4651    
4652                                    Query q = session.createQuery(sql);
4653    
4654                                    if (!pagination) {
4655                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
4656                                                            end, false);
4657    
4658                                            Collections.sort(list);
4659    
4660                                            list = Collections.unmodifiableList(list);
4661                                    }
4662                                    else {
4663                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
4664                                                            end);
4665                                    }
4666    
4667                                    cacheResult(list);
4668    
4669                                    finderCache.putResult(finderPath, finderArgs, list);
4670                            }
4671                            catch (Exception e) {
4672                                    finderCache.removeResult(finderPath, finderArgs);
4673    
4674                                    throw processException(e);
4675                            }
4676                            finally {
4677                                    closeSession(session);
4678                            }
4679                    }
4680    
4681                    return list;
4682            }
4683    
4684            /**
4685             * Removes all the phones from the database.
4686             *
4687             */
4688            @Override
4689            public void removeAll() {
4690                    for (Phone phone : findAll()) {
4691                            remove(phone);
4692                    }
4693            }
4694    
4695            /**
4696             * Returns the number of phones.
4697             *
4698             * @return the number of phones
4699             */
4700            @Override
4701            public int countAll() {
4702                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
4703                                    FINDER_ARGS_EMPTY, this);
4704    
4705                    if (count == null) {
4706                            Session session = null;
4707    
4708                            try {
4709                                    session = openSession();
4710    
4711                                    Query q = session.createQuery(_SQL_COUNT_PHONE);
4712    
4713                                    count = (Long)q.uniqueResult();
4714    
4715                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
4716                                            count);
4717                            }
4718                            catch (Exception e) {
4719                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
4720                                            FINDER_ARGS_EMPTY);
4721    
4722                                    throw processException(e);
4723                            }
4724                            finally {
4725                                    closeSession(session);
4726                            }
4727                    }
4728    
4729                    return count.intValue();
4730            }
4731    
4732            @Override
4733            public Set<String> getBadColumnNames() {
4734                    return _badColumnNames;
4735            }
4736    
4737            @Override
4738            protected Map<String, Integer> getTableColumnsMap() {
4739                    return PhoneModelImpl.TABLE_COLUMNS_MAP;
4740            }
4741    
4742            /**
4743             * Initializes the phone persistence.
4744             */
4745            public void afterPropertiesSet() {
4746            }
4747    
4748            public void destroy() {
4749                    entityCache.removeCache(PhoneImpl.class.getName());
4750                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
4751                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4752                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4753            }
4754    
4755            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
4756            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
4757            private static final String _SQL_SELECT_PHONE = "SELECT phone FROM Phone phone";
4758            private static final String _SQL_SELECT_PHONE_WHERE_PKS_IN = "SELECT phone FROM Phone phone WHERE phoneId IN (";
4759            private static final String _SQL_SELECT_PHONE_WHERE = "SELECT phone FROM Phone phone WHERE ";
4760            private static final String _SQL_COUNT_PHONE = "SELECT COUNT(phone) FROM Phone phone";
4761            private static final String _SQL_COUNT_PHONE_WHERE = "SELECT COUNT(phone) FROM Phone phone WHERE ";
4762            private static final String _ORDER_BY_ENTITY_ALIAS = "phone.";
4763            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Phone exists with the primary key ";
4764            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Phone exists with the key {";
4765            private static final Log _log = LogFactoryUtil.getLog(PhonePersistenceImpl.class);
4766            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
4767                                    "uuid", "number", "primary"
4768                            });
4769            private static final Phone _nullPhone = new PhoneImpl() {
4770                            @Override
4771                            public Object clone() {
4772                                    return this;
4773                            }
4774    
4775                            @Override
4776                            public CacheModel<Phone> toCacheModel() {
4777                                    return _nullPhoneCacheModel;
4778                            }
4779                    };
4780    
4781            private static final CacheModel<Phone> _nullPhoneCacheModel = new NullCacheModel();
4782    
4783            private static class NullCacheModel implements CacheModel<Phone>, MVCCModel {
4784                    @Override
4785                    public long getMvccVersion() {
4786                            return -1;
4787                    }
4788    
4789                    @Override
4790                    public void setMvccVersion(long mvccVersion) {
4791                    }
4792    
4793                    @Override
4794                    public Phone toEntityModel() {
4795                            return _nullPhone;
4796                    }
4797            }
4798    }