1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.SystemException;
27  import com.liferay.portal.kernel.dao.DynamicQuery;
28  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
29  import com.liferay.portal.kernel.util.GetterUtil;
30  import com.liferay.portal.kernel.util.OrderByComparator;
31  import com.liferay.portal.kernel.util.StringMaker;
32  import com.liferay.portal.kernel.util.StringPool;
33  import com.liferay.portal.kernel.util.Validator;
34  import com.liferay.portal.model.Company;
35  import com.liferay.portal.model.ModelListener;
36  import com.liferay.portal.model.impl.CompanyImpl;
37  import com.liferay.portal.model.impl.CompanyModelImpl;
38  import com.liferay.portal.spring.hibernate.FinderCache;
39  import com.liferay.portal.spring.hibernate.HibernateUtil;
40  import com.liferay.portal.util.PropsUtil;
41  
42  import com.liferay.util.dao.hibernate.QueryUtil;
43  
44  import org.apache.commons.logging.Log;
45  import org.apache.commons.logging.LogFactory;
46  
47  import org.hibernate.Query;
48  import org.hibernate.Session;
49  
50  import java.util.Collections;
51  import java.util.Iterator;
52  import java.util.List;
53  
54  /**
55   * <a href="CompanyPersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * @author Brian Wing Shun Chan
58   *
59   */
60  public class CompanyPersistenceImpl extends BasePersistence
61      implements CompanyPersistence {
62      public Company create(long companyId) {
63          Company company = new CompanyImpl();
64  
65          company.setNew(true);
66          company.setPrimaryKey(companyId);
67  
68          return company;
69      }
70  
71      public Company remove(long companyId)
72          throws NoSuchCompanyException, SystemException {
73          Session session = null;
74  
75          try {
76              session = openSession();
77  
78              Company company = (Company)session.get(CompanyImpl.class,
79                      new Long(companyId));
80  
81              if (company == null) {
82                  if (_log.isWarnEnabled()) {
83                      _log.warn("No Company exists with the primary key " +
84                          companyId);
85                  }
86  
87                  throw new NoSuchCompanyException(
88                      "No Company exists with the primary key " + companyId);
89              }
90  
91              return remove(company);
92          }
93          catch (NoSuchCompanyException nsee) {
94              throw nsee;
95          }
96          catch (Exception e) {
97              throw HibernateUtil.processException(e);
98          }
99          finally {
100             closeSession(session);
101         }
102     }
103 
104     public Company remove(Company company) throws SystemException {
105         ModelListener listener = _getListener();
106 
107         if (listener != null) {
108             listener.onBeforeRemove(company);
109         }
110 
111         company = removeImpl(company);
112 
113         if (listener != null) {
114             listener.onAfterRemove(company);
115         }
116 
117         return company;
118     }
119 
120     protected Company removeImpl(Company company) throws SystemException {
121         Session session = null;
122 
123         try {
124             session = openSession();
125 
126             session.delete(company);
127 
128             session.flush();
129 
130             return company;
131         }
132         catch (Exception e) {
133             throw HibernateUtil.processException(e);
134         }
135         finally {
136             closeSession(session);
137 
138             FinderCache.clearCache(Company.class.getName());
139         }
140     }
141 
142     public Company update(Company company) throws SystemException {
143         return update(company, false);
144     }
145 
146     public Company update(Company company, boolean merge)
147         throws SystemException {
148         ModelListener listener = _getListener();
149 
150         boolean isNew = company.isNew();
151 
152         if (listener != null) {
153             if (isNew) {
154                 listener.onBeforeCreate(company);
155             }
156             else {
157                 listener.onBeforeUpdate(company);
158             }
159         }
160 
161         company = updateImpl(company, merge);
162 
163         if (listener != null) {
164             if (isNew) {
165                 listener.onAfterCreate(company);
166             }
167             else {
168                 listener.onAfterUpdate(company);
169             }
170         }
171 
172         return company;
173     }
174 
175     public Company updateImpl(com.liferay.portal.model.Company company,
176         boolean merge) throws SystemException {
177         Session session = null;
178 
179         try {
180             session = openSession();
181 
182             if (merge) {
183                 session.merge(company);
184             }
185             else {
186                 if (company.isNew()) {
187                     session.save(company);
188                 }
189             }
190 
191             session.flush();
192 
193             company.setNew(false);
194 
195             return company;
196         }
197         catch (Exception e) {
198             throw HibernateUtil.processException(e);
199         }
200         finally {
201             closeSession(session);
202 
203             FinderCache.clearCache(Company.class.getName());
204         }
205     }
206 
207     public Company findByPrimaryKey(long companyId)
208         throws NoSuchCompanyException, SystemException {
209         Company company = fetchByPrimaryKey(companyId);
210 
211         if (company == null) {
212             if (_log.isWarnEnabled()) {
213                 _log.warn("No Company exists with the primary key " +
214                     companyId);
215             }
216 
217             throw new NoSuchCompanyException(
218                 "No Company exists with the primary key " + companyId);
219         }
220 
221         return company;
222     }
223 
224     public Company fetchByPrimaryKey(long companyId) throws SystemException {
225         Session session = null;
226 
227         try {
228             session = openSession();
229 
230             return (Company)session.get(CompanyImpl.class, new Long(companyId));
231         }
232         catch (Exception e) {
233             throw HibernateUtil.processException(e);
234         }
235         finally {
236             closeSession(session);
237         }
238     }
239 
240     public Company findByWebId(String webId)
241         throws NoSuchCompanyException, SystemException {
242         Company company = fetchByWebId(webId);
243 
244         if (company == null) {
245             StringMaker msg = new StringMaker();
246 
247             msg.append("No Company exists with the key {");
248 
249             msg.append("webId=" + webId);
250 
251             msg.append(StringPool.CLOSE_CURLY_BRACE);
252 
253             if (_log.isWarnEnabled()) {
254                 _log.warn(msg.toString());
255             }
256 
257             throw new NoSuchCompanyException(msg.toString());
258         }
259 
260         return company;
261     }
262 
263     public Company fetchByWebId(String webId) throws SystemException {
264         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
265         String finderClassName = Company.class.getName();
266         String finderMethodName = "fetchByWebId";
267         String[] finderParams = new String[] { String.class.getName() };
268         Object[] finderArgs = new Object[] { webId };
269 
270         Object result = null;
271 
272         if (finderClassNameCacheEnabled) {
273             result = FinderCache.getResult(finderClassName, finderMethodName,
274                     finderParams, finderArgs, getSessionFactory());
275         }
276 
277         if (result == null) {
278             Session session = null;
279 
280             try {
281                 session = openSession();
282 
283                 StringMaker query = new StringMaker();
284 
285                 query.append("FROM com.liferay.portal.model.Company WHERE ");
286 
287                 if (webId == null) {
288                     query.append("webId IS NULL");
289                 }
290                 else {
291                     query.append("webId = ?");
292                 }
293 
294                 query.append(" ");
295 
296                 Query q = session.createQuery(query.toString());
297 
298                 int queryPos = 0;
299 
300                 if (webId != null) {
301                     q.setString(queryPos++, webId);
302                 }
303 
304                 List list = q.list();
305 
306                 FinderCache.putResult(finderClassNameCacheEnabled,
307                     finderClassName, finderMethodName, finderParams,
308                     finderArgs, list);
309 
310                 if (list.size() == 0) {
311                     return null;
312                 }
313                 else {
314                     return (Company)list.get(0);
315                 }
316             }
317             catch (Exception e) {
318                 throw HibernateUtil.processException(e);
319             }
320             finally {
321                 closeSession(session);
322             }
323         }
324         else {
325             List list = (List)result;
326 
327             if (list.size() == 0) {
328                 return null;
329             }
330             else {
331                 return (Company)list.get(0);
332             }
333         }
334     }
335 
336     public Company findByVirtualHost(String virtualHost)
337         throws NoSuchCompanyException, SystemException {
338         Company company = fetchByVirtualHost(virtualHost);
339 
340         if (company == null) {
341             StringMaker msg = new StringMaker();
342 
343             msg.append("No Company exists with the key {");
344 
345             msg.append("virtualHost=" + virtualHost);
346 
347             msg.append(StringPool.CLOSE_CURLY_BRACE);
348 
349             if (_log.isWarnEnabled()) {
350                 _log.warn(msg.toString());
351             }
352 
353             throw new NoSuchCompanyException(msg.toString());
354         }
355 
356         return company;
357     }
358 
359     public Company fetchByVirtualHost(String virtualHost)
360         throws SystemException {
361         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
362         String finderClassName = Company.class.getName();
363         String finderMethodName = "fetchByVirtualHost";
364         String[] finderParams = new String[] { String.class.getName() };
365         Object[] finderArgs = new Object[] { virtualHost };
366 
367         Object result = null;
368 
369         if (finderClassNameCacheEnabled) {
370             result = FinderCache.getResult(finderClassName, finderMethodName,
371                     finderParams, finderArgs, getSessionFactory());
372         }
373 
374         if (result == null) {
375             Session session = null;
376 
377             try {
378                 session = openSession();
379 
380                 StringMaker query = new StringMaker();
381 
382                 query.append("FROM com.liferay.portal.model.Company WHERE ");
383 
384                 if (virtualHost == null) {
385                     query.append("virtualHost IS NULL");
386                 }
387                 else {
388                     query.append("virtualHost = ?");
389                 }
390 
391                 query.append(" ");
392 
393                 Query q = session.createQuery(query.toString());
394 
395                 int queryPos = 0;
396 
397                 if (virtualHost != null) {
398                     q.setString(queryPos++, virtualHost);
399                 }
400 
401                 List list = q.list();
402 
403                 FinderCache.putResult(finderClassNameCacheEnabled,
404                     finderClassName, finderMethodName, finderParams,
405                     finderArgs, list);
406 
407                 if (list.size() == 0) {
408                     return null;
409                 }
410                 else {
411                     return (Company)list.get(0);
412                 }
413             }
414             catch (Exception e) {
415                 throw HibernateUtil.processException(e);
416             }
417             finally {
418                 closeSession(session);
419             }
420         }
421         else {
422             List list = (List)result;
423 
424             if (list.size() == 0) {
425                 return null;
426             }
427             else {
428                 return (Company)list.get(0);
429             }
430         }
431     }
432 
433     public Company findByMx(String mx)
434         throws NoSuchCompanyException, SystemException {
435         Company company = fetchByMx(mx);
436 
437         if (company == null) {
438             StringMaker msg = new StringMaker();
439 
440             msg.append("No Company exists with the key {");
441 
442             msg.append("mx=" + mx);
443 
444             msg.append(StringPool.CLOSE_CURLY_BRACE);
445 
446             if (_log.isWarnEnabled()) {
447                 _log.warn(msg.toString());
448             }
449 
450             throw new NoSuchCompanyException(msg.toString());
451         }
452 
453         return company;
454     }
455 
456     public Company fetchByMx(String mx) throws SystemException {
457         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
458         String finderClassName = Company.class.getName();
459         String finderMethodName = "fetchByMx";
460         String[] finderParams = new String[] { String.class.getName() };
461         Object[] finderArgs = new Object[] { mx };
462 
463         Object result = null;
464 
465         if (finderClassNameCacheEnabled) {
466             result = FinderCache.getResult(finderClassName, finderMethodName,
467                     finderParams, finderArgs, getSessionFactory());
468         }
469 
470         if (result == null) {
471             Session session = null;
472 
473             try {
474                 session = openSession();
475 
476                 StringMaker query = new StringMaker();
477 
478                 query.append("FROM com.liferay.portal.model.Company WHERE ");
479 
480                 if (mx == null) {
481                     query.append("mx IS NULL");
482                 }
483                 else {
484                     query.append("mx = ?");
485                 }
486 
487                 query.append(" ");
488 
489                 Query q = session.createQuery(query.toString());
490 
491                 int queryPos = 0;
492 
493                 if (mx != null) {
494                     q.setString(queryPos++, mx);
495                 }
496 
497                 List list = q.list();
498 
499                 FinderCache.putResult(finderClassNameCacheEnabled,
500                     finderClassName, finderMethodName, finderParams,
501                     finderArgs, list);
502 
503                 if (list.size() == 0) {
504                     return null;
505                 }
506                 else {
507                     return (Company)list.get(0);
508                 }
509             }
510             catch (Exception e) {
511                 throw HibernateUtil.processException(e);
512             }
513             finally {
514                 closeSession(session);
515             }
516         }
517         else {
518             List list = (List)result;
519 
520             if (list.size() == 0) {
521                 return null;
522             }
523             else {
524                 return (Company)list.get(0);
525             }
526         }
527     }
528 
529     public Company findByLogoId(long logoId)
530         throws NoSuchCompanyException, SystemException {
531         Company company = fetchByLogoId(logoId);
532 
533         if (company == null) {
534             StringMaker msg = new StringMaker();
535 
536             msg.append("No Company exists with the key {");
537 
538             msg.append("logoId=" + logoId);
539 
540             msg.append(StringPool.CLOSE_CURLY_BRACE);
541 
542             if (_log.isWarnEnabled()) {
543                 _log.warn(msg.toString());
544             }
545 
546             throw new NoSuchCompanyException(msg.toString());
547         }
548 
549         return company;
550     }
551 
552     public Company fetchByLogoId(long logoId) throws SystemException {
553         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
554         String finderClassName = Company.class.getName();
555         String finderMethodName = "fetchByLogoId";
556         String[] finderParams = new String[] { Long.class.getName() };
557         Object[] finderArgs = new Object[] { new Long(logoId) };
558 
559         Object result = null;
560 
561         if (finderClassNameCacheEnabled) {
562             result = FinderCache.getResult(finderClassName, finderMethodName,
563                     finderParams, finderArgs, getSessionFactory());
564         }
565 
566         if (result == null) {
567             Session session = null;
568 
569             try {
570                 session = openSession();
571 
572                 StringMaker query = new StringMaker();
573 
574                 query.append("FROM com.liferay.portal.model.Company WHERE ");
575 
576                 query.append("logoId = ?");
577 
578                 query.append(" ");
579 
580                 Query q = session.createQuery(query.toString());
581 
582                 int queryPos = 0;
583 
584                 q.setLong(queryPos++, logoId);
585 
586                 List list = q.list();
587 
588                 FinderCache.putResult(finderClassNameCacheEnabled,
589                     finderClassName, finderMethodName, finderParams,
590                     finderArgs, list);
591 
592                 if (list.size() == 0) {
593                     return null;
594                 }
595                 else {
596                     return (Company)list.get(0);
597                 }
598             }
599             catch (Exception e) {
600                 throw HibernateUtil.processException(e);
601             }
602             finally {
603                 closeSession(session);
604             }
605         }
606         else {
607             List list = (List)result;
608 
609             if (list.size() == 0) {
610                 return null;
611             }
612             else {
613                 return (Company)list.get(0);
614             }
615         }
616     }
617 
618     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
619         throws SystemException {
620         Session session = null;
621 
622         try {
623             session = openSession();
624 
625             DynamicQuery query = queryInitializer.initialize(session);
626 
627             return query.list();
628         }
629         catch (Exception e) {
630             throw HibernateUtil.processException(e);
631         }
632         finally {
633             closeSession(session);
634         }
635     }
636 
637     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
638         int begin, int end) throws SystemException {
639         Session session = null;
640 
641         try {
642             session = openSession();
643 
644             DynamicQuery query = queryInitializer.initialize(session);
645 
646             query.setLimit(begin, end);
647 
648             return query.list();
649         }
650         catch (Exception e) {
651             throw HibernateUtil.processException(e);
652         }
653         finally {
654             closeSession(session);
655         }
656     }
657 
658     public List findAll() throws SystemException {
659         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
660     }
661 
662     public List findAll(int begin, int end) throws SystemException {
663         return findAll(begin, end, null);
664     }
665 
666     public List findAll(int begin, int end, OrderByComparator obc)
667         throws SystemException {
668         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
669         String finderClassName = Company.class.getName();
670         String finderMethodName = "findAll";
671         String[] finderParams = new String[] {
672                 "java.lang.Integer", "java.lang.Integer",
673                 "com.liferay.portal.kernel.util.OrderByComparator"
674             };
675         Object[] finderArgs = new Object[] {
676                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
677             };
678 
679         Object result = null;
680 
681         if (finderClassNameCacheEnabled) {
682             result = FinderCache.getResult(finderClassName, finderMethodName,
683                     finderParams, finderArgs, getSessionFactory());
684         }
685 
686         if (result == null) {
687             Session session = null;
688 
689             try {
690                 session = openSession();
691 
692                 StringMaker query = new StringMaker();
693 
694                 query.append("FROM com.liferay.portal.model.Company ");
695 
696                 if (obc != null) {
697                     query.append("ORDER BY ");
698                     query.append(obc.getOrderBy());
699                 }
700 
701                 Query q = session.createQuery(query.toString());
702 
703                 List list = QueryUtil.list(q, getDialect(), begin, end);
704 
705                 if (obc == null) {
706                     Collections.sort(list);
707                 }
708 
709                 FinderCache.putResult(finderClassNameCacheEnabled,
710                     finderClassName, finderMethodName, finderParams,
711                     finderArgs, list);
712 
713                 return list;
714             }
715             catch (Exception e) {
716                 throw HibernateUtil.processException(e);
717             }
718             finally {
719                 closeSession(session);
720             }
721         }
722         else {
723             return (List)result;
724         }
725     }
726 
727     public void removeByWebId(String webId)
728         throws NoSuchCompanyException, SystemException {
729         Company company = findByWebId(webId);
730 
731         remove(company);
732     }
733 
734     public void removeByVirtualHost(String virtualHost)
735         throws NoSuchCompanyException, SystemException {
736         Company company = findByVirtualHost(virtualHost);
737 
738         remove(company);
739     }
740 
741     public void removeByMx(String mx)
742         throws NoSuchCompanyException, SystemException {
743         Company company = findByMx(mx);
744 
745         remove(company);
746     }
747 
748     public void removeByLogoId(long logoId)
749         throws NoSuchCompanyException, SystemException {
750         Company company = findByLogoId(logoId);
751 
752         remove(company);
753     }
754 
755     public void removeAll() throws SystemException {
756         Iterator itr = findAll().iterator();
757 
758         while (itr.hasNext()) {
759             remove((Company)itr.next());
760         }
761     }
762 
763     public int countByWebId(String webId) throws SystemException {
764         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
765         String finderClassName = Company.class.getName();
766         String finderMethodName = "countByWebId";
767         String[] finderParams = new String[] { String.class.getName() };
768         Object[] finderArgs = new Object[] { webId };
769 
770         Object result = null;
771 
772         if (finderClassNameCacheEnabled) {
773             result = FinderCache.getResult(finderClassName, finderMethodName,
774                     finderParams, finderArgs, getSessionFactory());
775         }
776 
777         if (result == null) {
778             Session session = null;
779 
780             try {
781                 session = openSession();
782 
783                 StringMaker query = new StringMaker();
784 
785                 query.append("SELECT COUNT(*) ");
786                 query.append("FROM com.liferay.portal.model.Company WHERE ");
787 
788                 if (webId == null) {
789                     query.append("webId IS NULL");
790                 }
791                 else {
792                     query.append("webId = ?");
793                 }
794 
795                 query.append(" ");
796 
797                 Query q = session.createQuery(query.toString());
798 
799                 int queryPos = 0;
800 
801                 if (webId != null) {
802                     q.setString(queryPos++, webId);
803                 }
804 
805                 Long count = null;
806 
807                 Iterator itr = q.list().iterator();
808 
809                 if (itr.hasNext()) {
810                     count = (Long)itr.next();
811                 }
812 
813                 if (count == null) {
814                     count = new Long(0);
815                 }
816 
817                 FinderCache.putResult(finderClassNameCacheEnabled,
818                     finderClassName, finderMethodName, finderParams,
819                     finderArgs, count);
820 
821                 return count.intValue();
822             }
823             catch (Exception e) {
824                 throw HibernateUtil.processException(e);
825             }
826             finally {
827                 closeSession(session);
828             }
829         }
830         else {
831             return ((Long)result).intValue();
832         }
833     }
834 
835     public int countByVirtualHost(String virtualHost) throws SystemException {
836         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
837         String finderClassName = Company.class.getName();
838         String finderMethodName = "countByVirtualHost";
839         String[] finderParams = new String[] { String.class.getName() };
840         Object[] finderArgs = new Object[] { virtualHost };
841 
842         Object result = null;
843 
844         if (finderClassNameCacheEnabled) {
845             result = FinderCache.getResult(finderClassName, finderMethodName,
846                     finderParams, finderArgs, getSessionFactory());
847         }
848 
849         if (result == null) {
850             Session session = null;
851 
852             try {
853                 session = openSession();
854 
855                 StringMaker query = new StringMaker();
856 
857                 query.append("SELECT COUNT(*) ");
858                 query.append("FROM com.liferay.portal.model.Company WHERE ");
859 
860                 if (virtualHost == null) {
861                     query.append("virtualHost IS NULL");
862                 }
863                 else {
864                     query.append("virtualHost = ?");
865                 }
866 
867                 query.append(" ");
868 
869                 Query q = session.createQuery(query.toString());
870 
871                 int queryPos = 0;
872 
873                 if (virtualHost != null) {
874                     q.setString(queryPos++, virtualHost);
875                 }
876 
877                 Long count = null;
878 
879                 Iterator itr = q.list().iterator();
880 
881                 if (itr.hasNext()) {
882                     count = (Long)itr.next();
883                 }
884 
885                 if (count == null) {
886                     count = new Long(0);
887                 }
888 
889                 FinderCache.putResult(finderClassNameCacheEnabled,
890                     finderClassName, finderMethodName, finderParams,
891                     finderArgs, count);
892 
893                 return count.intValue();
894             }
895             catch (Exception e) {
896                 throw HibernateUtil.processException(e);
897             }
898             finally {
899                 closeSession(session);
900             }
901         }
902         else {
903             return ((Long)result).intValue();
904         }
905     }
906 
907     public int countByMx(String mx) throws SystemException {
908         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
909         String finderClassName = Company.class.getName();
910         String finderMethodName = "countByMx";
911         String[] finderParams = new String[] { String.class.getName() };
912         Object[] finderArgs = new Object[] { mx };
913 
914         Object result = null;
915 
916         if (finderClassNameCacheEnabled) {
917             result = FinderCache.getResult(finderClassName, finderMethodName,
918                     finderParams, finderArgs, getSessionFactory());
919         }
920 
921         if (result == null) {
922             Session session = null;
923 
924             try {
925                 session = openSession();
926 
927                 StringMaker query = new StringMaker();
928 
929                 query.append("SELECT COUNT(*) ");
930                 query.append("FROM com.liferay.portal.model.Company WHERE ");
931 
932                 if (mx == null) {
933                     query.append("mx IS NULL");
934                 }
935                 else {
936                     query.append("mx = ?");
937                 }
938 
939                 query.append(" ");
940 
941                 Query q = session.createQuery(query.toString());
942 
943                 int queryPos = 0;
944 
945                 if (mx != null) {
946                     q.setString(queryPos++, mx);
947                 }
948 
949                 Long count = null;
950 
951                 Iterator itr = q.list().iterator();
952 
953                 if (itr.hasNext()) {
954                     count = (Long)itr.next();
955                 }
956 
957                 if (count == null) {
958                     count = new Long(0);
959                 }
960 
961                 FinderCache.putResult(finderClassNameCacheEnabled,
962                     finderClassName, finderMethodName, finderParams,
963                     finderArgs, count);
964 
965                 return count.intValue();
966             }
967             catch (Exception e) {
968                 throw HibernateUtil.processException(e);
969             }
970             finally {
971                 closeSession(session);
972             }
973         }
974         else {
975             return ((Long)result).intValue();
976         }
977     }
978 
979     public int countByLogoId(long logoId) throws SystemException {
980         boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
981         String finderClassName = Company.class.getName();
982         String finderMethodName = "countByLogoId";
983         String[] finderParams = new String[] { Long.class.getName() };
984         Object[] finderArgs = new Object[] { new Long(logoId) };
985 
986         Object result = null;
987 
988         if (finderClassNameCacheEnabled) {
989             result = FinderCache.getResult(finderClassName, finderMethodName,
990                     finderParams, finderArgs, getSessionFactory());
991         }
992 
993         if (result == null) {
994             Session session = null;
995 
996             try {
997                 session = openSession();
998 
999                 StringMaker query = new StringMaker();
1000
1001                query.append("SELECT COUNT(*) ");
1002                query.append("FROM com.liferay.portal.model.Company WHERE ");
1003
1004                query.append("logoId = ?");
1005
1006                query.append(" ");
1007
1008                Query q = session.createQuery(query.toString());
1009
1010                int queryPos = 0;
1011
1012                q.setLong(queryPos++, logoId);
1013
1014                Long count = null;
1015
1016                Iterator itr = q.list().iterator();
1017
1018                if (itr.hasNext()) {
1019                    count = (Long)itr.next();
1020                }
1021
1022                if (count == null) {
1023                    count = new Long(0);
1024                }
1025
1026                FinderCache.putResult(finderClassNameCacheEnabled,
1027                    finderClassName, finderMethodName, finderParams,
1028                    finderArgs, count);
1029
1030                return count.intValue();
1031            }
1032            catch (Exception e) {
1033                throw HibernateUtil.processException(e);
1034            }
1035            finally {
1036                closeSession(session);
1037            }
1038        }
1039        else {
1040            return ((Long)result).intValue();
1041        }
1042    }
1043
1044    public int countAll() throws SystemException {
1045        boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
1046        String finderClassName = Company.class.getName();
1047        String finderMethodName = "countAll";
1048        String[] finderParams = new String[] {  };
1049        Object[] finderArgs = new Object[] {  };
1050
1051        Object result = null;
1052
1053        if (finderClassNameCacheEnabled) {
1054            result = FinderCache.getResult(finderClassName, finderMethodName,
1055                    finderParams, finderArgs, getSessionFactory());
1056        }
1057
1058        if (result == null) {
1059            Session session = null;
1060
1061            try {
1062                session = openSession();
1063
1064                Query q = session.createQuery(
1065                        "SELECT COUNT(*) FROM com.liferay.portal.model.Company");
1066
1067                Long count = null;
1068
1069                Iterator itr = q.list().iterator();
1070
1071                if (itr.hasNext()) {
1072                    count = (Long)itr.next();
1073                }
1074
1075                if (count == null) {
1076                    count = new Long(0);
1077                }
1078
1079                FinderCache.putResult(finderClassNameCacheEnabled,
1080                    finderClassName, finderMethodName, finderParams,
1081                    finderArgs, count);
1082
1083                return count.intValue();
1084            }
1085            catch (Exception e) {
1086                throw HibernateUtil.processException(e);
1087            }
1088            finally {
1089                closeSession(session);
1090            }
1091        }
1092        else {
1093            return ((Long)result).intValue();
1094        }
1095    }
1096
1097    protected void initDao() {
1098    }
1099
1100    private static ModelListener _getListener() {
1101        if (Validator.isNotNull(_LISTENER)) {
1102            try {
1103                return (ModelListener)Class.forName(_LISTENER).newInstance();
1104            }
1105            catch (Exception e) {
1106                _log.error(e);
1107            }
1108        }
1109
1110        return null;
1111    }
1112
1113    private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
1114                "value.object.listener.com.liferay.portal.model.Company"));
1115    private static Log _log = LogFactory.getLog(CompanyPersistenceImpl.class);
1116}