1   /**
2    * Copyright (c) 2000-2007 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.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.model.Address;
33  import com.liferay.portal.model.impl.AddressImpl;
34  import com.liferay.portal.service.persistence.BasePersistence;
35  import com.liferay.portal.spring.hibernate.FinderCache;
36  import com.liferay.portal.spring.hibernate.HibernateUtil;
37  
38  import com.liferay.util.dao.hibernate.QueryUtil;
39  
40  import org.apache.commons.logging.Log;
41  import org.apache.commons.logging.LogFactory;
42  
43  import org.hibernate.Query;
44  import org.hibernate.Session;
45  
46  import java.util.Collections;
47  import java.util.Iterator;
48  import java.util.List;
49  
50  /**
51   * <a href="AddressPersistenceImpl.java.html"><b><i>View Source</i></b></a>
52   *
53   * @author Brian Wing Shun Chan
54   *
55   */
56  public class AddressPersistenceImpl extends BasePersistence
57      implements AddressPersistence {
58      public Address create(long addressId) {
59          Address address = new AddressImpl();
60          address.setNew(true);
61          address.setPrimaryKey(addressId);
62  
63          return address;
64      }
65  
66      public Address remove(long addressId)
67          throws NoSuchAddressException, SystemException {
68          Session session = null;
69  
70          try {
71              session = openSession();
72  
73              Address address = (Address)session.get(AddressImpl.class,
74                      new Long(addressId));
75  
76              if (address == null) {
77                  if (_log.isWarnEnabled()) {
78                      _log.warn("No Address exists with the primary key " +
79                          addressId);
80                  }
81  
82                  throw new NoSuchAddressException(
83                      "No Address exists with the primary key " + addressId);
84              }
85  
86              return remove(address);
87          }
88          catch (NoSuchAddressException nsee) {
89              throw nsee;
90          }
91          catch (Exception e) {
92              throw HibernateUtil.processException(e);
93          }
94          finally {
95              closeSession(session);
96          }
97      }
98  
99      public Address remove(Address address) throws SystemException {
100         Session session = null;
101 
102         try {
103             session = openSession();
104             session.delete(address);
105             session.flush();
106 
107             return address;
108         }
109         catch (Exception e) {
110             throw HibernateUtil.processException(e);
111         }
112         finally {
113             closeSession(session);
114             FinderCache.clearCache(Address.class.getName());
115         }
116     }
117 
118     public Address update(com.liferay.portal.model.Address address)
119         throws SystemException {
120         return update(address, false);
121     }
122 
123     public Address update(com.liferay.portal.model.Address address,
124         boolean merge) throws SystemException {
125         Session session = null;
126 
127         try {
128             session = openSession();
129 
130             if (merge) {
131                 session.merge(address);
132             }
133             else {
134                 if (address.isNew()) {
135                     session.save(address);
136                 }
137             }
138 
139             session.flush();
140             address.setNew(false);
141 
142             return address;
143         }
144         catch (Exception e) {
145             throw HibernateUtil.processException(e);
146         }
147         finally {
148             closeSession(session);
149             FinderCache.clearCache(Address.class.getName());
150         }
151     }
152 
153     public Address findByPrimaryKey(long addressId)
154         throws NoSuchAddressException, SystemException {
155         Address address = fetchByPrimaryKey(addressId);
156 
157         if (address == null) {
158             if (_log.isWarnEnabled()) {
159                 _log.warn("No Address exists with the primary key " +
160                     addressId);
161             }
162 
163             throw new NoSuchAddressException(
164                 "No Address exists with the primary key " + addressId);
165         }
166 
167         return address;
168     }
169 
170     public Address fetchByPrimaryKey(long addressId) throws SystemException {
171         Session session = null;
172 
173         try {
174             session = openSession();
175 
176             return (Address)session.get(AddressImpl.class, new Long(addressId));
177         }
178         catch (Exception e) {
179             throw HibernateUtil.processException(e);
180         }
181         finally {
182             closeSession(session);
183         }
184     }
185 
186     public List findByCompanyId(long companyId) throws SystemException {
187         String finderClassName = Address.class.getName();
188         String finderMethodName = "findByCompanyId";
189         String[] finderParams = new String[] { Long.class.getName() };
190         Object[] finderArgs = new Object[] { new Long(companyId) };
191         Object result = FinderCache.getResult(finderClassName,
192                 finderMethodName, finderParams, finderArgs, getSessionFactory());
193 
194         if (result == null) {
195             Session session = null;
196 
197             try {
198                 session = openSession();
199 
200                 StringMaker query = new StringMaker();
201                 query.append("FROM com.liferay.portal.model.Address WHERE ");
202                 query.append("companyId = ?");
203                 query.append(" ");
204                 query.append("ORDER BY ");
205                 query.append("createDate ASC");
206 
207                 Query q = session.createQuery(query.toString());
208                 int queryPos = 0;
209                 q.setLong(queryPos++, companyId);
210 
211                 List list = q.list();
212                 FinderCache.putResult(finderClassName, finderMethodName,
213                     finderParams, finderArgs, list);
214 
215                 return list;
216             }
217             catch (Exception e) {
218                 throw HibernateUtil.processException(e);
219             }
220             finally {
221                 closeSession(session);
222             }
223         }
224         else {
225             return (List)result;
226         }
227     }
228 
229     public List findByCompanyId(long companyId, int begin, int end)
230         throws SystemException {
231         return findByCompanyId(companyId, begin, end, null);
232     }
233 
234     public List findByCompanyId(long companyId, int begin, int end,
235         OrderByComparator obc) throws SystemException {
236         String finderClassName = Address.class.getName();
237         String finderMethodName = "findByCompanyId";
238         String[] finderParams = new String[] {
239                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
240                 "com.liferay.portal.kernel.util.OrderByComparator"
241             };
242         Object[] finderArgs = new Object[] {
243                 new Long(companyId), String.valueOf(begin), String.valueOf(end),
244                 String.valueOf(obc)
245             };
246         Object result = FinderCache.getResult(finderClassName,
247                 finderMethodName, finderParams, finderArgs, getSessionFactory());
248 
249         if (result == null) {
250             Session session = null;
251 
252             try {
253                 session = openSession();
254 
255                 StringMaker query = new StringMaker();
256                 query.append("FROM com.liferay.portal.model.Address WHERE ");
257                 query.append("companyId = ?");
258                 query.append(" ");
259 
260                 if (obc != null) {
261                     query.append("ORDER BY ");
262                     query.append(obc.getOrderBy());
263                 }
264                 else {
265                     query.append("ORDER BY ");
266                     query.append("createDate ASC");
267                 }
268 
269                 Query q = session.createQuery(query.toString());
270                 int queryPos = 0;
271                 q.setLong(queryPos++, companyId);
272 
273                 List list = QueryUtil.list(q, getDialect(), begin, end);
274                 FinderCache.putResult(finderClassName, finderMethodName,
275                     finderParams, finderArgs, list);
276 
277                 return list;
278             }
279             catch (Exception e) {
280                 throw HibernateUtil.processException(e);
281             }
282             finally {
283                 closeSession(session);
284             }
285         }
286         else {
287             return (List)result;
288         }
289     }
290 
291     public Address findByCompanyId_First(long companyId, OrderByComparator obc)
292         throws NoSuchAddressException, SystemException {
293         List list = findByCompanyId(companyId, 0, 1, obc);
294 
295         if (list.size() == 0) {
296             StringMaker msg = new StringMaker();
297             msg.append("No Address exists with the key ");
298             msg.append(StringPool.OPEN_CURLY_BRACE);
299             msg.append("companyId=");
300             msg.append(companyId);
301             msg.append(StringPool.CLOSE_CURLY_BRACE);
302             throw new NoSuchAddressException(msg.toString());
303         }
304         else {
305             return (Address)list.get(0);
306         }
307     }
308 
309     public Address findByCompanyId_Last(long companyId, OrderByComparator obc)
310         throws NoSuchAddressException, SystemException {
311         int count = countByCompanyId(companyId);
312         List list = findByCompanyId(companyId, count - 1, count, obc);
313 
314         if (list.size() == 0) {
315             StringMaker msg = new StringMaker();
316             msg.append("No Address exists with the key ");
317             msg.append(StringPool.OPEN_CURLY_BRACE);
318             msg.append("companyId=");
319             msg.append(companyId);
320             msg.append(StringPool.CLOSE_CURLY_BRACE);
321             throw new NoSuchAddressException(msg.toString());
322         }
323         else {
324             return (Address)list.get(0);
325         }
326     }
327 
328     public Address[] findByCompanyId_PrevAndNext(long addressId,
329         long companyId, OrderByComparator obc)
330         throws NoSuchAddressException, SystemException {
331         Address address = findByPrimaryKey(addressId);
332         int count = countByCompanyId(companyId);
333         Session session = null;
334 
335         try {
336             session = openSession();
337 
338             StringMaker query = new StringMaker();
339             query.append("FROM com.liferay.portal.model.Address WHERE ");
340             query.append("companyId = ?");
341             query.append(" ");
342 
343             if (obc != null) {
344                 query.append("ORDER BY ");
345                 query.append(obc.getOrderBy());
346             }
347             else {
348                 query.append("ORDER BY ");
349                 query.append("createDate ASC");
350             }
351 
352             Query q = session.createQuery(query.toString());
353             int queryPos = 0;
354             q.setLong(queryPos++, companyId);
355 
356             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
357             Address[] array = new AddressImpl[3];
358             array[0] = (Address)objArray[0];
359             array[1] = (Address)objArray[1];
360             array[2] = (Address)objArray[2];
361 
362             return array;
363         }
364         catch (Exception e) {
365             throw HibernateUtil.processException(e);
366         }
367         finally {
368             closeSession(session);
369         }
370     }
371 
372     public List findByUserId(long userId) throws SystemException {
373         String finderClassName = Address.class.getName();
374         String finderMethodName = "findByUserId";
375         String[] finderParams = new String[] { Long.class.getName() };
376         Object[] finderArgs = new Object[] { new Long(userId) };
377         Object result = FinderCache.getResult(finderClassName,
378                 finderMethodName, finderParams, finderArgs, getSessionFactory());
379 
380         if (result == null) {
381             Session session = null;
382 
383             try {
384                 session = openSession();
385 
386                 StringMaker query = new StringMaker();
387                 query.append("FROM com.liferay.portal.model.Address WHERE ");
388                 query.append("userId = ?");
389                 query.append(" ");
390                 query.append("ORDER BY ");
391                 query.append("createDate ASC");
392 
393                 Query q = session.createQuery(query.toString());
394                 int queryPos = 0;
395                 q.setLong(queryPos++, userId);
396 
397                 List list = q.list();
398                 FinderCache.putResult(finderClassName, finderMethodName,
399                     finderParams, finderArgs, list);
400 
401                 return list;
402             }
403             catch (Exception e) {
404                 throw HibernateUtil.processException(e);
405             }
406             finally {
407                 closeSession(session);
408             }
409         }
410         else {
411             return (List)result;
412         }
413     }
414 
415     public List findByUserId(long userId, int begin, int end)
416         throws SystemException {
417         return findByUserId(userId, begin, end, null);
418     }
419 
420     public List findByUserId(long userId, int begin, int end,
421         OrderByComparator obc) throws SystemException {
422         String finderClassName = Address.class.getName();
423         String finderMethodName = "findByUserId";
424         String[] finderParams = new String[] {
425                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
426                 "com.liferay.portal.kernel.util.OrderByComparator"
427             };
428         Object[] finderArgs = new Object[] {
429                 new Long(userId), String.valueOf(begin), String.valueOf(end),
430                 String.valueOf(obc)
431             };
432         Object result = FinderCache.getResult(finderClassName,
433                 finderMethodName, finderParams, finderArgs, getSessionFactory());
434 
435         if (result == null) {
436             Session session = null;
437 
438             try {
439                 session = openSession();
440 
441                 StringMaker query = new StringMaker();
442                 query.append("FROM com.liferay.portal.model.Address WHERE ");
443                 query.append("userId = ?");
444                 query.append(" ");
445 
446                 if (obc != null) {
447                     query.append("ORDER BY ");
448                     query.append(obc.getOrderBy());
449                 }
450                 else {
451                     query.append("ORDER BY ");
452                     query.append("createDate ASC");
453                 }
454 
455                 Query q = session.createQuery(query.toString());
456                 int queryPos = 0;
457                 q.setLong(queryPos++, userId);
458 
459                 List list = QueryUtil.list(q, getDialect(), begin, end);
460                 FinderCache.putResult(finderClassName, finderMethodName,
461                     finderParams, finderArgs, list);
462 
463                 return list;
464             }
465             catch (Exception e) {
466                 throw HibernateUtil.processException(e);
467             }
468             finally {
469                 closeSession(session);
470             }
471         }
472         else {
473             return (List)result;
474         }
475     }
476 
477     public Address findByUserId_First(long userId, OrderByComparator obc)
478         throws NoSuchAddressException, SystemException {
479         List list = findByUserId(userId, 0, 1, obc);
480 
481         if (list.size() == 0) {
482             StringMaker msg = new StringMaker();
483             msg.append("No Address exists with the key ");
484             msg.append(StringPool.OPEN_CURLY_BRACE);
485             msg.append("userId=");
486             msg.append(userId);
487             msg.append(StringPool.CLOSE_CURLY_BRACE);
488             throw new NoSuchAddressException(msg.toString());
489         }
490         else {
491             return (Address)list.get(0);
492         }
493     }
494 
495     public Address findByUserId_Last(long userId, OrderByComparator obc)
496         throws NoSuchAddressException, SystemException {
497         int count = countByUserId(userId);
498         List list = findByUserId(userId, count - 1, count, obc);
499 
500         if (list.size() == 0) {
501             StringMaker msg = new StringMaker();
502             msg.append("No Address exists with the key ");
503             msg.append(StringPool.OPEN_CURLY_BRACE);
504             msg.append("userId=");
505             msg.append(userId);
506             msg.append(StringPool.CLOSE_CURLY_BRACE);
507             throw new NoSuchAddressException(msg.toString());
508         }
509         else {
510             return (Address)list.get(0);
511         }
512     }
513 
514     public Address[] findByUserId_PrevAndNext(long addressId, long userId,
515         OrderByComparator obc) throws NoSuchAddressException, SystemException {
516         Address address = findByPrimaryKey(addressId);
517         int count = countByUserId(userId);
518         Session session = null;
519 
520         try {
521             session = openSession();
522 
523             StringMaker query = new StringMaker();
524             query.append("FROM com.liferay.portal.model.Address WHERE ");
525             query.append("userId = ?");
526             query.append(" ");
527 
528             if (obc != null) {
529                 query.append("ORDER BY ");
530                 query.append(obc.getOrderBy());
531             }
532             else {
533                 query.append("ORDER BY ");
534                 query.append("createDate ASC");
535             }
536 
537             Query q = session.createQuery(query.toString());
538             int queryPos = 0;
539             q.setLong(queryPos++, userId);
540 
541             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
542             Address[] array = new AddressImpl[3];
543             array[0] = (Address)objArray[0];
544             array[1] = (Address)objArray[1];
545             array[2] = (Address)objArray[2];
546 
547             return array;
548         }
549         catch (Exception e) {
550             throw HibernateUtil.processException(e);
551         }
552         finally {
553             closeSession(session);
554         }
555     }
556 
557     public List findByC_C(long companyId, long classNameId)
558         throws SystemException {
559         String finderClassName = Address.class.getName();
560         String finderMethodName = "findByC_C";
561         String[] finderParams = new String[] {
562                 Long.class.getName(), Long.class.getName()
563             };
564         Object[] finderArgs = new Object[] {
565                 new Long(companyId), new Long(classNameId)
566             };
567         Object result = FinderCache.getResult(finderClassName,
568                 finderMethodName, finderParams, finderArgs, getSessionFactory());
569 
570         if (result == null) {
571             Session session = null;
572 
573             try {
574                 session = openSession();
575 
576                 StringMaker query = new StringMaker();
577                 query.append("FROM com.liferay.portal.model.Address WHERE ");
578                 query.append("companyId = ?");
579                 query.append(" AND ");
580                 query.append("classNameId = ?");
581                 query.append(" ");
582                 query.append("ORDER BY ");
583                 query.append("createDate ASC");
584 
585                 Query q = session.createQuery(query.toString());
586                 int queryPos = 0;
587                 q.setLong(queryPos++, companyId);
588                 q.setLong(queryPos++, classNameId);
589 
590                 List list = q.list();
591                 FinderCache.putResult(finderClassName, finderMethodName,
592                     finderParams, finderArgs, list);
593 
594                 return list;
595             }
596             catch (Exception e) {
597                 throw HibernateUtil.processException(e);
598             }
599             finally {
600                 closeSession(session);
601             }
602         }
603         else {
604             return (List)result;
605         }
606     }
607 
608     public List findByC_C(long companyId, long classNameId, int begin, int end)
609         throws SystemException {
610         return findByC_C(companyId, classNameId, begin, end, null);
611     }
612 
613     public List findByC_C(long companyId, long classNameId, int begin, int end,
614         OrderByComparator obc) throws SystemException {
615         String finderClassName = Address.class.getName();
616         String finderMethodName = "findByC_C";
617         String[] finderParams = new String[] {
618                 Long.class.getName(), Long.class.getName(), "java.lang.Integer",
619                 "java.lang.Integer",
620                 "com.liferay.portal.kernel.util.OrderByComparator"
621             };
622         Object[] finderArgs = new Object[] {
623                 new Long(companyId), new Long(classNameId),
624                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
625             };
626         Object result = FinderCache.getResult(finderClassName,
627                 finderMethodName, finderParams, finderArgs, getSessionFactory());
628 
629         if (result == null) {
630             Session session = null;
631 
632             try {
633                 session = openSession();
634 
635                 StringMaker query = new StringMaker();
636                 query.append("FROM com.liferay.portal.model.Address WHERE ");
637                 query.append("companyId = ?");
638                 query.append(" AND ");
639                 query.append("classNameId = ?");
640                 query.append(" ");
641 
642                 if (obc != null) {
643                     query.append("ORDER BY ");
644                     query.append(obc.getOrderBy());
645                 }
646                 else {
647                     query.append("ORDER BY ");
648                     query.append("createDate ASC");
649                 }
650 
651                 Query q = session.createQuery(query.toString());
652                 int queryPos = 0;
653                 q.setLong(queryPos++, companyId);
654                 q.setLong(queryPos++, classNameId);
655 
656                 List list = QueryUtil.list(q, getDialect(), begin, end);
657                 FinderCache.putResult(finderClassName, finderMethodName,
658                     finderParams, finderArgs, list);
659 
660                 return list;
661             }
662             catch (Exception e) {
663                 throw HibernateUtil.processException(e);
664             }
665             finally {
666                 closeSession(session);
667             }
668         }
669         else {
670             return (List)result;
671         }
672     }
673 
674     public Address findByC_C_First(long companyId, long classNameId,
675         OrderByComparator obc) throws NoSuchAddressException, SystemException {
676         List list = findByC_C(companyId, classNameId, 0, 1, obc);
677 
678         if (list.size() == 0) {
679             StringMaker msg = new StringMaker();
680             msg.append("No Address exists with the key ");
681             msg.append(StringPool.OPEN_CURLY_BRACE);
682             msg.append("companyId=");
683             msg.append(companyId);
684             msg.append(", ");
685             msg.append("classNameId=");
686             msg.append(classNameId);
687             msg.append(StringPool.CLOSE_CURLY_BRACE);
688             throw new NoSuchAddressException(msg.toString());
689         }
690         else {
691             return (Address)list.get(0);
692         }
693     }
694 
695     public Address findByC_C_Last(long companyId, long classNameId,
696         OrderByComparator obc) throws NoSuchAddressException, SystemException {
697         int count = countByC_C(companyId, classNameId);
698         List list = findByC_C(companyId, classNameId, count - 1, count, obc);
699 
700         if (list.size() == 0) {
701             StringMaker msg = new StringMaker();
702             msg.append("No Address exists with the key ");
703             msg.append(StringPool.OPEN_CURLY_BRACE);
704             msg.append("companyId=");
705             msg.append(companyId);
706             msg.append(", ");
707             msg.append("classNameId=");
708             msg.append(classNameId);
709             msg.append(StringPool.CLOSE_CURLY_BRACE);
710             throw new NoSuchAddressException(msg.toString());
711         }
712         else {
713             return (Address)list.get(0);
714         }
715     }
716 
717     public Address[] findByC_C_PrevAndNext(long addressId, long companyId,
718         long classNameId, OrderByComparator obc)
719         throws NoSuchAddressException, SystemException {
720         Address address = findByPrimaryKey(addressId);
721         int count = countByC_C(companyId, classNameId);
722         Session session = null;
723 
724         try {
725             session = openSession();
726 
727             StringMaker query = new StringMaker();
728             query.append("FROM com.liferay.portal.model.Address WHERE ");
729             query.append("companyId = ?");
730             query.append(" AND ");
731             query.append("classNameId = ?");
732             query.append(" ");
733 
734             if (obc != null) {
735                 query.append("ORDER BY ");
736                 query.append(obc.getOrderBy());
737             }
738             else {
739                 query.append("ORDER BY ");
740                 query.append("createDate ASC");
741             }
742 
743             Query q = session.createQuery(query.toString());
744             int queryPos = 0;
745             q.setLong(queryPos++, companyId);
746             q.setLong(queryPos++, classNameId);
747 
748             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
749             Address[] array = new AddressImpl[3];
750             array[0] = (Address)objArray[0];
751             array[1] = (Address)objArray[1];
752             array[2] = (Address)objArray[2];
753 
754             return array;
755         }
756         catch (Exception e) {
757             throw HibernateUtil.processException(e);
758         }
759         finally {
760             closeSession(session);
761         }
762     }
763 
764     public List findByC_C_C(long companyId, long classNameId, long classPK)
765         throws SystemException {
766         String finderClassName = Address.class.getName();
767         String finderMethodName = "findByC_C_C";
768         String[] finderParams = new String[] {
769                 Long.class.getName(), Long.class.getName(), Long.class.getName()
770             };
771         Object[] finderArgs = new Object[] {
772                 new Long(companyId), new Long(classNameId), new Long(classPK)
773             };
774         Object result = FinderCache.getResult(finderClassName,
775                 finderMethodName, finderParams, finderArgs, getSessionFactory());
776 
777         if (result == null) {
778             Session session = null;
779 
780             try {
781                 session = openSession();
782 
783                 StringMaker query = new StringMaker();
784                 query.append("FROM com.liferay.portal.model.Address WHERE ");
785                 query.append("companyId = ?");
786                 query.append(" AND ");
787                 query.append("classNameId = ?");
788                 query.append(" AND ");
789                 query.append("classPK = ?");
790                 query.append(" ");
791                 query.append("ORDER BY ");
792                 query.append("createDate ASC");
793 
794                 Query q = session.createQuery(query.toString());
795                 int queryPos = 0;
796                 q.setLong(queryPos++, companyId);
797                 q.setLong(queryPos++, classNameId);
798                 q.setLong(queryPos++, classPK);
799 
800                 List list = q.list();
801                 FinderCache.putResult(finderClassName, finderMethodName,
802                     finderParams, finderArgs, list);
803 
804                 return list;
805             }
806             catch (Exception e) {
807                 throw HibernateUtil.processException(e);
808             }
809             finally {
810                 closeSession(session);
811             }
812         }
813         else {
814             return (List)result;
815         }
816     }
817 
818     public List findByC_C_C(long companyId, long classNameId, long classPK,
819         int begin, int end) throws SystemException {
820         return findByC_C_C(companyId, classNameId, classPK, begin, end, null);
821     }
822 
823     public List findByC_C_C(long companyId, long classNameId, long classPK,
824         int begin, int end, OrderByComparator obc) throws SystemException {
825         String finderClassName = Address.class.getName();
826         String finderMethodName = "findByC_C_C";
827         String[] finderParams = new String[] {
828                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
829                 "java.lang.Integer", "java.lang.Integer",
830                 "com.liferay.portal.kernel.util.OrderByComparator"
831             };
832         Object[] finderArgs = new Object[] {
833                 new Long(companyId), new Long(classNameId), new Long(classPK),
834                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
835             };
836         Object result = FinderCache.getResult(finderClassName,
837                 finderMethodName, finderParams, finderArgs, getSessionFactory());
838 
839         if (result == null) {
840             Session session = null;
841 
842             try {
843                 session = openSession();
844 
845                 StringMaker query = new StringMaker();
846                 query.append("FROM com.liferay.portal.model.Address WHERE ");
847                 query.append("companyId = ?");
848                 query.append(" AND ");
849                 query.append("classNameId = ?");
850                 query.append(" AND ");
851                 query.append("classPK = ?");
852                 query.append(" ");
853 
854                 if (obc != null) {
855                     query.append("ORDER BY ");
856                     query.append(obc.getOrderBy());
857                 }
858                 else {
859                     query.append("ORDER BY ");
860                     query.append("createDate ASC");
861                 }
862 
863                 Query q = session.createQuery(query.toString());
864                 int queryPos = 0;
865                 q.setLong(queryPos++, companyId);
866                 q.setLong(queryPos++, classNameId);
867                 q.setLong(queryPos++, classPK);
868 
869                 List list = QueryUtil.list(q, getDialect(), begin, end);
870                 FinderCache.putResult(finderClassName, finderMethodName,
871                     finderParams, finderArgs, list);
872 
873                 return list;
874             }
875             catch (Exception e) {
876                 throw HibernateUtil.processException(e);
877             }
878             finally {
879                 closeSession(session);
880             }
881         }
882         else {
883             return (List)result;
884         }
885     }
886 
887     public Address findByC_C_C_First(long companyId, long classNameId,
888         long classPK, OrderByComparator obc)
889         throws NoSuchAddressException, SystemException {
890         List list = findByC_C_C(companyId, classNameId, classPK, 0, 1, obc);
891 
892         if (list.size() == 0) {
893             StringMaker msg = new StringMaker();
894             msg.append("No Address exists with the key ");
895             msg.append(StringPool.OPEN_CURLY_BRACE);
896             msg.append("companyId=");
897             msg.append(companyId);
898             msg.append(", ");
899             msg.append("classNameId=");
900             msg.append(classNameId);
901             msg.append(", ");
902             msg.append("classPK=");
903             msg.append(classPK);
904             msg.append(StringPool.CLOSE_CURLY_BRACE);
905             throw new NoSuchAddressException(msg.toString());
906         }
907         else {
908             return (Address)list.get(0);
909         }
910     }
911 
912     public Address findByC_C_C_Last(long companyId, long classNameId,
913         long classPK, OrderByComparator obc)
914         throws NoSuchAddressException, SystemException {
915         int count = countByC_C_C(companyId, classNameId, classPK);
916         List list = findByC_C_C(companyId, classNameId, classPK, count - 1,
917                 count, obc);
918 
919         if (list.size() == 0) {
920             StringMaker msg = new StringMaker();
921             msg.append("No Address exists with the key ");
922             msg.append(StringPool.OPEN_CURLY_BRACE);
923             msg.append("companyId=");
924             msg.append(companyId);
925             msg.append(", ");
926             msg.append("classNameId=");
927             msg.append(classNameId);
928             msg.append(", ");
929             msg.append("classPK=");
930             msg.append(classPK);
931             msg.append(StringPool.CLOSE_CURLY_BRACE);
932             throw new NoSuchAddressException(msg.toString());
933         }
934         else {
935             return (Address)list.get(0);
936         }
937     }
938 
939     public Address[] findByC_C_C_PrevAndNext(long addressId, long companyId,
940         long classNameId, long classPK, OrderByComparator obc)
941         throws NoSuchAddressException, SystemException {
942         Address address = findByPrimaryKey(addressId);
943         int count = countByC_C_C(companyId, classNameId, classPK);
944         Session session = null;
945 
946         try {
947             session = openSession();
948 
949             StringMaker query = new StringMaker();
950             query.append("FROM com.liferay.portal.model.Address WHERE ");
951             query.append("companyId = ?");
952             query.append(" AND ");
953             query.append("classNameId = ?");
954             query.append(" AND ");
955             query.append("classPK = ?");
956             query.append(" ");
957 
958             if (obc != null) {
959                 query.append("ORDER BY ");
960                 query.append(obc.getOrderBy());
961             }
962             else {
963                 query.append("ORDER BY ");
964                 query.append("createDate ASC");
965             }
966 
967             Query q = session.createQuery(query.toString());
968             int queryPos = 0;
969             q.setLong(queryPos++, companyId);
970             q.setLong(queryPos++, classNameId);
971             q.setLong(queryPos++, classPK);
972 
973             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
974             Address[] array = new AddressImpl[3];
975             array[0] = (Address)objArray[0];
976             array[1] = (Address)objArray[1];
977             array[2] = (Address)objArray[2];
978 
979             return array;
980         }
981         catch (Exception e) {
982             throw HibernateUtil.processException(e);
983         }
984         finally {
985             closeSession(session);
986         }
987     }
988 
989     public List findByC_C_C_M(long companyId, long classNameId, long classPK,
990         boolean mailing) throws SystemException {
991         String finderClassName = Address.class.getName();
992         String finderMethodName = "findByC_C_C_M";
993         String[] finderParams = new String[] {
994                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
995                 Boolean.class.getName()
996             };
997         Object[] finderArgs = new Object[] {
998                 new Long(companyId), new Long(classNameId), new Long(classPK),
999                 Boolean.valueOf(mailing)
1000            };
1001        Object result = FinderCache.getResult(finderClassName,
1002                finderMethodName, finderParams, finderArgs, getSessionFactory());
1003
1004        if (result == null) {
1005            Session session = null;
1006
1007            try {
1008                session = openSession();
1009
1010                StringMaker query = new StringMaker();
1011                query.append("FROM com.liferay.portal.model.Address WHERE ");
1012                query.append("companyId = ?");
1013                query.append(" AND ");
1014                query.append("classNameId = ?");
1015                query.append(" AND ");
1016                query.append("classPK = ?");
1017                query.append(" AND ");
1018                query.append("mailing = ?");
1019                query.append(" ");
1020                query.append("ORDER BY ");
1021                query.append("createDate ASC");
1022
1023                Query q = session.createQuery(query.toString());
1024                int queryPos = 0;
1025                q.setLong(queryPos++, companyId);
1026                q.setLong(queryPos++, classNameId);
1027                q.setLong(queryPos++, classPK);
1028                q.setBoolean(queryPos++, mailing);
1029
1030                List list = q.list();
1031                FinderCache.putResult(finderClassName, finderMethodName,
1032                    finderParams, finderArgs, list);
1033
1034                return list;
1035            }
1036            catch (Exception e) {
1037                throw HibernateUtil.processException(e);
1038            }
1039            finally {
1040                closeSession(session);
1041            }
1042        }
1043        else {
1044            return (List)result;
1045        }
1046    }
1047
1048    public List findByC_C_C_M(long companyId, long classNameId, long classPK,
1049        boolean mailing, int begin, int end) throws SystemException {
1050        return findByC_C_C_M(companyId, classNameId, classPK, mailing, begin,
1051            end, null);
1052    }
1053
1054    public List findByC_C_C_M(long companyId, long classNameId, long classPK,
1055        boolean mailing, int begin, int end, OrderByComparator obc)
1056        throws SystemException {
1057        String finderClassName = Address.class.getName();
1058        String finderMethodName = "findByC_C_C_M";
1059        String[] finderParams = new String[] {
1060                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1061                Boolean.class.getName(), "java.lang.Integer",
1062                "java.lang.Integer",
1063                "com.liferay.portal.kernel.util.OrderByComparator"
1064            };
1065        Object[] finderArgs = new Object[] {
1066                new Long(companyId), new Long(classNameId), new Long(classPK),
1067                Boolean.valueOf(mailing), String.valueOf(begin),
1068                String.valueOf(end), String.valueOf(obc)
1069            };
1070        Object result = FinderCache.getResult(finderClassName,
1071                finderMethodName, finderParams, finderArgs, getSessionFactory());
1072
1073        if (result == null) {
1074            Session session = null;
1075
1076            try {
1077                session = openSession();
1078
1079                StringMaker query = new StringMaker();
1080                query.append("FROM com.liferay.portal.model.Address WHERE ");
1081                query.append("companyId = ?");
1082                query.append(" AND ");
1083                query.append("classNameId = ?");
1084                query.append(" AND ");
1085                query.append("classPK = ?");
1086                query.append(" AND ");
1087                query.append("mailing = ?");
1088                query.append(" ");
1089
1090                if (obc != null) {
1091                    query.append("ORDER BY ");
1092                    query.append(obc.getOrderBy());
1093                }
1094                else {
1095                    query.append("ORDER BY ");
1096                    query.append("createDate ASC");
1097                }
1098
1099                Query q = session.createQuery(query.toString());
1100                int queryPos = 0;
1101                q.setLong(queryPos++, companyId);
1102                q.setLong(queryPos++, classNameId);
1103                q.setLong(queryPos++, classPK);
1104                q.setBoolean(queryPos++, mailing);
1105
1106                List list = QueryUtil.list(q, getDialect(), begin, end);
1107                FinderCache.putResult(finderClassName, finderMethodName,
1108                    finderParams, finderArgs, list);
1109
1110                return list;
1111            }
1112            catch (Exception e) {
1113                throw HibernateUtil.processException(e);
1114            }
1115            finally {
1116                closeSession(session);
1117            }
1118        }
1119        else {
1120            return (List)result;
1121        }
1122    }
1123
1124    public Address findByC_C_C_M_First(long companyId, long classNameId,
1125        long classPK, boolean mailing, OrderByComparator obc)
1126        throws NoSuchAddressException, SystemException {
1127        List list = findByC_C_C_M(companyId, classNameId, classPK, mailing, 0,
1128                1, obc);
1129
1130        if (list.size() == 0) {
1131            StringMaker msg = new StringMaker();
1132            msg.append("No Address exists with the key ");
1133            msg.append(StringPool.OPEN_CURLY_BRACE);
1134            msg.append("companyId=");
1135            msg.append(companyId);
1136            msg.append(", ");
1137            msg.append("classNameId=");
1138            msg.append(classNameId);
1139            msg.append(", ");
1140            msg.append("classPK=");
1141            msg.append(classPK);
1142            msg.append(", ");
1143            msg.append("mailing=");
1144            msg.append(mailing);
1145            msg.append(StringPool.CLOSE_CURLY_BRACE);
1146            throw new NoSuchAddressException(msg.toString());
1147        }
1148        else {
1149            return (Address)list.get(0);
1150        }
1151    }
1152
1153    public Address findByC_C_C_M_Last(long companyId, long classNameId,
1154        long classPK, boolean mailing, OrderByComparator obc)
1155        throws NoSuchAddressException, SystemException {
1156        int count = countByC_C_C_M(companyId, classNameId, classPK, mailing);
1157        List list = findByC_C_C_M(companyId, classNameId, classPK, mailing,
1158                count - 1, count, obc);
1159
1160        if (list.size() == 0) {
1161            StringMaker msg = new StringMaker();
1162            msg.append("No Address exists with the key ");
1163            msg.append(StringPool.OPEN_CURLY_BRACE);
1164            msg.append("companyId=");
1165            msg.append(companyId);
1166            msg.append(", ");
1167            msg.append("classNameId=");
1168            msg.append(classNameId);
1169            msg.append(", ");
1170            msg.append("classPK=");
1171            msg.append(classPK);
1172            msg.append(", ");
1173            msg.append("mailing=");
1174            msg.append(mailing);
1175            msg.append(StringPool.CLOSE_CURLY_BRACE);
1176            throw new NoSuchAddressException(msg.toString());
1177        }
1178        else {
1179            return (Address)list.get(0);
1180        }
1181    }
1182
1183    public Address[] findByC_C_C_M_PrevAndNext(long addressId, long companyId,
1184        long classNameId, long classPK, boolean mailing, OrderByComparator obc)
1185        throws NoSuchAddressException, SystemException {
1186        Address address = findByPrimaryKey(addressId);
1187        int count = countByC_C_C_M(companyId, classNameId, classPK, mailing);
1188        Session session = null;
1189
1190        try {
1191            session = openSession();
1192
1193            StringMaker query = new StringMaker();
1194            query.append("FROM com.liferay.portal.model.Address WHERE ");
1195            query.append("companyId = ?");
1196            query.append(" AND ");
1197            query.append("classNameId = ?");
1198            query.append(" AND ");
1199            query.append("classPK = ?");
1200            query.append(" AND ");
1201            query.append("mailing = ?");
1202            query.append(" ");
1203
1204            if (obc != null) {
1205                query.append("ORDER BY ");
1206                query.append(obc.getOrderBy());
1207            }
1208            else {
1209                query.append("ORDER BY ");
1210                query.append("createDate ASC");
1211            }
1212
1213            Query q = session.createQuery(query.toString());
1214            int queryPos = 0;
1215            q.setLong(queryPos++, companyId);
1216            q.setLong(queryPos++, classNameId);
1217            q.setLong(queryPos++, classPK);
1218            q.setBoolean(queryPos++, mailing);
1219
1220            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
1221            Address[] array = new AddressImpl[3];
1222            array[0] = (Address)objArray[0];
1223            array[1] = (Address)objArray[1];
1224            array[2] = (Address)objArray[2];
1225
1226            return array;
1227        }
1228        catch (Exception e) {
1229            throw HibernateUtil.processException(e);
1230        }
1231        finally {
1232            closeSession(session);
1233        }
1234    }
1235
1236    public List findByC_C_C_P(long companyId, long classNameId, long classPK,
1237        boolean primary) throws SystemException {
1238        String finderClassName = Address.class.getName();
1239        String finderMethodName = "findByC_C_C_P";
1240        String[] finderParams = new String[] {
1241                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1242                Boolean.class.getName()
1243            };
1244        Object[] finderArgs = new Object[] {
1245                new Long(companyId), new Long(classNameId), new Long(classPK),
1246                Boolean.valueOf(primary)
1247            };
1248        Object result = FinderCache.getResult(finderClassName,
1249                finderMethodName, finderParams, finderArgs, getSessionFactory());
1250
1251        if (result == null) {
1252            Session session = null;
1253
1254            try {
1255                session = openSession();
1256
1257                StringMaker query = new StringMaker();
1258                query.append("FROM com.liferay.portal.model.Address WHERE ");
1259                query.append("companyId = ?");
1260                query.append(" AND ");
1261                query.append("classNameId = ?");
1262                query.append(" AND ");
1263                query.append("classPK = ?");
1264                query.append(" AND ");
1265                query.append("primary_ = ?");
1266                query.append(" ");
1267                query.append("ORDER BY ");
1268                query.append("createDate ASC");
1269
1270                Query q = session.createQuery(query.toString());
1271                int queryPos = 0;
1272                q.setLong(queryPos++, companyId);
1273                q.setLong(queryPos++, classNameId);
1274                q.setLong(queryPos++, classPK);
1275                q.setBoolean(queryPos++, primary);
1276
1277                List list = q.list();
1278                FinderCache.putResult(finderClassName, finderMethodName,
1279                    finderParams, finderArgs, list);
1280
1281                return list;
1282            }
1283            catch (Exception e) {
1284                throw HibernateUtil.processException(e);
1285            }
1286            finally {
1287                closeSession(session);
1288            }
1289        }
1290        else {
1291            return (List)result;
1292        }
1293    }
1294
1295    public List findByC_C_C_P(long companyId, long classNameId, long classPK,
1296        boolean primary, int begin, int end) throws SystemException {
1297        return findByC_C_C_P(companyId, classNameId, classPK, primary, begin,
1298            end, null);
1299    }
1300
1301    public List findByC_C_C_P(long companyId, long classNameId, long classPK,
1302        boolean primary, int begin, int end, OrderByComparator obc)
1303        throws SystemException {
1304        String finderClassName = Address.class.getName();
1305        String finderMethodName = "findByC_C_C_P";
1306        String[] finderParams = new String[] {
1307                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1308                Boolean.class.getName(), "java.lang.Integer",
1309                "java.lang.Integer",
1310                "com.liferay.portal.kernel.util.OrderByComparator"
1311            };
1312        Object[] finderArgs = new Object[] {
1313                new Long(companyId), new Long(classNameId), new Long(classPK),
1314                Boolean.valueOf(primary), String.valueOf(begin),
1315                String.valueOf(end), String.valueOf(obc)
1316            };
1317        Object result = FinderCache.getResult(finderClassName,
1318                finderMethodName, finderParams, finderArgs, getSessionFactory());
1319
1320        if (result == null) {
1321            Session session = null;
1322
1323            try {
1324                session = openSession();
1325
1326                StringMaker query = new StringMaker();
1327                query.append("FROM com.liferay.portal.model.Address WHERE ");
1328                query.append("companyId = ?");
1329                query.append(" AND ");
1330                query.append("classNameId = ?");
1331                query.append(" AND ");
1332                query.append("classPK = ?");
1333                query.append(" AND ");
1334                query.append("primary_ = ?");
1335                query.append(" ");
1336
1337                if (obc != null) {
1338                    query.append("ORDER BY ");
1339                    query.append(obc.getOrderBy());
1340                }
1341                else {
1342                    query.append("ORDER BY ");
1343                    query.append("createDate ASC");
1344                }
1345
1346                Query q = session.createQuery(query.toString());
1347                int queryPos = 0;
1348                q.setLong(queryPos++, companyId);
1349                q.setLong(queryPos++, classNameId);
1350                q.setLong(queryPos++, classPK);
1351                q.setBoolean(queryPos++, primary);
1352
1353                List list = QueryUtil.list(q, getDialect(), begin, end);
1354                FinderCache.putResult(finderClassName, finderMethodName,
1355                    finderParams, finderArgs, list);
1356
1357                return list;
1358            }
1359            catch (Exception e) {
1360                throw HibernateUtil.processException(e);
1361            }
1362            finally {
1363                closeSession(session);
1364            }
1365        }
1366        else {
1367            return (List)result;
1368        }
1369    }
1370
1371    public Address findByC_C_C_P_First(long companyId, long classNameId,
1372        long classPK, boolean primary, OrderByComparator obc)
1373        throws NoSuchAddressException, SystemException {
1374        List list = findByC_C_C_P(companyId, classNameId, classPK, primary, 0,
1375                1, obc);
1376
1377        if (list.size() == 0) {
1378            StringMaker msg = new StringMaker();
1379            msg.append("No Address exists with the key ");
1380            msg.append(StringPool.OPEN_CURLY_BRACE);
1381            msg.append("companyId=");
1382            msg.append(companyId);
1383            msg.append(", ");
1384            msg.append("classNameId=");
1385            msg.append(classNameId);
1386            msg.append(", ");
1387            msg.append("classPK=");
1388            msg.append(classPK);
1389            msg.append(", ");
1390            msg.append("primary=");
1391            msg.append(primary);
1392            msg.append(StringPool.CLOSE_CURLY_BRACE);
1393            throw new NoSuchAddressException(msg.toString());
1394        }
1395        else {
1396            return (Address)list.get(0);
1397        }
1398    }
1399
1400    public Address findByC_C_C_P_Last(long companyId, long classNameId,
1401        long classPK, boolean primary, OrderByComparator obc)
1402        throws NoSuchAddressException, SystemException {
1403        int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
1404        List list = findByC_C_C_P(companyId, classNameId, classPK, primary,
1405                count - 1, count, obc);
1406
1407        if (list.size() == 0) {
1408            StringMaker msg = new StringMaker();
1409            msg.append("No Address exists with the key ");
1410            msg.append(StringPool.OPEN_CURLY_BRACE);
1411            msg.append("companyId=");
1412            msg.append(companyId);
1413            msg.append(", ");
1414            msg.append("classNameId=");
1415            msg.append(classNameId);
1416            msg.append(", ");
1417            msg.append("classPK=");
1418            msg.append(classPK);
1419            msg.append(", ");
1420            msg.append("primary=");
1421            msg.append(primary);
1422            msg.append(StringPool.CLOSE_CURLY_BRACE);
1423            throw new NoSuchAddressException(msg.toString());
1424        }
1425        else {
1426            return (Address)list.get(0);
1427        }
1428    }
1429
1430    public Address[] findByC_C_C_P_PrevAndNext(long addressId, long companyId,
1431        long classNameId, long classPK, boolean primary, OrderByComparator obc)
1432        throws NoSuchAddressException, SystemException {
1433        Address address = findByPrimaryKey(addressId);
1434        int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
1435        Session session = null;
1436
1437        try {
1438            session = openSession();
1439
1440            StringMaker query = new StringMaker();
1441            query.append("FROM com.liferay.portal.model.Address WHERE ");
1442            query.append("companyId = ?");
1443            query.append(" AND ");
1444            query.append("classNameId = ?");
1445            query.append(" AND ");
1446            query.append("classPK = ?");
1447            query.append(" AND ");
1448            query.append("primary_ = ?");
1449            query.append(" ");
1450
1451            if (obc != null) {
1452                query.append("ORDER BY ");
1453                query.append(obc.getOrderBy());
1454            }
1455            else {
1456                query.append("ORDER BY ");
1457                query.append("createDate ASC");
1458            }
1459
1460            Query q = session.createQuery(query.toString());
1461            int queryPos = 0;
1462            q.setLong(queryPos++, companyId);
1463            q.setLong(queryPos++, classNameId);
1464            q.setLong(queryPos++, classPK);
1465            q.setBoolean(queryPos++, primary);
1466
1467            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, address);
1468            Address[] array = new AddressImpl[3];
1469            array[0] = (Address)objArray[0];
1470            array[1] = (Address)objArray[1];
1471            array[2] = (Address)objArray[2];
1472
1473            return array;
1474        }
1475        catch (Exception e) {
1476            throw HibernateUtil.processException(e);
1477        }
1478        finally {
1479            closeSession(session);
1480        }
1481    }
1482
1483    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1484        throws SystemException {
1485        Session session = null;
1486
1487        try {
1488            session = openSession();
1489
1490            DynamicQuery query = queryInitializer.initialize(session);
1491
1492            return query.list();
1493        }
1494        catch (Exception e) {
1495            throw HibernateUtil.processException(e);
1496        }
1497        finally {
1498            closeSession(session);
1499        }
1500    }
1501
1502    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1503        int begin, int end) throws SystemException {
1504        Session session = null;
1505
1506        try {
1507            session = openSession();
1508
1509            DynamicQuery query = queryInitializer.initialize(session);
1510            query.setLimit(begin, end);
1511
1512            return query.list();
1513        }
1514        catch (Exception e) {
1515            throw HibernateUtil.processException(e);
1516        }
1517        finally {
1518            closeSession(session);
1519        }
1520    }
1521
1522    public List findAll() throws SystemException {
1523        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1524    }
1525
1526    public List findAll(int begin, int end) throws SystemException {
1527        return findAll(begin, end, null);
1528    }
1529
1530    public List findAll(int begin, int end, OrderByComparator obc)
1531        throws SystemException {
1532        String finderClassName = Address.class.getName();
1533        String finderMethodName = "findAll";
1534        String[] finderParams = new String[] {
1535                "java.lang.Integer", "java.lang.Integer",
1536                "com.liferay.portal.kernel.util.OrderByComparator"
1537            };
1538        Object[] finderArgs = new Object[] {
1539                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1540            };
1541        Object result = FinderCache.getResult(finderClassName,
1542                finderMethodName, finderParams, finderArgs, getSessionFactory());
1543
1544        if (result == null) {
1545            Session session = null;
1546
1547            try {
1548                session = openSession();
1549
1550                StringMaker query = new StringMaker();
1551                query.append("FROM com.liferay.portal.model.Address ");
1552
1553                if (obc != null) {
1554                    query.append("ORDER BY ");
1555                    query.append(obc.getOrderBy());
1556                }
1557                else {
1558                    query.append("ORDER BY ");
1559                    query.append("createDate ASC");
1560                }
1561
1562                Query q = session.createQuery(query.toString());
1563                List list = QueryUtil.list(q, getDialect(), begin, end);
1564
1565                if (obc == null) {
1566                    Collections.sort(list);
1567                }
1568
1569                FinderCache.putResult(finderClassName, finderMethodName,
1570                    finderParams, finderArgs, list);
1571
1572                return list;
1573            }
1574            catch (Exception e) {
1575                throw HibernateUtil.processException(e);
1576            }
1577            finally {
1578                closeSession(session);
1579            }
1580        }
1581        else {
1582            return (List)result;
1583        }
1584    }
1585
1586    public void removeByCompanyId(long companyId) throws SystemException {
1587        Iterator itr = findByCompanyId(companyId).iterator();
1588
1589        while (itr.hasNext()) {
1590            Address address = (Address)itr.next();
1591            remove(address);
1592        }
1593    }
1594
1595    public void removeByUserId(long userId) throws SystemException {
1596        Iterator itr = findByUserId(userId).iterator();
1597
1598        while (itr.hasNext()) {
1599            Address address = (Address)itr.next();
1600            remove(address);
1601        }
1602    }
1603
1604    public void removeByC_C(long companyId, long classNameId)
1605        throws SystemException {
1606        Iterator itr = findByC_C(companyId, classNameId).iterator();
1607
1608        while (itr.hasNext()) {
1609            Address address = (Address)itr.next();
1610            remove(address);
1611        }
1612    }
1613
1614    public void removeByC_C_C(long companyId, long classNameId, long classPK)
1615        throws SystemException {
1616        Iterator itr = findByC_C_C(companyId, classNameId, classPK).iterator();
1617
1618        while (itr.hasNext()) {
1619            Address address = (Address)itr.next();
1620            remove(address);
1621        }
1622    }
1623
1624    public void removeByC_C_C_M(long companyId, long classNameId, long classPK,
1625        boolean mailing) throws SystemException {
1626        Iterator itr = findByC_C_C_M(companyId, classNameId, classPK, mailing)
1627                           .iterator();
1628
1629        while (itr.hasNext()) {
1630            Address address = (Address)itr.next();
1631            remove(address);
1632        }
1633    }
1634
1635    public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
1636        boolean primary) throws SystemException {
1637        Iterator itr = findByC_C_C_P(companyId, classNameId, classPK, primary)
1638                           .iterator();
1639
1640        while (itr.hasNext()) {
1641            Address address = (Address)itr.next();
1642            remove(address);
1643        }
1644    }
1645
1646    public void removeAll() throws SystemException {
1647        Iterator itr = findAll().iterator();
1648
1649        while (itr.hasNext()) {
1650            remove((Address)itr.next());
1651        }
1652    }
1653
1654    public int countByCompanyId(long companyId) throws SystemException {
1655        String finderClassName = Address.class.getName();
1656        String finderMethodName = "countByCompanyId";
1657        String[] finderParams = new String[] { Long.class.getName() };
1658        Object[] finderArgs = new Object[] { new Long(companyId) };
1659        Object result = FinderCache.getResult(finderClassName,
1660                finderMethodName, finderParams, finderArgs, getSessionFactory());
1661
1662        if (result == null) {
1663            Session session = null;
1664
1665            try {
1666                session = openSession();
1667
1668                StringMaker query = new StringMaker();
1669                query.append("SELECT COUNT(*) ");
1670                query.append("FROM com.liferay.portal.model.Address WHERE ");
1671                query.append("companyId = ?");
1672                query.append(" ");
1673
1674                Query q = session.createQuery(query.toString());
1675                int queryPos = 0;
1676                q.setLong(queryPos++, companyId);
1677
1678                Long count = null;
1679                Iterator itr = q.list().iterator();
1680
1681                if (itr.hasNext()) {
1682                    count = (Long)itr.next();
1683                }
1684
1685                if (count == null) {
1686                    count = new Long(0);
1687                }
1688
1689                FinderCache.putResult(finderClassName, finderMethodName,
1690                    finderParams, finderArgs, count);
1691
1692                return count.intValue();
1693            }
1694            catch (Exception e) {
1695                throw HibernateUtil.processException(e);
1696            }
1697            finally {
1698                closeSession(session);
1699            }
1700        }
1701        else {
1702            return ((Long)result).intValue();
1703        }
1704    }
1705
1706    public int countByUserId(long userId) throws SystemException {
1707        String finderClassName = Address.class.getName();
1708        String finderMethodName = "countByUserId";
1709        String[] finderParams = new String[] { Long.class.getName() };
1710        Object[] finderArgs = new Object[] { new Long(userId) };
1711        Object result = FinderCache.getResult(finderClassName,
1712                finderMethodName, finderParams, finderArgs, getSessionFactory());
1713
1714        if (result == null) {
1715            Session session = null;
1716
1717            try {
1718                session = openSession();
1719
1720                StringMaker query = new StringMaker();
1721                query.append("SELECT COUNT(*) ");
1722                query.append("FROM com.liferay.portal.model.Address WHERE ");
1723                query.append("userId = ?");
1724                query.append(" ");
1725
1726                Query q = session.createQuery(query.toString());
1727                int queryPos = 0;
1728                q.setLong(queryPos++, userId);
1729
1730                Long count = null;
1731                Iterator itr = q.list().iterator();
1732
1733                if (itr.hasNext()) {
1734                    count = (Long)itr.next();
1735                }
1736
1737                if (count == null) {
1738                    count = new Long(0);
1739                }
1740
1741                FinderCache.putResult(finderClassName, finderMethodName,
1742                    finderParams, finderArgs, count);
1743
1744                return count.intValue();
1745            }
1746            catch (Exception e) {
1747                throw HibernateUtil.processException(e);
1748            }
1749            finally {
1750                closeSession(session);
1751            }
1752        }
1753        else {
1754            return ((Long)result).intValue();
1755        }
1756    }
1757
1758    public int countByC_C(long companyId, long classNameId)
1759        throws SystemException {
1760        String finderClassName = Address.class.getName();
1761        String finderMethodName = "countByC_C";
1762        String[] finderParams = new String[] {
1763                Long.class.getName(), Long.class.getName()
1764            };
1765        Object[] finderArgs = new Object[] {
1766                new Long(companyId), new Long(classNameId)
1767            };
1768        Object result = FinderCache.getResult(finderClassName,
1769                finderMethodName, finderParams, finderArgs, getSessionFactory());
1770
1771        if (result == null) {
1772            Session session = null;
1773
1774            try {
1775                session = openSession();
1776
1777                StringMaker query = new StringMaker();
1778                query.append("SELECT COUNT(*) ");
1779                query.append("FROM com.liferay.portal.model.Address WHERE ");
1780                query.append("companyId = ?");
1781                query.append(" AND ");
1782                query.append("classNameId = ?");
1783                query.append(" ");
1784
1785                Query q = session.createQuery(query.toString());
1786                int queryPos = 0;
1787                q.setLong(queryPos++, companyId);
1788                q.setLong(queryPos++, classNameId);
1789
1790                Long count = null;
1791                Iterator itr = q.list().iterator();
1792
1793                if (itr.hasNext()) {
1794                    count = (Long)itr.next();
1795                }
1796
1797                if (count == null) {
1798                    count = new Long(0);
1799                }
1800
1801                FinderCache.putResult(finderClassName, finderMethodName,
1802                    finderParams, finderArgs, count);
1803
1804                return count.intValue();
1805            }
1806            catch (Exception e) {
1807                throw HibernateUtil.processException(e);
1808            }
1809            finally {
1810                closeSession(session);
1811            }
1812        }
1813        else {
1814            return ((Long)result).intValue();
1815        }
1816    }
1817
1818    public int countByC_C_C(long companyId, long classNameId, long classPK)
1819        throws SystemException {
1820        String finderClassName = Address.class.getName();
1821        String finderMethodName = "countByC_C_C";
1822        String[] finderParams = new String[] {
1823                Long.class.getName(), Long.class.getName(), Long.class.getName()
1824            };
1825        Object[] finderArgs = new Object[] {
1826                new Long(companyId), new Long(classNameId), new Long(classPK)
1827            };
1828        Object result = FinderCache.getResult(finderClassName,
1829                finderMethodName, finderParams, finderArgs, getSessionFactory());
1830
1831        if (result == null) {
1832            Session session = null;
1833
1834            try {
1835                session = openSession();
1836
1837                StringMaker query = new StringMaker();
1838                query.append("SELECT COUNT(*) ");
1839                query.append("FROM com.liferay.portal.model.Address WHERE ");
1840                query.append("companyId = ?");
1841                query.append(" AND ");
1842                query.append("classNameId = ?");
1843                query.append(" AND ");
1844                query.append("classPK = ?");
1845                query.append(" ");
1846
1847                Query q = session.createQuery(query.toString());
1848                int queryPos = 0;
1849                q.setLong(queryPos++, companyId);
1850                q.setLong(queryPos++, classNameId);
1851                q.setLong(queryPos++, classPK);
1852
1853                Long count = null;
1854                Iterator itr = q.list().iterator();
1855
1856                if (itr.hasNext()) {
1857                    count = (Long)itr.next();
1858                }
1859
1860                if (count == null) {
1861                    count = new Long(0);
1862                }
1863
1864                FinderCache.putResult(finderClassName, finderMethodName,
1865                    finderParams, finderArgs, count);
1866
1867                return count.intValue();
1868            }
1869            catch (Exception e) {
1870                throw HibernateUtil.processException(e);
1871            }
1872            finally {
1873                closeSession(session);
1874            }
1875        }
1876        else {
1877            return ((Long)result).intValue();
1878        }
1879    }
1880
1881    public int countByC_C_C_M(long companyId, long classNameId, long classPK,
1882        boolean mailing) throws SystemException {
1883        String finderClassName = Address.class.getName();
1884        String finderMethodName = "countByC_C_C_M";
1885        String[] finderParams = new String[] {
1886                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1887                Boolean.class.getName()
1888            };
1889        Object[] finderArgs = new Object[] {
1890                new Long(companyId), new Long(classNameId), new Long(classPK),
1891                Boolean.valueOf(mailing)
1892            };
1893        Object result = FinderCache.getResult(finderClassName,
1894                finderMethodName, finderParams, finderArgs, getSessionFactory());
1895
1896        if (result == null) {
1897            Session session = null;
1898
1899            try {
1900                session = openSession();
1901
1902                StringMaker query = new StringMaker();
1903                query.append("SELECT COUNT(*) ");
1904                query.append("FROM com.liferay.portal.model.Address WHERE ");
1905                query.append("companyId = ?");
1906                query.append(" AND ");
1907                query.append("classNameId = ?");
1908                query.append(" AND ");
1909                query.append("classPK = ?");
1910                query.append(" AND ");
1911                query.append("mailing = ?");
1912                query.append(" ");
1913
1914                Query q = session.createQuery(query.toString());
1915                int queryPos = 0;
1916                q.setLong(queryPos++, companyId);
1917                q.setLong(queryPos++, classNameId);
1918                q.setLong(queryPos++, classPK);
1919                q.setBoolean(queryPos++, mailing);
1920
1921                Long count = null;
1922                Iterator itr = q.list().iterator();
1923
1924                if (itr.hasNext()) {
1925                    count = (Long)itr.next();
1926                }
1927
1928                if (count == null) {
1929                    count = new Long(0);
1930                }
1931
1932                FinderCache.putResult(finderClassName, finderMethodName,
1933                    finderParams, finderArgs, count);
1934
1935                return count.intValue();
1936            }
1937            catch (Exception e) {
1938                throw HibernateUtil.processException(e);
1939            }
1940            finally {
1941                closeSession(session);
1942            }
1943        }
1944        else {
1945            return ((Long)result).intValue();
1946        }
1947    }
1948
1949    public int countByC_C_C_P(long companyId, long classNameId, long classPK,
1950        boolean primary) throws SystemException {
1951        String finderClassName = Address.class.getName();
1952        String finderMethodName = "countByC_C_C_P";
1953        String[] finderParams = new String[] {
1954                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1955                Boolean.class.getName()
1956            };
1957        Object[] finderArgs = new Object[] {
1958                new Long(companyId), new Long(classNameId), new Long(classPK),
1959                Boolean.valueOf(primary)
1960            };
1961        Object result = FinderCache.getResult(finderClassName,
1962                finderMethodName, finderParams, finderArgs, getSessionFactory());
1963
1964        if (result == null) {
1965            Session session = null;
1966
1967            try {
1968                session = openSession();
1969
1970                StringMaker query = new StringMaker();
1971                query.append("SELECT COUNT(*) ");
1972                query.append("FROM com.liferay.portal.model.Address WHERE ");
1973                query.append("companyId = ?");
1974                query.append(" AND ");
1975                query.append("classNameId = ?");
1976                query.append(" AND ");
1977                query.append("classPK = ?");
1978                query.append(" AND ");
1979                query.append("primary_ = ?");
1980                query.append(" ");
1981
1982                Query q = session.createQuery(query.toString());
1983                int queryPos = 0;
1984                q.setLong(queryPos++, companyId);
1985                q.setLong(queryPos++, classNameId);
1986                q.setLong(queryPos++, classPK);
1987                q.setBoolean(queryPos++, primary);
1988
1989                Long count = null;
1990                Iterator itr = q.list().iterator();
1991
1992                if (itr.hasNext()) {
1993                    count = (Long)itr.next();
1994                }
1995
1996                if (count == null) {
1997                    count = new Long(0);
1998                }
1999
2000                FinderCache.putResult(finderClassName, finderMethodName,
2001                    finderParams, finderArgs, count);
2002
2003                return count.intValue();
2004            }
2005            catch (Exception e) {
2006                throw HibernateUtil.processException(e);
2007            }
2008            finally {
2009                closeSession(session);
2010            }
2011        }
2012        else {
2013            return ((Long)result).intValue();
2014        }
2015    }
2016
2017    public int countAll() throws SystemException {
2018        String finderClassName = Address.class.getName();
2019        String finderMethodName = "countAll";
2020        String[] finderParams = new String[] {  };
2021        Object[] finderArgs = new Object[] {  };
2022        Object result = FinderCache.getResult(finderClassName,
2023                finderMethodName, finderParams, finderArgs, getSessionFactory());
2024
2025        if (result == null) {
2026            Session session = null;
2027
2028            try {
2029                session = openSession();
2030
2031                StringMaker query = new StringMaker();
2032                query.append("SELECT COUNT(*) ");
2033                query.append("FROM com.liferay.portal.model.Address");
2034
2035                Query q = session.createQuery(query.toString());
2036                Long count = null;
2037                Iterator itr = q.list().iterator();
2038
2039                if (itr.hasNext()) {
2040                    count = (Long)itr.next();
2041                }
2042
2043                if (count == null) {
2044                    count = new Long(0);
2045                }
2046
2047                FinderCache.putResult(finderClassName, finderMethodName,
2048                    finderParams, finderArgs, count);
2049
2050                return count.intValue();
2051            }
2052            catch (Exception e) {
2053                throw HibernateUtil.processException(e);
2054            }
2055            finally {
2056                closeSession(session);
2057            }
2058        }
2059        else {
2060            return ((Long)result).intValue();
2061        }
2062    }
2063
2064    protected void initDao() {
2065    }
2066
2067    private static Log _log = LogFactory.getLog(AddressPersistenceImpl.class);
2068}