001    /**
002     * Copyright (c) 2000-2012 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.NoSuchModelException;
018    import com.liferay.portal.NoSuchPhoneException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.Phone;
040    import com.liferay.portal.model.impl.PhoneImpl;
041    import com.liferay.portal.model.impl.PhoneModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the phone service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see PhonePersistence
059     * @see PhoneUtil
060     * @generated
061     */
062    public class PhonePersistenceImpl extends BasePersistenceImpl<Phone>
063            implements PhonePersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * 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.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = PhoneImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
075                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
076                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
078                            new String[] {
079                                    Long.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
085                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
086                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
088                            new String[] { Long.class.getName() },
089                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
091                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
093                            new String[] { Long.class.getName() });
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
095                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
097                            new String[] {
098                                    Long.class.getName(),
099                                    
100                            "java.lang.Integer", "java.lang.Integer",
101                                    "com.liferay.portal.kernel.util.OrderByComparator"
102                            });
103            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
104                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
105                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
107                            new String[] { Long.class.getName() },
108                            PhoneModelImpl.USERID_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
110                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
112                            new String[] { Long.class.getName() });
113            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
114                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
115                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
116                            new String[] {
117                                    Long.class.getName(), Long.class.getName(),
118                                    
119                            "java.lang.Integer", "java.lang.Integer",
120                                    "com.liferay.portal.kernel.util.OrderByComparator"
121                            });
122            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
123                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
125                            new String[] { Long.class.getName(), Long.class.getName() },
126                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
127                            PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK);
128            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
129                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
130                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
131                            new String[] { Long.class.getName(), Long.class.getName() });
132            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
133                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
134                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
135                            new String[] {
136                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
137                                    
138                            "java.lang.Integer", "java.lang.Integer",
139                                    "com.liferay.portal.kernel.util.OrderByComparator"
140                            });
141            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
142                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
143                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
144                            new String[] {
145                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
146                            },
147                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
148                            PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
149                            PhoneModelImpl.CLASSPK_COLUMN_BITMASK);
150            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
151                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
152                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
153                            new String[] {
154                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
155                            });
156            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
157                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
158                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_P",
159                            new String[] {
160                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
161                                    Boolean.class.getName(),
162                                    
163                            "java.lang.Integer", "java.lang.Integer",
164                                    "com.liferay.portal.kernel.util.OrderByComparator"
165                            });
166            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P =
167                    new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
168                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
169                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_P",
170                            new String[] {
171                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
172                                    Boolean.class.getName()
173                            },
174                            PhoneModelImpl.COMPANYID_COLUMN_BITMASK |
175                            PhoneModelImpl.CLASSNAMEID_COLUMN_BITMASK |
176                            PhoneModelImpl.CLASSPK_COLUMN_BITMASK |
177                            PhoneModelImpl.PRIMARY_COLUMN_BITMASK);
178            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
179                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
180                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_P",
181                            new String[] {
182                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
183                                    Boolean.class.getName()
184                            });
185            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
186                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
187                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
188            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
189                            PhoneModelImpl.FINDER_CACHE_ENABLED, PhoneImpl.class,
190                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
191            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PhoneModelImpl.ENTITY_CACHE_ENABLED,
192                            PhoneModelImpl.FINDER_CACHE_ENABLED, Long.class,
193                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
194    
195            /**
196             * Caches the phone in the entity cache if it is enabled.
197             *
198             * @param phone the phone
199             */
200            public void cacheResult(Phone phone) {
201                    EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
202                            PhoneImpl.class, phone.getPrimaryKey(), phone);
203    
204                    phone.resetOriginalValues();
205            }
206    
207            /**
208             * Caches the phones in the entity cache if it is enabled.
209             *
210             * @param phones the phones
211             */
212            public void cacheResult(List<Phone> phones) {
213                    for (Phone phone : phones) {
214                            if (EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
215                                                    PhoneImpl.class, phone.getPrimaryKey()) == null) {
216                                    cacheResult(phone);
217                            }
218                            else {
219                                    phone.resetOriginalValues();
220                            }
221                    }
222            }
223    
224            /**
225             * Clears the cache for all phones.
226             *
227             * <p>
228             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
229             * </p>
230             */
231            @Override
232            public void clearCache() {
233                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
234                            CacheRegistryUtil.clear(PhoneImpl.class.getName());
235                    }
236    
237                    EntityCacheUtil.clearCache(PhoneImpl.class.getName());
238    
239                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
240                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
241                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
242            }
243    
244            /**
245             * Clears the cache for the phone.
246             *
247             * <p>
248             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
249             * </p>
250             */
251            @Override
252            public void clearCache(Phone phone) {
253                    EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
254                            PhoneImpl.class, phone.getPrimaryKey());
255    
256                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
257                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
258            }
259    
260            @Override
261            public void clearCache(List<Phone> phones) {
262                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
263                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
264    
265                    for (Phone phone : phones) {
266                            EntityCacheUtil.removeResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
267                                    PhoneImpl.class, phone.getPrimaryKey());
268                    }
269            }
270    
271            /**
272             * Creates a new phone with the primary key. Does not add the phone to the database.
273             *
274             * @param phoneId the primary key for the new phone
275             * @return the new phone
276             */
277            public Phone create(long phoneId) {
278                    Phone phone = new PhoneImpl();
279    
280                    phone.setNew(true);
281                    phone.setPrimaryKey(phoneId);
282    
283                    return phone;
284            }
285    
286            /**
287             * Removes the phone with the primary key from the database. Also notifies the appropriate model listeners.
288             *
289             * @param phoneId the primary key of the phone
290             * @return the phone that was removed
291             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
292             * @throws SystemException if a system exception occurred
293             */
294            public Phone remove(long phoneId)
295                    throws NoSuchPhoneException, SystemException {
296                    return remove(Long.valueOf(phoneId));
297            }
298    
299            /**
300             * Removes the phone with the primary key from the database. Also notifies the appropriate model listeners.
301             *
302             * @param primaryKey the primary key of the phone
303             * @return the phone that was removed
304             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
305             * @throws SystemException if a system exception occurred
306             */
307            @Override
308            public Phone remove(Serializable primaryKey)
309                    throws NoSuchPhoneException, SystemException {
310                    Session session = null;
311    
312                    try {
313                            session = openSession();
314    
315                            Phone phone = (Phone)session.get(PhoneImpl.class, primaryKey);
316    
317                            if (phone == null) {
318                                    if (_log.isWarnEnabled()) {
319                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
320                                    }
321    
322                                    throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
323                                            primaryKey);
324                            }
325    
326                            return remove(phone);
327                    }
328                    catch (NoSuchPhoneException nsee) {
329                            throw nsee;
330                    }
331                    catch (Exception e) {
332                            throw processException(e);
333                    }
334                    finally {
335                            closeSession(session);
336                    }
337            }
338    
339            @Override
340            protected Phone removeImpl(Phone phone) throws SystemException {
341                    phone = toUnwrappedModel(phone);
342    
343                    Session session = null;
344    
345                    try {
346                            session = openSession();
347    
348                            if (phone.isCachedModel()) {
349                                    phone = (Phone)session.get(PhoneImpl.class,
350                                                    phone.getPrimaryKeyObj());
351                            }
352    
353                            session.delete(phone);
354                    }
355                    catch (Exception e) {
356                            throw processException(e);
357                    }
358                    finally {
359                            closeSession(session);
360                    }
361    
362                    clearCache(phone);
363    
364                    return phone;
365            }
366    
367            @Override
368            public Phone updateImpl(com.liferay.portal.model.Phone phone)
369                    throws SystemException {
370                    phone = toUnwrappedModel(phone);
371    
372                    boolean isNew = phone.isNew();
373    
374                    PhoneModelImpl phoneModelImpl = (PhoneModelImpl)phone;
375    
376                    Session session = null;
377    
378                    try {
379                            session = openSession();
380    
381                            if (phone.isNew()) {
382                                    session.save(phone);
383    
384                                    phone.setNew(false);
385                            }
386                            else {
387                                    session.merge(phone);
388                            }
389                    }
390                    catch (Exception e) {
391                            throw processException(e);
392                    }
393                    finally {
394                            closeSession(session);
395                    }
396    
397                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
398    
399                    if (isNew || !PhoneModelImpl.COLUMN_BITMASK_ENABLED) {
400                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
401                    }
402    
403                    else {
404                            if ((phoneModelImpl.getColumnBitmask() &
405                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
406                                    Object[] args = new Object[] {
407                                                    Long.valueOf(phoneModelImpl.getOriginalCompanyId())
408                                            };
409    
410                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
411                                            args);
412                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
413                                            args);
414    
415                                    args = new Object[] { Long.valueOf(phoneModelImpl.getCompanyId()) };
416    
417                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
418                                            args);
419                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
420                                            args);
421                            }
422    
423                            if ((phoneModelImpl.getColumnBitmask() &
424                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
425                                    Object[] args = new Object[] {
426                                                    Long.valueOf(phoneModelImpl.getOriginalUserId())
427                                            };
428    
429                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
430                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
431                                            args);
432    
433                                    args = new Object[] { Long.valueOf(phoneModelImpl.getUserId()) };
434    
435                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
436                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
437                                            args);
438                            }
439    
440                            if ((phoneModelImpl.getColumnBitmask() &
441                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
442                                    Object[] args = new Object[] {
443                                                    Long.valueOf(phoneModelImpl.getOriginalCompanyId()),
444                                                    Long.valueOf(phoneModelImpl.getOriginalClassNameId())
445                                            };
446    
447                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
448                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
449                                            args);
450    
451                                    args = new Object[] {
452                                                    Long.valueOf(phoneModelImpl.getCompanyId()),
453                                                    Long.valueOf(phoneModelImpl.getClassNameId())
454                                            };
455    
456                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
457                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
458                                            args);
459                            }
460    
461                            if ((phoneModelImpl.getColumnBitmask() &
462                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
463                                    Object[] args = new Object[] {
464                                                    Long.valueOf(phoneModelImpl.getOriginalCompanyId()),
465                                                    Long.valueOf(phoneModelImpl.getOriginalClassNameId()),
466                                                    Long.valueOf(phoneModelImpl.getOriginalClassPK())
467                                            };
468    
469                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
470                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
471                                            args);
472    
473                                    args = new Object[] {
474                                                    Long.valueOf(phoneModelImpl.getCompanyId()),
475                                                    Long.valueOf(phoneModelImpl.getClassNameId()),
476                                                    Long.valueOf(phoneModelImpl.getClassPK())
477                                            };
478    
479                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
480                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
481                                            args);
482                            }
483    
484                            if ((phoneModelImpl.getColumnBitmask() &
485                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P.getColumnBitmask()) != 0) {
486                                    Object[] args = new Object[] {
487                                                    Long.valueOf(phoneModelImpl.getOriginalCompanyId()),
488                                                    Long.valueOf(phoneModelImpl.getOriginalClassNameId()),
489                                                    Long.valueOf(phoneModelImpl.getOriginalClassPK()),
490                                                    Boolean.valueOf(phoneModelImpl.getOriginalPrimary())
491                                            };
492    
493                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
494                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
495                                            args);
496    
497                                    args = new Object[] {
498                                                    Long.valueOf(phoneModelImpl.getCompanyId()),
499                                                    Long.valueOf(phoneModelImpl.getClassNameId()),
500                                                    Long.valueOf(phoneModelImpl.getClassPK()),
501                                                    Boolean.valueOf(phoneModelImpl.getPrimary())
502                                            };
503    
504                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
505                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
506                                            args);
507                            }
508                    }
509    
510                    EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
511                            PhoneImpl.class, phone.getPrimaryKey(), phone);
512    
513                    return phone;
514            }
515    
516            protected Phone toUnwrappedModel(Phone phone) {
517                    if (phone instanceof PhoneImpl) {
518                            return phone;
519                    }
520    
521                    PhoneImpl phoneImpl = new PhoneImpl();
522    
523                    phoneImpl.setNew(phone.isNew());
524                    phoneImpl.setPrimaryKey(phone.getPrimaryKey());
525    
526                    phoneImpl.setPhoneId(phone.getPhoneId());
527                    phoneImpl.setCompanyId(phone.getCompanyId());
528                    phoneImpl.setUserId(phone.getUserId());
529                    phoneImpl.setUserName(phone.getUserName());
530                    phoneImpl.setCreateDate(phone.getCreateDate());
531                    phoneImpl.setModifiedDate(phone.getModifiedDate());
532                    phoneImpl.setClassNameId(phone.getClassNameId());
533                    phoneImpl.setClassPK(phone.getClassPK());
534                    phoneImpl.setNumber(phone.getNumber());
535                    phoneImpl.setExtension(phone.getExtension());
536                    phoneImpl.setTypeId(phone.getTypeId());
537                    phoneImpl.setPrimary(phone.isPrimary());
538    
539                    return phoneImpl;
540            }
541    
542            /**
543             * Returns the phone with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
544             *
545             * @param primaryKey the primary key of the phone
546             * @return the phone
547             * @throws com.liferay.portal.NoSuchModelException if a phone with the primary key could not be found
548             * @throws SystemException if a system exception occurred
549             */
550            @Override
551            public Phone findByPrimaryKey(Serializable primaryKey)
552                    throws NoSuchModelException, SystemException {
553                    return findByPrimaryKey(((Long)primaryKey).longValue());
554            }
555    
556            /**
557             * Returns the phone with the primary key or throws a {@link com.liferay.portal.NoSuchPhoneException} if it could not be found.
558             *
559             * @param phoneId the primary key of the phone
560             * @return the phone
561             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
562             * @throws SystemException if a system exception occurred
563             */
564            public Phone findByPrimaryKey(long phoneId)
565                    throws NoSuchPhoneException, SystemException {
566                    Phone phone = fetchByPrimaryKey(phoneId);
567    
568                    if (phone == null) {
569                            if (_log.isWarnEnabled()) {
570                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + phoneId);
571                            }
572    
573                            throw new NoSuchPhoneException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
574                                    phoneId);
575                    }
576    
577                    return phone;
578            }
579    
580            /**
581             * Returns the phone with the primary key or returns <code>null</code> if it could not be found.
582             *
583             * @param primaryKey the primary key of the phone
584             * @return the phone, or <code>null</code> if a phone with the primary key could not be found
585             * @throws SystemException if a system exception occurred
586             */
587            @Override
588            public Phone fetchByPrimaryKey(Serializable primaryKey)
589                    throws SystemException {
590                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
591            }
592    
593            /**
594             * Returns the phone with the primary key or returns <code>null</code> if it could not be found.
595             *
596             * @param phoneId the primary key of the phone
597             * @return the phone, or <code>null</code> if a phone with the primary key could not be found
598             * @throws SystemException if a system exception occurred
599             */
600            public Phone fetchByPrimaryKey(long phoneId) throws SystemException {
601                    Phone phone = (Phone)EntityCacheUtil.getResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
602                                    PhoneImpl.class, phoneId);
603    
604                    if (phone == _nullPhone) {
605                            return null;
606                    }
607    
608                    if (phone == null) {
609                            Session session = null;
610    
611                            boolean hasException = false;
612    
613                            try {
614                                    session = openSession();
615    
616                                    phone = (Phone)session.get(PhoneImpl.class,
617                                                    Long.valueOf(phoneId));
618                            }
619                            catch (Exception e) {
620                                    hasException = true;
621    
622                                    throw processException(e);
623                            }
624                            finally {
625                                    if (phone != null) {
626                                            cacheResult(phone);
627                                    }
628                                    else if (!hasException) {
629                                            EntityCacheUtil.putResult(PhoneModelImpl.ENTITY_CACHE_ENABLED,
630                                                    PhoneImpl.class, phoneId, _nullPhone);
631                                    }
632    
633                                    closeSession(session);
634                            }
635                    }
636    
637                    return phone;
638            }
639    
640            /**
641             * Returns all the phones where companyId = &#63;.
642             *
643             * @param companyId the company ID
644             * @return the matching phones
645             * @throws SystemException if a system exception occurred
646             */
647            public List<Phone> findByCompanyId(long companyId)
648                    throws SystemException {
649                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
650                            null);
651            }
652    
653            /**
654             * Returns a range of all the phones where companyId = &#63;.
655             *
656             * <p>
657             * 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.
658             * </p>
659             *
660             * @param companyId the company ID
661             * @param start the lower bound of the range of phones
662             * @param end the upper bound of the range of phones (not inclusive)
663             * @return the range of matching phones
664             * @throws SystemException if a system exception occurred
665             */
666            public List<Phone> findByCompanyId(long companyId, int start, int end)
667                    throws SystemException {
668                    return findByCompanyId(companyId, start, end, null);
669            }
670    
671            /**
672             * Returns an ordered range of all the phones where 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.
676             * </p>
677             *
678             * @param companyId the company ID
679             * @param start the lower bound of the range of phones
680             * @param end the upper bound of the range of phones (not inclusive)
681             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
682             * @return the ordered range of matching phones
683             * @throws SystemException if a system exception occurred
684             */
685            public List<Phone> findByCompanyId(long companyId, int start, int end,
686                    OrderByComparator orderByComparator) throws SystemException {
687                    FinderPath finderPath = null;
688                    Object[] finderArgs = null;
689    
690                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
691                                    (orderByComparator == null)) {
692                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
693                            finderArgs = new Object[] { companyId };
694                    }
695                    else {
696                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
697                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
698                    }
699    
700                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
701                                    finderArgs, this);
702    
703                    if ((list != null) && !list.isEmpty()) {
704                            for (Phone phone : list) {
705                                    if ((companyId != phone.getCompanyId())) {
706                                            list = null;
707    
708                                            break;
709                                    }
710                            }
711                    }
712    
713                    if (list == null) {
714                            StringBundler query = null;
715    
716                            if (orderByComparator != null) {
717                                    query = new StringBundler(3 +
718                                                    (orderByComparator.getOrderByFields().length * 3));
719                            }
720                            else {
721                                    query = new StringBundler(3);
722                            }
723    
724                            query.append(_SQL_SELECT_PHONE_WHERE);
725    
726                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
727    
728                            if (orderByComparator != null) {
729                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
730                                            orderByComparator);
731                            }
732    
733                            else {
734                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
735                            }
736    
737                            String sql = query.toString();
738    
739                            Session session = null;
740    
741                            try {
742                                    session = openSession();
743    
744                                    Query q = session.createQuery(sql);
745    
746                                    QueryPos qPos = QueryPos.getInstance(q);
747    
748                                    qPos.add(companyId);
749    
750                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
751                            }
752                            catch (Exception e) {
753                                    throw processException(e);
754                            }
755                            finally {
756                                    if (list == null) {
757                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
758                                    }
759                                    else {
760                                            cacheResult(list);
761    
762                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
763                                    }
764    
765                                    closeSession(session);
766                            }
767                    }
768    
769                    return list;
770            }
771    
772            /**
773             * Returns the first phone in the ordered set where companyId = &#63;.
774             *
775             * @param companyId the company ID
776             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
777             * @return the first matching phone
778             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
779             * @throws SystemException if a system exception occurred
780             */
781            public Phone findByCompanyId_First(long companyId,
782                    OrderByComparator orderByComparator)
783                    throws NoSuchPhoneException, SystemException {
784                    Phone phone = fetchByCompanyId_First(companyId, orderByComparator);
785    
786                    if (phone != null) {
787                            return phone;
788                    }
789    
790                    StringBundler msg = new StringBundler(4);
791    
792                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
793    
794                    msg.append("companyId=");
795                    msg.append(companyId);
796    
797                    msg.append(StringPool.CLOSE_CURLY_BRACE);
798    
799                    throw new NoSuchPhoneException(msg.toString());
800            }
801    
802            /**
803             * Returns the first phone in the ordered set where companyId = &#63;.
804             *
805             * @param companyId the company ID
806             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
807             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
808             * @throws SystemException if a system exception occurred
809             */
810            public Phone fetchByCompanyId_First(long companyId,
811                    OrderByComparator orderByComparator) throws SystemException {
812                    List<Phone> list = findByCompanyId(companyId, 0, 1, orderByComparator);
813    
814                    if (!list.isEmpty()) {
815                            return list.get(0);
816                    }
817    
818                    return null;
819            }
820    
821            /**
822             * Returns the last phone in the ordered set where companyId = &#63;.
823             *
824             * @param companyId the company ID
825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
826             * @return the last matching phone
827             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
828             * @throws SystemException if a system exception occurred
829             */
830            public Phone findByCompanyId_Last(long companyId,
831                    OrderByComparator orderByComparator)
832                    throws NoSuchPhoneException, SystemException {
833                    Phone phone = fetchByCompanyId_Last(companyId, orderByComparator);
834    
835                    if (phone != null) {
836                            return phone;
837                    }
838    
839                    StringBundler msg = new StringBundler(4);
840    
841                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
842    
843                    msg.append("companyId=");
844                    msg.append(companyId);
845    
846                    msg.append(StringPool.CLOSE_CURLY_BRACE);
847    
848                    throw new NoSuchPhoneException(msg.toString());
849            }
850    
851            /**
852             * Returns the last phone in the ordered set where companyId = &#63;.
853             *
854             * @param companyId the company ID
855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
856             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
857             * @throws SystemException if a system exception occurred
858             */
859            public Phone fetchByCompanyId_Last(long companyId,
860                    OrderByComparator orderByComparator) throws SystemException {
861                    int count = countByCompanyId(companyId);
862    
863                    List<Phone> list = findByCompanyId(companyId, count - 1, count,
864                                    orderByComparator);
865    
866                    if (!list.isEmpty()) {
867                            return list.get(0);
868                    }
869    
870                    return null;
871            }
872    
873            /**
874             * Returns the phones before and after the current phone in the ordered set where companyId = &#63;.
875             *
876             * @param phoneId the primary key of the current phone
877             * @param companyId the company ID
878             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
879             * @return the previous, current, and next phone
880             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
881             * @throws SystemException if a system exception occurred
882             */
883            public Phone[] findByCompanyId_PrevAndNext(long phoneId, long companyId,
884                    OrderByComparator orderByComparator)
885                    throws NoSuchPhoneException, SystemException {
886                    Phone phone = findByPrimaryKey(phoneId);
887    
888                    Session session = null;
889    
890                    try {
891                            session = openSession();
892    
893                            Phone[] array = new PhoneImpl[3];
894    
895                            array[0] = getByCompanyId_PrevAndNext(session, phone, companyId,
896                                            orderByComparator, true);
897    
898                            array[1] = phone;
899    
900                            array[2] = getByCompanyId_PrevAndNext(session, phone, companyId,
901                                            orderByComparator, false);
902    
903                            return array;
904                    }
905                    catch (Exception e) {
906                            throw processException(e);
907                    }
908                    finally {
909                            closeSession(session);
910                    }
911            }
912    
913            protected Phone getByCompanyId_PrevAndNext(Session session, Phone phone,
914                    long companyId, OrderByComparator orderByComparator, boolean previous) {
915                    StringBundler query = null;
916    
917                    if (orderByComparator != null) {
918                            query = new StringBundler(6 +
919                                            (orderByComparator.getOrderByFields().length * 6));
920                    }
921                    else {
922                            query = new StringBundler(3);
923                    }
924    
925                    query.append(_SQL_SELECT_PHONE_WHERE);
926    
927                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
928    
929                    if (orderByComparator != null) {
930                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
931    
932                            if (orderByConditionFields.length > 0) {
933                                    query.append(WHERE_AND);
934                            }
935    
936                            for (int i = 0; i < orderByConditionFields.length; i++) {
937                                    query.append(_ORDER_BY_ENTITY_ALIAS);
938                                    query.append(orderByConditionFields[i]);
939    
940                                    if ((i + 1) < orderByConditionFields.length) {
941                                            if (orderByComparator.isAscending() ^ previous) {
942                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
943                                            }
944                                            else {
945                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
946                                            }
947                                    }
948                                    else {
949                                            if (orderByComparator.isAscending() ^ previous) {
950                                                    query.append(WHERE_GREATER_THAN);
951                                            }
952                                            else {
953                                                    query.append(WHERE_LESSER_THAN);
954                                            }
955                                    }
956                            }
957    
958                            query.append(ORDER_BY_CLAUSE);
959    
960                            String[] orderByFields = orderByComparator.getOrderByFields();
961    
962                            for (int i = 0; i < orderByFields.length; i++) {
963                                    query.append(_ORDER_BY_ENTITY_ALIAS);
964                                    query.append(orderByFields[i]);
965    
966                                    if ((i + 1) < orderByFields.length) {
967                                            if (orderByComparator.isAscending() ^ previous) {
968                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
969                                            }
970                                            else {
971                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
972                                            }
973                                    }
974                                    else {
975                                            if (orderByComparator.isAscending() ^ previous) {
976                                                    query.append(ORDER_BY_ASC);
977                                            }
978                                            else {
979                                                    query.append(ORDER_BY_DESC);
980                                            }
981                                    }
982                            }
983                    }
984    
985                    else {
986                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
987                    }
988    
989                    String sql = query.toString();
990    
991                    Query q = session.createQuery(sql);
992    
993                    q.setFirstResult(0);
994                    q.setMaxResults(2);
995    
996                    QueryPos qPos = QueryPos.getInstance(q);
997    
998                    qPos.add(companyId);
999    
1000                    if (orderByComparator != null) {
1001                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
1002    
1003                            for (Object value : values) {
1004                                    qPos.add(value);
1005                            }
1006                    }
1007    
1008                    List<Phone> list = q.list();
1009    
1010                    if (list.size() == 2) {
1011                            return list.get(1);
1012                    }
1013                    else {
1014                            return null;
1015                    }
1016            }
1017    
1018            /**
1019             * Returns all the phones where userId = &#63;.
1020             *
1021             * @param userId the user ID
1022             * @return the matching phones
1023             * @throws SystemException if a system exception occurred
1024             */
1025            public List<Phone> findByUserId(long userId) throws SystemException {
1026                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1027            }
1028    
1029            /**
1030             * Returns a range of all the phones where userId = &#63;.
1031             *
1032             * <p>
1033             * 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.
1034             * </p>
1035             *
1036             * @param userId the user ID
1037             * @param start the lower bound of the range of phones
1038             * @param end the upper bound of the range of phones (not inclusive)
1039             * @return the range of matching phones
1040             * @throws SystemException if a system exception occurred
1041             */
1042            public List<Phone> findByUserId(long userId, int start, int end)
1043                    throws SystemException {
1044                    return findByUserId(userId, start, end, null);
1045            }
1046    
1047            /**
1048             * Returns an ordered range of all the phones where userId = &#63;.
1049             *
1050             * <p>
1051             * 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.
1052             * </p>
1053             *
1054             * @param userId the user ID
1055             * @param start the lower bound of the range of phones
1056             * @param end the upper bound of the range of phones (not inclusive)
1057             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1058             * @return the ordered range of matching phones
1059             * @throws SystemException if a system exception occurred
1060             */
1061            public List<Phone> findByUserId(long userId, int start, int end,
1062                    OrderByComparator orderByComparator) throws SystemException {
1063                    FinderPath finderPath = null;
1064                    Object[] finderArgs = null;
1065    
1066                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1067                                    (orderByComparator == null)) {
1068                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1069                            finderArgs = new Object[] { userId };
1070                    }
1071                    else {
1072                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1073                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1074                    }
1075    
1076                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
1077                                    finderArgs, this);
1078    
1079                    if ((list != null) && !list.isEmpty()) {
1080                            for (Phone phone : list) {
1081                                    if ((userId != phone.getUserId())) {
1082                                            list = null;
1083    
1084                                            break;
1085                                    }
1086                            }
1087                    }
1088    
1089                    if (list == null) {
1090                            StringBundler query = null;
1091    
1092                            if (orderByComparator != null) {
1093                                    query = new StringBundler(3 +
1094                                                    (orderByComparator.getOrderByFields().length * 3));
1095                            }
1096                            else {
1097                                    query = new StringBundler(3);
1098                            }
1099    
1100                            query.append(_SQL_SELECT_PHONE_WHERE);
1101    
1102                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1103    
1104                            if (orderByComparator != null) {
1105                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1106                                            orderByComparator);
1107                            }
1108    
1109                            else {
1110                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
1111                            }
1112    
1113                            String sql = query.toString();
1114    
1115                            Session session = null;
1116    
1117                            try {
1118                                    session = openSession();
1119    
1120                                    Query q = session.createQuery(sql);
1121    
1122                                    QueryPos qPos = QueryPos.getInstance(q);
1123    
1124                                    qPos.add(userId);
1125    
1126                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
1127                            }
1128                            catch (Exception e) {
1129                                    throw processException(e);
1130                            }
1131                            finally {
1132                                    if (list == null) {
1133                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1134                                    }
1135                                    else {
1136                                            cacheResult(list);
1137    
1138                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1139                                    }
1140    
1141                                    closeSession(session);
1142                            }
1143                    }
1144    
1145                    return list;
1146            }
1147    
1148            /**
1149             * Returns the first phone in the ordered set where userId = &#63;.
1150             *
1151             * @param userId the user ID
1152             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1153             * @return the first matching phone
1154             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1155             * @throws SystemException if a system exception occurred
1156             */
1157            public Phone findByUserId_First(long userId,
1158                    OrderByComparator orderByComparator)
1159                    throws NoSuchPhoneException, SystemException {
1160                    Phone phone = fetchByUserId_First(userId, orderByComparator);
1161    
1162                    if (phone != null) {
1163                            return phone;
1164                    }
1165    
1166                    StringBundler msg = new StringBundler(4);
1167    
1168                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1169    
1170                    msg.append("userId=");
1171                    msg.append(userId);
1172    
1173                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1174    
1175                    throw new NoSuchPhoneException(msg.toString());
1176            }
1177    
1178            /**
1179             * Returns the first phone in the ordered set where userId = &#63;.
1180             *
1181             * @param userId the user ID
1182             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1183             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
1184             * @throws SystemException if a system exception occurred
1185             */
1186            public Phone fetchByUserId_First(long userId,
1187                    OrderByComparator orderByComparator) throws SystemException {
1188                    List<Phone> list = findByUserId(userId, 0, 1, orderByComparator);
1189    
1190                    if (!list.isEmpty()) {
1191                            return list.get(0);
1192                    }
1193    
1194                    return null;
1195            }
1196    
1197            /**
1198             * Returns the last phone in the ordered set where userId = &#63;.
1199             *
1200             * @param userId the user ID
1201             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1202             * @return the last matching phone
1203             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1204             * @throws SystemException if a system exception occurred
1205             */
1206            public Phone findByUserId_Last(long userId,
1207                    OrderByComparator orderByComparator)
1208                    throws NoSuchPhoneException, SystemException {
1209                    Phone phone = fetchByUserId_Last(userId, orderByComparator);
1210    
1211                    if (phone != null) {
1212                            return phone;
1213                    }
1214    
1215                    StringBundler msg = new StringBundler(4);
1216    
1217                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1218    
1219                    msg.append("userId=");
1220                    msg.append(userId);
1221    
1222                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1223    
1224                    throw new NoSuchPhoneException(msg.toString());
1225            }
1226    
1227            /**
1228             * Returns the last phone in the ordered set where userId = &#63;.
1229             *
1230             * @param userId the user ID
1231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1232             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
1233             * @throws SystemException if a system exception occurred
1234             */
1235            public Phone fetchByUserId_Last(long userId,
1236                    OrderByComparator orderByComparator) throws SystemException {
1237                    int count = countByUserId(userId);
1238    
1239                    List<Phone> list = findByUserId(userId, count - 1, count,
1240                                    orderByComparator);
1241    
1242                    if (!list.isEmpty()) {
1243                            return list.get(0);
1244                    }
1245    
1246                    return null;
1247            }
1248    
1249            /**
1250             * Returns the phones before and after the current phone in the ordered set where userId = &#63;.
1251             *
1252             * @param phoneId the primary key of the current phone
1253             * @param userId the user ID
1254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1255             * @return the previous, current, and next phone
1256             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
1257             * @throws SystemException if a system exception occurred
1258             */
1259            public Phone[] findByUserId_PrevAndNext(long phoneId, long userId,
1260                    OrderByComparator orderByComparator)
1261                    throws NoSuchPhoneException, SystemException {
1262                    Phone phone = findByPrimaryKey(phoneId);
1263    
1264                    Session session = null;
1265    
1266                    try {
1267                            session = openSession();
1268    
1269                            Phone[] array = new PhoneImpl[3];
1270    
1271                            array[0] = getByUserId_PrevAndNext(session, phone, userId,
1272                                            orderByComparator, true);
1273    
1274                            array[1] = phone;
1275    
1276                            array[2] = getByUserId_PrevAndNext(session, phone, userId,
1277                                            orderByComparator, false);
1278    
1279                            return array;
1280                    }
1281                    catch (Exception e) {
1282                            throw processException(e);
1283                    }
1284                    finally {
1285                            closeSession(session);
1286                    }
1287            }
1288    
1289            protected Phone getByUserId_PrevAndNext(Session session, Phone phone,
1290                    long userId, OrderByComparator orderByComparator, boolean previous) {
1291                    StringBundler query = null;
1292    
1293                    if (orderByComparator != null) {
1294                            query = new StringBundler(6 +
1295                                            (orderByComparator.getOrderByFields().length * 6));
1296                    }
1297                    else {
1298                            query = new StringBundler(3);
1299                    }
1300    
1301                    query.append(_SQL_SELECT_PHONE_WHERE);
1302    
1303                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1304    
1305                    if (orderByComparator != null) {
1306                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1307    
1308                            if (orderByConditionFields.length > 0) {
1309                                    query.append(WHERE_AND);
1310                            }
1311    
1312                            for (int i = 0; i < orderByConditionFields.length; i++) {
1313                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1314                                    query.append(orderByConditionFields[i]);
1315    
1316                                    if ((i + 1) < orderByConditionFields.length) {
1317                                            if (orderByComparator.isAscending() ^ previous) {
1318                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1319                                            }
1320                                            else {
1321                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1322                                            }
1323                                    }
1324                                    else {
1325                                            if (orderByComparator.isAscending() ^ previous) {
1326                                                    query.append(WHERE_GREATER_THAN);
1327                                            }
1328                                            else {
1329                                                    query.append(WHERE_LESSER_THAN);
1330                                            }
1331                                    }
1332                            }
1333    
1334                            query.append(ORDER_BY_CLAUSE);
1335    
1336                            String[] orderByFields = orderByComparator.getOrderByFields();
1337    
1338                            for (int i = 0; i < orderByFields.length; i++) {
1339                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1340                                    query.append(orderByFields[i]);
1341    
1342                                    if ((i + 1) < orderByFields.length) {
1343                                            if (orderByComparator.isAscending() ^ previous) {
1344                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1345                                            }
1346                                            else {
1347                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1348                                            }
1349                                    }
1350                                    else {
1351                                            if (orderByComparator.isAscending() ^ previous) {
1352                                                    query.append(ORDER_BY_ASC);
1353                                            }
1354                                            else {
1355                                                    query.append(ORDER_BY_DESC);
1356                                            }
1357                                    }
1358                            }
1359                    }
1360    
1361                    else {
1362                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1363                    }
1364    
1365                    String sql = query.toString();
1366    
1367                    Query q = session.createQuery(sql);
1368    
1369                    q.setFirstResult(0);
1370                    q.setMaxResults(2);
1371    
1372                    QueryPos qPos = QueryPos.getInstance(q);
1373    
1374                    qPos.add(userId);
1375    
1376                    if (orderByComparator != null) {
1377                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
1378    
1379                            for (Object value : values) {
1380                                    qPos.add(value);
1381                            }
1382                    }
1383    
1384                    List<Phone> list = q.list();
1385    
1386                    if (list.size() == 2) {
1387                            return list.get(1);
1388                    }
1389                    else {
1390                            return null;
1391                    }
1392            }
1393    
1394            /**
1395             * Returns all the phones where companyId = &#63; and classNameId = &#63;.
1396             *
1397             * @param companyId the company ID
1398             * @param classNameId the class name ID
1399             * @return the matching phones
1400             * @throws SystemException if a system exception occurred
1401             */
1402            public List<Phone> findByC_C(long companyId, long classNameId)
1403                    throws SystemException {
1404                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
1405                            QueryUtil.ALL_POS, null);
1406            }
1407    
1408            /**
1409             * Returns a range of all the phones where companyId = &#63; and classNameId = &#63;.
1410             *
1411             * <p>
1412             * 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.
1413             * </p>
1414             *
1415             * @param companyId the company ID
1416             * @param classNameId the class name ID
1417             * @param start the lower bound of the range of phones
1418             * @param end the upper bound of the range of phones (not inclusive)
1419             * @return the range of matching phones
1420             * @throws SystemException if a system exception occurred
1421             */
1422            public List<Phone> findByC_C(long companyId, long classNameId, int start,
1423                    int end) throws SystemException {
1424                    return findByC_C(companyId, classNameId, start, end, null);
1425            }
1426    
1427            /**
1428             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63;.
1429             *
1430             * <p>
1431             * 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.
1432             * </p>
1433             *
1434             * @param companyId the company ID
1435             * @param classNameId the class name ID
1436             * @param start the lower bound of the range of phones
1437             * @param end the upper bound of the range of phones (not inclusive)
1438             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1439             * @return the ordered range of matching phones
1440             * @throws SystemException if a system exception occurred
1441             */
1442            public List<Phone> findByC_C(long companyId, long classNameId, int start,
1443                    int end, OrderByComparator orderByComparator) throws SystemException {
1444                    FinderPath finderPath = null;
1445                    Object[] finderArgs = null;
1446    
1447                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1448                                    (orderByComparator == null)) {
1449                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
1450                            finderArgs = new Object[] { companyId, classNameId };
1451                    }
1452                    else {
1453                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
1454                            finderArgs = new Object[] {
1455                                            companyId, classNameId,
1456                                            
1457                                            start, end, orderByComparator
1458                                    };
1459                    }
1460    
1461                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
1462                                    finderArgs, this);
1463    
1464                    if ((list != null) && !list.isEmpty()) {
1465                            for (Phone phone : list) {
1466                                    if ((companyId != phone.getCompanyId()) ||
1467                                                    (classNameId != phone.getClassNameId())) {
1468                                            list = null;
1469    
1470                                            break;
1471                                    }
1472                            }
1473                    }
1474    
1475                    if (list == null) {
1476                            StringBundler query = null;
1477    
1478                            if (orderByComparator != null) {
1479                                    query = new StringBundler(4 +
1480                                                    (orderByComparator.getOrderByFields().length * 3));
1481                            }
1482                            else {
1483                                    query = new StringBundler(4);
1484                            }
1485    
1486                            query.append(_SQL_SELECT_PHONE_WHERE);
1487    
1488                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1489    
1490                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1491    
1492                            if (orderByComparator != null) {
1493                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1494                                            orderByComparator);
1495                            }
1496    
1497                            else {
1498                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
1499                            }
1500    
1501                            String sql = query.toString();
1502    
1503                            Session session = null;
1504    
1505                            try {
1506                                    session = openSession();
1507    
1508                                    Query q = session.createQuery(sql);
1509    
1510                                    QueryPos qPos = QueryPos.getInstance(q);
1511    
1512                                    qPos.add(companyId);
1513    
1514                                    qPos.add(classNameId);
1515    
1516                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
1517                            }
1518                            catch (Exception e) {
1519                                    throw processException(e);
1520                            }
1521                            finally {
1522                                    if (list == null) {
1523                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1524                                    }
1525                                    else {
1526                                            cacheResult(list);
1527    
1528                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1529                                    }
1530    
1531                                    closeSession(session);
1532                            }
1533                    }
1534    
1535                    return list;
1536            }
1537    
1538            /**
1539             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63;.
1540             *
1541             * @param companyId the company ID
1542             * @param classNameId the class name ID
1543             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1544             * @return the first matching phone
1545             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1546             * @throws SystemException if a system exception occurred
1547             */
1548            public Phone findByC_C_First(long companyId, long classNameId,
1549                    OrderByComparator orderByComparator)
1550                    throws NoSuchPhoneException, SystemException {
1551                    Phone phone = fetchByC_C_First(companyId, classNameId, orderByComparator);
1552    
1553                    if (phone != null) {
1554                            return phone;
1555                    }
1556    
1557                    StringBundler msg = new StringBundler(6);
1558    
1559                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1560    
1561                    msg.append("companyId=");
1562                    msg.append(companyId);
1563    
1564                    msg.append(", classNameId=");
1565                    msg.append(classNameId);
1566    
1567                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1568    
1569                    throw new NoSuchPhoneException(msg.toString());
1570            }
1571    
1572            /**
1573             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63;.
1574             *
1575             * @param companyId the company ID
1576             * @param classNameId the class name ID
1577             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1578             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
1579             * @throws SystemException if a system exception occurred
1580             */
1581            public Phone fetchByC_C_First(long companyId, long classNameId,
1582                    OrderByComparator orderByComparator) throws SystemException {
1583                    List<Phone> list = findByC_C(companyId, classNameId, 0, 1,
1584                                    orderByComparator);
1585    
1586                    if (!list.isEmpty()) {
1587                            return list.get(0);
1588                    }
1589    
1590                    return null;
1591            }
1592    
1593            /**
1594             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63;.
1595             *
1596             * @param companyId the company ID
1597             * @param classNameId the class name ID
1598             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1599             * @return the last matching phone
1600             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1601             * @throws SystemException if a system exception occurred
1602             */
1603            public Phone findByC_C_Last(long companyId, long classNameId,
1604                    OrderByComparator orderByComparator)
1605                    throws NoSuchPhoneException, SystemException {
1606                    Phone phone = fetchByC_C_Last(companyId, classNameId, orderByComparator);
1607    
1608                    if (phone != null) {
1609                            return phone;
1610                    }
1611    
1612                    StringBundler msg = new StringBundler(6);
1613    
1614                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1615    
1616                    msg.append("companyId=");
1617                    msg.append(companyId);
1618    
1619                    msg.append(", classNameId=");
1620                    msg.append(classNameId);
1621    
1622                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1623    
1624                    throw new NoSuchPhoneException(msg.toString());
1625            }
1626    
1627            /**
1628             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63;.
1629             *
1630             * @param companyId the company ID
1631             * @param classNameId the class name ID
1632             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1633             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
1634             * @throws SystemException if a system exception occurred
1635             */
1636            public Phone fetchByC_C_Last(long companyId, long classNameId,
1637                    OrderByComparator orderByComparator) throws SystemException {
1638                    int count = countByC_C(companyId, classNameId);
1639    
1640                    List<Phone> list = findByC_C(companyId, classNameId, count - 1, count,
1641                                    orderByComparator);
1642    
1643                    if (!list.isEmpty()) {
1644                            return list.get(0);
1645                    }
1646    
1647                    return null;
1648            }
1649    
1650            /**
1651             * Returns the phones before and after the current phone in the ordered set where companyId = &#63; and classNameId = &#63;.
1652             *
1653             * @param phoneId the primary key of the current phone
1654             * @param companyId the company ID
1655             * @param classNameId the class name ID
1656             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1657             * @return the previous, current, and next phone
1658             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
1659             * @throws SystemException if a system exception occurred
1660             */
1661            public Phone[] findByC_C_PrevAndNext(long phoneId, long companyId,
1662                    long classNameId, OrderByComparator orderByComparator)
1663                    throws NoSuchPhoneException, SystemException {
1664                    Phone phone = findByPrimaryKey(phoneId);
1665    
1666                    Session session = null;
1667    
1668                    try {
1669                            session = openSession();
1670    
1671                            Phone[] array = new PhoneImpl[3];
1672    
1673                            array[0] = getByC_C_PrevAndNext(session, phone, companyId,
1674                                            classNameId, orderByComparator, true);
1675    
1676                            array[1] = phone;
1677    
1678                            array[2] = getByC_C_PrevAndNext(session, phone, companyId,
1679                                            classNameId, orderByComparator, false);
1680    
1681                            return array;
1682                    }
1683                    catch (Exception e) {
1684                            throw processException(e);
1685                    }
1686                    finally {
1687                            closeSession(session);
1688                    }
1689            }
1690    
1691            protected Phone getByC_C_PrevAndNext(Session session, Phone phone,
1692                    long companyId, long classNameId, OrderByComparator orderByComparator,
1693                    boolean previous) {
1694                    StringBundler query = null;
1695    
1696                    if (orderByComparator != null) {
1697                            query = new StringBundler(6 +
1698                                            (orderByComparator.getOrderByFields().length * 6));
1699                    }
1700                    else {
1701                            query = new StringBundler(3);
1702                    }
1703    
1704                    query.append(_SQL_SELECT_PHONE_WHERE);
1705    
1706                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1707    
1708                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1709    
1710                    if (orderByComparator != null) {
1711                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1712    
1713                            if (orderByConditionFields.length > 0) {
1714                                    query.append(WHERE_AND);
1715                            }
1716    
1717                            for (int i = 0; i < orderByConditionFields.length; i++) {
1718                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1719                                    query.append(orderByConditionFields[i]);
1720    
1721                                    if ((i + 1) < orderByConditionFields.length) {
1722                                            if (orderByComparator.isAscending() ^ previous) {
1723                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1724                                            }
1725                                            else {
1726                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1727                                            }
1728                                    }
1729                                    else {
1730                                            if (orderByComparator.isAscending() ^ previous) {
1731                                                    query.append(WHERE_GREATER_THAN);
1732                                            }
1733                                            else {
1734                                                    query.append(WHERE_LESSER_THAN);
1735                                            }
1736                                    }
1737                            }
1738    
1739                            query.append(ORDER_BY_CLAUSE);
1740    
1741                            String[] orderByFields = orderByComparator.getOrderByFields();
1742    
1743                            for (int i = 0; i < orderByFields.length; i++) {
1744                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1745                                    query.append(orderByFields[i]);
1746    
1747                                    if ((i + 1) < orderByFields.length) {
1748                                            if (orderByComparator.isAscending() ^ previous) {
1749                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1750                                            }
1751                                            else {
1752                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1753                                            }
1754                                    }
1755                                    else {
1756                                            if (orderByComparator.isAscending() ^ previous) {
1757                                                    query.append(ORDER_BY_ASC);
1758                                            }
1759                                            else {
1760                                                    query.append(ORDER_BY_DESC);
1761                                            }
1762                                    }
1763                            }
1764                    }
1765    
1766                    else {
1767                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
1768                    }
1769    
1770                    String sql = query.toString();
1771    
1772                    Query q = session.createQuery(sql);
1773    
1774                    q.setFirstResult(0);
1775                    q.setMaxResults(2);
1776    
1777                    QueryPos qPos = QueryPos.getInstance(q);
1778    
1779                    qPos.add(companyId);
1780    
1781                    qPos.add(classNameId);
1782    
1783                    if (orderByComparator != null) {
1784                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
1785    
1786                            for (Object value : values) {
1787                                    qPos.add(value);
1788                            }
1789                    }
1790    
1791                    List<Phone> list = q.list();
1792    
1793                    if (list.size() == 2) {
1794                            return list.get(1);
1795                    }
1796                    else {
1797                            return null;
1798                    }
1799            }
1800    
1801            /**
1802             * Returns all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1803             *
1804             * @param companyId the company ID
1805             * @param classNameId the class name ID
1806             * @param classPK the class p k
1807             * @return the matching phones
1808             * @throws SystemException if a system exception occurred
1809             */
1810            public List<Phone> findByC_C_C(long companyId, long classNameId,
1811                    long classPK) throws SystemException {
1812                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1813                            QueryUtil.ALL_POS, null);
1814            }
1815    
1816            /**
1817             * Returns a range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1818             *
1819             * <p>
1820             * 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.
1821             * </p>
1822             *
1823             * @param companyId the company ID
1824             * @param classNameId the class name ID
1825             * @param classPK the class p k
1826             * @param start the lower bound of the range of phones
1827             * @param end the upper bound of the range of phones (not inclusive)
1828             * @return the range of matching phones
1829             * @throws SystemException if a system exception occurred
1830             */
1831            public List<Phone> findByC_C_C(long companyId, long classNameId,
1832                    long classPK, int start, int end) throws SystemException {
1833                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1834            }
1835    
1836            /**
1837             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1838             *
1839             * <p>
1840             * 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.
1841             * </p>
1842             *
1843             * @param companyId the company ID
1844             * @param classNameId the class name ID
1845             * @param classPK the class p k
1846             * @param start the lower bound of the range of phones
1847             * @param end the upper bound of the range of phones (not inclusive)
1848             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1849             * @return the ordered range of matching phones
1850             * @throws SystemException if a system exception occurred
1851             */
1852            public List<Phone> findByC_C_C(long companyId, long classNameId,
1853                    long classPK, int start, int end, OrderByComparator orderByComparator)
1854                    throws SystemException {
1855                    FinderPath finderPath = null;
1856                    Object[] finderArgs = null;
1857    
1858                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1859                                    (orderByComparator == null)) {
1860                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
1861                            finderArgs = new Object[] { companyId, classNameId, classPK };
1862                    }
1863                    else {
1864                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
1865                            finderArgs = new Object[] {
1866                                            companyId, classNameId, classPK,
1867                                            
1868                                            start, end, orderByComparator
1869                                    };
1870                    }
1871    
1872                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
1873                                    finderArgs, this);
1874    
1875                    if ((list != null) && !list.isEmpty()) {
1876                            for (Phone phone : list) {
1877                                    if ((companyId != phone.getCompanyId()) ||
1878                                                    (classNameId != phone.getClassNameId()) ||
1879                                                    (classPK != phone.getClassPK())) {
1880                                            list = null;
1881    
1882                                            break;
1883                                    }
1884                            }
1885                    }
1886    
1887                    if (list == null) {
1888                            StringBundler query = null;
1889    
1890                            if (orderByComparator != null) {
1891                                    query = new StringBundler(5 +
1892                                                    (orderByComparator.getOrderByFields().length * 3));
1893                            }
1894                            else {
1895                                    query = new StringBundler(5);
1896                            }
1897    
1898                            query.append(_SQL_SELECT_PHONE_WHERE);
1899    
1900                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1901    
1902                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1903    
1904                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1905    
1906                            if (orderByComparator != null) {
1907                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1908                                            orderByComparator);
1909                            }
1910    
1911                            else {
1912                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
1913                            }
1914    
1915                            String sql = query.toString();
1916    
1917                            Session session = null;
1918    
1919                            try {
1920                                    session = openSession();
1921    
1922                                    Query q = session.createQuery(sql);
1923    
1924                                    QueryPos qPos = QueryPos.getInstance(q);
1925    
1926                                    qPos.add(companyId);
1927    
1928                                    qPos.add(classNameId);
1929    
1930                                    qPos.add(classPK);
1931    
1932                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
1933                            }
1934                            catch (Exception e) {
1935                                    throw processException(e);
1936                            }
1937                            finally {
1938                                    if (list == null) {
1939                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1940                                    }
1941                                    else {
1942                                            cacheResult(list);
1943    
1944                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1945                                    }
1946    
1947                                    closeSession(session);
1948                            }
1949                    }
1950    
1951                    return list;
1952            }
1953    
1954            /**
1955             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1956             *
1957             * @param companyId the company ID
1958             * @param classNameId the class name ID
1959             * @param classPK the class p k
1960             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1961             * @return the first matching phone
1962             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
1963             * @throws SystemException if a system exception occurred
1964             */
1965            public Phone findByC_C_C_First(long companyId, long classNameId,
1966                    long classPK, OrderByComparator orderByComparator)
1967                    throws NoSuchPhoneException, SystemException {
1968                    Phone phone = fetchByC_C_C_First(companyId, classNameId, classPK,
1969                                    orderByComparator);
1970    
1971                    if (phone != null) {
1972                            return phone;
1973                    }
1974    
1975                    StringBundler msg = new StringBundler(8);
1976    
1977                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1978    
1979                    msg.append("companyId=");
1980                    msg.append(companyId);
1981    
1982                    msg.append(", classNameId=");
1983                    msg.append(classNameId);
1984    
1985                    msg.append(", classPK=");
1986                    msg.append(classPK);
1987    
1988                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1989    
1990                    throw new NoSuchPhoneException(msg.toString());
1991            }
1992    
1993            /**
1994             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1995             *
1996             * @param companyId the company ID
1997             * @param classNameId the class name ID
1998             * @param classPK the class p k
1999             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2000             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
2001             * @throws SystemException if a system exception occurred
2002             */
2003            public Phone fetchByC_C_C_First(long companyId, long classNameId,
2004                    long classPK, OrderByComparator orderByComparator)
2005                    throws SystemException {
2006                    List<Phone> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
2007                                    orderByComparator);
2008    
2009                    if (!list.isEmpty()) {
2010                            return list.get(0);
2011                    }
2012    
2013                    return null;
2014            }
2015    
2016            /**
2017             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2018             *
2019             * @param companyId the company ID
2020             * @param classNameId the class name ID
2021             * @param classPK the class p k
2022             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2023             * @return the last matching phone
2024             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
2025             * @throws SystemException if a system exception occurred
2026             */
2027            public Phone findByC_C_C_Last(long companyId, long classNameId,
2028                    long classPK, OrderByComparator orderByComparator)
2029                    throws NoSuchPhoneException, SystemException {
2030                    Phone phone = fetchByC_C_C_Last(companyId, classNameId, classPK,
2031                                    orderByComparator);
2032    
2033                    if (phone != null) {
2034                            return phone;
2035                    }
2036    
2037                    StringBundler msg = new StringBundler(8);
2038    
2039                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2040    
2041                    msg.append("companyId=");
2042                    msg.append(companyId);
2043    
2044                    msg.append(", classNameId=");
2045                    msg.append(classNameId);
2046    
2047                    msg.append(", classPK=");
2048                    msg.append(classPK);
2049    
2050                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2051    
2052                    throw new NoSuchPhoneException(msg.toString());
2053            }
2054    
2055            /**
2056             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2057             *
2058             * @param companyId the company ID
2059             * @param classNameId the class name ID
2060             * @param classPK the class p k
2061             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2062             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
2063             * @throws SystemException if a system exception occurred
2064             */
2065            public Phone fetchByC_C_C_Last(long companyId, long classNameId,
2066                    long classPK, OrderByComparator orderByComparator)
2067                    throws SystemException {
2068                    int count = countByC_C_C(companyId, classNameId, classPK);
2069    
2070                    List<Phone> list = findByC_C_C(companyId, classNameId, classPK,
2071                                    count - 1, count, orderByComparator);
2072    
2073                    if (!list.isEmpty()) {
2074                            return list.get(0);
2075                    }
2076    
2077                    return null;
2078            }
2079    
2080            /**
2081             * Returns the phones before and after the current phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2082             *
2083             * @param phoneId the primary key of the current phone
2084             * @param companyId the company ID
2085             * @param classNameId the class name ID
2086             * @param classPK the class p k
2087             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2088             * @return the previous, current, and next phone
2089             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
2090             * @throws SystemException if a system exception occurred
2091             */
2092            public Phone[] findByC_C_C_PrevAndNext(long phoneId, long companyId,
2093                    long classNameId, long classPK, OrderByComparator orderByComparator)
2094                    throws NoSuchPhoneException, SystemException {
2095                    Phone phone = findByPrimaryKey(phoneId);
2096    
2097                    Session session = null;
2098    
2099                    try {
2100                            session = openSession();
2101    
2102                            Phone[] array = new PhoneImpl[3];
2103    
2104                            array[0] = getByC_C_C_PrevAndNext(session, phone, companyId,
2105                                            classNameId, classPK, orderByComparator, true);
2106    
2107                            array[1] = phone;
2108    
2109                            array[2] = getByC_C_C_PrevAndNext(session, phone, companyId,
2110                                            classNameId, classPK, orderByComparator, false);
2111    
2112                            return array;
2113                    }
2114                    catch (Exception e) {
2115                            throw processException(e);
2116                    }
2117                    finally {
2118                            closeSession(session);
2119                    }
2120            }
2121    
2122            protected Phone getByC_C_C_PrevAndNext(Session session, Phone phone,
2123                    long companyId, long classNameId, long classPK,
2124                    OrderByComparator orderByComparator, boolean previous) {
2125                    StringBundler query = null;
2126    
2127                    if (orderByComparator != null) {
2128                            query = new StringBundler(6 +
2129                                            (orderByComparator.getOrderByFields().length * 6));
2130                    }
2131                    else {
2132                            query = new StringBundler(3);
2133                    }
2134    
2135                    query.append(_SQL_SELECT_PHONE_WHERE);
2136    
2137                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2138    
2139                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2140    
2141                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2142    
2143                    if (orderByComparator != null) {
2144                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2145    
2146                            if (orderByConditionFields.length > 0) {
2147                                    query.append(WHERE_AND);
2148                            }
2149    
2150                            for (int i = 0; i < orderByConditionFields.length; i++) {
2151                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2152                                    query.append(orderByConditionFields[i]);
2153    
2154                                    if ((i + 1) < orderByConditionFields.length) {
2155                                            if (orderByComparator.isAscending() ^ previous) {
2156                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2157                                            }
2158                                            else {
2159                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2160                                            }
2161                                    }
2162                                    else {
2163                                            if (orderByComparator.isAscending() ^ previous) {
2164                                                    query.append(WHERE_GREATER_THAN);
2165                                            }
2166                                            else {
2167                                                    query.append(WHERE_LESSER_THAN);
2168                                            }
2169                                    }
2170                            }
2171    
2172                            query.append(ORDER_BY_CLAUSE);
2173    
2174                            String[] orderByFields = orderByComparator.getOrderByFields();
2175    
2176                            for (int i = 0; i < orderByFields.length; i++) {
2177                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2178                                    query.append(orderByFields[i]);
2179    
2180                                    if ((i + 1) < orderByFields.length) {
2181                                            if (orderByComparator.isAscending() ^ previous) {
2182                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2183                                            }
2184                                            else {
2185                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2186                                            }
2187                                    }
2188                                    else {
2189                                            if (orderByComparator.isAscending() ^ previous) {
2190                                                    query.append(ORDER_BY_ASC);
2191                                            }
2192                                            else {
2193                                                    query.append(ORDER_BY_DESC);
2194                                            }
2195                                    }
2196                            }
2197                    }
2198    
2199                    else {
2200                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
2201                    }
2202    
2203                    String sql = query.toString();
2204    
2205                    Query q = session.createQuery(sql);
2206    
2207                    q.setFirstResult(0);
2208                    q.setMaxResults(2);
2209    
2210                    QueryPos qPos = QueryPos.getInstance(q);
2211    
2212                    qPos.add(companyId);
2213    
2214                    qPos.add(classNameId);
2215    
2216                    qPos.add(classPK);
2217    
2218                    if (orderByComparator != null) {
2219                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
2220    
2221                            for (Object value : values) {
2222                                    qPos.add(value);
2223                            }
2224                    }
2225    
2226                    List<Phone> list = q.list();
2227    
2228                    if (list.size() == 2) {
2229                            return list.get(1);
2230                    }
2231                    else {
2232                            return null;
2233                    }
2234            }
2235    
2236            /**
2237             * Returns all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2238             *
2239             * @param companyId the company ID
2240             * @param classNameId the class name ID
2241             * @param classPK the class p k
2242             * @param primary the primary
2243             * @return the matching phones
2244             * @throws SystemException if a system exception occurred
2245             */
2246            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
2247                    long classPK, boolean primary) throws SystemException {
2248                    return findByC_C_C_P(companyId, classNameId, classPK, primary,
2249                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2250            }
2251    
2252            /**
2253             * Returns a range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2254             *
2255             * <p>
2256             * 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.
2257             * </p>
2258             *
2259             * @param companyId the company ID
2260             * @param classNameId the class name ID
2261             * @param classPK the class p k
2262             * @param primary the primary
2263             * @param start the lower bound of the range of phones
2264             * @param end the upper bound of the range of phones (not inclusive)
2265             * @return the range of matching phones
2266             * @throws SystemException if a system exception occurred
2267             */
2268            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
2269                    long classPK, boolean primary, int start, int end)
2270                    throws SystemException {
2271                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
2272                            end, null);
2273            }
2274    
2275            /**
2276             * Returns an ordered range of all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2277             *
2278             * <p>
2279             * 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.
2280             * </p>
2281             *
2282             * @param companyId the company ID
2283             * @param classNameId the class name ID
2284             * @param classPK the class p k
2285             * @param primary the primary
2286             * @param start the lower bound of the range of phones
2287             * @param end the upper bound of the range of phones (not inclusive)
2288             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2289             * @return the ordered range of matching phones
2290             * @throws SystemException if a system exception occurred
2291             */
2292            public List<Phone> findByC_C_C_P(long companyId, long classNameId,
2293                    long classPK, boolean primary, int start, int end,
2294                    OrderByComparator orderByComparator) throws SystemException {
2295                    FinderPath finderPath = null;
2296                    Object[] finderArgs = null;
2297    
2298                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2299                                    (orderByComparator == null)) {
2300                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P;
2301                            finderArgs = new Object[] { companyId, classNameId, classPK, primary };
2302                    }
2303                    else {
2304                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
2305                            finderArgs = new Object[] {
2306                                            companyId, classNameId, classPK, primary,
2307                                            
2308                                            start, end, orderByComparator
2309                                    };
2310                    }
2311    
2312                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
2313                                    finderArgs, this);
2314    
2315                    if ((list != null) && !list.isEmpty()) {
2316                            for (Phone phone : list) {
2317                                    if ((companyId != phone.getCompanyId()) ||
2318                                                    (classNameId != phone.getClassNameId()) ||
2319                                                    (classPK != phone.getClassPK()) ||
2320                                                    (primary != phone.getPrimary())) {
2321                                            list = null;
2322    
2323                                            break;
2324                                    }
2325                            }
2326                    }
2327    
2328                    if (list == null) {
2329                            StringBundler query = null;
2330    
2331                            if (orderByComparator != null) {
2332                                    query = new StringBundler(6 +
2333                                                    (orderByComparator.getOrderByFields().length * 3));
2334                            }
2335                            else {
2336                                    query = new StringBundler(6);
2337                            }
2338    
2339                            query.append(_SQL_SELECT_PHONE_WHERE);
2340    
2341                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2342    
2343                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2344    
2345                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2346    
2347                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2348    
2349                            if (orderByComparator != null) {
2350                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2351                                            orderByComparator);
2352                            }
2353    
2354                            else {
2355                                    query.append(PhoneModelImpl.ORDER_BY_JPQL);
2356                            }
2357    
2358                            String sql = query.toString();
2359    
2360                            Session session = null;
2361    
2362                            try {
2363                                    session = openSession();
2364    
2365                                    Query q = session.createQuery(sql);
2366    
2367                                    QueryPos qPos = QueryPos.getInstance(q);
2368    
2369                                    qPos.add(companyId);
2370    
2371                                    qPos.add(classNameId);
2372    
2373                                    qPos.add(classPK);
2374    
2375                                    qPos.add(primary);
2376    
2377                                    list = (List<Phone>)QueryUtil.list(q, getDialect(), start, end);
2378                            }
2379                            catch (Exception e) {
2380                                    throw processException(e);
2381                            }
2382                            finally {
2383                                    if (list == null) {
2384                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2385                                    }
2386                                    else {
2387                                            cacheResult(list);
2388    
2389                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2390                                    }
2391    
2392                                    closeSession(session);
2393                            }
2394                    }
2395    
2396                    return list;
2397            }
2398    
2399            /**
2400             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2401             *
2402             * @param companyId the company ID
2403             * @param classNameId the class name ID
2404             * @param classPK the class p k
2405             * @param primary the primary
2406             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2407             * @return the first matching phone
2408             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
2409             * @throws SystemException if a system exception occurred
2410             */
2411            public Phone findByC_C_C_P_First(long companyId, long classNameId,
2412                    long classPK, boolean primary, OrderByComparator orderByComparator)
2413                    throws NoSuchPhoneException, SystemException {
2414                    Phone phone = fetchByC_C_C_P_First(companyId, classNameId, classPK,
2415                                    primary, orderByComparator);
2416    
2417                    if (phone != null) {
2418                            return phone;
2419                    }
2420    
2421                    StringBundler msg = new StringBundler(10);
2422    
2423                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2424    
2425                    msg.append("companyId=");
2426                    msg.append(companyId);
2427    
2428                    msg.append(", classNameId=");
2429                    msg.append(classNameId);
2430    
2431                    msg.append(", classPK=");
2432                    msg.append(classPK);
2433    
2434                    msg.append(", primary=");
2435                    msg.append(primary);
2436    
2437                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2438    
2439                    throw new NoSuchPhoneException(msg.toString());
2440            }
2441    
2442            /**
2443             * Returns the first phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2444             *
2445             * @param companyId the company ID
2446             * @param classNameId the class name ID
2447             * @param classPK the class p k
2448             * @param primary the primary
2449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2450             * @return the first matching phone, or <code>null</code> if a matching phone could not be found
2451             * @throws SystemException if a system exception occurred
2452             */
2453            public Phone fetchByC_C_C_P_First(long companyId, long classNameId,
2454                    long classPK, boolean primary, OrderByComparator orderByComparator)
2455                    throws SystemException {
2456                    List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
2457                                    primary, 0, 1, orderByComparator);
2458    
2459                    if (!list.isEmpty()) {
2460                            return list.get(0);
2461                    }
2462    
2463                    return null;
2464            }
2465    
2466            /**
2467             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2468             *
2469             * @param companyId the company ID
2470             * @param classNameId the class name ID
2471             * @param classPK the class p k
2472             * @param primary the primary
2473             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2474             * @return the last matching phone
2475             * @throws com.liferay.portal.NoSuchPhoneException if a matching phone could not be found
2476             * @throws SystemException if a system exception occurred
2477             */
2478            public Phone findByC_C_C_P_Last(long companyId, long classNameId,
2479                    long classPK, boolean primary, OrderByComparator orderByComparator)
2480                    throws NoSuchPhoneException, SystemException {
2481                    Phone phone = fetchByC_C_C_P_Last(companyId, classNameId, classPK,
2482                                    primary, orderByComparator);
2483    
2484                    if (phone != null) {
2485                            return phone;
2486                    }
2487    
2488                    StringBundler msg = new StringBundler(10);
2489    
2490                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2491    
2492                    msg.append("companyId=");
2493                    msg.append(companyId);
2494    
2495                    msg.append(", classNameId=");
2496                    msg.append(classNameId);
2497    
2498                    msg.append(", classPK=");
2499                    msg.append(classPK);
2500    
2501                    msg.append(", primary=");
2502                    msg.append(primary);
2503    
2504                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2505    
2506                    throw new NoSuchPhoneException(msg.toString());
2507            }
2508    
2509            /**
2510             * Returns the last phone in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2511             *
2512             * @param companyId the company ID
2513             * @param classNameId the class name ID
2514             * @param classPK the class p k
2515             * @param primary the primary
2516             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2517             * @return the last matching phone, or <code>null</code> if a matching phone could not be found
2518             * @throws SystemException if a system exception occurred
2519             */
2520            public Phone fetchByC_C_C_P_Last(long companyId, long classNameId,
2521                    long classPK, boolean primary, OrderByComparator orderByComparator)
2522                    throws SystemException {
2523                    int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
2524    
2525                    List<Phone> list = findByC_C_C_P(companyId, classNameId, classPK,
2526                                    primary, count - 1, count, orderByComparator);
2527    
2528                    if (!list.isEmpty()) {
2529                            return list.get(0);
2530                    }
2531    
2532                    return null;
2533            }
2534    
2535            /**
2536             * 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;.
2537             *
2538             * @param phoneId the primary key of the current phone
2539             * @param companyId the company ID
2540             * @param classNameId the class name ID
2541             * @param classPK the class p k
2542             * @param primary the primary
2543             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2544             * @return the previous, current, and next phone
2545             * @throws com.liferay.portal.NoSuchPhoneException if a phone with the primary key could not be found
2546             * @throws SystemException if a system exception occurred
2547             */
2548            public Phone[] findByC_C_C_P_PrevAndNext(long phoneId, long companyId,
2549                    long classNameId, long classPK, boolean primary,
2550                    OrderByComparator orderByComparator)
2551                    throws NoSuchPhoneException, SystemException {
2552                    Phone phone = findByPrimaryKey(phoneId);
2553    
2554                    Session session = null;
2555    
2556                    try {
2557                            session = openSession();
2558    
2559                            Phone[] array = new PhoneImpl[3];
2560    
2561                            array[0] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
2562                                            classNameId, classPK, primary, orderByComparator, true);
2563    
2564                            array[1] = phone;
2565    
2566                            array[2] = getByC_C_C_P_PrevAndNext(session, phone, companyId,
2567                                            classNameId, classPK, primary, orderByComparator, false);
2568    
2569                            return array;
2570                    }
2571                    catch (Exception e) {
2572                            throw processException(e);
2573                    }
2574                    finally {
2575                            closeSession(session);
2576                    }
2577            }
2578    
2579            protected Phone getByC_C_C_P_PrevAndNext(Session session, Phone phone,
2580                    long companyId, long classNameId, long classPK, boolean primary,
2581                    OrderByComparator orderByComparator, boolean previous) {
2582                    StringBundler query = null;
2583    
2584                    if (orderByComparator != null) {
2585                            query = new StringBundler(6 +
2586                                            (orderByComparator.getOrderByFields().length * 6));
2587                    }
2588                    else {
2589                            query = new StringBundler(3);
2590                    }
2591    
2592                    query.append(_SQL_SELECT_PHONE_WHERE);
2593    
2594                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2595    
2596                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2597    
2598                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2599    
2600                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2601    
2602                    if (orderByComparator != null) {
2603                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2604    
2605                            if (orderByConditionFields.length > 0) {
2606                                    query.append(WHERE_AND);
2607                            }
2608    
2609                            for (int i = 0; i < orderByConditionFields.length; i++) {
2610                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2611                                    query.append(orderByConditionFields[i]);
2612    
2613                                    if ((i + 1) < orderByConditionFields.length) {
2614                                            if (orderByComparator.isAscending() ^ previous) {
2615                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2616                                            }
2617                                            else {
2618                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2619                                            }
2620                                    }
2621                                    else {
2622                                            if (orderByComparator.isAscending() ^ previous) {
2623                                                    query.append(WHERE_GREATER_THAN);
2624                                            }
2625                                            else {
2626                                                    query.append(WHERE_LESSER_THAN);
2627                                            }
2628                                    }
2629                            }
2630    
2631                            query.append(ORDER_BY_CLAUSE);
2632    
2633                            String[] orderByFields = orderByComparator.getOrderByFields();
2634    
2635                            for (int i = 0; i < orderByFields.length; i++) {
2636                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2637                                    query.append(orderByFields[i]);
2638    
2639                                    if ((i + 1) < orderByFields.length) {
2640                                            if (orderByComparator.isAscending() ^ previous) {
2641                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2642                                            }
2643                                            else {
2644                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2645                                            }
2646                                    }
2647                                    else {
2648                                            if (orderByComparator.isAscending() ^ previous) {
2649                                                    query.append(ORDER_BY_ASC);
2650                                            }
2651                                            else {
2652                                                    query.append(ORDER_BY_DESC);
2653                                            }
2654                                    }
2655                            }
2656                    }
2657    
2658                    else {
2659                            query.append(PhoneModelImpl.ORDER_BY_JPQL);
2660                    }
2661    
2662                    String sql = query.toString();
2663    
2664                    Query q = session.createQuery(sql);
2665    
2666                    q.setFirstResult(0);
2667                    q.setMaxResults(2);
2668    
2669                    QueryPos qPos = QueryPos.getInstance(q);
2670    
2671                    qPos.add(companyId);
2672    
2673                    qPos.add(classNameId);
2674    
2675                    qPos.add(classPK);
2676    
2677                    qPos.add(primary);
2678    
2679                    if (orderByComparator != null) {
2680                            Object[] values = orderByComparator.getOrderByConditionValues(phone);
2681    
2682                            for (Object value : values) {
2683                                    qPos.add(value);
2684                            }
2685                    }
2686    
2687                    List<Phone> list = q.list();
2688    
2689                    if (list.size() == 2) {
2690                            return list.get(1);
2691                    }
2692                    else {
2693                            return null;
2694                    }
2695            }
2696    
2697            /**
2698             * Returns all the phones.
2699             *
2700             * @return the phones
2701             * @throws SystemException if a system exception occurred
2702             */
2703            public List<Phone> findAll() throws SystemException {
2704                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2705            }
2706    
2707            /**
2708             * Returns a range of all the phones.
2709             *
2710             * <p>
2711             * 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.
2712             * </p>
2713             *
2714             * @param start the lower bound of the range of phones
2715             * @param end the upper bound of the range of phones (not inclusive)
2716             * @return the range of phones
2717             * @throws SystemException if a system exception occurred
2718             */
2719            public List<Phone> findAll(int start, int end) throws SystemException {
2720                    return findAll(start, end, null);
2721            }
2722    
2723            /**
2724             * Returns an ordered range of all the phones.
2725             *
2726             * <p>
2727             * 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.
2728             * </p>
2729             *
2730             * @param start the lower bound of the range of phones
2731             * @param end the upper bound of the range of phones (not inclusive)
2732             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2733             * @return the ordered range of phones
2734             * @throws SystemException if a system exception occurred
2735             */
2736            public List<Phone> findAll(int start, int end,
2737                    OrderByComparator orderByComparator) throws SystemException {
2738                    FinderPath finderPath = null;
2739                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2740    
2741                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2742                                    (orderByComparator == null)) {
2743                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2744                            finderArgs = FINDER_ARGS_EMPTY;
2745                    }
2746                    else {
2747                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2748                            finderArgs = new Object[] { start, end, orderByComparator };
2749                    }
2750    
2751                    List<Phone> list = (List<Phone>)FinderCacheUtil.getResult(finderPath,
2752                                    finderArgs, this);
2753    
2754                    if (list == null) {
2755                            StringBundler query = null;
2756                            String sql = null;
2757    
2758                            if (orderByComparator != null) {
2759                                    query = new StringBundler(2 +
2760                                                    (orderByComparator.getOrderByFields().length * 3));
2761    
2762                                    query.append(_SQL_SELECT_PHONE);
2763    
2764                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2765                                            orderByComparator);
2766    
2767                                    sql = query.toString();
2768                            }
2769                            else {
2770                                    sql = _SQL_SELECT_PHONE.concat(PhoneModelImpl.ORDER_BY_JPQL);
2771                            }
2772    
2773                            Session session = null;
2774    
2775                            try {
2776                                    session = openSession();
2777    
2778                                    Query q = session.createQuery(sql);
2779    
2780                                    if (orderByComparator == null) {
2781                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2782                                                            end, false);
2783    
2784                                            Collections.sort(list);
2785                                    }
2786                                    else {
2787                                            list = (List<Phone>)QueryUtil.list(q, getDialect(), start,
2788                                                            end);
2789                                    }
2790                            }
2791                            catch (Exception e) {
2792                                    throw processException(e);
2793                            }
2794                            finally {
2795                                    if (list == null) {
2796                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2797                                    }
2798                                    else {
2799                                            cacheResult(list);
2800    
2801                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2802                                    }
2803    
2804                                    closeSession(session);
2805                            }
2806                    }
2807    
2808                    return list;
2809            }
2810    
2811            /**
2812             * Removes all the phones where companyId = &#63; from the database.
2813             *
2814             * @param companyId the company ID
2815             * @throws SystemException if a system exception occurred
2816             */
2817            public void removeByCompanyId(long companyId) throws SystemException {
2818                    for (Phone phone : findByCompanyId(companyId)) {
2819                            remove(phone);
2820                    }
2821            }
2822    
2823            /**
2824             * Removes all the phones where userId = &#63; from the database.
2825             *
2826             * @param userId the user ID
2827             * @throws SystemException if a system exception occurred
2828             */
2829            public void removeByUserId(long userId) throws SystemException {
2830                    for (Phone phone : findByUserId(userId)) {
2831                            remove(phone);
2832                    }
2833            }
2834    
2835            /**
2836             * Removes all the phones where companyId = &#63; and classNameId = &#63; from the database.
2837             *
2838             * @param companyId the company ID
2839             * @param classNameId the class name ID
2840             * @throws SystemException if a system exception occurred
2841             */
2842            public void removeByC_C(long companyId, long classNameId)
2843                    throws SystemException {
2844                    for (Phone phone : findByC_C(companyId, classNameId)) {
2845                            remove(phone);
2846                    }
2847            }
2848    
2849            /**
2850             * Removes all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2851             *
2852             * @param companyId the company ID
2853             * @param classNameId the class name ID
2854             * @param classPK the class p k
2855             * @throws SystemException if a system exception occurred
2856             */
2857            public void removeByC_C_C(long companyId, long classNameId, long classPK)
2858                    throws SystemException {
2859                    for (Phone phone : findByC_C_C(companyId, classNameId, classPK)) {
2860                            remove(phone);
2861                    }
2862            }
2863    
2864            /**
2865             * Removes all the phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63; from the database.
2866             *
2867             * @param companyId the company ID
2868             * @param classNameId the class name ID
2869             * @param classPK the class p k
2870             * @param primary the primary
2871             * @throws SystemException if a system exception occurred
2872             */
2873            public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
2874                    boolean primary) throws SystemException {
2875                    for (Phone phone : findByC_C_C_P(companyId, classNameId, classPK,
2876                                    primary)) {
2877                            remove(phone);
2878                    }
2879            }
2880    
2881            /**
2882             * Removes all the phones from the database.
2883             *
2884             * @throws SystemException if a system exception occurred
2885             */
2886            public void removeAll() throws SystemException {
2887                    for (Phone phone : findAll()) {
2888                            remove(phone);
2889                    }
2890            }
2891    
2892            /**
2893             * Returns the number of phones where companyId = &#63;.
2894             *
2895             * @param companyId the company ID
2896             * @return the number of matching phones
2897             * @throws SystemException if a system exception occurred
2898             */
2899            public int countByCompanyId(long companyId) throws SystemException {
2900                    Object[] finderArgs = new Object[] { companyId };
2901    
2902                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2903                                    finderArgs, this);
2904    
2905                    if (count == null) {
2906                            StringBundler query = new StringBundler(2);
2907    
2908                            query.append(_SQL_COUNT_PHONE_WHERE);
2909    
2910                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2911    
2912                            String sql = query.toString();
2913    
2914                            Session session = null;
2915    
2916                            try {
2917                                    session = openSession();
2918    
2919                                    Query q = session.createQuery(sql);
2920    
2921                                    QueryPos qPos = QueryPos.getInstance(q);
2922    
2923                                    qPos.add(companyId);
2924    
2925                                    count = (Long)q.uniqueResult();
2926                            }
2927                            catch (Exception e) {
2928                                    throw processException(e);
2929                            }
2930                            finally {
2931                                    if (count == null) {
2932                                            count = Long.valueOf(0);
2933                                    }
2934    
2935                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2936                                            finderArgs, count);
2937    
2938                                    closeSession(session);
2939                            }
2940                    }
2941    
2942                    return count.intValue();
2943            }
2944    
2945            /**
2946             * Returns the number of phones where userId = &#63;.
2947             *
2948             * @param userId the user ID
2949             * @return the number of matching phones
2950             * @throws SystemException if a system exception occurred
2951             */
2952            public int countByUserId(long userId) throws SystemException {
2953                    Object[] finderArgs = new Object[] { userId };
2954    
2955                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2956                                    finderArgs, this);
2957    
2958                    if (count == null) {
2959                            StringBundler query = new StringBundler(2);
2960    
2961                            query.append(_SQL_COUNT_PHONE_WHERE);
2962    
2963                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2964    
2965                            String sql = query.toString();
2966    
2967                            Session session = null;
2968    
2969                            try {
2970                                    session = openSession();
2971    
2972                                    Query q = session.createQuery(sql);
2973    
2974                                    QueryPos qPos = QueryPos.getInstance(q);
2975    
2976                                    qPos.add(userId);
2977    
2978                                    count = (Long)q.uniqueResult();
2979                            }
2980                            catch (Exception e) {
2981                                    throw processException(e);
2982                            }
2983                            finally {
2984                                    if (count == null) {
2985                                            count = Long.valueOf(0);
2986                                    }
2987    
2988                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2989                                            finderArgs, count);
2990    
2991                                    closeSession(session);
2992                            }
2993                    }
2994    
2995                    return count.intValue();
2996            }
2997    
2998            /**
2999             * Returns the number of phones where companyId = &#63; and classNameId = &#63;.
3000             *
3001             * @param companyId the company ID
3002             * @param classNameId the class name ID
3003             * @return the number of matching phones
3004             * @throws SystemException if a system exception occurred
3005             */
3006            public int countByC_C(long companyId, long classNameId)
3007                    throws SystemException {
3008                    Object[] finderArgs = new Object[] { companyId, classNameId };
3009    
3010                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
3011                                    finderArgs, this);
3012    
3013                    if (count == null) {
3014                            StringBundler query = new StringBundler(3);
3015    
3016                            query.append(_SQL_COUNT_PHONE_WHERE);
3017    
3018                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
3019    
3020                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3021    
3022                            String sql = query.toString();
3023    
3024                            Session session = null;
3025    
3026                            try {
3027                                    session = openSession();
3028    
3029                                    Query q = session.createQuery(sql);
3030    
3031                                    QueryPos qPos = QueryPos.getInstance(q);
3032    
3033                                    qPos.add(companyId);
3034    
3035                                    qPos.add(classNameId);
3036    
3037                                    count = (Long)q.uniqueResult();
3038                            }
3039                            catch (Exception e) {
3040                                    throw processException(e);
3041                            }
3042                            finally {
3043                                    if (count == null) {
3044                                            count = Long.valueOf(0);
3045                                    }
3046    
3047                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
3048                                            count);
3049    
3050                                    closeSession(session);
3051                            }
3052                    }
3053    
3054                    return count.intValue();
3055            }
3056    
3057            /**
3058             * Returns the number of phones where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3059             *
3060             * @param companyId the company ID
3061             * @param classNameId the class name ID
3062             * @param classPK the class p k
3063             * @return the number of matching phones
3064             * @throws SystemException if a system exception occurred
3065             */
3066            public int countByC_C_C(long companyId, long classNameId, long classPK)
3067                    throws SystemException {
3068                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
3069    
3070                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
3071                                    finderArgs, this);
3072    
3073                    if (count == null) {
3074                            StringBundler query = new StringBundler(4);
3075    
3076                            query.append(_SQL_COUNT_PHONE_WHERE);
3077    
3078                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3079    
3080                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3081    
3082                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3083    
3084                            String sql = query.toString();
3085    
3086                            Session session = null;
3087    
3088                            try {
3089                                    session = openSession();
3090    
3091                                    Query q = session.createQuery(sql);
3092    
3093                                    QueryPos qPos = QueryPos.getInstance(q);
3094    
3095                                    qPos.add(companyId);
3096    
3097                                    qPos.add(classNameId);
3098    
3099                                    qPos.add(classPK);
3100    
3101                                    count = (Long)q.uniqueResult();
3102                            }
3103                            catch (Exception e) {
3104                                    throw processException(e);
3105                            }
3106                            finally {
3107                                    if (count == null) {
3108                                            count = Long.valueOf(0);
3109                                    }
3110    
3111                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
3112                                            finderArgs, count);
3113    
3114                                    closeSession(session);
3115                            }
3116                    }
3117    
3118                    return count.intValue();
3119            }
3120    
3121            /**
3122             * Returns the number of phones where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3123             *
3124             * @param companyId the company ID
3125             * @param classNameId the class name ID
3126             * @param classPK the class p k
3127             * @param primary the primary
3128             * @return the number of matching phones
3129             * @throws SystemException if a system exception occurred
3130             */
3131            public int countByC_C_C_P(long companyId, long classNameId, long classPK,
3132                    boolean primary) throws SystemException {
3133                    Object[] finderArgs = new Object[] {
3134                                    companyId, classNameId, classPK, primary
3135                            };
3136    
3137                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C_P,
3138                                    finderArgs, this);
3139    
3140                    if (count == null) {
3141                            StringBundler query = new StringBundler(5);
3142    
3143                            query.append(_SQL_COUNT_PHONE_WHERE);
3144    
3145                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3146    
3147                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3148    
3149                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3150    
3151                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3152    
3153                            String sql = query.toString();
3154    
3155                            Session session = null;
3156    
3157                            try {
3158                                    session = openSession();
3159    
3160                                    Query q = session.createQuery(sql);
3161    
3162                                    QueryPos qPos = QueryPos.getInstance(q);
3163    
3164                                    qPos.add(companyId);
3165    
3166                                    qPos.add(classNameId);
3167    
3168                                    qPos.add(classPK);
3169    
3170                                    qPos.add(primary);
3171    
3172                                    count = (Long)q.uniqueResult();
3173                            }
3174                            catch (Exception e) {
3175                                    throw processException(e);
3176                            }
3177                            finally {
3178                                    if (count == null) {
3179                                            count = Long.valueOf(0);
3180                                    }
3181    
3182                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C_P,
3183                                            finderArgs, count);
3184    
3185                                    closeSession(session);
3186                            }
3187                    }
3188    
3189                    return count.intValue();
3190            }
3191    
3192            /**
3193             * Returns the number of phones.
3194             *
3195             * @return the number of phones
3196             * @throws SystemException if a system exception occurred
3197             */
3198            public int countAll() throws SystemException {
3199                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3200                                    FINDER_ARGS_EMPTY, this);
3201    
3202                    if (count == null) {
3203                            Session session = null;
3204    
3205                            try {
3206                                    session = openSession();
3207    
3208                                    Query q = session.createQuery(_SQL_COUNT_PHONE);
3209    
3210                                    count = (Long)q.uniqueResult();
3211                            }
3212                            catch (Exception e) {
3213                                    throw processException(e);
3214                            }
3215                            finally {
3216                                    if (count == null) {
3217                                            count = Long.valueOf(0);
3218                                    }
3219    
3220                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3221                                            FINDER_ARGS_EMPTY, count);
3222    
3223                                    closeSession(session);
3224                            }
3225                    }
3226    
3227                    return count.intValue();
3228            }
3229    
3230            /**
3231             * Initializes the phone persistence.
3232             */
3233            public void afterPropertiesSet() {
3234                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3235                                            com.liferay.portal.util.PropsUtil.get(
3236                                                    "value.object.listener.com.liferay.portal.model.Phone")));
3237    
3238                    if (listenerClassNames.length > 0) {
3239                            try {
3240                                    List<ModelListener<Phone>> listenersList = new ArrayList<ModelListener<Phone>>();
3241    
3242                                    for (String listenerClassName : listenerClassNames) {
3243                                            listenersList.add((ModelListener<Phone>)InstanceFactory.newInstance(
3244                                                            listenerClassName));
3245                                    }
3246    
3247                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3248                            }
3249                            catch (Exception e) {
3250                                    _log.error(e);
3251                            }
3252                    }
3253            }
3254    
3255            public void destroy() {
3256                    EntityCacheUtil.removeCache(PhoneImpl.class.getName());
3257                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3258                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3259            }
3260    
3261            @BeanReference(type = AccountPersistence.class)
3262            protected AccountPersistence accountPersistence;
3263            @BeanReference(type = AddressPersistence.class)
3264            protected AddressPersistence addressPersistence;
3265            @BeanReference(type = BrowserTrackerPersistence.class)
3266            protected BrowserTrackerPersistence browserTrackerPersistence;
3267            @BeanReference(type = ClassNamePersistence.class)
3268            protected ClassNamePersistence classNamePersistence;
3269            @BeanReference(type = ClusterGroupPersistence.class)
3270            protected ClusterGroupPersistence clusterGroupPersistence;
3271            @BeanReference(type = CompanyPersistence.class)
3272            protected CompanyPersistence companyPersistence;
3273            @BeanReference(type = ContactPersistence.class)
3274            protected ContactPersistence contactPersistence;
3275            @BeanReference(type = CountryPersistence.class)
3276            protected CountryPersistence countryPersistence;
3277            @BeanReference(type = EmailAddressPersistence.class)
3278            protected EmailAddressPersistence emailAddressPersistence;
3279            @BeanReference(type = GroupPersistence.class)
3280            protected GroupPersistence groupPersistence;
3281            @BeanReference(type = ImagePersistence.class)
3282            protected ImagePersistence imagePersistence;
3283            @BeanReference(type = LayoutPersistence.class)
3284            protected LayoutPersistence layoutPersistence;
3285            @BeanReference(type = LayoutBranchPersistence.class)
3286            protected LayoutBranchPersistence layoutBranchPersistence;
3287            @BeanReference(type = LayoutPrototypePersistence.class)
3288            protected LayoutPrototypePersistence layoutPrototypePersistence;
3289            @BeanReference(type = LayoutRevisionPersistence.class)
3290            protected LayoutRevisionPersistence layoutRevisionPersistence;
3291            @BeanReference(type = LayoutSetPersistence.class)
3292            protected LayoutSetPersistence layoutSetPersistence;
3293            @BeanReference(type = LayoutSetBranchPersistence.class)
3294            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
3295            @BeanReference(type = LayoutSetPrototypePersistence.class)
3296            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
3297            @BeanReference(type = ListTypePersistence.class)
3298            protected ListTypePersistence listTypePersistence;
3299            @BeanReference(type = LockPersistence.class)
3300            protected LockPersistence lockPersistence;
3301            @BeanReference(type = MembershipRequestPersistence.class)
3302            protected MembershipRequestPersistence membershipRequestPersistence;
3303            @BeanReference(type = OrganizationPersistence.class)
3304            protected OrganizationPersistence organizationPersistence;
3305            @BeanReference(type = OrgGroupRolePersistence.class)
3306            protected OrgGroupRolePersistence orgGroupRolePersistence;
3307            @BeanReference(type = OrgLaborPersistence.class)
3308            protected OrgLaborPersistence orgLaborPersistence;
3309            @BeanReference(type = PasswordPolicyPersistence.class)
3310            protected PasswordPolicyPersistence passwordPolicyPersistence;
3311            @BeanReference(type = PasswordPolicyRelPersistence.class)
3312            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
3313            @BeanReference(type = PasswordTrackerPersistence.class)
3314            protected PasswordTrackerPersistence passwordTrackerPersistence;
3315            @BeanReference(type = PhonePersistence.class)
3316            protected PhonePersistence phonePersistence;
3317            @BeanReference(type = PluginSettingPersistence.class)
3318            protected PluginSettingPersistence pluginSettingPersistence;
3319            @BeanReference(type = PortalPreferencesPersistence.class)
3320            protected PortalPreferencesPersistence portalPreferencesPersistence;
3321            @BeanReference(type = PortletPersistence.class)
3322            protected PortletPersistence portletPersistence;
3323            @BeanReference(type = PortletItemPersistence.class)
3324            protected PortletItemPersistence portletItemPersistence;
3325            @BeanReference(type = PortletPreferencesPersistence.class)
3326            protected PortletPreferencesPersistence portletPreferencesPersistence;
3327            @BeanReference(type = RegionPersistence.class)
3328            protected RegionPersistence regionPersistence;
3329            @BeanReference(type = ReleasePersistence.class)
3330            protected ReleasePersistence releasePersistence;
3331            @BeanReference(type = RepositoryPersistence.class)
3332            protected RepositoryPersistence repositoryPersistence;
3333            @BeanReference(type = RepositoryEntryPersistence.class)
3334            protected RepositoryEntryPersistence repositoryEntryPersistence;
3335            @BeanReference(type = ResourceActionPersistence.class)
3336            protected ResourceActionPersistence resourceActionPersistence;
3337            @BeanReference(type = ResourceBlockPersistence.class)
3338            protected ResourceBlockPersistence resourceBlockPersistence;
3339            @BeanReference(type = ResourceBlockPermissionPersistence.class)
3340            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
3341            @BeanReference(type = ResourcePermissionPersistence.class)
3342            protected ResourcePermissionPersistence resourcePermissionPersistence;
3343            @BeanReference(type = ResourceTypePermissionPersistence.class)
3344            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
3345            @BeanReference(type = RolePersistence.class)
3346            protected RolePersistence rolePersistence;
3347            @BeanReference(type = ServiceComponentPersistence.class)
3348            protected ServiceComponentPersistence serviceComponentPersistence;
3349            @BeanReference(type = ShardPersistence.class)
3350            protected ShardPersistence shardPersistence;
3351            @BeanReference(type = SubscriptionPersistence.class)
3352            protected SubscriptionPersistence subscriptionPersistence;
3353            @BeanReference(type = TeamPersistence.class)
3354            protected TeamPersistence teamPersistence;
3355            @BeanReference(type = TicketPersistence.class)
3356            protected TicketPersistence ticketPersistence;
3357            @BeanReference(type = UserPersistence.class)
3358            protected UserPersistence userPersistence;
3359            @BeanReference(type = UserGroupPersistence.class)
3360            protected UserGroupPersistence userGroupPersistence;
3361            @BeanReference(type = UserGroupGroupRolePersistence.class)
3362            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
3363            @BeanReference(type = UserGroupRolePersistence.class)
3364            protected UserGroupRolePersistence userGroupRolePersistence;
3365            @BeanReference(type = UserIdMapperPersistence.class)
3366            protected UserIdMapperPersistence userIdMapperPersistence;
3367            @BeanReference(type = UserNotificationEventPersistence.class)
3368            protected UserNotificationEventPersistence userNotificationEventPersistence;
3369            @BeanReference(type = UserTrackerPersistence.class)
3370            protected UserTrackerPersistence userTrackerPersistence;
3371            @BeanReference(type = UserTrackerPathPersistence.class)
3372            protected UserTrackerPathPersistence userTrackerPathPersistence;
3373            @BeanReference(type = VirtualHostPersistence.class)
3374            protected VirtualHostPersistence virtualHostPersistence;
3375            @BeanReference(type = WebDAVPropsPersistence.class)
3376            protected WebDAVPropsPersistence webDAVPropsPersistence;
3377            @BeanReference(type = WebsitePersistence.class)
3378            protected WebsitePersistence websitePersistence;
3379            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
3380            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
3381            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
3382            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
3383            private static final String _SQL_SELECT_PHONE = "SELECT phone FROM Phone phone";
3384            private static final String _SQL_SELECT_PHONE_WHERE = "SELECT phone FROM Phone phone WHERE ";
3385            private static final String _SQL_COUNT_PHONE = "SELECT COUNT(phone) FROM Phone phone";
3386            private static final String _SQL_COUNT_PHONE_WHERE = "SELECT COUNT(phone) FROM Phone phone WHERE ";
3387            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "phone.companyId = ?";
3388            private static final String _FINDER_COLUMN_USERID_USERID_2 = "phone.userId = ?";
3389            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
3390            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "phone.classNameId = ?";
3391            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "phone.companyId = ? AND ";
3392            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
3393            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "phone.classPK = ?";
3394            private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "phone.companyId = ? AND ";
3395            private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "phone.classNameId = ? AND ";
3396            private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "phone.classPK = ? AND ";
3397            private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "phone.primary = ?";
3398            private static final String _ORDER_BY_ENTITY_ALIAS = "phone.";
3399            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Phone exists with the primary key ";
3400            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Phone exists with the key {";
3401            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3402            private static Log _log = LogFactoryUtil.getLog(PhonePersistenceImpl.class);
3403            private static Phone _nullPhone = new PhoneImpl() {
3404                            @Override
3405                            public Object clone() {
3406                                    return this;
3407                            }
3408    
3409                            @Override
3410                            public CacheModel<Phone> toCacheModel() {
3411                                    return _nullPhoneCacheModel;
3412                            }
3413                    };
3414    
3415            private static CacheModel<Phone> _nullPhoneCacheModel = new CacheModel<Phone>() {
3416                            public Phone toEntityModel() {
3417                                    return _nullPhone;
3418                            }
3419                    };
3420    }