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