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