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