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("FROM com.liferay.portal.model.Address WHERE ");
438 
439                 query.append("companyId = ?");
440 
441                 query.append(" ");
442 
443                 query.append("ORDER BY ");
444 
445                 query.append("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("FROM com.liferay.portal.model.Address WHERE ");
500 
501                 query.append("companyId = ?");
502 
503                 query.append(" ");
504 
505                 if (obc != null) {
506                     query.append("ORDER BY ");
507                     query.append(obc.getOrderBy());
508                 }
509 
510                 else {
511                     query.append("ORDER BY ");
512 
513                     query.append("createDate ASC");
514                 }
515 
516                 Query q = session.createQuery(query.toString());
517 
518                 QueryPos qPos = QueryPos.getInstance(q);
519 
520                 qPos.add(companyId);
521 
522                 list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
523             }
524             catch (Exception e) {
525                 throw processException(e);
526             }
527             finally {
528                 if (list == null) {
529                     list = new ArrayList<Address>();
530                 }
531 
532                 cacheResult(list);
533 
534                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
535                     finderArgs, list);
536 
537                 closeSession(session);
538             }
539         }
540 
541         return list;
542     }
543 
544     public Address findByCompanyId_First(long companyId, OrderByComparator obc)
545         throws NoSuchAddressException, SystemException {
546         List<Address> list = findByCompanyId(companyId, 0, 1, obc);
547 
548         if (list.isEmpty()) {
549             StringBuilder msg = new StringBuilder();
550 
551             msg.append("No Address exists with the key {");
552 
553             msg.append("companyId=" + companyId);
554 
555             msg.append(StringPool.CLOSE_CURLY_BRACE);
556 
557             throw new NoSuchAddressException(msg.toString());
558         }
559         else {
560             return list.get(0);
561         }
562     }
563 
564     public Address findByCompanyId_Last(long companyId, OrderByComparator obc)
565         throws NoSuchAddressException, SystemException {
566         int count = countByCompanyId(companyId);
567 
568         List<Address> list = findByCompanyId(companyId, count - 1, count, obc);
569 
570         if (list.isEmpty()) {
571             StringBuilder msg = new StringBuilder();
572 
573             msg.append("No Address exists with the key {");
574 
575             msg.append("companyId=" + companyId);
576 
577             msg.append(StringPool.CLOSE_CURLY_BRACE);
578 
579             throw new NoSuchAddressException(msg.toString());
580         }
581         else {
582             return list.get(0);
583         }
584     }
585 
586     public Address[] findByCompanyId_PrevAndNext(long addressId,
587         long companyId, OrderByComparator obc)
588         throws NoSuchAddressException, SystemException {
589         Address address = findByPrimaryKey(addressId);
590 
591         int count = countByCompanyId(companyId);
592 
593         Session session = null;
594 
595         try {
596             session = openSession();
597 
598             StringBuilder query = new StringBuilder();
599 
600             query.append("FROM com.liferay.portal.model.Address WHERE ");
601 
602             query.append("companyId = ?");
603 
604             query.append(" ");
605 
606             if (obc != null) {
607                 query.append("ORDER BY ");
608                 query.append(obc.getOrderBy());
609             }
610 
611             else {
612                 query.append("ORDER BY ");
613 
614                 query.append("createDate ASC");
615             }
616 
617             Query q = session.createQuery(query.toString());
618 
619             QueryPos qPos = QueryPos.getInstance(q);
620 
621             qPos.add(companyId);
622 
623             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
624 
625             Address[] array = new AddressImpl[3];
626 
627             array[0] = (Address)objArray[0];
628             array[1] = (Address)objArray[1];
629             array[2] = (Address)objArray[2];
630 
631             return array;
632         }
633         catch (Exception e) {
634             throw processException(e);
635         }
636         finally {
637             closeSession(session);
638         }
639     }
640 
641     public List<Address> findByUserId(long userId) throws SystemException {
642         Object[] finderArgs = new Object[] { new Long(userId) };
643 
644         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
645                 finderArgs, this);
646 
647         if (list == null) {
648             Session session = null;
649 
650             try {
651                 session = openSession();
652 
653                 StringBuilder query = new StringBuilder();
654 
655                 query.append("FROM com.liferay.portal.model.Address WHERE ");
656 
657                 query.append("userId = ?");
658 
659                 query.append(" ");
660 
661                 query.append("ORDER BY ");
662 
663                 query.append("createDate ASC");
664 
665                 Query q = session.createQuery(query.toString());
666 
667                 QueryPos qPos = QueryPos.getInstance(q);
668 
669                 qPos.add(userId);
670 
671                 list = q.list();
672             }
673             catch (Exception e) {
674                 throw processException(e);
675             }
676             finally {
677                 if (list == null) {
678                     list = new ArrayList<Address>();
679                 }
680 
681                 cacheResult(list);
682 
683                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
684                     finderArgs, list);
685 
686                 closeSession(session);
687             }
688         }
689 
690         return list;
691     }
692 
693     public List<Address> findByUserId(long userId, int start, int end)
694         throws SystemException {
695         return findByUserId(userId, start, end, null);
696     }
697 
698     public List<Address> findByUserId(long userId, int start, int end,
699         OrderByComparator obc) throws SystemException {
700         Object[] finderArgs = new Object[] {
701                 new Long(userId),
702                 
703                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
704             };
705 
706         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
707                 finderArgs, this);
708 
709         if (list == null) {
710             Session session = null;
711 
712             try {
713                 session = openSession();
714 
715                 StringBuilder query = new StringBuilder();
716 
717                 query.append("FROM com.liferay.portal.model.Address WHERE ");
718 
719                 query.append("userId = ?");
720 
721                 query.append(" ");
722 
723                 if (obc != null) {
724                     query.append("ORDER BY ");
725                     query.append(obc.getOrderBy());
726                 }
727 
728                 else {
729                     query.append("ORDER BY ");
730 
731                     query.append("createDate ASC");
732                 }
733 
734                 Query q = session.createQuery(query.toString());
735 
736                 QueryPos qPos = QueryPos.getInstance(q);
737 
738                 qPos.add(userId);
739 
740                 list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
741             }
742             catch (Exception e) {
743                 throw processException(e);
744             }
745             finally {
746                 if (list == null) {
747                     list = new ArrayList<Address>();
748                 }
749 
750                 cacheResult(list);
751 
752                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
753                     finderArgs, list);
754 
755                 closeSession(session);
756             }
757         }
758 
759         return list;
760     }
761 
762     public Address findByUserId_First(long userId, OrderByComparator obc)
763         throws NoSuchAddressException, SystemException {
764         List<Address> list = findByUserId(userId, 0, 1, obc);
765 
766         if (list.isEmpty()) {
767             StringBuilder msg = new StringBuilder();
768 
769             msg.append("No Address exists with the key {");
770 
771             msg.append("userId=" + userId);
772 
773             msg.append(StringPool.CLOSE_CURLY_BRACE);
774 
775             throw new NoSuchAddressException(msg.toString());
776         }
777         else {
778             return list.get(0);
779         }
780     }
781 
782     public Address findByUserId_Last(long userId, OrderByComparator obc)
783         throws NoSuchAddressException, SystemException {
784         int count = countByUserId(userId);
785 
786         List<Address> list = findByUserId(userId, count - 1, count, obc);
787 
788         if (list.isEmpty()) {
789             StringBuilder msg = new StringBuilder();
790 
791             msg.append("No Address exists with the key {");
792 
793             msg.append("userId=" + userId);
794 
795             msg.append(StringPool.CLOSE_CURLY_BRACE);
796 
797             throw new NoSuchAddressException(msg.toString());
798         }
799         else {
800             return list.get(0);
801         }
802     }
803 
804     public Address[] findByUserId_PrevAndNext(long addressId, long userId,
805         OrderByComparator obc) throws NoSuchAddressException, SystemException {
806         Address address = findByPrimaryKey(addressId);
807 
808         int count = countByUserId(userId);
809 
810         Session session = null;
811 
812         try {
813             session = openSession();
814 
815             StringBuilder query = new StringBuilder();
816 
817             query.append("FROM com.liferay.portal.model.Address WHERE ");
818 
819             query.append("userId = ?");
820 
821             query.append(" ");
822 
823             if (obc != null) {
824                 query.append("ORDER BY ");
825                 query.append(obc.getOrderBy());
826             }
827 
828             else {
829                 query.append("ORDER BY ");
830 
831                 query.append("createDate ASC");
832             }
833 
834             Query q = session.createQuery(query.toString());
835 
836             QueryPos qPos = QueryPos.getInstance(q);
837 
838             qPos.add(userId);
839 
840             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
841 
842             Address[] array = new AddressImpl[3];
843 
844             array[0] = (Address)objArray[0];
845             array[1] = (Address)objArray[1];
846             array[2] = (Address)objArray[2];
847 
848             return array;
849         }
850         catch (Exception e) {
851             throw processException(e);
852         }
853         finally {
854             closeSession(session);
855         }
856     }
857 
858     public List<Address> findByC_C(long companyId, long classNameId)
859         throws SystemException {
860         Object[] finderArgs = new Object[] {
861                 new Long(companyId), new Long(classNameId)
862             };
863 
864         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
865                 finderArgs, this);
866 
867         if (list == null) {
868             Session session = null;
869 
870             try {
871                 session = openSession();
872 
873                 StringBuilder query = new StringBuilder();
874 
875                 query.append("FROM com.liferay.portal.model.Address WHERE ");
876 
877                 query.append("companyId = ?");
878 
879                 query.append(" AND ");
880 
881                 query.append("classNameId = ?");
882 
883                 query.append(" ");
884 
885                 query.append("ORDER BY ");
886 
887                 query.append("createDate ASC");
888 
889                 Query q = session.createQuery(query.toString());
890 
891                 QueryPos qPos = QueryPos.getInstance(q);
892 
893                 qPos.add(companyId);
894 
895                 qPos.add(classNameId);
896 
897                 list = q.list();
898             }
899             catch (Exception e) {
900                 throw processException(e);
901             }
902             finally {
903                 if (list == null) {
904                     list = new ArrayList<Address>();
905                 }
906 
907                 cacheResult(list);
908 
909                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
910                     list);
911 
912                 closeSession(session);
913             }
914         }
915 
916         return list;
917     }
918 
919     public List<Address> findByC_C(long companyId, long classNameId, int start,
920         int end) throws SystemException {
921         return findByC_C(companyId, classNameId, start, end, null);
922     }
923 
924     public List<Address> findByC_C(long companyId, long classNameId, int start,
925         int end, OrderByComparator obc) throws SystemException {
926         Object[] finderArgs = new Object[] {
927                 new Long(companyId), new Long(classNameId),
928                 
929                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
930             };
931 
932         List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_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("FROM com.liferay.portal.model.Address WHERE ");
944 
945                 query.append("companyId = ?");
946 
947                 query.append(" AND ");
948 
949                 query.append("classNameId = ?");
950 
951                 query.append(" ");
952 
953                 if (obc != null) {
954                     query.append("ORDER BY ");
955                     query.append(obc.getOrderBy());
956                 }
957 
958                 else {
959                     query.append("ORDER BY ");
960 
961                     query.append("createDate ASC");
962                 }
963 
964                 Query q = session.createQuery(query.toString());
965 
966                 QueryPos qPos = QueryPos.getInstance(q);
967 
968                 qPos.add(companyId);
969 
970                 qPos.add(classNameId);
971 
972                 list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
973             }
974             catch (Exception e) {
975                 throw processException(e);
976             }
977             finally {
978                 if (list == null) {
979                     list = new ArrayList<Address>();
980                 }
981 
982                 cacheResult(list);
983 
984                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C,
985                     finderArgs, list);
986 
987                 closeSession(session);
988             }
989         }
990 
991         return list;
992     }
993 
994     public Address findByC_C_First(long companyId, long classNameId,
995         OrderByComparator obc) throws NoSuchAddressException, SystemException {
996         List<Address> list = findByC_C(companyId, classNameId, 0, 1, obc);
997 
998         if (list.isEmpty()) {
999             StringBuilder msg = new StringBuilder();
1000
1001            msg.append("No Address exists with the key {");
1002
1003            msg.append("companyId=" + companyId);
1004
1005            msg.append(", ");
1006            msg.append("classNameId=" + classNameId);
1007
1008            msg.append(StringPool.CLOSE_CURLY_BRACE);
1009
1010            throw new NoSuchAddressException(msg.toString());
1011        }
1012        else {
1013            return list.get(0);
1014        }
1015    }
1016
1017    public Address findByC_C_Last(long companyId, long classNameId,
1018        OrderByComparator obc) throws NoSuchAddressException, SystemException {
1019        int count = countByC_C(companyId, classNameId);
1020
1021        List<Address> list = findByC_C(companyId, classNameId, count - 1,
1022                count, obc);
1023
1024        if (list.isEmpty()) {
1025            StringBuilder msg = new StringBuilder();
1026
1027            msg.append("No Address exists with the key {");
1028
1029            msg.append("companyId=" + companyId);
1030
1031            msg.append(", ");
1032            msg.append("classNameId=" + classNameId);
1033
1034            msg.append(StringPool.CLOSE_CURLY_BRACE);
1035
1036            throw new NoSuchAddressException(msg.toString());
1037        }
1038        else {
1039            return list.get(0);
1040        }
1041    }
1042
1043    public Address[] findByC_C_PrevAndNext(long addressId, long companyId,
1044        long classNameId, OrderByComparator obc)
1045        throws NoSuchAddressException, SystemException {
1046        Address address = findByPrimaryKey(addressId);
1047
1048        int count = countByC_C(companyId, classNameId);
1049
1050        Session session = null;
1051
1052        try {
1053            session = openSession();
1054
1055            StringBuilder query = new StringBuilder();
1056
1057            query.append("FROM com.liferay.portal.model.Address WHERE ");
1058
1059            query.append("companyId = ?");
1060
1061            query.append(" AND ");
1062
1063            query.append("classNameId = ?");
1064
1065            query.append(" ");
1066
1067            if (obc != null) {
1068                query.append("ORDER BY ");
1069                query.append(obc.getOrderBy());
1070            }
1071
1072            else {
1073                query.append("ORDER BY ");
1074
1075                query.append("createDate ASC");
1076            }
1077
1078            Query q = session.createQuery(query.toString());
1079
1080            QueryPos qPos = QueryPos.getInstance(q);
1081
1082            qPos.add(companyId);
1083
1084            qPos.add(classNameId);
1085
1086            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
1087
1088            Address[] array = new AddressImpl[3];
1089
1090            array[0] = (Address)objArray[0];
1091            array[1] = (Address)objArray[1];
1092            array[2] = (Address)objArray[2];
1093
1094            return array;
1095        }
1096        catch (Exception e) {
1097            throw processException(e);
1098        }
1099        finally {
1100            closeSession(session);
1101        }
1102    }
1103
1104    public List<Address> findByC_C_C(long companyId, long classNameId,
1105        long classPK) throws SystemException {
1106        Object[] finderArgs = new Object[] {
1107                new Long(companyId), new Long(classNameId), new Long(classPK)
1108            };
1109
1110        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C,
1111                finderArgs, this);
1112
1113        if (list == null) {
1114            Session session = null;
1115
1116            try {
1117                session = openSession();
1118
1119                StringBuilder query = new StringBuilder();
1120
1121                query.append("FROM com.liferay.portal.model.Address WHERE ");
1122
1123                query.append("companyId = ?");
1124
1125                query.append(" AND ");
1126
1127                query.append("classNameId = ?");
1128
1129                query.append(" AND ");
1130
1131                query.append("classPK = ?");
1132
1133                query.append(" ");
1134
1135                query.append("ORDER BY ");
1136
1137                query.append("createDate ASC");
1138
1139                Query q = session.createQuery(query.toString());
1140
1141                QueryPos qPos = QueryPos.getInstance(q);
1142
1143                qPos.add(companyId);
1144
1145                qPos.add(classNameId);
1146
1147                qPos.add(classPK);
1148
1149                list = q.list();
1150            }
1151            catch (Exception e) {
1152                throw processException(e);
1153            }
1154            finally {
1155                if (list == null) {
1156                    list = new ArrayList<Address>();
1157                }
1158
1159                cacheResult(list);
1160
1161                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C,
1162                    finderArgs, list);
1163
1164                closeSession(session);
1165            }
1166        }
1167
1168        return list;
1169    }
1170
1171    public List<Address> findByC_C_C(long companyId, long classNameId,
1172        long classPK, int start, int end) throws SystemException {
1173        return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1174    }
1175
1176    public List<Address> findByC_C_C(long companyId, long classNameId,
1177        long classPK, int start, int end, OrderByComparator obc)
1178        throws SystemException {
1179        Object[] finderArgs = new Object[] {
1180                new Long(companyId), new Long(classNameId), new Long(classPK),
1181                
1182                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1183            };
1184
1185        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_C,
1186                finderArgs, this);
1187
1188        if (list == null) {
1189            Session session = null;
1190
1191            try {
1192                session = openSession();
1193
1194                StringBuilder query = new StringBuilder();
1195
1196                query.append("FROM com.liferay.portal.model.Address WHERE ");
1197
1198                query.append("companyId = ?");
1199
1200                query.append(" AND ");
1201
1202                query.append("classNameId = ?");
1203
1204                query.append(" AND ");
1205
1206                query.append("classPK = ?");
1207
1208                query.append(" ");
1209
1210                if (obc != null) {
1211                    query.append("ORDER BY ");
1212                    query.append(obc.getOrderBy());
1213                }
1214
1215                else {
1216                    query.append("ORDER BY ");
1217
1218                    query.append("createDate ASC");
1219                }
1220
1221                Query q = session.createQuery(query.toString());
1222
1223                QueryPos qPos = QueryPos.getInstance(q);
1224
1225                qPos.add(companyId);
1226
1227                qPos.add(classNameId);
1228
1229                qPos.add(classPK);
1230
1231                list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
1232            }
1233            catch (Exception e) {
1234                throw processException(e);
1235            }
1236            finally {
1237                if (list == null) {
1238                    list = new ArrayList<Address>();
1239                }
1240
1241                cacheResult(list);
1242
1243                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_C,
1244                    finderArgs, list);
1245
1246                closeSession(session);
1247            }
1248        }
1249
1250        return list;
1251    }
1252
1253    public Address findByC_C_C_First(long companyId, long classNameId,
1254        long classPK, OrderByComparator obc)
1255        throws NoSuchAddressException, SystemException {
1256        List<Address> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
1257                obc);
1258
1259        if (list.isEmpty()) {
1260            StringBuilder msg = new StringBuilder();
1261
1262            msg.append("No Address exists with the key {");
1263
1264            msg.append("companyId=" + companyId);
1265
1266            msg.append(", ");
1267            msg.append("classNameId=" + classNameId);
1268
1269            msg.append(", ");
1270            msg.append("classPK=" + classPK);
1271
1272            msg.append(StringPool.CLOSE_CURLY_BRACE);
1273
1274            throw new NoSuchAddressException(msg.toString());
1275        }
1276        else {
1277            return list.get(0);
1278        }
1279    }
1280
1281    public Address findByC_C_C_Last(long companyId, long classNameId,
1282        long classPK, OrderByComparator obc)
1283        throws NoSuchAddressException, SystemException {
1284        int count = countByC_C_C(companyId, classNameId, classPK);
1285
1286        List<Address> list = findByC_C_C(companyId, classNameId, classPK,
1287                count - 1, count, obc);
1288
1289        if (list.isEmpty()) {
1290            StringBuilder msg = new StringBuilder();
1291
1292            msg.append("No Address exists with the key {");
1293
1294            msg.append("companyId=" + companyId);
1295
1296            msg.append(", ");
1297            msg.append("classNameId=" + classNameId);
1298
1299            msg.append(", ");
1300            msg.append("classPK=" + classPK);
1301
1302            msg.append(StringPool.CLOSE_CURLY_BRACE);
1303
1304            throw new NoSuchAddressException(msg.toString());
1305        }
1306        else {
1307            return list.get(0);
1308        }
1309    }
1310
1311    public Address[] findByC_C_C_PrevAndNext(long addressId, long companyId,
1312        long classNameId, long classPK, OrderByComparator obc)
1313        throws NoSuchAddressException, SystemException {
1314        Address address = findByPrimaryKey(addressId);
1315
1316        int count = countByC_C_C(companyId, classNameId, classPK);
1317
1318        Session session = null;
1319
1320        try {
1321            session = openSession();
1322
1323            StringBuilder query = new StringBuilder();
1324
1325            query.append("FROM com.liferay.portal.model.Address WHERE ");
1326
1327            query.append("companyId = ?");
1328
1329            query.append(" AND ");
1330
1331            query.append("classNameId = ?");
1332
1333            query.append(" AND ");
1334
1335            query.append("classPK = ?");
1336
1337            query.append(" ");
1338
1339            if (obc != null) {
1340                query.append("ORDER BY ");
1341                query.append(obc.getOrderBy());
1342            }
1343
1344            else {
1345                query.append("ORDER BY ");
1346
1347                query.append("createDate ASC");
1348            }
1349
1350            Query q = session.createQuery(query.toString());
1351
1352            QueryPos qPos = QueryPos.getInstance(q);
1353
1354            qPos.add(companyId);
1355
1356            qPos.add(classNameId);
1357
1358            qPos.add(classPK);
1359
1360            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
1361
1362            Address[] array = new AddressImpl[3];
1363
1364            array[0] = (Address)objArray[0];
1365            array[1] = (Address)objArray[1];
1366            array[2] = (Address)objArray[2];
1367
1368            return array;
1369        }
1370        catch (Exception e) {
1371            throw processException(e);
1372        }
1373        finally {
1374            closeSession(session);
1375        }
1376    }
1377
1378    public List<Address> findByC_C_C_M(long companyId, long classNameId,
1379        long classPK, boolean mailing) throws SystemException {
1380        Object[] finderArgs = new Object[] {
1381                new Long(companyId), new Long(classNameId), new Long(classPK),
1382                Boolean.valueOf(mailing)
1383            };
1384
1385        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C_M,
1386                finderArgs, this);
1387
1388        if (list == null) {
1389            Session session = null;
1390
1391            try {
1392                session = openSession();
1393
1394                StringBuilder query = new StringBuilder();
1395
1396                query.append("FROM com.liferay.portal.model.Address WHERE ");
1397
1398                query.append("companyId = ?");
1399
1400                query.append(" AND ");
1401
1402                query.append("classNameId = ?");
1403
1404                query.append(" AND ");
1405
1406                query.append("classPK = ?");
1407
1408                query.append(" AND ");
1409
1410                query.append("mailing = ?");
1411
1412                query.append(" ");
1413
1414                query.append("ORDER BY ");
1415
1416                query.append("createDate ASC");
1417
1418                Query q = session.createQuery(query.toString());
1419
1420                QueryPos qPos = QueryPos.getInstance(q);
1421
1422                qPos.add(companyId);
1423
1424                qPos.add(classNameId);
1425
1426                qPos.add(classPK);
1427
1428                qPos.add(mailing);
1429
1430                list = q.list();
1431            }
1432            catch (Exception e) {
1433                throw processException(e);
1434            }
1435            finally {
1436                if (list == null) {
1437                    list = new ArrayList<Address>();
1438                }
1439
1440                cacheResult(list);
1441
1442                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C_M,
1443                    finderArgs, list);
1444
1445                closeSession(session);
1446            }
1447        }
1448
1449        return list;
1450    }
1451
1452    public List<Address> findByC_C_C_M(long companyId, long classNameId,
1453        long classPK, boolean mailing, int start, int end)
1454        throws SystemException {
1455        return findByC_C_C_M(companyId, classNameId, classPK, mailing, start,
1456            end, null);
1457    }
1458
1459    public List<Address> findByC_C_C_M(long companyId, long classNameId,
1460        long classPK, boolean mailing, int start, int end, OrderByComparator obc)
1461        throws SystemException {
1462        Object[] finderArgs = new Object[] {
1463                new Long(companyId), new Long(classNameId), new Long(classPK),
1464                Boolean.valueOf(mailing),
1465                
1466                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1467            };
1468
1469        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_C_M,
1470                finderArgs, this);
1471
1472        if (list == null) {
1473            Session session = null;
1474
1475            try {
1476                session = openSession();
1477
1478                StringBuilder query = new StringBuilder();
1479
1480                query.append("FROM com.liferay.portal.model.Address WHERE ");
1481
1482                query.append("companyId = ?");
1483
1484                query.append(" AND ");
1485
1486                query.append("classNameId = ?");
1487
1488                query.append(" AND ");
1489
1490                query.append("classPK = ?");
1491
1492                query.append(" AND ");
1493
1494                query.append("mailing = ?");
1495
1496                query.append(" ");
1497
1498                if (obc != null) {
1499                    query.append("ORDER BY ");
1500                    query.append(obc.getOrderBy());
1501                }
1502
1503                else {
1504                    query.append("ORDER BY ");
1505
1506                    query.append("createDate ASC");
1507                }
1508
1509                Query q = session.createQuery(query.toString());
1510
1511                QueryPos qPos = QueryPos.getInstance(q);
1512
1513                qPos.add(companyId);
1514
1515                qPos.add(classNameId);
1516
1517                qPos.add(classPK);
1518
1519                qPos.add(mailing);
1520
1521                list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
1522            }
1523            catch (Exception e) {
1524                throw processException(e);
1525            }
1526            finally {
1527                if (list == null) {
1528                    list = new ArrayList<Address>();
1529                }
1530
1531                cacheResult(list);
1532
1533                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_C_M,
1534                    finderArgs, list);
1535
1536                closeSession(session);
1537            }
1538        }
1539
1540        return list;
1541    }
1542
1543    public Address findByC_C_C_M_First(long companyId, long classNameId,
1544        long classPK, boolean mailing, OrderByComparator obc)
1545        throws NoSuchAddressException, SystemException {
1546        List<Address> list = findByC_C_C_M(companyId, classNameId, classPK,
1547                mailing, 0, 1, obc);
1548
1549        if (list.isEmpty()) {
1550            StringBuilder msg = new StringBuilder();
1551
1552            msg.append("No Address exists with the key {");
1553
1554            msg.append("companyId=" + companyId);
1555
1556            msg.append(", ");
1557            msg.append("classNameId=" + classNameId);
1558
1559            msg.append(", ");
1560            msg.append("classPK=" + classPK);
1561
1562            msg.append(", ");
1563            msg.append("mailing=" + mailing);
1564
1565            msg.append(StringPool.CLOSE_CURLY_BRACE);
1566
1567            throw new NoSuchAddressException(msg.toString());
1568        }
1569        else {
1570            return list.get(0);
1571        }
1572    }
1573
1574    public Address findByC_C_C_M_Last(long companyId, long classNameId,
1575        long classPK, boolean mailing, OrderByComparator obc)
1576        throws NoSuchAddressException, SystemException {
1577        int count = countByC_C_C_M(companyId, classNameId, classPK, mailing);
1578
1579        List<Address> list = findByC_C_C_M(companyId, classNameId, classPK,
1580                mailing, count - 1, count, obc);
1581
1582        if (list.isEmpty()) {
1583            StringBuilder msg = new StringBuilder();
1584
1585            msg.append("No Address exists with the key {");
1586
1587            msg.append("companyId=" + companyId);
1588
1589            msg.append(", ");
1590            msg.append("classNameId=" + classNameId);
1591
1592            msg.append(", ");
1593            msg.append("classPK=" + classPK);
1594
1595            msg.append(", ");
1596            msg.append("mailing=" + mailing);
1597
1598            msg.append(StringPool.CLOSE_CURLY_BRACE);
1599
1600            throw new NoSuchAddressException(msg.toString());
1601        }
1602        else {
1603            return list.get(0);
1604        }
1605    }
1606
1607    public Address[] findByC_C_C_M_PrevAndNext(long addressId, long companyId,
1608        long classNameId, long classPK, boolean mailing, OrderByComparator obc)
1609        throws NoSuchAddressException, SystemException {
1610        Address address = findByPrimaryKey(addressId);
1611
1612        int count = countByC_C_C_M(companyId, classNameId, classPK, mailing);
1613
1614        Session session = null;
1615
1616        try {
1617            session = openSession();
1618
1619            StringBuilder query = new StringBuilder();
1620
1621            query.append("FROM com.liferay.portal.model.Address WHERE ");
1622
1623            query.append("companyId = ?");
1624
1625            query.append(" AND ");
1626
1627            query.append("classNameId = ?");
1628
1629            query.append(" AND ");
1630
1631            query.append("classPK = ?");
1632
1633            query.append(" AND ");
1634
1635            query.append("mailing = ?");
1636
1637            query.append(" ");
1638
1639            if (obc != null) {
1640                query.append("ORDER BY ");
1641                query.append(obc.getOrderBy());
1642            }
1643
1644            else {
1645                query.append("ORDER BY ");
1646
1647                query.append("createDate ASC");
1648            }
1649
1650            Query q = session.createQuery(query.toString());
1651
1652            QueryPos qPos = QueryPos.getInstance(q);
1653
1654            qPos.add(companyId);
1655
1656            qPos.add(classNameId);
1657
1658            qPos.add(classPK);
1659
1660            qPos.add(mailing);
1661
1662            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
1663
1664            Address[] array = new AddressImpl[3];
1665
1666            array[0] = (Address)objArray[0];
1667            array[1] = (Address)objArray[1];
1668            array[2] = (Address)objArray[2];
1669
1670            return array;
1671        }
1672        catch (Exception e) {
1673            throw processException(e);
1674        }
1675        finally {
1676            closeSession(session);
1677        }
1678    }
1679
1680    public List<Address> findByC_C_C_P(long companyId, long classNameId,
1681        long classPK, boolean primary) throws SystemException {
1682        Object[] finderArgs = new Object[] {
1683                new Long(companyId), new Long(classNameId), new Long(classPK),
1684                Boolean.valueOf(primary)
1685            };
1686
1687        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C_P,
1688                finderArgs, this);
1689
1690        if (list == null) {
1691            Session session = null;
1692
1693            try {
1694                session = openSession();
1695
1696                StringBuilder query = new StringBuilder();
1697
1698                query.append("FROM com.liferay.portal.model.Address WHERE ");
1699
1700                query.append("companyId = ?");
1701
1702                query.append(" AND ");
1703
1704                query.append("classNameId = ?");
1705
1706                query.append(" AND ");
1707
1708                query.append("classPK = ?");
1709
1710                query.append(" AND ");
1711
1712                query.append("primary_ = ?");
1713
1714                query.append(" ");
1715
1716                query.append("ORDER BY ");
1717
1718                query.append("createDate ASC");
1719
1720                Query q = session.createQuery(query.toString());
1721
1722                QueryPos qPos = QueryPos.getInstance(q);
1723
1724                qPos.add(companyId);
1725
1726                qPos.add(classNameId);
1727
1728                qPos.add(classPK);
1729
1730                qPos.add(primary);
1731
1732                list = q.list();
1733            }
1734            catch (Exception e) {
1735                throw processException(e);
1736            }
1737            finally {
1738                if (list == null) {
1739                    list = new ArrayList<Address>();
1740                }
1741
1742                cacheResult(list);
1743
1744                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C_P,
1745                    finderArgs, list);
1746
1747                closeSession(session);
1748            }
1749        }
1750
1751        return list;
1752    }
1753
1754    public List<Address> findByC_C_C_P(long companyId, long classNameId,
1755        long classPK, boolean primary, int start, int end)
1756        throws SystemException {
1757        return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
1758            end, null);
1759    }
1760
1761    public List<Address> findByC_C_C_P(long companyId, long classNameId,
1762        long classPK, boolean primary, int start, int end, OrderByComparator obc)
1763        throws SystemException {
1764        Object[] finderArgs = new Object[] {
1765                new Long(companyId), new Long(classNameId), new Long(classPK),
1766                Boolean.valueOf(primary),
1767                
1768                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1769            };
1770
1771        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_C_P,
1772                finderArgs, this);
1773
1774        if (list == null) {
1775            Session session = null;
1776
1777            try {
1778                session = openSession();
1779
1780                StringBuilder query = new StringBuilder();
1781
1782                query.append("FROM com.liferay.portal.model.Address WHERE ");
1783
1784                query.append("companyId = ?");
1785
1786                query.append(" AND ");
1787
1788                query.append("classNameId = ?");
1789
1790                query.append(" AND ");
1791
1792                query.append("classPK = ?");
1793
1794                query.append(" AND ");
1795
1796                query.append("primary_ = ?");
1797
1798                query.append(" ");
1799
1800                if (obc != null) {
1801                    query.append("ORDER BY ");
1802                    query.append(obc.getOrderBy());
1803                }
1804
1805                else {
1806                    query.append("ORDER BY ");
1807
1808                    query.append("createDate ASC");
1809                }
1810
1811                Query q = session.createQuery(query.toString());
1812
1813                QueryPos qPos = QueryPos.getInstance(q);
1814
1815                qPos.add(companyId);
1816
1817                qPos.add(classNameId);
1818
1819                qPos.add(classPK);
1820
1821                qPos.add(primary);
1822
1823                list = (List<Address>)QueryUtil.list(q, getDialect(), start, end);
1824            }
1825            catch (Exception e) {
1826                throw processException(e);
1827            }
1828            finally {
1829                if (list == null) {
1830                    list = new ArrayList<Address>();
1831                }
1832
1833                cacheResult(list);
1834
1835                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_C_P,
1836                    finderArgs, list);
1837
1838                closeSession(session);
1839            }
1840        }
1841
1842        return list;
1843    }
1844
1845    public Address findByC_C_C_P_First(long companyId, long classNameId,
1846        long classPK, boolean primary, OrderByComparator obc)
1847        throws NoSuchAddressException, SystemException {
1848        List<Address> list = findByC_C_C_P(companyId, classNameId, classPK,
1849                primary, 0, 1, obc);
1850
1851        if (list.isEmpty()) {
1852            StringBuilder msg = new StringBuilder();
1853
1854            msg.append("No Address exists with the key {");
1855
1856            msg.append("companyId=" + companyId);
1857
1858            msg.append(", ");
1859            msg.append("classNameId=" + classNameId);
1860
1861            msg.append(", ");
1862            msg.append("classPK=" + classPK);
1863
1864            msg.append(", ");
1865            msg.append("primary=" + primary);
1866
1867            msg.append(StringPool.CLOSE_CURLY_BRACE);
1868
1869            throw new NoSuchAddressException(msg.toString());
1870        }
1871        else {
1872            return list.get(0);
1873        }
1874    }
1875
1876    public Address findByC_C_C_P_Last(long companyId, long classNameId,
1877        long classPK, boolean primary, OrderByComparator obc)
1878        throws NoSuchAddressException, SystemException {
1879        int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
1880
1881        List<Address> list = findByC_C_C_P(companyId, classNameId, classPK,
1882                primary, count - 1, count, obc);
1883
1884        if (list.isEmpty()) {
1885            StringBuilder msg = new StringBuilder();
1886
1887            msg.append("No Address exists with the key {");
1888
1889            msg.append("companyId=" + companyId);
1890
1891            msg.append(", ");
1892            msg.append("classNameId=" + classNameId);
1893
1894            msg.append(", ");
1895            msg.append("classPK=" + classPK);
1896
1897            msg.append(", ");
1898            msg.append("primary=" + primary);
1899
1900            msg.append(StringPool.CLOSE_CURLY_BRACE);
1901
1902            throw new NoSuchAddressException(msg.toString());
1903        }
1904        else {
1905            return list.get(0);
1906        }
1907    }
1908
1909    public Address[] findByC_C_C_P_PrevAndNext(long addressId, long companyId,
1910        long classNameId, long classPK, boolean primary, OrderByComparator obc)
1911        throws NoSuchAddressException, SystemException {
1912        Address address = findByPrimaryKey(addressId);
1913
1914        int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
1915
1916        Session session = null;
1917
1918        try {
1919            session = openSession();
1920
1921            StringBuilder query = new StringBuilder();
1922
1923            query.append("FROM com.liferay.portal.model.Address WHERE ");
1924
1925            query.append("companyId = ?");
1926
1927            query.append(" AND ");
1928
1929            query.append("classNameId = ?");
1930
1931            query.append(" AND ");
1932
1933            query.append("classPK = ?");
1934
1935            query.append(" AND ");
1936
1937            query.append("primary_ = ?");
1938
1939            query.append(" ");
1940
1941            if (obc != null) {
1942                query.append("ORDER BY ");
1943                query.append(obc.getOrderBy());
1944            }
1945
1946            else {
1947                query.append("ORDER BY ");
1948
1949                query.append("createDate ASC");
1950            }
1951
1952            Query q = session.createQuery(query.toString());
1953
1954            QueryPos qPos = QueryPos.getInstance(q);
1955
1956            qPos.add(companyId);
1957
1958            qPos.add(classNameId);
1959
1960            qPos.add(classPK);
1961
1962            qPos.add(primary);
1963
1964            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
1965
1966            Address[] array = new AddressImpl[3];
1967
1968            array[0] = (Address)objArray[0];
1969            array[1] = (Address)objArray[1];
1970            array[2] = (Address)objArray[2];
1971
1972            return array;
1973        }
1974        catch (Exception e) {
1975            throw processException(e);
1976        }
1977        finally {
1978            closeSession(session);
1979        }
1980    }
1981
1982    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1983        throws SystemException {
1984        Session session = null;
1985
1986        try {
1987            session = openSession();
1988
1989            dynamicQuery.compile(session);
1990
1991            return dynamicQuery.list();
1992        }
1993        catch (Exception e) {
1994            throw processException(e);
1995        }
1996        finally {
1997            closeSession(session);
1998        }
1999    }
2000
2001    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2002        int start, int end) throws SystemException {
2003        Session session = null;
2004
2005        try {
2006            session = openSession();
2007
2008            dynamicQuery.setLimit(start, end);
2009
2010            dynamicQuery.compile(session);
2011
2012            return dynamicQuery.list();
2013        }
2014        catch (Exception e) {
2015            throw processException(e);
2016        }
2017        finally {
2018            closeSession(session);
2019        }
2020    }
2021
2022    public List<Address> findAll() throws SystemException {
2023        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2024    }
2025
2026    public List<Address> findAll(int start, int end) throws SystemException {
2027        return findAll(start, end, null);
2028    }
2029
2030    public List<Address> findAll(int start, int end, OrderByComparator obc)
2031        throws SystemException {
2032        Object[] finderArgs = new Object[] {
2033                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2034            };
2035
2036        List<Address> list = (List<Address>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2037                finderArgs, this);
2038
2039        if (list == null) {
2040            Session session = null;
2041
2042            try {
2043                session = openSession();
2044
2045                StringBuilder query = new StringBuilder();
2046
2047                query.append("FROM com.liferay.portal.model.Address ");
2048
2049                if (obc != null) {
2050                    query.append("ORDER BY ");
2051                    query.append(obc.getOrderBy());
2052                }
2053
2054                else {
2055                    query.append("ORDER BY ");
2056
2057                    query.append("createDate ASC");
2058                }
2059
2060                Query q = session.createQuery(query.toString());
2061
2062                if (obc == null) {
2063                    list = (List<Address>)QueryUtil.list(q, getDialect(),
2064                            start, end, false);
2065
2066                    Collections.sort(list);
2067                }
2068                else {
2069                    list = (List<Address>)QueryUtil.list(q, getDialect(),
2070                            start, end);
2071                }
2072            }
2073            catch (Exception e) {
2074                throw processException(e);
2075            }
2076            finally {
2077                if (list == null) {
2078                    list = new ArrayList<Address>();
2079                }
2080
2081                cacheResult(list);
2082
2083                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2084
2085                closeSession(session);
2086            }
2087        }
2088
2089        return list;
2090    }
2091
2092    public void removeByCompanyId(long companyId) throws SystemException {
2093        for (Address address : findByCompanyId(companyId)) {
2094            remove(address);
2095        }
2096    }
2097
2098    public void removeByUserId(long userId) throws SystemException {
2099        for (Address address : findByUserId(userId)) {
2100            remove(address);
2101        }
2102    }
2103
2104    public void removeByC_C(long companyId, long classNameId)
2105        throws SystemException {
2106        for (Address address : findByC_C(companyId, classNameId)) {
2107            remove(address);
2108        }
2109    }
2110
2111    public void removeByC_C_C(long companyId, long classNameId, long classPK)
2112        throws SystemException {
2113        for (Address address : findByC_C_C(companyId, classNameId, classPK)) {
2114            remove(address);
2115        }
2116    }
2117
2118    public void removeByC_C_C_M(long companyId, long classNameId, long classPK,
2119        boolean mailing) throws SystemException {
2120        for (Address address : findByC_C_C_M(companyId, classNameId, classPK,
2121                mailing)) {
2122            remove(address);
2123        }
2124    }
2125
2126    public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
2127        boolean primary) throws SystemException {
2128        for (Address address : findByC_C_C_P(companyId, classNameId, classPK,
2129                primary)) {
2130            remove(address);
2131        }
2132    }
2133
2134    public void removeAll() throws SystemException {
2135        for (Address address : findAll()) {
2136            remove(address);
2137        }
2138    }
2139
2140    public int countByCompanyId(long companyId) throws SystemException {
2141        Object[] finderArgs = new Object[] { new Long(companyId) };
2142
2143        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2144                finderArgs, this);
2145
2146        if (count == null) {
2147            Session session = null;
2148
2149            try {
2150                session = openSession();
2151
2152                StringBuilder query = new StringBuilder();
2153
2154                query.append("SELECT COUNT(*) ");
2155                query.append("FROM com.liferay.portal.model.Address WHERE ");
2156
2157                query.append("companyId = ?");
2158
2159                query.append(" ");
2160
2161                Query q = session.createQuery(query.toString());
2162
2163                QueryPos qPos = QueryPos.getInstance(q);
2164
2165                qPos.add(companyId);
2166
2167                count = (Long)q.uniqueResult();
2168            }
2169            catch (Exception e) {
2170                throw processException(e);
2171            }
2172            finally {
2173                if (count == null) {
2174                    count = Long.valueOf(0);
2175                }
2176
2177                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2178                    finderArgs, count);
2179
2180                closeSession(session);
2181            }
2182        }
2183
2184        return count.intValue();
2185    }
2186
2187    public int countByUserId(long userId) throws SystemException {
2188        Object[] finderArgs = new Object[] { new Long(userId) };
2189
2190        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2191                finderArgs, this);
2192
2193        if (count == null) {
2194            Session session = null;
2195
2196            try {
2197                session = openSession();
2198
2199                StringBuilder query = new StringBuilder();
2200
2201                query.append("SELECT COUNT(*) ");
2202                query.append("FROM com.liferay.portal.model.Address WHERE ");
2203
2204                query.append("userId = ?");
2205
2206                query.append(" ");
2207
2208                Query q = session.createQuery(query.toString());
2209
2210                QueryPos qPos = QueryPos.getInstance(q);
2211
2212                qPos.add(userId);
2213
2214                count = (Long)q.uniqueResult();
2215            }
2216            catch (Exception e) {
2217                throw processException(e);
2218            }
2219            finally {
2220                if (count == null) {
2221                    count = Long.valueOf(0);
2222                }
2223
2224                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2225                    finderArgs, count);
2226
2227                closeSession(session);
2228            }
2229        }
2230
2231        return count.intValue();
2232    }
2233
2234    public int countByC_C(long companyId, long classNameId)
2235        throws SystemException {
2236        Object[] finderArgs = new Object[] {
2237                new Long(companyId), new Long(classNameId)
2238            };
2239
2240        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
2241                finderArgs, this);
2242
2243        if (count == null) {
2244            Session session = null;
2245
2246            try {
2247                session = openSession();
2248
2249                StringBuilder query = new StringBuilder();
2250
2251                query.append("SELECT COUNT(*) ");
2252                query.append("FROM com.liferay.portal.model.Address WHERE ");
2253
2254                query.append("companyId = ?");
2255
2256                query.append(" AND ");
2257
2258                query.append("classNameId = ?");
2259
2260                query.append(" ");
2261
2262                Query q = session.createQuery(query.toString());
2263
2264                QueryPos qPos = QueryPos.getInstance(q);
2265
2266                qPos.add(companyId);
2267
2268                qPos.add(classNameId);
2269
2270                count = (Long)q.uniqueResult();
2271            }
2272            catch (Exception e) {
2273                throw processException(e);
2274            }
2275            finally {
2276                if (count == null) {
2277                    count = Long.valueOf(0);
2278                }
2279
2280                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2281                    count);
2282
2283                closeSession(session);
2284            }
2285        }
2286
2287        return count.intValue();
2288    }
2289
2290    public int countByC_C_C(long companyId, long classNameId, long classPK)
2291        throws SystemException {
2292        Object[] finderArgs = new Object[] {
2293                new Long(companyId), new Long(classNameId), new Long(classPK)
2294            };
2295
2296        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
2297                finderArgs, this);
2298
2299        if (count == null) {
2300            Session session = null;
2301
2302            try {
2303                session = openSession();
2304
2305                StringBuilder query = new StringBuilder();
2306
2307                query.append("SELECT COUNT(*) ");
2308                query.append("FROM com.liferay.portal.model.Address WHERE ");
2309
2310                query.append("companyId = ?");
2311
2312                query.append(" AND ");
2313
2314                query.append("classNameId = ?");
2315
2316                query.append(" AND ");
2317
2318                query.append("classPK = ?");
2319
2320                query.append(" ");
2321
2322                Query q = session.createQuery(query.toString());
2323
2324                QueryPos qPos = QueryPos.getInstance(q);
2325
2326                qPos.add(companyId);
2327
2328                qPos.add(classNameId);
2329
2330                qPos.add(classPK);
2331
2332                count = (Long)q.uniqueResult();
2333            }
2334            catch (Exception e) {
2335                throw processException(e);
2336            }
2337            finally {
2338                if (count == null) {
2339                    count = Long.valueOf(0);
2340                }
2341
2342                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2343                    finderArgs, count);
2344
2345                closeSession(session);
2346            }
2347        }
2348
2349        return count.intValue();
2350    }
2351
2352    public int countByC_C_C_M(long companyId, long classNameId, long classPK,
2353        boolean mailing) throws SystemException {
2354        Object[] finderArgs = new Object[] {
2355                new Long(companyId), new Long(classNameId), new Long(classPK),
2356                Boolean.valueOf(mailing)
2357            };
2358
2359        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C_M,
2360                finderArgs, this);
2361
2362        if (count == null) {
2363            Session session = null;
2364
2365            try {
2366                session = openSession();
2367
2368                StringBuilder query = new StringBuilder();
2369
2370                query.append("SELECT COUNT(*) ");
2371                query.append("FROM com.liferay.portal.model.Address WHERE ");
2372
2373                query.append("companyId = ?");
2374
2375                query.append(" AND ");
2376
2377                query.append("classNameId = ?");
2378
2379                query.append(" AND ");
2380
2381                query.append("classPK = ?");
2382
2383                query.append(" AND ");
2384
2385                query.append("mailing = ?");
2386
2387                query.append(" ");
2388
2389                Query q = session.createQuery(query.toString());
2390
2391                QueryPos qPos = QueryPos.getInstance(q);
2392
2393                qPos.add(companyId);
2394
2395                qPos.add(classNameId);
2396
2397                qPos.add(classPK);
2398
2399                qPos.add(mailing);
2400
2401                count = (Long)q.uniqueResult();
2402            }
2403            catch (Exception e) {
2404                throw processException(e);
2405            }
2406            finally {
2407                if (count == null) {
2408                    count = Long.valueOf(0);
2409                }
2410
2411                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C_M,
2412                    finderArgs, count);
2413
2414                closeSession(session);
2415            }
2416        }
2417
2418        return count.intValue();
2419    }
2420
2421    public int countByC_C_C_P(long companyId, long classNameId, long classPK,
2422        boolean primary) throws SystemException {
2423        Object[] finderArgs = new Object[] {
2424                new Long(companyId), new Long(classNameId), new Long(classPK),
2425                Boolean.valueOf(primary)
2426            };
2427
2428        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C_P,
2429                finderArgs, this);
2430
2431        if (count == null) {
2432            Session session = null;
2433
2434            try {
2435                session = openSession();
2436
2437                StringBuilder query = new StringBuilder();
2438
2439                query.append("SELECT COUNT(*) ");
2440                query.append("FROM com.liferay.portal.model.Address WHERE ");
2441
2442                query.append("companyId = ?");
2443
2444                query.append(" AND ");
2445
2446                query.append("classNameId = ?");
2447
2448                query.append(" AND ");
2449
2450                query.append("classPK = ?");
2451
2452                query.append(" AND ");
2453
2454                query.append("primary_ = ?");
2455
2456                query.append(" ");
2457
2458                Query q = session.createQuery(query.toString());
2459
2460                QueryPos qPos = QueryPos.getInstance(q);
2461
2462                qPos.add(companyId);
2463
2464                qPos.add(classNameId);
2465
2466                qPos.add(classPK);
2467
2468                qPos.add(primary);
2469
2470                count = (Long)q.uniqueResult();
2471            }
2472            catch (Exception e) {
2473                throw processException(e);
2474            }
2475            finally {
2476                if (count == null) {
2477                    count = Long.valueOf(0);
2478                }
2479
2480                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C_P,
2481                    finderArgs, count);
2482
2483                closeSession(session);
2484            }
2485        }
2486
2487        return count.intValue();
2488    }
2489
2490    public int countAll() throws SystemException {
2491        Object[] finderArgs = new Object[0];
2492
2493        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2494                finderArgs, this);
2495
2496        if (count == null) {
2497            Session session = null;
2498
2499            try {
2500                session = openSession();
2501
2502                Query q = session.createQuery(
2503                        "SELECT COUNT(*) FROM com.liferay.portal.model.Address");
2504
2505                count = (Long)q.uniqueResult();
2506            }
2507            catch (Exception e) {
2508                throw processException(e);
2509            }
2510            finally {
2511                if (count == null) {
2512                    count = Long.valueOf(0);
2513                }
2514
2515                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2516                    count);
2517
2518                closeSession(session);
2519            }
2520        }
2521
2522        return count.intValue();
2523    }
2524
2525    public void afterPropertiesSet() {
2526        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2527                    com.liferay.portal.util.PropsUtil.get(
2528                        "value.object.listener.com.liferay.portal.model.Address")));
2529
2530        if (listenerClassNames.length > 0) {
2531            try {
2532                List<ModelListener<Address>> listenersList = new ArrayList<ModelListener<Address>>();
2533
2534                for (String listenerClassName : listenerClassNames) {
2535                    listenersList.add((ModelListener<Address>)Class.forName(
2536                            listenerClassName).newInstance());
2537                }
2538
2539                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2540            }
2541            catch (Exception e) {
2542                _log.error(e);
2543            }
2544        }
2545    }
2546
2547    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
2548    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
2549    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
2550    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
2551    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
2552    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
2553    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
2554    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
2555    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
2556    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
2557    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
2558    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
2559    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
2560    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
2561    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
2562    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
2563    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
2564    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
2565    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
2566    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
2567    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
2568    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
2569    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
2570    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
2571    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
2572    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
2573    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
2574    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
2575    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
2576    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
2577    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
2578    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2579    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
2580    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
2581    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
2582    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
2583    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
2584    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
2585    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
2586    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2587    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
2588    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
2589    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
2590    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
2591    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
2592    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
2593    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
2594    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
2595    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
2596    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
2597    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
2598    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
2599    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
2600    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
2601    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
2602    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
2603    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
2604    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
2605    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2606    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2607    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
2608    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
2609    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
2610    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
2611    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
2612    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
2613    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
2614    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
2615    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
2616    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
2617    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
2618    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
2619    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
2620    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
2621    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2622    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2623    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
2624    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
2625    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
2626    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
2627    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
2628    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
2629    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
2630    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
2631    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
2632    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
2633    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
2634    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
2635    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
2636    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
2637    private static Log _log = LogFactoryUtil.getLog(AddressPersistenceImpl.class);
2638}