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