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