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