001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchCompanyException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.Company;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.model.impl.CompanyImpl;
042 import com.liferay.portal.model.impl.CompanyModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050 import java.util.Set;
051
052
064 public class CompanyPersistenceImpl extends BasePersistenceImpl<Company>
065 implements CompanyPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = CompanyImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
077 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
080 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
083 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_FETCH_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
086 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
087 FINDER_CLASS_NAME_ENTITY, "fetchByWebId",
088 new String[] { String.class.getName() },
089 CompanyModelImpl.WEBID_COLUMN_BITMASK);
090 public static final FinderPath FINDER_PATH_COUNT_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
091 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByWebId",
093 new String[] { String.class.getName() });
094
095
103 @Override
104 public Company findByWebId(String webId)
105 throws NoSuchCompanyException, SystemException {
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
135 @Override
136 public Company fetchByWebId(String webId) throws SystemException {
137 return fetchByWebId(webId, true);
138 }
139
140
148 @Override
149 public Company fetchByWebId(String webId, boolean retrieveFromCache)
150 throws SystemException {
151 Object[] finderArgs = new Object[] { webId };
152
153 Object result = null;
154
155 if (retrieveFromCache) {
156 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_WEBID,
157 finderArgs, this);
158 }
159
160 if (result instanceof Company) {
161 Company company = (Company)result;
162
163 if (!Validator.equals(webId, company.getWebId())) {
164 result = null;
165 }
166 }
167
168 if (result == null) {
169 StringBundler query = new StringBundler(3);
170
171 query.append(_SQL_SELECT_COMPANY_WHERE);
172
173 boolean bindWebId = false;
174
175 if (webId == null) {
176 query.append(_FINDER_COLUMN_WEBID_WEBID_1);
177 }
178 else if (webId.equals(StringPool.BLANK)) {
179 query.append(_FINDER_COLUMN_WEBID_WEBID_3);
180 }
181 else {
182 bindWebId = true;
183
184 query.append(_FINDER_COLUMN_WEBID_WEBID_2);
185 }
186
187 String sql = query.toString();
188
189 Session session = null;
190
191 try {
192 session = openSession();
193
194 Query q = session.createQuery(sql);
195
196 QueryPos qPos = QueryPos.getInstance(q);
197
198 if (bindWebId) {
199 qPos.add(webId);
200 }
201
202 List<Company> list = q.list();
203
204 if (list.isEmpty()) {
205 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
206 finderArgs, list);
207 }
208 else {
209 Company company = list.get(0);
210
211 result = company;
212
213 cacheResult(company);
214
215 if ((company.getWebId() == null) ||
216 !company.getWebId().equals(webId)) {
217 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
218 finderArgs, company);
219 }
220 }
221 }
222 catch (Exception e) {
223 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
224 finderArgs);
225
226 throw processException(e);
227 }
228 finally {
229 closeSession(session);
230 }
231 }
232
233 if (result instanceof List<?>) {
234 return null;
235 }
236 else {
237 return (Company)result;
238 }
239 }
240
241
248 @Override
249 public Company removeByWebId(String webId)
250 throws NoSuchCompanyException, SystemException {
251 Company company = findByWebId(webId);
252
253 return remove(company);
254 }
255
256
263 @Override
264 public int countByWebId(String webId) throws SystemException {
265 FinderPath finderPath = FINDER_PATH_COUNT_BY_WEBID;
266
267 Object[] finderArgs = new Object[] { webId };
268
269 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
270 this);
271
272 if (count == null) {
273 StringBundler query = new StringBundler(2);
274
275 query.append(_SQL_COUNT_COMPANY_WHERE);
276
277 boolean bindWebId = false;
278
279 if (webId == null) {
280 query.append(_FINDER_COLUMN_WEBID_WEBID_1);
281 }
282 else if (webId.equals(StringPool.BLANK)) {
283 query.append(_FINDER_COLUMN_WEBID_WEBID_3);
284 }
285 else {
286 bindWebId = true;
287
288 query.append(_FINDER_COLUMN_WEBID_WEBID_2);
289 }
290
291 String sql = query.toString();
292
293 Session session = null;
294
295 try {
296 session = openSession();
297
298 Query q = session.createQuery(sql);
299
300 QueryPos qPos = QueryPos.getInstance(q);
301
302 if (bindWebId) {
303 qPos.add(webId);
304 }
305
306 count = (Long)q.uniqueResult();
307
308 FinderCacheUtil.putResult(finderPath, finderArgs, count);
309 }
310 catch (Exception e) {
311 FinderCacheUtil.removeResult(finderPath, finderArgs);
312
313 throw processException(e);
314 }
315 finally {
316 closeSession(session);
317 }
318 }
319
320 return count.intValue();
321 }
322
323 private static final String _FINDER_COLUMN_WEBID_WEBID_1 = "company.webId IS NULL";
324 private static final String _FINDER_COLUMN_WEBID_WEBID_2 = "company.webId = ?";
325 private static final String _FINDER_COLUMN_WEBID_WEBID_3 = "(company.webId IS NULL OR company.webId = '')";
326 public static final FinderPath FINDER_PATH_FETCH_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
327 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
328 FINDER_CLASS_NAME_ENTITY, "fetchByMx",
329 new String[] { String.class.getName() },
330 CompanyModelImpl.MX_COLUMN_BITMASK);
331 public static final FinderPath FINDER_PATH_COUNT_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
332 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
333 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMx",
334 new String[] { String.class.getName() });
335
336
344 @Override
345 public Company findByMx(String mx)
346 throws NoSuchCompanyException, SystemException {
347 Company company = fetchByMx(mx);
348
349 if (company == null) {
350 StringBundler msg = new StringBundler(4);
351
352 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
353
354 msg.append("mx=");
355 msg.append(mx);
356
357 msg.append(StringPool.CLOSE_CURLY_BRACE);
358
359 if (_log.isWarnEnabled()) {
360 _log.warn(msg.toString());
361 }
362
363 throw new NoSuchCompanyException(msg.toString());
364 }
365
366 return company;
367 }
368
369
376 @Override
377 public Company fetchByMx(String mx) throws SystemException {
378 return fetchByMx(mx, true);
379 }
380
381
389 @Override
390 public Company fetchByMx(String mx, boolean retrieveFromCache)
391 throws SystemException {
392 Object[] finderArgs = new Object[] { mx };
393
394 Object result = null;
395
396 if (retrieveFromCache) {
397 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MX,
398 finderArgs, this);
399 }
400
401 if (result instanceof Company) {
402 Company company = (Company)result;
403
404 if (!Validator.equals(mx, company.getMx())) {
405 result = null;
406 }
407 }
408
409 if (result == null) {
410 StringBundler query = new StringBundler(3);
411
412 query.append(_SQL_SELECT_COMPANY_WHERE);
413
414 boolean bindMx = false;
415
416 if (mx == null) {
417 query.append(_FINDER_COLUMN_MX_MX_1);
418 }
419 else if (mx.equals(StringPool.BLANK)) {
420 query.append(_FINDER_COLUMN_MX_MX_3);
421 }
422 else {
423 bindMx = true;
424
425 query.append(_FINDER_COLUMN_MX_MX_2);
426 }
427
428 String sql = query.toString();
429
430 Session session = null;
431
432 try {
433 session = openSession();
434
435 Query q = session.createQuery(sql);
436
437 QueryPos qPos = QueryPos.getInstance(q);
438
439 if (bindMx) {
440 qPos.add(mx);
441 }
442
443 List<Company> list = q.list();
444
445 if (list.isEmpty()) {
446 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
447 finderArgs, list);
448 }
449 else {
450 if ((list.size() > 1) && _log.isWarnEnabled()) {
451 _log.warn(
452 "CompanyPersistenceImpl.fetchByMx(String, boolean) with parameters (" +
453 StringUtil.merge(finderArgs) +
454 ") 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.");
455 }
456
457 Company company = list.get(0);
458
459 result = company;
460
461 cacheResult(company);
462
463 if ((company.getMx() == null) ||
464 !company.getMx().equals(mx)) {
465 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
466 finderArgs, company);
467 }
468 }
469 }
470 catch (Exception e) {
471 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, finderArgs);
472
473 throw processException(e);
474 }
475 finally {
476 closeSession(session);
477 }
478 }
479
480 if (result instanceof List<?>) {
481 return null;
482 }
483 else {
484 return (Company)result;
485 }
486 }
487
488
495 @Override
496 public Company removeByMx(String mx)
497 throws NoSuchCompanyException, SystemException {
498 Company company = findByMx(mx);
499
500 return remove(company);
501 }
502
503
510 @Override
511 public int countByMx(String mx) throws SystemException {
512 FinderPath finderPath = FINDER_PATH_COUNT_BY_MX;
513
514 Object[] finderArgs = new Object[] { mx };
515
516 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
517 this);
518
519 if (count == null) {
520 StringBundler query = new StringBundler(2);
521
522 query.append(_SQL_COUNT_COMPANY_WHERE);
523
524 boolean bindMx = false;
525
526 if (mx == null) {
527 query.append(_FINDER_COLUMN_MX_MX_1);
528 }
529 else if (mx.equals(StringPool.BLANK)) {
530 query.append(_FINDER_COLUMN_MX_MX_3);
531 }
532 else {
533 bindMx = true;
534
535 query.append(_FINDER_COLUMN_MX_MX_2);
536 }
537
538 String sql = query.toString();
539
540 Session session = null;
541
542 try {
543 session = openSession();
544
545 Query q = session.createQuery(sql);
546
547 QueryPos qPos = QueryPos.getInstance(q);
548
549 if (bindMx) {
550 qPos.add(mx);
551 }
552
553 count = (Long)q.uniqueResult();
554
555 FinderCacheUtil.putResult(finderPath, finderArgs, count);
556 }
557 catch (Exception e) {
558 FinderCacheUtil.removeResult(finderPath, finderArgs);
559
560 throw processException(e);
561 }
562 finally {
563 closeSession(session);
564 }
565 }
566
567 return count.intValue();
568 }
569
570 private static final String _FINDER_COLUMN_MX_MX_1 = "company.mx IS NULL";
571 private static final String _FINDER_COLUMN_MX_MX_2 = "company.mx = ?";
572 private static final String _FINDER_COLUMN_MX_MX_3 = "(company.mx IS NULL OR company.mx = '')";
573 public static final FinderPath FINDER_PATH_FETCH_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
574 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
575 FINDER_CLASS_NAME_ENTITY, "fetchByLogoId",
576 new String[] { Long.class.getName() },
577 CompanyModelImpl.LOGOID_COLUMN_BITMASK);
578 public static final FinderPath FINDER_PATH_COUNT_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
579 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
580 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLogoId",
581 new String[] { Long.class.getName() });
582
583
591 @Override
592 public Company findByLogoId(long logoId)
593 throws NoSuchCompanyException, SystemException {
594 Company company = fetchByLogoId(logoId);
595
596 if (company == null) {
597 StringBundler msg = new StringBundler(4);
598
599 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
600
601 msg.append("logoId=");
602 msg.append(logoId);
603
604 msg.append(StringPool.CLOSE_CURLY_BRACE);
605
606 if (_log.isWarnEnabled()) {
607 _log.warn(msg.toString());
608 }
609
610 throw new NoSuchCompanyException(msg.toString());
611 }
612
613 return company;
614 }
615
616
623 @Override
624 public Company fetchByLogoId(long logoId) throws SystemException {
625 return fetchByLogoId(logoId, true);
626 }
627
628
636 @Override
637 public Company fetchByLogoId(long logoId, boolean retrieveFromCache)
638 throws SystemException {
639 Object[] finderArgs = new Object[] { logoId };
640
641 Object result = null;
642
643 if (retrieveFromCache) {
644 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LOGOID,
645 finderArgs, this);
646 }
647
648 if (result instanceof Company) {
649 Company company = (Company)result;
650
651 if ((logoId != company.getLogoId())) {
652 result = null;
653 }
654 }
655
656 if (result == null) {
657 StringBundler query = new StringBundler(3);
658
659 query.append(_SQL_SELECT_COMPANY_WHERE);
660
661 query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
662
663 String sql = query.toString();
664
665 Session session = null;
666
667 try {
668 session = openSession();
669
670 Query q = session.createQuery(sql);
671
672 QueryPos qPos = QueryPos.getInstance(q);
673
674 qPos.add(logoId);
675
676 List<Company> list = q.list();
677
678 if (list.isEmpty()) {
679 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
680 finderArgs, list);
681 }
682 else {
683 if ((list.size() > 1) && _log.isWarnEnabled()) {
684 _log.warn(
685 "CompanyPersistenceImpl.fetchByLogoId(long, boolean) with parameters (" +
686 StringUtil.merge(finderArgs) +
687 ") 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.");
688 }
689
690 Company company = list.get(0);
691
692 result = company;
693
694 cacheResult(company);
695
696 if ((company.getLogoId() != logoId)) {
697 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
698 finderArgs, company);
699 }
700 }
701 }
702 catch (Exception e) {
703 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
704 finderArgs);
705
706 throw processException(e);
707 }
708 finally {
709 closeSession(session);
710 }
711 }
712
713 if (result instanceof List<?>) {
714 return null;
715 }
716 else {
717 return (Company)result;
718 }
719 }
720
721
728 @Override
729 public Company removeByLogoId(long logoId)
730 throws NoSuchCompanyException, SystemException {
731 Company company = findByLogoId(logoId);
732
733 return remove(company);
734 }
735
736
743 @Override
744 public int countByLogoId(long logoId) throws SystemException {
745 FinderPath finderPath = FINDER_PATH_COUNT_BY_LOGOID;
746
747 Object[] finderArgs = new Object[] { logoId };
748
749 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
750 this);
751
752 if (count == null) {
753 StringBundler query = new StringBundler(2);
754
755 query.append(_SQL_COUNT_COMPANY_WHERE);
756
757 query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
758
759 String sql = query.toString();
760
761 Session session = null;
762
763 try {
764 session = openSession();
765
766 Query q = session.createQuery(sql);
767
768 QueryPos qPos = QueryPos.getInstance(q);
769
770 qPos.add(logoId);
771
772 count = (Long)q.uniqueResult();
773
774 FinderCacheUtil.putResult(finderPath, finderArgs, count);
775 }
776 catch (Exception e) {
777 FinderCacheUtil.removeResult(finderPath, finderArgs);
778
779 throw processException(e);
780 }
781 finally {
782 closeSession(session);
783 }
784 }
785
786 return count.intValue();
787 }
788
789 private static final String _FINDER_COLUMN_LOGOID_LOGOID_2 = "company.logoId = ?";
790 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
791 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
792 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySystem",
793 new String[] {
794 Boolean.class.getName(),
795
796 Integer.class.getName(), Integer.class.getName(),
797 OrderByComparator.class.getName()
798 });
799 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM =
800 new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
801 CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
802 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySystem",
803 new String[] { Boolean.class.getName() },
804 CompanyModelImpl.SYSTEM_COLUMN_BITMASK);
805 public static final FinderPath FINDER_PATH_COUNT_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
806 CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
807 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySystem",
808 new String[] { Boolean.class.getName() });
809
810
817 @Override
818 public List<Company> findBySystem(boolean system) throws SystemException {
819 return findBySystem(system, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
820 }
821
822
835 @Override
836 public List<Company> findBySystem(boolean system, int start, int end)
837 throws SystemException {
838 return findBySystem(system, start, end, null);
839 }
840
841
855 @Override
856 public List<Company> findBySystem(boolean system, int start, int end,
857 OrderByComparator orderByComparator) throws SystemException {
858 boolean pagination = true;
859 FinderPath finderPath = null;
860 Object[] finderArgs = null;
861
862 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
863 (orderByComparator == null)) {
864 pagination = false;
865 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM;
866 finderArgs = new Object[] { system };
867 }
868 else {
869 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM;
870 finderArgs = new Object[] { system, start, end, orderByComparator };
871 }
872
873 List<Company> list = (List<Company>)FinderCacheUtil.getResult(finderPath,
874 finderArgs, this);
875
876 if ((list != null) && !list.isEmpty()) {
877 for (Company company : list) {
878 if ((system != company.getSystem())) {
879 list = null;
880
881 break;
882 }
883 }
884 }
885
886 if (list == null) {
887 StringBundler query = null;
888
889 if (orderByComparator != null) {
890 query = new StringBundler(3 +
891 (orderByComparator.getOrderByFields().length * 3));
892 }
893 else {
894 query = new StringBundler(3);
895 }
896
897 query.append(_SQL_SELECT_COMPANY_WHERE);
898
899 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
900
901 if (orderByComparator != null) {
902 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
903 orderByComparator);
904 }
905 else
906 if (pagination) {
907 query.append(CompanyModelImpl.ORDER_BY_JPQL);
908 }
909
910 String sql = query.toString();
911
912 Session session = null;
913
914 try {
915 session = openSession();
916
917 Query q = session.createQuery(sql);
918
919 QueryPos qPos = QueryPos.getInstance(q);
920
921 qPos.add(system);
922
923 if (!pagination) {
924 list = (List<Company>)QueryUtil.list(q, getDialect(),
925 start, end, false);
926
927 Collections.sort(list);
928
929 list = new UnmodifiableList<Company>(list);
930 }
931 else {
932 list = (List<Company>)QueryUtil.list(q, getDialect(),
933 start, end);
934 }
935
936 cacheResult(list);
937
938 FinderCacheUtil.putResult(finderPath, finderArgs, list);
939 }
940 catch (Exception e) {
941 FinderCacheUtil.removeResult(finderPath, finderArgs);
942
943 throw processException(e);
944 }
945 finally {
946 closeSession(session);
947 }
948 }
949
950 return list;
951 }
952
953
962 @Override
963 public Company findBySystem_First(boolean system,
964 OrderByComparator orderByComparator)
965 throws NoSuchCompanyException, SystemException {
966 Company company = fetchBySystem_First(system, orderByComparator);
967
968 if (company != null) {
969 return company;
970 }
971
972 StringBundler msg = new StringBundler(4);
973
974 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
975
976 msg.append("system=");
977 msg.append(system);
978
979 msg.append(StringPool.CLOSE_CURLY_BRACE);
980
981 throw new NoSuchCompanyException(msg.toString());
982 }
983
984
992 @Override
993 public Company fetchBySystem_First(boolean system,
994 OrderByComparator orderByComparator) throws SystemException {
995 List<Company> list = findBySystem(system, 0, 1, orderByComparator);
996
997 if (!list.isEmpty()) {
998 return list.get(0);
999 }
1000
1001 return null;
1002 }
1003
1004
1013 @Override
1014 public Company findBySystem_Last(boolean system,
1015 OrderByComparator orderByComparator)
1016 throws NoSuchCompanyException, SystemException {
1017 Company company = fetchBySystem_Last(system, orderByComparator);
1018
1019 if (company != null) {
1020 return company;
1021 }
1022
1023 StringBundler msg = new StringBundler(4);
1024
1025 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1026
1027 msg.append("system=");
1028 msg.append(system);
1029
1030 msg.append(StringPool.CLOSE_CURLY_BRACE);
1031
1032 throw new NoSuchCompanyException(msg.toString());
1033 }
1034
1035
1043 @Override
1044 public Company fetchBySystem_Last(boolean system,
1045 OrderByComparator orderByComparator) throws SystemException {
1046 int count = countBySystem(system);
1047
1048 if (count == 0) {
1049 return null;
1050 }
1051
1052 List<Company> list = findBySystem(system, count - 1, count,
1053 orderByComparator);
1054
1055 if (!list.isEmpty()) {
1056 return list.get(0);
1057 }
1058
1059 return null;
1060 }
1061
1062
1072 @Override
1073 public Company[] findBySystem_PrevAndNext(long companyId, boolean system,
1074 OrderByComparator orderByComparator)
1075 throws NoSuchCompanyException, SystemException {
1076 Company company = findByPrimaryKey(companyId);
1077
1078 Session session = null;
1079
1080 try {
1081 session = openSession();
1082
1083 Company[] array = new CompanyImpl[3];
1084
1085 array[0] = getBySystem_PrevAndNext(session, company, system,
1086 orderByComparator, true);
1087
1088 array[1] = company;
1089
1090 array[2] = getBySystem_PrevAndNext(session, company, system,
1091 orderByComparator, false);
1092
1093 return array;
1094 }
1095 catch (Exception e) {
1096 throw processException(e);
1097 }
1098 finally {
1099 closeSession(session);
1100 }
1101 }
1102
1103 protected Company getBySystem_PrevAndNext(Session session, Company company,
1104 boolean system, OrderByComparator orderByComparator, boolean previous) {
1105 StringBundler query = null;
1106
1107 if (orderByComparator != null) {
1108 query = new StringBundler(6 +
1109 (orderByComparator.getOrderByFields().length * 6));
1110 }
1111 else {
1112 query = new StringBundler(3);
1113 }
1114
1115 query.append(_SQL_SELECT_COMPANY_WHERE);
1116
1117 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1118
1119 if (orderByComparator != null) {
1120 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1121
1122 if (orderByConditionFields.length > 0) {
1123 query.append(WHERE_AND);
1124 }
1125
1126 for (int i = 0; i < orderByConditionFields.length; i++) {
1127 query.append(_ORDER_BY_ENTITY_ALIAS);
1128 query.append(orderByConditionFields[i]);
1129
1130 if ((i + 1) < orderByConditionFields.length) {
1131 if (orderByComparator.isAscending() ^ previous) {
1132 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1133 }
1134 else {
1135 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1136 }
1137 }
1138 else {
1139 if (orderByComparator.isAscending() ^ previous) {
1140 query.append(WHERE_GREATER_THAN);
1141 }
1142 else {
1143 query.append(WHERE_LESSER_THAN);
1144 }
1145 }
1146 }
1147
1148 query.append(ORDER_BY_CLAUSE);
1149
1150 String[] orderByFields = orderByComparator.getOrderByFields();
1151
1152 for (int i = 0; i < orderByFields.length; i++) {
1153 query.append(_ORDER_BY_ENTITY_ALIAS);
1154 query.append(orderByFields[i]);
1155
1156 if ((i + 1) < orderByFields.length) {
1157 if (orderByComparator.isAscending() ^ previous) {
1158 query.append(ORDER_BY_ASC_HAS_NEXT);
1159 }
1160 else {
1161 query.append(ORDER_BY_DESC_HAS_NEXT);
1162 }
1163 }
1164 else {
1165 if (orderByComparator.isAscending() ^ previous) {
1166 query.append(ORDER_BY_ASC);
1167 }
1168 else {
1169 query.append(ORDER_BY_DESC);
1170 }
1171 }
1172 }
1173 }
1174 else {
1175 query.append(CompanyModelImpl.ORDER_BY_JPQL);
1176 }
1177
1178 String sql = query.toString();
1179
1180 Query q = session.createQuery(sql);
1181
1182 q.setFirstResult(0);
1183 q.setMaxResults(2);
1184
1185 QueryPos qPos = QueryPos.getInstance(q);
1186
1187 qPos.add(system);
1188
1189 if (orderByComparator != null) {
1190 Object[] values = orderByComparator.getOrderByConditionValues(company);
1191
1192 for (Object value : values) {
1193 qPos.add(value);
1194 }
1195 }
1196
1197 List<Company> list = q.list();
1198
1199 if (list.size() == 2) {
1200 return list.get(1);
1201 }
1202 else {
1203 return null;
1204 }
1205 }
1206
1207
1213 @Override
1214 public void removeBySystem(boolean system) throws SystemException {
1215 for (Company company : findBySystem(system, QueryUtil.ALL_POS,
1216 QueryUtil.ALL_POS, null)) {
1217 remove(company);
1218 }
1219 }
1220
1221
1228 @Override
1229 public int countBySystem(boolean system) throws SystemException {
1230 FinderPath finderPath = FINDER_PATH_COUNT_BY_SYSTEM;
1231
1232 Object[] finderArgs = new Object[] { system };
1233
1234 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1235 this);
1236
1237 if (count == null) {
1238 StringBundler query = new StringBundler(2);
1239
1240 query.append(_SQL_COUNT_COMPANY_WHERE);
1241
1242 query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1243
1244 String sql = query.toString();
1245
1246 Session session = null;
1247
1248 try {
1249 session = openSession();
1250
1251 Query q = session.createQuery(sql);
1252
1253 QueryPos qPos = QueryPos.getInstance(q);
1254
1255 qPos.add(system);
1256
1257 count = (Long)q.uniqueResult();
1258
1259 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1260 }
1261 catch (Exception e) {
1262 FinderCacheUtil.removeResult(finderPath, finderArgs);
1263
1264 throw processException(e);
1265 }
1266 finally {
1267 closeSession(session);
1268 }
1269 }
1270
1271 return count.intValue();
1272 }
1273
1274 private static final String _FINDER_COLUMN_SYSTEM_SYSTEM_2 = "company.system = ?";
1275
1276
1281 @Override
1282 public void cacheResult(Company company) {
1283 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1284 CompanyImpl.class, company.getPrimaryKey(), company);
1285
1286 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
1287 new Object[] { company.getWebId() }, company);
1288
1289 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
1290 new Object[] { company.getMx() }, company);
1291
1292 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
1293 new Object[] { company.getLogoId() }, company);
1294
1295 company.resetOriginalValues();
1296 }
1297
1298
1303 @Override
1304 public void cacheResult(List<Company> companies) {
1305 for (Company company : companies) {
1306 if (EntityCacheUtil.getResult(
1307 CompanyModelImpl.ENTITY_CACHE_ENABLED,
1308 CompanyImpl.class, company.getPrimaryKey()) == null) {
1309 cacheResult(company);
1310 }
1311 else {
1312 company.resetOriginalValues();
1313 }
1314 }
1315 }
1316
1317
1324 @Override
1325 public void clearCache() {
1326 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1327 CacheRegistryUtil.clear(CompanyImpl.class.getName());
1328 }
1329
1330 EntityCacheUtil.clearCache(CompanyImpl.class.getName());
1331
1332 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1333 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1334 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1335 }
1336
1337
1344 @Override
1345 public void clearCache(Company company) {
1346 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1347 CompanyImpl.class, company.getPrimaryKey());
1348
1349 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1350 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1351
1352 clearUniqueFindersCache(company);
1353 }
1354
1355 @Override
1356 public void clearCache(List<Company> companies) {
1357 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1358 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1359
1360 for (Company company : companies) {
1361 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1362 CompanyImpl.class, company.getPrimaryKey());
1363
1364 clearUniqueFindersCache(company);
1365 }
1366 }
1367
1368 protected void cacheUniqueFindersCache(Company company) {
1369 if (company.isNew()) {
1370 Object[] args = new Object[] { company.getWebId() };
1371
1372 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1373 Long.valueOf(1));
1374 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID, args, company);
1375
1376 args = new Object[] { company.getMx() };
1377
1378 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MX, args,
1379 Long.valueOf(1));
1380 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX, args, company);
1381
1382 args = new Object[] { company.getLogoId() };
1383
1384 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1385 Long.valueOf(1));
1386 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID, args, company);
1387 }
1388 else {
1389 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1390
1391 if ((companyModelImpl.getColumnBitmask() &
1392 FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1393 Object[] args = new Object[] { company.getWebId() };
1394
1395 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1396 Long.valueOf(1));
1397 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID, args,
1398 company);
1399 }
1400
1401 if ((companyModelImpl.getColumnBitmask() &
1402 FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1403 Object[] args = new Object[] { company.getMx() };
1404
1405 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MX, args,
1406 Long.valueOf(1));
1407 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX, args, company);
1408 }
1409
1410 if ((companyModelImpl.getColumnBitmask() &
1411 FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1412 Object[] args = new Object[] { company.getLogoId() };
1413
1414 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1415 Long.valueOf(1));
1416 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID, args,
1417 company);
1418 }
1419 }
1420 }
1421
1422 protected void clearUniqueFindersCache(Company company) {
1423 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1424
1425 Object[] args = new Object[] { company.getWebId() };
1426
1427 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1428 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1429
1430 if ((companyModelImpl.getColumnBitmask() &
1431 FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1432 args = new Object[] { companyModelImpl.getOriginalWebId() };
1433
1434 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1435 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1436 }
1437
1438 args = new Object[] { company.getMx() };
1439
1440 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1441 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1442
1443 if ((companyModelImpl.getColumnBitmask() &
1444 FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1445 args = new Object[] { companyModelImpl.getOriginalMx() };
1446
1447 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1448 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1449 }
1450
1451 args = new Object[] { company.getLogoId() };
1452
1453 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1454 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1455
1456 if ((companyModelImpl.getColumnBitmask() &
1457 FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1458 args = new Object[] { companyModelImpl.getOriginalLogoId() };
1459
1460 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1461 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1462 }
1463 }
1464
1465
1471 @Override
1472 public Company create(long companyId) {
1473 Company company = new CompanyImpl();
1474
1475 company.setNew(true);
1476 company.setPrimaryKey(companyId);
1477
1478 return company;
1479 }
1480
1481
1489 @Override
1490 public Company remove(long companyId)
1491 throws NoSuchCompanyException, SystemException {
1492 return remove((Serializable)companyId);
1493 }
1494
1495
1503 @Override
1504 public Company remove(Serializable primaryKey)
1505 throws NoSuchCompanyException, SystemException {
1506 Session session = null;
1507
1508 try {
1509 session = openSession();
1510
1511 Company company = (Company)session.get(CompanyImpl.class, primaryKey);
1512
1513 if (company == null) {
1514 if (_log.isWarnEnabled()) {
1515 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1516 }
1517
1518 throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1519 primaryKey);
1520 }
1521
1522 return remove(company);
1523 }
1524 catch (NoSuchCompanyException nsee) {
1525 throw nsee;
1526 }
1527 catch (Exception e) {
1528 throw processException(e);
1529 }
1530 finally {
1531 closeSession(session);
1532 }
1533 }
1534
1535 @Override
1536 protected Company removeImpl(Company company) throws SystemException {
1537 company = toUnwrappedModel(company);
1538
1539 Session session = null;
1540
1541 try {
1542 session = openSession();
1543
1544 if (!session.contains(company)) {
1545 company = (Company)session.get(CompanyImpl.class,
1546 company.getPrimaryKeyObj());
1547 }
1548
1549 if (company != null) {
1550 session.delete(company);
1551 }
1552 }
1553 catch (Exception e) {
1554 throw processException(e);
1555 }
1556 finally {
1557 closeSession(session);
1558 }
1559
1560 if (company != null) {
1561 clearCache(company);
1562 }
1563
1564 return company;
1565 }
1566
1567 @Override
1568 public Company updateImpl(com.liferay.portal.model.Company company)
1569 throws SystemException {
1570 company = toUnwrappedModel(company);
1571
1572 boolean isNew = company.isNew();
1573
1574 CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1575
1576 Session session = null;
1577
1578 try {
1579 session = openSession();
1580
1581 if (company.isNew()) {
1582 session.save(company);
1583
1584 company.setNew(false);
1585 }
1586 else {
1587 session.merge(company);
1588 }
1589 }
1590 catch (Exception e) {
1591 throw processException(e);
1592 }
1593 finally {
1594 closeSession(session);
1595 }
1596
1597 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1598
1599 if (isNew || !CompanyModelImpl.COLUMN_BITMASK_ENABLED) {
1600 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1601 }
1602
1603 else {
1604 if ((companyModelImpl.getColumnBitmask() &
1605 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM.getColumnBitmask()) != 0) {
1606 Object[] args = new Object[] {
1607 companyModelImpl.getOriginalSystem()
1608 };
1609
1610 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1611 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1612 args);
1613
1614 args = new Object[] { companyModelImpl.getSystem() };
1615
1616 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1617 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1618 args);
1619 }
1620 }
1621
1622 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1623 CompanyImpl.class, company.getPrimaryKey(), company);
1624
1625 clearUniqueFindersCache(company);
1626 cacheUniqueFindersCache(company);
1627
1628 return company;
1629 }
1630
1631 protected Company toUnwrappedModel(Company company) {
1632 if (company instanceof CompanyImpl) {
1633 return company;
1634 }
1635
1636 CompanyImpl companyImpl = new CompanyImpl();
1637
1638 companyImpl.setNew(company.isNew());
1639 companyImpl.setPrimaryKey(company.getPrimaryKey());
1640
1641 companyImpl.setCompanyId(company.getCompanyId());
1642 companyImpl.setAccountId(company.getAccountId());
1643 companyImpl.setWebId(company.getWebId());
1644 companyImpl.setKey(company.getKey());
1645 companyImpl.setMx(company.getMx());
1646 companyImpl.setHomeURL(company.getHomeURL());
1647 companyImpl.setLogoId(company.getLogoId());
1648 companyImpl.setSystem(company.isSystem());
1649 companyImpl.setMaxUsers(company.getMaxUsers());
1650 companyImpl.setActive(company.isActive());
1651
1652 return companyImpl;
1653 }
1654
1655
1663 @Override
1664 public Company findByPrimaryKey(Serializable primaryKey)
1665 throws NoSuchCompanyException, SystemException {
1666 Company company = fetchByPrimaryKey(primaryKey);
1667
1668 if (company == null) {
1669 if (_log.isWarnEnabled()) {
1670 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1671 }
1672
1673 throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1674 primaryKey);
1675 }
1676
1677 return company;
1678 }
1679
1680
1688 @Override
1689 public Company findByPrimaryKey(long companyId)
1690 throws NoSuchCompanyException, SystemException {
1691 return findByPrimaryKey((Serializable)companyId);
1692 }
1693
1694
1701 @Override
1702 public Company fetchByPrimaryKey(Serializable primaryKey)
1703 throws SystemException {
1704 Company company = (Company)EntityCacheUtil.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1705 CompanyImpl.class, primaryKey);
1706
1707 if (company == _nullCompany) {
1708 return null;
1709 }
1710
1711 if (company == null) {
1712 Session session = null;
1713
1714 try {
1715 session = openSession();
1716
1717 company = (Company)session.get(CompanyImpl.class, primaryKey);
1718
1719 if (company != null) {
1720 cacheResult(company);
1721 }
1722 else {
1723 EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1724 CompanyImpl.class, primaryKey, _nullCompany);
1725 }
1726 }
1727 catch (Exception e) {
1728 EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1729 CompanyImpl.class, primaryKey);
1730
1731 throw processException(e);
1732 }
1733 finally {
1734 closeSession(session);
1735 }
1736 }
1737
1738 return company;
1739 }
1740
1741
1748 @Override
1749 public Company fetchByPrimaryKey(long companyId) throws SystemException {
1750 return fetchByPrimaryKey((Serializable)companyId);
1751 }
1752
1753
1759 @Override
1760 public List<Company> findAll() throws SystemException {
1761 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1762 }
1763
1764
1776 @Override
1777 public List<Company> findAll(int start, int end) throws SystemException {
1778 return findAll(start, end, null);
1779 }
1780
1781
1794 @Override
1795 public List<Company> findAll(int start, int end,
1796 OrderByComparator orderByComparator) throws SystemException {
1797 boolean pagination = true;
1798 FinderPath finderPath = null;
1799 Object[] finderArgs = null;
1800
1801 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1802 (orderByComparator == null)) {
1803 pagination = false;
1804 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1805 finderArgs = FINDER_ARGS_EMPTY;
1806 }
1807 else {
1808 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1809 finderArgs = new Object[] { start, end, orderByComparator };
1810 }
1811
1812 List<Company> list = (List<Company>)FinderCacheUtil.getResult(finderPath,
1813 finderArgs, this);
1814
1815 if (list == null) {
1816 StringBundler query = null;
1817 String sql = null;
1818
1819 if (orderByComparator != null) {
1820 query = new StringBundler(2 +
1821 (orderByComparator.getOrderByFields().length * 3));
1822
1823 query.append(_SQL_SELECT_COMPANY);
1824
1825 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1826 orderByComparator);
1827
1828 sql = query.toString();
1829 }
1830 else {
1831 sql = _SQL_SELECT_COMPANY;
1832
1833 if (pagination) {
1834 sql = sql.concat(CompanyModelImpl.ORDER_BY_JPQL);
1835 }
1836 }
1837
1838 Session session = null;
1839
1840 try {
1841 session = openSession();
1842
1843 Query q = session.createQuery(sql);
1844
1845 if (!pagination) {
1846 list = (List<Company>)QueryUtil.list(q, getDialect(),
1847 start, end, false);
1848
1849 Collections.sort(list);
1850
1851 list = new UnmodifiableList<Company>(list);
1852 }
1853 else {
1854 list = (List<Company>)QueryUtil.list(q, getDialect(),
1855 start, end);
1856 }
1857
1858 cacheResult(list);
1859
1860 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1861 }
1862 catch (Exception e) {
1863 FinderCacheUtil.removeResult(finderPath, finderArgs);
1864
1865 throw processException(e);
1866 }
1867 finally {
1868 closeSession(session);
1869 }
1870 }
1871
1872 return list;
1873 }
1874
1875
1880 @Override
1881 public void removeAll() throws SystemException {
1882 for (Company company : findAll()) {
1883 remove(company);
1884 }
1885 }
1886
1887
1893 @Override
1894 public int countAll() throws SystemException {
1895 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1896 FINDER_ARGS_EMPTY, this);
1897
1898 if (count == null) {
1899 Session session = null;
1900
1901 try {
1902 session = openSession();
1903
1904 Query q = session.createQuery(_SQL_COUNT_COMPANY);
1905
1906 count = (Long)q.uniqueResult();
1907
1908 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1909 FINDER_ARGS_EMPTY, count);
1910 }
1911 catch (Exception e) {
1912 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1913 FINDER_ARGS_EMPTY);
1914
1915 throw processException(e);
1916 }
1917 finally {
1918 closeSession(session);
1919 }
1920 }
1921
1922 return count.intValue();
1923 }
1924
1925 @Override
1926 protected Set<String> getBadColumnNames() {
1927 return _badColumnNames;
1928 }
1929
1930
1933 public void afterPropertiesSet() {
1934 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1935 com.liferay.portal.util.PropsUtil.get(
1936 "value.object.listener.com.liferay.portal.model.Company")));
1937
1938 if (listenerClassNames.length > 0) {
1939 try {
1940 List<ModelListener<Company>> listenersList = new ArrayList<ModelListener<Company>>();
1941
1942 for (String listenerClassName : listenerClassNames) {
1943 listenersList.add((ModelListener<Company>)InstanceFactory.newInstance(
1944 getClassLoader(), listenerClassName));
1945 }
1946
1947 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1948 }
1949 catch (Exception e) {
1950 _log.error(e);
1951 }
1952 }
1953 }
1954
1955 public void destroy() {
1956 EntityCacheUtil.removeCache(CompanyImpl.class.getName());
1957 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1958 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1959 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1960 }
1961
1962 private static final String _SQL_SELECT_COMPANY = "SELECT company FROM Company company";
1963 private static final String _SQL_SELECT_COMPANY_WHERE = "SELECT company FROM Company company WHERE ";
1964 private static final String _SQL_COUNT_COMPANY = "SELECT COUNT(company) FROM Company company";
1965 private static final String _SQL_COUNT_COMPANY_WHERE = "SELECT COUNT(company) FROM Company company WHERE ";
1966 private static final String _ORDER_BY_ENTITY_ALIAS = "company.";
1967 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Company exists with the primary key ";
1968 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Company exists with the key {";
1969 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1970 private static Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
1971 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1972 "key", "active"
1973 });
1974 private static Company _nullCompany = new CompanyImpl() {
1975 @Override
1976 public Object clone() {
1977 return this;
1978 }
1979
1980 @Override
1981 public CacheModel<Company> toCacheModel() {
1982 return _nullCompanyCacheModel;
1983 }
1984 };
1985
1986 private static CacheModel<Company> _nullCompanyCacheModel = new CacheModel<Company>() {
1987 @Override
1988 public Company toEntityModel() {
1989 return _nullCompany;
1990 }
1991 };
1992 }