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