001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchClassNameException;
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.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.Validator;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.model.ClassName;
035 import com.liferay.portal.model.MVCCModel;
036 import com.liferay.portal.model.impl.ClassNameImpl;
037 import com.liferay.portal.model.impl.ClassNameModelImpl;
038 import com.liferay.portal.service.persistence.ClassNamePersistence;
039
040 import java.io.Serializable;
041
042 import java.util.Collections;
043 import java.util.HashMap;
044 import java.util.HashSet;
045 import java.util.Iterator;
046 import java.util.List;
047 import java.util.Map;
048 import java.util.Set;
049
050
062 @ProviderType
063 public class ClassNamePersistenceImpl extends BasePersistenceImpl<ClassName>
064 implements ClassNamePersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ClassNameImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
076 ClassNameModelImpl.FINDER_CACHE_ENABLED, ClassNameImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
079 ClassNameModelImpl.FINDER_CACHE_ENABLED, ClassNameImpl.class,
080 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
082 ClassNameModelImpl.FINDER_CACHE_ENABLED, Long.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084 public static final FinderPath FINDER_PATH_FETCH_BY_VALUE = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
085 ClassNameModelImpl.FINDER_CACHE_ENABLED, ClassNameImpl.class,
086 FINDER_CLASS_NAME_ENTITY, "fetchByValue",
087 new String[] { String.class.getName() },
088 ClassNameModelImpl.VALUE_COLUMN_BITMASK);
089 public static final FinderPath FINDER_PATH_COUNT_BY_VALUE = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
090 ClassNameModelImpl.FINDER_CACHE_ENABLED, Long.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByValue",
092 new String[] { String.class.getName() });
093
094
101 @Override
102 public ClassName findByValue(String value) throws NoSuchClassNameException {
103 ClassName className = fetchByValue(value);
104
105 if (className == null) {
106 StringBundler msg = new StringBundler(4);
107
108 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
109
110 msg.append("value=");
111 msg.append(value);
112
113 msg.append(StringPool.CLOSE_CURLY_BRACE);
114
115 if (_log.isWarnEnabled()) {
116 _log.warn(msg.toString());
117 }
118
119 throw new NoSuchClassNameException(msg.toString());
120 }
121
122 return className;
123 }
124
125
131 @Override
132 public ClassName fetchByValue(String value) {
133 return fetchByValue(value, true);
134 }
135
136
143 @Override
144 public ClassName fetchByValue(String value, boolean retrieveFromCache) {
145 Object[] finderArgs = new Object[] { value };
146
147 Object result = null;
148
149 if (retrieveFromCache) {
150 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VALUE,
151 finderArgs, this);
152 }
153
154 if (result instanceof ClassName) {
155 ClassName className = (ClassName)result;
156
157 if (!Validator.equals(value, className.getValue())) {
158 result = null;
159 }
160 }
161
162 if (result == null) {
163 StringBundler query = new StringBundler(3);
164
165 query.append(_SQL_SELECT_CLASSNAME_WHERE);
166
167 boolean bindValue = false;
168
169 if (value == null) {
170 query.append(_FINDER_COLUMN_VALUE_VALUE_1);
171 }
172 else if (value.equals(StringPool.BLANK)) {
173 query.append(_FINDER_COLUMN_VALUE_VALUE_3);
174 }
175 else {
176 bindValue = true;
177
178 query.append(_FINDER_COLUMN_VALUE_VALUE_2);
179 }
180
181 String sql = query.toString();
182
183 Session session = null;
184
185 try {
186 session = openSession();
187
188 Query q = session.createQuery(sql);
189
190 QueryPos qPos = QueryPos.getInstance(q);
191
192 if (bindValue) {
193 qPos.add(value);
194 }
195
196 List<ClassName> list = q.list();
197
198 if (list.isEmpty()) {
199 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
200 finderArgs, list);
201 }
202 else {
203 ClassName className = list.get(0);
204
205 result = className;
206
207 cacheResult(className);
208
209 if ((className.getValue() == null) ||
210 !className.getValue().equals(value)) {
211 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
212 finderArgs, className);
213 }
214 }
215 }
216 catch (Exception e) {
217 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VALUE,
218 finderArgs);
219
220 throw processException(e);
221 }
222 finally {
223 closeSession(session);
224 }
225 }
226
227 if (result instanceof List<?>) {
228 return null;
229 }
230 else {
231 return (ClassName)result;
232 }
233 }
234
235
241 @Override
242 public ClassName removeByValue(String value)
243 throws NoSuchClassNameException {
244 ClassName className = findByValue(value);
245
246 return remove(className);
247 }
248
249
255 @Override
256 public int countByValue(String value) {
257 FinderPath finderPath = FINDER_PATH_COUNT_BY_VALUE;
258
259 Object[] finderArgs = new Object[] { value };
260
261 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
262 this);
263
264 if (count == null) {
265 StringBundler query = new StringBundler(2);
266
267 query.append(_SQL_COUNT_CLASSNAME_WHERE);
268
269 boolean bindValue = false;
270
271 if (value == null) {
272 query.append(_FINDER_COLUMN_VALUE_VALUE_1);
273 }
274 else if (value.equals(StringPool.BLANK)) {
275 query.append(_FINDER_COLUMN_VALUE_VALUE_3);
276 }
277 else {
278 bindValue = true;
279
280 query.append(_FINDER_COLUMN_VALUE_VALUE_2);
281 }
282
283 String sql = query.toString();
284
285 Session session = null;
286
287 try {
288 session = openSession();
289
290 Query q = session.createQuery(sql);
291
292 QueryPos qPos = QueryPos.getInstance(q);
293
294 if (bindValue) {
295 qPos.add(value);
296 }
297
298 count = (Long)q.uniqueResult();
299
300 FinderCacheUtil.putResult(finderPath, finderArgs, count);
301 }
302 catch (Exception e) {
303 FinderCacheUtil.removeResult(finderPath, finderArgs);
304
305 throw processException(e);
306 }
307 finally {
308 closeSession(session);
309 }
310 }
311
312 return count.intValue();
313 }
314
315 private static final String _FINDER_COLUMN_VALUE_VALUE_1 = "className.value IS NULL";
316 private static final String _FINDER_COLUMN_VALUE_VALUE_2 = "className.value = ?";
317 private static final String _FINDER_COLUMN_VALUE_VALUE_3 = "(className.value IS NULL OR className.value = '')";
318
319 public ClassNamePersistenceImpl() {
320 setModelClass(ClassName.class);
321 }
322
323
328 @Override
329 public void cacheResult(ClassName className) {
330 EntityCacheUtil.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
331 ClassNameImpl.class, className.getPrimaryKey(), className);
332
333 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
334 new Object[] { className.getValue() }, className);
335
336 className.resetOriginalValues();
337 }
338
339
344 @Override
345 public void cacheResult(List<ClassName> classNames) {
346 for (ClassName className : classNames) {
347 if (EntityCacheUtil.getResult(
348 ClassNameModelImpl.ENTITY_CACHE_ENABLED,
349 ClassNameImpl.class, className.getPrimaryKey()) == null) {
350 cacheResult(className);
351 }
352 else {
353 className.resetOriginalValues();
354 }
355 }
356 }
357
358
365 @Override
366 public void clearCache() {
367 EntityCacheUtil.clearCache(ClassNameImpl.class);
368
369 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
370 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
371 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
372 }
373
374
381 @Override
382 public void clearCache(ClassName className) {
383 EntityCacheUtil.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
384 ClassNameImpl.class, className.getPrimaryKey());
385
386 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
387 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
388
389 clearUniqueFindersCache(className);
390 }
391
392 @Override
393 public void clearCache(List<ClassName> classNames) {
394 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
395 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
396
397 for (ClassName className : classNames) {
398 EntityCacheUtil.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
399 ClassNameImpl.class, className.getPrimaryKey());
400
401 clearUniqueFindersCache(className);
402 }
403 }
404
405 protected void cacheUniqueFindersCache(ClassName className) {
406 if (className.isNew()) {
407 Object[] args = new Object[] { className.getValue() };
408
409 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VALUE, args,
410 Long.valueOf(1));
411 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE, args,
412 className);
413 }
414 else {
415 ClassNameModelImpl classNameModelImpl = (ClassNameModelImpl)className;
416
417 if ((classNameModelImpl.getColumnBitmask() &
418 FINDER_PATH_FETCH_BY_VALUE.getColumnBitmask()) != 0) {
419 Object[] args = new Object[] { className.getValue() };
420
421 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VALUE, args,
422 Long.valueOf(1));
423 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE, args,
424 className);
425 }
426 }
427 }
428
429 protected void clearUniqueFindersCache(ClassName className) {
430 ClassNameModelImpl classNameModelImpl = (ClassNameModelImpl)className;
431
432 Object[] args = new Object[] { className.getValue() };
433
434 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VALUE, args);
435 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VALUE, args);
436
437 if ((classNameModelImpl.getColumnBitmask() &
438 FINDER_PATH_FETCH_BY_VALUE.getColumnBitmask()) != 0) {
439 args = new Object[] { classNameModelImpl.getOriginalValue() };
440
441 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VALUE, args);
442 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VALUE, args);
443 }
444 }
445
446
452 @Override
453 public ClassName create(long classNameId) {
454 ClassName className = new ClassNameImpl();
455
456 className.setNew(true);
457 className.setPrimaryKey(classNameId);
458
459 return className;
460 }
461
462
469 @Override
470 public ClassName remove(long classNameId) throws NoSuchClassNameException {
471 return remove((Serializable)classNameId);
472 }
473
474
481 @Override
482 public ClassName remove(Serializable primaryKey)
483 throws NoSuchClassNameException {
484 Session session = null;
485
486 try {
487 session = openSession();
488
489 ClassName className = (ClassName)session.get(ClassNameImpl.class,
490 primaryKey);
491
492 if (className == null) {
493 if (_log.isWarnEnabled()) {
494 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
495 }
496
497 throw new NoSuchClassNameException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
498 primaryKey);
499 }
500
501 return remove(className);
502 }
503 catch (NoSuchClassNameException nsee) {
504 throw nsee;
505 }
506 catch (Exception e) {
507 throw processException(e);
508 }
509 finally {
510 closeSession(session);
511 }
512 }
513
514 @Override
515 protected ClassName removeImpl(ClassName className) {
516 className = toUnwrappedModel(className);
517
518 Session session = null;
519
520 try {
521 session = openSession();
522
523 if (!session.contains(className)) {
524 className = (ClassName)session.get(ClassNameImpl.class,
525 className.getPrimaryKeyObj());
526 }
527
528 if (className != null) {
529 session.delete(className);
530 }
531 }
532 catch (Exception e) {
533 throw processException(e);
534 }
535 finally {
536 closeSession(session);
537 }
538
539 if (className != null) {
540 clearCache(className);
541 }
542
543 return className;
544 }
545
546 @Override
547 public ClassName updateImpl(ClassName className) {
548 className = toUnwrappedModel(className);
549
550 boolean isNew = className.isNew();
551
552 Session session = null;
553
554 try {
555 session = openSession();
556
557 if (className.isNew()) {
558 session.save(className);
559
560 className.setNew(false);
561 }
562 else {
563 session.merge(className);
564 }
565 }
566 catch (Exception e) {
567 throw processException(e);
568 }
569 finally {
570 closeSession(session);
571 }
572
573 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
574
575 if (isNew || !ClassNameModelImpl.COLUMN_BITMASK_ENABLED) {
576 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
577 }
578
579 EntityCacheUtil.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
580 ClassNameImpl.class, className.getPrimaryKey(), className, false);
581
582 clearUniqueFindersCache(className);
583 cacheUniqueFindersCache(className);
584
585 className.resetOriginalValues();
586
587 return className;
588 }
589
590 protected ClassName toUnwrappedModel(ClassName className) {
591 if (className instanceof ClassNameImpl) {
592 return className;
593 }
594
595 ClassNameImpl classNameImpl = new ClassNameImpl();
596
597 classNameImpl.setNew(className.isNew());
598 classNameImpl.setPrimaryKey(className.getPrimaryKey());
599
600 classNameImpl.setMvccVersion(className.getMvccVersion());
601 classNameImpl.setClassNameId(className.getClassNameId());
602 classNameImpl.setValue(className.getValue());
603
604 return classNameImpl;
605 }
606
607
614 @Override
615 public ClassName findByPrimaryKey(Serializable primaryKey)
616 throws NoSuchClassNameException {
617 ClassName className = fetchByPrimaryKey(primaryKey);
618
619 if (className == null) {
620 if (_log.isWarnEnabled()) {
621 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
622 }
623
624 throw new NoSuchClassNameException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
625 primaryKey);
626 }
627
628 return className;
629 }
630
631
638 @Override
639 public ClassName findByPrimaryKey(long classNameId)
640 throws NoSuchClassNameException {
641 return findByPrimaryKey((Serializable)classNameId);
642 }
643
644
650 @Override
651 public ClassName fetchByPrimaryKey(Serializable primaryKey) {
652 ClassName className = (ClassName)EntityCacheUtil.getResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
653 ClassNameImpl.class, primaryKey);
654
655 if (className == _nullClassName) {
656 return null;
657 }
658
659 if (className == null) {
660 Session session = null;
661
662 try {
663 session = openSession();
664
665 className = (ClassName)session.get(ClassNameImpl.class,
666 primaryKey);
667
668 if (className != null) {
669 cacheResult(className);
670 }
671 else {
672 EntityCacheUtil.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
673 ClassNameImpl.class, primaryKey, _nullClassName);
674 }
675 }
676 catch (Exception e) {
677 EntityCacheUtil.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
678 ClassNameImpl.class, primaryKey);
679
680 throw processException(e);
681 }
682 finally {
683 closeSession(session);
684 }
685 }
686
687 return className;
688 }
689
690
696 @Override
697 public ClassName fetchByPrimaryKey(long classNameId) {
698 return fetchByPrimaryKey((Serializable)classNameId);
699 }
700
701 @Override
702 public Map<Serializable, ClassName> fetchByPrimaryKeys(
703 Set<Serializable> primaryKeys) {
704 if (primaryKeys.isEmpty()) {
705 return Collections.emptyMap();
706 }
707
708 Map<Serializable, ClassName> map = new HashMap<Serializable, ClassName>();
709
710 if (primaryKeys.size() == 1) {
711 Iterator<Serializable> iterator = primaryKeys.iterator();
712
713 Serializable primaryKey = iterator.next();
714
715 ClassName className = fetchByPrimaryKey(primaryKey);
716
717 if (className != null) {
718 map.put(primaryKey, className);
719 }
720
721 return map;
722 }
723
724 Set<Serializable> uncachedPrimaryKeys = null;
725
726 for (Serializable primaryKey : primaryKeys) {
727 ClassName className = (ClassName)EntityCacheUtil.getResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
728 ClassNameImpl.class, primaryKey);
729
730 if (className == null) {
731 if (uncachedPrimaryKeys == null) {
732 uncachedPrimaryKeys = new HashSet<Serializable>();
733 }
734
735 uncachedPrimaryKeys.add(primaryKey);
736 }
737 else {
738 map.put(primaryKey, className);
739 }
740 }
741
742 if (uncachedPrimaryKeys == null) {
743 return map;
744 }
745
746 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
747 1);
748
749 query.append(_SQL_SELECT_CLASSNAME_WHERE_PKS_IN);
750
751 for (Serializable primaryKey : uncachedPrimaryKeys) {
752 query.append(String.valueOf(primaryKey));
753
754 query.append(StringPool.COMMA);
755 }
756
757 query.setIndex(query.index() - 1);
758
759 query.append(StringPool.CLOSE_PARENTHESIS);
760
761 String sql = query.toString();
762
763 Session session = null;
764
765 try {
766 session = openSession();
767
768 Query q = session.createQuery(sql);
769
770 for (ClassName className : (List<ClassName>)q.list()) {
771 map.put(className.getPrimaryKeyObj(), className);
772
773 cacheResult(className);
774
775 uncachedPrimaryKeys.remove(className.getPrimaryKeyObj());
776 }
777
778 for (Serializable primaryKey : uncachedPrimaryKeys) {
779 EntityCacheUtil.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
780 ClassNameImpl.class, primaryKey, _nullClassName);
781 }
782 }
783 catch (Exception e) {
784 throw processException(e);
785 }
786 finally {
787 closeSession(session);
788 }
789
790 return map;
791 }
792
793
798 @Override
799 public List<ClassName> findAll() {
800 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
801 }
802
803
814 @Override
815 public List<ClassName> findAll(int start, int end) {
816 return findAll(start, end, null);
817 }
818
819
831 @Override
832 public List<ClassName> findAll(int start, int end,
833 OrderByComparator<ClassName> orderByComparator) {
834 boolean pagination = true;
835 FinderPath finderPath = null;
836 Object[] finderArgs = null;
837
838 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
839 (orderByComparator == null)) {
840 pagination = false;
841 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
842 finderArgs = FINDER_ARGS_EMPTY;
843 }
844 else {
845 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
846 finderArgs = new Object[] { start, end, orderByComparator };
847 }
848
849 List<ClassName> list = (List<ClassName>)FinderCacheUtil.getResult(finderPath,
850 finderArgs, this);
851
852 if (list == null) {
853 StringBundler query = null;
854 String sql = null;
855
856 if (orderByComparator != null) {
857 query = new StringBundler(2 +
858 (orderByComparator.getOrderByFields().length * 3));
859
860 query.append(_SQL_SELECT_CLASSNAME);
861
862 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
863 orderByComparator);
864
865 sql = query.toString();
866 }
867 else {
868 sql = _SQL_SELECT_CLASSNAME;
869
870 if (pagination) {
871 sql = sql.concat(ClassNameModelImpl.ORDER_BY_JPQL);
872 }
873 }
874
875 Session session = null;
876
877 try {
878 session = openSession();
879
880 Query q = session.createQuery(sql);
881
882 if (!pagination) {
883 list = (List<ClassName>)QueryUtil.list(q, getDialect(),
884 start, end, false);
885
886 Collections.sort(list);
887
888 list = Collections.unmodifiableList(list);
889 }
890 else {
891 list = (List<ClassName>)QueryUtil.list(q, getDialect(),
892 start, end);
893 }
894
895 cacheResult(list);
896
897 FinderCacheUtil.putResult(finderPath, finderArgs, list);
898 }
899 catch (Exception e) {
900 FinderCacheUtil.removeResult(finderPath, finderArgs);
901
902 throw processException(e);
903 }
904 finally {
905 closeSession(session);
906 }
907 }
908
909 return list;
910 }
911
912
916 @Override
917 public void removeAll() {
918 for (ClassName className : findAll()) {
919 remove(className);
920 }
921 }
922
923
928 @Override
929 public int countAll() {
930 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
931 FINDER_ARGS_EMPTY, this);
932
933 if (count == null) {
934 Session session = null;
935
936 try {
937 session = openSession();
938
939 Query q = session.createQuery(_SQL_COUNT_CLASSNAME);
940
941 count = (Long)q.uniqueResult();
942
943 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
944 FINDER_ARGS_EMPTY, count);
945 }
946 catch (Exception e) {
947 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
948 FINDER_ARGS_EMPTY);
949
950 throw processException(e);
951 }
952 finally {
953 closeSession(session);
954 }
955 }
956
957 return count.intValue();
958 }
959
960
963 public void afterPropertiesSet() {
964 }
965
966 public void destroy() {
967 EntityCacheUtil.removeCache(ClassNameImpl.class.getName());
968 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
969 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
970 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
971 }
972
973 private static final String _SQL_SELECT_CLASSNAME = "SELECT className FROM ClassName className";
974 private static final String _SQL_SELECT_CLASSNAME_WHERE_PKS_IN = "SELECT className FROM ClassName className WHERE classNameId IN (";
975 private static final String _SQL_SELECT_CLASSNAME_WHERE = "SELECT className FROM ClassName className WHERE ";
976 private static final String _SQL_COUNT_CLASSNAME = "SELECT COUNT(className) FROM ClassName className";
977 private static final String _SQL_COUNT_CLASSNAME_WHERE = "SELECT COUNT(className) FROM ClassName className WHERE ";
978 private static final String _ORDER_BY_ENTITY_ALIAS = "className.";
979 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClassName exists with the primary key ";
980 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ClassName exists with the key {";
981 private static final Log _log = LogFactoryUtil.getLog(ClassNamePersistenceImpl.class);
982 private static final ClassName _nullClassName = new ClassNameImpl() {
983 @Override
984 public Object clone() {
985 return this;
986 }
987
988 @Override
989 public CacheModel<ClassName> toCacheModel() {
990 return _nullClassNameCacheModel;
991 }
992 };
993
994 private static final CacheModel<ClassName> _nullClassNameCacheModel = new NullCacheModel();
995
996 private static class NullCacheModel implements CacheModel<ClassName>,
997 MVCCModel {
998 @Override
999 public long getMvccVersion() {
1000 return -1;
1001 }
1002
1003 @Override
1004 public void setMvccVersion(long mvccVersion) {
1005 }
1006
1007 @Override
1008 public ClassName toEntityModel() {
1009 return _nullClassName;
1010 }
1011 }
1012 }