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