001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchCompanyException;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
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.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.Company;
038 import com.liferay.portal.model.MVCCModel;
039 import com.liferay.portal.model.impl.CompanyImpl;
040 import com.liferay.portal.model.impl.CompanyModelImpl;
041 import com.liferay.portal.service.persistence.CompanyPersistence;
042
043 import java.io.Serializable;
044
045 import java.util.Collections;
046 import java.util.HashMap;
047 import java.util.HashSet;
048 import java.util.Iterator;
049 import java.util.List;
050 import java.util.Map;
051 import java.util.Set;
052
053
065 @ProviderType
066 public class CompanyPersistenceImpl extends BasePersistenceImpl<Company>
067 implements CompanyPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = CompanyImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
079 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
082 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
085 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_FETCH_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
088 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
089 FINDER_CLASS_NAME_ENTITY, "fetchByWebId",
090 new String[] { String.class.getName() },
091 CompanyModelImpl.WEBID_COLUMN_BITMASK);
092 public static final FinderPath FINDER_PATH_COUNT_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
093 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByWebId",
095 new String[] { String.class.getName() });
096
097
104 @Override
105 public Company findByWebId(String webId) throws NoSuchCompanyException {
106 Company company = fetchByWebId(webId);
107
108 if (company == null) {
109 StringBundler msg = new StringBundler(4);
110
111 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
112
113 msg.append("webId=");
114 msg.append(webId);
115
116 msg.append(StringPool.CLOSE_CURLY_BRACE);
117
118 if (_log.isWarnEnabled()) {
119 _log.warn(msg.toString());
120 }
121
122 throw new NoSuchCompanyException(msg.toString());
123 }
124
125 return company;
126 }
127
128
134 @Override
135 public Company fetchByWebId(String webId) {
136 return fetchByWebId(webId, true);
137 }
138
139
146 @Override
147 public Company fetchByWebId(String webId, boolean retrieveFromCache) {
148 Object[] finderArgs = new Object[] { webId };
149
150 Object result = null;
151
152 if (retrieveFromCache) {
153 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_WEBID,
154 finderArgs, this);
155 }
156
157 if (result instanceof Company) {
158 Company company = (Company)result;
159
160 if (!Validator.equals(webId, company.getWebId())) {
161 result = null;
162 }
163 }
164
165 if (result == null) {
166 StringBundler query = new StringBundler(3);
167
168 query.append(_SQL_SELECT_COMPANY_WHERE);
169
170 boolean bindWebId = false;
171
172 if (webId == null) {
173 query.append(_FINDER_COLUMN_WEBID_WEBID_1);
174 }
175 else if (webId.equals(StringPool.BLANK)) {
176 query.append(_FINDER_COLUMN_WEBID_WEBID_3);
177 }
178 else {
179 bindWebId = true;
180
181 query.append(_FINDER_COLUMN_WEBID_WEBID_2);
182 }
183
184 String sql = query.toString();
185
186 Session session = null;
187
188 try {
189 session = openSession();
190
191 Query q = session.createQuery(sql);
192
193 QueryPos qPos = QueryPos.getInstance(q);
194
195 if (bindWebId) {
196 qPos.add(webId);
197 }
198
199 List<Company> list = q.list();
200
201 if (list.isEmpty()) {
202 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
203 finderArgs, list);
204 }
205 else {
206 Company company = list.get(0);
207
208 result = company;
209
210 cacheResult(company);
211
212 if ((company.getWebId() == null) ||
213 !company.getWebId().equals(webId)) {
214 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
215 finderArgs, company);
216 }
217 }
218 }
219 catch (Exception e) {
220 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
221 finderArgs);
222
223 throw processException(e);
224 }
225 finally {
226 closeSession(session);
227 }
228 }
229
230 if (result instanceof List<?>) {
231 return null;
232 }
233 else {
234 return (Company)result;
235 }
236 }
237
238
244 @Override
245 public Company removeByWebId(String webId) throws NoSuchCompanyException {
246 Company company = findByWebId(webId);
247
248 return remove(company);
249 }
250
251
257 @Override
258 public int countByWebId(String webId) {
259 FinderPath finderPath = FINDER_PATH_COUNT_BY_WEBID;
260
261 Object[] finderArgs = new Object[] { webId };
262
263 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
264 this);
265
266 if (count == null) {
267 StringBundler query = new StringBundler(2);
268
269 query.append(_SQL_COUNT_COMPANY_WHERE);
270
271 boolean bindWebId = false;
272
273 if (webId == null) {
274 query.append(_FINDER_COLUMN_WEBID_WEBID_1);
275 }
276 else if (webId.equals(StringPool.BLANK)) {
277 query.append(_FINDER_COLUMN_WEBID_WEBID_3);
278 }
279 else {
280 bindWebId = true;
281
282 query.append(_FINDER_COLUMN_WEBID_WEBID_2);
283 }
284
285 String sql = query.toString();
286
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 Query q = session.createQuery(sql);
293
294 QueryPos qPos = QueryPos.getInstance(q);
295
296 if (bindWebId) {
297 qPos.add(webId);
298 }
299
300 count = (Long)q.uniqueResult();
301
302 FinderCacheUtil.putResult(finderPath, finderArgs, count);
303 }
304 catch (Exception e) {
305 FinderCacheUtil.removeResult(finderPath, finderArgs);
306
307 throw processException(e);
308 }
309 finally {
310 closeSession(session);
311 }
312 }
313
314 return count.intValue();
315 }
316
317 private static final String _FINDER_COLUMN_WEBID_WEBID_1 = "company.webId IS NULL";
318 private static final String _FINDER_COLUMN_WEBID_WEBID_2 = "company.webId = ?";
319 private static final String _FINDER_COLUMN_WEBID_WEBID_3 = "(company.webId IS NULL OR company.webId = '')";
320 public static final FinderPath FINDER_PATH_FETCH_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
321 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
322 FINDER_CLASS_NAME_ENTITY, "fetchByMx",
323 new String[] { String.class.getName() },
324 CompanyModelImpl.MX_COLUMN_BITMASK);
325 public static final FinderPath FINDER_PATH_COUNT_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
326 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
327 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMx",
328 new String[] { String.class.getName() });
329
330
337 @Override
338 public Company findByMx(String mx) throws NoSuchCompanyException {
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
367 @Override
368 public Company fetchByMx(String mx) {
369 return fetchByMx(mx, true);
370 }
371
372
379 @Override
380 public Company fetchByMx(String mx, boolean retrieveFromCache) {
381 Object[] finderArgs = new Object[] { mx };
382
383 Object result = null;
384
385 if (retrieveFromCache) {
386 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MX,
387 finderArgs, this);
388 }
389
390 if (result instanceof Company) {
391 Company company = (Company)result;
392
393 if (!Validator.equals(mx, company.getMx())) {
394 result = null;
395 }
396 }
397
398 if (result == null) {
399 StringBundler query = new StringBundler(3);
400
401 query.append(_SQL_SELECT_COMPANY_WHERE);
402
403 boolean bindMx = false;
404
405 if (mx == null) {
406 query.append(_FINDER_COLUMN_MX_MX_1);
407 }
408 else if (mx.equals(StringPool.BLANK)) {
409 query.append(_FINDER_COLUMN_MX_MX_3);
410 }
411 else {
412 bindMx = true;
413
414 query.append(_FINDER_COLUMN_MX_MX_2);
415 }
416
417 String sql = query.toString();
418
419 Session session = null;
420
421 try {
422 session = openSession();
423
424 Query q = session.createQuery(sql);
425
426 QueryPos qPos = QueryPos.getInstance(q);
427
428 if (bindMx) {
429 qPos.add(mx);
430 }
431
432 List<Company> list = q.list();
433
434 if (list.isEmpty()) {
435 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
436 finderArgs, list);
437 }
438 else {
439 if ((list.size() > 1) && _log.isWarnEnabled()) {
440 _log.warn(
441 "CompanyPersistenceImpl.fetchByMx(String, boolean) with parameters (" +
442 StringUtil.merge(finderArgs) +
443 ") 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.");
444 }
445
446 Company company = list.get(0);
447
448 result = company;
449
450 cacheResult(company);
451
452 if ((company.getMx() == null) ||
453 !company.getMx().equals(mx)) {
454 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
455 finderArgs, company);
456 }
457 }
458 }
459 catch (Exception e) {
460 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, finderArgs);
461
462 throw processException(e);
463 }
464 finally {
465 closeSession(session);
466 }
467 }
468
469 if (result instanceof List<?>) {
470 return null;
471 }
472 else {
473 return (Company)result;
474 }
475 }
476
477
483 @Override
484 public Company removeByMx(String mx) throws NoSuchCompanyException {
485 Company company = findByMx(mx);
486
487 return remove(company);
488 }
489
490
496 @Override
497 public int countByMx(String mx) {
498 FinderPath finderPath = FINDER_PATH_COUNT_BY_MX;
499
500 Object[] finderArgs = new Object[] { mx };
501
502 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
503 this);
504
505 if (count == null) {
506 StringBundler query = new StringBundler(2);
507
508 query.append(_SQL_COUNT_COMPANY_WHERE);
509
510 boolean bindMx = false;
511
512 if (mx == null) {
513 query.append(_FINDER_COLUMN_MX_MX_1);
514 }
515 else if (mx.equals(StringPool.BLANK)) {
516 query.append(_FINDER_COLUMN_MX_MX_3);
517 }
518 else {
519 bindMx = true;
520
521 query.append(_FINDER_COLUMN_MX_MX_2);
522 }
523
524 String sql = query.toString();
525
526 Session session = null;
527
528 try {
529 session = openSession();
530
531 Query q = session.createQuery(sql);
532
533 QueryPos qPos = QueryPos.getInstance(q);
534
535 if (bindMx) {
536 qPos.add(mx);
537 }
538
539 count = (Long)q.uniqueResult();
540
541 FinderCacheUtil.putResult(finderPath, finderArgs, count);
542 }
543 catch (Exception e) {
544 FinderCacheUtil.removeResult(finderPath, finderArgs);
545
546 throw processException(e);
547 }
548 finally {
549 closeSession(session);
550 }
551 }
552
553 return count.intValue();
554 }
555
556 private static final String _FINDER_COLUMN_MX_MX_1 = "company.mx IS NULL";
557 private static final String _FINDER_COLUMN_MX_MX_2 = "company.mx = ?";
558 private static final String _FINDER_COLUMN_MX_MX_3 = "(company.mx IS NULL OR company.mx = '')";
559 public static final FinderPath FINDER_PATH_FETCH_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
560 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
561 FINDER_CLASS_NAME_ENTITY, "fetchByLogoId",
562 new String[] { Long.class.getName() },
563 CompanyModelImpl.LOGOID_COLUMN_BITMASK);
564 public static final FinderPath FINDER_PATH_COUNT_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
565 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
566 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLogoId",
567 new String[] { Long.class.getName() });
568
569
576 @Override
577 public Company findByLogoId(long logoId) throws NoSuchCompanyException {
578 Company company = fetchByLogoId(logoId);
579
580 if (company == null) {
581 StringBundler msg = new StringBundler(4);
582
583 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
584
585 msg.append("logoId=");
586 msg.append(logoId);
587
588 msg.append(StringPool.CLOSE_CURLY_BRACE);
589
590 if (_log.isWarnEnabled()) {
591 _log.warn(msg.toString());
592 }
593
594 throw new NoSuchCompanyException(msg.toString());
595 }
596
597 return company;
598 }
599
600
606 @Override
607 public Company fetchByLogoId(long logoId) {
608 return fetchByLogoId(logoId, true);
609 }
610
611
618 @Override
619 public Company fetchByLogoId(long logoId, boolean retrieveFromCache) {
620 Object[] finderArgs = new Object[] { logoId };
621
622 Object result = null;
623
624 if (retrieveFromCache) {
625 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LOGOID,
626 finderArgs, this);
627 }
628
629 if (result instanceof Company) {
630 Company company = (Company)result;
631
632 if ((logoId != company.getLogoId())) {
633 result = null;
634 }
635 }
636
637 if (result == null) {
638 StringBundler query = new StringBundler(3);
639
640 query.append(_SQL_SELECT_COMPANY_WHERE);
641
642 query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
643
644 String sql = query.toString();
645
646 Session session = null;
647
648 try {
649 session = openSession();
650
651 Query q = session.createQuery(sql);
652
653 QueryPos qPos = QueryPos.getInstance(q);
654
655 qPos.add(logoId);
656
657 List<Company> list = q.list();
658
659 if (list.isEmpty()) {
660 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
661 finderArgs, list);
662 }
663 else {
664 if ((list.size() > 1) && _log.isWarnEnabled()) {
665 _log.warn(
666 "CompanyPersistenceImpl.fetchByLogoId(long, boolean) with parameters (" +
667 StringUtil.merge(finderArgs) +
668 ") 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.");
669 }
670
671 Company company = list.get(0);
672
673 result = company;
674
675 cacheResult(company);
676
677 if ((company.getLogoId() != logoId)) {
678 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
679 finderArgs, company);
680 }
681 }
682 }
683 catch (Exception e) {
684 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
685 finderArgs);
686
687 throw processException(e);
688 }
689 finally {
690 closeSession(session);
691 }
692 }
693
694 if (result instanceof List<?>) {
695 return null;
696 }
697 else {
698 return (Company)result;
699 }
700 }
701
702
708 @Override
709 public Company removeByLogoId(long logoId) throws NoSuchCompanyException {
710 Company company = findByLogoId(logoId);
711
712 return remove(company);
713 }
714
715
721 @Override
722 public int countByLogoId(long logoId) {
723 FinderPath finderPath = FINDER_PATH_COUNT_BY_LOGOID;
724
725 Object[] finderArgs = new Object[] { logoId };
726
727 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
728 this);
729
730 if (count == null) {
731 StringBundler query = new StringBundler(2);
732
733 query.append(_SQL_COUNT_COMPANY_WHERE);
734
735 query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
736
737 String sql = query.toString();
738
739 Session session = null;
740
741 try {
742 session = openSession();
743
744 Query q = session.createQuery(sql);
745
746 QueryPos qPos = QueryPos.getInstance(q);
747
748 qPos.add(logoId);
749
750 count = (Long)q.uniqueResult();
751
752 FinderCacheUtil.putResult(finderPath, finderArgs, count);
753 }
754 catch (Exception e) {
755 FinderCacheUtil.removeResult(finderPath, finderArgs);
756
757 throw processException(e);
758 }
759 finally {
760 closeSession(session);
761 }
762 }
763
764 return count.intValue();
765 }
766
767 private static final String _FINDER_COLUMN_LOGOID_LOGOID_2 = "company.logoId = ?";
768 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
769 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
770 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySystem",
771 new String[] {
772 Boolean.class.getName(),
773
774 Integer.class.getName(), Integer.class.getName(),
775 OrderByComparator.class.getName()
776 });
777 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM =
778 new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
779 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
780 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySystem",
781 new String[] { Boolean.class.getName() },
782 CompanyModelImpl.SYSTEM_COLUMN_BITMASK);
783 public static final FinderPath FINDER_PATH_COUNT_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
784 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
785 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySystem",
786 new String[] { Boolean.class.getName() });
787
788
794 @Override
795 public List<Company> findBySystem(boolean system) {
796 return findBySystem(system, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
797 }
798
799
811 @Override
812 public List<Company> findBySystem(boolean system, int start, int end) {
813 return findBySystem(system, start, end, null);
814 }
815
816
829 @Override
830 public List<Company> findBySystem(boolean system, int start, int end,
831 OrderByComparator<Company> orderByComparator) {
832 boolean pagination = true;
833 FinderPath finderPath = null;
834 Object[] finderArgs = null;
835
836 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
837 (orderByComparator == null)) {
838 pagination = false;
839 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM;
840 finderArgs = new Object[] { system };
841 }
842 else {
843 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM;
844 finderArgs = new Object[] { system, start, end, orderByComparator };
845 }
846
847 List<Company> list = (List<Company>)FinderCacheUtil.getResult(finderPath,
848 finderArgs, this);
849
850 if ((list != null) && !list.isEmpty()) {
851 for (Company company : list) {
852 if ((system != company.getSystem())) {
853 list = null;
854
855 break;
856 }
857 }
858 }
859
860 if (list == null) {
861 StringBundler query = null;
862
863 if (orderByComparator != null) {
864 query = new StringBundler(3 +
865 (orderByComparator.getOrderByFields().length * 3));
866 }
867 else {
868 query = new StringBundler(3);
869 }
870
871 query.append(_SQL_SELECT_COMPANY_WHERE);
872
873 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
874
875 if (orderByComparator != null) {
876 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
877 orderByComparator);
878 }
879 else
880 if (pagination) {
881 query.append(CompanyModelImpl.ORDER_BY_JPQL);
882 }
883
884 String sql = query.toString();
885
886 Session session = null;
887
888 try {
889 session = openSession();
890
891 Query q = session.createQuery(sql);
892
893 QueryPos qPos = QueryPos.getInstance(q);
894
895 qPos.add(system);
896
897 if (!pagination) {
898 list = (List<Company>)QueryUtil.list(q, getDialect(),
899 start, end, false);
900
901 Collections.sort(list);
902
903 list = Collections.unmodifiableList(list);
904 }
905 else {
906 list = (List<Company>)QueryUtil.list(q, getDialect(),
907 start, end);
908 }
909
910 cacheResult(list);
911
912 FinderCacheUtil.putResult(finderPath, finderArgs, list);
913 }
914 catch (Exception e) {
915 FinderCacheUtil.removeResult(finderPath, finderArgs);
916
917 throw processException(e);
918 }
919 finally {
920 closeSession(session);
921 }
922 }
923
924 return list;
925 }
926
927
935 @Override
936 public Company findBySystem_First(boolean system,
937 OrderByComparator<Company> orderByComparator)
938 throws NoSuchCompanyException {
939 Company company = fetchBySystem_First(system, orderByComparator);
940
941 if (company != null) {
942 return company;
943 }
944
945 StringBundler msg = new StringBundler(4);
946
947 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
948
949 msg.append("system=");
950 msg.append(system);
951
952 msg.append(StringPool.CLOSE_CURLY_BRACE);
953
954 throw new NoSuchCompanyException(msg.toString());
955 }
956
957
964 @Override
965 public Company fetchBySystem_First(boolean system,
966 OrderByComparator<Company> orderByComparator) {
967 List<Company> list = findBySystem(system, 0, 1, orderByComparator);
968
969 if (!list.isEmpty()) {
970 return list.get(0);
971 }
972
973 return null;
974 }
975
976
984 @Override
985 public Company findBySystem_Last(boolean system,
986 OrderByComparator<Company> orderByComparator)
987 throws NoSuchCompanyException {
988 Company company = fetchBySystem_Last(system, orderByComparator);
989
990 if (company != null) {
991 return company;
992 }
993
994 StringBundler msg = new StringBundler(4);
995
996 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
997
998 msg.append("system=");
999 msg.append(system);
1000
1001 msg.append(StringPool.CLOSE_CURLY_BRACE);
1002
1003 throw new NoSuchCompanyException(msg.toString());
1004 }
1005
1006
1013 @Override
1014 public Company fetchBySystem_Last(boolean system,
1015 OrderByComparator<Company> orderByComparator) {
1016 int count = countBySystem(system);
1017
1018 if (count == 0) {
1019 return null;
1020 }
1021
1022 List<Company> list = findBySystem(system, count - 1, count,
1023 orderByComparator);
1024
1025 if (!list.isEmpty()) {
1026 return list.get(0);
1027 }
1028
1029 return null;
1030 }
1031
1032
1041 @Override
1042 public Company[] findBySystem_PrevAndNext(long companyId, boolean system,
1043 OrderByComparator<Company> orderByComparator)
1044 throws NoSuchCompanyException {
1045 Company company = findByPrimaryKey(companyId);
1046
1047 Session session = null;
1048
1049 try {
1050 session = openSession();
1051
1052 Company[] array = new CompanyImpl[3];
1053
1054 array[0] = getBySystem_PrevAndNext(session, company, system,
1055 orderByComparator, true);
1056
1057 array[1] = company;
1058
1059 array[2] = getBySystem_PrevAndNext(session, company, system,
1060 orderByComparator, false);
1061
1062 return array;
1063 }
1064 catch (Exception e) {
1065 throw processException(e);
1066 }
1067 finally {
1068 closeSession(session);
1069 }
1070 }
1071
1072 protected Company getBySystem_PrevAndNext(Session session, Company company,
1073 boolean system, OrderByComparator<Company> orderByComparator,
1074 boolean previous) {
1075 StringBundler query = null;
1076
1077 if (orderByComparator != null) {
1078 query = new StringBundler(6 +
1079 (orderByComparator.getOrderByFields().length * 6));
1080 }
1081 else {
1082 query = new StringBundler(3);
1083 }
1084
1085 query.append(_SQL_SELECT_COMPANY_WHERE);
1086
1087 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1088
1089 if (orderByComparator != null) {
1090 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1091
1092 if (orderByConditionFields.length > 0) {
1093 query.append(WHERE_AND);
1094 }
1095
1096 for (int i = 0; i < orderByConditionFields.length; i++) {
1097 query.append(_ORDER_BY_ENTITY_ALIAS);
1098 query.append(orderByConditionFields[i]);
1099
1100 if ((i + 1) < orderByConditionFields.length) {
1101 if (orderByComparator.isAscending() ^ previous) {
1102 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1103 }
1104 else {
1105 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1106 }
1107 }
1108 else {
1109 if (orderByComparator.isAscending() ^ previous) {
1110 query.append(WHERE_GREATER_THAN);
1111 }
1112 else {
1113 query.append(WHERE_LESSER_THAN);
1114 }
1115 }
1116 }
1117
1118 query.append(ORDER_BY_CLAUSE);
1119
1120 String[] orderByFields = orderByComparator.getOrderByFields();
1121
1122 for (int i = 0; i < orderByFields.length; i++) {
1123 query.append(_ORDER_BY_ENTITY_ALIAS);
1124 query.append(orderByFields[i]);
1125
1126 if ((i + 1) < orderByFields.length) {
1127 if (orderByComparator.isAscending() ^ previous) {
1128 query.append(ORDER_BY_ASC_HAS_NEXT);
1129 }
1130 else {
1131 query.append(ORDER_BY_DESC_HAS_NEXT);
1132 }
1133 }
1134 else {
1135 if (orderByComparator.isAscending() ^ previous) {
1136 query.append(ORDER_BY_ASC);
1137 }
1138 else {
1139 query.append(ORDER_BY_DESC);
1140 }
1141 }
1142 }
1143 }
1144 else {
1145 query.append(CompanyModelImpl.ORDER_BY_JPQL);
1146 }
1147
1148 String sql = query.toString();
1149
1150 Query q = session.createQuery(sql);
1151
1152 q.setFirstResult(0);
1153 q.setMaxResults(2);
1154
1155 QueryPos qPos = QueryPos.getInstance(q);
1156
1157 qPos.add(system);
1158
1159 if (orderByComparator != null) {
1160 Object[] values = orderByComparator.getOrderByConditionValues(company);
1161
1162 for (Object value : values) {
1163 qPos.add(value);
1164 }
1165 }
1166
1167 List<Company> list = q.list();
1168
1169 if (list.size() == 2) {
1170 return list.get(1);
1171 }
1172 else {
1173 return null;
1174 }
1175 }
1176
1177
1182 @Override
1183 public void removeBySystem(boolean system) {
1184 for (Company company : findBySystem(system, QueryUtil.ALL_POS,
1185 QueryUtil.ALL_POS, null)) {
1186 remove(company);
1187 }
1188 }
1189
1190
1196 @Override
1197 public int countBySystem(boolean system) {
1198 FinderPath finderPath = FINDER_PATH_COUNT_BY_SYSTEM;
1199
1200 Object[] finderArgs = new Object[] { system };
1201
1202 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1203 this);
1204
1205 if (count == null) {
1206 StringBundler query = new StringBundler(2);
1207
1208 query.append(_SQL_COUNT_COMPANY_WHERE);
1209
1210 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1211
1212 String sql = query.toString();
1213
1214 Session session = null;
1215
1216 try {
1217 session = openSession();
1218
1219 Query q = session.createQuery(sql);
1220
1221 QueryPos qPos = QueryPos.getInstance(q);
1222
1223 qPos.add(system);
1224
1225 count = (Long)q.uniqueResult();
1226
1227 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1228 }
1229 catch (Exception e) {
1230 FinderCacheUtil.removeResult(finderPath, finderArgs);
1231
1232 throw processException(e);
1233 }
1234 finally {
1235 closeSession(session);
1236 }
1237 }
1238
1239 return count.intValue();
1240 }
1241
1242 private static final String _FINDER_COLUMN_SYSTEM_SYSTEM_2 = "company.system = ?";
1243
1244 public CompanyPersistenceImpl() {
1245 setModelClass(Company.class);
1246 }
1247
1248
1253 @Override
1254 public void cacheResult(Company company) {
1255 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1256 CompanyImpl.class, company.getPrimaryKey(), company);
1257
1258 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
1259 new Object[] { company.getWebId() }, company);
1260
1261 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
1262 new Object[] { company.getMx() }, company);
1263
1264 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
1265 new Object[] { company.getLogoId() }, company);
1266
1267 company.resetOriginalValues();
1268 }
1269
1270
1275 @Override
1276 public void cacheResult(List<Company> companies) {
1277 for (Company company : companies) {
1278 if (EntityCacheUtil.getResult(
1279 CompanyModelImpl.ENTITY_CACHE_ENABLED,
1280 CompanyImpl.class, company.getPrimaryKey()) == null) {
1281 cacheResult(company);
1282 }
1283 else {
1284 company.resetOriginalValues();
1285 }
1286 }
1287 }
1288
1289
1296 @Override
1297 public void clearCache() {
1298 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1299 CacheRegistryUtil.clear(CompanyImpl.class.getName());
1300 }
1301
1302 EntityCacheUtil.clearCache(CompanyImpl.class);
1303
1304 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1305 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1306 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1307 }
1308
1309
1316 @Override
1317 public void clearCache(Company company) {
1318 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1319 CompanyImpl.class, company.getPrimaryKey());
1320
1321 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1322 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1323
1324 clearUniqueFindersCache(company);
1325 }
1326
1327 @Override
1328 public void clearCache(List<Company> companies) {
1329 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1330 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1331
1332 for (Company company : companies) {
1333 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1334 CompanyImpl.class, company.getPrimaryKey());
1335
1336 clearUniqueFindersCache(company);
1337 }
1338 }
1339
1340 protected void cacheUniqueFindersCache(Company company) {
1341 if (company.isNew()) {
1342 Object[] args = new Object[] { company.getWebId() };
1343
1344 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1345 Long.valueOf(1));
1346 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID, args, company);
1347
1348 args = new Object[] { company.getMx() };
1349
1350 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MX, args,
1351 Long.valueOf(1));
1352 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX, args, company);
1353
1354 args = new Object[] { company.getLogoId() };
1355
1356 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1357 Long.valueOf(1));
1358 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID, args, company);
1359 }
1360 else {
1361 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1362
1363 if ((companyModelImpl.getColumnBitmask() &
1364 FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1365 Object[] args = new Object[] { company.getWebId() };
1366
1367 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1368 Long.valueOf(1));
1369 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID, args,
1370 company);
1371 }
1372
1373 if ((companyModelImpl.getColumnBitmask() &
1374 FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1375 Object[] args = new Object[] { company.getMx() };
1376
1377 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MX, args,
1378 Long.valueOf(1));
1379 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX, args, company);
1380 }
1381
1382 if ((companyModelImpl.getColumnBitmask() &
1383 FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1384 Object[] args = new Object[] { company.getLogoId() };
1385
1386 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1387 Long.valueOf(1));
1388 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID, args,
1389 company);
1390 }
1391 }
1392 }
1393
1394 protected void clearUniqueFindersCache(Company company) {
1395 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1396
1397 Object[] args = new Object[] { company.getWebId() };
1398
1399 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1400 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1401
1402 if ((companyModelImpl.getColumnBitmask() &
1403 FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1404 args = new Object[] { companyModelImpl.getOriginalWebId() };
1405
1406 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1407 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1408 }
1409
1410 args = new Object[] { company.getMx() };
1411
1412 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1413 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1414
1415 if ((companyModelImpl.getColumnBitmask() &
1416 FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1417 args = new Object[] { companyModelImpl.getOriginalMx() };
1418
1419 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1420 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1421 }
1422
1423 args = new Object[] { company.getLogoId() };
1424
1425 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1426 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1427
1428 if ((companyModelImpl.getColumnBitmask() &
1429 FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1430 args = new Object[] { companyModelImpl.getOriginalLogoId() };
1431
1432 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1433 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1434 }
1435 }
1436
1437
1443 @Override
1444 public Company create(long companyId) {
1445 Company company = new CompanyImpl();
1446
1447 company.setNew(true);
1448 company.setPrimaryKey(companyId);
1449
1450 return company;
1451 }
1452
1453
1460 @Override
1461 public Company remove(long companyId) throws NoSuchCompanyException {
1462 return remove((Serializable)companyId);
1463 }
1464
1465
1472 @Override
1473 public Company remove(Serializable primaryKey)
1474 throws NoSuchCompanyException {
1475 Session session = null;
1476
1477 try {
1478 session = openSession();
1479
1480 Company company = (Company)session.get(CompanyImpl.class, primaryKey);
1481
1482 if (company == null) {
1483 if (_log.isWarnEnabled()) {
1484 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1485 }
1486
1487 throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1488 primaryKey);
1489 }
1490
1491 return remove(company);
1492 }
1493 catch (NoSuchCompanyException nsee) {
1494 throw nsee;
1495 }
1496 catch (Exception e) {
1497 throw processException(e);
1498 }
1499 finally {
1500 closeSession(session);
1501 }
1502 }
1503
1504 @Override
1505 protected Company removeImpl(Company company) {
1506 company = toUnwrappedModel(company);
1507
1508 Session session = null;
1509
1510 try {
1511 session = openSession();
1512
1513 if (!session.contains(company)) {
1514 company = (Company)session.get(CompanyImpl.class,
1515 company.getPrimaryKeyObj());
1516 }
1517
1518 if (company != null) {
1519 session.delete(company);
1520 }
1521 }
1522 catch (Exception e) {
1523 throw processException(e);
1524 }
1525 finally {
1526 closeSession(session);
1527 }
1528
1529 if (company != null) {
1530 clearCache(company);
1531 }
1532
1533 return company;
1534 }
1535
1536 @Override
1537 public Company updateImpl(com.liferay.portal.model.Company company) {
1538 company = toUnwrappedModel(company);
1539
1540 boolean isNew = company.isNew();
1541
1542 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1543
1544 Session session = null;
1545
1546 try {
1547 session = openSession();
1548
1549 if (company.isNew()) {
1550 session.save(company);
1551
1552 company.setNew(false);
1553 }
1554 else {
1555 session.merge(company);
1556 }
1557 }
1558 catch (Exception e) {
1559 throw processException(e);
1560 }
1561 finally {
1562 closeSession(session);
1563 }
1564
1565 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1566
1567 if (isNew || !CompanyModelImpl.COLUMN_BITMASK_ENABLED) {
1568 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1569 }
1570
1571 else {
1572 if ((companyModelImpl.getColumnBitmask() &
1573 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM.getColumnBitmask()) != 0) {
1574 Object[] args = new Object[] {
1575 companyModelImpl.getOriginalSystem()
1576 };
1577
1578 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1579 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1580 args);
1581
1582 args = new Object[] { companyModelImpl.getSystem() };
1583
1584 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1585 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1586 args);
1587 }
1588 }
1589
1590 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1591 CompanyImpl.class, company.getPrimaryKey(), company, false);
1592
1593 clearUniqueFindersCache(company);
1594 cacheUniqueFindersCache(company);
1595
1596 company.resetOriginalValues();
1597
1598 return company;
1599 }
1600
1601 protected Company toUnwrappedModel(Company company) {
1602 if (company instanceof CompanyImpl) {
1603 return company;
1604 }
1605
1606 CompanyImpl companyImpl = new CompanyImpl();
1607
1608 companyImpl.setNew(company.isNew());
1609 companyImpl.setPrimaryKey(company.getPrimaryKey());
1610
1611 companyImpl.setMvccVersion(company.getMvccVersion());
1612 companyImpl.setCompanyId(company.getCompanyId());
1613 companyImpl.setAccountId(company.getAccountId());
1614 companyImpl.setWebId(company.getWebId());
1615 companyImpl.setKey(company.getKey());
1616 companyImpl.setMx(company.getMx());
1617 companyImpl.setHomeURL(company.getHomeURL());
1618 companyImpl.setLogoId(company.getLogoId());
1619 companyImpl.setSystem(company.isSystem());
1620 companyImpl.setMaxUsers(company.getMaxUsers());
1621 companyImpl.setActive(company.isActive());
1622
1623 return companyImpl;
1624 }
1625
1626
1633 @Override
1634 public Company findByPrimaryKey(Serializable primaryKey)
1635 throws NoSuchCompanyException {
1636 Company company = fetchByPrimaryKey(primaryKey);
1637
1638 if (company == null) {
1639 if (_log.isWarnEnabled()) {
1640 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1641 }
1642
1643 throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1644 primaryKey);
1645 }
1646
1647 return company;
1648 }
1649
1650
1657 @Override
1658 public Company findByPrimaryKey(long companyId)
1659 throws NoSuchCompanyException {
1660 return findByPrimaryKey((Serializable)companyId);
1661 }
1662
1663
1669 @Override
1670 public Company fetchByPrimaryKey(Serializable primaryKey) {
1671 Company company = (Company)EntityCacheUtil.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1672 CompanyImpl.class, primaryKey);
1673
1674 if (company == _nullCompany) {
1675 return null;
1676 }
1677
1678 if (company == null) {
1679 Session session = null;
1680
1681 try {
1682 session = openSession();
1683
1684 company = (Company)session.get(CompanyImpl.class, primaryKey);
1685
1686 if (company != null) {
1687 cacheResult(company);
1688 }
1689 else {
1690 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1691 CompanyImpl.class, primaryKey, _nullCompany);
1692 }
1693 }
1694 catch (Exception e) {
1695 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1696 CompanyImpl.class, primaryKey);
1697
1698 throw processException(e);
1699 }
1700 finally {
1701 closeSession(session);
1702 }
1703 }
1704
1705 return company;
1706 }
1707
1708
1714 @Override
1715 public Company fetchByPrimaryKey(long companyId) {
1716 return fetchByPrimaryKey((Serializable)companyId);
1717 }
1718
1719 @Override
1720 public Map<Serializable, Company> fetchByPrimaryKeys(
1721 Set<Serializable> primaryKeys) {
1722 if (primaryKeys.isEmpty()) {
1723 return Collections.emptyMap();
1724 }
1725
1726 Map<Serializable, Company> map = new HashMap<Serializable, Company>();
1727
1728 if (primaryKeys.size() == 1) {
1729 Iterator<Serializable> iterator = primaryKeys.iterator();
1730
1731 Serializable primaryKey = iterator.next();
1732
1733 Company company = fetchByPrimaryKey(primaryKey);
1734
1735 if (company != null) {
1736 map.put(primaryKey, company);
1737 }
1738
1739 return map;
1740 }
1741
1742 Set<Serializable> uncachedPrimaryKeys = null;
1743
1744 for (Serializable primaryKey : primaryKeys) {
1745 Company company = (Company)EntityCacheUtil.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1746 CompanyImpl.class, primaryKey);
1747
1748 if (company == null) {
1749 if (uncachedPrimaryKeys == null) {
1750 uncachedPrimaryKeys = new HashSet<Serializable>();
1751 }
1752
1753 uncachedPrimaryKeys.add(primaryKey);
1754 }
1755 else {
1756 map.put(primaryKey, company);
1757 }
1758 }
1759
1760 if (uncachedPrimaryKeys == null) {
1761 return map;
1762 }
1763
1764 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1765 1);
1766
1767 query.append(_SQL_SELECT_COMPANY_WHERE_PKS_IN);
1768
1769 for (Serializable primaryKey : uncachedPrimaryKeys) {
1770 query.append(String.valueOf(primaryKey));
1771
1772 query.append(StringPool.COMMA);
1773 }
1774
1775 query.setIndex(query.index() - 1);
1776
1777 query.append(StringPool.CLOSE_PARENTHESIS);
1778
1779 String sql = query.toString();
1780
1781 Session session = null;
1782
1783 try {
1784 session = openSession();
1785
1786 Query q = session.createQuery(sql);
1787
1788 for (Company company : (List<Company>)q.list()) {
1789 map.put(company.getPrimaryKeyObj(), company);
1790
1791 cacheResult(company);
1792
1793 uncachedPrimaryKeys.remove(company.getPrimaryKeyObj());
1794 }
1795
1796 for (Serializable primaryKey : uncachedPrimaryKeys) {
1797 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1798 CompanyImpl.class, primaryKey, _nullCompany);
1799 }
1800 }
1801 catch (Exception e) {
1802 throw processException(e);
1803 }
1804 finally {
1805 closeSession(session);
1806 }
1807
1808 return map;
1809 }
1810
1811
1816 @Override
1817 public List<Company> findAll() {
1818 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1819 }
1820
1821
1832 @Override
1833 public List<Company> findAll(int start, int end) {
1834 return findAll(start, end, null);
1835 }
1836
1837
1849 @Override
1850 public List<Company> findAll(int start, int end,
1851 OrderByComparator<Company> orderByComparator) {
1852 boolean pagination = true;
1853 FinderPath finderPath = null;
1854 Object[] finderArgs = null;
1855
1856 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1857 (orderByComparator == null)) {
1858 pagination = false;
1859 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1860 finderArgs = FINDER_ARGS_EMPTY;
1861 }
1862 else {
1863 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1864 finderArgs = new Object[] { start, end, orderByComparator };
1865 }
1866
1867 List<Company> list = (List<Company>)FinderCacheUtil.getResult(finderPath,
1868 finderArgs, this);
1869
1870 if (list == null) {
1871 StringBundler query = null;
1872 String sql = null;
1873
1874 if (orderByComparator != null) {
1875 query = new StringBundler(2 +
1876 (orderByComparator.getOrderByFields().length * 3));
1877
1878 query.append(_SQL_SELECT_COMPANY);
1879
1880 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1881 orderByComparator);
1882
1883 sql = query.toString();
1884 }
1885 else {
1886 sql = _SQL_SELECT_COMPANY;
1887
1888 if (pagination) {
1889 sql = sql.concat(CompanyModelImpl.ORDER_BY_JPQL);
1890 }
1891 }
1892
1893 Session session = null;
1894
1895 try {
1896 session = openSession();
1897
1898 Query q = session.createQuery(sql);
1899
1900 if (!pagination) {
1901 list = (List<Company>)QueryUtil.list(q, getDialect(),
1902 start, end, false);
1903
1904 Collections.sort(list);
1905
1906 list = Collections.unmodifiableList(list);
1907 }
1908 else {
1909 list = (List<Company>)QueryUtil.list(q, getDialect(),
1910 start, end);
1911 }
1912
1913 cacheResult(list);
1914
1915 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1916 }
1917 catch (Exception e) {
1918 FinderCacheUtil.removeResult(finderPath, finderArgs);
1919
1920 throw processException(e);
1921 }
1922 finally {
1923 closeSession(session);
1924 }
1925 }
1926
1927 return list;
1928 }
1929
1930
1934 @Override
1935 public void removeAll() {
1936 for (Company company : findAll()) {
1937 remove(company);
1938 }
1939 }
1940
1941
1946 @Override
1947 public int countAll() {
1948 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1949 FINDER_ARGS_EMPTY, this);
1950
1951 if (count == null) {
1952 Session session = null;
1953
1954 try {
1955 session = openSession();
1956
1957 Query q = session.createQuery(_SQL_COUNT_COMPANY);
1958
1959 count = (Long)q.uniqueResult();
1960
1961 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1962 FINDER_ARGS_EMPTY, count);
1963 }
1964 catch (Exception e) {
1965 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1966 FINDER_ARGS_EMPTY);
1967
1968 throw processException(e);
1969 }
1970 finally {
1971 closeSession(session);
1972 }
1973 }
1974
1975 return count.intValue();
1976 }
1977
1978 @Override
1979 protected Set<String> getBadColumnNames() {
1980 return _badColumnNames;
1981 }
1982
1983
1986 public void afterPropertiesSet() {
1987 }
1988
1989 public void destroy() {
1990 EntityCacheUtil.removeCache(CompanyImpl.class.getName());
1991 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1992 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1993 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1994 }
1995
1996 private static final String _SQL_SELECT_COMPANY = "SELECT company FROM Company company";
1997 private static final String _SQL_SELECT_COMPANY_WHERE_PKS_IN = "SELECT company FROM Company company WHERE companyId IN (";
1998 private static final String _SQL_SELECT_COMPANY_WHERE = "SELECT company FROM Company company WHERE ";
1999 private static final String _SQL_COUNT_COMPANY = "SELECT COUNT(company) FROM Company company";
2000 private static final String _SQL_COUNT_COMPANY_WHERE = "SELECT COUNT(company) FROM Company company WHERE ";
2001 private static final String _ORDER_BY_ENTITY_ALIAS = "company.";
2002 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Company exists with the primary key ";
2003 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Company exists with the key {";
2004 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2005 private static final Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
2006 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2007 "key", "active"
2008 });
2009 private static final Company _nullCompany = new CompanyImpl() {
2010 @Override
2011 public Object clone() {
2012 return this;
2013 }
2014
2015 @Override
2016 public CacheModel<Company> toCacheModel() {
2017 return _nullCompanyCacheModel;
2018 }
2019 };
2020
2021 private static final CacheModel<Company> _nullCompanyCacheModel = new NullCacheModel();
2022
2023 private static class NullCacheModel implements CacheModel<Company>,
2024 MVCCModel {
2025 @Override
2026 public long getMvccVersion() {
2027 return -1;
2028 }
2029
2030 @Override
2031 public void setMvccVersion(long mvccVersion) {
2032 }
2033
2034 @Override
2035 public Company toEntityModel() {
2036 return _nullCompany;
2037 }
2038 }
2039 }