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