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