001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchCompanyException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.Company;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.impl.CompanyImpl;
041 import com.liferay.portal.model.impl.CompanyModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class CompanyPersistenceImpl extends BasePersistenceImpl<Company>
063 implements CompanyPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = CompanyImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
075 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
078 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
081 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_FETCH_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
084 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
085 FINDER_CLASS_NAME_ENTITY, "fetchByWebId",
086 new String[] { String.class.getName() },
087 CompanyModelImpl.WEBID_COLUMN_BITMASK);
088 public static final FinderPath FINDER_PATH_COUNT_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
089 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByWebId",
091 new String[] { String.class.getName() });
092
093
101 public Company findByWebId(String webId)
102 throws NoSuchCompanyException, SystemException {
103 Company company = fetchByWebId(webId);
104
105 if (company == null) {
106 StringBundler msg = new StringBundler(4);
107
108 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
109
110 msg.append("webId=");
111 msg.append(webId);
112
113 msg.append(StringPool.CLOSE_CURLY_BRACE);
114
115 if (_log.isWarnEnabled()) {
116 _log.warn(msg.toString());
117 }
118
119 throw new NoSuchCompanyException(msg.toString());
120 }
121
122 return company;
123 }
124
125
132 public Company fetchByWebId(String webId) throws SystemException {
133 return fetchByWebId(webId, true);
134 }
135
136
144 public Company fetchByWebId(String webId, boolean retrieveFromCache)
145 throws SystemException {
146 Object[] finderArgs = new Object[] { webId };
147
148 Object result = null;
149
150 if (retrieveFromCache) {
151 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_WEBID,
152 finderArgs, this);
153 }
154
155 if (result instanceof Company) {
156 Company company = (Company)result;
157
158 if (!Validator.equals(webId, company.getWebId())) {
159 result = null;
160 }
161 }
162
163 if (result == null) {
164 StringBundler query = new StringBundler(3);
165
166 query.append(_SQL_SELECT_COMPANY_WHERE);
167
168 boolean bindWebId = false;
169
170 if (webId == null) {
171 query.append(_FINDER_COLUMN_WEBID_WEBID_1);
172 }
173 else if (webId.equals(StringPool.BLANK)) {
174 query.append(_FINDER_COLUMN_WEBID_WEBID_3);
175 }
176 else {
177 bindWebId = true;
178
179 query.append(_FINDER_COLUMN_WEBID_WEBID_2);
180 }
181
182 String sql = query.toString();
183
184 Session session = null;
185
186 try {
187 session = openSession();
188
189 Query q = session.createQuery(sql);
190
191 QueryPos qPos = QueryPos.getInstance(q);
192
193 if (bindWebId) {
194 qPos.add(webId);
195 }
196
197 List<Company> list = q.list();
198
199 if (list.isEmpty()) {
200 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
201 finderArgs, list);
202 }
203 else {
204 Company company = list.get(0);
205
206 result = company;
207
208 cacheResult(company);
209
210 if ((company.getWebId() == null) ||
211 !company.getWebId().equals(webId)) {
212 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
213 finderArgs, company);
214 }
215 }
216 }
217 catch (Exception e) {
218 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
219 finderArgs);
220
221 throw processException(e);
222 }
223 finally {
224 closeSession(session);
225 }
226 }
227
228 if (result instanceof List<?>) {
229 return null;
230 }
231 else {
232 return (Company)result;
233 }
234 }
235
236
243 public Company removeByWebId(String webId)
244 throws NoSuchCompanyException, SystemException {
245 Company company = findByWebId(webId);
246
247 return remove(company);
248 }
249
250
257 public int countByWebId(String webId) throws SystemException {
258 FinderPath finderPath = FINDER_PATH_COUNT_BY_WEBID;
259
260 Object[] finderArgs = new Object[] { webId };
261
262 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
263 this);
264
265 if (count == null) {
266 StringBundler query = new StringBundler(2);
267
268 query.append(_SQL_COUNT_COMPANY_WHERE);
269
270 boolean bindWebId = false;
271
272 if (webId == null) {
273 query.append(_FINDER_COLUMN_WEBID_WEBID_1);
274 }
275 else if (webId.equals(StringPool.BLANK)) {
276 query.append(_FINDER_COLUMN_WEBID_WEBID_3);
277 }
278 else {
279 bindWebId = true;
280
281 query.append(_FINDER_COLUMN_WEBID_WEBID_2);
282 }
283
284 String sql = query.toString();
285
286 Session session = null;
287
288 try {
289 session = openSession();
290
291 Query q = session.createQuery(sql);
292
293 QueryPos qPos = QueryPos.getInstance(q);
294
295 if (bindWebId) {
296 qPos.add(webId);
297 }
298
299 count = (Long)q.uniqueResult();
300
301 FinderCacheUtil.putResult(finderPath, finderArgs, count);
302 }
303 catch (Exception e) {
304 FinderCacheUtil.removeResult(finderPath, finderArgs);
305
306 throw processException(e);
307 }
308 finally {
309 closeSession(session);
310 }
311 }
312
313 return count.intValue();
314 }
315
316 private static final String _FINDER_COLUMN_WEBID_WEBID_1 = "company.webId IS NULL";
317 private static final String _FINDER_COLUMN_WEBID_WEBID_2 = "company.webId = ?";
318 private static final String _FINDER_COLUMN_WEBID_WEBID_3 = "(company.webId IS NULL OR company.webId = '')";
319 public static final FinderPath FINDER_PATH_FETCH_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
320 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
321 FINDER_CLASS_NAME_ENTITY, "fetchByMx",
322 new String[] { String.class.getName() },
323 CompanyModelImpl.MX_COLUMN_BITMASK);
324 public static final FinderPath FINDER_PATH_COUNT_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
325 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
326 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMx",
327 new String[] { String.class.getName() });
328
329
337 public Company findByMx(String mx)
338 throws NoSuchCompanyException, SystemException {
339 Company company = fetchByMx(mx);
340
341 if (company == null) {
342 StringBundler msg = new StringBundler(4);
343
344 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
345
346 msg.append("mx=");
347 msg.append(mx);
348
349 msg.append(StringPool.CLOSE_CURLY_BRACE);
350
351 if (_log.isWarnEnabled()) {
352 _log.warn(msg.toString());
353 }
354
355 throw new NoSuchCompanyException(msg.toString());
356 }
357
358 return company;
359 }
360
361
368 public Company fetchByMx(String mx) throws SystemException {
369 return fetchByMx(mx, true);
370 }
371
372
380 public Company fetchByMx(String mx, boolean retrieveFromCache)
381 throws SystemException {
382 Object[] finderArgs = new Object[] { mx };
383
384 Object result = null;
385
386 if (retrieveFromCache) {
387 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MX,
388 finderArgs, this);
389 }
390
391 if (result instanceof Company) {
392 Company company = (Company)result;
393
394 if (!Validator.equals(mx, company.getMx())) {
395 result = null;
396 }
397 }
398
399 if (result == null) {
400 StringBundler query = new StringBundler(3);
401
402 query.append(_SQL_SELECT_COMPANY_WHERE);
403
404 boolean bindMx = false;
405
406 if (mx == null) {
407 query.append(_FINDER_COLUMN_MX_MX_1);
408 }
409 else if (mx.equals(StringPool.BLANK)) {
410 query.append(_FINDER_COLUMN_MX_MX_3);
411 }
412 else {
413 bindMx = true;
414
415 query.append(_FINDER_COLUMN_MX_MX_2);
416 }
417
418 String sql = query.toString();
419
420 Session session = null;
421
422 try {
423 session = openSession();
424
425 Query q = session.createQuery(sql);
426
427 QueryPos qPos = QueryPos.getInstance(q);
428
429 if (bindMx) {
430 qPos.add(mx);
431 }
432
433 List<Company> list = q.list();
434
435 if (list.isEmpty()) {
436 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
437 finderArgs, list);
438 }
439 else {
440 if ((list.size() > 1) && _log.isWarnEnabled()) {
441 _log.warn(
442 "CompanyPersistenceImpl.fetchByMx(String, boolean) with parameters (" +
443 StringUtil.merge(finderArgs) +
444 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
445 }
446
447 Company company = list.get(0);
448
449 result = company;
450
451 cacheResult(company);
452
453 if ((company.getMx() == null) ||
454 !company.getMx().equals(mx)) {
455 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
456 finderArgs, company);
457 }
458 }
459 }
460 catch (Exception e) {
461 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, finderArgs);
462
463 throw processException(e);
464 }
465 finally {
466 closeSession(session);
467 }
468 }
469
470 if (result instanceof List<?>) {
471 return null;
472 }
473 else {
474 return (Company)result;
475 }
476 }
477
478
485 public Company removeByMx(String mx)
486 throws NoSuchCompanyException, SystemException {
487 Company company = findByMx(mx);
488
489 return remove(company);
490 }
491
492
499 public int countByMx(String mx) throws SystemException {
500 FinderPath finderPath = FINDER_PATH_COUNT_BY_MX;
501
502 Object[] finderArgs = new Object[] { mx };
503
504 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
505 this);
506
507 if (count == null) {
508 StringBundler query = new StringBundler(2);
509
510 query.append(_SQL_COUNT_COMPANY_WHERE);
511
512 boolean bindMx = false;
513
514 if (mx == null) {
515 query.append(_FINDER_COLUMN_MX_MX_1);
516 }
517 else if (mx.equals(StringPool.BLANK)) {
518 query.append(_FINDER_COLUMN_MX_MX_3);
519 }
520 else {
521 bindMx = true;
522
523 query.append(_FINDER_COLUMN_MX_MX_2);
524 }
525
526 String sql = query.toString();
527
528 Session session = null;
529
530 try {
531 session = openSession();
532
533 Query q = session.createQuery(sql);
534
535 QueryPos qPos = QueryPos.getInstance(q);
536
537 if (bindMx) {
538 qPos.add(mx);
539 }
540
541 count = (Long)q.uniqueResult();
542
543 FinderCacheUtil.putResult(finderPath, finderArgs, count);
544 }
545 catch (Exception e) {
546 FinderCacheUtil.removeResult(finderPath, finderArgs);
547
548 throw processException(e);
549 }
550 finally {
551 closeSession(session);
552 }
553 }
554
555 return count.intValue();
556 }
557
558 private static final String _FINDER_COLUMN_MX_MX_1 = "company.mx IS NULL";
559 private static final String _FINDER_COLUMN_MX_MX_2 = "company.mx = ?";
560 private static final String _FINDER_COLUMN_MX_MX_3 = "(company.mx IS NULL OR company.mx = '')";
561 public static final FinderPath FINDER_PATH_FETCH_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
562 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
563 FINDER_CLASS_NAME_ENTITY, "fetchByLogoId",
564 new String[] { Long.class.getName() },
565 CompanyModelImpl.LOGOID_COLUMN_BITMASK);
566 public static final FinderPath FINDER_PATH_COUNT_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
567 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
568 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLogoId",
569 new String[] { Long.class.getName() });
570
571
579 public Company findByLogoId(long logoId)
580 throws NoSuchCompanyException, SystemException {
581 Company company = fetchByLogoId(logoId);
582
583 if (company == null) {
584 StringBundler msg = new StringBundler(4);
585
586 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
587
588 msg.append("logoId=");
589 msg.append(logoId);
590
591 msg.append(StringPool.CLOSE_CURLY_BRACE);
592
593 if (_log.isWarnEnabled()) {
594 _log.warn(msg.toString());
595 }
596
597 throw new NoSuchCompanyException(msg.toString());
598 }
599
600 return company;
601 }
602
603
610 public Company fetchByLogoId(long logoId) throws SystemException {
611 return fetchByLogoId(logoId, true);
612 }
613
614
622 public Company fetchByLogoId(long logoId, boolean retrieveFromCache)
623 throws SystemException {
624 Object[] finderArgs = new Object[] { logoId };
625
626 Object result = null;
627
628 if (retrieveFromCache) {
629 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LOGOID,
630 finderArgs, this);
631 }
632
633 if (result instanceof Company) {
634 Company company = (Company)result;
635
636 if ((logoId != company.getLogoId())) {
637 result = null;
638 }
639 }
640
641 if (result == null) {
642 StringBundler query = new StringBundler(3);
643
644 query.append(_SQL_SELECT_COMPANY_WHERE);
645
646 query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
647
648 String sql = query.toString();
649
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 Query q = session.createQuery(sql);
656
657 QueryPos qPos = QueryPos.getInstance(q);
658
659 qPos.add(logoId);
660
661 List<Company> list = q.list();
662
663 if (list.isEmpty()) {
664 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
665 finderArgs, list);
666 }
667 else {
668 if ((list.size() > 1) && _log.isWarnEnabled()) {
669 _log.warn(
670 "CompanyPersistenceImpl.fetchByLogoId(long, boolean) with parameters (" +
671 StringUtil.merge(finderArgs) +
672 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
673 }
674
675 Company company = list.get(0);
676
677 result = company;
678
679 cacheResult(company);
680
681 if ((company.getLogoId() != logoId)) {
682 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
683 finderArgs, company);
684 }
685 }
686 }
687 catch (Exception e) {
688 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
689 finderArgs);
690
691 throw processException(e);
692 }
693 finally {
694 closeSession(session);
695 }
696 }
697
698 if (result instanceof List<?>) {
699 return null;
700 }
701 else {
702 return (Company)result;
703 }
704 }
705
706
713 public Company removeByLogoId(long logoId)
714 throws NoSuchCompanyException, SystemException {
715 Company company = findByLogoId(logoId);
716
717 return remove(company);
718 }
719
720
727 public int countByLogoId(long logoId) throws SystemException {
728 FinderPath finderPath = FINDER_PATH_COUNT_BY_LOGOID;
729
730 Object[] finderArgs = new Object[] { logoId };
731
732 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
733 this);
734
735 if (count == null) {
736 StringBundler query = new StringBundler(2);
737
738 query.append(_SQL_COUNT_COMPANY_WHERE);
739
740 query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
741
742 String sql = query.toString();
743
744 Session session = null;
745
746 try {
747 session = openSession();
748
749 Query q = session.createQuery(sql);
750
751 QueryPos qPos = QueryPos.getInstance(q);
752
753 qPos.add(logoId);
754
755 count = (Long)q.uniqueResult();
756
757 FinderCacheUtil.putResult(finderPath, finderArgs, count);
758 }
759 catch (Exception e) {
760 FinderCacheUtil.removeResult(finderPath, finderArgs);
761
762 throw processException(e);
763 }
764 finally {
765 closeSession(session);
766 }
767 }
768
769 return count.intValue();
770 }
771
772 private static final String _FINDER_COLUMN_LOGOID_LOGOID_2 = "company.logoId = ?";
773 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
774 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
775 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySystem",
776 new String[] {
777 Boolean.class.getName(),
778
779 Integer.class.getName(), Integer.class.getName(),
780 OrderByComparator.class.getName()
781 });
782 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM =
783 new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
784 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
785 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySystem",
786 new String[] { Boolean.class.getName() },
787 CompanyModelImpl.SYSTEM_COLUMN_BITMASK);
788 public static final FinderPath FINDER_PATH_COUNT_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
789 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
790 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySystem",
791 new String[] { Boolean.class.getName() });
792
793
800 public List<Company> findBySystem(boolean system) throws SystemException {
801 return findBySystem(system, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
802 }
803
804
817 public List<Company> findBySystem(boolean system, int start, int end)
818 throws SystemException {
819 return findBySystem(system, start, end, null);
820 }
821
822
836 public List<Company> findBySystem(boolean system, int start, int end,
837 OrderByComparator orderByComparator) throws SystemException {
838 boolean pagination = true;
839 FinderPath finderPath = null;
840 Object[] finderArgs = null;
841
842 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
843 (orderByComparator == null)) {
844 pagination = false;
845 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM;
846 finderArgs = new Object[] { system };
847 }
848 else {
849 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM;
850 finderArgs = new Object[] { system, start, end, orderByComparator };
851 }
852
853 List<Company> list = (List<Company>)FinderCacheUtil.getResult(finderPath,
854 finderArgs, this);
855
856 if ((list != null) && !list.isEmpty()) {
857 for (Company company : list) {
858 if ((system != company.getSystem())) {
859 list = null;
860
861 break;
862 }
863 }
864 }
865
866 if (list == null) {
867 StringBundler query = null;
868
869 if (orderByComparator != null) {
870 query = new StringBundler(3 +
871 (orderByComparator.getOrderByFields().length * 3));
872 }
873 else {
874 query = new StringBundler(3);
875 }
876
877 query.append(_SQL_SELECT_COMPANY_WHERE);
878
879 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
880
881 if (orderByComparator != null) {
882 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
883 orderByComparator);
884 }
885 else
886 if (pagination) {
887 query.append(CompanyModelImpl.ORDER_BY_JPQL);
888 }
889
890 String sql = query.toString();
891
892 Session session = null;
893
894 try {
895 session = openSession();
896
897 Query q = session.createQuery(sql);
898
899 QueryPos qPos = QueryPos.getInstance(q);
900
901 qPos.add(system);
902
903 if (!pagination) {
904 list = (List<Company>)QueryUtil.list(q, getDialect(),
905 start, end, false);
906
907 Collections.sort(list);
908
909 list = new UnmodifiableList<Company>(list);
910 }
911 else {
912 list = (List<Company>)QueryUtil.list(q, getDialect(),
913 start, end);
914 }
915
916 cacheResult(list);
917
918 FinderCacheUtil.putResult(finderPath, finderArgs, list);
919 }
920 catch (Exception e) {
921 FinderCacheUtil.removeResult(finderPath, finderArgs);
922
923 throw processException(e);
924 }
925 finally {
926 closeSession(session);
927 }
928 }
929
930 return list;
931 }
932
933
942 public Company findBySystem_First(boolean system,
943 OrderByComparator orderByComparator)
944 throws NoSuchCompanyException, SystemException {
945 Company company = fetchBySystem_First(system, orderByComparator);
946
947 if (company != null) {
948 return company;
949 }
950
951 StringBundler msg = new StringBundler(4);
952
953 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
954
955 msg.append("system=");
956 msg.append(system);
957
958 msg.append(StringPool.CLOSE_CURLY_BRACE);
959
960 throw new NoSuchCompanyException(msg.toString());
961 }
962
963
971 public Company fetchBySystem_First(boolean system,
972 OrderByComparator orderByComparator) throws SystemException {
973 List<Company> list = findBySystem(system, 0, 1, orderByComparator);
974
975 if (!list.isEmpty()) {
976 return list.get(0);
977 }
978
979 return null;
980 }
981
982
991 public Company findBySystem_Last(boolean system,
992 OrderByComparator orderByComparator)
993 throws NoSuchCompanyException, SystemException {
994 Company company = fetchBySystem_Last(system, orderByComparator);
995
996 if (company != null) {
997 return company;
998 }
999
1000 StringBundler msg = new StringBundler(4);
1001
1002 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1003
1004 msg.append("system=");
1005 msg.append(system);
1006
1007 msg.append(StringPool.CLOSE_CURLY_BRACE);
1008
1009 throw new NoSuchCompanyException(msg.toString());
1010 }
1011
1012
1020 public Company fetchBySystem_Last(boolean system,
1021 OrderByComparator orderByComparator) throws SystemException {
1022 int count = countBySystem(system);
1023
1024 List<Company> list = findBySystem(system, count - 1, count,
1025 orderByComparator);
1026
1027 if (!list.isEmpty()) {
1028 return list.get(0);
1029 }
1030
1031 return null;
1032 }
1033
1034
1044 public Company[] findBySystem_PrevAndNext(long companyId, boolean system,
1045 OrderByComparator orderByComparator)
1046 throws NoSuchCompanyException, SystemException {
1047 Company company = findByPrimaryKey(companyId);
1048
1049 Session session = null;
1050
1051 try {
1052 session = openSession();
1053
1054 Company[] array = new CompanyImpl[3];
1055
1056 array[0] = getBySystem_PrevAndNext(session, company, system,
1057 orderByComparator, true);
1058
1059 array[1] = company;
1060
1061 array[2] = getBySystem_PrevAndNext(session, company, system,
1062 orderByComparator, false);
1063
1064 return array;
1065 }
1066 catch (Exception e) {
1067 throw processException(e);
1068 }
1069 finally {
1070 closeSession(session);
1071 }
1072 }
1073
1074 protected Company getBySystem_PrevAndNext(Session session, Company company,
1075 boolean system, OrderByComparator orderByComparator, boolean previous) {
1076 StringBundler query = null;
1077
1078 if (orderByComparator != null) {
1079 query = new StringBundler(6 +
1080 (orderByComparator.getOrderByFields().length * 6));
1081 }
1082 else {
1083 query = new StringBundler(3);
1084 }
1085
1086 query.append(_SQL_SELECT_COMPANY_WHERE);
1087
1088 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1089
1090 if (orderByComparator != null) {
1091 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1092
1093 if (orderByConditionFields.length > 0) {
1094 query.append(WHERE_AND);
1095 }
1096
1097 for (int i = 0; i < orderByConditionFields.length; i++) {
1098 query.append(_ORDER_BY_ENTITY_ALIAS);
1099 query.append(orderByConditionFields[i]);
1100
1101 if ((i + 1) < orderByConditionFields.length) {
1102 if (orderByComparator.isAscending() ^ previous) {
1103 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1104 }
1105 else {
1106 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1107 }
1108 }
1109 else {
1110 if (orderByComparator.isAscending() ^ previous) {
1111 query.append(WHERE_GREATER_THAN);
1112 }
1113 else {
1114 query.append(WHERE_LESSER_THAN);
1115 }
1116 }
1117 }
1118
1119 query.append(ORDER_BY_CLAUSE);
1120
1121 String[] orderByFields = orderByComparator.getOrderByFields();
1122
1123 for (int i = 0; i < orderByFields.length; i++) {
1124 query.append(_ORDER_BY_ENTITY_ALIAS);
1125 query.append(orderByFields[i]);
1126
1127 if ((i + 1) < orderByFields.length) {
1128 if (orderByComparator.isAscending() ^ previous) {
1129 query.append(ORDER_BY_ASC_HAS_NEXT);
1130 }
1131 else {
1132 query.append(ORDER_BY_DESC_HAS_NEXT);
1133 }
1134 }
1135 else {
1136 if (orderByComparator.isAscending() ^ previous) {
1137 query.append(ORDER_BY_ASC);
1138 }
1139 else {
1140 query.append(ORDER_BY_DESC);
1141 }
1142 }
1143 }
1144 }
1145 else {
1146 query.append(CompanyModelImpl.ORDER_BY_JPQL);
1147 }
1148
1149 String sql = query.toString();
1150
1151 Query q = session.createQuery(sql);
1152
1153 q.setFirstResult(0);
1154 q.setMaxResults(2);
1155
1156 QueryPos qPos = QueryPos.getInstance(q);
1157
1158 qPos.add(system);
1159
1160 if (orderByComparator != null) {
1161 Object[] values = orderByComparator.getOrderByConditionValues(company);
1162
1163 for (Object value : values) {
1164 qPos.add(value);
1165 }
1166 }
1167
1168 List<Company> list = q.list();
1169
1170 if (list.size() == 2) {
1171 return list.get(1);
1172 }
1173 else {
1174 return null;
1175 }
1176 }
1177
1178
1184 public void removeBySystem(boolean system) throws SystemException {
1185 for (Company company : findBySystem(system, QueryUtil.ALL_POS,
1186 QueryUtil.ALL_POS, null)) {
1187 remove(company);
1188 }
1189 }
1190
1191
1198 public int countBySystem(boolean system) throws SystemException {
1199 FinderPath finderPath = FINDER_PATH_COUNT_BY_SYSTEM;
1200
1201 Object[] finderArgs = new Object[] { system };
1202
1203 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1204 this);
1205
1206 if (count == null) {
1207 StringBundler query = new StringBundler(2);
1208
1209 query.append(_SQL_COUNT_COMPANY_WHERE);
1210
1211 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1212
1213 String sql = query.toString();
1214
1215 Session session = null;
1216
1217 try {
1218 session = openSession();
1219
1220 Query q = session.createQuery(sql);
1221
1222 QueryPos qPos = QueryPos.getInstance(q);
1223
1224 qPos.add(system);
1225
1226 count = (Long)q.uniqueResult();
1227
1228 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1229 }
1230 catch (Exception e) {
1231 FinderCacheUtil.removeResult(finderPath, finderArgs);
1232
1233 throw processException(e);
1234 }
1235 finally {
1236 closeSession(session);
1237 }
1238 }
1239
1240 return count.intValue();
1241 }
1242
1243 private static final String _FINDER_COLUMN_SYSTEM_SYSTEM_2 = "company.system = ?";
1244
1245
1250 public void cacheResult(Company company) {
1251 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1252 CompanyImpl.class, company.getPrimaryKey(), company);
1253
1254 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
1255 new Object[] { company.getWebId() }, company);
1256
1257 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
1258 new Object[] { company.getMx() }, company);
1259
1260 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
1261 new Object[] { company.getLogoId() }, company);
1262
1263 company.resetOriginalValues();
1264 }
1265
1266
1271 public void cacheResult(List<Company> companies) {
1272 for (Company company : companies) {
1273 if (EntityCacheUtil.getResult(
1274 CompanyModelImpl.ENTITY_CACHE_ENABLED,
1275 CompanyImpl.class, company.getPrimaryKey()) == null) {
1276 cacheResult(company);
1277 }
1278 else {
1279 company.resetOriginalValues();
1280 }
1281 }
1282 }
1283
1284
1291 @Override
1292 public void clearCache() {
1293 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1294 CacheRegistryUtil.clear(CompanyImpl.class.getName());
1295 }
1296
1297 EntityCacheUtil.clearCache(CompanyImpl.class.getName());
1298
1299 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1301 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1302 }
1303
1304
1311 @Override
1312 public void clearCache(Company company) {
1313 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1314 CompanyImpl.class, company.getPrimaryKey());
1315
1316 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1317 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1318
1319 clearUniqueFindersCache(company);
1320 }
1321
1322 @Override
1323 public void clearCache(List<Company> companies) {
1324 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1325 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1326
1327 for (Company company : companies) {
1328 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1329 CompanyImpl.class, company.getPrimaryKey());
1330
1331 clearUniqueFindersCache(company);
1332 }
1333 }
1334
1335 protected void cacheUniqueFindersCache(Company company) {
1336 if (company.isNew()) {
1337 Object[] args = new Object[] { company.getWebId() };
1338
1339 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1340 Long.valueOf(1));
1341 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID, args, company);
1342
1343 args = new Object[] { company.getMx() };
1344
1345 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MX, args,
1346 Long.valueOf(1));
1347 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX, args, company);
1348
1349 args = new Object[] { company.getLogoId() };
1350
1351 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1352 Long.valueOf(1));
1353 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID, args, company);
1354 }
1355 else {
1356 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1357
1358 if ((companyModelImpl.getColumnBitmask() &
1359 FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1360 Object[] args = new Object[] { company.getWebId() };
1361
1362 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1363 Long.valueOf(1));
1364 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID, args,
1365 company);
1366 }
1367
1368 if ((companyModelImpl.getColumnBitmask() &
1369 FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1370 Object[] args = new Object[] { company.getMx() };
1371
1372 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MX, args,
1373 Long.valueOf(1));
1374 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX, args, company);
1375 }
1376
1377 if ((companyModelImpl.getColumnBitmask() &
1378 FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1379 Object[] args = new Object[] { company.getLogoId() };
1380
1381 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1382 Long.valueOf(1));
1383 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID, args,
1384 company);
1385 }
1386 }
1387 }
1388
1389 protected void clearUniqueFindersCache(Company company) {
1390 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1391
1392 Object[] args = new Object[] { company.getWebId() };
1393
1394 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1395 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1396
1397 if ((companyModelImpl.getColumnBitmask() &
1398 FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1399 args = new Object[] { companyModelImpl.getOriginalWebId() };
1400
1401 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1402 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1403 }
1404
1405 args = new Object[] { company.getMx() };
1406
1407 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1408 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1409
1410 if ((companyModelImpl.getColumnBitmask() &
1411 FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1412 args = new Object[] { companyModelImpl.getOriginalMx() };
1413
1414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1415 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1416 }
1417
1418 args = new Object[] { company.getLogoId() };
1419
1420 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1421 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1422
1423 if ((companyModelImpl.getColumnBitmask() &
1424 FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1425 args = new Object[] { companyModelImpl.getOriginalLogoId() };
1426
1427 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1428 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1429 }
1430 }
1431
1432
1438 public Company create(long companyId) {
1439 Company company = new CompanyImpl();
1440
1441 company.setNew(true);
1442 company.setPrimaryKey(companyId);
1443
1444 return company;
1445 }
1446
1447
1455 public Company remove(long companyId)
1456 throws NoSuchCompanyException, SystemException {
1457 return remove((Serializable)companyId);
1458 }
1459
1460
1468 @Override
1469 public Company remove(Serializable primaryKey)
1470 throws NoSuchCompanyException, SystemException {
1471 Session session = null;
1472
1473 try {
1474 session = openSession();
1475
1476 Company company = (Company)session.get(CompanyImpl.class, primaryKey);
1477
1478 if (company == null) {
1479 if (_log.isWarnEnabled()) {
1480 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1481 }
1482
1483 throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1484 primaryKey);
1485 }
1486
1487 return remove(company);
1488 }
1489 catch (NoSuchCompanyException nsee) {
1490 throw nsee;
1491 }
1492 catch (Exception e) {
1493 throw processException(e);
1494 }
1495 finally {
1496 closeSession(session);
1497 }
1498 }
1499
1500 @Override
1501 protected Company removeImpl(Company company) throws SystemException {
1502 company = toUnwrappedModel(company);
1503
1504 Session session = null;
1505
1506 try {
1507 session = openSession();
1508
1509 if (!session.contains(company)) {
1510 company = (Company)session.get(CompanyImpl.class,
1511 company.getPrimaryKeyObj());
1512 }
1513
1514 if (company != null) {
1515 session.delete(company);
1516 }
1517 }
1518 catch (Exception e) {
1519 throw processException(e);
1520 }
1521 finally {
1522 closeSession(session);
1523 }
1524
1525 if (company != null) {
1526 clearCache(company);
1527 }
1528
1529 return company;
1530 }
1531
1532 @Override
1533 public Company updateImpl(com.liferay.portal.model.Company company)
1534 throws SystemException {
1535 company = toUnwrappedModel(company);
1536
1537 boolean isNew = company.isNew();
1538
1539 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1540
1541 Session session = null;
1542
1543 try {
1544 session = openSession();
1545
1546 if (company.isNew()) {
1547 session.save(company);
1548
1549 company.setNew(false);
1550 }
1551 else {
1552 session.merge(company);
1553 }
1554 }
1555 catch (Exception e) {
1556 throw processException(e);
1557 }
1558 finally {
1559 closeSession(session);
1560 }
1561
1562 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1563
1564 if (isNew || !CompanyModelImpl.COLUMN_BITMASK_ENABLED) {
1565 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1566 }
1567
1568 else {
1569 if ((companyModelImpl.getColumnBitmask() &
1570 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM.getColumnBitmask()) != 0) {
1571 Object[] args = new Object[] {
1572 companyModelImpl.getOriginalSystem()
1573 };
1574
1575 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1576 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1577 args);
1578
1579 args = new Object[] { companyModelImpl.getSystem() };
1580
1581 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1582 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1583 args);
1584 }
1585 }
1586
1587 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1588 CompanyImpl.class, company.getPrimaryKey(), company);
1589
1590 clearUniqueFindersCache(company);
1591 cacheUniqueFindersCache(company);
1592
1593 return company;
1594 }
1595
1596 protected Company toUnwrappedModel(Company company) {
1597 if (company instanceof CompanyImpl) {
1598 return company;
1599 }
1600
1601 CompanyImpl companyImpl = new CompanyImpl();
1602
1603 companyImpl.setNew(company.isNew());
1604 companyImpl.setPrimaryKey(company.getPrimaryKey());
1605
1606 companyImpl.setCompanyId(company.getCompanyId());
1607 companyImpl.setAccountId(company.getAccountId());
1608 companyImpl.setWebId(company.getWebId());
1609 companyImpl.setKey(company.getKey());
1610 companyImpl.setMx(company.getMx());
1611 companyImpl.setHomeURL(company.getHomeURL());
1612 companyImpl.setLogoId(company.getLogoId());
1613 companyImpl.setSystem(company.isSystem());
1614 companyImpl.setMaxUsers(company.getMaxUsers());
1615 companyImpl.setActive(company.isActive());
1616
1617 return companyImpl;
1618 }
1619
1620
1628 @Override
1629 public Company findByPrimaryKey(Serializable primaryKey)
1630 throws NoSuchCompanyException, SystemException {
1631 Company company = fetchByPrimaryKey(primaryKey);
1632
1633 if (company == null) {
1634 if (_log.isWarnEnabled()) {
1635 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1636 }
1637
1638 throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1639 primaryKey);
1640 }
1641
1642 return company;
1643 }
1644
1645
1653 public Company findByPrimaryKey(long companyId)
1654 throws NoSuchCompanyException, SystemException {
1655 return findByPrimaryKey((Serializable)companyId);
1656 }
1657
1658
1665 @Override
1666 public Company fetchByPrimaryKey(Serializable primaryKey)
1667 throws SystemException {
1668 Company company = (Company)EntityCacheUtil.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1669 CompanyImpl.class, primaryKey);
1670
1671 if (company == _nullCompany) {
1672 return null;
1673 }
1674
1675 if (company == null) {
1676 Session session = null;
1677
1678 try {
1679 session = openSession();
1680
1681 company = (Company)session.get(CompanyImpl.class, primaryKey);
1682
1683 if (company != null) {
1684 cacheResult(company);
1685 }
1686 else {
1687 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1688 CompanyImpl.class, primaryKey, _nullCompany);
1689 }
1690 }
1691 catch (Exception e) {
1692 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1693 CompanyImpl.class, primaryKey);
1694
1695 throw processException(e);
1696 }
1697 finally {
1698 closeSession(session);
1699 }
1700 }
1701
1702 return company;
1703 }
1704
1705
1712 public Company fetchByPrimaryKey(long companyId) throws SystemException {
1713 return fetchByPrimaryKey((Serializable)companyId);
1714 }
1715
1716
1722 public List<Company> findAll() throws SystemException {
1723 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1724 }
1725
1726
1738 public List<Company> findAll(int start, int end) throws SystemException {
1739 return findAll(start, end, null);
1740 }
1741
1742
1755 public List<Company> findAll(int start, int end,
1756 OrderByComparator orderByComparator) throws SystemException {
1757 boolean pagination = true;
1758 FinderPath finderPath = null;
1759 Object[] finderArgs = null;
1760
1761 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1762 (orderByComparator == null)) {
1763 pagination = false;
1764 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1765 finderArgs = FINDER_ARGS_EMPTY;
1766 }
1767 else {
1768 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1769 finderArgs = new Object[] { start, end, orderByComparator };
1770 }
1771
1772 List<Company> list = (List<Company>)FinderCacheUtil.getResult(finderPath,
1773 finderArgs, this);
1774
1775 if (list == null) {
1776 StringBundler query = null;
1777 String sql = null;
1778
1779 if (orderByComparator != null) {
1780 query = new StringBundler(2 +
1781 (orderByComparator.getOrderByFields().length * 3));
1782
1783 query.append(_SQL_SELECT_COMPANY);
1784
1785 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1786 orderByComparator);
1787
1788 sql = query.toString();
1789 }
1790 else {
1791 sql = _SQL_SELECT_COMPANY;
1792
1793 if (pagination) {
1794 sql = sql.concat(CompanyModelImpl.ORDER_BY_JPQL);
1795 }
1796 }
1797
1798 Session session = null;
1799
1800 try {
1801 session = openSession();
1802
1803 Query q = session.createQuery(sql);
1804
1805 if (!pagination) {
1806 list = (List<Company>)QueryUtil.list(q, getDialect(),
1807 start, end, false);
1808
1809 Collections.sort(list);
1810
1811 list = new UnmodifiableList<Company>(list);
1812 }
1813 else {
1814 list = (List<Company>)QueryUtil.list(q, getDialect(),
1815 start, end);
1816 }
1817
1818 cacheResult(list);
1819
1820 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1821 }
1822 catch (Exception e) {
1823 FinderCacheUtil.removeResult(finderPath, finderArgs);
1824
1825 throw processException(e);
1826 }
1827 finally {
1828 closeSession(session);
1829 }
1830 }
1831
1832 return list;
1833 }
1834
1835
1840 public void removeAll() throws SystemException {
1841 for (Company company : findAll()) {
1842 remove(company);
1843 }
1844 }
1845
1846
1852 public int countAll() throws SystemException {
1853 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1854 FINDER_ARGS_EMPTY, this);
1855
1856 if (count == null) {
1857 Session session = null;
1858
1859 try {
1860 session = openSession();
1861
1862 Query q = session.createQuery(_SQL_COUNT_COMPANY);
1863
1864 count = (Long)q.uniqueResult();
1865
1866 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1867 FINDER_ARGS_EMPTY, count);
1868 }
1869 catch (Exception e) {
1870 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1871 FINDER_ARGS_EMPTY);
1872
1873 throw processException(e);
1874 }
1875 finally {
1876 closeSession(session);
1877 }
1878 }
1879
1880 return count.intValue();
1881 }
1882
1883
1886 public void afterPropertiesSet() {
1887 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1888 com.liferay.portal.util.PropsUtil.get(
1889 "value.object.listener.com.liferay.portal.model.Company")));
1890
1891 if (listenerClassNames.length > 0) {
1892 try {
1893 List<ModelListener<Company>> listenersList = new ArrayList<ModelListener<Company>>();
1894
1895 for (String listenerClassName : listenerClassNames) {
1896 listenersList.add((ModelListener<Company>)InstanceFactory.newInstance(
1897 listenerClassName));
1898 }
1899
1900 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1901 }
1902 catch (Exception e) {
1903 _log.error(e);
1904 }
1905 }
1906 }
1907
1908 public void destroy() {
1909 EntityCacheUtil.removeCache(CompanyImpl.class.getName());
1910 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1911 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1912 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1913 }
1914
1915 private static final String _SQL_SELECT_COMPANY = "SELECT company FROM Company company";
1916 private static final String _SQL_SELECT_COMPANY_WHERE = "SELECT company FROM Company company WHERE ";
1917 private static final String _SQL_COUNT_COMPANY = "SELECT COUNT(company) FROM Company company";
1918 private static final String _SQL_COUNT_COMPANY_WHERE = "SELECT COUNT(company) FROM Company company WHERE ";
1919 private static final String _ORDER_BY_ENTITY_ALIAS = "company.";
1920 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Company exists with the primary key ";
1921 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Company exists with the key {";
1922 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1923 private static Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
1924 private static Company _nullCompany = new CompanyImpl() {
1925 @Override
1926 public Object clone() {
1927 return this;
1928 }
1929
1930 @Override
1931 public CacheModel<Company> toCacheModel() {
1932 return _nullCompanyCacheModel;
1933 }
1934 };
1935
1936 private static CacheModel<Company> _nullCompanyCacheModel = new CacheModel<Company>() {
1937 public Company toEntityModel() {
1938 return _nullCompany;
1939 }
1940 };
1941 }