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