1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.NoSuchCompanyException;
18  import com.liferay.portal.NoSuchModelException;
19  import com.liferay.portal.SystemException;
20  import com.liferay.portal.kernel.annotation.BeanReference;
21  import com.liferay.portal.kernel.cache.CacheRegistry;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.InstanceFactory;
33  import com.liferay.portal.kernel.util.OrderByComparator;
34  import com.liferay.portal.kernel.util.StringBundler;
35  import com.liferay.portal.kernel.util.StringPool;
36  import com.liferay.portal.kernel.util.StringUtil;
37  import com.liferay.portal.kernel.util.Validator;
38  import com.liferay.portal.model.Company;
39  import com.liferay.portal.model.ModelListener;
40  import com.liferay.portal.model.impl.CompanyImpl;
41  import com.liferay.portal.model.impl.CompanyModelImpl;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import java.io.Serializable;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.List;
49  
50  /**
51   * <a href="CompanyPersistenceImpl.java.html"><b><i>View Source</i></b></a>
52   *
53   * <p>
54   * ServiceBuilder generated this class. Modifications in this class will be
55   * overwritten the next time is generated.
56   * </p>
57   *
58   * @author    Brian Wing Shun Chan
59   * @see       CompanyPersistence
60   * @see       CompanyUtil
61   * @generated
62   */
63  public class CompanyPersistenceImpl extends BasePersistenceImpl<Company>
64      implements CompanyPersistence {
65      public static final String FINDER_CLASS_NAME_ENTITY = CompanyImpl.class.getName();
66      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67          ".List";
68      public static final FinderPath FINDER_PATH_FETCH_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
69              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
70              "fetchByWebId", new String[] { String.class.getName() });
71      public static final FinderPath FINDER_PATH_COUNT_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
72              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73              "countByWebId", new String[] { String.class.getName() });
74      public static final FinderPath FINDER_PATH_FETCH_BY_VIRTUALHOST = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
75              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
76              "fetchByVirtualHost", new String[] { String.class.getName() });
77      public static final FinderPath FINDER_PATH_COUNT_BY_VIRTUALHOST = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
78              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
79              "countByVirtualHost", new String[] { String.class.getName() });
80      public static final FinderPath FINDER_PATH_FETCH_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
81              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
82              "fetchByMx", new String[] { String.class.getName() });
83      public static final FinderPath FINDER_PATH_COUNT_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
84              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
85              "countByMx", new String[] { String.class.getName() });
86      public static final FinderPath FINDER_PATH_FETCH_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
87              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
88              "fetchByLogoId", new String[] { Long.class.getName() });
89      public static final FinderPath FINDER_PATH_COUNT_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
90              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
91              "countByLogoId", new String[] { Long.class.getName() });
92      public static final FinderPath FINDER_PATH_FIND_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
93              CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
94              "findBySystem",
95              new String[] {
96                  Boolean.class.getName(),
97                  
98              "java.lang.Integer", "java.lang.Integer",
99                  "com.liferay.portal.kernel.util.OrderByComparator"
100             });
101     public static final FinderPath FINDER_PATH_COUNT_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
102             CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103             "countBySystem", new String[] { Boolean.class.getName() });
104     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
105             CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106             "findAll", new String[0]);
107     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
108             CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109             "countAll", new String[0]);
110 
111     public void cacheResult(Company company) {
112         EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
113             CompanyImpl.class, company.getPrimaryKey(), company);
114 
115         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
116             new Object[] { company.getWebId() }, company);
117 
118         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
119             new Object[] { company.getVirtualHost() }, company);
120 
121         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
122             new Object[] { company.getMx() }, company);
123 
124         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
125             new Object[] { new Long(company.getLogoId()) }, company);
126     }
127 
128     public void cacheResult(List<Company> companies) {
129         for (Company company : companies) {
130             if (EntityCacheUtil.getResult(
131                         CompanyModelImpl.ENTITY_CACHE_ENABLED,
132                         CompanyImpl.class, company.getPrimaryKey(), this) == null) {
133                 cacheResult(company);
134             }
135         }
136     }
137 
138     public void clearCache() {
139         CacheRegistry.clear(CompanyImpl.class.getName());
140         EntityCacheUtil.clearCache(CompanyImpl.class.getName());
141         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
142         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
143     }
144 
145     public void clearCache(Company company) {
146         EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
147             CompanyImpl.class, company.getPrimaryKey());
148 
149         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
150             new Object[] { company.getWebId() });
151 
152         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
153             new Object[] { company.getVirtualHost() });
154 
155         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX,
156             new Object[] { company.getMx() });
157 
158         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
159             new Object[] { new Long(company.getLogoId()) });
160     }
161 
162     public Company create(long companyId) {
163         Company company = new CompanyImpl();
164 
165         company.setNew(true);
166         company.setPrimaryKey(companyId);
167 
168         return company;
169     }
170 
171     public Company remove(Serializable primaryKey)
172         throws NoSuchModelException, SystemException {
173         return remove(((Long)primaryKey).longValue());
174     }
175 
176     public Company remove(long companyId)
177         throws NoSuchCompanyException, SystemException {
178         Session session = null;
179 
180         try {
181             session = openSession();
182 
183             Company company = (Company)session.get(CompanyImpl.class,
184                     new Long(companyId));
185 
186             if (company == null) {
187                 if (_log.isWarnEnabled()) {
188                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + companyId);
189                 }
190 
191                 throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
192                     companyId);
193             }
194 
195             return remove(company);
196         }
197         catch (NoSuchCompanyException nsee) {
198             throw nsee;
199         }
200         catch (Exception e) {
201             throw processException(e);
202         }
203         finally {
204             closeSession(session);
205         }
206     }
207 
208     protected Company removeImpl(Company company) throws SystemException {
209         company = toUnwrappedModel(company);
210 
211         Session session = null;
212 
213         try {
214             session = openSession();
215 
216             BatchSessionUtil.delete(session, company);
217         }
218         catch (Exception e) {
219             throw processException(e);
220         }
221         finally {
222             closeSession(session);
223         }
224 
225         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
226 
227         CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
228 
229         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
230             new Object[] { companyModelImpl.getOriginalWebId() });
231 
232         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
233             new Object[] { companyModelImpl.getOriginalVirtualHost() });
234 
235         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX,
236             new Object[] { companyModelImpl.getOriginalMx() });
237 
238         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
239             new Object[] { new Long(companyModelImpl.getOriginalLogoId()) });
240 
241         EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
242             CompanyImpl.class, company.getPrimaryKey());
243 
244         return company;
245     }
246 
247     /**
248      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
249      */
250     public Company update(Company company) throws SystemException {
251         if (_log.isWarnEnabled()) {
252             _log.warn(
253                 "Using the deprecated update(Company company) method. Use update(Company company, boolean merge) instead.");
254         }
255 
256         return update(company, false);
257     }
258 
259     public Company updateImpl(com.liferay.portal.model.Company company,
260         boolean merge) throws SystemException {
261         company = toUnwrappedModel(company);
262 
263         boolean isNew = company.isNew();
264 
265         CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
266 
267         Session session = null;
268 
269         try {
270             session = openSession();
271 
272             BatchSessionUtil.update(session, company, merge);
273 
274             company.setNew(false);
275         }
276         catch (Exception e) {
277             throw processException(e);
278         }
279         finally {
280             closeSession(session);
281         }
282 
283         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
284 
285         EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
286             CompanyImpl.class, company.getPrimaryKey(), company);
287 
288         if (!isNew &&
289                 (!Validator.equals(company.getWebId(),
290                     companyModelImpl.getOriginalWebId()))) {
291             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
292                 new Object[] { companyModelImpl.getOriginalWebId() });
293         }
294 
295         if (isNew ||
296                 (!Validator.equals(company.getWebId(),
297                     companyModelImpl.getOriginalWebId()))) {
298             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
299                 new Object[] { company.getWebId() }, company);
300         }
301 
302         if (!isNew &&
303                 (!Validator.equals(company.getVirtualHost(),
304                     companyModelImpl.getOriginalVirtualHost()))) {
305             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
306                 new Object[] { companyModelImpl.getOriginalVirtualHost() });
307         }
308 
309         if (isNew ||
310                 (!Validator.equals(company.getVirtualHost(),
311                     companyModelImpl.getOriginalVirtualHost()))) {
312             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
313                 new Object[] { company.getVirtualHost() }, company);
314         }
315 
316         if (!isNew &&
317                 (!Validator.equals(company.getMx(),
318                     companyModelImpl.getOriginalMx()))) {
319             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX,
320                 new Object[] { companyModelImpl.getOriginalMx() });
321         }
322 
323         if (isNew ||
324                 (!Validator.equals(company.getMx(),
325                     companyModelImpl.getOriginalMx()))) {
326             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
327                 new Object[] { company.getMx() }, company);
328         }
329 
330         if (!isNew &&
331                 (company.getLogoId() != companyModelImpl.getOriginalLogoId())) {
332             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
333                 new Object[] { new Long(companyModelImpl.getOriginalLogoId()) });
334         }
335 
336         if (isNew ||
337                 (company.getLogoId() != companyModelImpl.getOriginalLogoId())) {
338             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
339                 new Object[] { new Long(company.getLogoId()) }, company);
340         }
341 
342         return company;
343     }
344 
345     protected Company toUnwrappedModel(Company company) {
346         if (company instanceof CompanyImpl) {
347             return company;
348         }
349 
350         CompanyImpl companyImpl = new CompanyImpl();
351 
352         companyImpl.setNew(company.isNew());
353         companyImpl.setPrimaryKey(company.getPrimaryKey());
354 
355         companyImpl.setCompanyId(company.getCompanyId());
356         companyImpl.setAccountId(company.getAccountId());
357         companyImpl.setWebId(company.getWebId());
358         companyImpl.setKey(company.getKey());
359         companyImpl.setVirtualHost(company.getVirtualHost());
360         companyImpl.setMx(company.getMx());
361         companyImpl.setHomeURL(company.getHomeURL());
362         companyImpl.setLogoId(company.getLogoId());
363         companyImpl.setSystem(company.isSystem());
364 
365         return companyImpl;
366     }
367 
368     public Company findByPrimaryKey(Serializable primaryKey)
369         throws NoSuchModelException, SystemException {
370         return findByPrimaryKey(((Long)primaryKey).longValue());
371     }
372 
373     public Company findByPrimaryKey(long companyId)
374         throws NoSuchCompanyException, SystemException {
375         Company company = fetchByPrimaryKey(companyId);
376 
377         if (company == null) {
378             if (_log.isWarnEnabled()) {
379                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + companyId);
380             }
381 
382             throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
383                 companyId);
384         }
385 
386         return company;
387     }
388 
389     public Company fetchByPrimaryKey(Serializable primaryKey)
390         throws SystemException {
391         return fetchByPrimaryKey(((Long)primaryKey).longValue());
392     }
393 
394     public Company fetchByPrimaryKey(long companyId) throws SystemException {
395         Company company = (Company)EntityCacheUtil.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
396                 CompanyImpl.class, companyId, this);
397 
398         if (company == null) {
399             Session session = null;
400 
401             try {
402                 session = openSession();
403 
404                 company = (Company)session.get(CompanyImpl.class,
405                         new Long(companyId));
406             }
407             catch (Exception e) {
408                 throw processException(e);
409             }
410             finally {
411                 if (company != null) {
412                     cacheResult(company);
413                 }
414 
415                 closeSession(session);
416             }
417         }
418 
419         return company;
420     }
421 
422     public Company findByWebId(String webId)
423         throws NoSuchCompanyException, SystemException {
424         Company company = fetchByWebId(webId);
425 
426         if (company == null) {
427             StringBundler msg = new StringBundler(4);
428 
429             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
430 
431             msg.append("webId=");
432             msg.append(webId);
433 
434             msg.append(StringPool.CLOSE_CURLY_BRACE);
435 
436             if (_log.isWarnEnabled()) {
437                 _log.warn(msg.toString());
438             }
439 
440             throw new NoSuchCompanyException(msg.toString());
441         }
442 
443         return company;
444     }
445 
446     public Company fetchByWebId(String webId) throws SystemException {
447         return fetchByWebId(webId, true);
448     }
449 
450     public Company fetchByWebId(String webId, boolean retrieveFromCache)
451         throws SystemException {
452         Object[] finderArgs = new Object[] { webId };
453 
454         Object result = null;
455 
456         if (retrieveFromCache) {
457             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_WEBID,
458                     finderArgs, this);
459         }
460 
461         if (result == null) {
462             StringBundler query = new StringBundler(2);
463 
464             query.append(_SQL_SELECT_COMPANY_WHERE);
465 
466             if (webId == null) {
467                 query.append(_FINDER_COLUMN_WEBID_WEBID_1);
468             }
469             else {
470                 if (webId.equals(StringPool.BLANK)) {
471                     query.append(_FINDER_COLUMN_WEBID_WEBID_3);
472                 }
473                 else {
474                     query.append(_FINDER_COLUMN_WEBID_WEBID_2);
475                 }
476             }
477 
478             String sql = query.toString();
479 
480             Session session = null;
481 
482             try {
483                 session = openSession();
484 
485                 Query q = session.createQuery(sql);
486 
487                 QueryPos qPos = QueryPos.getInstance(q);
488 
489                 if (webId != null) {
490                     qPos.add(webId);
491                 }
492 
493                 List<Company> list = q.list();
494 
495                 result = list;
496 
497                 Company company = null;
498 
499                 if (list.isEmpty()) {
500                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
501                         finderArgs, list);
502                 }
503                 else {
504                     company = list.get(0);
505 
506                     cacheResult(company);
507 
508                     if ((company.getWebId() == null) ||
509                             !company.getWebId().equals(webId)) {
510                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
511                             finderArgs, company);
512                     }
513                 }
514 
515                 return company;
516             }
517             catch (Exception e) {
518                 throw processException(e);
519             }
520             finally {
521                 if (result == null) {
522                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
523                         finderArgs, new ArrayList<Company>());
524                 }
525 
526                 closeSession(session);
527             }
528         }
529         else {
530             if (result instanceof List<?>) {
531                 return null;
532             }
533             else {
534                 return (Company)result;
535             }
536         }
537     }
538 
539     public Company findByVirtualHost(String virtualHost)
540         throws NoSuchCompanyException, SystemException {
541         Company company = fetchByVirtualHost(virtualHost);
542 
543         if (company == null) {
544             StringBundler msg = new StringBundler(4);
545 
546             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
547 
548             msg.append("virtualHost=");
549             msg.append(virtualHost);
550 
551             msg.append(StringPool.CLOSE_CURLY_BRACE);
552 
553             if (_log.isWarnEnabled()) {
554                 _log.warn(msg.toString());
555             }
556 
557             throw new NoSuchCompanyException(msg.toString());
558         }
559 
560         return company;
561     }
562 
563     public Company fetchByVirtualHost(String virtualHost)
564         throws SystemException {
565         return fetchByVirtualHost(virtualHost, true);
566     }
567 
568     public Company fetchByVirtualHost(String virtualHost,
569         boolean retrieveFromCache) throws SystemException {
570         Object[] finderArgs = new Object[] { virtualHost };
571 
572         Object result = null;
573 
574         if (retrieveFromCache) {
575             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
576                     finderArgs, this);
577         }
578 
579         if (result == null) {
580             StringBundler query = new StringBundler(2);
581 
582             query.append(_SQL_SELECT_COMPANY_WHERE);
583 
584             if (virtualHost == null) {
585                 query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
586             }
587             else {
588                 if (virtualHost.equals(StringPool.BLANK)) {
589                     query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
590                 }
591                 else {
592                     query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
593                 }
594             }
595 
596             String sql = query.toString();
597 
598             Session session = null;
599 
600             try {
601                 session = openSession();
602 
603                 Query q = session.createQuery(sql);
604 
605                 QueryPos qPos = QueryPos.getInstance(q);
606 
607                 if (virtualHost != null) {
608                     qPos.add(virtualHost);
609                 }
610 
611                 List<Company> list = q.list();
612 
613                 result = list;
614 
615                 Company company = null;
616 
617                 if (list.isEmpty()) {
618                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
619                         finderArgs, list);
620                 }
621                 else {
622                     company = list.get(0);
623 
624                     cacheResult(company);
625 
626                     if ((company.getVirtualHost() == null) ||
627                             !company.getVirtualHost().equals(virtualHost)) {
628                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
629                             finderArgs, company);
630                     }
631                 }
632 
633                 return company;
634             }
635             catch (Exception e) {
636                 throw processException(e);
637             }
638             finally {
639                 if (result == null) {
640                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
641                         finderArgs, new ArrayList<Company>());
642                 }
643 
644                 closeSession(session);
645             }
646         }
647         else {
648             if (result instanceof List<?>) {
649                 return null;
650             }
651             else {
652                 return (Company)result;
653             }
654         }
655     }
656 
657     public Company findByMx(String mx)
658         throws NoSuchCompanyException, SystemException {
659         Company company = fetchByMx(mx);
660 
661         if (company == null) {
662             StringBundler msg = new StringBundler(4);
663 
664             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
665 
666             msg.append("mx=");
667             msg.append(mx);
668 
669             msg.append(StringPool.CLOSE_CURLY_BRACE);
670 
671             if (_log.isWarnEnabled()) {
672                 _log.warn(msg.toString());
673             }
674 
675             throw new NoSuchCompanyException(msg.toString());
676         }
677 
678         return company;
679     }
680 
681     public Company fetchByMx(String mx) throws SystemException {
682         return fetchByMx(mx, true);
683     }
684 
685     public Company fetchByMx(String mx, boolean retrieveFromCache)
686         throws SystemException {
687         Object[] finderArgs = new Object[] { mx };
688 
689         Object result = null;
690 
691         if (retrieveFromCache) {
692             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MX,
693                     finderArgs, this);
694         }
695 
696         if (result == null) {
697             StringBundler query = new StringBundler(2);
698 
699             query.append(_SQL_SELECT_COMPANY_WHERE);
700 
701             if (mx == null) {
702                 query.append(_FINDER_COLUMN_MX_MX_1);
703             }
704             else {
705                 if (mx.equals(StringPool.BLANK)) {
706                     query.append(_FINDER_COLUMN_MX_MX_3);
707                 }
708                 else {
709                     query.append(_FINDER_COLUMN_MX_MX_2);
710                 }
711             }
712 
713             String sql = query.toString();
714 
715             Session session = null;
716 
717             try {
718                 session = openSession();
719 
720                 Query q = session.createQuery(sql);
721 
722                 QueryPos qPos = QueryPos.getInstance(q);
723 
724                 if (mx != null) {
725                     qPos.add(mx);
726                 }
727 
728                 List<Company> list = q.list();
729 
730                 result = list;
731 
732                 Company company = null;
733 
734                 if (list.isEmpty()) {
735                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
736                         finderArgs, list);
737                 }
738                 else {
739                     company = list.get(0);
740 
741                     cacheResult(company);
742 
743                     if ((company.getMx() == null) ||
744                             !company.getMx().equals(mx)) {
745                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
746                             finderArgs, company);
747                     }
748                 }
749 
750                 return company;
751             }
752             catch (Exception e) {
753                 throw processException(e);
754             }
755             finally {
756                 if (result == null) {
757                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
758                         finderArgs, new ArrayList<Company>());
759                 }
760 
761                 closeSession(session);
762             }
763         }
764         else {
765             if (result instanceof List<?>) {
766                 return null;
767             }
768             else {
769                 return (Company)result;
770             }
771         }
772     }
773 
774     public Company findByLogoId(long logoId)
775         throws NoSuchCompanyException, SystemException {
776         Company company = fetchByLogoId(logoId);
777 
778         if (company == null) {
779             StringBundler msg = new StringBundler(4);
780 
781             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
782 
783             msg.append("logoId=");
784             msg.append(logoId);
785 
786             msg.append(StringPool.CLOSE_CURLY_BRACE);
787 
788             if (_log.isWarnEnabled()) {
789                 _log.warn(msg.toString());
790             }
791 
792             throw new NoSuchCompanyException(msg.toString());
793         }
794 
795         return company;
796     }
797 
798     public Company fetchByLogoId(long logoId) throws SystemException {
799         return fetchByLogoId(logoId, true);
800     }
801 
802     public Company fetchByLogoId(long logoId, boolean retrieveFromCache)
803         throws SystemException {
804         Object[] finderArgs = new Object[] { logoId };
805 
806         Object result = null;
807 
808         if (retrieveFromCache) {
809             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LOGOID,
810                     finderArgs, this);
811         }
812 
813         if (result == null) {
814             StringBundler query = new StringBundler(2);
815 
816             query.append(_SQL_SELECT_COMPANY_WHERE);
817 
818             query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
819 
820             String sql = query.toString();
821 
822             Session session = null;
823 
824             try {
825                 session = openSession();
826 
827                 Query q = session.createQuery(sql);
828 
829                 QueryPos qPos = QueryPos.getInstance(q);
830 
831                 qPos.add(logoId);
832 
833                 List<Company> list = q.list();
834 
835                 result = list;
836 
837                 Company company = null;
838 
839                 if (list.isEmpty()) {
840                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
841                         finderArgs, list);
842                 }
843                 else {
844                     company = list.get(0);
845 
846                     cacheResult(company);
847 
848                     if ((company.getLogoId() != logoId)) {
849                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
850                             finderArgs, company);
851                     }
852                 }
853 
854                 return company;
855             }
856             catch (Exception e) {
857                 throw processException(e);
858             }
859             finally {
860                 if (result == null) {
861                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
862                         finderArgs, new ArrayList<Company>());
863                 }
864 
865                 closeSession(session);
866             }
867         }
868         else {
869             if (result instanceof List<?>) {
870                 return null;
871             }
872             else {
873                 return (Company)result;
874             }
875         }
876     }
877 
878     public List<Company> findBySystem(boolean system) throws SystemException {
879         return findBySystem(system, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
880     }
881 
882     public List<Company> findBySystem(boolean system, int start, int end)
883         throws SystemException {
884         return findBySystem(system, start, end, null);
885     }
886 
887     public List<Company> findBySystem(boolean system, int start, int end,
888         OrderByComparator orderByComparator) throws SystemException {
889         Object[] finderArgs = new Object[] {
890                 system,
891                 
892                 String.valueOf(start), String.valueOf(end),
893                 String.valueOf(orderByComparator)
894             };
895 
896         List<Company> list = (List<Company>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_SYSTEM,
897                 finderArgs, this);
898 
899         if (list == null) {
900             StringBundler query = null;
901 
902             if (orderByComparator != null) {
903                 query = new StringBundler(3 +
904                         (orderByComparator.getOrderByFields().length * 3));
905             }
906             else {
907                 query = new StringBundler(2);
908             }
909 
910             query.append(_SQL_SELECT_COMPANY_WHERE);
911 
912             query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
913 
914             if (orderByComparator != null) {
915                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
916                     orderByComparator);
917             }
918 
919             String sql = query.toString();
920 
921             Session session = null;
922 
923             try {
924                 session = openSession();
925 
926                 Query q = session.createQuery(sql);
927 
928                 QueryPos qPos = QueryPos.getInstance(q);
929 
930                 qPos.add(system);
931 
932                 list = (List<Company>)QueryUtil.list(q, getDialect(), start, end);
933             }
934             catch (Exception e) {
935                 throw processException(e);
936             }
937             finally {
938                 if (list == null) {
939                     list = new ArrayList<Company>();
940                 }
941 
942                 cacheResult(list);
943 
944                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_SYSTEM,
945                     finderArgs, list);
946 
947                 closeSession(session);
948             }
949         }
950 
951         return list;
952     }
953 
954     public Company findBySystem_First(boolean system,
955         OrderByComparator orderByComparator)
956         throws NoSuchCompanyException, SystemException {
957         List<Company> list = findBySystem(system, 0, 1, orderByComparator);
958 
959         if (list.isEmpty()) {
960             StringBundler msg = new StringBundler(4);
961 
962             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
963 
964             msg.append("system=");
965             msg.append(system);
966 
967             msg.append(StringPool.CLOSE_CURLY_BRACE);
968 
969             throw new NoSuchCompanyException(msg.toString());
970         }
971         else {
972             return list.get(0);
973         }
974     }
975 
976     public Company findBySystem_Last(boolean system,
977         OrderByComparator orderByComparator)
978         throws NoSuchCompanyException, SystemException {
979         int count = countBySystem(system);
980 
981         List<Company> list = findBySystem(system, count - 1, count,
982                 orderByComparator);
983 
984         if (list.isEmpty()) {
985             StringBundler msg = new StringBundler(4);
986 
987             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
988 
989             msg.append("system=");
990             msg.append(system);
991 
992             msg.append(StringPool.CLOSE_CURLY_BRACE);
993 
994             throw new NoSuchCompanyException(msg.toString());
995         }
996         else {
997             return list.get(0);
998         }
999     }
1000
1001    public Company[] findBySystem_PrevAndNext(long companyId, boolean system,
1002        OrderByComparator orderByComparator)
1003        throws NoSuchCompanyException, SystemException {
1004        Company company = findByPrimaryKey(companyId);
1005
1006        Session session = null;
1007
1008        try {
1009            session = openSession();
1010
1011            Company[] array = new CompanyImpl[3];
1012
1013            array[0] = getBySystem_PrevAndNext(session, company, system,
1014                    orderByComparator, true);
1015
1016            array[1] = company;
1017
1018            array[2] = getBySystem_PrevAndNext(session, company, system,
1019                    orderByComparator, false);
1020
1021            return array;
1022        }
1023        catch (Exception e) {
1024            throw processException(e);
1025        }
1026        finally {
1027            closeSession(session);
1028        }
1029    }
1030
1031    protected Company getBySystem_PrevAndNext(Session session, Company company,
1032        boolean system, OrderByComparator orderByComparator, boolean previous) {
1033        StringBundler query = null;
1034
1035        if (orderByComparator != null) {
1036            query = new StringBundler(6 +
1037                    (orderByComparator.getOrderByFields().length * 6));
1038        }
1039        else {
1040            query = new StringBundler(3);
1041        }
1042
1043        query.append(_SQL_SELECT_COMPANY_WHERE);
1044
1045        query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1046
1047        if (orderByComparator != null) {
1048            String[] orderByFields = orderByComparator.getOrderByFields();
1049
1050            if (orderByFields.length > 0) {
1051                query.append(WHERE_AND);
1052            }
1053
1054            for (int i = 0; i < orderByFields.length; i++) {
1055                query.append(_ORDER_BY_ENTITY_ALIAS);
1056                query.append(orderByFields[i]);
1057
1058                if ((i + 1) < orderByFields.length) {
1059                    if (orderByComparator.isAscending() ^ previous) {
1060                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1061                    }
1062                    else {
1063                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1064                    }
1065                }
1066                else {
1067                    if (orderByComparator.isAscending() ^ previous) {
1068                        query.append(WHERE_GREATER_THAN);
1069                    }
1070                    else {
1071                        query.append(WHERE_LESSER_THAN);
1072                    }
1073                }
1074            }
1075
1076            query.append(ORDER_BY_CLAUSE);
1077
1078            for (int i = 0; i < orderByFields.length; i++) {
1079                query.append(_ORDER_BY_ENTITY_ALIAS);
1080                query.append(orderByFields[i]);
1081
1082                if ((i + 1) < orderByFields.length) {
1083                    if (orderByComparator.isAscending() ^ previous) {
1084                        query.append(ORDER_BY_ASC_HAS_NEXT);
1085                    }
1086                    else {
1087                        query.append(ORDER_BY_DESC_HAS_NEXT);
1088                    }
1089                }
1090                else {
1091                    if (orderByComparator.isAscending() ^ previous) {
1092                        query.append(ORDER_BY_ASC);
1093                    }
1094                    else {
1095                        query.append(ORDER_BY_DESC);
1096                    }
1097                }
1098            }
1099        }
1100
1101        String sql = query.toString();
1102
1103        Query q = session.createQuery(sql);
1104
1105        q.setFirstResult(0);
1106        q.setMaxResults(2);
1107
1108        QueryPos qPos = QueryPos.getInstance(q);
1109
1110        qPos.add(system);
1111
1112        if (orderByComparator != null) {
1113            Object[] values = orderByComparator.getOrderByValues(company);
1114
1115            for (Object value : values) {
1116                qPos.add(value);
1117            }
1118        }
1119
1120        List<Company> list = q.list();
1121
1122        if (list.size() == 2) {
1123            return list.get(1);
1124        }
1125        else {
1126            return null;
1127        }
1128    }
1129
1130    public List<Company> findAll() throws SystemException {
1131        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1132    }
1133
1134    public List<Company> findAll(int start, int end) throws SystemException {
1135        return findAll(start, end, null);
1136    }
1137
1138    public List<Company> findAll(int start, int end,
1139        OrderByComparator orderByComparator) throws SystemException {
1140        Object[] finderArgs = new Object[] {
1141                String.valueOf(start), String.valueOf(end),
1142                String.valueOf(orderByComparator)
1143            };
1144
1145        List<Company> list = (List<Company>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1146                finderArgs, this);
1147
1148        if (list == null) {
1149            StringBundler query = null;
1150            String sql = null;
1151
1152            if (orderByComparator != null) {
1153                query = new StringBundler(2 +
1154                        (orderByComparator.getOrderByFields().length * 3));
1155
1156                query.append(_SQL_SELECT_COMPANY);
1157
1158                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1159                    orderByComparator);
1160
1161                sql = query.toString();
1162            }
1163            else {
1164                sql = _SQL_SELECT_COMPANY;
1165            }
1166
1167            Session session = null;
1168
1169            try {
1170                session = openSession();
1171
1172                Query q = session.createQuery(sql);
1173
1174                if (orderByComparator == null) {
1175                    list = (List<Company>)QueryUtil.list(q, getDialect(),
1176                            start, end, false);
1177
1178                    Collections.sort(list);
1179                }
1180                else {
1181                    list = (List<Company>)QueryUtil.list(q, getDialect(),
1182                            start, end);
1183                }
1184            }
1185            catch (Exception e) {
1186                throw processException(e);
1187            }
1188            finally {
1189                if (list == null) {
1190                    list = new ArrayList<Company>();
1191                }
1192
1193                cacheResult(list);
1194
1195                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1196
1197                closeSession(session);
1198            }
1199        }
1200
1201        return list;
1202    }
1203
1204    public void removeByWebId(String webId)
1205        throws NoSuchCompanyException, SystemException {
1206        Company company = findByWebId(webId);
1207
1208        remove(company);
1209    }
1210
1211    public void removeByVirtualHost(String virtualHost)
1212        throws NoSuchCompanyException, SystemException {
1213        Company company = findByVirtualHost(virtualHost);
1214
1215        remove(company);
1216    }
1217
1218    public void removeByMx(String mx)
1219        throws NoSuchCompanyException, SystemException {
1220        Company company = findByMx(mx);
1221
1222        remove(company);
1223    }
1224
1225    public void removeByLogoId(long logoId)
1226        throws NoSuchCompanyException, SystemException {
1227        Company company = findByLogoId(logoId);
1228
1229        remove(company);
1230    }
1231
1232    public void removeBySystem(boolean system) throws SystemException {
1233        for (Company company : findBySystem(system)) {
1234            remove(company);
1235        }
1236    }
1237
1238    public void removeAll() throws SystemException {
1239        for (Company company : findAll()) {
1240            remove(company);
1241        }
1242    }
1243
1244    public int countByWebId(String webId) throws SystemException {
1245        Object[] finderArgs = new Object[] { webId };
1246
1247        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_WEBID,
1248                finderArgs, this);
1249
1250        if (count == null) {
1251            StringBundler query = new StringBundler(2);
1252
1253            query.append(_SQL_COUNT_COMPANY_WHERE);
1254
1255            if (webId == null) {
1256                query.append(_FINDER_COLUMN_WEBID_WEBID_1);
1257            }
1258            else {
1259                if (webId.equals(StringPool.BLANK)) {
1260                    query.append(_FINDER_COLUMN_WEBID_WEBID_3);
1261                }
1262                else {
1263                    query.append(_FINDER_COLUMN_WEBID_WEBID_2);
1264                }
1265            }
1266
1267            String sql = query.toString();
1268
1269            Session session = null;
1270
1271            try {
1272                session = openSession();
1273
1274                Query q = session.createQuery(sql);
1275
1276                QueryPos qPos = QueryPos.getInstance(q);
1277
1278                if (webId != null) {
1279                    qPos.add(webId);
1280                }
1281
1282                count = (Long)q.uniqueResult();
1283            }
1284            catch (Exception e) {
1285                throw processException(e);
1286            }
1287            finally {
1288                if (count == null) {
1289                    count = Long.valueOf(0);
1290                }
1291
1292                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_WEBID,
1293                    finderArgs, count);
1294
1295                closeSession(session);
1296            }
1297        }
1298
1299        return count.intValue();
1300    }
1301
1302    public int countByVirtualHost(String virtualHost) throws SystemException {
1303        Object[] finderArgs = new Object[] { virtualHost };
1304
1305        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1306                finderArgs, this);
1307
1308        if (count == null) {
1309            StringBundler query = new StringBundler(2);
1310
1311            query.append(_SQL_COUNT_COMPANY_WHERE);
1312
1313            if (virtualHost == null) {
1314                query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
1315            }
1316            else {
1317                if (virtualHost.equals(StringPool.BLANK)) {
1318                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
1319                }
1320                else {
1321                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
1322                }
1323            }
1324
1325            String sql = query.toString();
1326
1327            Session session = null;
1328
1329            try {
1330                session = openSession();
1331
1332                Query q = session.createQuery(sql);
1333
1334                QueryPos qPos = QueryPos.getInstance(q);
1335
1336                if (virtualHost != null) {
1337                    qPos.add(virtualHost);
1338                }
1339
1340                count = (Long)q.uniqueResult();
1341            }
1342            catch (Exception e) {
1343                throw processException(e);
1344            }
1345            finally {
1346                if (count == null) {
1347                    count = Long.valueOf(0);
1348                }
1349
1350                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1351                    finderArgs, count);
1352
1353                closeSession(session);
1354            }
1355        }
1356
1357        return count.intValue();
1358    }
1359
1360    public int countByMx(String mx) throws SystemException {
1361        Object[] finderArgs = new Object[] { mx };
1362
1363        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MX,
1364                finderArgs, this);
1365
1366        if (count == null) {
1367            StringBundler query = new StringBundler(2);
1368
1369            query.append(_SQL_COUNT_COMPANY_WHERE);
1370
1371            if (mx == null) {
1372                query.append(_FINDER_COLUMN_MX_MX_1);
1373            }
1374            else {
1375                if (mx.equals(StringPool.BLANK)) {
1376                    query.append(_FINDER_COLUMN_MX_MX_3);
1377                }
1378                else {
1379                    query.append(_FINDER_COLUMN_MX_MX_2);
1380                }
1381            }
1382
1383            String sql = query.toString();
1384
1385            Session session = null;
1386
1387            try {
1388                session = openSession();
1389
1390                Query q = session.createQuery(sql);
1391
1392                QueryPos qPos = QueryPos.getInstance(q);
1393
1394                if (mx != null) {
1395                    qPos.add(mx);
1396                }
1397
1398                count = (Long)q.uniqueResult();
1399            }
1400            catch (Exception e) {
1401                throw processException(e);
1402            }
1403            finally {
1404                if (count == null) {
1405                    count = Long.valueOf(0);
1406                }
1407
1408                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MX, finderArgs,
1409                    count);
1410
1411                closeSession(session);
1412            }
1413        }
1414
1415        return count.intValue();
1416    }
1417
1418    public int countByLogoId(long logoId) throws SystemException {
1419        Object[] finderArgs = new Object[] { logoId };
1420
1421        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LOGOID,
1422                finderArgs, this);
1423
1424        if (count == null) {
1425            StringBundler query = new StringBundler(2);
1426
1427            query.append(_SQL_COUNT_COMPANY_WHERE);
1428
1429            query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
1430
1431            String sql = query.toString();
1432
1433            Session session = null;
1434
1435            try {
1436                session = openSession();
1437
1438                Query q = session.createQuery(sql);
1439
1440                QueryPos qPos = QueryPos.getInstance(q);
1441
1442                qPos.add(logoId);
1443
1444                count = (Long)q.uniqueResult();
1445            }
1446            catch (Exception e) {
1447                throw processException(e);
1448            }
1449            finally {
1450                if (count == null) {
1451                    count = Long.valueOf(0);
1452                }
1453
1454                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOGOID,
1455                    finderArgs, count);
1456
1457                closeSession(session);
1458            }
1459        }
1460
1461        return count.intValue();
1462    }
1463
1464    public int countBySystem(boolean system) throws SystemException {
1465        Object[] finderArgs = new Object[] { system };
1466
1467        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SYSTEM,
1468                finderArgs, this);
1469
1470        if (count == null) {
1471            StringBundler query = new StringBundler(2);
1472
1473            query.append(_SQL_COUNT_COMPANY_WHERE);
1474
1475            query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1476
1477            String sql = query.toString();
1478
1479            Session session = null;
1480
1481            try {
1482                session = openSession();
1483
1484                Query q = session.createQuery(sql);
1485
1486                QueryPos qPos = QueryPos.getInstance(q);
1487
1488                qPos.add(system);
1489
1490                count = (Long)q.uniqueResult();
1491            }
1492            catch (Exception e) {
1493                throw processException(e);
1494            }
1495            finally {
1496                if (count == null) {
1497                    count = Long.valueOf(0);
1498                }
1499
1500                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SYSTEM,
1501                    finderArgs, count);
1502
1503                closeSession(session);
1504            }
1505        }
1506
1507        return count.intValue();
1508    }
1509
1510    public int countAll() throws SystemException {
1511        Object[] finderArgs = new Object[0];
1512
1513        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1514                finderArgs, this);
1515
1516        if (count == null) {
1517            Session session = null;
1518
1519            try {
1520                session = openSession();
1521
1522                Query q = session.createQuery(_SQL_COUNT_COMPANY);
1523
1524                count = (Long)q.uniqueResult();
1525            }
1526            catch (Exception e) {
1527                throw processException(e);
1528            }
1529            finally {
1530                if (count == null) {
1531                    count = Long.valueOf(0);
1532                }
1533
1534                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1535                    count);
1536
1537                closeSession(session);
1538            }
1539        }
1540
1541        return count.intValue();
1542    }
1543
1544    public void afterPropertiesSet() {
1545        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1546                    com.liferay.portal.util.PropsUtil.get(
1547                        "value.object.listener.com.liferay.portal.model.Company")));
1548
1549        if (listenerClassNames.length > 0) {
1550            try {
1551                List<ModelListener<Company>> listenersList = new ArrayList<ModelListener<Company>>();
1552
1553                for (String listenerClassName : listenerClassNames) {
1554                    listenersList.add((ModelListener<Company>)InstanceFactory.newInstance(
1555                            listenerClassName));
1556                }
1557
1558                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1559            }
1560            catch (Exception e) {
1561                _log.error(e);
1562            }
1563        }
1564    }
1565
1566    public void destroy() {
1567        EntityCacheUtil.removeCache(CompanyImpl.class.getName());
1568        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1569        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1570    }
1571
1572    @BeanReference(type = AccountPersistence.class)
1573    protected AccountPersistence accountPersistence;
1574    @BeanReference(type = AddressPersistence.class)
1575    protected AddressPersistence addressPersistence;
1576    @BeanReference(type = BrowserTrackerPersistence.class)
1577    protected BrowserTrackerPersistence browserTrackerPersistence;
1578    @BeanReference(type = ClassNamePersistence.class)
1579    protected ClassNamePersistence classNamePersistence;
1580    @BeanReference(type = CompanyPersistence.class)
1581    protected CompanyPersistence companyPersistence;
1582    @BeanReference(type = ContactPersistence.class)
1583    protected ContactPersistence contactPersistence;
1584    @BeanReference(type = CountryPersistence.class)
1585    protected CountryPersistence countryPersistence;
1586    @BeanReference(type = EmailAddressPersistence.class)
1587    protected EmailAddressPersistence emailAddressPersistence;
1588    @BeanReference(type = GroupPersistence.class)
1589    protected GroupPersistence groupPersistence;
1590    @BeanReference(type = ImagePersistence.class)
1591    protected ImagePersistence imagePersistence;
1592    @BeanReference(type = LayoutPersistence.class)
1593    protected LayoutPersistence layoutPersistence;
1594    @BeanReference(type = LayoutSetPersistence.class)
1595    protected LayoutSetPersistence layoutSetPersistence;
1596    @BeanReference(type = ListTypePersistence.class)
1597    protected ListTypePersistence listTypePersistence;
1598    @BeanReference(type = LockPersistence.class)
1599    protected LockPersistence lockPersistence;
1600    @BeanReference(type = MembershipRequestPersistence.class)
1601    protected MembershipRequestPersistence membershipRequestPersistence;
1602    @BeanReference(type = OrganizationPersistence.class)
1603    protected OrganizationPersistence organizationPersistence;
1604    @BeanReference(type = OrgGroupPermissionPersistence.class)
1605    protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1606    @BeanReference(type = OrgGroupRolePersistence.class)
1607    protected OrgGroupRolePersistence orgGroupRolePersistence;
1608    @BeanReference(type = OrgLaborPersistence.class)
1609    protected OrgLaborPersistence orgLaborPersistence;
1610    @BeanReference(type = PasswordPolicyPersistence.class)
1611    protected PasswordPolicyPersistence passwordPolicyPersistence;
1612    @BeanReference(type = PasswordPolicyRelPersistence.class)
1613    protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1614    @BeanReference(type = PasswordTrackerPersistence.class)
1615    protected PasswordTrackerPersistence passwordTrackerPersistence;
1616    @BeanReference(type = PermissionPersistence.class)
1617    protected PermissionPersistence permissionPersistence;
1618    @BeanReference(type = PhonePersistence.class)
1619    protected PhonePersistence phonePersistence;
1620    @BeanReference(type = PluginSettingPersistence.class)
1621    protected PluginSettingPersistence pluginSettingPersistence;
1622    @BeanReference(type = PortletPersistence.class)
1623    protected PortletPersistence portletPersistence;
1624    @BeanReference(type = PortletItemPersistence.class)
1625    protected PortletItemPersistence portletItemPersistence;
1626    @BeanReference(type = PortletPreferencesPersistence.class)
1627    protected PortletPreferencesPersistence portletPreferencesPersistence;
1628    @BeanReference(type = RegionPersistence.class)
1629    protected RegionPersistence regionPersistence;
1630    @BeanReference(type = ReleasePersistence.class)
1631    protected ReleasePersistence releasePersistence;
1632    @BeanReference(type = ResourcePersistence.class)
1633    protected ResourcePersistence resourcePersistence;
1634    @BeanReference(type = ResourceActionPersistence.class)
1635    protected ResourceActionPersistence resourceActionPersistence;
1636    @BeanReference(type = ResourceCodePersistence.class)
1637    protected ResourceCodePersistence resourceCodePersistence;
1638    @BeanReference(type = ResourcePermissionPersistence.class)
1639    protected ResourcePermissionPersistence resourcePermissionPersistence;
1640    @BeanReference(type = RolePersistence.class)
1641    protected RolePersistence rolePersistence;
1642    @BeanReference(type = ServiceComponentPersistence.class)
1643    protected ServiceComponentPersistence serviceComponentPersistence;
1644    @BeanReference(type = ShardPersistence.class)
1645    protected ShardPersistence shardPersistence;
1646    @BeanReference(type = SubscriptionPersistence.class)
1647    protected SubscriptionPersistence subscriptionPersistence;
1648    @BeanReference(type = UserPersistence.class)
1649    protected UserPersistence userPersistence;
1650    @BeanReference(type = UserGroupPersistence.class)
1651    protected UserGroupPersistence userGroupPersistence;
1652    @BeanReference(type = UserGroupGroupRolePersistence.class)
1653    protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1654    @BeanReference(type = UserGroupRolePersistence.class)
1655    protected UserGroupRolePersistence userGroupRolePersistence;
1656    @BeanReference(type = UserIdMapperPersistence.class)
1657    protected UserIdMapperPersistence userIdMapperPersistence;
1658    @BeanReference(type = UserTrackerPersistence.class)
1659    protected UserTrackerPersistence userTrackerPersistence;
1660    @BeanReference(type = UserTrackerPathPersistence.class)
1661    protected UserTrackerPathPersistence userTrackerPathPersistence;
1662    @BeanReference(type = WebDAVPropsPersistence.class)
1663    protected WebDAVPropsPersistence webDAVPropsPersistence;
1664    @BeanReference(type = WebsitePersistence.class)
1665    protected WebsitePersistence websitePersistence;
1666    private static final String _SQL_SELECT_COMPANY = "SELECT company FROM Company company";
1667    private static final String _SQL_SELECT_COMPANY_WHERE = "SELECT company FROM Company company WHERE ";
1668    private static final String _SQL_COUNT_COMPANY = "SELECT COUNT(company) FROM Company company";
1669    private static final String _SQL_COUNT_COMPANY_WHERE = "SELECT COUNT(company) FROM Company company WHERE ";
1670    private static final String _FINDER_COLUMN_WEBID_WEBID_1 = "company.webId IS NULL";
1671    private static final String _FINDER_COLUMN_WEBID_WEBID_2 = "company.webId = ?";
1672    private static final String _FINDER_COLUMN_WEBID_WEBID_3 = "(company.webId IS NULL OR company.webId = ?)";
1673    private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1 = "company.virtualHost IS NULL";
1674    private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2 = "company.virtualHost = ?";
1675    private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3 = "(company.virtualHost IS NULL OR company.virtualHost = ?)";
1676    private static final String _FINDER_COLUMN_MX_MX_1 = "company.mx IS NULL";
1677    private static final String _FINDER_COLUMN_MX_MX_2 = "company.mx = ?";
1678    private static final String _FINDER_COLUMN_MX_MX_3 = "(company.mx IS NULL OR company.mx = ?)";
1679    private static final String _FINDER_COLUMN_LOGOID_LOGOID_2 = "company.logoId = ?";
1680    private static final String _FINDER_COLUMN_SYSTEM_SYSTEM_2 = "company.system = ?";
1681    private static final String _ORDER_BY_ENTITY_ALIAS = "company.";
1682    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Company exists with the primary key ";
1683    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Company exists with the key {";
1684    private static Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
1685}