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