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