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