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.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.SetUtil;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.Company;
037 import com.liferay.portal.model.MVCCModel;
038 import com.liferay.portal.model.impl.CompanyImpl;
039 import com.liferay.portal.model.impl.CompanyModelImpl;
040 import com.liferay.portal.service.persistence.CompanyPersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.HashSet;
047 import java.util.Iterator;
048 import java.util.List;
049 import java.util.Map;
050 import java.util.Set;
051
052
064 @ProviderType
065 public class CompanyPersistenceImpl extends BasePersistenceImpl<Company>
066 implements CompanyPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = CompanyImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
078 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
081 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
084 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_FETCH_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
087 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
088 FINDER_CLASS_NAME_ENTITY, "fetchByWebId",
089 new String[] { String.class.getName() },
090 CompanyModelImpl.WEBID_COLUMN_BITMASK);
091 public static final FinderPath FINDER_PATH_COUNT_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
092 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByWebId",
094 new String[] { String.class.getName() });
095
096
103 @Override
104 public Company findByWebId(String webId) throws NoSuchCompanyException {
105 Company company = fetchByWebId(webId);
106
107 if (company == null) {
108 StringBundler msg = new StringBundler(4);
109
110 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
111
112 msg.append("webId=");
113 msg.append(webId);
114
115 msg.append(StringPool.CLOSE_CURLY_BRACE);
116
117 if (_log.isWarnEnabled()) {
118 _log.warn(msg.toString());
119 }
120
121 throw new NoSuchCompanyException(msg.toString());
122 }
123
124 return company;
125 }
126
127
133 @Override
134 public Company fetchByWebId(String webId) {
135 return fetchByWebId(webId, true);
136 }
137
138
145 @Override
146 public Company fetchByWebId(String webId, boolean retrieveFromCache) {
147 Object[] finderArgs = new Object[] { webId };
148
149 Object result = null;
150
151 if (retrieveFromCache) {
152 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_WEBID,
153 finderArgs, this);
154 }
155
156 if (result instanceof Company) {
157 Company company = (Company)result;
158
159 if (!Validator.equals(webId, company.getWebId())) {
160 result = null;
161 }
162 }
163
164 if (result == null) {
165 StringBundler query = new StringBundler(3);
166
167 query.append(_SQL_SELECT_COMPANY_WHERE);
168
169 boolean bindWebId = false;
170
171 if (webId == null) {
172 query.append(_FINDER_COLUMN_WEBID_WEBID_1);
173 }
174 else if (webId.equals(StringPool.BLANK)) {
175 query.append(_FINDER_COLUMN_WEBID_WEBID_3);
176 }
177 else {
178 bindWebId = true;
179
180 query.append(_FINDER_COLUMN_WEBID_WEBID_2);
181 }
182
183 String sql = query.toString();
184
185 Session session = null;
186
187 try {
188 session = openSession();
189
190 Query q = session.createQuery(sql);
191
192 QueryPos qPos = QueryPos.getInstance(q);
193
194 if (bindWebId) {
195 qPos.add(webId);
196 }
197
198 List<Company> list = q.list();
199
200 if (list.isEmpty()) {
201 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
202 finderArgs, list);
203 }
204 else {
205 Company company = list.get(0);
206
207 result = company;
208
209 cacheResult(company);
210
211 if ((company.getWebId() == null) ||
212 !company.getWebId().equals(webId)) {
213 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
214 finderArgs, company);
215 }
216 }
217 }
218 catch (Exception e) {
219 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
220 finderArgs);
221
222 throw processException(e);
223 }
224 finally {
225 closeSession(session);
226 }
227 }
228
229 if (result instanceof List<?>) {
230 return null;
231 }
232 else {
233 return (Company)result;
234 }
235 }
236
237
243 @Override
244 public Company removeByWebId(String webId) throws NoSuchCompanyException {
245 Company company = findByWebId(webId);
246
247 return remove(company);
248 }
249
250
256 @Override
257 public int countByWebId(String webId) {
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
336 @Override
337 public Company findByMx(String mx) throws NoSuchCompanyException {
338 Company company = fetchByMx(mx);
339
340 if (company == null) {
341 StringBundler msg = new StringBundler(4);
342
343 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
344
345 msg.append("mx=");
346 msg.append(mx);
347
348 msg.append(StringPool.CLOSE_CURLY_BRACE);
349
350 if (_log.isWarnEnabled()) {
351 _log.warn(msg.toString());
352 }
353
354 throw new NoSuchCompanyException(msg.toString());
355 }
356
357 return company;
358 }
359
360
366 @Override
367 public Company fetchByMx(String mx) {
368 return fetchByMx(mx, true);
369 }
370
371
378 @Override
379 public Company fetchByMx(String mx, boolean retrieveFromCache) {
380 Object[] finderArgs = new Object[] { mx };
381
382 Object result = null;
383
384 if (retrieveFromCache) {
385 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MX,
386 finderArgs, this);
387 }
388
389 if (result instanceof Company) {
390 Company company = (Company)result;
391
392 if (!Validator.equals(mx, company.getMx())) {
393 result = null;
394 }
395 }
396
397 if (result == null) {
398 StringBundler query = new StringBundler(3);
399
400 query.append(_SQL_SELECT_COMPANY_WHERE);
401
402 boolean bindMx = false;
403
404 if (mx == null) {
405 query.append(_FINDER_COLUMN_MX_MX_1);
406 }
407 else if (mx.equals(StringPool.BLANK)) {
408 query.append(_FINDER_COLUMN_MX_MX_3);
409 }
410 else {
411 bindMx = true;
412
413 query.append(_FINDER_COLUMN_MX_MX_2);
414 }
415
416 String sql = query.toString();
417
418 Session session = null;
419
420 try {
421 session = openSession();
422
423 Query q = session.createQuery(sql);
424
425 QueryPos qPos = QueryPos.getInstance(q);
426
427 if (bindMx) {
428 qPos.add(mx);
429 }
430
431 List<Company> list = q.list();
432
433 if (list.isEmpty()) {
434 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
435 finderArgs, list);
436 }
437 else {
438 if ((list.size() > 1) && _log.isWarnEnabled()) {
439 _log.warn(
440 "CompanyPersistenceImpl.fetchByMx(String, boolean) with parameters (" +
441 StringUtil.merge(finderArgs) +
442 ") 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.");
443 }
444
445 Company company = list.get(0);
446
447 result = company;
448
449 cacheResult(company);
450
451 if ((company.getMx() == null) ||
452 !company.getMx().equals(mx)) {
453 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
454 finderArgs, company);
455 }
456 }
457 }
458 catch (Exception e) {
459 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, finderArgs);
460
461 throw processException(e);
462 }
463 finally {
464 closeSession(session);
465 }
466 }
467
468 if (result instanceof List<?>) {
469 return null;
470 }
471 else {
472 return (Company)result;
473 }
474 }
475
476
482 @Override
483 public Company removeByMx(String mx) throws NoSuchCompanyException {
484 Company company = findByMx(mx);
485
486 return remove(company);
487 }
488
489
495 @Override
496 public int countByMx(String mx) {
497 FinderPath finderPath = FINDER_PATH_COUNT_BY_MX;
498
499 Object[] finderArgs = new Object[] { mx };
500
501 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
502 this);
503
504 if (count == null) {
505 StringBundler query = new StringBundler(2);
506
507 query.append(_SQL_COUNT_COMPANY_WHERE);
508
509 boolean bindMx = false;
510
511 if (mx == null) {
512 query.append(_FINDER_COLUMN_MX_MX_1);
513 }
514 else if (mx.equals(StringPool.BLANK)) {
515 query.append(_FINDER_COLUMN_MX_MX_3);
516 }
517 else {
518 bindMx = true;
519
520 query.append(_FINDER_COLUMN_MX_MX_2);
521 }
522
523 String sql = query.toString();
524
525 Session session = null;
526
527 try {
528 session = openSession();
529
530 Query q = session.createQuery(sql);
531
532 QueryPos qPos = QueryPos.getInstance(q);
533
534 if (bindMx) {
535 qPos.add(mx);
536 }
537
538 count = (Long)q.uniqueResult();
539
540 FinderCacheUtil.putResult(finderPath, finderArgs, count);
541 }
542 catch (Exception e) {
543 FinderCacheUtil.removeResult(finderPath, finderArgs);
544
545 throw processException(e);
546 }
547 finally {
548 closeSession(session);
549 }
550 }
551
552 return count.intValue();
553 }
554
555 private static final String _FINDER_COLUMN_MX_MX_1 = "company.mx IS NULL";
556 private static final String _FINDER_COLUMN_MX_MX_2 = "company.mx = ?";
557 private static final String _FINDER_COLUMN_MX_MX_3 = "(company.mx IS NULL OR company.mx = '')";
558 public static final FinderPath FINDER_PATH_FETCH_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
559 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
560 FINDER_CLASS_NAME_ENTITY, "fetchByLogoId",
561 new String[] { Long.class.getName() },
562 CompanyModelImpl.LOGOID_COLUMN_BITMASK);
563 public static final FinderPath FINDER_PATH_COUNT_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
564 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
565 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLogoId",
566 new String[] { Long.class.getName() });
567
568
575 @Override
576 public Company findByLogoId(long logoId) throws NoSuchCompanyException {
577 Company company = fetchByLogoId(logoId);
578
579 if (company == null) {
580 StringBundler msg = new StringBundler(4);
581
582 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
583
584 msg.append("logoId=");
585 msg.append(logoId);
586
587 msg.append(StringPool.CLOSE_CURLY_BRACE);
588
589 if (_log.isWarnEnabled()) {
590 _log.warn(msg.toString());
591 }
592
593 throw new NoSuchCompanyException(msg.toString());
594 }
595
596 return company;
597 }
598
599
605 @Override
606 public Company fetchByLogoId(long logoId) {
607 return fetchByLogoId(logoId, true);
608 }
609
610
617 @Override
618 public Company fetchByLogoId(long logoId, boolean retrieveFromCache) {
619 Object[] finderArgs = new Object[] { logoId };
620
621 Object result = null;
622
623 if (retrieveFromCache) {
624 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LOGOID,
625 finderArgs, this);
626 }
627
628 if (result instanceof Company) {
629 Company company = (Company)result;
630
631 if ((logoId != company.getLogoId())) {
632 result = null;
633 }
634 }
635
636 if (result == null) {
637 StringBundler query = new StringBundler(3);
638
639 query.append(_SQL_SELECT_COMPANY_WHERE);
640
641 query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
642
643 String sql = query.toString();
644
645 Session session = null;
646
647 try {
648 session = openSession();
649
650 Query q = session.createQuery(sql);
651
652 QueryPos qPos = QueryPos.getInstance(q);
653
654 qPos.add(logoId);
655
656 List<Company> list = q.list();
657
658 if (list.isEmpty()) {
659 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
660 finderArgs, list);
661 }
662 else {
663 if ((list.size() > 1) && _log.isWarnEnabled()) {
664 _log.warn(
665 "CompanyPersistenceImpl.fetchByLogoId(long, boolean) with parameters (" +
666 StringUtil.merge(finderArgs) +
667 ") 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.");
668 }
669
670 Company company = list.get(0);
671
672 result = company;
673
674 cacheResult(company);
675
676 if ((company.getLogoId() != logoId)) {
677 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
678 finderArgs, company);
679 }
680 }
681 }
682 catch (Exception e) {
683 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
684 finderArgs);
685
686 throw processException(e);
687 }
688 finally {
689 closeSession(session);
690 }
691 }
692
693 if (result instanceof List<?>) {
694 return null;
695 }
696 else {
697 return (Company)result;
698 }
699 }
700
701
707 @Override
708 public Company removeByLogoId(long logoId) throws NoSuchCompanyException {
709 Company company = findByLogoId(logoId);
710
711 return remove(company);
712 }
713
714
720 @Override
721 public int countByLogoId(long logoId) {
722 FinderPath finderPath = FINDER_PATH_COUNT_BY_LOGOID;
723
724 Object[] finderArgs = new Object[] { logoId };
725
726 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
727 this);
728
729 if (count == null) {
730 StringBundler query = new StringBundler(2);
731
732 query.append(_SQL_COUNT_COMPANY_WHERE);
733
734 query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
735
736 String sql = query.toString();
737
738 Session session = null;
739
740 try {
741 session = openSession();
742
743 Query q = session.createQuery(sql);
744
745 QueryPos qPos = QueryPos.getInstance(q);
746
747 qPos.add(logoId);
748
749 count = (Long)q.uniqueResult();
750
751 FinderCacheUtil.putResult(finderPath, finderArgs, count);
752 }
753 catch (Exception e) {
754 FinderCacheUtil.removeResult(finderPath, finderArgs);
755
756 throw processException(e);
757 }
758 finally {
759 closeSession(session);
760 }
761 }
762
763 return count.intValue();
764 }
765
766 private static final String _FINDER_COLUMN_LOGOID_LOGOID_2 = "company.logoId = ?";
767 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
768 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
769 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySystem",
770 new String[] {
771 Boolean.class.getName(),
772
773 Integer.class.getName(), Integer.class.getName(),
774 OrderByComparator.class.getName()
775 });
776 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM =
777 new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
778 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
779 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySystem",
780 new String[] { Boolean.class.getName() },
781 CompanyModelImpl.SYSTEM_COLUMN_BITMASK);
782 public static final FinderPath FINDER_PATH_COUNT_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
783 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
784 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySystem",
785 new String[] { Boolean.class.getName() });
786
787
793 @Override
794 public List<Company> findBySystem(boolean system) {
795 return findBySystem(system, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
796 }
797
798
810 @Override
811 public List<Company> findBySystem(boolean system, int start, int end) {
812 return findBySystem(system, start, end, null);
813 }
814
815
828 @Override
829 public List<Company> findBySystem(boolean system, int start, int end,
830 OrderByComparator<Company> orderByComparator) {
831 boolean pagination = true;
832 FinderPath finderPath = null;
833 Object[] finderArgs = null;
834
835 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
836 (orderByComparator == null)) {
837 pagination = false;
838 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM;
839 finderArgs = new Object[] { system };
840 }
841 else {
842 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM;
843 finderArgs = new Object[] { system, start, end, orderByComparator };
844 }
845
846 List<Company> list = (List<Company>)FinderCacheUtil.getResult(finderPath,
847 finderArgs, this);
848
849 if ((list != null) && !list.isEmpty()) {
850 for (Company company : list) {
851 if ((system != company.getSystem())) {
852 list = null;
853
854 break;
855 }
856 }
857 }
858
859 if (list == null) {
860 StringBundler query = null;
861
862 if (orderByComparator != null) {
863 query = new StringBundler(3 +
864 (orderByComparator.getOrderByFields().length * 3));
865 }
866 else {
867 query = new StringBundler(3);
868 }
869
870 query.append(_SQL_SELECT_COMPANY_WHERE);
871
872 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
873
874 if (orderByComparator != null) {
875 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
876 orderByComparator);
877 }
878 else
879 if (pagination) {
880 query.append(CompanyModelImpl.ORDER_BY_JPQL);
881 }
882
883 String sql = query.toString();
884
885 Session session = null;
886
887 try {
888 session = openSession();
889
890 Query q = session.createQuery(sql);
891
892 QueryPos qPos = QueryPos.getInstance(q);
893
894 qPos.add(system);
895
896 if (!pagination) {
897 list = (List<Company>)QueryUtil.list(q, getDialect(),
898 start, end, false);
899
900 Collections.sort(list);
901
902 list = Collections.unmodifiableList(list);
903 }
904 else {
905 list = (List<Company>)QueryUtil.list(q, getDialect(),
906 start, end);
907 }
908
909 cacheResult(list);
910
911 FinderCacheUtil.putResult(finderPath, finderArgs, list);
912 }
913 catch (Exception e) {
914 FinderCacheUtil.removeResult(finderPath, finderArgs);
915
916 throw processException(e);
917 }
918 finally {
919 closeSession(session);
920 }
921 }
922
923 return list;
924 }
925
926
934 @Override
935 public Company findBySystem_First(boolean system,
936 OrderByComparator<Company> orderByComparator)
937 throws NoSuchCompanyException {
938 Company company = fetchBySystem_First(system, orderByComparator);
939
940 if (company != null) {
941 return company;
942 }
943
944 StringBundler msg = new StringBundler(4);
945
946 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
947
948 msg.append("system=");
949 msg.append(system);
950
951 msg.append(StringPool.CLOSE_CURLY_BRACE);
952
953 throw new NoSuchCompanyException(msg.toString());
954 }
955
956
963 @Override
964 public Company fetchBySystem_First(boolean system,
965 OrderByComparator<Company> orderByComparator) {
966 List<Company> list = findBySystem(system, 0, 1, orderByComparator);
967
968 if (!list.isEmpty()) {
969 return list.get(0);
970 }
971
972 return null;
973 }
974
975
983 @Override
984 public Company findBySystem_Last(boolean system,
985 OrderByComparator<Company> orderByComparator)
986 throws NoSuchCompanyException {
987 Company company = fetchBySystem_Last(system, orderByComparator);
988
989 if (company != null) {
990 return company;
991 }
992
993 StringBundler msg = new StringBundler(4);
994
995 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
996
997 msg.append("system=");
998 msg.append(system);
999
1000 msg.append(StringPool.CLOSE_CURLY_BRACE);
1001
1002 throw new NoSuchCompanyException(msg.toString());
1003 }
1004
1005
1012 @Override
1013 public Company fetchBySystem_Last(boolean system,
1014 OrderByComparator<Company> orderByComparator) {
1015 int count = countBySystem(system);
1016
1017 if (count == 0) {
1018 return null;
1019 }
1020
1021 List<Company> list = findBySystem(system, count - 1, count,
1022 orderByComparator);
1023
1024 if (!list.isEmpty()) {
1025 return list.get(0);
1026 }
1027
1028 return null;
1029 }
1030
1031
1040 @Override
1041 public Company[] findBySystem_PrevAndNext(long companyId, boolean system,
1042 OrderByComparator<Company> orderByComparator)
1043 throws NoSuchCompanyException {
1044 Company company = findByPrimaryKey(companyId);
1045
1046 Session session = null;
1047
1048 try {
1049 session = openSession();
1050
1051 Company[] array = new CompanyImpl[3];
1052
1053 array[0] = getBySystem_PrevAndNext(session, company, system,
1054 orderByComparator, true);
1055
1056 array[1] = company;
1057
1058 array[2] = getBySystem_PrevAndNext(session, company, system,
1059 orderByComparator, false);
1060
1061 return array;
1062 }
1063 catch (Exception e) {
1064 throw processException(e);
1065 }
1066 finally {
1067 closeSession(session);
1068 }
1069 }
1070
1071 protected Company getBySystem_PrevAndNext(Session session, Company company,
1072 boolean system, OrderByComparator<Company> orderByComparator,
1073 boolean previous) {
1074 StringBundler query = null;
1075
1076 if (orderByComparator != null) {
1077 query = new StringBundler(6 +
1078 (orderByComparator.getOrderByFields().length * 6));
1079 }
1080 else {
1081 query = new StringBundler(3);
1082 }
1083
1084 query.append(_SQL_SELECT_COMPANY_WHERE);
1085
1086 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1087
1088 if (orderByComparator != null) {
1089 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1090
1091 if (orderByConditionFields.length > 0) {
1092 query.append(WHERE_AND);
1093 }
1094
1095 for (int i = 0; i < orderByConditionFields.length; i++) {
1096 query.append(_ORDER_BY_ENTITY_ALIAS);
1097 query.append(orderByConditionFields[i]);
1098
1099 if ((i + 1) < orderByConditionFields.length) {
1100 if (orderByComparator.isAscending() ^ previous) {
1101 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1102 }
1103 else {
1104 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1105 }
1106 }
1107 else {
1108 if (orderByComparator.isAscending() ^ previous) {
1109 query.append(WHERE_GREATER_THAN);
1110 }
1111 else {
1112 query.append(WHERE_LESSER_THAN);
1113 }
1114 }
1115 }
1116
1117 query.append(ORDER_BY_CLAUSE);
1118
1119 String[] orderByFields = orderByComparator.getOrderByFields();
1120
1121 for (int i = 0; i < orderByFields.length; i++) {
1122 query.append(_ORDER_BY_ENTITY_ALIAS);
1123 query.append(orderByFields[i]);
1124
1125 if ((i + 1) < orderByFields.length) {
1126 if (orderByComparator.isAscending() ^ previous) {
1127 query.append(ORDER_BY_ASC_HAS_NEXT);
1128 }
1129 else {
1130 query.append(ORDER_BY_DESC_HAS_NEXT);
1131 }
1132 }
1133 else {
1134 if (orderByComparator.isAscending() ^ previous) {
1135 query.append(ORDER_BY_ASC);
1136 }
1137 else {
1138 query.append(ORDER_BY_DESC);
1139 }
1140 }
1141 }
1142 }
1143 else {
1144 query.append(CompanyModelImpl.ORDER_BY_JPQL);
1145 }
1146
1147 String sql = query.toString();
1148
1149 Query q = session.createQuery(sql);
1150
1151 q.setFirstResult(0);
1152 q.setMaxResults(2);
1153
1154 QueryPos qPos = QueryPos.getInstance(q);
1155
1156 qPos.add(system);
1157
1158 if (orderByComparator != null) {
1159 Object[] values = orderByComparator.getOrderByConditionValues(company);
1160
1161 for (Object value : values) {
1162 qPos.add(value);
1163 }
1164 }
1165
1166 List<Company> list = q.list();
1167
1168 if (list.size() == 2) {
1169 return list.get(1);
1170 }
1171 else {
1172 return null;
1173 }
1174 }
1175
1176
1181 @Override
1182 public void removeBySystem(boolean system) {
1183 for (Company company : findBySystem(system, QueryUtil.ALL_POS,
1184 QueryUtil.ALL_POS, null)) {
1185 remove(company);
1186 }
1187 }
1188
1189
1195 @Override
1196 public int countBySystem(boolean system) {
1197 FinderPath finderPath = FINDER_PATH_COUNT_BY_SYSTEM;
1198
1199 Object[] finderArgs = new Object[] { system };
1200
1201 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1202 this);
1203
1204 if (count == null) {
1205 StringBundler query = new StringBundler(2);
1206
1207 query.append(_SQL_COUNT_COMPANY_WHERE);
1208
1209 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1210
1211 String sql = query.toString();
1212
1213 Session session = null;
1214
1215 try {
1216 session = openSession();
1217
1218 Query q = session.createQuery(sql);
1219
1220 QueryPos qPos = QueryPos.getInstance(q);
1221
1222 qPos.add(system);
1223
1224 count = (Long)q.uniqueResult();
1225
1226 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1227 }
1228 catch (Exception e) {
1229 FinderCacheUtil.removeResult(finderPath, finderArgs);
1230
1231 throw processException(e);
1232 }
1233 finally {
1234 closeSession(session);
1235 }
1236 }
1237
1238 return count.intValue();
1239 }
1240
1241 private static final String _FINDER_COLUMN_SYSTEM_SYSTEM_2 = "company.system = ?";
1242
1243 public CompanyPersistenceImpl() {
1244 setModelClass(Company.class);
1245 }
1246
1247
1252 @Override
1253 public void cacheResult(Company company) {
1254 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1255 CompanyImpl.class, company.getPrimaryKey(), company);
1256
1257 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
1258 new Object[] { company.getWebId() }, company);
1259
1260 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
1261 new Object[] { company.getMx() }, company);
1262
1263 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
1264 new Object[] { company.getLogoId() }, company);
1265
1266 company.resetOriginalValues();
1267 }
1268
1269
1274 @Override
1275 public void cacheResult(List<Company> companies) {
1276 for (Company company : companies) {
1277 if (EntityCacheUtil.getResult(
1278 CompanyModelImpl.ENTITY_CACHE_ENABLED,
1279 CompanyImpl.class, company.getPrimaryKey()) == null) {
1280 cacheResult(company);
1281 }
1282 else {
1283 company.resetOriginalValues();
1284 }
1285 }
1286 }
1287
1288
1295 @Override
1296 public void clearCache() {
1297 EntityCacheUtil.clearCache(CompanyImpl.class);
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 @Override
1439 public Company create(long companyId) {
1440 Company company = new CompanyImpl();
1441
1442 company.setNew(true);
1443 company.setPrimaryKey(companyId);
1444
1445 return company;
1446 }
1447
1448
1455 @Override
1456 public Company remove(long companyId) throws NoSuchCompanyException {
1457 return remove((Serializable)companyId);
1458 }
1459
1460
1467 @Override
1468 public Company remove(Serializable primaryKey)
1469 throws NoSuchCompanyException {
1470 Session session = null;
1471
1472 try {
1473 session = openSession();
1474
1475 Company company = (Company)session.get(CompanyImpl.class, primaryKey);
1476
1477 if (company == null) {
1478 if (_log.isWarnEnabled()) {
1479 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1480 }
1481
1482 throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1483 primaryKey);
1484 }
1485
1486 return remove(company);
1487 }
1488 catch (NoSuchCompanyException nsee) {
1489 throw nsee;
1490 }
1491 catch (Exception e) {
1492 throw processException(e);
1493 }
1494 finally {
1495 closeSession(session);
1496 }
1497 }
1498
1499 @Override
1500 protected Company removeImpl(Company company) {
1501 company = toUnwrappedModel(company);
1502
1503 Session session = null;
1504
1505 try {
1506 session = openSession();
1507
1508 if (!session.contains(company)) {
1509 company = (Company)session.get(CompanyImpl.class,
1510 company.getPrimaryKeyObj());
1511 }
1512
1513 if (company != null) {
1514 session.delete(company);
1515 }
1516 }
1517 catch (Exception e) {
1518 throw processException(e);
1519 }
1520 finally {
1521 closeSession(session);
1522 }
1523
1524 if (company != null) {
1525 clearCache(company);
1526 }
1527
1528 return company;
1529 }
1530
1531 @Override
1532 public Company updateImpl(Company company) {
1533 company = toUnwrappedModel(company);
1534
1535 boolean isNew = company.isNew();
1536
1537 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1538
1539 Session session = null;
1540
1541 try {
1542 session = openSession();
1543
1544 if (company.isNew()) {
1545 session.save(company);
1546
1547 company.setNew(false);
1548 }
1549 else {
1550 session.merge(company);
1551 }
1552 }
1553 catch (Exception e) {
1554 throw processException(e);
1555 }
1556 finally {
1557 closeSession(session);
1558 }
1559
1560 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1561
1562 if (isNew || !CompanyModelImpl.COLUMN_BITMASK_ENABLED) {
1563 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1564 }
1565
1566 else {
1567 if ((companyModelImpl.getColumnBitmask() &
1568 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM.getColumnBitmask()) != 0) {
1569 Object[] args = new Object[] {
1570 companyModelImpl.getOriginalSystem()
1571 };
1572
1573 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1574 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1575 args);
1576
1577 args = new Object[] { companyModelImpl.getSystem() };
1578
1579 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1580 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1581 args);
1582 }
1583 }
1584
1585 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1586 CompanyImpl.class, company.getPrimaryKey(), company, false);
1587
1588 clearUniqueFindersCache(company);
1589 cacheUniqueFindersCache(company);
1590
1591 company.resetOriginalValues();
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.setMvccVersion(company.getMvccVersion());
1607 companyImpl.setCompanyId(company.getCompanyId());
1608 companyImpl.setAccountId(company.getAccountId());
1609 companyImpl.setWebId(company.getWebId());
1610 companyImpl.setKey(company.getKey());
1611 companyImpl.setMx(company.getMx());
1612 companyImpl.setHomeURL(company.getHomeURL());
1613 companyImpl.setLogoId(company.getLogoId());
1614 companyImpl.setSystem(company.isSystem());
1615 companyImpl.setMaxUsers(company.getMaxUsers());
1616 companyImpl.setActive(company.isActive());
1617
1618 return companyImpl;
1619 }
1620
1621
1628 @Override
1629 public Company findByPrimaryKey(Serializable primaryKey)
1630 throws NoSuchCompanyException {
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
1652 @Override
1653 public Company findByPrimaryKey(long companyId)
1654 throws NoSuchCompanyException {
1655 return findByPrimaryKey((Serializable)companyId);
1656 }
1657
1658
1664 @Override
1665 public Company fetchByPrimaryKey(Serializable primaryKey) {
1666 Company company = (Company)EntityCacheUtil.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1667 CompanyImpl.class, primaryKey);
1668
1669 if (company == _nullCompany) {
1670 return null;
1671 }
1672
1673 if (company == null) {
1674 Session session = null;
1675
1676 try {
1677 session = openSession();
1678
1679 company = (Company)session.get(CompanyImpl.class, primaryKey);
1680
1681 if (company != null) {
1682 cacheResult(company);
1683 }
1684 else {
1685 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1686 CompanyImpl.class, primaryKey, _nullCompany);
1687 }
1688 }
1689 catch (Exception e) {
1690 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1691 CompanyImpl.class, primaryKey);
1692
1693 throw processException(e);
1694 }
1695 finally {
1696 closeSession(session);
1697 }
1698 }
1699
1700 return company;
1701 }
1702
1703
1709 @Override
1710 public Company fetchByPrimaryKey(long companyId) {
1711 return fetchByPrimaryKey((Serializable)companyId);
1712 }
1713
1714 @Override
1715 public Map<Serializable, Company> fetchByPrimaryKeys(
1716 Set<Serializable> primaryKeys) {
1717 if (primaryKeys.isEmpty()) {
1718 return Collections.emptyMap();
1719 }
1720
1721 Map<Serializable, Company> map = new HashMap<Serializable, Company>();
1722
1723 if (primaryKeys.size() == 1) {
1724 Iterator<Serializable> iterator = primaryKeys.iterator();
1725
1726 Serializable primaryKey = iterator.next();
1727
1728 Company company = fetchByPrimaryKey(primaryKey);
1729
1730 if (company != null) {
1731 map.put(primaryKey, company);
1732 }
1733
1734 return map;
1735 }
1736
1737 Set<Serializable> uncachedPrimaryKeys = null;
1738
1739 for (Serializable primaryKey : primaryKeys) {
1740 Company company = (Company)EntityCacheUtil.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1741 CompanyImpl.class, primaryKey);
1742
1743 if (company == null) {
1744 if (uncachedPrimaryKeys == null) {
1745 uncachedPrimaryKeys = new HashSet<Serializable>();
1746 }
1747
1748 uncachedPrimaryKeys.add(primaryKey);
1749 }
1750 else {
1751 map.put(primaryKey, company);
1752 }
1753 }
1754
1755 if (uncachedPrimaryKeys == null) {
1756 return map;
1757 }
1758
1759 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1760 1);
1761
1762 query.append(_SQL_SELECT_COMPANY_WHERE_PKS_IN);
1763
1764 for (Serializable primaryKey : uncachedPrimaryKeys) {
1765 query.append(String.valueOf(primaryKey));
1766
1767 query.append(StringPool.COMMA);
1768 }
1769
1770 query.setIndex(query.index() - 1);
1771
1772 query.append(StringPool.CLOSE_PARENTHESIS);
1773
1774 String sql = query.toString();
1775
1776 Session session = null;
1777
1778 try {
1779 session = openSession();
1780
1781 Query q = session.createQuery(sql);
1782
1783 for (Company company : (List<Company>)q.list()) {
1784 map.put(company.getPrimaryKeyObj(), company);
1785
1786 cacheResult(company);
1787
1788 uncachedPrimaryKeys.remove(company.getPrimaryKeyObj());
1789 }
1790
1791 for (Serializable primaryKey : uncachedPrimaryKeys) {
1792 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1793 CompanyImpl.class, primaryKey, _nullCompany);
1794 }
1795 }
1796 catch (Exception e) {
1797 throw processException(e);
1798 }
1799 finally {
1800 closeSession(session);
1801 }
1802
1803 return map;
1804 }
1805
1806
1811 @Override
1812 public List<Company> findAll() {
1813 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1814 }
1815
1816
1827 @Override
1828 public List<Company> findAll(int start, int end) {
1829 return findAll(start, end, null);
1830 }
1831
1832
1844 @Override
1845 public List<Company> findAll(int start, int end,
1846 OrderByComparator<Company> orderByComparator) {
1847 boolean pagination = true;
1848 FinderPath finderPath = null;
1849 Object[] finderArgs = null;
1850
1851 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1852 (orderByComparator == null)) {
1853 pagination = false;
1854 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1855 finderArgs = FINDER_ARGS_EMPTY;
1856 }
1857 else {
1858 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1859 finderArgs = new Object[] { start, end, orderByComparator };
1860 }
1861
1862 List<Company> list = (List<Company>)FinderCacheUtil.getResult(finderPath,
1863 finderArgs, this);
1864
1865 if (list == null) {
1866 StringBundler query = null;
1867 String sql = null;
1868
1869 if (orderByComparator != null) {
1870 query = new StringBundler(2 +
1871 (orderByComparator.getOrderByFields().length * 3));
1872
1873 query.append(_SQL_SELECT_COMPANY);
1874
1875 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1876 orderByComparator);
1877
1878 sql = query.toString();
1879 }
1880 else {
1881 sql = _SQL_SELECT_COMPANY;
1882
1883 if (pagination) {
1884 sql = sql.concat(CompanyModelImpl.ORDER_BY_JPQL);
1885 }
1886 }
1887
1888 Session session = null;
1889
1890 try {
1891 session = openSession();
1892
1893 Query q = session.createQuery(sql);
1894
1895 if (!pagination) {
1896 list = (List<Company>)QueryUtil.list(q, getDialect(),
1897 start, end, false);
1898
1899 Collections.sort(list);
1900
1901 list = Collections.unmodifiableList(list);
1902 }
1903 else {
1904 list = (List<Company>)QueryUtil.list(q, getDialect(),
1905 start, end);
1906 }
1907
1908 cacheResult(list);
1909
1910 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1911 }
1912 catch (Exception e) {
1913 FinderCacheUtil.removeResult(finderPath, finderArgs);
1914
1915 throw processException(e);
1916 }
1917 finally {
1918 closeSession(session);
1919 }
1920 }
1921
1922 return list;
1923 }
1924
1925
1929 @Override
1930 public void removeAll() {
1931 for (Company company : findAll()) {
1932 remove(company);
1933 }
1934 }
1935
1936
1941 @Override
1942 public int countAll() {
1943 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1944 FINDER_ARGS_EMPTY, this);
1945
1946 if (count == null) {
1947 Session session = null;
1948
1949 try {
1950 session = openSession();
1951
1952 Query q = session.createQuery(_SQL_COUNT_COMPANY);
1953
1954 count = (Long)q.uniqueResult();
1955
1956 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1957 FINDER_ARGS_EMPTY, count);
1958 }
1959 catch (Exception e) {
1960 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1961 FINDER_ARGS_EMPTY);
1962
1963 throw processException(e);
1964 }
1965 finally {
1966 closeSession(session);
1967 }
1968 }
1969
1970 return count.intValue();
1971 }
1972
1973 @Override
1974 protected Set<String> getBadColumnNames() {
1975 return _badColumnNames;
1976 }
1977
1978
1981 public void afterPropertiesSet() {
1982 }
1983
1984 public void destroy() {
1985 EntityCacheUtil.removeCache(CompanyImpl.class.getName());
1986 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1987 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1988 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1989 }
1990
1991 private static final String _SQL_SELECT_COMPANY = "SELECT company FROM Company company";
1992 private static final String _SQL_SELECT_COMPANY_WHERE_PKS_IN = "SELECT company FROM Company company WHERE companyId IN (";
1993 private static final String _SQL_SELECT_COMPANY_WHERE = "SELECT company FROM Company company WHERE ";
1994 private static final String _SQL_COUNT_COMPANY = "SELECT COUNT(company) FROM Company company";
1995 private static final String _SQL_COUNT_COMPANY_WHERE = "SELECT COUNT(company) FROM Company company WHERE ";
1996 private static final String _ORDER_BY_ENTITY_ALIAS = "company.";
1997 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Company exists with the primary key ";
1998 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Company exists with the key {";
1999 private static final Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
2000 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2001 "key", "active"
2002 });
2003 private static final Company _nullCompany = new CompanyImpl() {
2004 @Override
2005 public Object clone() {
2006 return this;
2007 }
2008
2009 @Override
2010 public CacheModel<Company> toCacheModel() {
2011 return _nullCompanyCacheModel;
2012 }
2013 };
2014
2015 private static final CacheModel<Company> _nullCompanyCacheModel = new NullCacheModel();
2016
2017 private static class NullCacheModel implements CacheModel<Company>,
2018 MVCCModel {
2019 @Override
2020 public long getMvccVersion() {
2021 return -1;
2022 }
2023
2024 @Override
2025 public void setMvccVersion(long mvccVersion) {
2026 }
2027
2028 @Override
2029 public Company toEntityModel() {
2030 return _nullCompany;
2031 }
2032 }
2033 }