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