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