001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchAddressException;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.SetUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.Validator;
034    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
035    import com.liferay.portal.model.Address;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.MVCCModel;
038    import com.liferay.portal.model.impl.AddressImpl;
039    import com.liferay.portal.model.impl.AddressModelImpl;
040    import com.liferay.portal.service.ServiceContext;
041    import com.liferay.portal.service.ServiceContextThreadLocal;
042    import com.liferay.portal.service.persistence.AddressPersistence;
043    
044    import java.io.Serializable;
045    
046    import java.util.Collections;
047    import java.util.Date;
048    import java.util.HashMap;
049    import java.util.HashSet;
050    import java.util.Iterator;
051    import java.util.List;
052    import java.util.Map;
053    import java.util.Set;
054    
055    /**
056     * The persistence implementation for the address service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see AddressPersistence
064     * @see com.liferay.portal.service.persistence.AddressUtil
065     * @generated
066     */
067    @ProviderType
068    public class AddressPersistenceImpl extends BasePersistenceImpl<Address>
069            implements AddressPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = AddressImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
081                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
084                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
087                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
090                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
092                            new String[] {
093                                    String.class.getName(),
094                                    
095                            Integer.class.getName(), Integer.class.getName(),
096                                    OrderByComparator.class.getName()
097                            });
098            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
099                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
101                            new String[] { String.class.getName() },
102                            AddressModelImpl.UUID_COLUMN_BITMASK |
103                            AddressModelImpl.CREATEDATE_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
105                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107                            new String[] { String.class.getName() });
108    
109            /**
110             * Returns all the addresses where uuid = &#63;.
111             *
112             * @param uuid the uuid
113             * @return the matching addresses
114             */
115            @Override
116            public List<Address> findByUuid(String uuid) {
117                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118            }
119    
120            /**
121             * Returns a range of all the addresses where uuid = &#63;.
122             *
123             * <p>
124             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
125             * </p>
126             *
127             * @param uuid the uuid
128             * @param start the lower bound of the range of addresses
129             * @param end the upper bound of the range of addresses (not inclusive)
130             * @return the range of matching addresses
131             */
132            @Override
133            public List<Address> findByUuid(String uuid, int start, int end) {
134                    return findByUuid(uuid, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the addresses where uuid = &#63;.
139             *
140             * <p>
141             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
142             * </p>
143             *
144             * @param uuid the uuid
145             * @param start the lower bound of the range of addresses
146             * @param end the upper bound of the range of addresses (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching addresses
149             */
150            @Override
151            public List<Address> findByUuid(String uuid, int start, int end,
152                    OrderByComparator<Address> orderByComparator) {
153                    boolean pagination = true;
154                    FinderPath finderPath = null;
155                    Object[] finderArgs = null;
156    
157                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158                                    (orderByComparator == null)) {
159                            pagination = false;
160                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
161                            finderArgs = new Object[] { uuid };
162                    }
163                    else {
164                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
165                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
166                    }
167    
168                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
169                                    finderArgs, this);
170    
171                    if ((list != null) && !list.isEmpty()) {
172                            for (Address address : list) {
173                                    if (!Validator.equals(uuid, address.getUuid())) {
174                                            list = null;
175    
176                                            break;
177                                    }
178                            }
179                    }
180    
181                    if (list == null) {
182                            StringBundler query = null;
183    
184                            if (orderByComparator != null) {
185                                    query = new StringBundler(3 +
186                                                    (orderByComparator.getOrderByFields().length * 3));
187                            }
188                            else {
189                                    query = new StringBundler(3);
190                            }
191    
192                            query.append(_SQL_SELECT_ADDRESS_WHERE);
193    
194                            boolean bindUuid = false;
195    
196                            if (uuid == null) {
197                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
198                            }
199                            else if (uuid.equals(StringPool.BLANK)) {
200                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
201                            }
202                            else {
203                                    bindUuid = true;
204    
205                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
206                            }
207    
208                            if (orderByComparator != null) {
209                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210                                            orderByComparator);
211                            }
212                            else
213                             if (pagination) {
214                                    query.append(AddressModelImpl.ORDER_BY_JPQL);
215                            }
216    
217                            String sql = query.toString();
218    
219                            Session session = null;
220    
221                            try {
222                                    session = openSession();
223    
224                                    Query q = session.createQuery(sql);
225    
226                                    QueryPos qPos = QueryPos.getInstance(q);
227    
228                                    if (bindUuid) {
229                                            qPos.add(uuid);
230                                    }
231    
232                                    if (!pagination) {
233                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
234                                                            start, end, false);
235    
236                                            Collections.sort(list);
237    
238                                            list = Collections.unmodifiableList(list);
239                                    }
240                                    else {
241                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
242                                                            start, end);
243                                    }
244    
245                                    cacheResult(list);
246    
247                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
248                            }
249                            catch (Exception e) {
250                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
251    
252                                    throw processException(e);
253                            }
254                            finally {
255                                    closeSession(session);
256                            }
257                    }
258    
259                    return list;
260            }
261    
262            /**
263             * Returns the first address in the ordered set where uuid = &#63;.
264             *
265             * @param uuid the uuid
266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
267             * @return the first matching address
268             * @throws NoSuchAddressException if a matching address could not be found
269             */
270            @Override
271            public Address findByUuid_First(String uuid,
272                    OrderByComparator<Address> orderByComparator)
273                    throws NoSuchAddressException {
274                    Address address = fetchByUuid_First(uuid, orderByComparator);
275    
276                    if (address != null) {
277                            return address;
278                    }
279    
280                    StringBundler msg = new StringBundler(4);
281    
282                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283    
284                    msg.append("uuid=");
285                    msg.append(uuid);
286    
287                    msg.append(StringPool.CLOSE_CURLY_BRACE);
288    
289                    throw new NoSuchAddressException(msg.toString());
290            }
291    
292            /**
293             * Returns the first address in the ordered set where uuid = &#63;.
294             *
295             * @param uuid the uuid
296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
297             * @return the first matching address, or <code>null</code> if a matching address could not be found
298             */
299            @Override
300            public Address fetchByUuid_First(String uuid,
301                    OrderByComparator<Address> orderByComparator) {
302                    List<Address> list = findByUuid(uuid, 0, 1, orderByComparator);
303    
304                    if (!list.isEmpty()) {
305                            return list.get(0);
306                    }
307    
308                    return null;
309            }
310    
311            /**
312             * Returns the last address in the ordered set where uuid = &#63;.
313             *
314             * @param uuid the uuid
315             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
316             * @return the last matching address
317             * @throws NoSuchAddressException if a matching address could not be found
318             */
319            @Override
320            public Address findByUuid_Last(String uuid,
321                    OrderByComparator<Address> orderByComparator)
322                    throws NoSuchAddressException {
323                    Address address = fetchByUuid_Last(uuid, orderByComparator);
324    
325                    if (address != null) {
326                            return address;
327                    }
328    
329                    StringBundler msg = new StringBundler(4);
330    
331                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
332    
333                    msg.append("uuid=");
334                    msg.append(uuid);
335    
336                    msg.append(StringPool.CLOSE_CURLY_BRACE);
337    
338                    throw new NoSuchAddressException(msg.toString());
339            }
340    
341            /**
342             * Returns the last address in the ordered set where uuid = &#63;.
343             *
344             * @param uuid the uuid
345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
346             * @return the last matching address, or <code>null</code> if a matching address could not be found
347             */
348            @Override
349            public Address fetchByUuid_Last(String uuid,
350                    OrderByComparator<Address> orderByComparator) {
351                    int count = countByUuid(uuid);
352    
353                    if (count == 0) {
354                            return null;
355                    }
356    
357                    List<Address> list = findByUuid(uuid, count - 1, count,
358                                    orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the addresses before and after the current address in the ordered set where uuid = &#63;.
369             *
370             * @param addressId the primary key of the current address
371             * @param uuid the uuid
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next address
374             * @throws NoSuchAddressException if a address with the primary key could not be found
375             */
376            @Override
377            public Address[] findByUuid_PrevAndNext(long addressId, String uuid,
378                    OrderByComparator<Address> orderByComparator)
379                    throws NoSuchAddressException {
380                    Address address = findByPrimaryKey(addressId);
381    
382                    Session session = null;
383    
384                    try {
385                            session = openSession();
386    
387                            Address[] array = new AddressImpl[3];
388    
389                            array[0] = getByUuid_PrevAndNext(session, address, uuid,
390                                            orderByComparator, true);
391    
392                            array[1] = address;
393    
394                            array[2] = getByUuid_PrevAndNext(session, address, uuid,
395                                            orderByComparator, false);
396    
397                            return array;
398                    }
399                    catch (Exception e) {
400                            throw processException(e);
401                    }
402                    finally {
403                            closeSession(session);
404                    }
405            }
406    
407            protected Address getByUuid_PrevAndNext(Session session, Address address,
408                    String uuid, OrderByComparator<Address> orderByComparator,
409                    boolean previous) {
410                    StringBundler query = null;
411    
412                    if (orderByComparator != null) {
413                            query = new StringBundler(6 +
414                                            (orderByComparator.getOrderByFields().length * 6));
415                    }
416                    else {
417                            query = new StringBundler(3);
418                    }
419    
420                    query.append(_SQL_SELECT_ADDRESS_WHERE);
421    
422                    boolean bindUuid = false;
423    
424                    if (uuid == null) {
425                            query.append(_FINDER_COLUMN_UUID_UUID_1);
426                    }
427                    else if (uuid.equals(StringPool.BLANK)) {
428                            query.append(_FINDER_COLUMN_UUID_UUID_3);
429                    }
430                    else {
431                            bindUuid = true;
432    
433                            query.append(_FINDER_COLUMN_UUID_UUID_2);
434                    }
435    
436                    if (orderByComparator != null) {
437                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438    
439                            if (orderByConditionFields.length > 0) {
440                                    query.append(WHERE_AND);
441                            }
442    
443                            for (int i = 0; i < orderByConditionFields.length; i++) {
444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
445                                    query.append(orderByConditionFields[i]);
446    
447                                    if ((i + 1) < orderByConditionFields.length) {
448                                            if (orderByComparator.isAscending() ^ previous) {
449                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
450                                            }
451                                            else {
452                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
453                                            }
454                                    }
455                                    else {
456                                            if (orderByComparator.isAscending() ^ previous) {
457                                                    query.append(WHERE_GREATER_THAN);
458                                            }
459                                            else {
460                                                    query.append(WHERE_LESSER_THAN);
461                                            }
462                                    }
463                            }
464    
465                            query.append(ORDER_BY_CLAUSE);
466    
467                            String[] orderByFields = orderByComparator.getOrderByFields();
468    
469                            for (int i = 0; i < orderByFields.length; i++) {
470                                    query.append(_ORDER_BY_ENTITY_ALIAS);
471                                    query.append(orderByFields[i]);
472    
473                                    if ((i + 1) < orderByFields.length) {
474                                            if (orderByComparator.isAscending() ^ previous) {
475                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
476                                            }
477                                            else {
478                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
479                                            }
480                                    }
481                                    else {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(ORDER_BY_ASC);
484                                            }
485                                            else {
486                                                    query.append(ORDER_BY_DESC);
487                                            }
488                                    }
489                            }
490                    }
491                    else {
492                            query.append(AddressModelImpl.ORDER_BY_JPQL);
493                    }
494    
495                    String sql = query.toString();
496    
497                    Query q = session.createQuery(sql);
498    
499                    q.setFirstResult(0);
500                    q.setMaxResults(2);
501    
502                    QueryPos qPos = QueryPos.getInstance(q);
503    
504                    if (bindUuid) {
505                            qPos.add(uuid);
506                    }
507    
508                    if (orderByComparator != null) {
509                            Object[] values = orderByComparator.getOrderByConditionValues(address);
510    
511                            for (Object value : values) {
512                                    qPos.add(value);
513                            }
514                    }
515    
516                    List<Address> list = q.list();
517    
518                    if (list.size() == 2) {
519                            return list.get(1);
520                    }
521                    else {
522                            return null;
523                    }
524            }
525    
526            /**
527             * Removes all the addresses where uuid = &#63; from the database.
528             *
529             * @param uuid the uuid
530             */
531            @Override
532            public void removeByUuid(String uuid) {
533                    for (Address address : findByUuid(uuid, QueryUtil.ALL_POS,
534                                    QueryUtil.ALL_POS, null)) {
535                            remove(address);
536                    }
537            }
538    
539            /**
540             * Returns the number of addresses where uuid = &#63;.
541             *
542             * @param uuid the uuid
543             * @return the number of matching addresses
544             */
545            @Override
546            public int countByUuid(String uuid) {
547                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
548    
549                    Object[] finderArgs = new Object[] { uuid };
550    
551                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
552                                    this);
553    
554                    if (count == null) {
555                            StringBundler query = new StringBundler(2);
556    
557                            query.append(_SQL_COUNT_ADDRESS_WHERE);
558    
559                            boolean bindUuid = false;
560    
561                            if (uuid == null) {
562                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
563                            }
564                            else if (uuid.equals(StringPool.BLANK)) {
565                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
566                            }
567                            else {
568                                    bindUuid = true;
569    
570                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
571                            }
572    
573                            String sql = query.toString();
574    
575                            Session session = null;
576    
577                            try {
578                                    session = openSession();
579    
580                                    Query q = session.createQuery(sql);
581    
582                                    QueryPos qPos = QueryPos.getInstance(q);
583    
584                                    if (bindUuid) {
585                                            qPos.add(uuid);
586                                    }
587    
588                                    count = (Long)q.uniqueResult();
589    
590                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
591                            }
592                            catch (Exception e) {
593                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
594    
595                                    throw processException(e);
596                            }
597                            finally {
598                                    closeSession(session);
599                            }
600                    }
601    
602                    return count.intValue();
603            }
604    
605            private static final String _FINDER_COLUMN_UUID_UUID_1 = "address.uuid IS NULL";
606            private static final String _FINDER_COLUMN_UUID_UUID_2 = "address.uuid = ?";
607            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(address.uuid IS NULL OR address.uuid = '')";
608            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
609                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
610                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
611                            new String[] {
612                                    String.class.getName(), Long.class.getName(),
613                                    
614                            Integer.class.getName(), Integer.class.getName(),
615                                    OrderByComparator.class.getName()
616                            });
617            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
618                    new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
619                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
620                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
621                            new String[] { String.class.getName(), Long.class.getName() },
622                            AddressModelImpl.UUID_COLUMN_BITMASK |
623                            AddressModelImpl.COMPANYID_COLUMN_BITMASK |
624                            AddressModelImpl.CREATEDATE_COLUMN_BITMASK);
625            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
626                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
627                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
628                            new String[] { String.class.getName(), Long.class.getName() });
629    
630            /**
631             * Returns all the addresses where uuid = &#63; and companyId = &#63;.
632             *
633             * @param uuid the uuid
634             * @param companyId the company ID
635             * @return the matching addresses
636             */
637            @Override
638            public List<Address> findByUuid_C(String uuid, long companyId) {
639                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
640                            QueryUtil.ALL_POS, null);
641            }
642    
643            /**
644             * Returns a range of all the addresses where uuid = &#63; and companyId = &#63;.
645             *
646             * <p>
647             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
648             * </p>
649             *
650             * @param uuid the uuid
651             * @param companyId the company ID
652             * @param start the lower bound of the range of addresses
653             * @param end the upper bound of the range of addresses (not inclusive)
654             * @return the range of matching addresses
655             */
656            @Override
657            public List<Address> findByUuid_C(String uuid, long companyId, int start,
658                    int end) {
659                    return findByUuid_C(uuid, companyId, start, end, null);
660            }
661    
662            /**
663             * Returns an ordered range of all the addresses where uuid = &#63; and companyId = &#63;.
664             *
665             * <p>
666             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
667             * </p>
668             *
669             * @param uuid the uuid
670             * @param companyId the company ID
671             * @param start the lower bound of the range of addresses
672             * @param end the upper bound of the range of addresses (not inclusive)
673             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
674             * @return the ordered range of matching addresses
675             */
676            @Override
677            public List<Address> findByUuid_C(String uuid, long companyId, int start,
678                    int end, OrderByComparator<Address> orderByComparator) {
679                    boolean pagination = true;
680                    FinderPath finderPath = null;
681                    Object[] finderArgs = null;
682    
683                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
684                                    (orderByComparator == null)) {
685                            pagination = false;
686                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
687                            finderArgs = new Object[] { uuid, companyId };
688                    }
689                    else {
690                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
691                            finderArgs = new Object[] {
692                                            uuid, companyId,
693                                            
694                                            start, end, orderByComparator
695                                    };
696                    }
697    
698                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
699                                    finderArgs, this);
700    
701                    if ((list != null) && !list.isEmpty()) {
702                            for (Address address : list) {
703                                    if (!Validator.equals(uuid, address.getUuid()) ||
704                                                    (companyId != address.getCompanyId())) {
705                                            list = null;
706    
707                                            break;
708                                    }
709                            }
710                    }
711    
712                    if (list == null) {
713                            StringBundler query = null;
714    
715                            if (orderByComparator != null) {
716                                    query = new StringBundler(4 +
717                                                    (orderByComparator.getOrderByFields().length * 3));
718                            }
719                            else {
720                                    query = new StringBundler(4);
721                            }
722    
723                            query.append(_SQL_SELECT_ADDRESS_WHERE);
724    
725                            boolean bindUuid = false;
726    
727                            if (uuid == null) {
728                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
729                            }
730                            else if (uuid.equals(StringPool.BLANK)) {
731                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
732                            }
733                            else {
734                                    bindUuid = true;
735    
736                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
737                            }
738    
739                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
740    
741                            if (orderByComparator != null) {
742                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
743                                            orderByComparator);
744                            }
745                            else
746                             if (pagination) {
747                                    query.append(AddressModelImpl.ORDER_BY_JPQL);
748                            }
749    
750                            String sql = query.toString();
751    
752                            Session session = null;
753    
754                            try {
755                                    session = openSession();
756    
757                                    Query q = session.createQuery(sql);
758    
759                                    QueryPos qPos = QueryPos.getInstance(q);
760    
761                                    if (bindUuid) {
762                                            qPos.add(uuid);
763                                    }
764    
765                                    qPos.add(companyId);
766    
767                                    if (!pagination) {
768                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
769                                                            start, end, false);
770    
771                                            Collections.sort(list);
772    
773                                            list = Collections.unmodifiableList(list);
774                                    }
775                                    else {
776                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
777                                                            start, end);
778                                    }
779    
780                                    cacheResult(list);
781    
782                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
783                            }
784                            catch (Exception e) {
785                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
786    
787                                    throw processException(e);
788                            }
789                            finally {
790                                    closeSession(session);
791                            }
792                    }
793    
794                    return list;
795            }
796    
797            /**
798             * Returns the first address in the ordered set where uuid = &#63; and companyId = &#63;.
799             *
800             * @param uuid the uuid
801             * @param companyId the company ID
802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
803             * @return the first matching address
804             * @throws NoSuchAddressException if a matching address could not be found
805             */
806            @Override
807            public Address findByUuid_C_First(String uuid, long companyId,
808                    OrderByComparator<Address> orderByComparator)
809                    throws NoSuchAddressException {
810                    Address address = fetchByUuid_C_First(uuid, companyId, orderByComparator);
811    
812                    if (address != null) {
813                            return address;
814                    }
815    
816                    StringBundler msg = new StringBundler(6);
817    
818                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
819    
820                    msg.append("uuid=");
821                    msg.append(uuid);
822    
823                    msg.append(", companyId=");
824                    msg.append(companyId);
825    
826                    msg.append(StringPool.CLOSE_CURLY_BRACE);
827    
828                    throw new NoSuchAddressException(msg.toString());
829            }
830    
831            /**
832             * Returns the first address in the ordered set where uuid = &#63; and companyId = &#63;.
833             *
834             * @param uuid the uuid
835             * @param companyId the company ID
836             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
837             * @return the first matching address, or <code>null</code> if a matching address could not be found
838             */
839            @Override
840            public Address fetchByUuid_C_First(String uuid, long companyId,
841                    OrderByComparator<Address> orderByComparator) {
842                    List<Address> list = findByUuid_C(uuid, companyId, 0, 1,
843                                    orderByComparator);
844    
845                    if (!list.isEmpty()) {
846                            return list.get(0);
847                    }
848    
849                    return null;
850            }
851    
852            /**
853             * Returns the last address in the ordered set where uuid = &#63; and companyId = &#63;.
854             *
855             * @param uuid the uuid
856             * @param companyId the company ID
857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
858             * @return the last matching address
859             * @throws NoSuchAddressException if a matching address could not be found
860             */
861            @Override
862            public Address findByUuid_C_Last(String uuid, long companyId,
863                    OrderByComparator<Address> orderByComparator)
864                    throws NoSuchAddressException {
865                    Address address = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
866    
867                    if (address != null) {
868                            return address;
869                    }
870    
871                    StringBundler msg = new StringBundler(6);
872    
873                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
874    
875                    msg.append("uuid=");
876                    msg.append(uuid);
877    
878                    msg.append(", companyId=");
879                    msg.append(companyId);
880    
881                    msg.append(StringPool.CLOSE_CURLY_BRACE);
882    
883                    throw new NoSuchAddressException(msg.toString());
884            }
885    
886            /**
887             * Returns the last address in the ordered set where uuid = &#63; and companyId = &#63;.
888             *
889             * @param uuid the uuid
890             * @param companyId the company ID
891             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
892             * @return the last matching address, or <code>null</code> if a matching address could not be found
893             */
894            @Override
895            public Address fetchByUuid_C_Last(String uuid, long companyId,
896                    OrderByComparator<Address> orderByComparator) {
897                    int count = countByUuid_C(uuid, companyId);
898    
899                    if (count == 0) {
900                            return null;
901                    }
902    
903                    List<Address> list = findByUuid_C(uuid, companyId, count - 1, count,
904                                    orderByComparator);
905    
906                    if (!list.isEmpty()) {
907                            return list.get(0);
908                    }
909    
910                    return null;
911            }
912    
913            /**
914             * Returns the addresses before and after the current address in the ordered set where uuid = &#63; and companyId = &#63;.
915             *
916             * @param addressId the primary key of the current address
917             * @param uuid the uuid
918             * @param companyId the company ID
919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
920             * @return the previous, current, and next address
921             * @throws NoSuchAddressException if a address with the primary key could not be found
922             */
923            @Override
924            public Address[] findByUuid_C_PrevAndNext(long addressId, String uuid,
925                    long companyId, OrderByComparator<Address> orderByComparator)
926                    throws NoSuchAddressException {
927                    Address address = findByPrimaryKey(addressId);
928    
929                    Session session = null;
930    
931                    try {
932                            session = openSession();
933    
934                            Address[] array = new AddressImpl[3];
935    
936                            array[0] = getByUuid_C_PrevAndNext(session, address, uuid,
937                                            companyId, orderByComparator, true);
938    
939                            array[1] = address;
940    
941                            array[2] = getByUuid_C_PrevAndNext(session, address, uuid,
942                                            companyId, orderByComparator, false);
943    
944                            return array;
945                    }
946                    catch (Exception e) {
947                            throw processException(e);
948                    }
949                    finally {
950                            closeSession(session);
951                    }
952            }
953    
954            protected Address getByUuid_C_PrevAndNext(Session session, Address address,
955                    String uuid, long companyId,
956                    OrderByComparator<Address> orderByComparator, boolean previous) {
957                    StringBundler query = null;
958    
959                    if (orderByComparator != null) {
960                            query = new StringBundler(6 +
961                                            (orderByComparator.getOrderByFields().length * 6));
962                    }
963                    else {
964                            query = new StringBundler(3);
965                    }
966    
967                    query.append(_SQL_SELECT_ADDRESS_WHERE);
968    
969                    boolean bindUuid = false;
970    
971                    if (uuid == null) {
972                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
973                    }
974                    else if (uuid.equals(StringPool.BLANK)) {
975                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
976                    }
977                    else {
978                            bindUuid = true;
979    
980                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
981                    }
982    
983                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
984    
985                    if (orderByComparator != null) {
986                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
987    
988                            if (orderByConditionFields.length > 0) {
989                                    query.append(WHERE_AND);
990                            }
991    
992                            for (int i = 0; i < orderByConditionFields.length; i++) {
993                                    query.append(_ORDER_BY_ENTITY_ALIAS);
994                                    query.append(orderByConditionFields[i]);
995    
996                                    if ((i + 1) < orderByConditionFields.length) {
997                                            if (orderByComparator.isAscending() ^ previous) {
998                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
999                                            }
1000                                            else {
1001                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1002                                            }
1003                                    }
1004                                    else {
1005                                            if (orderByComparator.isAscending() ^ previous) {
1006                                                    query.append(WHERE_GREATER_THAN);
1007                                            }
1008                                            else {
1009                                                    query.append(WHERE_LESSER_THAN);
1010                                            }
1011                                    }
1012                            }
1013    
1014                            query.append(ORDER_BY_CLAUSE);
1015    
1016                            String[] orderByFields = orderByComparator.getOrderByFields();
1017    
1018                            for (int i = 0; i < orderByFields.length; i++) {
1019                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1020                                    query.append(orderByFields[i]);
1021    
1022                                    if ((i + 1) < orderByFields.length) {
1023                                            if (orderByComparator.isAscending() ^ previous) {
1024                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1025                                            }
1026                                            else {
1027                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1028                                            }
1029                                    }
1030                                    else {
1031                                            if (orderByComparator.isAscending() ^ previous) {
1032                                                    query.append(ORDER_BY_ASC);
1033                                            }
1034                                            else {
1035                                                    query.append(ORDER_BY_DESC);
1036                                            }
1037                                    }
1038                            }
1039                    }
1040                    else {
1041                            query.append(AddressModelImpl.ORDER_BY_JPQL);
1042                    }
1043    
1044                    String sql = query.toString();
1045    
1046                    Query q = session.createQuery(sql);
1047    
1048                    q.setFirstResult(0);
1049                    q.setMaxResults(2);
1050    
1051                    QueryPos qPos = QueryPos.getInstance(q);
1052    
1053                    if (bindUuid) {
1054                            qPos.add(uuid);
1055                    }
1056    
1057                    qPos.add(companyId);
1058    
1059                    if (orderByComparator != null) {
1060                            Object[] values = orderByComparator.getOrderByConditionValues(address);
1061    
1062                            for (Object value : values) {
1063                                    qPos.add(value);
1064                            }
1065                    }
1066    
1067                    List<Address> list = q.list();
1068    
1069                    if (list.size() == 2) {
1070                            return list.get(1);
1071                    }
1072                    else {
1073                            return null;
1074                    }
1075            }
1076    
1077            /**
1078             * Removes all the addresses where uuid = &#63; and companyId = &#63; from the database.
1079             *
1080             * @param uuid the uuid
1081             * @param companyId the company ID
1082             */
1083            @Override
1084            public void removeByUuid_C(String uuid, long companyId) {
1085                    for (Address address : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1086                                    QueryUtil.ALL_POS, null)) {
1087                            remove(address);
1088                    }
1089            }
1090    
1091            /**
1092             * Returns the number of addresses where uuid = &#63; and companyId = &#63;.
1093             *
1094             * @param uuid the uuid
1095             * @param companyId the company ID
1096             * @return the number of matching addresses
1097             */
1098            @Override
1099            public int countByUuid_C(String uuid, long companyId) {
1100                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1101    
1102                    Object[] finderArgs = new Object[] { uuid, companyId };
1103    
1104                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1105                                    this);
1106    
1107                    if (count == null) {
1108                            StringBundler query = new StringBundler(3);
1109    
1110                            query.append(_SQL_COUNT_ADDRESS_WHERE);
1111    
1112                            boolean bindUuid = false;
1113    
1114                            if (uuid == null) {
1115                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1116                            }
1117                            else if (uuid.equals(StringPool.BLANK)) {
1118                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1119                            }
1120                            else {
1121                                    bindUuid = true;
1122    
1123                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1124                            }
1125    
1126                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1127    
1128                            String sql = query.toString();
1129    
1130                            Session session = null;
1131    
1132                            try {
1133                                    session = openSession();
1134    
1135                                    Query q = session.createQuery(sql);
1136    
1137                                    QueryPos qPos = QueryPos.getInstance(q);
1138    
1139                                    if (bindUuid) {
1140                                            qPos.add(uuid);
1141                                    }
1142    
1143                                    qPos.add(companyId);
1144    
1145                                    count = (Long)q.uniqueResult();
1146    
1147                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1148                            }
1149                            catch (Exception e) {
1150                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1151    
1152                                    throw processException(e);
1153                            }
1154                            finally {
1155                                    closeSession(session);
1156                            }
1157                    }
1158    
1159                    return count.intValue();
1160            }
1161    
1162            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "address.uuid IS NULL AND ";
1163            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "address.uuid = ? AND ";
1164            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(address.uuid IS NULL OR address.uuid = '') AND ";
1165            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "address.companyId = ?";
1166            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1167                    new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
1168                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
1169                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1170                            new String[] {
1171                                    Long.class.getName(),
1172                                    
1173                            Integer.class.getName(), Integer.class.getName(),
1174                                    OrderByComparator.class.getName()
1175                            });
1176            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1177                    new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
1178                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
1179                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1180                            new String[] { Long.class.getName() },
1181                            AddressModelImpl.COMPANYID_COLUMN_BITMASK |
1182                            AddressModelImpl.CREATEDATE_COLUMN_BITMASK);
1183            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
1184                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
1185                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1186                            new String[] { Long.class.getName() });
1187    
1188            /**
1189             * Returns all the addresses where companyId = &#63;.
1190             *
1191             * @param companyId the company ID
1192             * @return the matching addresses
1193             */
1194            @Override
1195            public List<Address> findByCompanyId(long companyId) {
1196                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1197                            null);
1198            }
1199    
1200            /**
1201             * Returns a range of all the addresses where companyId = &#63;.
1202             *
1203             * <p>
1204             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1205             * </p>
1206             *
1207             * @param companyId the company ID
1208             * @param start the lower bound of the range of addresses
1209             * @param end the upper bound of the range of addresses (not inclusive)
1210             * @return the range of matching addresses
1211             */
1212            @Override
1213            public List<Address> findByCompanyId(long companyId, int start, int end) {
1214                    return findByCompanyId(companyId, start, end, null);
1215            }
1216    
1217            /**
1218             * Returns an ordered range of all the addresses where companyId = &#63;.
1219             *
1220             * <p>
1221             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1222             * </p>
1223             *
1224             * @param companyId the company ID
1225             * @param start the lower bound of the range of addresses
1226             * @param end the upper bound of the range of addresses (not inclusive)
1227             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1228             * @return the ordered range of matching addresses
1229             */
1230            @Override
1231            public List<Address> findByCompanyId(long companyId, int start, int end,
1232                    OrderByComparator<Address> orderByComparator) {
1233                    boolean pagination = true;
1234                    FinderPath finderPath = null;
1235                    Object[] finderArgs = null;
1236    
1237                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1238                                    (orderByComparator == null)) {
1239                            pagination = false;
1240                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1241                            finderArgs = new Object[] { companyId };
1242                    }
1243                    else {
1244                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1245                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1246                    }
1247    
1248                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
1249                                    finderArgs, this);
1250    
1251                    if ((list != null) && !list.isEmpty()) {
1252                            for (Address address : list) {
1253                                    if ((companyId != address.getCompanyId())) {
1254                                            list = null;
1255    
1256                                            break;
1257                                    }
1258                            }
1259                    }
1260    
1261                    if (list == null) {
1262                            StringBundler query = null;
1263    
1264                            if (orderByComparator != null) {
1265                                    query = new StringBundler(3 +
1266                                                    (orderByComparator.getOrderByFields().length * 3));
1267                            }
1268                            else {
1269                                    query = new StringBundler(3);
1270                            }
1271    
1272                            query.append(_SQL_SELECT_ADDRESS_WHERE);
1273    
1274                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1275    
1276                            if (orderByComparator != null) {
1277                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1278                                            orderByComparator);
1279                            }
1280                            else
1281                             if (pagination) {
1282                                    query.append(AddressModelImpl.ORDER_BY_JPQL);
1283                            }
1284    
1285                            String sql = query.toString();
1286    
1287                            Session session = null;
1288    
1289                            try {
1290                                    session = openSession();
1291    
1292                                    Query q = session.createQuery(sql);
1293    
1294                                    QueryPos qPos = QueryPos.getInstance(q);
1295    
1296                                    qPos.add(companyId);
1297    
1298                                    if (!pagination) {
1299                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
1300                                                            start, end, false);
1301    
1302                                            Collections.sort(list);
1303    
1304                                            list = Collections.unmodifiableList(list);
1305                                    }
1306                                    else {
1307                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
1308                                                            start, end);
1309                                    }
1310    
1311                                    cacheResult(list);
1312    
1313                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1314                            }
1315                            catch (Exception e) {
1316                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1317    
1318                                    throw processException(e);
1319                            }
1320                            finally {
1321                                    closeSession(session);
1322                            }
1323                    }
1324    
1325                    return list;
1326            }
1327    
1328            /**
1329             * Returns the first address in the ordered set where companyId = &#63;.
1330             *
1331             * @param companyId the company ID
1332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1333             * @return the first matching address
1334             * @throws NoSuchAddressException if a matching address could not be found
1335             */
1336            @Override
1337            public Address findByCompanyId_First(long companyId,
1338                    OrderByComparator<Address> orderByComparator)
1339                    throws NoSuchAddressException {
1340                    Address address = fetchByCompanyId_First(companyId, orderByComparator);
1341    
1342                    if (address != null) {
1343                            return address;
1344                    }
1345    
1346                    StringBundler msg = new StringBundler(4);
1347    
1348                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1349    
1350                    msg.append("companyId=");
1351                    msg.append(companyId);
1352    
1353                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1354    
1355                    throw new NoSuchAddressException(msg.toString());
1356            }
1357    
1358            /**
1359             * Returns the first address in the ordered set where companyId = &#63;.
1360             *
1361             * @param companyId the company ID
1362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1363             * @return the first matching address, or <code>null</code> if a matching address could not be found
1364             */
1365            @Override
1366            public Address fetchByCompanyId_First(long companyId,
1367                    OrderByComparator<Address> orderByComparator) {
1368                    List<Address> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1369    
1370                    if (!list.isEmpty()) {
1371                            return list.get(0);
1372                    }
1373    
1374                    return null;
1375            }
1376    
1377            /**
1378             * Returns the last address in the ordered set where companyId = &#63;.
1379             *
1380             * @param companyId the company ID
1381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1382             * @return the last matching address
1383             * @throws NoSuchAddressException if a matching address could not be found
1384             */
1385            @Override
1386            public Address findByCompanyId_Last(long companyId,
1387                    OrderByComparator<Address> orderByComparator)
1388                    throws NoSuchAddressException {
1389                    Address address = fetchByCompanyId_Last(companyId, orderByComparator);
1390    
1391                    if (address != null) {
1392                            return address;
1393                    }
1394    
1395                    StringBundler msg = new StringBundler(4);
1396    
1397                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1398    
1399                    msg.append("companyId=");
1400                    msg.append(companyId);
1401    
1402                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1403    
1404                    throw new NoSuchAddressException(msg.toString());
1405            }
1406    
1407            /**
1408             * Returns the last address in the ordered set where companyId = &#63;.
1409             *
1410             * @param companyId the company ID
1411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1412             * @return the last matching address, or <code>null</code> if a matching address could not be found
1413             */
1414            @Override
1415            public Address fetchByCompanyId_Last(long companyId,
1416                    OrderByComparator<Address> orderByComparator) {
1417                    int count = countByCompanyId(companyId);
1418    
1419                    if (count == 0) {
1420                            return null;
1421                    }
1422    
1423                    List<Address> list = findByCompanyId(companyId, count - 1, count,
1424                                    orderByComparator);
1425    
1426                    if (!list.isEmpty()) {
1427                            return list.get(0);
1428                    }
1429    
1430                    return null;
1431            }
1432    
1433            /**
1434             * Returns the addresses before and after the current address in the ordered set where companyId = &#63;.
1435             *
1436             * @param addressId the primary key of the current address
1437             * @param companyId the company ID
1438             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1439             * @return the previous, current, and next address
1440             * @throws NoSuchAddressException if a address with the primary key could not be found
1441             */
1442            @Override
1443            public Address[] findByCompanyId_PrevAndNext(long addressId,
1444                    long companyId, OrderByComparator<Address> orderByComparator)
1445                    throws NoSuchAddressException {
1446                    Address address = findByPrimaryKey(addressId);
1447    
1448                    Session session = null;
1449    
1450                    try {
1451                            session = openSession();
1452    
1453                            Address[] array = new AddressImpl[3];
1454    
1455                            array[0] = getByCompanyId_PrevAndNext(session, address, companyId,
1456                                            orderByComparator, true);
1457    
1458                            array[1] = address;
1459    
1460                            array[2] = getByCompanyId_PrevAndNext(session, address, companyId,
1461                                            orderByComparator, false);
1462    
1463                            return array;
1464                    }
1465                    catch (Exception e) {
1466                            throw processException(e);
1467                    }
1468                    finally {
1469                            closeSession(session);
1470                    }
1471            }
1472    
1473            protected Address getByCompanyId_PrevAndNext(Session session,
1474                    Address address, long companyId,
1475                    OrderByComparator<Address> orderByComparator, boolean previous) {
1476                    StringBundler query = null;
1477    
1478                    if (orderByComparator != null) {
1479                            query = new StringBundler(6 +
1480                                            (orderByComparator.getOrderByFields().length * 6));
1481                    }
1482                    else {
1483                            query = new StringBundler(3);
1484                    }
1485    
1486                    query.append(_SQL_SELECT_ADDRESS_WHERE);
1487    
1488                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1489    
1490                    if (orderByComparator != null) {
1491                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1492    
1493                            if (orderByConditionFields.length > 0) {
1494                                    query.append(WHERE_AND);
1495                            }
1496    
1497                            for (int i = 0; i < orderByConditionFields.length; i++) {
1498                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1499                                    query.append(orderByConditionFields[i]);
1500    
1501                                    if ((i + 1) < orderByConditionFields.length) {
1502                                            if (orderByComparator.isAscending() ^ previous) {
1503                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1504                                            }
1505                                            else {
1506                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1507                                            }
1508                                    }
1509                                    else {
1510                                            if (orderByComparator.isAscending() ^ previous) {
1511                                                    query.append(WHERE_GREATER_THAN);
1512                                            }
1513                                            else {
1514                                                    query.append(WHERE_LESSER_THAN);
1515                                            }
1516                                    }
1517                            }
1518    
1519                            query.append(ORDER_BY_CLAUSE);
1520    
1521                            String[] orderByFields = orderByComparator.getOrderByFields();
1522    
1523                            for (int i = 0; i < orderByFields.length; i++) {
1524                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1525                                    query.append(orderByFields[i]);
1526    
1527                                    if ((i + 1) < orderByFields.length) {
1528                                            if (orderByComparator.isAscending() ^ previous) {
1529                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1530                                            }
1531                                            else {
1532                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1533                                            }
1534                                    }
1535                                    else {
1536                                            if (orderByComparator.isAscending() ^ previous) {
1537                                                    query.append(ORDER_BY_ASC);
1538                                            }
1539                                            else {
1540                                                    query.append(ORDER_BY_DESC);
1541                                            }
1542                                    }
1543                            }
1544                    }
1545                    else {
1546                            query.append(AddressModelImpl.ORDER_BY_JPQL);
1547                    }
1548    
1549                    String sql = query.toString();
1550    
1551                    Query q = session.createQuery(sql);
1552    
1553                    q.setFirstResult(0);
1554                    q.setMaxResults(2);
1555    
1556                    QueryPos qPos = QueryPos.getInstance(q);
1557    
1558                    qPos.add(companyId);
1559    
1560                    if (orderByComparator != null) {
1561                            Object[] values = orderByComparator.getOrderByConditionValues(address);
1562    
1563                            for (Object value : values) {
1564                                    qPos.add(value);
1565                            }
1566                    }
1567    
1568                    List<Address> list = q.list();
1569    
1570                    if (list.size() == 2) {
1571                            return list.get(1);
1572                    }
1573                    else {
1574                            return null;
1575                    }
1576            }
1577    
1578            /**
1579             * Removes all the addresses where companyId = &#63; from the database.
1580             *
1581             * @param companyId the company ID
1582             */
1583            @Override
1584            public void removeByCompanyId(long companyId) {
1585                    for (Address address : findByCompanyId(companyId, QueryUtil.ALL_POS,
1586                                    QueryUtil.ALL_POS, null)) {
1587                            remove(address);
1588                    }
1589            }
1590    
1591            /**
1592             * Returns the number of addresses where companyId = &#63;.
1593             *
1594             * @param companyId the company ID
1595             * @return the number of matching addresses
1596             */
1597            @Override
1598            public int countByCompanyId(long companyId) {
1599                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1600    
1601                    Object[] finderArgs = new Object[] { companyId };
1602    
1603                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1604                                    this);
1605    
1606                    if (count == null) {
1607                            StringBundler query = new StringBundler(2);
1608    
1609                            query.append(_SQL_COUNT_ADDRESS_WHERE);
1610    
1611                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1612    
1613                            String sql = query.toString();
1614    
1615                            Session session = null;
1616    
1617                            try {
1618                                    session = openSession();
1619    
1620                                    Query q = session.createQuery(sql);
1621    
1622                                    QueryPos qPos = QueryPos.getInstance(q);
1623    
1624                                    qPos.add(companyId);
1625    
1626                                    count = (Long)q.uniqueResult();
1627    
1628                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1629                            }
1630                            catch (Exception e) {
1631                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1632    
1633                                    throw processException(e);
1634                            }
1635                            finally {
1636                                    closeSession(session);
1637                            }
1638                    }
1639    
1640                    return count.intValue();
1641            }
1642    
1643            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "address.companyId = ?";
1644            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
1645                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
1646                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1647                            new String[] {
1648                                    Long.class.getName(),
1649                                    
1650                            Integer.class.getName(), Integer.class.getName(),
1651                                    OrderByComparator.class.getName()
1652                            });
1653            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1654                    new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
1655                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
1656                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1657                            new String[] { Long.class.getName() },
1658                            AddressModelImpl.USERID_COLUMN_BITMASK |
1659                            AddressModelImpl.CREATEDATE_COLUMN_BITMASK);
1660            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
1661                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
1662                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1663                            new String[] { Long.class.getName() });
1664    
1665            /**
1666             * Returns all the addresses where userId = &#63;.
1667             *
1668             * @param userId the user ID
1669             * @return the matching addresses
1670             */
1671            @Override
1672            public List<Address> findByUserId(long userId) {
1673                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1674            }
1675    
1676            /**
1677             * Returns a range of all the addresses where userId = &#63;.
1678             *
1679             * <p>
1680             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1681             * </p>
1682             *
1683             * @param userId the user ID
1684             * @param start the lower bound of the range of addresses
1685             * @param end the upper bound of the range of addresses (not inclusive)
1686             * @return the range of matching addresses
1687             */
1688            @Override
1689            public List<Address> findByUserId(long userId, int start, int end) {
1690                    return findByUserId(userId, start, end, null);
1691            }
1692    
1693            /**
1694             * Returns an ordered range of all the addresses where userId = &#63;.
1695             *
1696             * <p>
1697             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1698             * </p>
1699             *
1700             * @param userId the user ID
1701             * @param start the lower bound of the range of addresses
1702             * @param end the upper bound of the range of addresses (not inclusive)
1703             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1704             * @return the ordered range of matching addresses
1705             */
1706            @Override
1707            public List<Address> findByUserId(long userId, int start, int end,
1708                    OrderByComparator<Address> orderByComparator) {
1709                    boolean pagination = true;
1710                    FinderPath finderPath = null;
1711                    Object[] finderArgs = null;
1712    
1713                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1714                                    (orderByComparator == null)) {
1715                            pagination = false;
1716                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1717                            finderArgs = new Object[] { userId };
1718                    }
1719                    else {
1720                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1721                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1722                    }
1723    
1724                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
1725                                    finderArgs, this);
1726    
1727                    if ((list != null) && !list.isEmpty()) {
1728                            for (Address address : list) {
1729                                    if ((userId != address.getUserId())) {
1730                                            list = null;
1731    
1732                                            break;
1733                                    }
1734                            }
1735                    }
1736    
1737                    if (list == null) {
1738                            StringBundler query = null;
1739    
1740                            if (orderByComparator != null) {
1741                                    query = new StringBundler(3 +
1742                                                    (orderByComparator.getOrderByFields().length * 3));
1743                            }
1744                            else {
1745                                    query = new StringBundler(3);
1746                            }
1747    
1748                            query.append(_SQL_SELECT_ADDRESS_WHERE);
1749    
1750                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1751    
1752                            if (orderByComparator != null) {
1753                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1754                                            orderByComparator);
1755                            }
1756                            else
1757                             if (pagination) {
1758                                    query.append(AddressModelImpl.ORDER_BY_JPQL);
1759                            }
1760    
1761                            String sql = query.toString();
1762    
1763                            Session session = null;
1764    
1765                            try {
1766                                    session = openSession();
1767    
1768                                    Query q = session.createQuery(sql);
1769    
1770                                    QueryPos qPos = QueryPos.getInstance(q);
1771    
1772                                    qPos.add(userId);
1773    
1774                                    if (!pagination) {
1775                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
1776                                                            start, end, false);
1777    
1778                                            Collections.sort(list);
1779    
1780                                            list = Collections.unmodifiableList(list);
1781                                    }
1782                                    else {
1783                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
1784                                                            start, end);
1785                                    }
1786    
1787                                    cacheResult(list);
1788    
1789                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1790                            }
1791                            catch (Exception e) {
1792                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1793    
1794                                    throw processException(e);
1795                            }
1796                            finally {
1797                                    closeSession(session);
1798                            }
1799                    }
1800    
1801                    return list;
1802            }
1803    
1804            /**
1805             * Returns the first address in the ordered set where userId = &#63;.
1806             *
1807             * @param userId the user ID
1808             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1809             * @return the first matching address
1810             * @throws NoSuchAddressException if a matching address could not be found
1811             */
1812            @Override
1813            public Address findByUserId_First(long userId,
1814                    OrderByComparator<Address> orderByComparator)
1815                    throws NoSuchAddressException {
1816                    Address address = fetchByUserId_First(userId, orderByComparator);
1817    
1818                    if (address != null) {
1819                            return address;
1820                    }
1821    
1822                    StringBundler msg = new StringBundler(4);
1823    
1824                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1825    
1826                    msg.append("userId=");
1827                    msg.append(userId);
1828    
1829                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1830    
1831                    throw new NoSuchAddressException(msg.toString());
1832            }
1833    
1834            /**
1835             * Returns the first address in the ordered set where userId = &#63;.
1836             *
1837             * @param userId the user ID
1838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1839             * @return the first matching address, or <code>null</code> if a matching address could not be found
1840             */
1841            @Override
1842            public Address fetchByUserId_First(long userId,
1843                    OrderByComparator<Address> orderByComparator) {
1844                    List<Address> list = findByUserId(userId, 0, 1, orderByComparator);
1845    
1846                    if (!list.isEmpty()) {
1847                            return list.get(0);
1848                    }
1849    
1850                    return null;
1851            }
1852    
1853            /**
1854             * Returns the last address in the ordered set where userId = &#63;.
1855             *
1856             * @param userId the user ID
1857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1858             * @return the last matching address
1859             * @throws NoSuchAddressException if a matching address could not be found
1860             */
1861            @Override
1862            public Address findByUserId_Last(long userId,
1863                    OrderByComparator<Address> orderByComparator)
1864                    throws NoSuchAddressException {
1865                    Address address = fetchByUserId_Last(userId, orderByComparator);
1866    
1867                    if (address != null) {
1868                            return address;
1869                    }
1870    
1871                    StringBundler msg = new StringBundler(4);
1872    
1873                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1874    
1875                    msg.append("userId=");
1876                    msg.append(userId);
1877    
1878                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1879    
1880                    throw new NoSuchAddressException(msg.toString());
1881            }
1882    
1883            /**
1884             * Returns the last address in the ordered set where userId = &#63;.
1885             *
1886             * @param userId the user ID
1887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1888             * @return the last matching address, or <code>null</code> if a matching address could not be found
1889             */
1890            @Override
1891            public Address fetchByUserId_Last(long userId,
1892                    OrderByComparator<Address> orderByComparator) {
1893                    int count = countByUserId(userId);
1894    
1895                    if (count == 0) {
1896                            return null;
1897                    }
1898    
1899                    List<Address> list = findByUserId(userId, count - 1, count,
1900                                    orderByComparator);
1901    
1902                    if (!list.isEmpty()) {
1903                            return list.get(0);
1904                    }
1905    
1906                    return null;
1907            }
1908    
1909            /**
1910             * Returns the addresses before and after the current address in the ordered set where userId = &#63;.
1911             *
1912             * @param addressId the primary key of the current address
1913             * @param userId the user ID
1914             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1915             * @return the previous, current, and next address
1916             * @throws NoSuchAddressException if a address with the primary key could not be found
1917             */
1918            @Override
1919            public Address[] findByUserId_PrevAndNext(long addressId, long userId,
1920                    OrderByComparator<Address> orderByComparator)
1921                    throws NoSuchAddressException {
1922                    Address address = findByPrimaryKey(addressId);
1923    
1924                    Session session = null;
1925    
1926                    try {
1927                            session = openSession();
1928    
1929                            Address[] array = new AddressImpl[3];
1930    
1931                            array[0] = getByUserId_PrevAndNext(session, address, userId,
1932                                            orderByComparator, true);
1933    
1934                            array[1] = address;
1935    
1936                            array[2] = getByUserId_PrevAndNext(session, address, userId,
1937                                            orderByComparator, false);
1938    
1939                            return array;
1940                    }
1941                    catch (Exception e) {
1942                            throw processException(e);
1943                    }
1944                    finally {
1945                            closeSession(session);
1946                    }
1947            }
1948    
1949            protected Address getByUserId_PrevAndNext(Session session, Address address,
1950                    long userId, OrderByComparator<Address> orderByComparator,
1951                    boolean previous) {
1952                    StringBundler query = null;
1953    
1954                    if (orderByComparator != null) {
1955                            query = new StringBundler(6 +
1956                                            (orderByComparator.getOrderByFields().length * 6));
1957                    }
1958                    else {
1959                            query = new StringBundler(3);
1960                    }
1961    
1962                    query.append(_SQL_SELECT_ADDRESS_WHERE);
1963    
1964                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1965    
1966                    if (orderByComparator != null) {
1967                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1968    
1969                            if (orderByConditionFields.length > 0) {
1970                                    query.append(WHERE_AND);
1971                            }
1972    
1973                            for (int i = 0; i < orderByConditionFields.length; i++) {
1974                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1975                                    query.append(orderByConditionFields[i]);
1976    
1977                                    if ((i + 1) < orderByConditionFields.length) {
1978                                            if (orderByComparator.isAscending() ^ previous) {
1979                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1980                                            }
1981                                            else {
1982                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1983                                            }
1984                                    }
1985                                    else {
1986                                            if (orderByComparator.isAscending() ^ previous) {
1987                                                    query.append(WHERE_GREATER_THAN);
1988                                            }
1989                                            else {
1990                                                    query.append(WHERE_LESSER_THAN);
1991                                            }
1992                                    }
1993                            }
1994    
1995                            query.append(ORDER_BY_CLAUSE);
1996    
1997                            String[] orderByFields = orderByComparator.getOrderByFields();
1998    
1999                            for (int i = 0; i < orderByFields.length; i++) {
2000                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2001                                    query.append(orderByFields[i]);
2002    
2003                                    if ((i + 1) < orderByFields.length) {
2004                                            if (orderByComparator.isAscending() ^ previous) {
2005                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2006                                            }
2007                                            else {
2008                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2009                                            }
2010                                    }
2011                                    else {
2012                                            if (orderByComparator.isAscending() ^ previous) {
2013                                                    query.append(ORDER_BY_ASC);
2014                                            }
2015                                            else {
2016                                                    query.append(ORDER_BY_DESC);
2017                                            }
2018                                    }
2019                            }
2020                    }
2021                    else {
2022                            query.append(AddressModelImpl.ORDER_BY_JPQL);
2023                    }
2024    
2025                    String sql = query.toString();
2026    
2027                    Query q = session.createQuery(sql);
2028    
2029                    q.setFirstResult(0);
2030                    q.setMaxResults(2);
2031    
2032                    QueryPos qPos = QueryPos.getInstance(q);
2033    
2034                    qPos.add(userId);
2035    
2036                    if (orderByComparator != null) {
2037                            Object[] values = orderByComparator.getOrderByConditionValues(address);
2038    
2039                            for (Object value : values) {
2040                                    qPos.add(value);
2041                            }
2042                    }
2043    
2044                    List<Address> list = q.list();
2045    
2046                    if (list.size() == 2) {
2047                            return list.get(1);
2048                    }
2049                    else {
2050                            return null;
2051                    }
2052            }
2053    
2054            /**
2055             * Removes all the addresses where userId = &#63; from the database.
2056             *
2057             * @param userId the user ID
2058             */
2059            @Override
2060            public void removeByUserId(long userId) {
2061                    for (Address address : findByUserId(userId, QueryUtil.ALL_POS,
2062                                    QueryUtil.ALL_POS, null)) {
2063                            remove(address);
2064                    }
2065            }
2066    
2067            /**
2068             * Returns the number of addresses where userId = &#63;.
2069             *
2070             * @param userId the user ID
2071             * @return the number of matching addresses
2072             */
2073            @Override
2074            public int countByUserId(long userId) {
2075                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2076    
2077                    Object[] finderArgs = new Object[] { userId };
2078    
2079                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2080                                    this);
2081    
2082                    if (count == null) {
2083                            StringBundler query = new StringBundler(2);
2084    
2085                            query.append(_SQL_COUNT_ADDRESS_WHERE);
2086    
2087                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2088    
2089                            String sql = query.toString();
2090    
2091                            Session session = null;
2092    
2093                            try {
2094                                    session = openSession();
2095    
2096                                    Query q = session.createQuery(sql);
2097    
2098                                    QueryPos qPos = QueryPos.getInstance(q);
2099    
2100                                    qPos.add(userId);
2101    
2102                                    count = (Long)q.uniqueResult();
2103    
2104                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2105                            }
2106                            catch (Exception e) {
2107                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2108    
2109                                    throw processException(e);
2110                            }
2111                            finally {
2112                                    closeSession(session);
2113                            }
2114                    }
2115    
2116                    return count.intValue();
2117            }
2118    
2119            private static final String _FINDER_COLUMN_USERID_USERID_2 = "address.userId = ?";
2120            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
2121                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
2122                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
2123                            new String[] {
2124                                    Long.class.getName(), Long.class.getName(),
2125                                    
2126                            Integer.class.getName(), Integer.class.getName(),
2127                                    OrderByComparator.class.getName()
2128                            });
2129            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
2130                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
2131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
2132                            new String[] { Long.class.getName(), Long.class.getName() },
2133                            AddressModelImpl.COMPANYID_COLUMN_BITMASK |
2134                            AddressModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2135                            AddressModelImpl.CREATEDATE_COLUMN_BITMASK);
2136            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
2137                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
2138                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2139                            new String[] { Long.class.getName(), Long.class.getName() });
2140    
2141            /**
2142             * Returns all the addresses where companyId = &#63; and classNameId = &#63;.
2143             *
2144             * @param companyId the company ID
2145             * @param classNameId the class name ID
2146             * @return the matching addresses
2147             */
2148            @Override
2149            public List<Address> findByC_C(long companyId, long classNameId) {
2150                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
2151                            QueryUtil.ALL_POS, null);
2152            }
2153    
2154            /**
2155             * Returns a range of all the addresses where companyId = &#63; and classNameId = &#63;.
2156             *
2157             * <p>
2158             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2159             * </p>
2160             *
2161             * @param companyId the company ID
2162             * @param classNameId the class name ID
2163             * @param start the lower bound of the range of addresses
2164             * @param end the upper bound of the range of addresses (not inclusive)
2165             * @return the range of matching addresses
2166             */
2167            @Override
2168            public List<Address> findByC_C(long companyId, long classNameId, int start,
2169                    int end) {
2170                    return findByC_C(companyId, classNameId, start, end, null);
2171            }
2172    
2173            /**
2174             * Returns an ordered range of all the addresses where companyId = &#63; and classNameId = &#63;.
2175             *
2176             * <p>
2177             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2178             * </p>
2179             *
2180             * @param companyId the company ID
2181             * @param classNameId the class name ID
2182             * @param start the lower bound of the range of addresses
2183             * @param end the upper bound of the range of addresses (not inclusive)
2184             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2185             * @return the ordered range of matching addresses
2186             */
2187            @Override
2188            public List<Address> findByC_C(long companyId, long classNameId, int start,
2189                    int end, OrderByComparator<Address> orderByComparator) {
2190                    boolean pagination = true;
2191                    FinderPath finderPath = null;
2192                    Object[] finderArgs = null;
2193    
2194                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2195                                    (orderByComparator == null)) {
2196                            pagination = false;
2197                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2198                            finderArgs = new Object[] { companyId, classNameId };
2199                    }
2200                    else {
2201                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2202                            finderArgs = new Object[] {
2203                                            companyId, classNameId,
2204                                            
2205                                            start, end, orderByComparator
2206                                    };
2207                    }
2208    
2209                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
2210                                    finderArgs, this);
2211    
2212                    if ((list != null) && !list.isEmpty()) {
2213                            for (Address address : list) {
2214                                    if ((companyId != address.getCompanyId()) ||
2215                                                    (classNameId != address.getClassNameId())) {
2216                                            list = null;
2217    
2218                                            break;
2219                                    }
2220                            }
2221                    }
2222    
2223                    if (list == null) {
2224                            StringBundler query = null;
2225    
2226                            if (orderByComparator != null) {
2227                                    query = new StringBundler(4 +
2228                                                    (orderByComparator.getOrderByFields().length * 3));
2229                            }
2230                            else {
2231                                    query = new StringBundler(4);
2232                            }
2233    
2234                            query.append(_SQL_SELECT_ADDRESS_WHERE);
2235    
2236                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2237    
2238                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2239    
2240                            if (orderByComparator != null) {
2241                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2242                                            orderByComparator);
2243                            }
2244                            else
2245                             if (pagination) {
2246                                    query.append(AddressModelImpl.ORDER_BY_JPQL);
2247                            }
2248    
2249                            String sql = query.toString();
2250    
2251                            Session session = null;
2252    
2253                            try {
2254                                    session = openSession();
2255    
2256                                    Query q = session.createQuery(sql);
2257    
2258                                    QueryPos qPos = QueryPos.getInstance(q);
2259    
2260                                    qPos.add(companyId);
2261    
2262                                    qPos.add(classNameId);
2263    
2264                                    if (!pagination) {
2265                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
2266                                                            start, end, false);
2267    
2268                                            Collections.sort(list);
2269    
2270                                            list = Collections.unmodifiableList(list);
2271                                    }
2272                                    else {
2273                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
2274                                                            start, end);
2275                                    }
2276    
2277                                    cacheResult(list);
2278    
2279                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2280                            }
2281                            catch (Exception e) {
2282                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2283    
2284                                    throw processException(e);
2285                            }
2286                            finally {
2287                                    closeSession(session);
2288                            }
2289                    }
2290    
2291                    return list;
2292            }
2293    
2294            /**
2295             * Returns the first address in the ordered set where companyId = &#63; and classNameId = &#63;.
2296             *
2297             * @param companyId the company ID
2298             * @param classNameId the class name ID
2299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2300             * @return the first matching address
2301             * @throws NoSuchAddressException if a matching address could not be found
2302             */
2303            @Override
2304            public Address findByC_C_First(long companyId, long classNameId,
2305                    OrderByComparator<Address> orderByComparator)
2306                    throws NoSuchAddressException {
2307                    Address address = fetchByC_C_First(companyId, classNameId,
2308                                    orderByComparator);
2309    
2310                    if (address != null) {
2311                            return address;
2312                    }
2313    
2314                    StringBundler msg = new StringBundler(6);
2315    
2316                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2317    
2318                    msg.append("companyId=");
2319                    msg.append(companyId);
2320    
2321                    msg.append(", classNameId=");
2322                    msg.append(classNameId);
2323    
2324                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2325    
2326                    throw new NoSuchAddressException(msg.toString());
2327            }
2328    
2329            /**
2330             * Returns the first address in the ordered set where companyId = &#63; and classNameId = &#63;.
2331             *
2332             * @param companyId the company ID
2333             * @param classNameId the class name ID
2334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2335             * @return the first matching address, or <code>null</code> if a matching address could not be found
2336             */
2337            @Override
2338            public Address fetchByC_C_First(long companyId, long classNameId,
2339                    OrderByComparator<Address> orderByComparator) {
2340                    List<Address> list = findByC_C(companyId, classNameId, 0, 1,
2341                                    orderByComparator);
2342    
2343                    if (!list.isEmpty()) {
2344                            return list.get(0);
2345                    }
2346    
2347                    return null;
2348            }
2349    
2350            /**
2351             * Returns the last address in the ordered set where companyId = &#63; and classNameId = &#63;.
2352             *
2353             * @param companyId the company ID
2354             * @param classNameId the class name ID
2355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2356             * @return the last matching address
2357             * @throws NoSuchAddressException if a matching address could not be found
2358             */
2359            @Override
2360            public Address findByC_C_Last(long companyId, long classNameId,
2361                    OrderByComparator<Address> orderByComparator)
2362                    throws NoSuchAddressException {
2363                    Address address = fetchByC_C_Last(companyId, classNameId,
2364                                    orderByComparator);
2365    
2366                    if (address != null) {
2367                            return address;
2368                    }
2369    
2370                    StringBundler msg = new StringBundler(6);
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(StringPool.CLOSE_CURLY_BRACE);
2381    
2382                    throw new NoSuchAddressException(msg.toString());
2383            }
2384    
2385            /**
2386             * Returns the last address in the ordered set where companyId = &#63; and classNameId = &#63;.
2387             *
2388             * @param companyId the company ID
2389             * @param classNameId the class name ID
2390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2391             * @return the last matching address, or <code>null</code> if a matching address could not be found
2392             */
2393            @Override
2394            public Address fetchByC_C_Last(long companyId, long classNameId,
2395                    OrderByComparator<Address> orderByComparator) {
2396                    int count = countByC_C(companyId, classNameId);
2397    
2398                    if (count == 0) {
2399                            return null;
2400                    }
2401    
2402                    List<Address> list = findByC_C(companyId, classNameId, count - 1,
2403                                    count, orderByComparator);
2404    
2405                    if (!list.isEmpty()) {
2406                            return list.get(0);
2407                    }
2408    
2409                    return null;
2410            }
2411    
2412            /**
2413             * Returns the addresses before and after the current address in the ordered set where companyId = &#63; and classNameId = &#63;.
2414             *
2415             * @param addressId the primary key of the current address
2416             * @param companyId the company ID
2417             * @param classNameId the class name ID
2418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2419             * @return the previous, current, and next address
2420             * @throws NoSuchAddressException if a address with the primary key could not be found
2421             */
2422            @Override
2423            public Address[] findByC_C_PrevAndNext(long addressId, long companyId,
2424                    long classNameId, OrderByComparator<Address> orderByComparator)
2425                    throws NoSuchAddressException {
2426                    Address address = findByPrimaryKey(addressId);
2427    
2428                    Session session = null;
2429    
2430                    try {
2431                            session = openSession();
2432    
2433                            Address[] array = new AddressImpl[3];
2434    
2435                            array[0] = getByC_C_PrevAndNext(session, address, companyId,
2436                                            classNameId, orderByComparator, true);
2437    
2438                            array[1] = address;
2439    
2440                            array[2] = getByC_C_PrevAndNext(session, address, companyId,
2441                                            classNameId, orderByComparator, false);
2442    
2443                            return array;
2444                    }
2445                    catch (Exception e) {
2446                            throw processException(e);
2447                    }
2448                    finally {
2449                            closeSession(session);
2450                    }
2451            }
2452    
2453            protected Address getByC_C_PrevAndNext(Session session, Address address,
2454                    long companyId, long classNameId,
2455                    OrderByComparator<Address> orderByComparator, boolean previous) {
2456                    StringBundler query = null;
2457    
2458                    if (orderByComparator != null) {
2459                            query = new StringBundler(6 +
2460                                            (orderByComparator.getOrderByFields().length * 6));
2461                    }
2462                    else {
2463                            query = new StringBundler(3);
2464                    }
2465    
2466                    query.append(_SQL_SELECT_ADDRESS_WHERE);
2467    
2468                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2469    
2470                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2471    
2472                    if (orderByComparator != null) {
2473                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2474    
2475                            if (orderByConditionFields.length > 0) {
2476                                    query.append(WHERE_AND);
2477                            }
2478    
2479                            for (int i = 0; i < orderByConditionFields.length; i++) {
2480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2481                                    query.append(orderByConditionFields[i]);
2482    
2483                                    if ((i + 1) < orderByConditionFields.length) {
2484                                            if (orderByComparator.isAscending() ^ previous) {
2485                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2486                                            }
2487                                            else {
2488                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2489                                            }
2490                                    }
2491                                    else {
2492                                            if (orderByComparator.isAscending() ^ previous) {
2493                                                    query.append(WHERE_GREATER_THAN);
2494                                            }
2495                                            else {
2496                                                    query.append(WHERE_LESSER_THAN);
2497                                            }
2498                                    }
2499                            }
2500    
2501                            query.append(ORDER_BY_CLAUSE);
2502    
2503                            String[] orderByFields = orderByComparator.getOrderByFields();
2504    
2505                            for (int i = 0; i < orderByFields.length; i++) {
2506                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2507                                    query.append(orderByFields[i]);
2508    
2509                                    if ((i + 1) < orderByFields.length) {
2510                                            if (orderByComparator.isAscending() ^ previous) {
2511                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2512                                            }
2513                                            else {
2514                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2515                                            }
2516                                    }
2517                                    else {
2518                                            if (orderByComparator.isAscending() ^ previous) {
2519                                                    query.append(ORDER_BY_ASC);
2520                                            }
2521                                            else {
2522                                                    query.append(ORDER_BY_DESC);
2523                                            }
2524                                    }
2525                            }
2526                    }
2527                    else {
2528                            query.append(AddressModelImpl.ORDER_BY_JPQL);
2529                    }
2530    
2531                    String sql = query.toString();
2532    
2533                    Query q = session.createQuery(sql);
2534    
2535                    q.setFirstResult(0);
2536                    q.setMaxResults(2);
2537    
2538                    QueryPos qPos = QueryPos.getInstance(q);
2539    
2540                    qPos.add(companyId);
2541    
2542                    qPos.add(classNameId);
2543    
2544                    if (orderByComparator != null) {
2545                            Object[] values = orderByComparator.getOrderByConditionValues(address);
2546    
2547                            for (Object value : values) {
2548                                    qPos.add(value);
2549                            }
2550                    }
2551    
2552                    List<Address> list = q.list();
2553    
2554                    if (list.size() == 2) {
2555                            return list.get(1);
2556                    }
2557                    else {
2558                            return null;
2559                    }
2560            }
2561    
2562            /**
2563             * Removes all the addresses where companyId = &#63; and classNameId = &#63; from the database.
2564             *
2565             * @param companyId the company ID
2566             * @param classNameId the class name ID
2567             */
2568            @Override
2569            public void removeByC_C(long companyId, long classNameId) {
2570                    for (Address address : findByC_C(companyId, classNameId,
2571                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2572                            remove(address);
2573                    }
2574            }
2575    
2576            /**
2577             * Returns the number of addresses where companyId = &#63; and classNameId = &#63;.
2578             *
2579             * @param companyId the company ID
2580             * @param classNameId the class name ID
2581             * @return the number of matching addresses
2582             */
2583            @Override
2584            public int countByC_C(long companyId, long classNameId) {
2585                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
2586    
2587                    Object[] finderArgs = new Object[] { companyId, classNameId };
2588    
2589                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2590                                    this);
2591    
2592                    if (count == null) {
2593                            StringBundler query = new StringBundler(3);
2594    
2595                            query.append(_SQL_COUNT_ADDRESS_WHERE);
2596    
2597                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2598    
2599                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2600    
2601                            String sql = query.toString();
2602    
2603                            Session session = null;
2604    
2605                            try {
2606                                    session = openSession();
2607    
2608                                    Query q = session.createQuery(sql);
2609    
2610                                    QueryPos qPos = QueryPos.getInstance(q);
2611    
2612                                    qPos.add(companyId);
2613    
2614                                    qPos.add(classNameId);
2615    
2616                                    count = (Long)q.uniqueResult();
2617    
2618                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2619                            }
2620                            catch (Exception e) {
2621                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2622    
2623                                    throw processException(e);
2624                            }
2625                            finally {
2626                                    closeSession(session);
2627                            }
2628                    }
2629    
2630                    return count.intValue();
2631            }
2632    
2633            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "address.companyId = ? AND ";
2634            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "address.classNameId = ?";
2635            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
2636                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
2637                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
2638                            new String[] {
2639                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2640                                    
2641                            Integer.class.getName(), Integer.class.getName(),
2642                                    OrderByComparator.class.getName()
2643                            });
2644            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
2645                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
2646                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
2647                            new String[] {
2648                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
2649                            },
2650                            AddressModelImpl.COMPANYID_COLUMN_BITMASK |
2651                            AddressModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2652                            AddressModelImpl.CLASSPK_COLUMN_BITMASK |
2653                            AddressModelImpl.CREATEDATE_COLUMN_BITMASK);
2654            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
2655                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
2656                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
2657                            new String[] {
2658                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
2659                            });
2660    
2661            /**
2662             * Returns all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2663             *
2664             * @param companyId the company ID
2665             * @param classNameId the class name ID
2666             * @param classPK the class p k
2667             * @return the matching addresses
2668             */
2669            @Override
2670            public List<Address> findByC_C_C(long companyId, long classNameId,
2671                    long classPK) {
2672                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
2673                            QueryUtil.ALL_POS, null);
2674            }
2675    
2676            /**
2677             * Returns a range of all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2678             *
2679             * <p>
2680             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2681             * </p>
2682             *
2683             * @param companyId the company ID
2684             * @param classNameId the class name ID
2685             * @param classPK the class p k
2686             * @param start the lower bound of the range of addresses
2687             * @param end the upper bound of the range of addresses (not inclusive)
2688             * @return the range of matching addresses
2689             */
2690            @Override
2691            public List<Address> findByC_C_C(long companyId, long classNameId,
2692                    long classPK, int start, int end) {
2693                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
2694            }
2695    
2696            /**
2697             * Returns an ordered range of all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2698             *
2699             * <p>
2700             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2701             * </p>
2702             *
2703             * @param companyId the company ID
2704             * @param classNameId the class name ID
2705             * @param classPK the class p k
2706             * @param start the lower bound of the range of addresses
2707             * @param end the upper bound of the range of addresses (not inclusive)
2708             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2709             * @return the ordered range of matching addresses
2710             */
2711            @Override
2712            public List<Address> findByC_C_C(long companyId, long classNameId,
2713                    long classPK, int start, int end,
2714                    OrderByComparator<Address> orderByComparator) {
2715                    boolean pagination = true;
2716                    FinderPath finderPath = null;
2717                    Object[] finderArgs = null;
2718    
2719                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2720                                    (orderByComparator == null)) {
2721                            pagination = false;
2722                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
2723                            finderArgs = new Object[] { companyId, classNameId, classPK };
2724                    }
2725                    else {
2726                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
2727                            finderArgs = new Object[] {
2728                                            companyId, classNameId, classPK,
2729                                            
2730                                            start, end, orderByComparator
2731                                    };
2732                    }
2733    
2734                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
2735                                    finderArgs, this);
2736    
2737                    if ((list != null) && !list.isEmpty()) {
2738                            for (Address address : list) {
2739                                    if ((companyId != address.getCompanyId()) ||
2740                                                    (classNameId != address.getClassNameId()) ||
2741                                                    (classPK != address.getClassPK())) {
2742                                            list = null;
2743    
2744                                            break;
2745                                    }
2746                            }
2747                    }
2748    
2749                    if (list == null) {
2750                            StringBundler query = null;
2751    
2752                            if (orderByComparator != null) {
2753                                    query = new StringBundler(5 +
2754                                                    (orderByComparator.getOrderByFields().length * 3));
2755                            }
2756                            else {
2757                                    query = new StringBundler(5);
2758                            }
2759    
2760                            query.append(_SQL_SELECT_ADDRESS_WHERE);
2761    
2762                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2763    
2764                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2765    
2766                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2767    
2768                            if (orderByComparator != null) {
2769                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2770                                            orderByComparator);
2771                            }
2772                            else
2773                             if (pagination) {
2774                                    query.append(AddressModelImpl.ORDER_BY_JPQL);
2775                            }
2776    
2777                            String sql = query.toString();
2778    
2779                            Session session = null;
2780    
2781                            try {
2782                                    session = openSession();
2783    
2784                                    Query q = session.createQuery(sql);
2785    
2786                                    QueryPos qPos = QueryPos.getInstance(q);
2787    
2788                                    qPos.add(companyId);
2789    
2790                                    qPos.add(classNameId);
2791    
2792                                    qPos.add(classPK);
2793    
2794                                    if (!pagination) {
2795                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
2796                                                            start, end, false);
2797    
2798                                            Collections.sort(list);
2799    
2800                                            list = Collections.unmodifiableList(list);
2801                                    }
2802                                    else {
2803                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
2804                                                            start, end);
2805                                    }
2806    
2807                                    cacheResult(list);
2808    
2809                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2810                            }
2811                            catch (Exception e) {
2812                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2813    
2814                                    throw processException(e);
2815                            }
2816                            finally {
2817                                    closeSession(session);
2818                            }
2819                    }
2820    
2821                    return list;
2822            }
2823    
2824            /**
2825             * Returns the first address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2826             *
2827             * @param companyId the company ID
2828             * @param classNameId the class name ID
2829             * @param classPK the class p k
2830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2831             * @return the first matching address
2832             * @throws NoSuchAddressException if a matching address could not be found
2833             */
2834            @Override
2835            public Address findByC_C_C_First(long companyId, long classNameId,
2836                    long classPK, OrderByComparator<Address> orderByComparator)
2837                    throws NoSuchAddressException {
2838                    Address address = fetchByC_C_C_First(companyId, classNameId, classPK,
2839                                    orderByComparator);
2840    
2841                    if (address != null) {
2842                            return address;
2843                    }
2844    
2845                    StringBundler msg = new StringBundler(8);
2846    
2847                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2848    
2849                    msg.append("companyId=");
2850                    msg.append(companyId);
2851    
2852                    msg.append(", classNameId=");
2853                    msg.append(classNameId);
2854    
2855                    msg.append(", classPK=");
2856                    msg.append(classPK);
2857    
2858                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2859    
2860                    throw new NoSuchAddressException(msg.toString());
2861            }
2862    
2863            /**
2864             * Returns the first address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2865             *
2866             * @param companyId the company ID
2867             * @param classNameId the class name ID
2868             * @param classPK the class p k
2869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2870             * @return the first matching address, or <code>null</code> if a matching address could not be found
2871             */
2872            @Override
2873            public Address fetchByC_C_C_First(long companyId, long classNameId,
2874                    long classPK, OrderByComparator<Address> orderByComparator) {
2875                    List<Address> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
2876                                    orderByComparator);
2877    
2878                    if (!list.isEmpty()) {
2879                            return list.get(0);
2880                    }
2881    
2882                    return null;
2883            }
2884    
2885            /**
2886             * Returns the last address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2887             *
2888             * @param companyId the company ID
2889             * @param classNameId the class name ID
2890             * @param classPK the class p k
2891             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2892             * @return the last matching address
2893             * @throws NoSuchAddressException if a matching address could not be found
2894             */
2895            @Override
2896            public Address findByC_C_C_Last(long companyId, long classNameId,
2897                    long classPK, OrderByComparator<Address> orderByComparator)
2898                    throws NoSuchAddressException {
2899                    Address address = fetchByC_C_C_Last(companyId, classNameId, classPK,
2900                                    orderByComparator);
2901    
2902                    if (address != null) {
2903                            return address;
2904                    }
2905    
2906                    StringBundler msg = new StringBundler(8);
2907    
2908                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2909    
2910                    msg.append("companyId=");
2911                    msg.append(companyId);
2912    
2913                    msg.append(", classNameId=");
2914                    msg.append(classNameId);
2915    
2916                    msg.append(", classPK=");
2917                    msg.append(classPK);
2918    
2919                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2920    
2921                    throw new NoSuchAddressException(msg.toString());
2922            }
2923    
2924            /**
2925             * Returns the last address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2926             *
2927             * @param companyId the company ID
2928             * @param classNameId the class name ID
2929             * @param classPK the class p k
2930             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2931             * @return the last matching address, or <code>null</code> if a matching address could not be found
2932             */
2933            @Override
2934            public Address fetchByC_C_C_Last(long companyId, long classNameId,
2935                    long classPK, OrderByComparator<Address> orderByComparator) {
2936                    int count = countByC_C_C(companyId, classNameId, classPK);
2937    
2938                    if (count == 0) {
2939                            return null;
2940                    }
2941    
2942                    List<Address> list = findByC_C_C(companyId, classNameId, classPK,
2943                                    count - 1, count, orderByComparator);
2944    
2945                    if (!list.isEmpty()) {
2946                            return list.get(0);
2947                    }
2948    
2949                    return null;
2950            }
2951    
2952            /**
2953             * Returns the addresses before and after the current address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2954             *
2955             * @param addressId the primary key of the current address
2956             * @param companyId the company ID
2957             * @param classNameId the class name ID
2958             * @param classPK the class p k
2959             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2960             * @return the previous, current, and next address
2961             * @throws NoSuchAddressException if a address with the primary key could not be found
2962             */
2963            @Override
2964            public Address[] findByC_C_C_PrevAndNext(long addressId, long companyId,
2965                    long classNameId, long classPK,
2966                    OrderByComparator<Address> orderByComparator)
2967                    throws NoSuchAddressException {
2968                    Address address = findByPrimaryKey(addressId);
2969    
2970                    Session session = null;
2971    
2972                    try {
2973                            session = openSession();
2974    
2975                            Address[] array = new AddressImpl[3];
2976    
2977                            array[0] = getByC_C_C_PrevAndNext(session, address, companyId,
2978                                            classNameId, classPK, orderByComparator, true);
2979    
2980                            array[1] = address;
2981    
2982                            array[2] = getByC_C_C_PrevAndNext(session, address, companyId,
2983                                            classNameId, classPK, orderByComparator, false);
2984    
2985                            return array;
2986                    }
2987                    catch (Exception e) {
2988                            throw processException(e);
2989                    }
2990                    finally {
2991                            closeSession(session);
2992                    }
2993            }
2994    
2995            protected Address getByC_C_C_PrevAndNext(Session session, Address address,
2996                    long companyId, long classNameId, long classPK,
2997                    OrderByComparator<Address> orderByComparator, boolean previous) {
2998                    StringBundler query = null;
2999    
3000                    if (orderByComparator != null) {
3001                            query = new StringBundler(6 +
3002                                            (orderByComparator.getOrderByFields().length * 6));
3003                    }
3004                    else {
3005                            query = new StringBundler(3);
3006                    }
3007    
3008                    query.append(_SQL_SELECT_ADDRESS_WHERE);
3009    
3010                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3011    
3012                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3013    
3014                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3015    
3016                    if (orderByComparator != null) {
3017                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3018    
3019                            if (orderByConditionFields.length > 0) {
3020                                    query.append(WHERE_AND);
3021                            }
3022    
3023                            for (int i = 0; i < orderByConditionFields.length; i++) {
3024                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3025                                    query.append(orderByConditionFields[i]);
3026    
3027                                    if ((i + 1) < orderByConditionFields.length) {
3028                                            if (orderByComparator.isAscending() ^ previous) {
3029                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3030                                            }
3031                                            else {
3032                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3033                                            }
3034                                    }
3035                                    else {
3036                                            if (orderByComparator.isAscending() ^ previous) {
3037                                                    query.append(WHERE_GREATER_THAN);
3038                                            }
3039                                            else {
3040                                                    query.append(WHERE_LESSER_THAN);
3041                                            }
3042                                    }
3043                            }
3044    
3045                            query.append(ORDER_BY_CLAUSE);
3046    
3047                            String[] orderByFields = orderByComparator.getOrderByFields();
3048    
3049                            for (int i = 0; i < orderByFields.length; i++) {
3050                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3051                                    query.append(orderByFields[i]);
3052    
3053                                    if ((i + 1) < orderByFields.length) {
3054                                            if (orderByComparator.isAscending() ^ previous) {
3055                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3056                                            }
3057                                            else {
3058                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3059                                            }
3060                                    }
3061                                    else {
3062                                            if (orderByComparator.isAscending() ^ previous) {
3063                                                    query.append(ORDER_BY_ASC);
3064                                            }
3065                                            else {
3066                                                    query.append(ORDER_BY_DESC);
3067                                            }
3068                                    }
3069                            }
3070                    }
3071                    else {
3072                            query.append(AddressModelImpl.ORDER_BY_JPQL);
3073                    }
3074    
3075                    String sql = query.toString();
3076    
3077                    Query q = session.createQuery(sql);
3078    
3079                    q.setFirstResult(0);
3080                    q.setMaxResults(2);
3081    
3082                    QueryPos qPos = QueryPos.getInstance(q);
3083    
3084                    qPos.add(companyId);
3085    
3086                    qPos.add(classNameId);
3087    
3088                    qPos.add(classPK);
3089    
3090                    if (orderByComparator != null) {
3091                            Object[] values = orderByComparator.getOrderByConditionValues(address);
3092    
3093                            for (Object value : values) {
3094                                    qPos.add(value);
3095                            }
3096                    }
3097    
3098                    List<Address> list = q.list();
3099    
3100                    if (list.size() == 2) {
3101                            return list.get(1);
3102                    }
3103                    else {
3104                            return null;
3105                    }
3106            }
3107    
3108            /**
3109             * Removes all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
3110             *
3111             * @param companyId the company ID
3112             * @param classNameId the class name ID
3113             * @param classPK the class p k
3114             */
3115            @Override
3116            public void removeByC_C_C(long companyId, long classNameId, long classPK) {
3117                    for (Address address : findByC_C_C(companyId, classNameId, classPK,
3118                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3119                            remove(address);
3120                    }
3121            }
3122    
3123            /**
3124             * Returns the number of addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3125             *
3126             * @param companyId the company ID
3127             * @param classNameId the class name ID
3128             * @param classPK the class p k
3129             * @return the number of matching addresses
3130             */
3131            @Override
3132            public int countByC_C_C(long companyId, long classNameId, long classPK) {
3133                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
3134    
3135                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
3136    
3137                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3138                                    this);
3139    
3140                    if (count == null) {
3141                            StringBundler query = new StringBundler(4);
3142    
3143                            query.append(_SQL_COUNT_ADDRESS_WHERE);
3144    
3145                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3146    
3147                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3148    
3149                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3150    
3151                            String sql = query.toString();
3152    
3153                            Session session = null;
3154    
3155                            try {
3156                                    session = openSession();
3157    
3158                                    Query q = session.createQuery(sql);
3159    
3160                                    QueryPos qPos = QueryPos.getInstance(q);
3161    
3162                                    qPos.add(companyId);
3163    
3164                                    qPos.add(classNameId);
3165    
3166                                    qPos.add(classPK);
3167    
3168                                    count = (Long)q.uniqueResult();
3169    
3170                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3171                            }
3172                            catch (Exception e) {
3173                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3174    
3175                                    throw processException(e);
3176                            }
3177                            finally {
3178                                    closeSession(session);
3179                            }
3180                    }
3181    
3182                    return count.intValue();
3183            }
3184    
3185            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "address.companyId = ? AND ";
3186            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "address.classNameId = ? AND ";
3187            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "address.classPK = ?";
3188            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_M = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
3189                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
3190                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_M",
3191                            new String[] {
3192                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3193                                    Boolean.class.getName(),
3194                                    
3195                            Integer.class.getName(), Integer.class.getName(),
3196                                    OrderByComparator.class.getName()
3197                            });
3198            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_M =
3199                    new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
3200                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
3201                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_M",
3202                            new String[] {
3203                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3204                                    Boolean.class.getName()
3205                            },
3206                            AddressModelImpl.COMPANYID_COLUMN_BITMASK |
3207                            AddressModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3208                            AddressModelImpl.CLASSPK_COLUMN_BITMASK |
3209                            AddressModelImpl.MAILING_COLUMN_BITMASK |
3210                            AddressModelImpl.CREATEDATE_COLUMN_BITMASK);
3211            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_M = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
3212                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
3213                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_M",
3214                            new String[] {
3215                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3216                                    Boolean.class.getName()
3217                            });
3218    
3219            /**
3220             * Returns all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63;.
3221             *
3222             * @param companyId the company ID
3223             * @param classNameId the class name ID
3224             * @param classPK the class p k
3225             * @param mailing the mailing
3226             * @return the matching addresses
3227             */
3228            @Override
3229            public List<Address> findByC_C_C_M(long companyId, long classNameId,
3230                    long classPK, boolean mailing) {
3231                    return findByC_C_C_M(companyId, classNameId, classPK, mailing,
3232                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3233            }
3234    
3235            /**
3236             * Returns a range of all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63;.
3237             *
3238             * <p>
3239             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3240             * </p>
3241             *
3242             * @param companyId the company ID
3243             * @param classNameId the class name ID
3244             * @param classPK the class p k
3245             * @param mailing the mailing
3246             * @param start the lower bound of the range of addresses
3247             * @param end the upper bound of the range of addresses (not inclusive)
3248             * @return the range of matching addresses
3249             */
3250            @Override
3251            public List<Address> findByC_C_C_M(long companyId, long classNameId,
3252                    long classPK, boolean mailing, int start, int end) {
3253                    return findByC_C_C_M(companyId, classNameId, classPK, mailing, start,
3254                            end, null);
3255            }
3256    
3257            /**
3258             * Returns an ordered range of all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63;.
3259             *
3260             * <p>
3261             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3262             * </p>
3263             *
3264             * @param companyId the company ID
3265             * @param classNameId the class name ID
3266             * @param classPK the class p k
3267             * @param mailing the mailing
3268             * @param start the lower bound of the range of addresses
3269             * @param end the upper bound of the range of addresses (not inclusive)
3270             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3271             * @return the ordered range of matching addresses
3272             */
3273            @Override
3274            public List<Address> findByC_C_C_M(long companyId, long classNameId,
3275                    long classPK, boolean mailing, int start, int end,
3276                    OrderByComparator<Address> orderByComparator) {
3277                    boolean pagination = true;
3278                    FinderPath finderPath = null;
3279                    Object[] finderArgs = null;
3280    
3281                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3282                                    (orderByComparator == null)) {
3283                            pagination = false;
3284                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_M;
3285                            finderArgs = new Object[] { companyId, classNameId, classPK, mailing };
3286                    }
3287                    else {
3288                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_M;
3289                            finderArgs = new Object[] {
3290                                            companyId, classNameId, classPK, mailing,
3291                                            
3292                                            start, end, orderByComparator
3293                                    };
3294                    }
3295    
3296                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
3297                                    finderArgs, this);
3298    
3299                    if ((list != null) && !list.isEmpty()) {
3300                            for (Address address : list) {
3301                                    if ((companyId != address.getCompanyId()) ||
3302                                                    (classNameId != address.getClassNameId()) ||
3303                                                    (classPK != address.getClassPK()) ||
3304                                                    (mailing != address.getMailing())) {
3305                                            list = null;
3306    
3307                                            break;
3308                                    }
3309                            }
3310                    }
3311    
3312                    if (list == null) {
3313                            StringBundler query = null;
3314    
3315                            if (orderByComparator != null) {
3316                                    query = new StringBundler(6 +
3317                                                    (orderByComparator.getOrderByFields().length * 3));
3318                            }
3319                            else {
3320                                    query = new StringBundler(6);
3321                            }
3322    
3323                            query.append(_SQL_SELECT_ADDRESS_WHERE);
3324    
3325                            query.append(_FINDER_COLUMN_C_C_C_M_COMPANYID_2);
3326    
3327                            query.append(_FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2);
3328    
3329                            query.append(_FINDER_COLUMN_C_C_C_M_CLASSPK_2);
3330    
3331                            query.append(_FINDER_COLUMN_C_C_C_M_MAILING_2);
3332    
3333                            if (orderByComparator != null) {
3334                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3335                                            orderByComparator);
3336                            }
3337                            else
3338                             if (pagination) {
3339                                    query.append(AddressModelImpl.ORDER_BY_JPQL);
3340                            }
3341    
3342                            String sql = query.toString();
3343    
3344                            Session session = null;
3345    
3346                            try {
3347                                    session = openSession();
3348    
3349                                    Query q = session.createQuery(sql);
3350    
3351                                    QueryPos qPos = QueryPos.getInstance(q);
3352    
3353                                    qPos.add(companyId);
3354    
3355                                    qPos.add(classNameId);
3356    
3357                                    qPos.add(classPK);
3358    
3359                                    qPos.add(mailing);
3360    
3361                                    if (!pagination) {
3362                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
3363                                                            start, end, false);
3364    
3365                                            Collections.sort(list);
3366    
3367                                            list = Collections.unmodifiableList(list);
3368                                    }
3369                                    else {
3370                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
3371                                                            start, end);
3372                                    }
3373    
3374                                    cacheResult(list);
3375    
3376                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3377                            }
3378                            catch (Exception e) {
3379                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3380    
3381                                    throw processException(e);
3382                            }
3383                            finally {
3384                                    closeSession(session);
3385                            }
3386                    }
3387    
3388                    return list;
3389            }
3390    
3391            /**
3392             * Returns the first address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63;.
3393             *
3394             * @param companyId the company ID
3395             * @param classNameId the class name ID
3396             * @param classPK the class p k
3397             * @param mailing the mailing
3398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3399             * @return the first matching address
3400             * @throws NoSuchAddressException if a matching address could not be found
3401             */
3402            @Override
3403            public Address findByC_C_C_M_First(long companyId, long classNameId,
3404                    long classPK, boolean mailing,
3405                    OrderByComparator<Address> orderByComparator)
3406                    throws NoSuchAddressException {
3407                    Address address = fetchByC_C_C_M_First(companyId, classNameId, classPK,
3408                                    mailing, orderByComparator);
3409    
3410                    if (address != null) {
3411                            return address;
3412                    }
3413    
3414                    StringBundler msg = new StringBundler(10);
3415    
3416                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3417    
3418                    msg.append("companyId=");
3419                    msg.append(companyId);
3420    
3421                    msg.append(", classNameId=");
3422                    msg.append(classNameId);
3423    
3424                    msg.append(", classPK=");
3425                    msg.append(classPK);
3426    
3427                    msg.append(", mailing=");
3428                    msg.append(mailing);
3429    
3430                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3431    
3432                    throw new NoSuchAddressException(msg.toString());
3433            }
3434    
3435            /**
3436             * Returns the first address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63;.
3437             *
3438             * @param companyId the company ID
3439             * @param classNameId the class name ID
3440             * @param classPK the class p k
3441             * @param mailing the mailing
3442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3443             * @return the first matching address, or <code>null</code> if a matching address could not be found
3444             */
3445            @Override
3446            public Address fetchByC_C_C_M_First(long companyId, long classNameId,
3447                    long classPK, boolean mailing,
3448                    OrderByComparator<Address> orderByComparator) {
3449                    List<Address> list = findByC_C_C_M(companyId, classNameId, classPK,
3450                                    mailing, 0, 1, orderByComparator);
3451    
3452                    if (!list.isEmpty()) {
3453                            return list.get(0);
3454                    }
3455    
3456                    return null;
3457            }
3458    
3459            /**
3460             * Returns the last address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63;.
3461             *
3462             * @param companyId the company ID
3463             * @param classNameId the class name ID
3464             * @param classPK the class p k
3465             * @param mailing the mailing
3466             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3467             * @return the last matching address
3468             * @throws NoSuchAddressException if a matching address could not be found
3469             */
3470            @Override
3471            public Address findByC_C_C_M_Last(long companyId, long classNameId,
3472                    long classPK, boolean mailing,
3473                    OrderByComparator<Address> orderByComparator)
3474                    throws NoSuchAddressException {
3475                    Address address = fetchByC_C_C_M_Last(companyId, classNameId, classPK,
3476                                    mailing, orderByComparator);
3477    
3478                    if (address != null) {
3479                            return address;
3480                    }
3481    
3482                    StringBundler msg = new StringBundler(10);
3483    
3484                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3485    
3486                    msg.append("companyId=");
3487                    msg.append(companyId);
3488    
3489                    msg.append(", classNameId=");
3490                    msg.append(classNameId);
3491    
3492                    msg.append(", classPK=");
3493                    msg.append(classPK);
3494    
3495                    msg.append(", mailing=");
3496                    msg.append(mailing);
3497    
3498                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3499    
3500                    throw new NoSuchAddressException(msg.toString());
3501            }
3502    
3503            /**
3504             * Returns the last address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63;.
3505             *
3506             * @param companyId the company ID
3507             * @param classNameId the class name ID
3508             * @param classPK the class p k
3509             * @param mailing the mailing
3510             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3511             * @return the last matching address, or <code>null</code> if a matching address could not be found
3512             */
3513            @Override
3514            public Address fetchByC_C_C_M_Last(long companyId, long classNameId,
3515                    long classPK, boolean mailing,
3516                    OrderByComparator<Address> orderByComparator) {
3517                    int count = countByC_C_C_M(companyId, classNameId, classPK, mailing);
3518    
3519                    if (count == 0) {
3520                            return null;
3521                    }
3522    
3523                    List<Address> list = findByC_C_C_M(companyId, classNameId, classPK,
3524                                    mailing, count - 1, count, orderByComparator);
3525    
3526                    if (!list.isEmpty()) {
3527                            return list.get(0);
3528                    }
3529    
3530                    return null;
3531            }
3532    
3533            /**
3534             * 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;.
3535             *
3536             * @param addressId the primary key of the current address
3537             * @param companyId the company ID
3538             * @param classNameId the class name ID
3539             * @param classPK the class p k
3540             * @param mailing the mailing
3541             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3542             * @return the previous, current, and next address
3543             * @throws NoSuchAddressException if a address with the primary key could not be found
3544             */
3545            @Override
3546            public Address[] findByC_C_C_M_PrevAndNext(long addressId, long companyId,
3547                    long classNameId, long classPK, boolean mailing,
3548                    OrderByComparator<Address> orderByComparator)
3549                    throws NoSuchAddressException {
3550                    Address address = findByPrimaryKey(addressId);
3551    
3552                    Session session = null;
3553    
3554                    try {
3555                            session = openSession();
3556    
3557                            Address[] array = new AddressImpl[3];
3558    
3559                            array[0] = getByC_C_C_M_PrevAndNext(session, address, companyId,
3560                                            classNameId, classPK, mailing, orderByComparator, true);
3561    
3562                            array[1] = address;
3563    
3564                            array[2] = getByC_C_C_M_PrevAndNext(session, address, companyId,
3565                                            classNameId, classPK, mailing, orderByComparator, false);
3566    
3567                            return array;
3568                    }
3569                    catch (Exception e) {
3570                            throw processException(e);
3571                    }
3572                    finally {
3573                            closeSession(session);
3574                    }
3575            }
3576    
3577            protected Address getByC_C_C_M_PrevAndNext(Session session,
3578                    Address address, long companyId, long classNameId, long classPK,
3579                    boolean mailing, OrderByComparator<Address> orderByComparator,
3580                    boolean previous) {
3581                    StringBundler query = null;
3582    
3583                    if (orderByComparator != null) {
3584                            query = new StringBundler(6 +
3585                                            (orderByComparator.getOrderByFields().length * 6));
3586                    }
3587                    else {
3588                            query = new StringBundler(3);
3589                    }
3590    
3591                    query.append(_SQL_SELECT_ADDRESS_WHERE);
3592    
3593                    query.append(_FINDER_COLUMN_C_C_C_M_COMPANYID_2);
3594    
3595                    query.append(_FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2);
3596    
3597                    query.append(_FINDER_COLUMN_C_C_C_M_CLASSPK_2);
3598    
3599                    query.append(_FINDER_COLUMN_C_C_C_M_MAILING_2);
3600    
3601                    if (orderByComparator != null) {
3602                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3603    
3604                            if (orderByConditionFields.length > 0) {
3605                                    query.append(WHERE_AND);
3606                            }
3607    
3608                            for (int i = 0; i < orderByConditionFields.length; i++) {
3609                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3610                                    query.append(orderByConditionFields[i]);
3611    
3612                                    if ((i + 1) < orderByConditionFields.length) {
3613                                            if (orderByComparator.isAscending() ^ previous) {
3614                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3615                                            }
3616                                            else {
3617                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3618                                            }
3619                                    }
3620                                    else {
3621                                            if (orderByComparator.isAscending() ^ previous) {
3622                                                    query.append(WHERE_GREATER_THAN);
3623                                            }
3624                                            else {
3625                                                    query.append(WHERE_LESSER_THAN);
3626                                            }
3627                                    }
3628                            }
3629    
3630                            query.append(ORDER_BY_CLAUSE);
3631    
3632                            String[] orderByFields = orderByComparator.getOrderByFields();
3633    
3634                            for (int i = 0; i < orderByFields.length; i++) {
3635                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3636                                    query.append(orderByFields[i]);
3637    
3638                                    if ((i + 1) < orderByFields.length) {
3639                                            if (orderByComparator.isAscending() ^ previous) {
3640                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3641                                            }
3642                                            else {
3643                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3644                                            }
3645                                    }
3646                                    else {
3647                                            if (orderByComparator.isAscending() ^ previous) {
3648                                                    query.append(ORDER_BY_ASC);
3649                                            }
3650                                            else {
3651                                                    query.append(ORDER_BY_DESC);
3652                                            }
3653                                    }
3654                            }
3655                    }
3656                    else {
3657                            query.append(AddressModelImpl.ORDER_BY_JPQL);
3658                    }
3659    
3660                    String sql = query.toString();
3661    
3662                    Query q = session.createQuery(sql);
3663    
3664                    q.setFirstResult(0);
3665                    q.setMaxResults(2);
3666    
3667                    QueryPos qPos = QueryPos.getInstance(q);
3668    
3669                    qPos.add(companyId);
3670    
3671                    qPos.add(classNameId);
3672    
3673                    qPos.add(classPK);
3674    
3675                    qPos.add(mailing);
3676    
3677                    if (orderByComparator != null) {
3678                            Object[] values = orderByComparator.getOrderByConditionValues(address);
3679    
3680                            for (Object value : values) {
3681                                    qPos.add(value);
3682                            }
3683                    }
3684    
3685                    List<Address> list = q.list();
3686    
3687                    if (list.size() == 2) {
3688                            return list.get(1);
3689                    }
3690                    else {
3691                            return null;
3692                    }
3693            }
3694    
3695            /**
3696             * Removes all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63; from the database.
3697             *
3698             * @param companyId the company ID
3699             * @param classNameId the class name ID
3700             * @param classPK the class p k
3701             * @param mailing the mailing
3702             */
3703            @Override
3704            public void removeByC_C_C_M(long companyId, long classNameId, long classPK,
3705                    boolean mailing) {
3706                    for (Address address : findByC_C_C_M(companyId, classNameId, classPK,
3707                                    mailing, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3708                            remove(address);
3709                    }
3710            }
3711    
3712            /**
3713             * Returns the number of addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and mailing = &#63;.
3714             *
3715             * @param companyId the company ID
3716             * @param classNameId the class name ID
3717             * @param classPK the class p k
3718             * @param mailing the mailing
3719             * @return the number of matching addresses
3720             */
3721            @Override
3722            public int countByC_C_C_M(long companyId, long classNameId, long classPK,
3723                    boolean mailing) {
3724                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C_M;
3725    
3726                    Object[] finderArgs = new Object[] {
3727                                    companyId, classNameId, classPK, mailing
3728                            };
3729    
3730                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3731                                    this);
3732    
3733                    if (count == null) {
3734                            StringBundler query = new StringBundler(5);
3735    
3736                            query.append(_SQL_COUNT_ADDRESS_WHERE);
3737    
3738                            query.append(_FINDER_COLUMN_C_C_C_M_COMPANYID_2);
3739    
3740                            query.append(_FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2);
3741    
3742                            query.append(_FINDER_COLUMN_C_C_C_M_CLASSPK_2);
3743    
3744                            query.append(_FINDER_COLUMN_C_C_C_M_MAILING_2);
3745    
3746                            String sql = query.toString();
3747    
3748                            Session session = null;
3749    
3750                            try {
3751                                    session = openSession();
3752    
3753                                    Query q = session.createQuery(sql);
3754    
3755                                    QueryPos qPos = QueryPos.getInstance(q);
3756    
3757                                    qPos.add(companyId);
3758    
3759                                    qPos.add(classNameId);
3760    
3761                                    qPos.add(classPK);
3762    
3763                                    qPos.add(mailing);
3764    
3765                                    count = (Long)q.uniqueResult();
3766    
3767                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3768                            }
3769                            catch (Exception e) {
3770                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3771    
3772                                    throw processException(e);
3773                            }
3774                            finally {
3775                                    closeSession(session);
3776                            }
3777                    }
3778    
3779                    return count.intValue();
3780            }
3781    
3782            private static final String _FINDER_COLUMN_C_C_C_M_COMPANYID_2 = "address.companyId = ? AND ";
3783            private static final String _FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2 = "address.classNameId = ? AND ";
3784            private static final String _FINDER_COLUMN_C_C_C_M_CLASSPK_2 = "address.classPK = ? AND ";
3785            private static final String _FINDER_COLUMN_C_C_C_M_MAILING_2 = "address.mailing = ?";
3786            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
3787                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
3788                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_P",
3789                            new String[] {
3790                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3791                                    Boolean.class.getName(),
3792                                    
3793                            Integer.class.getName(), Integer.class.getName(),
3794                                    OrderByComparator.class.getName()
3795                            });
3796            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P =
3797                    new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
3798                            AddressModelImpl.FINDER_CACHE_ENABLED, AddressImpl.class,
3799                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_P",
3800                            new String[] {
3801                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3802                                    Boolean.class.getName()
3803                            },
3804                            AddressModelImpl.COMPANYID_COLUMN_BITMASK |
3805                            AddressModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3806                            AddressModelImpl.CLASSPK_COLUMN_BITMASK |
3807                            AddressModelImpl.PRIMARY_COLUMN_BITMASK |
3808                            AddressModelImpl.CREATEDATE_COLUMN_BITMASK);
3809            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
3810                            AddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
3811                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_P",
3812                            new String[] {
3813                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3814                                    Boolean.class.getName()
3815                            });
3816    
3817            /**
3818             * Returns all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3819             *
3820             * @param companyId the company ID
3821             * @param classNameId the class name ID
3822             * @param classPK the class p k
3823             * @param primary the primary
3824             * @return the matching addresses
3825             */
3826            @Override
3827            public List<Address> findByC_C_C_P(long companyId, long classNameId,
3828                    long classPK, boolean primary) {
3829                    return findByC_C_C_P(companyId, classNameId, classPK, primary,
3830                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3831            }
3832    
3833            /**
3834             * Returns a range of all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3835             *
3836             * <p>
3837             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3838             * </p>
3839             *
3840             * @param companyId the company ID
3841             * @param classNameId the class name ID
3842             * @param classPK the class p k
3843             * @param primary the primary
3844             * @param start the lower bound of the range of addresses
3845             * @param end the upper bound of the range of addresses (not inclusive)
3846             * @return the range of matching addresses
3847             */
3848            @Override
3849            public List<Address> findByC_C_C_P(long companyId, long classNameId,
3850                    long classPK, boolean primary, int start, int end) {
3851                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
3852                            end, null);
3853            }
3854    
3855            /**
3856             * Returns an ordered range of all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3857             *
3858             * <p>
3859             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3860             * </p>
3861             *
3862             * @param companyId the company ID
3863             * @param classNameId the class name ID
3864             * @param classPK the class p k
3865             * @param primary the primary
3866             * @param start the lower bound of the range of addresses
3867             * @param end the upper bound of the range of addresses (not inclusive)
3868             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3869             * @return the ordered range of matching addresses
3870             */
3871            @Override
3872            public List<Address> findByC_C_C_P(long companyId, long classNameId,
3873                    long classPK, boolean primary, int start, int end,
3874                    OrderByComparator<Address> orderByComparator) {
3875                    boolean pagination = true;
3876                    FinderPath finderPath = null;
3877                    Object[] finderArgs = null;
3878    
3879                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3880                                    (orderByComparator == null)) {
3881                            pagination = false;
3882                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P;
3883                            finderArgs = new Object[] { companyId, classNameId, classPK, primary };
3884                    }
3885                    else {
3886                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
3887                            finderArgs = new Object[] {
3888                                            companyId, classNameId, classPK, primary,
3889                                            
3890                                            start, end, orderByComparator
3891                                    };
3892                    }
3893    
3894                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
3895                                    finderArgs, this);
3896    
3897                    if ((list != null) && !list.isEmpty()) {
3898                            for (Address address : list) {
3899                                    if ((companyId != address.getCompanyId()) ||
3900                                                    (classNameId != address.getClassNameId()) ||
3901                                                    (classPK != address.getClassPK()) ||
3902                                                    (primary != address.getPrimary())) {
3903                                            list = null;
3904    
3905                                            break;
3906                                    }
3907                            }
3908                    }
3909    
3910                    if (list == null) {
3911                            StringBundler query = null;
3912    
3913                            if (orderByComparator != null) {
3914                                    query = new StringBundler(6 +
3915                                                    (orderByComparator.getOrderByFields().length * 3));
3916                            }
3917                            else {
3918                                    query = new StringBundler(6);
3919                            }
3920    
3921                            query.append(_SQL_SELECT_ADDRESS_WHERE);
3922    
3923                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3924    
3925                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3926    
3927                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3928    
3929                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3930    
3931                            if (orderByComparator != null) {
3932                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3933                                            orderByComparator);
3934                            }
3935                            else
3936                             if (pagination) {
3937                                    query.append(AddressModelImpl.ORDER_BY_JPQL);
3938                            }
3939    
3940                            String sql = query.toString();
3941    
3942                            Session session = null;
3943    
3944                            try {
3945                                    session = openSession();
3946    
3947                                    Query q = session.createQuery(sql);
3948    
3949                                    QueryPos qPos = QueryPos.getInstance(q);
3950    
3951                                    qPos.add(companyId);
3952    
3953                                    qPos.add(classNameId);
3954    
3955                                    qPos.add(classPK);
3956    
3957                                    qPos.add(primary);
3958    
3959                                    if (!pagination) {
3960                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
3961                                                            start, end, false);
3962    
3963                                            Collections.sort(list);
3964    
3965                                            list = Collections.unmodifiableList(list);
3966                                    }
3967                                    else {
3968                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
3969                                                            start, end);
3970                                    }
3971    
3972                                    cacheResult(list);
3973    
3974                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3975                            }
3976                            catch (Exception e) {
3977                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3978    
3979                                    throw processException(e);
3980                            }
3981                            finally {
3982                                    closeSession(session);
3983                            }
3984                    }
3985    
3986                    return list;
3987            }
3988    
3989            /**
3990             * Returns the first address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3991             *
3992             * @param companyId the company ID
3993             * @param classNameId the class name ID
3994             * @param classPK the class p k
3995             * @param primary the primary
3996             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3997             * @return the first matching address
3998             * @throws NoSuchAddressException if a matching address could not be found
3999             */
4000            @Override
4001            public Address findByC_C_C_P_First(long companyId, long classNameId,
4002                    long classPK, boolean primary,
4003                    OrderByComparator<Address> orderByComparator)
4004                    throws NoSuchAddressException {
4005                    Address address = fetchByC_C_C_P_First(companyId, classNameId, classPK,
4006                                    primary, orderByComparator);
4007    
4008                    if (address != null) {
4009                            return address;
4010                    }
4011    
4012                    StringBundler msg = new StringBundler(10);
4013    
4014                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4015    
4016                    msg.append("companyId=");
4017                    msg.append(companyId);
4018    
4019                    msg.append(", classNameId=");
4020                    msg.append(classNameId);
4021    
4022                    msg.append(", classPK=");
4023                    msg.append(classPK);
4024    
4025                    msg.append(", primary=");
4026                    msg.append(primary);
4027    
4028                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4029    
4030                    throw new NoSuchAddressException(msg.toString());
4031            }
4032    
4033            /**
4034             * Returns the first address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
4035             *
4036             * @param companyId the company ID
4037             * @param classNameId the class name ID
4038             * @param classPK the class p k
4039             * @param primary the primary
4040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4041             * @return the first matching address, or <code>null</code> if a matching address could not be found
4042             */
4043            @Override
4044            public Address fetchByC_C_C_P_First(long companyId, long classNameId,
4045                    long classPK, boolean primary,
4046                    OrderByComparator<Address> orderByComparator) {
4047                    List<Address> list = findByC_C_C_P(companyId, classNameId, classPK,
4048                                    primary, 0, 1, orderByComparator);
4049    
4050                    if (!list.isEmpty()) {
4051                            return list.get(0);
4052                    }
4053    
4054                    return null;
4055            }
4056    
4057            /**
4058             * Returns the last address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
4059             *
4060             * @param companyId the company ID
4061             * @param classNameId the class name ID
4062             * @param classPK the class p k
4063             * @param primary the primary
4064             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4065             * @return the last matching address
4066             * @throws NoSuchAddressException if a matching address could not be found
4067             */
4068            @Override
4069            public Address findByC_C_C_P_Last(long companyId, long classNameId,
4070                    long classPK, boolean primary,
4071                    OrderByComparator<Address> orderByComparator)
4072                    throws NoSuchAddressException {
4073                    Address address = fetchByC_C_C_P_Last(companyId, classNameId, classPK,
4074                                    primary, orderByComparator);
4075    
4076                    if (address != null) {
4077                            return address;
4078                    }
4079    
4080                    StringBundler msg = new StringBundler(10);
4081    
4082                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4083    
4084                    msg.append("companyId=");
4085                    msg.append(companyId);
4086    
4087                    msg.append(", classNameId=");
4088                    msg.append(classNameId);
4089    
4090                    msg.append(", classPK=");
4091                    msg.append(classPK);
4092    
4093                    msg.append(", primary=");
4094                    msg.append(primary);
4095    
4096                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4097    
4098                    throw new NoSuchAddressException(msg.toString());
4099            }
4100    
4101            /**
4102             * Returns the last address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
4103             *
4104             * @param companyId the company ID
4105             * @param classNameId the class name ID
4106             * @param classPK the class p k
4107             * @param primary the primary
4108             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4109             * @return the last matching address, or <code>null</code> if a matching address could not be found
4110             */
4111            @Override
4112            public Address fetchByC_C_C_P_Last(long companyId, long classNameId,
4113                    long classPK, boolean primary,
4114                    OrderByComparator<Address> orderByComparator) {
4115                    int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
4116    
4117                    if (count == 0) {
4118                            return null;
4119                    }
4120    
4121                    List<Address> list = findByC_C_C_P(companyId, classNameId, classPK,
4122                                    primary, count - 1, count, orderByComparator);
4123    
4124                    if (!list.isEmpty()) {
4125                            return list.get(0);
4126                    }
4127    
4128                    return null;
4129            }
4130    
4131            /**
4132             * 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;.
4133             *
4134             * @param addressId the primary key of the current address
4135             * @param companyId the company ID
4136             * @param classNameId the class name ID
4137             * @param classPK the class p k
4138             * @param primary the primary
4139             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4140             * @return the previous, current, and next address
4141             * @throws NoSuchAddressException if a address with the primary key could not be found
4142             */
4143            @Override
4144            public Address[] findByC_C_C_P_PrevAndNext(long addressId, long companyId,
4145                    long classNameId, long classPK, boolean primary,
4146                    OrderByComparator<Address> orderByComparator)
4147                    throws NoSuchAddressException {
4148                    Address address = findByPrimaryKey(addressId);
4149    
4150                    Session session = null;
4151    
4152                    try {
4153                            session = openSession();
4154    
4155                            Address[] array = new AddressImpl[3];
4156    
4157                            array[0] = getByC_C_C_P_PrevAndNext(session, address, companyId,
4158                                            classNameId, classPK, primary, orderByComparator, true);
4159    
4160                            array[1] = address;
4161    
4162                            array[2] = getByC_C_C_P_PrevAndNext(session, address, companyId,
4163                                            classNameId, classPK, primary, orderByComparator, false);
4164    
4165                            return array;
4166                    }
4167                    catch (Exception e) {
4168                            throw processException(e);
4169                    }
4170                    finally {
4171                            closeSession(session);
4172                    }
4173            }
4174    
4175            protected Address getByC_C_C_P_PrevAndNext(Session session,
4176                    Address address, long companyId, long classNameId, long classPK,
4177                    boolean primary, OrderByComparator<Address> orderByComparator,
4178                    boolean previous) {
4179                    StringBundler query = null;
4180    
4181                    if (orderByComparator != null) {
4182                            query = new StringBundler(6 +
4183                                            (orderByComparator.getOrderByFields().length * 6));
4184                    }
4185                    else {
4186                            query = new StringBundler(3);
4187                    }
4188    
4189                    query.append(_SQL_SELECT_ADDRESS_WHERE);
4190    
4191                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
4192    
4193                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
4194    
4195                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
4196    
4197                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
4198    
4199                    if (orderByComparator != null) {
4200                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4201    
4202                            if (orderByConditionFields.length > 0) {
4203                                    query.append(WHERE_AND);
4204                            }
4205    
4206                            for (int i = 0; i < orderByConditionFields.length; i++) {
4207                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4208                                    query.append(orderByConditionFields[i]);
4209    
4210                                    if ((i + 1) < orderByConditionFields.length) {
4211                                            if (orderByComparator.isAscending() ^ previous) {
4212                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4213                                            }
4214                                            else {
4215                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4216                                            }
4217                                    }
4218                                    else {
4219                                            if (orderByComparator.isAscending() ^ previous) {
4220                                                    query.append(WHERE_GREATER_THAN);
4221                                            }
4222                                            else {
4223                                                    query.append(WHERE_LESSER_THAN);
4224                                            }
4225                                    }
4226                            }
4227    
4228                            query.append(ORDER_BY_CLAUSE);
4229    
4230                            String[] orderByFields = orderByComparator.getOrderByFields();
4231    
4232                            for (int i = 0; i < orderByFields.length; i++) {
4233                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4234                                    query.append(orderByFields[i]);
4235    
4236                                    if ((i + 1) < orderByFields.length) {
4237                                            if (orderByComparator.isAscending() ^ previous) {
4238                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4239                                            }
4240                                            else {
4241                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4242                                            }
4243                                    }
4244                                    else {
4245                                            if (orderByComparator.isAscending() ^ previous) {
4246                                                    query.append(ORDER_BY_ASC);
4247                                            }
4248                                            else {
4249                                                    query.append(ORDER_BY_DESC);
4250                                            }
4251                                    }
4252                            }
4253                    }
4254                    else {
4255                            query.append(AddressModelImpl.ORDER_BY_JPQL);
4256                    }
4257    
4258                    String sql = query.toString();
4259    
4260                    Query q = session.createQuery(sql);
4261    
4262                    q.setFirstResult(0);
4263                    q.setMaxResults(2);
4264    
4265                    QueryPos qPos = QueryPos.getInstance(q);
4266    
4267                    qPos.add(companyId);
4268    
4269                    qPos.add(classNameId);
4270    
4271                    qPos.add(classPK);
4272    
4273                    qPos.add(primary);
4274    
4275                    if (orderByComparator != null) {
4276                            Object[] values = orderByComparator.getOrderByConditionValues(address);
4277    
4278                            for (Object value : values) {
4279                                    qPos.add(value);
4280                            }
4281                    }
4282    
4283                    List<Address> list = q.list();
4284    
4285                    if (list.size() == 2) {
4286                            return list.get(1);
4287                    }
4288                    else {
4289                            return null;
4290                    }
4291            }
4292    
4293            /**
4294             * Removes all the addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63; from the database.
4295             *
4296             * @param companyId the company ID
4297             * @param classNameId the class name ID
4298             * @param classPK the class p k
4299             * @param primary the primary
4300             */
4301            @Override
4302            public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
4303                    boolean primary) {
4304                    for (Address address : findByC_C_C_P(companyId, classNameId, classPK,
4305                                    primary, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4306                            remove(address);
4307                    }
4308            }
4309    
4310            /**
4311             * Returns the number of addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
4312             *
4313             * @param companyId the company ID
4314             * @param classNameId the class name ID
4315             * @param classPK the class p k
4316             * @param primary the primary
4317             * @return the number of matching addresses
4318             */
4319            @Override
4320            public int countByC_C_C_P(long companyId, long classNameId, long classPK,
4321                    boolean primary) {
4322                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C_P;
4323    
4324                    Object[] finderArgs = new Object[] {
4325                                    companyId, classNameId, classPK, primary
4326                            };
4327    
4328                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4329                                    this);
4330    
4331                    if (count == null) {
4332                            StringBundler query = new StringBundler(5);
4333    
4334                            query.append(_SQL_COUNT_ADDRESS_WHERE);
4335    
4336                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
4337    
4338                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
4339    
4340                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
4341    
4342                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
4343    
4344                            String sql = query.toString();
4345    
4346                            Session session = null;
4347    
4348                            try {
4349                                    session = openSession();
4350    
4351                                    Query q = session.createQuery(sql);
4352    
4353                                    QueryPos qPos = QueryPos.getInstance(q);
4354    
4355                                    qPos.add(companyId);
4356    
4357                                    qPos.add(classNameId);
4358    
4359                                    qPos.add(classPK);
4360    
4361                                    qPos.add(primary);
4362    
4363                                    count = (Long)q.uniqueResult();
4364    
4365                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4366                            }
4367                            catch (Exception e) {
4368                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4369    
4370                                    throw processException(e);
4371                            }
4372                            finally {
4373                                    closeSession(session);
4374                            }
4375                    }
4376    
4377                    return count.intValue();
4378            }
4379    
4380            private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "address.companyId = ? AND ";
4381            private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "address.classNameId = ? AND ";
4382            private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "address.classPK = ? AND ";
4383            private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "address.primary = ?";
4384    
4385            public AddressPersistenceImpl() {
4386                    setModelClass(Address.class);
4387            }
4388    
4389            /**
4390             * Caches the address in the entity cache if it is enabled.
4391             *
4392             * @param address the address
4393             */
4394            @Override
4395            public void cacheResult(Address address) {
4396                    EntityCacheUtil.putResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
4397                            AddressImpl.class, address.getPrimaryKey(), address);
4398    
4399                    address.resetOriginalValues();
4400            }
4401    
4402            /**
4403             * Caches the addresses in the entity cache if it is enabled.
4404             *
4405             * @param addresses the addresses
4406             */
4407            @Override
4408            public void cacheResult(List<Address> addresses) {
4409                    for (Address address : addresses) {
4410                            if (EntityCacheUtil.getResult(
4411                                                    AddressModelImpl.ENTITY_CACHE_ENABLED,
4412                                                    AddressImpl.class, address.getPrimaryKey()) == null) {
4413                                    cacheResult(address);
4414                            }
4415                            else {
4416                                    address.resetOriginalValues();
4417                            }
4418                    }
4419            }
4420    
4421            /**
4422             * Clears the cache for all addresses.
4423             *
4424             * <p>
4425             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4426             * </p>
4427             */
4428            @Override
4429            public void clearCache() {
4430                    EntityCacheUtil.clearCache(AddressImpl.class);
4431    
4432                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4433                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4434                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4435            }
4436    
4437            /**
4438             * Clears the cache for the address.
4439             *
4440             * <p>
4441             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4442             * </p>
4443             */
4444            @Override
4445            public void clearCache(Address address) {
4446                    EntityCacheUtil.removeResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
4447                            AddressImpl.class, address.getPrimaryKey());
4448    
4449                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4450                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4451            }
4452    
4453            @Override
4454            public void clearCache(List<Address> addresses) {
4455                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4456                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4457    
4458                    for (Address address : addresses) {
4459                            EntityCacheUtil.removeResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
4460                                    AddressImpl.class, address.getPrimaryKey());
4461                    }
4462            }
4463    
4464            /**
4465             * Creates a new address with the primary key. Does not add the address to the database.
4466             *
4467             * @param addressId the primary key for the new address
4468             * @return the new address
4469             */
4470            @Override
4471            public Address create(long addressId) {
4472                    Address address = new AddressImpl();
4473    
4474                    address.setNew(true);
4475                    address.setPrimaryKey(addressId);
4476    
4477                    String uuid = PortalUUIDUtil.generate();
4478    
4479                    address.setUuid(uuid);
4480    
4481                    return address;
4482            }
4483    
4484            /**
4485             * Removes the address with the primary key from the database. Also notifies the appropriate model listeners.
4486             *
4487             * @param addressId the primary key of the address
4488             * @return the address that was removed
4489             * @throws NoSuchAddressException if a address with the primary key could not be found
4490             */
4491            @Override
4492            public Address remove(long addressId) throws NoSuchAddressException {
4493                    return remove((Serializable)addressId);
4494            }
4495    
4496            /**
4497             * Removes the address with the primary key from the database. Also notifies the appropriate model listeners.
4498             *
4499             * @param primaryKey the primary key of the address
4500             * @return the address that was removed
4501             * @throws NoSuchAddressException if a address with the primary key could not be found
4502             */
4503            @Override
4504            public Address remove(Serializable primaryKey)
4505                    throws NoSuchAddressException {
4506                    Session session = null;
4507    
4508                    try {
4509                            session = openSession();
4510    
4511                            Address address = (Address)session.get(AddressImpl.class, primaryKey);
4512    
4513                            if (address == null) {
4514                                    if (_log.isWarnEnabled()) {
4515                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4516                                    }
4517    
4518                                    throw new NoSuchAddressException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4519                                            primaryKey);
4520                            }
4521    
4522                            return remove(address);
4523                    }
4524                    catch (NoSuchAddressException nsee) {
4525                            throw nsee;
4526                    }
4527                    catch (Exception e) {
4528                            throw processException(e);
4529                    }
4530                    finally {
4531                            closeSession(session);
4532                    }
4533            }
4534    
4535            @Override
4536            protected Address removeImpl(Address address) {
4537                    address = toUnwrappedModel(address);
4538    
4539                    Session session = null;
4540    
4541                    try {
4542                            session = openSession();
4543    
4544                            if (!session.contains(address)) {
4545                                    address = (Address)session.get(AddressImpl.class,
4546                                                    address.getPrimaryKeyObj());
4547                            }
4548    
4549                            if (address != null) {
4550                                    session.delete(address);
4551                            }
4552                    }
4553                    catch (Exception e) {
4554                            throw processException(e);
4555                    }
4556                    finally {
4557                            closeSession(session);
4558                    }
4559    
4560                    if (address != null) {
4561                            clearCache(address);
4562                    }
4563    
4564                    return address;
4565            }
4566    
4567            @Override
4568            public Address updateImpl(Address address) {
4569                    address = toUnwrappedModel(address);
4570    
4571                    boolean isNew = address.isNew();
4572    
4573                    AddressModelImpl addressModelImpl = (AddressModelImpl)address;
4574    
4575                    if (Validator.isNull(address.getUuid())) {
4576                            String uuid = PortalUUIDUtil.generate();
4577    
4578                            address.setUuid(uuid);
4579                    }
4580    
4581                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
4582    
4583                    Date now = new Date();
4584    
4585                    if (isNew && (address.getCreateDate() == null)) {
4586                            if (serviceContext == null) {
4587                                    address.setCreateDate(now);
4588                            }
4589                            else {
4590                                    address.setCreateDate(serviceContext.getCreateDate(now));
4591                            }
4592                    }
4593    
4594                    if (!addressModelImpl.hasSetModifiedDate()) {
4595                            if (serviceContext == null) {
4596                                    address.setModifiedDate(now);
4597                            }
4598                            else {
4599                                    address.setModifiedDate(serviceContext.getModifiedDate(now));
4600                            }
4601                    }
4602    
4603                    Session session = null;
4604    
4605                    try {
4606                            session = openSession();
4607    
4608                            if (address.isNew()) {
4609                                    session.save(address);
4610    
4611                                    address.setNew(false);
4612                            }
4613                            else {
4614                                    session.merge(address);
4615                            }
4616                    }
4617                    catch (Exception e) {
4618                            throw processException(e);
4619                    }
4620                    finally {
4621                            closeSession(session);
4622                    }
4623    
4624                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4625    
4626                    if (isNew || !AddressModelImpl.COLUMN_BITMASK_ENABLED) {
4627                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4628                    }
4629    
4630                    else {
4631                            if ((addressModelImpl.getColumnBitmask() &
4632                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4633                                    Object[] args = new Object[] { addressModelImpl.getOriginalUuid() };
4634    
4635                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4636                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4637                                            args);
4638    
4639                                    args = new Object[] { addressModelImpl.getUuid() };
4640    
4641                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4642                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4643                                            args);
4644                            }
4645    
4646                            if ((addressModelImpl.getColumnBitmask() &
4647                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4648                                    Object[] args = new Object[] {
4649                                                    addressModelImpl.getOriginalUuid(),
4650                                                    addressModelImpl.getOriginalCompanyId()
4651                                            };
4652    
4653                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4654                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4655                                            args);
4656    
4657                                    args = new Object[] {
4658                                                    addressModelImpl.getUuid(),
4659                                                    addressModelImpl.getCompanyId()
4660                                            };
4661    
4662                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4663                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4664                                            args);
4665                            }
4666    
4667                            if ((addressModelImpl.getColumnBitmask() &
4668                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4669                                    Object[] args = new Object[] {
4670                                                    addressModelImpl.getOriginalCompanyId()
4671                                            };
4672    
4673                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4674                                            args);
4675                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4676                                            args);
4677    
4678                                    args = new Object[] { addressModelImpl.getCompanyId() };
4679    
4680                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4681                                            args);
4682                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4683                                            args);
4684                            }
4685    
4686                            if ((addressModelImpl.getColumnBitmask() &
4687                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
4688                                    Object[] args = new Object[] {
4689                                                    addressModelImpl.getOriginalUserId()
4690                                            };
4691    
4692                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4693                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4694                                            args);
4695    
4696                                    args = new Object[] { addressModelImpl.getUserId() };
4697    
4698                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4699                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4700                                            args);
4701                            }
4702    
4703                            if ((addressModelImpl.getColumnBitmask() &
4704                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
4705                                    Object[] args = new Object[] {
4706                                                    addressModelImpl.getOriginalCompanyId(),
4707                                                    addressModelImpl.getOriginalClassNameId()
4708                                            };
4709    
4710                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4711                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4712                                            args);
4713    
4714                                    args = new Object[] {
4715                                                    addressModelImpl.getCompanyId(),
4716                                                    addressModelImpl.getClassNameId()
4717                                            };
4718    
4719                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4720                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4721                                            args);
4722                            }
4723    
4724                            if ((addressModelImpl.getColumnBitmask() &
4725                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
4726                                    Object[] args = new Object[] {
4727                                                    addressModelImpl.getOriginalCompanyId(),
4728                                                    addressModelImpl.getOriginalClassNameId(),
4729                                                    addressModelImpl.getOriginalClassPK()
4730                                            };
4731    
4732                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4733                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4734                                            args);
4735    
4736                                    args = new Object[] {
4737                                                    addressModelImpl.getCompanyId(),
4738                                                    addressModelImpl.getClassNameId(),
4739                                                    addressModelImpl.getClassPK()
4740                                            };
4741    
4742                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4743                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4744                                            args);
4745                            }
4746    
4747                            if ((addressModelImpl.getColumnBitmask() &
4748                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_M.getColumnBitmask()) != 0) {
4749                                    Object[] args = new Object[] {
4750                                                    addressModelImpl.getOriginalCompanyId(),
4751                                                    addressModelImpl.getOriginalClassNameId(),
4752                                                    addressModelImpl.getOriginalClassPK(),
4753                                                    addressModelImpl.getOriginalMailing()
4754                                            };
4755    
4756                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_M, args);
4757                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_M,
4758                                            args);
4759    
4760                                    args = new Object[] {
4761                                                    addressModelImpl.getCompanyId(),
4762                                                    addressModelImpl.getClassNameId(),
4763                                                    addressModelImpl.getClassPK(),
4764                                                    addressModelImpl.getMailing()
4765                                            };
4766    
4767                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_M, args);
4768                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_M,
4769                                            args);
4770                            }
4771    
4772                            if ((addressModelImpl.getColumnBitmask() &
4773                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P.getColumnBitmask()) != 0) {
4774                                    Object[] args = new Object[] {
4775                                                    addressModelImpl.getOriginalCompanyId(),
4776                                                    addressModelImpl.getOriginalClassNameId(),
4777                                                    addressModelImpl.getOriginalClassPK(),
4778                                                    addressModelImpl.getOriginalPrimary()
4779                                            };
4780    
4781                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4782                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4783                                            args);
4784    
4785                                    args = new Object[] {
4786                                                    addressModelImpl.getCompanyId(),
4787                                                    addressModelImpl.getClassNameId(),
4788                                                    addressModelImpl.getClassPK(),
4789                                                    addressModelImpl.getPrimary()
4790                                            };
4791    
4792                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4793                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4794                                            args);
4795                            }
4796                    }
4797    
4798                    EntityCacheUtil.putResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
4799                            AddressImpl.class, address.getPrimaryKey(), address, false);
4800    
4801                    address.resetOriginalValues();
4802    
4803                    return address;
4804            }
4805    
4806            protected Address toUnwrappedModel(Address address) {
4807                    if (address instanceof AddressImpl) {
4808                            return address;
4809                    }
4810    
4811                    AddressImpl addressImpl = new AddressImpl();
4812    
4813                    addressImpl.setNew(address.isNew());
4814                    addressImpl.setPrimaryKey(address.getPrimaryKey());
4815    
4816                    addressImpl.setMvccVersion(address.getMvccVersion());
4817                    addressImpl.setUuid(address.getUuid());
4818                    addressImpl.setAddressId(address.getAddressId());
4819                    addressImpl.setCompanyId(address.getCompanyId());
4820                    addressImpl.setUserId(address.getUserId());
4821                    addressImpl.setUserName(address.getUserName());
4822                    addressImpl.setCreateDate(address.getCreateDate());
4823                    addressImpl.setModifiedDate(address.getModifiedDate());
4824                    addressImpl.setClassNameId(address.getClassNameId());
4825                    addressImpl.setClassPK(address.getClassPK());
4826                    addressImpl.setStreet1(address.getStreet1());
4827                    addressImpl.setStreet2(address.getStreet2());
4828                    addressImpl.setStreet3(address.getStreet3());
4829                    addressImpl.setCity(address.getCity());
4830                    addressImpl.setZip(address.getZip());
4831                    addressImpl.setRegionId(address.getRegionId());
4832                    addressImpl.setCountryId(address.getCountryId());
4833                    addressImpl.setTypeId(address.getTypeId());
4834                    addressImpl.setMailing(address.isMailing());
4835                    addressImpl.setPrimary(address.isPrimary());
4836    
4837                    return addressImpl;
4838            }
4839    
4840            /**
4841             * Returns the address with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4842             *
4843             * @param primaryKey the primary key of the address
4844             * @return the address
4845             * @throws NoSuchAddressException if a address with the primary key could not be found
4846             */
4847            @Override
4848            public Address findByPrimaryKey(Serializable primaryKey)
4849                    throws NoSuchAddressException {
4850                    Address address = fetchByPrimaryKey(primaryKey);
4851    
4852                    if (address == null) {
4853                            if (_log.isWarnEnabled()) {
4854                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4855                            }
4856    
4857                            throw new NoSuchAddressException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4858                                    primaryKey);
4859                    }
4860    
4861                    return address;
4862            }
4863    
4864            /**
4865             * Returns the address with the primary key or throws a {@link NoSuchAddressException} if it could not be found.
4866             *
4867             * @param addressId the primary key of the address
4868             * @return the address
4869             * @throws NoSuchAddressException if a address with the primary key could not be found
4870             */
4871            @Override
4872            public Address findByPrimaryKey(long addressId)
4873                    throws NoSuchAddressException {
4874                    return findByPrimaryKey((Serializable)addressId);
4875            }
4876    
4877            /**
4878             * Returns the address with the primary key or returns <code>null</code> if it could not be found.
4879             *
4880             * @param primaryKey the primary key of the address
4881             * @return the address, or <code>null</code> if a address with the primary key could not be found
4882             */
4883            @Override
4884            public Address fetchByPrimaryKey(Serializable primaryKey) {
4885                    Address address = (Address)EntityCacheUtil.getResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
4886                                    AddressImpl.class, primaryKey);
4887    
4888                    if (address == _nullAddress) {
4889                            return null;
4890                    }
4891    
4892                    if (address == null) {
4893                            Session session = null;
4894    
4895                            try {
4896                                    session = openSession();
4897    
4898                                    address = (Address)session.get(AddressImpl.class, primaryKey);
4899    
4900                                    if (address != null) {
4901                                            cacheResult(address);
4902                                    }
4903                                    else {
4904                                            EntityCacheUtil.putResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
4905                                                    AddressImpl.class, primaryKey, _nullAddress);
4906                                    }
4907                            }
4908                            catch (Exception e) {
4909                                    EntityCacheUtil.removeResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
4910                                            AddressImpl.class, primaryKey);
4911    
4912                                    throw processException(e);
4913                            }
4914                            finally {
4915                                    closeSession(session);
4916                            }
4917                    }
4918    
4919                    return address;
4920            }
4921    
4922            /**
4923             * Returns the address with the primary key or returns <code>null</code> if it could not be found.
4924             *
4925             * @param addressId the primary key of the address
4926             * @return the address, or <code>null</code> if a address with the primary key could not be found
4927             */
4928            @Override
4929            public Address fetchByPrimaryKey(long addressId) {
4930                    return fetchByPrimaryKey((Serializable)addressId);
4931            }
4932    
4933            @Override
4934            public Map<Serializable, Address> fetchByPrimaryKeys(
4935                    Set<Serializable> primaryKeys) {
4936                    if (primaryKeys.isEmpty()) {
4937                            return Collections.emptyMap();
4938                    }
4939    
4940                    Map<Serializable, Address> map = new HashMap<Serializable, Address>();
4941    
4942                    if (primaryKeys.size() == 1) {
4943                            Iterator<Serializable> iterator = primaryKeys.iterator();
4944    
4945                            Serializable primaryKey = iterator.next();
4946    
4947                            Address address = fetchByPrimaryKey(primaryKey);
4948    
4949                            if (address != null) {
4950                                    map.put(primaryKey, address);
4951                            }
4952    
4953                            return map;
4954                    }
4955    
4956                    Set<Serializable> uncachedPrimaryKeys = null;
4957    
4958                    for (Serializable primaryKey : primaryKeys) {
4959                            Address address = (Address)EntityCacheUtil.getResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
4960                                            AddressImpl.class, primaryKey);
4961    
4962                            if (address == null) {
4963                                    if (uncachedPrimaryKeys == null) {
4964                                            uncachedPrimaryKeys = new HashSet<Serializable>();
4965                                    }
4966    
4967                                    uncachedPrimaryKeys.add(primaryKey);
4968                            }
4969                            else {
4970                                    map.put(primaryKey, address);
4971                            }
4972                    }
4973    
4974                    if (uncachedPrimaryKeys == null) {
4975                            return map;
4976                    }
4977    
4978                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
4979                                    1);
4980    
4981                    query.append(_SQL_SELECT_ADDRESS_WHERE_PKS_IN);
4982    
4983                    for (Serializable primaryKey : uncachedPrimaryKeys) {
4984                            query.append(String.valueOf(primaryKey));
4985    
4986                            query.append(StringPool.COMMA);
4987                    }
4988    
4989                    query.setIndex(query.index() - 1);
4990    
4991                    query.append(StringPool.CLOSE_PARENTHESIS);
4992    
4993                    String sql = query.toString();
4994    
4995                    Session session = null;
4996    
4997                    try {
4998                            session = openSession();
4999    
5000                            Query q = session.createQuery(sql);
5001    
5002                            for (Address address : (List<Address>)q.list()) {
5003                                    map.put(address.getPrimaryKeyObj(), address);
5004    
5005                                    cacheResult(address);
5006    
5007                                    uncachedPrimaryKeys.remove(address.getPrimaryKeyObj());
5008                            }
5009    
5010                            for (Serializable primaryKey : uncachedPrimaryKeys) {
5011                                    EntityCacheUtil.putResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
5012                                            AddressImpl.class, primaryKey, _nullAddress);
5013                            }
5014                    }
5015                    catch (Exception e) {
5016                            throw processException(e);
5017                    }
5018                    finally {
5019                            closeSession(session);
5020                    }
5021    
5022                    return map;
5023            }
5024    
5025            /**
5026             * Returns all the addresses.
5027             *
5028             * @return the addresses
5029             */
5030            @Override
5031            public List<Address> findAll() {
5032                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5033            }
5034    
5035            /**
5036             * Returns a range of all the addresses.
5037             *
5038             * <p>
5039             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5040             * </p>
5041             *
5042             * @param start the lower bound of the range of addresses
5043             * @param end the upper bound of the range of addresses (not inclusive)
5044             * @return the range of addresses
5045             */
5046            @Override
5047            public List<Address> findAll(int start, int end) {
5048                    return findAll(start, end, null);
5049            }
5050    
5051            /**
5052             * Returns an ordered range of all the addresses.
5053             *
5054             * <p>
5055             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AddressModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5056             * </p>
5057             *
5058             * @param start the lower bound of the range of addresses
5059             * @param end the upper bound of the range of addresses (not inclusive)
5060             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5061             * @return the ordered range of addresses
5062             */
5063            @Override
5064            public List<Address> findAll(int start, int end,
5065                    OrderByComparator<Address> orderByComparator) {
5066                    boolean pagination = true;
5067                    FinderPath finderPath = null;
5068                    Object[] finderArgs = null;
5069    
5070                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5071                                    (orderByComparator == null)) {
5072                            pagination = false;
5073                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5074                            finderArgs = FINDER_ARGS_EMPTY;
5075                    }
5076                    else {
5077                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5078                            finderArgs = new Object[] { start, end, orderByComparator };
5079                    }
5080    
5081                    List<Address> list = (List<Address>)FinderCacheUtil.getResult(finderPath,
5082                                    finderArgs, this);
5083    
5084                    if (list == null) {
5085                            StringBundler query = null;
5086                            String sql = null;
5087    
5088                            if (orderByComparator != null) {
5089                                    query = new StringBundler(2 +
5090                                                    (orderByComparator.getOrderByFields().length * 3));
5091    
5092                                    query.append(_SQL_SELECT_ADDRESS);
5093    
5094                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5095                                            orderByComparator);
5096    
5097                                    sql = query.toString();
5098                            }
5099                            else {
5100                                    sql = _SQL_SELECT_ADDRESS;
5101    
5102                                    if (pagination) {
5103                                            sql = sql.concat(AddressModelImpl.ORDER_BY_JPQL);
5104                                    }
5105                            }
5106    
5107                            Session session = null;
5108    
5109                            try {
5110                                    session = openSession();
5111    
5112                                    Query q = session.createQuery(sql);
5113    
5114                                    if (!pagination) {
5115                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
5116                                                            start, end, false);
5117    
5118                                            Collections.sort(list);
5119    
5120                                            list = Collections.unmodifiableList(list);
5121                                    }
5122                                    else {
5123                                            list = (List<Address>)QueryUtil.list(q, getDialect(),
5124                                                            start, end);
5125                                    }
5126    
5127                                    cacheResult(list);
5128    
5129                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5130                            }
5131                            catch (Exception e) {
5132                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5133    
5134                                    throw processException(e);
5135                            }
5136                            finally {
5137                                    closeSession(session);
5138                            }
5139                    }
5140    
5141                    return list;
5142            }
5143    
5144            /**
5145             * Removes all the addresses from the database.
5146             *
5147             */
5148            @Override
5149            public void removeAll() {
5150                    for (Address address : findAll()) {
5151                            remove(address);
5152                    }
5153            }
5154    
5155            /**
5156             * Returns the number of addresses.
5157             *
5158             * @return the number of addresses
5159             */
5160            @Override
5161            public int countAll() {
5162                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5163                                    FINDER_ARGS_EMPTY, this);
5164    
5165                    if (count == null) {
5166                            Session session = null;
5167    
5168                            try {
5169                                    session = openSession();
5170    
5171                                    Query q = session.createQuery(_SQL_COUNT_ADDRESS);
5172    
5173                                    count = (Long)q.uniqueResult();
5174    
5175                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5176                                            FINDER_ARGS_EMPTY, count);
5177                            }
5178                            catch (Exception e) {
5179                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5180                                            FINDER_ARGS_EMPTY);
5181    
5182                                    throw processException(e);
5183                            }
5184                            finally {
5185                                    closeSession(session);
5186                            }
5187                    }
5188    
5189                    return count.intValue();
5190            }
5191    
5192            @Override
5193            protected Set<String> getBadColumnNames() {
5194                    return _badColumnNames;
5195            }
5196    
5197            /**
5198             * Initializes the address persistence.
5199             */
5200            public void afterPropertiesSet() {
5201            }
5202    
5203            public void destroy() {
5204                    EntityCacheUtil.removeCache(AddressImpl.class.getName());
5205                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5206                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5207                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5208            }
5209    
5210            private static final String _SQL_SELECT_ADDRESS = "SELECT address FROM Address address";
5211            private static final String _SQL_SELECT_ADDRESS_WHERE_PKS_IN = "SELECT address FROM Address address WHERE addressId IN (";
5212            private static final String _SQL_SELECT_ADDRESS_WHERE = "SELECT address FROM Address address WHERE ";
5213            private static final String _SQL_COUNT_ADDRESS = "SELECT COUNT(address) FROM Address address";
5214            private static final String _SQL_COUNT_ADDRESS_WHERE = "SELECT COUNT(address) FROM Address address WHERE ";
5215            private static final String _ORDER_BY_ENTITY_ALIAS = "address.";
5216            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Address exists with the primary key ";
5217            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Address exists with the key {";
5218            private static final Log _log = LogFactoryUtil.getLog(AddressPersistenceImpl.class);
5219            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
5220                                    "uuid", "primary"
5221                            });
5222            private static final Address _nullAddress = new AddressImpl() {
5223                            @Override
5224                            public Object clone() {
5225                                    return this;
5226                            }
5227    
5228                            @Override
5229                            public CacheModel<Address> toCacheModel() {
5230                                    return _nullAddressCacheModel;
5231                            }
5232                    };
5233    
5234            private static final CacheModel<Address> _nullAddressCacheModel = new NullCacheModel();
5235    
5236            private static class NullCacheModel implements CacheModel<Address>,
5237                    MVCCModel {
5238                    @Override
5239                    public long getMvccVersion() {
5240                            return -1;
5241                    }
5242    
5243                    @Override
5244                    public void setMvccVersion(long mvccVersion) {
5245                    }
5246    
5247                    @Override
5248                    public Address toEntityModel() {
5249                            return _nullAddress;
5250                    }
5251            }
5252    }