1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.NoSuchAddressException;
18  import com.liferay.portal.NoSuchModelException;
19  import com.liferay.portal.SystemException;
20  import com.liferay.portal.kernel.annotation.BeanReference;
21  import com.liferay.portal.kernel.cache.CacheRegistry;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.model.Address;
37  import com.liferay.portal.model.ModelListener;
38  import com.liferay.portal.model.impl.AddressImpl;
39  import com.liferay.portal.model.impl.AddressModelImpl;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import java.io.Serializable;
43  
44  import java.util.ArrayList;
45  import java.util.Collections;
46  import java.util.List;
47  
48  /**
49   * <a href="AddressPersistenceImpl.java.html"><b><i>View Source</i></b></a>
50   *
51   * <p>
52   * ServiceBuilder generated this class. Modifications in this class will be
53   * overwritten the next time is generated.
54   * </p>
55   *
56   * @author    Brian Wing Shun Chan
57   * @see       AddressPersistence
58   * @see       AddressUtil
59   * @generated
60   */
61  public class AddressPersistenceImpl extends BasePersistenceImpl<Address>
62      implements AddressPersistence {
63      public static final String FINDER_CLASS_NAME_ENTITY = AddressImpl.class.getName();
64      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
65          ".List";
66      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
67              AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
68              "findByCompanyId", new String[] { Long.class.getName() });
69      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
70              AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
71              "findByCompanyId",
72              new String[] {
73                  Long.class.getName(),
74                  
75              "java.lang.Integer", "java.lang.Integer",
76                  "com.liferay.portal.kernel.util.OrderByComparator"
77              });
78      public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
79              AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
80              "countByCompanyId", new String[] { Long.class.getName() });
81      public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
82              AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
83              "findByUserId", new String[] { Long.class.getName() });
84      public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
85              AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
86              "findByUserId",
87              new String[] {
88                  Long.class.getName(),
89                  
90              "java.lang.Integer", "java.lang.Integer",
91                  "com.liferay.portal.kernel.util.OrderByComparator"
92              });
93      public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
94              AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
95              "countByUserId", new String[] { Long.class.getName() });
96      public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
97              AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
98              "findByC_C",
99              new String[] { Long.class.getName(), Long.class.getName() });
100     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
101             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102             "findByC_C",
103             new String[] {
104                 Long.class.getName(), Long.class.getName(),
105                 
106             "java.lang.Integer", "java.lang.Integer",
107                 "com.liferay.portal.kernel.util.OrderByComparator"
108             });
109     public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
110             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111             "countByC_C",
112             new String[] { Long.class.getName(), Long.class.getName() });
113     public static final FinderPath FINDER_PATH_FIND_BY_C_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
114             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
115             "findByC_C_C",
116             new String[] {
117                 Long.class.getName(), Long.class.getName(), Long.class.getName()
118             });
119     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
120             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121             "findByC_C_C",
122             new String[] {
123                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
124                 
125             "java.lang.Integer", "java.lang.Integer",
126                 "com.liferay.portal.kernel.util.OrderByComparator"
127             });
128     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
129             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130             "countByC_C_C",
131             new String[] {
132                 Long.class.getName(), Long.class.getName(), Long.class.getName()
133             });
134     public static final FinderPath FINDER_PATH_FIND_BY_C_C_C_M = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
135             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
136             "findByC_C_C_M",
137             new String[] {
138                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
139                 Boolean.class.getName()
140             });
141     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C_C_M = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
142             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
143             "findByC_C_C_M",
144             new String[] {
145                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
146                 Boolean.class.getName(),
147                 
148             "java.lang.Integer", "java.lang.Integer",
149                 "com.liferay.portal.kernel.util.OrderByComparator"
150             });
151     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_M = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
152             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
153             "countByC_C_C_M",
154             new String[] {
155                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
156                 Boolean.class.getName()
157             });
158     public static final FinderPath FINDER_PATH_FIND_BY_C_C_C_P = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
159             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
160             "findByC_C_C_P",
161             new String[] {
162                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
163                 Boolean.class.getName()
164             });
165     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C_C_P = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
166             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
167             "findByC_C_C_P",
168             new String[] {
169                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
170                 Boolean.class.getName(),
171                 
172             "java.lang.Integer", "java.lang.Integer",
173                 "com.liferay.portal.kernel.util.OrderByComparator"
174             });
175     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
176             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
177             "countByC_C_C_P",
178             new String[] {
179                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
180                 Boolean.class.getName()
181             });
182     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
183             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
184             "findAll", new String[0]);
185     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AddressModelImpl.ENTITY_CACHE_ENABLED,
186             AddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
187             "countAll", new String[0]);
188 
189     public void cacheResult(Address address) {
190         EntityCacheUtil.putResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
191             AddressImpl.class, address.getPrimaryKey(), address);
192     }
193 
194     public void cacheResult(List<Address> addresses) {
195         for (Address address : addresses) {
196             if (EntityCacheUtil.getResult(
197                         AddressModelImpl.ENTITY_CACHE_ENABLED,
198                         AddressImpl.class, address.getPrimaryKey(), this) == null) {
199                 cacheResult(address);
200             }
201         }
202     }
203 
204     public void clearCache() {
205         CacheRegistry.clear(AddressImpl.class.getName());
206         EntityCacheUtil.clearCache(AddressImpl.class.getName());
207         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
208         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
209     }
210 
211     public Address create(long addressId) {
212         Address address = new AddressImpl();
213 
214         address.setNew(true);
215         address.setPrimaryKey(addressId);
216 
217         return address;
218     }
219 
220     public Address remove(Serializable primaryKey)
221         throws NoSuchModelException, SystemException {
222         return remove(((Long)primaryKey).longValue());
223     }
224 
225     public Address remove(long addressId)
226         throws NoSuchAddressException, SystemException {
227         Session session = null;
228 
229         try {
230             session = openSession();
231 
232             Address address = (Address)session.get(AddressImpl.class,
233                     new Long(addressId));
234 
235             if (address == null) {
236                 if (_log.isWarnEnabled()) {
237                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + addressId);
238                 }
239 
240                 throw new NoSuchAddressException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
241                     addressId);
242             }
243 
244             return remove(address);
245         }
246         catch (NoSuchAddressException nsee) {
247             throw nsee;
248         }
249         catch (Exception e) {
250             throw processException(e);
251         }
252         finally {
253             closeSession(session);
254         }
255     }
256 
257     public Address remove(Address address) throws SystemException {
258         for (ModelListener<Address> listener : listeners) {
259             listener.onBeforeRemove(address);
260         }
261 
262         address = removeImpl(address);
263 
264         for (ModelListener<Address> listener : listeners) {
265             listener.onAfterRemove(address);
266         }
267 
268         return address;
269     }
270 
271     protected Address removeImpl(Address address) throws SystemException {
272         address = toUnwrappedModel(address);
273 
274         Session session = null;
275 
276         try {
277             session = openSession();
278 
279             if (address.isCachedModel() || BatchSessionUtil.isEnabled()) {
280                 Object staleObject = session.get(AddressImpl.class,
281                         address.getPrimaryKeyObj());
282 
283                 if (staleObject != null) {
284                     session.evict(staleObject);
285                 }
286             }
287 
288             session.delete(address);
289 
290             session.flush();
291         }
292         catch (Exception e) {
293             throw processException(e);
294         }
295         finally {
296             closeSession(session);
297         }
298 
299         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
300 
301         EntityCacheUtil.removeResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
302             AddressImpl.class, address.getPrimaryKey());
303 
304         return address;
305     }
306 
307     /**
308      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
309      */
310     public Address update(Address address) throws SystemException {
311         if (_log.isWarnEnabled()) {
312             _log.warn(
313                 "Using the deprecated update(Address address) method. Use update(Address address, boolean merge) instead.");
314         }
315 
316         return update(address, false);
317     }
318 
319     public Address updateImpl(com.liferay.portal.model.Address address,
320         boolean merge) throws SystemException {
321         address = toUnwrappedModel(address);
322 
323         Session session = null;
324 
325         try {
326             session = openSession();
327 
328             BatchSessionUtil.update(session, address, merge);
329 
330             address.setNew(false);
331         }
332         catch (Exception e) {
333             throw processException(e);
334         }
335         finally {
336             closeSession(session);
337         }
338 
339         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
340 
341         EntityCacheUtil.putResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
342             AddressImpl.class, address.getPrimaryKey(), address);
343 
344         return address;
345     }
346 
347     protected Address toUnwrappedModel(Address address) {
348         if (address instanceof AddressImpl) {
349             return address;
350         }
351 
352         AddressImpl addressImpl = new AddressImpl();
353 
354         addressImpl.setNew(address.isNew());
355         addressImpl.setPrimaryKey(address.getPrimaryKey());
356 
357         addressImpl.setAddressId(address.getAddressId());
358         addressImpl.setCompanyId(address.getCompanyId());
359         addressImpl.setUserId(address.getUserId());
360         addressImpl.setUserName(address.getUserName());
361         addressImpl.setCreateDate(address.getCreateDate());
362         addressImpl.setModifiedDate(address.getModifiedDate());
363         addressImpl.setClassNameId(address.getClassNameId());
364         addressImpl.setClassPK(address.getClassPK());
365         addressImpl.setStreet1(address.getStreet1());
366         addressImpl.setStreet2(address.getStreet2());
367         addressImpl.setStreet3(address.getStreet3());
368         addressImpl.setCity(address.getCity());
369         addressImpl.setZip(address.getZip());
370         addressImpl.setRegionId(address.getRegionId());
371         addressImpl.setCountryId(address.getCountryId());
372         addressImpl.setTypeId(address.getTypeId());
373         addressImpl.setMailing(address.isMailing());
374         addressImpl.setPrimary(address.isPrimary());
375 
376         return addressImpl;
377     }
378 
379     public Address findByPrimaryKey(Serializable primaryKey)
380         throws NoSuchModelException, SystemException {
381         return findByPrimaryKey(((Long)primaryKey).longValue());
382     }
383 
384     public Address findByPrimaryKey(long addressId)
385         throws NoSuchAddressException, SystemException {
386         Address address = fetchByPrimaryKey(addressId);
387 
388         if (address == null) {
389             if (_log.isWarnEnabled()) {
390                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + addressId);
391             }
392 
393             throw new NoSuchAddressException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
394                 addressId);
395         }
396 
397         return address;
398     }
399 
400     public Address fetchByPrimaryKey(Serializable primaryKey)
401         throws SystemException {
402         return fetchByPrimaryKey(((Long)primaryKey).longValue());
403     }
404 
405     public Address fetchByPrimaryKey(long addressId) throws SystemException {
406         Address address = (Address)EntityCacheUtil.getResult(AddressModelImpl.ENTITY_CACHE_ENABLED,
407                 AddressImpl.class, addressId, this);
408 
409         if (address == null) {
410             Session session = null;
411 
412             try {
413                 session = openSession();
414 
415                 address = (Address)session.get(AddressImpl.class,
416                         new Long(addressId));
417             }
418             catch (Exception e) {
419                 throw processException(e);
420             }
421             finally {
422                 if (address != null) {
423                     cacheResult(address);
424                 }
425 
426                 closeSession(session);
427             }
428         }
429 
430         return address;
431     }
432 
433     public List<Address> findByCompanyId(long companyId)
434         throws SystemException {
435         Object[] finderArgs = new Object[] { new Long(companyId) };
436 
437         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
438                 finderArgs, this);
439 
440         if (list == null) {
441             Session session = null;
442 
443             try {
444                 session = openSession();
445 
446                 StringBundler query = new StringBundler(3);
447 
448                 query.append(_SQL_SELECT_ADDRESS_WHERE);
449 
450                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
451 
452                 query.append(AddressModelImpl.ORDER_BY_JPQL);
453 
454                 String sql = query.toString();
455 
456                 Query q = session.createQuery(sql);
457 
458                 QueryPos qPos = QueryPos.getInstance(q);
459 
460                 qPos.add(companyId);
461 
462                 list = q.list();
463             }
464             catch (Exception e) {
465                 throw processException(e);
466             }
467             finally {
468                 if (list == null) {
469                     list = new ArrayList<Address>();
470                 }
471 
472                 cacheResult(list);
473 
474                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
475                     finderArgs, list);
476 
477                 closeSession(session);
478             }
479         }
480 
481         return list;
482     }
483 
484     public List<Address> findByCompanyId(long companyId, int start, int end)
485         throws SystemException {
486         return findByCompanyId(companyId, start, end, null);
487     }
488 
489     public List<Address> findByCompanyId(long companyId, int start, int end,
490         OrderByComparator orderByComparator) throws SystemException {
491         Object[] finderArgs = new Object[] {
492                 new Long(companyId),
493                 
494                 String.valueOf(start), String.valueOf(end),
495                 String.valueOf(orderByComparator)
496             };
497 
498         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
499                 finderArgs, this);
500 
501         if (list == null) {
502             Session session = null;
503 
504             try {
505                 session = openSession();
506 
507                 StringBundler query = null;
508 
509                 if (orderByComparator != null) {
510                     query = new StringBundler(3 +
511                             (orderByComparator.getOrderByFields().length * 3));
512                 }
513                 else {
514                     query = new StringBundler(3);
515                 }
516 
517                 query.append(_SQL_SELECT_ADDRESS_WHERE);
518 
519                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
520 
521                 if (orderByComparator != null) {
522                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
523                         orderByComparator);
524                 }
525 
526                 else {
527                     query.append(AddressModelImpl.ORDER_BY_JPQL);
528                 }
529 
530                 String sql = query.toString();
531 
532                 Query q = session.createQuery(sql);
533 
534                 QueryPos qPos = QueryPos.getInstance(q);
535 
536                 qPos.add(companyId);
537 
538                 list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
539             }
540             catch (Exception e) {
541                 throw processException(e);
542             }
543             finally {
544                 if (list == null) {
545                     list = new ArrayList<Address>();
546                 }
547 
548                 cacheResult(list);
549 
550                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
551                     finderArgs, list);
552 
553                 closeSession(session);
554             }
555         }
556 
557         return list;
558     }
559 
560     public Address findByCompanyId_First(long companyId,
561         OrderByComparator orderByComparator)
562         throws NoSuchAddressException, SystemException {
563         List<Address> list = findByCompanyId(companyId, 0, 1, orderByComparator);
564 
565         if (list.isEmpty()) {
566             StringBundler msg = new StringBundler(4);
567 
568             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
569 
570             msg.append("companyId=");
571             msg.append(companyId);
572 
573             msg.append(StringPool.CLOSE_CURLY_BRACE);
574 
575             throw new NoSuchAddressException(msg.toString());
576         }
577         else {
578             return list.get(0);
579         }
580     }
581 
582     public Address findByCompanyId_Last(long companyId,
583         OrderByComparator orderByComparator)
584         throws NoSuchAddressException, SystemException {
585         int count = countByCompanyId(companyId);
586 
587         List<Address> list = findByCompanyId(companyId, count - 1, count,
588                 orderByComparator);
589 
590         if (list.isEmpty()) {
591             StringBundler msg = new StringBundler(4);
592 
593             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
594 
595             msg.append("companyId=");
596             msg.append(companyId);
597 
598             msg.append(StringPool.CLOSE_CURLY_BRACE);
599 
600             throw new NoSuchAddressException(msg.toString());
601         }
602         else {
603             return list.get(0);
604         }
605     }
606 
607     public Address[] findByCompanyId_PrevAndNext(long addressId,
608         long companyId, OrderByComparator orderByComparator)
609         throws NoSuchAddressException, SystemException {
610         Address address = findByPrimaryKey(addressId);
611 
612         int count = countByCompanyId(companyId);
613 
614         Session session = null;
615 
616         try {
617             session = openSession();
618 
619             StringBundler query = null;
620 
621             if (orderByComparator != null) {
622                 query = new StringBundler(3 +
623                         (orderByComparator.getOrderByFields().length * 3));
624             }
625             else {
626                 query = new StringBundler(3);
627             }
628 
629             query.append(_SQL_SELECT_ADDRESS_WHERE);
630 
631             query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
632 
633             if (orderByComparator != null) {
634                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
635                     orderByComparator);
636             }
637 
638             else {
639                 query.append(AddressModelImpl.ORDER_BY_JPQL);
640             }
641 
642             String sql = query.toString();
643 
644             Query q = session.createQuery(sql);
645 
646             QueryPos qPos = QueryPos.getInstance(q);
647 
648             qPos.add(companyId);
649 
650             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
651                     orderByComparator, address);
652 
653             Address[] array = new AddressImpl[3];
654 
655             array[0] = (Address)objArray[0];
656             array[1] = (Address)objArray[1];
657             array[2] = (Address)objArray[2];
658 
659             return array;
660         }
661         catch (Exception e) {
662             throw processException(e);
663         }
664         finally {
665             closeSession(session);
666         }
667     }
668 
669     public List<Address> findByUserId(long userId) throws SystemException {
670         Object[] finderArgs = new Object[] { new Long(userId) };
671 
672         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
673                 finderArgs, this);
674 
675         if (list == null) {
676             Session session = null;
677 
678             try {
679                 session = openSession();
680 
681                 StringBundler query = new StringBundler(3);
682 
683                 query.append(_SQL_SELECT_ADDRESS_WHERE);
684 
685                 query.append(_FINDER_COLUMN_USERID_USERID_2);
686 
687                 query.append(AddressModelImpl.ORDER_BY_JPQL);
688 
689                 String sql = query.toString();
690 
691                 Query q = session.createQuery(sql);
692 
693                 QueryPos qPos = QueryPos.getInstance(q);
694 
695                 qPos.add(userId);
696 
697                 list = q.list();
698             }
699             catch (Exception e) {
700                 throw processException(e);
701             }
702             finally {
703                 if (list == null) {
704                     list = new ArrayList<Address>();
705                 }
706 
707                 cacheResult(list);
708 
709                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
710                     finderArgs, list);
711 
712                 closeSession(session);
713             }
714         }
715 
716         return list;
717     }
718 
719     public List<Address> findByUserId(long userId, int start, int end)
720         throws SystemException {
721         return findByUserId(userId, start, end, null);
722     }
723 
724     public List<Address> findByUserId(long userId, int start, int end,
725         OrderByComparator orderByComparator) throws SystemException {
726         Object[] finderArgs = new Object[] {
727                 new Long(userId),
728                 
729                 String.valueOf(start), String.valueOf(end),
730                 String.valueOf(orderByComparator)
731             };
732 
733         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
734                 finderArgs, this);
735 
736         if (list == null) {
737             Session session = null;
738 
739             try {
740                 session = openSession();
741 
742                 StringBundler query = null;
743 
744                 if (orderByComparator != null) {
745                     query = new StringBundler(3 +
746                             (orderByComparator.getOrderByFields().length * 3));
747                 }
748                 else {
749                     query = new StringBundler(3);
750                 }
751 
752                 query.append(_SQL_SELECT_ADDRESS_WHERE);
753 
754                 query.append(_FINDER_COLUMN_USERID_USERID_2);
755 
756                 if (orderByComparator != null) {
757                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
758                         orderByComparator);
759                 }
760 
761                 else {
762                     query.append(AddressModelImpl.ORDER_BY_JPQL);
763                 }
764 
765                 String sql = query.toString();
766 
767                 Query q = session.createQuery(sql);
768 
769                 QueryPos qPos = QueryPos.getInstance(q);
770 
771                 qPos.add(userId);
772 
773                 list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
774             }
775             catch (Exception e) {
776                 throw processException(e);
777             }
778             finally {
779                 if (list == null) {
780                     list = new ArrayList<Address>();
781                 }
782 
783                 cacheResult(list);
784 
785                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
786                     finderArgs, list);
787 
788                 closeSession(session);
789             }
790         }
791 
792         return list;
793     }
794 
795     public Address findByUserId_First(long userId,
796         OrderByComparator orderByComparator)
797         throws NoSuchAddressException, SystemException {
798         List<Address> list = findByUserId(userId, 0, 1, orderByComparator);
799 
800         if (list.isEmpty()) {
801             StringBundler msg = new StringBundler(4);
802 
803             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
804 
805             msg.append("userId=");
806             msg.append(userId);
807 
808             msg.append(StringPool.CLOSE_CURLY_BRACE);
809 
810             throw new NoSuchAddressException(msg.toString());
811         }
812         else {
813             return list.get(0);
814         }
815     }
816 
817     public Address findByUserId_Last(long userId,
818         OrderByComparator orderByComparator)
819         throws NoSuchAddressException, SystemException {
820         int count = countByUserId(userId);
821 
822         List<Address> list = findByUserId(userId, count - 1, count,
823                 orderByComparator);
824 
825         if (list.isEmpty()) {
826             StringBundler msg = new StringBundler(4);
827 
828             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
829 
830             msg.append("userId=");
831             msg.append(userId);
832 
833             msg.append(StringPool.CLOSE_CURLY_BRACE);
834 
835             throw new NoSuchAddressException(msg.toString());
836         }
837         else {
838             return list.get(0);
839         }
840     }
841 
842     public Address[] findByUserId_PrevAndNext(long addressId, long userId,
843         OrderByComparator orderByComparator)
844         throws NoSuchAddressException, SystemException {
845         Address address = findByPrimaryKey(addressId);
846 
847         int count = countByUserId(userId);
848 
849         Session session = null;
850 
851         try {
852             session = openSession();
853 
854             StringBundler query = null;
855 
856             if (orderByComparator != null) {
857                 query = new StringBundler(3 +
858                         (orderByComparator.getOrderByFields().length * 3));
859             }
860             else {
861                 query = new StringBundler(3);
862             }
863 
864             query.append(_SQL_SELECT_ADDRESS_WHERE);
865 
866             query.append(_FINDER_COLUMN_USERID_USERID_2);
867 
868             if (orderByComparator != null) {
869                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
870                     orderByComparator);
871             }
872 
873             else {
874                 query.append(AddressModelImpl.ORDER_BY_JPQL);
875             }
876 
877             String sql = query.toString();
878 
879             Query q = session.createQuery(sql);
880 
881             QueryPos qPos = QueryPos.getInstance(q);
882 
883             qPos.add(userId);
884 
885             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
886                     orderByComparator, address);
887 
888             Address[] array = new AddressImpl[3];
889 
890             array[0] = (Address)objArray[0];
891             array[1] = (Address)objArray[1];
892             array[2] = (Address)objArray[2];
893 
894             return array;
895         }
896         catch (Exception e) {
897             throw processException(e);
898         }
899         finally {
900             closeSession(session);
901         }
902     }
903 
904     public List<Address> findByC_C(long companyId, long classNameId)
905         throws SystemException {
906         Object[] finderArgs = new Object[] {
907                 new Long(companyId), new Long(classNameId)
908             };
909 
910         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
911                 finderArgs, this);
912 
913         if (list == null) {
914             Session session = null;
915 
916             try {
917                 session = openSession();
918 
919                 StringBundler query = new StringBundler(4);
920 
921                 query.append(_SQL_SELECT_ADDRESS_WHERE);
922 
923                 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
924 
925                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
926 
927                 query.append(AddressModelImpl.ORDER_BY_JPQL);
928 
929                 String sql = query.toString();
930 
931                 Query q = session.createQuery(sql);
932 
933                 QueryPos qPos = QueryPos.getInstance(q);
934 
935                 qPos.add(companyId);
936 
937                 qPos.add(classNameId);
938 
939                 list = q.list();
940             }
941             catch (Exception e) {
942                 throw processException(e);
943             }
944             finally {
945                 if (list == null) {
946                     list = new ArrayList<Address>();
947                 }
948 
949                 cacheResult(list);
950 
951                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
952                     list);
953 
954                 closeSession(session);
955             }
956         }
957 
958         return list;
959     }
960 
961     public List<Address> findByC_C(long companyId, long classNameId, int start,
962         int end) throws SystemException {
963         return findByC_C(companyId, classNameId, start, end, null);
964     }
965 
966     public List<Address> findByC_C(long companyId, long classNameId, int start,
967         int end, OrderByComparator orderByComparator) throws SystemException {
968         Object[] finderArgs = new Object[] {
969                 new Long(companyId), new Long(classNameId),
970                 
971                 String.valueOf(start), String.valueOf(end),
972                 String.valueOf(orderByComparator)
973             };
974 
975         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C,
976                 finderArgs, this);
977 
978         if (list == null) {
979             Session session = null;
980 
981             try {
982                 session = openSession();
983 
984                 StringBundler query = null;
985 
986                 if (orderByComparator != null) {
987                     query = new StringBundler(4 +
988                             (orderByComparator.getOrderByFields().length * 3));
989                 }
990                 else {
991                     query = new StringBundler(4);
992                 }
993 
994                 query.append(_SQL_SELECT_ADDRESS_WHERE);
995 
996                 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
997 
998                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
999 
1000                if (orderByComparator != null) {
1001                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1002                        orderByComparator);
1003                }
1004
1005                else {
1006                    query.append(AddressModelImpl.ORDER_BY_JPQL);
1007                }
1008
1009                String sql = query.toString();
1010
1011                Query q = session.createQuery(sql);
1012
1013                QueryPos qPos = QueryPos.getInstance(q);
1014
1015                qPos.add(companyId);
1016
1017                qPos.add(classNameId);
1018
1019                list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
1020            }
1021            catch (Exception e) {
1022                throw processException(e);
1023            }
1024            finally {
1025                if (list == null) {
1026                    list = new ArrayList<Address>();
1027                }
1028
1029                cacheResult(list);
1030
1031                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C,
1032                    finderArgs, list);
1033
1034                closeSession(session);
1035            }
1036        }
1037
1038        return list;
1039    }
1040
1041    public Address findByC_C_First(long companyId, long classNameId,
1042        OrderByComparator orderByComparator)
1043        throws NoSuchAddressException, SystemException {
1044        List<Address> list = findByC_C(companyId, classNameId, 0, 1,
1045                orderByComparator);
1046
1047        if (list.isEmpty()) {
1048            StringBundler msg = new StringBundler(6);
1049
1050            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1051
1052            msg.append("companyId=");
1053            msg.append(companyId);
1054
1055            msg.append(", classNameId=");
1056            msg.append(classNameId);
1057
1058            msg.append(StringPool.CLOSE_CURLY_BRACE);
1059
1060            throw new NoSuchAddressException(msg.toString());
1061        }
1062        else {
1063            return list.get(0);
1064        }
1065    }
1066
1067    public Address findByC_C_Last(long companyId, long classNameId,
1068        OrderByComparator orderByComparator)
1069        throws NoSuchAddressException, SystemException {
1070        int count = countByC_C(companyId, classNameId);
1071
1072        List<Address> list = findByC_C(companyId, classNameId, count - 1,
1073                count, orderByComparator);
1074
1075        if (list.isEmpty()) {
1076            StringBundler msg = new StringBundler(6);
1077
1078            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1079
1080            msg.append("companyId=");
1081            msg.append(companyId);
1082
1083            msg.append(", classNameId=");
1084            msg.append(classNameId);
1085
1086            msg.append(StringPool.CLOSE_CURLY_BRACE);
1087
1088            throw new NoSuchAddressException(msg.toString());
1089        }
1090        else {
1091            return list.get(0);
1092        }
1093    }
1094
1095    public Address[] findByC_C_PrevAndNext(long addressId, long companyId,
1096        long classNameId, OrderByComparator orderByComparator)
1097        throws NoSuchAddressException, SystemException {
1098        Address address = findByPrimaryKey(addressId);
1099
1100        int count = countByC_C(companyId, classNameId);
1101
1102        Session session = null;
1103
1104        try {
1105            session = openSession();
1106
1107            StringBundler query = null;
1108
1109            if (orderByComparator != null) {
1110                query = new StringBundler(4 +
1111                        (orderByComparator.getOrderByFields().length * 3));
1112            }
1113            else {
1114                query = new StringBundler(4);
1115            }
1116
1117            query.append(_SQL_SELECT_ADDRESS_WHERE);
1118
1119            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1120
1121            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1122
1123            if (orderByComparator != null) {
1124                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1125                    orderByComparator);
1126            }
1127
1128            else {
1129                query.append(AddressModelImpl.ORDER_BY_JPQL);
1130            }
1131
1132            String sql = query.toString();
1133
1134            Query q = session.createQuery(sql);
1135
1136            QueryPos qPos = QueryPos.getInstance(q);
1137
1138            qPos.add(companyId);
1139
1140            qPos.add(classNameId);
1141
1142            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1143                    orderByComparator, address);
1144
1145            Address[] array = new AddressImpl[3];
1146
1147            array[0] = (Address)objArray[0];
1148            array[1] = (Address)objArray[1];
1149            array[2] = (Address)objArray[2];
1150
1151            return array;
1152        }
1153        catch (Exception e) {
1154            throw processException(e);
1155        }
1156        finally {
1157            closeSession(session);
1158        }
1159    }
1160
1161    public List<Address> findByC_C_C(long companyId, long classNameId,
1162        long classPK) throws SystemException {
1163        Object[] finderArgs = new Object[] {
1164                new Long(companyId), new Long(classNameId), new Long(classPK)
1165            };
1166
1167        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C,
1168                finderArgs, this);
1169
1170        if (list == null) {
1171            Session session = null;
1172
1173            try {
1174                session = openSession();
1175
1176                StringBundler query = new StringBundler(5);
1177
1178                query.append(_SQL_SELECT_ADDRESS_WHERE);
1179
1180                query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1181
1182                query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1183
1184                query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1185
1186                query.append(AddressModelImpl.ORDER_BY_JPQL);
1187
1188                String sql = query.toString();
1189
1190                Query q = session.createQuery(sql);
1191
1192                QueryPos qPos = QueryPos.getInstance(q);
1193
1194                qPos.add(companyId);
1195
1196                qPos.add(classNameId);
1197
1198                qPos.add(classPK);
1199
1200                list = q.list();
1201            }
1202            catch (Exception e) {
1203                throw processException(e);
1204            }
1205            finally {
1206                if (list == null) {
1207                    list = new ArrayList<Address>();
1208                }
1209
1210                cacheResult(list);
1211
1212                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C,
1213                    finderArgs, list);
1214
1215                closeSession(session);
1216            }
1217        }
1218
1219        return list;
1220    }
1221
1222    public List<Address> findByC_C_C(long companyId, long classNameId,
1223        long classPK, int start, int end) throws SystemException {
1224        return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1225    }
1226
1227    public List<Address> findByC_C_C(long companyId, long classNameId,
1228        long classPK, int start, int end, OrderByComparator orderByComparator)
1229        throws SystemException {
1230        Object[] finderArgs = new Object[] {
1231                new Long(companyId), new Long(classNameId), new Long(classPK),
1232                
1233                String.valueOf(start), String.valueOf(end),
1234                String.valueOf(orderByComparator)
1235            };
1236
1237        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_C,
1238                finderArgs, this);
1239
1240        if (list == null) {
1241            Session session = null;
1242
1243            try {
1244                session = openSession();
1245
1246                StringBundler query = null;
1247
1248                if (orderByComparator != null) {
1249                    query = new StringBundler(5 +
1250                            (orderByComparator.getOrderByFields().length * 3));
1251                }
1252                else {
1253                    query = new StringBundler(5);
1254                }
1255
1256                query.append(_SQL_SELECT_ADDRESS_WHERE);
1257
1258                query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1259
1260                query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1261
1262                query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1263
1264                if (orderByComparator != null) {
1265                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1266                        orderByComparator);
1267                }
1268
1269                else {
1270                    query.append(AddressModelImpl.ORDER_BY_JPQL);
1271                }
1272
1273                String sql = query.toString();
1274
1275                Query q = session.createQuery(sql);
1276
1277                QueryPos qPos = QueryPos.getInstance(q);
1278
1279                qPos.add(companyId);
1280
1281                qPos.add(classNameId);
1282
1283                qPos.add(classPK);
1284
1285                list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
1286            }
1287            catch (Exception e) {
1288                throw processException(e);
1289            }
1290            finally {
1291                if (list == null) {
1292                    list = new ArrayList<Address>();
1293                }
1294
1295                cacheResult(list);
1296
1297                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_C,
1298                    finderArgs, list);
1299
1300                closeSession(session);
1301            }
1302        }
1303
1304        return list;
1305    }
1306
1307    public Address findByC_C_C_First(long companyId, long classNameId,
1308        long classPK, OrderByComparator orderByComparator)
1309        throws NoSuchAddressException, SystemException {
1310        List<Address> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
1311                orderByComparator);
1312
1313        if (list.isEmpty()) {
1314            StringBundler msg = new StringBundler(8);
1315
1316            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1317
1318            msg.append("companyId=");
1319            msg.append(companyId);
1320
1321            msg.append(", classNameId=");
1322            msg.append(classNameId);
1323
1324            msg.append(", classPK=");
1325            msg.append(classPK);
1326
1327            msg.append(StringPool.CLOSE_CURLY_BRACE);
1328
1329            throw new NoSuchAddressException(msg.toString());
1330        }
1331        else {
1332            return list.get(0);
1333        }
1334    }
1335
1336    public Address findByC_C_C_Last(long companyId, long classNameId,
1337        long classPK, OrderByComparator orderByComparator)
1338        throws NoSuchAddressException, SystemException {
1339        int count = countByC_C_C(companyId, classNameId, classPK);
1340
1341        List<Address> list = findByC_C_C(companyId, classNameId, classPK,
1342                count - 1, count, orderByComparator);
1343
1344        if (list.isEmpty()) {
1345            StringBundler msg = new StringBundler(8);
1346
1347            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1348
1349            msg.append("companyId=");
1350            msg.append(companyId);
1351
1352            msg.append(", classNameId=");
1353            msg.append(classNameId);
1354
1355            msg.append(", classPK=");
1356            msg.append(classPK);
1357
1358            msg.append(StringPool.CLOSE_CURLY_BRACE);
1359
1360            throw new NoSuchAddressException(msg.toString());
1361        }
1362        else {
1363            return list.get(0);
1364        }
1365    }
1366
1367    public Address[] findByC_C_C_PrevAndNext(long addressId, long companyId,
1368        long classNameId, long classPK, OrderByComparator orderByComparator)
1369        throws NoSuchAddressException, SystemException {
1370        Address address = findByPrimaryKey(addressId);
1371
1372        int count = countByC_C_C(companyId, classNameId, classPK);
1373
1374        Session session = null;
1375
1376        try {
1377            session = openSession();
1378
1379            StringBundler query = null;
1380
1381            if (orderByComparator != null) {
1382                query = new StringBundler(5 +
1383                        (orderByComparator.getOrderByFields().length * 3));
1384            }
1385            else {
1386                query = new StringBundler(5);
1387            }
1388
1389            query.append(_SQL_SELECT_ADDRESS_WHERE);
1390
1391            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1392
1393            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1394
1395            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1396
1397            if (orderByComparator != null) {
1398                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1399                    orderByComparator);
1400            }
1401
1402            else {
1403                query.append(AddressModelImpl.ORDER_BY_JPQL);
1404            }
1405
1406            String sql = query.toString();
1407
1408            Query q = session.createQuery(sql);
1409
1410            QueryPos qPos = QueryPos.getInstance(q);
1411
1412            qPos.add(companyId);
1413
1414            qPos.add(classNameId);
1415
1416            qPos.add(classPK);
1417
1418            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1419                    orderByComparator, address);
1420
1421            Address[] array = new AddressImpl[3];
1422
1423            array[0] = (Address)objArray[0];
1424            array[1] = (Address)objArray[1];
1425            array[2] = (Address)objArray[2];
1426
1427            return array;
1428        }
1429        catch (Exception e) {
1430            throw processException(e);
1431        }
1432        finally {
1433            closeSession(session);
1434        }
1435    }
1436
1437    public List<Address> findByC_C_C_M(long companyId, long classNameId,
1438        long classPK, boolean mailing) throws SystemException {
1439        Object[] finderArgs = new Object[] {
1440                new Long(companyId), new Long(classNameId), new Long(classPK),
1441                Boolean.valueOf(mailing)
1442            };
1443
1444        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C_M,
1445                finderArgs, this);
1446
1447        if (list == null) {
1448            Session session = null;
1449
1450            try {
1451                session = openSession();
1452
1453                StringBundler query = new StringBundler(6);
1454
1455                query.append(_SQL_SELECT_ADDRESS_WHERE);
1456
1457                query.append(_FINDER_COLUMN_C_C_C_M_COMPANYID_2);
1458
1459                query.append(_FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2);
1460
1461                query.append(_FINDER_COLUMN_C_C_C_M_CLASSPK_2);
1462
1463                query.append(_FINDER_COLUMN_C_C_C_M_MAILING_2);
1464
1465                query.append(AddressModelImpl.ORDER_BY_JPQL);
1466
1467                String sql = query.toString();
1468
1469                Query q = session.createQuery(sql);
1470
1471                QueryPos qPos = QueryPos.getInstance(q);
1472
1473                qPos.add(companyId);
1474
1475                qPos.add(classNameId);
1476
1477                qPos.add(classPK);
1478
1479                qPos.add(mailing);
1480
1481                list = q.list();
1482            }
1483            catch (Exception e) {
1484                throw processException(e);
1485            }
1486            finally {
1487                if (list == null) {
1488                    list = new ArrayList<Address>();
1489                }
1490
1491                cacheResult(list);
1492
1493                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C_M,
1494                    finderArgs, list);
1495
1496                closeSession(session);
1497            }
1498        }
1499
1500        return list;
1501    }
1502
1503    public List<Address> findByC_C_C_M(long companyId, long classNameId,
1504        long classPK, boolean mailing, int start, int end)
1505        throws SystemException {
1506        return findByC_C_C_M(companyId, classNameId, classPK, mailing, start,
1507            end, null);
1508    }
1509
1510    public List<Address> findByC_C_C_M(long companyId, long classNameId,
1511        long classPK, boolean mailing, int start, int end,
1512        OrderByComparator orderByComparator) throws SystemException {
1513        Object[] finderArgs = new Object[] {
1514                new Long(companyId), new Long(classNameId), new Long(classPK),
1515                Boolean.valueOf(mailing),
1516                
1517                String.valueOf(start), String.valueOf(end),
1518                String.valueOf(orderByComparator)
1519            };
1520
1521        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_C_M,
1522                finderArgs, this);
1523
1524        if (list == null) {
1525            Session session = null;
1526
1527            try {
1528                session = openSession();
1529
1530                StringBundler query = null;
1531
1532                if (orderByComparator != null) {
1533                    query = new StringBundler(6 +
1534                            (orderByComparator.getOrderByFields().length * 3));
1535                }
1536                else {
1537                    query = new StringBundler(6);
1538                }
1539
1540                query.append(_SQL_SELECT_ADDRESS_WHERE);
1541
1542                query.append(_FINDER_COLUMN_C_C_C_M_COMPANYID_2);
1543
1544                query.append(_FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2);
1545
1546                query.append(_FINDER_COLUMN_C_C_C_M_CLASSPK_2);
1547
1548                query.append(_FINDER_COLUMN_C_C_C_M_MAILING_2);
1549
1550                if (orderByComparator != null) {
1551                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1552                        orderByComparator);
1553                }
1554
1555                else {
1556                    query.append(AddressModelImpl.ORDER_BY_JPQL);
1557                }
1558
1559                String sql = query.toString();
1560
1561                Query q = session.createQuery(sql);
1562
1563                QueryPos qPos = QueryPos.getInstance(q);
1564
1565                qPos.add(companyId);
1566
1567                qPos.add(classNameId);
1568
1569                qPos.add(classPK);
1570
1571                qPos.add(mailing);
1572
1573                list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
1574            }
1575            catch (Exception e) {
1576                throw processException(e);
1577            }
1578            finally {
1579                if (list == null) {
1580                    list = new ArrayList<Address>();
1581                }
1582
1583                cacheResult(list);
1584
1585                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_C_M,
1586                    finderArgs, list);
1587
1588                closeSession(session);
1589            }
1590        }
1591
1592        return list;
1593    }
1594
1595    public Address findByC_C_C_M_First(long companyId, long classNameId,
1596        long classPK, boolean mailing, OrderByComparator orderByComparator)
1597        throws NoSuchAddressException, SystemException {
1598        List<Address> list = findByC_C_C_M(companyId, classNameId, classPK,
1599                mailing, 0, 1, orderByComparator);
1600
1601        if (list.isEmpty()) {
1602            StringBundler msg = new StringBundler(10);
1603
1604            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1605
1606            msg.append("companyId=");
1607            msg.append(companyId);
1608
1609            msg.append(", classNameId=");
1610            msg.append(classNameId);
1611
1612            msg.append(", classPK=");
1613            msg.append(classPK);
1614
1615            msg.append(", mailing=");
1616            msg.append(mailing);
1617
1618            msg.append(StringPool.CLOSE_CURLY_BRACE);
1619
1620            throw new NoSuchAddressException(msg.toString());
1621        }
1622        else {
1623            return list.get(0);
1624        }
1625    }
1626
1627    public Address findByC_C_C_M_Last(long companyId, long classNameId,
1628        long classPK, boolean mailing, OrderByComparator orderByComparator)
1629        throws NoSuchAddressException, SystemException {
1630        int count = countByC_C_C_M(companyId, classNameId, classPK, mailing);
1631
1632        List<Address> list = findByC_C_C_M(companyId, classNameId, classPK,
1633                mailing, count - 1, count, orderByComparator);
1634
1635        if (list.isEmpty()) {
1636            StringBundler msg = new StringBundler(10);
1637
1638            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1639
1640            msg.append("companyId=");
1641            msg.append(companyId);
1642
1643            msg.append(", classNameId=");
1644            msg.append(classNameId);
1645
1646            msg.append(", classPK=");
1647            msg.append(classPK);
1648
1649            msg.append(", mailing=");
1650            msg.append(mailing);
1651
1652            msg.append(StringPool.CLOSE_CURLY_BRACE);
1653
1654            throw new NoSuchAddressException(msg.toString());
1655        }
1656        else {
1657            return list.get(0);
1658        }
1659    }
1660
1661    public Address[] findByC_C_C_M_PrevAndNext(long addressId, long companyId,
1662        long classNameId, long classPK, boolean mailing,
1663        OrderByComparator orderByComparator)
1664        throws NoSuchAddressException, SystemException {
1665        Address address = findByPrimaryKey(addressId);
1666
1667        int count = countByC_C_C_M(companyId, classNameId, classPK, mailing);
1668
1669        Session session = null;
1670
1671        try {
1672            session = openSession();
1673
1674            StringBundler query = null;
1675
1676            if (orderByComparator != null) {
1677                query = new StringBundler(6 +
1678                        (orderByComparator.getOrderByFields().length * 3));
1679            }
1680            else {
1681                query = new StringBundler(6);
1682            }
1683
1684            query.append(_SQL_SELECT_ADDRESS_WHERE);
1685
1686            query.append(_FINDER_COLUMN_C_C_C_M_COMPANYID_2);
1687
1688            query.append(_FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2);
1689
1690            query.append(_FINDER_COLUMN_C_C_C_M_CLASSPK_2);
1691
1692            query.append(_FINDER_COLUMN_C_C_C_M_MAILING_2);
1693
1694            if (orderByComparator != null) {
1695                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1696                    orderByComparator);
1697            }
1698
1699            else {
1700                query.append(AddressModelImpl.ORDER_BY_JPQL);
1701            }
1702
1703            String sql = query.toString();
1704
1705            Query q = session.createQuery(sql);
1706
1707            QueryPos qPos = QueryPos.getInstance(q);
1708
1709            qPos.add(companyId);
1710
1711            qPos.add(classNameId);
1712
1713            qPos.add(classPK);
1714
1715            qPos.add(mailing);
1716
1717            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1718                    orderByComparator, address);
1719
1720            Address[] array = new AddressImpl[3];
1721
1722            array[0] = (Address)objArray[0];
1723            array[1] = (Address)objArray[1];
1724            array[2] = (Address)objArray[2];
1725
1726            return array;
1727        }
1728        catch (Exception e) {
1729            throw processException(e);
1730        }
1731        finally {
1732            closeSession(session);
1733        }
1734    }
1735
1736    public List<Address> findByC_C_C_P(long companyId, long classNameId,
1737        long classPK, boolean primary) throws SystemException {
1738        Object[] finderArgs = new Object[] {
1739                new Long(companyId), new Long(classNameId), new Long(classPK),
1740                Boolean.valueOf(primary)
1741            };
1742
1743        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C_P,
1744                finderArgs, this);
1745
1746        if (list == null) {
1747            Session session = null;
1748
1749            try {
1750                session = openSession();
1751
1752                StringBundler query = new StringBundler(6);
1753
1754                query.append(_SQL_SELECT_ADDRESS_WHERE);
1755
1756                query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
1757
1758                query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
1759
1760                query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
1761
1762                query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
1763
1764                query.append(AddressModelImpl.ORDER_BY_JPQL);
1765
1766                String sql = query.toString();
1767
1768                Query q = session.createQuery(sql);
1769
1770                QueryPos qPos = QueryPos.getInstance(q);
1771
1772                qPos.add(companyId);
1773
1774                qPos.add(classNameId);
1775
1776                qPos.add(classPK);
1777
1778                qPos.add(primary);
1779
1780                list = q.list();
1781            }
1782            catch (Exception e) {
1783                throw processException(e);
1784            }
1785            finally {
1786                if (list == null) {
1787                    list = new ArrayList<Address>();
1788                }
1789
1790                cacheResult(list);
1791
1792                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C_P,
1793                    finderArgs, list);
1794
1795                closeSession(session);
1796            }
1797        }
1798
1799        return list;
1800    }
1801
1802    public List<Address> findByC_C_C_P(long companyId, long classNameId,
1803        long classPK, boolean primary, int start, int end)
1804        throws SystemException {
1805        return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
1806            end, null);
1807    }
1808
1809    public List<Address> findByC_C_C_P(long companyId, long classNameId,
1810        long classPK, boolean primary, int start, int end,
1811        OrderByComparator orderByComparator) throws SystemException {
1812        Object[] finderArgs = new Object[] {
1813                new Long(companyId), new Long(classNameId), new Long(classPK),
1814                Boolean.valueOf(primary),
1815                
1816                String.valueOf(start), String.valueOf(end),
1817                String.valueOf(orderByComparator)
1818            };
1819
1820        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_C_P,
1821                finderArgs, this);
1822
1823        if (list == null) {
1824            Session session = null;
1825
1826            try {
1827                session = openSession();
1828
1829                StringBundler query = null;
1830
1831                if (orderByComparator != null) {
1832                    query = new StringBundler(6 +
1833                            (orderByComparator.getOrderByFields().length * 3));
1834                }
1835                else {
1836                    query = new StringBundler(6);
1837                }
1838
1839                query.append(_SQL_SELECT_ADDRESS_WHERE);
1840
1841                query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
1842
1843                query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
1844
1845                query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
1846
1847                query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
1848
1849                if (orderByComparator != null) {
1850                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1851                        orderByComparator);
1852                }
1853
1854                else {
1855                    query.append(AddressModelImpl.ORDER_BY_JPQL);
1856                }
1857
1858                String sql = query.toString();
1859
1860                Query q = session.createQuery(sql);
1861
1862                QueryPos qPos = QueryPos.getInstance(q);
1863
1864                qPos.add(companyId);
1865
1866                qPos.add(classNameId);
1867
1868                qPos.add(classPK);
1869
1870                qPos.add(primary);
1871
1872                list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
1873            }
1874            catch (Exception e) {
1875                throw processException(e);
1876            }
1877            finally {
1878                if (list == null) {
1879                    list = new ArrayList<Address>();
1880                }
1881
1882                cacheResult(list);
1883
1884                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_C_P,
1885                    finderArgs, list);
1886
1887                closeSession(session);
1888            }
1889        }
1890
1891        return list;
1892    }
1893
1894    public Address findByC_C_C_P_First(long companyId, long classNameId,
1895        long classPK, boolean primary, OrderByComparator orderByComparator)
1896        throws NoSuchAddressException, SystemException {
1897        List<Address> list = findByC_C_C_P(companyId, classNameId, classPK,
1898                primary, 0, 1, orderByComparator);
1899
1900        if (list.isEmpty()) {
1901            StringBundler msg = new StringBundler(10);
1902
1903            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1904
1905            msg.append("companyId=");
1906            msg.append(companyId);
1907
1908            msg.append(", classNameId=");
1909            msg.append(classNameId);
1910
1911            msg.append(", classPK=");
1912            msg.append(classPK);
1913
1914            msg.append(", primary=");
1915            msg.append(primary);
1916
1917            msg.append(StringPool.CLOSE_CURLY_BRACE);
1918
1919            throw new NoSuchAddressException(msg.toString());
1920        }
1921        else {
1922            return list.get(0);
1923        }
1924    }
1925
1926    public Address findByC_C_C_P_Last(long companyId, long classNameId,
1927        long classPK, boolean primary, OrderByComparator orderByComparator)
1928        throws NoSuchAddressException, SystemException {
1929        int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
1930
1931        List<Address> list = findByC_C_C_P(companyId, classNameId, classPK,
1932                primary, count - 1, count, orderByComparator);
1933
1934        if (list.isEmpty()) {
1935            StringBundler msg = new StringBundler(10);
1936
1937            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1938
1939            msg.append("companyId=");
1940            msg.append(companyId);
1941
1942            msg.append(", classNameId=");
1943            msg.append(classNameId);
1944
1945            msg.append(", classPK=");
1946            msg.append(classPK);
1947
1948            msg.append(", primary=");
1949            msg.append(primary);
1950
1951            msg.append(StringPool.CLOSE_CURLY_BRACE);
1952
1953            throw new NoSuchAddressException(msg.toString());
1954        }
1955        else {
1956            return list.get(0);
1957        }
1958    }
1959
1960    public Address[] findByC_C_C_P_PrevAndNext(long addressId, long companyId,
1961        long classNameId, long classPK, boolean primary,
1962        OrderByComparator orderByComparator)
1963        throws NoSuchAddressException, SystemException {
1964        Address address = findByPrimaryKey(addressId);
1965
1966        int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
1967
1968        Session session = null;
1969
1970        try {
1971            session = openSession();
1972
1973            StringBundler query = null;
1974
1975            if (orderByComparator != null) {
1976                query = new StringBundler(6 +
1977                        (orderByComparator.getOrderByFields().length * 3));
1978            }
1979            else {
1980                query = new StringBundler(6);
1981            }
1982
1983            query.append(_SQL_SELECT_ADDRESS_WHERE);
1984
1985            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
1986
1987            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
1988
1989            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
1990
1991            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
1992
1993            if (orderByComparator != null) {
1994                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1995                    orderByComparator);
1996            }
1997
1998            else {
1999                query.append(AddressModelImpl.ORDER_BY_JPQL);
2000            }
2001
2002            String sql = query.toString();
2003
2004            Query q = session.createQuery(sql);
2005
2006            QueryPos qPos = QueryPos.getInstance(q);
2007
2008            qPos.add(companyId);
2009
2010            qPos.add(classNameId);
2011
2012            qPos.add(classPK);
2013
2014            qPos.add(primary);
2015
2016            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
2017                    orderByComparator, address);
2018
2019            Address[] array = new AddressImpl[3];
2020
2021            array[0] = (Address)objArray[0];
2022            array[1] = (Address)objArray[1];
2023            array[2] = (Address)objArray[2];
2024
2025            return array;
2026        }
2027        catch (Exception e) {
2028            throw processException(e);
2029        }
2030        finally {
2031            closeSession(session);
2032        }
2033    }
2034
2035    public List<Address> findAll() throws SystemException {
2036        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2037    }
2038
2039    public List<Address> findAll(int start, int end) throws SystemException {
2040        return findAll(start, end, null);
2041    }
2042
2043    public List<Address> findAll(int start, int end,
2044        OrderByComparator orderByComparator) throws SystemException {
2045        Object[] finderArgs = new Object[] {
2046                String.valueOf(start), String.valueOf(end),
2047                String.valueOf(orderByComparator)
2048            };
2049
2050        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2051                finderArgs, this);
2052
2053        if (list == null) {
2054            Session session = null;
2055
2056            try {
2057                session = openSession();
2058
2059                StringBundler query = null;
2060                String sql = null;
2061
2062                if (orderByComparator != null) {
2063                    query = new StringBundler(2 +
2064                            (orderByComparator.getOrderByFields().length * 3));
2065
2066                    query.append(_SQL_SELECT_ADDRESS);
2067
2068                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2069                        orderByComparator);
2070
2071                    sql = query.toString();
2072                }
2073
2074                else {
2075                    sql = _SQL_SELECT_ADDRESS.concat(AddressModelImpl.ORDER_BY_JPQL);
2076                }
2077
2078                Query q = session.createQuery(sql);
2079
2080                if (orderByComparator == null) {
2081                    list = (List<Address>)QueryUtil.list(q, getDialect(),
2082                            start, end, false);
2083
2084                    Collections.sort(list);
2085                }
2086                else {
2087                    list = (List<Address>)QueryUtil.list(q, getDialect(),
2088                            start, end);
2089                }
2090            }
2091            catch (Exception e) {
2092                throw processException(e);
2093            }
2094            finally {
2095                if (list == null) {
2096                    list = new ArrayList<Address>();
2097                }
2098
2099                cacheResult(list);
2100
2101                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2102
2103                closeSession(session);
2104            }
2105        }
2106
2107        return list;
2108    }
2109
2110    public void removeByCompanyId(long companyId) throws SystemException {
2111        for (Address address : findByCompanyId(companyId)) {
2112            remove(address);
2113        }
2114    }
2115
2116    public void removeByUserId(long userId) throws SystemException {
2117        for (Address address : findByUserId(userId)) {
2118            remove(address);
2119        }
2120    }
2121
2122    public void removeByC_C(long companyId, long classNameId)
2123        throws SystemException {
2124        for (Address address : findByC_C(companyId, classNameId)) {
2125            remove(address);
2126        }
2127    }
2128
2129    public void removeByC_C_C(long companyId, long classNameId, long classPK)
2130        throws SystemException {
2131        for (Address address : findByC_C_C(companyId, classNameId, classPK)) {
2132            remove(address);
2133        }
2134    }
2135
2136    public void removeByC_C_C_M(long companyId, long classNameId, long classPK,
2137        boolean mailing) throws SystemException {
2138        for (Address address : findByC_C_C_M(companyId, classNameId, classPK,
2139                mailing)) {
2140            remove(address);
2141        }
2142    }
2143
2144    public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
2145        boolean primary) throws SystemException {
2146        for (Address address : findByC_C_C_P(companyId, classNameId, classPK,
2147                primary)) {
2148            remove(address);
2149        }
2150    }
2151
2152    public void removeAll() throws SystemException {
2153        for (Address address : findAll()) {
2154            remove(address);
2155        }
2156    }
2157
2158    public int countByCompanyId(long companyId) throws SystemException {
2159        Object[] finderArgs = new Object[] { new Long(companyId) };
2160
2161        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2162                finderArgs, this);
2163
2164        if (count == null) {
2165            Session session = null;
2166
2167            try {
2168                session = openSession();
2169
2170                StringBundler query = new StringBundler(2);
2171
2172                query.append(_SQL_COUNT_ADDRESS_WHERE);
2173
2174                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2175
2176                String sql = query.toString();
2177
2178                Query q = session.createQuery(sql);
2179
2180                QueryPos qPos = QueryPos.getInstance(q);
2181
2182                qPos.add(companyId);
2183
2184                count = (Long)q.uniqueResult();
2185            }
2186            catch (Exception e) {
2187                throw processException(e);
2188            }
2189            finally {
2190                if (count == null) {
2191                    count = Long.valueOf(0);
2192                }
2193
2194                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2195                    finderArgs, count);
2196
2197                closeSession(session);
2198            }
2199        }
2200
2201        return count.intValue();
2202    }
2203
2204    public int countByUserId(long userId) throws SystemException {
2205        Object[] finderArgs = new Object[] { new Long(userId) };
2206
2207        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2208                finderArgs, this);
2209
2210        if (count == null) {
2211            Session session = null;
2212
2213            try {
2214                session = openSession();
2215
2216                StringBundler query = new StringBundler(2);
2217
2218                query.append(_SQL_COUNT_ADDRESS_WHERE);
2219
2220                query.append(_FINDER_COLUMN_USERID_USERID_2);
2221
2222                String sql = query.toString();
2223
2224                Query q = session.createQuery(sql);
2225
2226                QueryPos qPos = QueryPos.getInstance(q);
2227
2228                qPos.add(userId);
2229
2230                count = (Long)q.uniqueResult();
2231            }
2232            catch (Exception e) {
2233                throw processException(e);
2234            }
2235            finally {
2236                if (count == null) {
2237                    count = Long.valueOf(0);
2238                }
2239
2240                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2241                    finderArgs, count);
2242
2243                closeSession(session);
2244            }
2245        }
2246
2247        return count.intValue();
2248    }
2249
2250    public int countByC_C(long companyId, long classNameId)
2251        throws SystemException {
2252        Object[] finderArgs = new Object[] {
2253                new Long(companyId), new Long(classNameId)
2254            };
2255
2256        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
2257                finderArgs, this);
2258
2259        if (count == null) {
2260            Session session = null;
2261
2262            try {
2263                session = openSession();
2264
2265                StringBundler query = new StringBundler(3);
2266
2267                query.append(_SQL_COUNT_ADDRESS_WHERE);
2268
2269                query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2270
2271                query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2272
2273                String sql = query.toString();
2274
2275                Query q = session.createQuery(sql);
2276
2277                QueryPos qPos = QueryPos.getInstance(q);
2278
2279                qPos.add(companyId);
2280
2281                qPos.add(classNameId);
2282
2283                count = (Long)q.uniqueResult();
2284            }
2285            catch (Exception e) {
2286                throw processException(e);
2287            }
2288            finally {
2289                if (count == null) {
2290                    count = Long.valueOf(0);
2291                }
2292
2293                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2294                    count);
2295
2296                closeSession(session);
2297            }
2298        }
2299
2300        return count.intValue();
2301    }
2302
2303    public int countByC_C_C(long companyId, long classNameId, long classPK)
2304        throws SystemException {
2305        Object[] finderArgs = new Object[] {
2306                new Long(companyId), new Long(classNameId), new Long(classPK)
2307            };
2308
2309        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
2310                finderArgs, this);
2311
2312        if (count == null) {
2313            Session session = null;
2314
2315            try {
2316                session = openSession();
2317
2318                StringBundler query = new StringBundler(4);
2319
2320                query.append(_SQL_COUNT_ADDRESS_WHERE);
2321
2322                query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2323
2324                query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2325
2326                query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2327
2328                String sql = query.toString();
2329
2330                Query q = session.createQuery(sql);
2331
2332                QueryPos qPos = QueryPos.getInstance(q);
2333
2334                qPos.add(companyId);
2335
2336                qPos.add(classNameId);
2337
2338                qPos.add(classPK);
2339
2340                count = (Long)q.uniqueResult();
2341            }
2342            catch (Exception e) {
2343                throw processException(e);
2344            }
2345            finally {
2346                if (count == null) {
2347                    count = Long.valueOf(0);
2348                }
2349
2350                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2351                    finderArgs, count);
2352
2353                closeSession(session);
2354            }
2355        }
2356
2357        return count.intValue();
2358    }
2359
2360    public int countByC_C_C_M(long companyId, long classNameId, long classPK,
2361        boolean mailing) throws SystemException {
2362        Object[] finderArgs = new Object[] {
2363                new Long(companyId), new Long(classNameId), new Long(classPK),
2364                Boolean.valueOf(mailing)
2365            };
2366
2367        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C_M,
2368                finderArgs, this);
2369
2370        if (count == null) {
2371            Session session = null;
2372
2373            try {
2374                session = openSession();
2375
2376                StringBundler query = new StringBundler(5);
2377
2378                query.append(_SQL_COUNT_ADDRESS_WHERE);
2379
2380                query.append(_FINDER_COLUMN_C_C_C_M_COMPANYID_2);
2381
2382                query.append(_FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2);
2383
2384                query.append(_FINDER_COLUMN_C_C_C_M_CLASSPK_2);
2385
2386                query.append(_FINDER_COLUMN_C_C_C_M_MAILING_2);
2387
2388                String sql = query.toString();
2389
2390                Query q = session.createQuery(sql);
2391
2392                QueryPos qPos = QueryPos.getInstance(q);
2393
2394                qPos.add(companyId);
2395
2396                qPos.add(classNameId);
2397
2398                qPos.add(classPK);
2399
2400                qPos.add(mailing);
2401
2402                count = (Long)q.uniqueResult();
2403            }
2404            catch (Exception e) {
2405                throw processException(e);
2406            }
2407            finally {
2408                if (count == null) {
2409                    count = Long.valueOf(0);
2410                }
2411
2412                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C_M,
2413                    finderArgs, count);
2414
2415                closeSession(session);
2416            }
2417        }
2418
2419        return count.intValue();
2420    }
2421
2422    public int countByC_C_C_P(long companyId, long classNameId, long classPK,
2423        boolean primary) throws SystemException {
2424        Object[] finderArgs = new Object[] {
2425                new Long(companyId), new Long(classNameId), new Long(classPK),
2426                Boolean.valueOf(primary)
2427            };
2428
2429        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C_P,
2430                finderArgs, this);
2431
2432        if (count == null) {
2433            Session session = null;
2434
2435            try {
2436                session = openSession();
2437
2438                StringBundler query = new StringBundler(5);
2439
2440                query.append(_SQL_COUNT_ADDRESS_WHERE);
2441
2442                query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2443
2444                query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2445
2446                query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2447
2448                query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2449
2450                String sql = query.toString();
2451
2452                Query q = session.createQuery(sql);
2453
2454                QueryPos qPos = QueryPos.getInstance(q);
2455
2456                qPos.add(companyId);
2457
2458                qPos.add(classNameId);
2459
2460                qPos.add(classPK);
2461
2462                qPos.add(primary);
2463
2464                count = (Long)q.uniqueResult();
2465            }
2466            catch (Exception e) {
2467                throw processException(e);
2468            }
2469            finally {
2470                if (count == null) {
2471                    count = Long.valueOf(0);
2472                }
2473
2474                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C_P,
2475                    finderArgs, count);
2476
2477                closeSession(session);
2478            }
2479        }
2480
2481        return count.intValue();
2482    }
2483
2484    public int countAll() throws SystemException {
2485        Object[] finderArgs = new Object[0];
2486
2487        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2488                finderArgs, this);
2489
2490        if (count == null) {
2491            Session session = null;
2492
2493            try {
2494                session = openSession();
2495
2496                Query q = session.createQuery(_SQL_COUNT_ADDRESS);
2497
2498                count = (Long)q.uniqueResult();
2499            }
2500            catch (Exception e) {
2501                throw processException(e);
2502            }
2503            finally {
2504                if (count == null) {
2505                    count = Long.valueOf(0);
2506                }
2507
2508                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2509                    count);
2510
2511                closeSession(session);
2512            }
2513        }
2514
2515        return count.intValue();
2516    }
2517
2518    public void afterPropertiesSet() {
2519        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2520                    com.liferay.portal.util.PropsUtil.get(
2521                        "value.object.listener.com.liferay.portal.model.Address")));
2522
2523        if (listenerClassNames.length > 0) {
2524            try {
2525                List<ModelListener<Address>> listenersList = new ArrayList<ModelListener<Address>>();
2526
2527                for (String listenerClassName : listenerClassNames) {
2528                    listenersList.add((ModelListener<Address>)Class.forName(
2529                            listenerClassName).newInstance());
2530                }
2531
2532                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2533            }
2534            catch (Exception e) {
2535                _log.error(e);
2536            }
2537        }
2538    }
2539
2540    @BeanReference(type = AccountPersistence.class)
2541    protected AccountPersistence accountPersistence;
2542    @BeanReference(type = AddressPersistence.class)
2543    protected AddressPersistence addressPersistence;
2544    @BeanReference(type = BrowserTrackerPersistence.class)
2545    protected BrowserTrackerPersistence browserTrackerPersistence;
2546    @BeanReference(type = ClassNamePersistence.class)
2547    protected ClassNamePersistence classNamePersistence;
2548    @BeanReference(type = CompanyPersistence.class)
2549    protected CompanyPersistence companyPersistence;
2550    @BeanReference(type = ContactPersistence.class)
2551    protected ContactPersistence contactPersistence;
2552    @BeanReference(type = CountryPersistence.class)
2553    protected CountryPersistence countryPersistence;
2554    @BeanReference(type = EmailAddressPersistence.class)
2555    protected EmailAddressPersistence emailAddressPersistence;
2556    @BeanReference(type = GroupPersistence.class)
2557    protected GroupPersistence groupPersistence;
2558    @BeanReference(type = ImagePersistence.class)
2559    protected ImagePersistence imagePersistence;
2560    @BeanReference(type = LayoutPersistence.class)
2561    protected LayoutPersistence layoutPersistence;
2562    @BeanReference(type = LayoutSetPersistence.class)
2563    protected LayoutSetPersistence layoutSetPersistence;
2564    @BeanReference(type = ListTypePersistence.class)
2565    protected ListTypePersistence listTypePersistence;
2566    @BeanReference(type = LockPersistence.class)
2567    protected LockPersistence lockPersistence;
2568    @BeanReference(type = MembershipRequestPersistence.class)
2569    protected MembershipRequestPersistence membershipRequestPersistence;
2570    @BeanReference(type = OrganizationPersistence.class)
2571    protected OrganizationPersistence organizationPersistence;
2572    @BeanReference(type = OrgGroupPermissionPersistence.class)
2573    protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2574    @BeanReference(type = OrgGroupRolePersistence.class)
2575    protected OrgGroupRolePersistence orgGroupRolePersistence;
2576    @BeanReference(type = OrgLaborPersistence.class)
2577    protected OrgLaborPersistence orgLaborPersistence;
2578    @BeanReference(type = PasswordPolicyPersistence.class)
2579    protected PasswordPolicyPersistence passwordPolicyPersistence;
2580    @BeanReference(type = PasswordPolicyRelPersistence.class)
2581    protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2582    @BeanReference(type = PasswordTrackerPersistence.class)
2583    protected PasswordTrackerPersistence passwordTrackerPersistence;
2584    @BeanReference(type = PermissionPersistence.class)
2585    protected PermissionPersistence permissionPersistence;
2586    @BeanReference(type = PhonePersistence.class)
2587    protected PhonePersistence phonePersistence;
2588    @BeanReference(type = PluginSettingPersistence.class)
2589    protected PluginSettingPersistence pluginSettingPersistence;
2590    @BeanReference(type = PortletPersistence.class)
2591    protected PortletPersistence portletPersistence;
2592    @BeanReference(type = PortletItemPersistence.class)
2593    protected PortletItemPersistence portletItemPersistence;
2594    @BeanReference(type = PortletPreferencesPersistence.class)
2595    protected PortletPreferencesPersistence portletPreferencesPersistence;
2596    @BeanReference(type = RegionPersistence.class)
2597    protected RegionPersistence regionPersistence;
2598    @BeanReference(type = ReleasePersistence.class)
2599    protected ReleasePersistence releasePersistence;
2600    @BeanReference(type = ResourcePersistence.class)
2601    protected ResourcePersistence resourcePersistence;
2602    @BeanReference(type = ResourceActionPersistence.class)
2603    protected ResourceActionPersistence resourceActionPersistence;
2604    @BeanReference(type = ResourceCodePersistence.class)
2605    protected ResourceCodePersistence resourceCodePersistence;
2606    @BeanReference(type = ResourcePermissionPersistence.class)
2607    protected ResourcePermissionPersistence resourcePermissionPersistence;
2608    @BeanReference(type = RolePersistence.class)
2609    protected RolePersistence rolePersistence;
2610    @BeanReference(type = ServiceComponentPersistence.class)
2611    protected ServiceComponentPersistence serviceComponentPersistence;
2612    @BeanReference(type = ShardPersistence.class)
2613    protected ShardPersistence shardPersistence;
2614    @BeanReference(type = SubscriptionPersistence.class)
2615    protected SubscriptionPersistence subscriptionPersistence;
2616    @BeanReference(type = UserPersistence.class)
2617    protected UserPersistence userPersistence;
2618    @BeanReference(type = UserGroupPersistence.class)
2619    protected UserGroupPersistence userGroupPersistence;
2620    @BeanReference(type = UserGroupGroupRolePersistence.class)
2621    protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2622    @BeanReference(type = UserGroupRolePersistence.class)
2623    protected UserGroupRolePersistence userGroupRolePersistence;
2624    @BeanReference(type = UserIdMapperPersistence.class)
2625    protected UserIdMapperPersistence userIdMapperPersistence;
2626    @BeanReference(type = UserTrackerPersistence.class)
2627    protected UserTrackerPersistence userTrackerPersistence;
2628    @BeanReference(type = UserTrackerPathPersistence.class)
2629    protected UserTrackerPathPersistence userTrackerPathPersistence;
2630    @BeanReference(type = WebDAVPropsPersistence.class)
2631    protected WebDAVPropsPersistence webDAVPropsPersistence;
2632    @BeanReference(type = WebsitePersistence.class)
2633    protected WebsitePersistence websitePersistence;
2634    private static final String _SQL_SELECT_ADDRESS = "SELECT address FROM Address address";
2635    private static final String _SQL_SELECT_ADDRESS_WHERE = "SELECT address FROM Address address WHERE ";
2636    private static final String _SQL_COUNT_ADDRESS = "SELECT COUNT(address) FROM Address address";
2637    private static final String _SQL_COUNT_ADDRESS_WHERE = "SELECT COUNT(address) FROM Address address WHERE ";
2638    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "address.companyId = ?";
2639    private static final String _FINDER_COLUMN_USERID_USERID_2 = "address.userId = ?";
2640    private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "address.companyId = ? AND ";
2641    private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "address.classNameId = ?";
2642    private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "address.companyId = ? AND ";
2643    private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "address.classNameId = ? AND ";
2644    private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "address.classPK = ?";
2645    private static final String _FINDER_COLUMN_C_C_C_M_COMPANYID_2 = "address.companyId = ? AND ";
2646    private static final String _FINDER_COLUMN_C_C_C_M_CLASSNAMEID_2 = "address.classNameId = ? AND ";
2647    private static final String _FINDER_COLUMN_C_C_C_M_CLASSPK_2 = "address.classPK = ? AND ";
2648    private static final String _FINDER_COLUMN_C_C_C_M_MAILING_2 = "address.mailing = ?";
2649    private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "address.companyId = ? AND ";
2650    private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "address.classNameId = ? AND ";
2651    private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "address.classPK = ? AND ";
2652    private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "address.primary = ?";
2653    private static final String _ORDER_BY_ENTITY_ALIAS = "address.";
2654    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Address exists with the primary key ";
2655    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Address exists with the key {";
2656    private static Log _log = LogFactoryUtil.getLog(AddressPersistenceImpl.class);
2657}