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