001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchClassNameException;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.ClassName;
037 import com.liferay.portal.model.MVCCModel;
038 import com.liferay.portal.model.impl.ClassNameImpl;
039 import com.liferay.portal.model.impl.ClassNameModelImpl;
040 import com.liferay.portal.service.persistence.ClassNamePersistence;
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 ClassNamePersistenceImpl extends BasePersistenceImpl<ClassName>
066 implements ClassNamePersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = ClassNameImpl.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(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
078 ClassNameModelImpl.FINDER_CACHE_ENABLED, ClassNameImpl.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(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
081 ClassNameModelImpl.FINDER_CACHE_ENABLED, ClassNameImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
084 ClassNameModelImpl.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_VALUE = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
087 ClassNameModelImpl.FINDER_CACHE_ENABLED, ClassNameImpl.class,
088 FINDER_CLASS_NAME_ENTITY, "fetchByValue",
089 new String[] { String.class.getName() },
090 ClassNameModelImpl.VALUE_COLUMN_BITMASK);
091 public static final FinderPath FINDER_PATH_COUNT_BY_VALUE = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
092 ClassNameModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByValue",
094 new String[] { String.class.getName() });
095
096
103 @Override
104 public ClassName findByValue(String value) throws NoSuchClassNameException {
105 ClassName className = fetchByValue(value);
106
107 if (className == null) {
108 StringBundler msg = new StringBundler(4);
109
110 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
111
112 msg.append("value=");
113 msg.append(value);
114
115 msg.append(StringPool.CLOSE_CURLY_BRACE);
116
117 if (_log.isWarnEnabled()) {
118 _log.warn(msg.toString());
119 }
120
121 throw new NoSuchClassNameException(msg.toString());
122 }
123
124 return className;
125 }
126
127
133 @Override
134 public ClassName fetchByValue(String value) {
135 return fetchByValue(value, true);
136 }
137
138
145 @Override
146 public ClassName fetchByValue(String value, boolean retrieveFromCache) {
147 Object[] finderArgs = new Object[] { value };
148
149 Object result = null;
150
151 if (retrieveFromCache) {
152 result = finderCache.getResult(FINDER_PATH_FETCH_BY_VALUE,
153 finderArgs, this);
154 }
155
156 if (result instanceof ClassName) {
157 ClassName className = (ClassName)result;
158
159 if (!Validator.equals(value, className.getValue())) {
160 result = null;
161 }
162 }
163
164 if (result == null) {
165 StringBundler query = new StringBundler(3);
166
167 query.append(_SQL_SELECT_CLASSNAME_WHERE);
168
169 boolean bindValue = false;
170
171 if (value == null) {
172 query.append(_FINDER_COLUMN_VALUE_VALUE_1);
173 }
174 else if (value.equals(StringPool.BLANK)) {
175 query.append(_FINDER_COLUMN_VALUE_VALUE_3);
176 }
177 else {
178 bindValue = true;
179
180 query.append(_FINDER_COLUMN_VALUE_VALUE_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 (bindValue) {
195 qPos.add(value);
196 }
197
198 List<ClassName> list = q.list();
199
200 if (list.isEmpty()) {
201 finderCache.putResult(FINDER_PATH_FETCH_BY_VALUE,
202 finderArgs, list);
203 }
204 else {
205 ClassName className = list.get(0);
206
207 result = className;
208
209 cacheResult(className);
210
211 if ((className.getValue() == null) ||
212 !className.getValue().equals(value)) {
213 finderCache.putResult(FINDER_PATH_FETCH_BY_VALUE,
214 finderArgs, className);
215 }
216 }
217 }
218 catch (Exception e) {
219 finderCache.removeResult(FINDER_PATH_FETCH_BY_VALUE, finderArgs);
220
221 throw processException(e);
222 }
223 finally {
224 closeSession(session);
225 }
226 }
227
228 if (result instanceof List<?>) {
229 return null;
230 }
231 else {
232 return (ClassName)result;
233 }
234 }
235
236
242 @Override
243 public ClassName removeByValue(String value)
244 throws NoSuchClassNameException {
245 ClassName className = findByValue(value);
246
247 return remove(className);
248 }
249
250
256 @Override
257 public int countByValue(String value) {
258 FinderPath finderPath = FINDER_PATH_COUNT_BY_VALUE;
259
260 Object[] finderArgs = new Object[] { value };
261
262 Long count = (Long)finderCache.getResult(finderPath, finderArgs, 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 finderCache.putResult(finderPath, finderArgs, count);
301 }
302 catch (Exception e) {
303 finderCache.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 entityCache.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
331 ClassNameImpl.class, className.getPrimaryKey(), className);
332
333 finderCache.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 (entityCache.getResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
348 ClassNameImpl.class, className.getPrimaryKey()) == null) {
349 cacheResult(className);
350 }
351 else {
352 className.resetOriginalValues();
353 }
354 }
355 }
356
357
364 @Override
365 public void clearCache() {
366 entityCache.clearCache(ClassNameImpl.class);
367
368 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
369 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
370 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
371 }
372
373
380 @Override
381 public void clearCache(ClassName className) {
382 entityCache.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
383 ClassNameImpl.class, className.getPrimaryKey());
384
385 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
386 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
387
388 clearUniqueFindersCache((ClassNameModelImpl)className);
389 }
390
391 @Override
392 public void clearCache(List<ClassName> classNames) {
393 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
394 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
395
396 for (ClassName className : classNames) {
397 entityCache.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
398 ClassNameImpl.class, className.getPrimaryKey());
399
400 clearUniqueFindersCache((ClassNameModelImpl)className);
401 }
402 }
403
404 protected void cacheUniqueFindersCache(
405 ClassNameModelImpl classNameModelImpl, boolean isNew) {
406 if (isNew) {
407 Object[] args = new Object[] { classNameModelImpl.getValue() };
408
409 finderCache.putResult(FINDER_PATH_COUNT_BY_VALUE, args,
410 Long.valueOf(1));
411 finderCache.putResult(FINDER_PATH_FETCH_BY_VALUE, args,
412 classNameModelImpl);
413 }
414 else {
415 if ((classNameModelImpl.getColumnBitmask() &
416 FINDER_PATH_FETCH_BY_VALUE.getColumnBitmask()) != 0) {
417 Object[] args = new Object[] { classNameModelImpl.getValue() };
418
419 finderCache.putResult(FINDER_PATH_COUNT_BY_VALUE, args,
420 Long.valueOf(1));
421 finderCache.putResult(FINDER_PATH_FETCH_BY_VALUE, args,
422 classNameModelImpl);
423 }
424 }
425 }
426
427 protected void clearUniqueFindersCache(
428 ClassNameModelImpl classNameModelImpl) {
429 Object[] args = new Object[] { classNameModelImpl.getValue() };
430
431 finderCache.removeResult(FINDER_PATH_COUNT_BY_VALUE, args);
432 finderCache.removeResult(FINDER_PATH_FETCH_BY_VALUE, args);
433
434 if ((classNameModelImpl.getColumnBitmask() &
435 FINDER_PATH_FETCH_BY_VALUE.getColumnBitmask()) != 0) {
436 args = new Object[] { classNameModelImpl.getOriginalValue() };
437
438 finderCache.removeResult(FINDER_PATH_COUNT_BY_VALUE, args);
439 finderCache.removeResult(FINDER_PATH_FETCH_BY_VALUE, args);
440 }
441 }
442
443
449 @Override
450 public ClassName create(long classNameId) {
451 ClassName className = new ClassNameImpl();
452
453 className.setNew(true);
454 className.setPrimaryKey(classNameId);
455
456 return className;
457 }
458
459
466 @Override
467 public ClassName remove(long classNameId) throws NoSuchClassNameException {
468 return remove((Serializable)classNameId);
469 }
470
471
478 @Override
479 public ClassName remove(Serializable primaryKey)
480 throws NoSuchClassNameException {
481 Session session = null;
482
483 try {
484 session = openSession();
485
486 ClassName className = (ClassName)session.get(ClassNameImpl.class,
487 primaryKey);
488
489 if (className == null) {
490 if (_log.isWarnEnabled()) {
491 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
492 }
493
494 throw new NoSuchClassNameException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
495 primaryKey);
496 }
497
498 return remove(className);
499 }
500 catch (NoSuchClassNameException nsee) {
501 throw nsee;
502 }
503 catch (Exception e) {
504 throw processException(e);
505 }
506 finally {
507 closeSession(session);
508 }
509 }
510
511 @Override
512 protected ClassName removeImpl(ClassName className) {
513 className = toUnwrappedModel(className);
514
515 Session session = null;
516
517 try {
518 session = openSession();
519
520 if (!session.contains(className)) {
521 className = (ClassName)session.get(ClassNameImpl.class,
522 className.getPrimaryKeyObj());
523 }
524
525 if (className != null) {
526 session.delete(className);
527 }
528 }
529 catch (Exception e) {
530 throw processException(e);
531 }
532 finally {
533 closeSession(session);
534 }
535
536 if (className != null) {
537 clearCache(className);
538 }
539
540 return className;
541 }
542
543 @Override
544 public ClassName updateImpl(ClassName className) {
545 className = toUnwrappedModel(className);
546
547 boolean isNew = className.isNew();
548
549 ClassNameModelImpl classNameModelImpl = (ClassNameModelImpl)className;
550
551 Session session = null;
552
553 try {
554 session = openSession();
555
556 if (className.isNew()) {
557 session.save(className);
558
559 className.setNew(false);
560 }
561 else {
562 className = (ClassName)session.merge(className);
563 }
564 }
565 catch (Exception e) {
566 throw processException(e);
567 }
568 finally {
569 closeSession(session);
570 }
571
572 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
573
574 if (isNew || !ClassNameModelImpl.COLUMN_BITMASK_ENABLED) {
575 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
576 }
577
578 entityCache.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
579 ClassNameImpl.class, className.getPrimaryKey(), className, false);
580
581 clearUniqueFindersCache(classNameModelImpl);
582 cacheUniqueFindersCache(classNameModelImpl, isNew);
583
584 className.resetOriginalValues();
585
586 return className;
587 }
588
589 protected ClassName toUnwrappedModel(ClassName className) {
590 if (className instanceof ClassNameImpl) {
591 return className;
592 }
593
594 ClassNameImpl classNameImpl = new ClassNameImpl();
595
596 classNameImpl.setNew(className.isNew());
597 classNameImpl.setPrimaryKey(className.getPrimaryKey());
598
599 classNameImpl.setMvccVersion(className.getMvccVersion());
600 classNameImpl.setClassNameId(className.getClassNameId());
601 classNameImpl.setValue(className.getValue());
602
603 return classNameImpl;
604 }
605
606
613 @Override
614 public ClassName findByPrimaryKey(Serializable primaryKey)
615 throws NoSuchClassNameException {
616 ClassName className = fetchByPrimaryKey(primaryKey);
617
618 if (className == null) {
619 if (_log.isWarnEnabled()) {
620 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
621 }
622
623 throw new NoSuchClassNameException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
624 primaryKey);
625 }
626
627 return className;
628 }
629
630
637 @Override
638 public ClassName findByPrimaryKey(long classNameId)
639 throws NoSuchClassNameException {
640 return findByPrimaryKey((Serializable)classNameId);
641 }
642
643
649 @Override
650 public ClassName fetchByPrimaryKey(Serializable primaryKey) {
651 ClassName className = (ClassName)entityCache.getResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
652 ClassNameImpl.class, primaryKey);
653
654 if (className == _nullClassName) {
655 return null;
656 }
657
658 if (className == null) {
659 Session session = null;
660
661 try {
662 session = openSession();
663
664 className = (ClassName)session.get(ClassNameImpl.class,
665 primaryKey);
666
667 if (className != null) {
668 cacheResult(className);
669 }
670 else {
671 entityCache.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
672 ClassNameImpl.class, primaryKey, _nullClassName);
673 }
674 }
675 catch (Exception e) {
676 entityCache.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
677 ClassNameImpl.class, primaryKey);
678
679 throw processException(e);
680 }
681 finally {
682 closeSession(session);
683 }
684 }
685
686 return className;
687 }
688
689
695 @Override
696 public ClassName fetchByPrimaryKey(long classNameId) {
697 return fetchByPrimaryKey((Serializable)classNameId);
698 }
699
700 @Override
701 public Map<Serializable, ClassName> fetchByPrimaryKeys(
702 Set<Serializable> primaryKeys) {
703 if (primaryKeys.isEmpty()) {
704 return Collections.emptyMap();
705 }
706
707 Map<Serializable, ClassName> map = new HashMap<Serializable, ClassName>();
708
709 if (primaryKeys.size() == 1) {
710 Iterator<Serializable> iterator = primaryKeys.iterator();
711
712 Serializable primaryKey = iterator.next();
713
714 ClassName className = fetchByPrimaryKey(primaryKey);
715
716 if (className != null) {
717 map.put(primaryKey, className);
718 }
719
720 return map;
721 }
722
723 Set<Serializable> uncachedPrimaryKeys = null;
724
725 for (Serializable primaryKey : primaryKeys) {
726 ClassName className = (ClassName)entityCache.getResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
727 ClassNameImpl.class, primaryKey);
728
729 if (className == null) {
730 if (uncachedPrimaryKeys == null) {
731 uncachedPrimaryKeys = new HashSet<Serializable>();
732 }
733
734 uncachedPrimaryKeys.add(primaryKey);
735 }
736 else {
737 map.put(primaryKey, className);
738 }
739 }
740
741 if (uncachedPrimaryKeys == null) {
742 return map;
743 }
744
745 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
746 1);
747
748 query.append(_SQL_SELECT_CLASSNAME_WHERE_PKS_IN);
749
750 for (Serializable primaryKey : uncachedPrimaryKeys) {
751 query.append(String.valueOf(primaryKey));
752
753 query.append(StringPool.COMMA);
754 }
755
756 query.setIndex(query.index() - 1);
757
758 query.append(StringPool.CLOSE_PARENTHESIS);
759
760 String sql = query.toString();
761
762 Session session = null;
763
764 try {
765 session = openSession();
766
767 Query q = session.createQuery(sql);
768
769 for (ClassName className : (List<ClassName>)q.list()) {
770 map.put(className.getPrimaryKeyObj(), className);
771
772 cacheResult(className);
773
774 uncachedPrimaryKeys.remove(className.getPrimaryKeyObj());
775 }
776
777 for (Serializable primaryKey : uncachedPrimaryKeys) {
778 entityCache.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
779 ClassNameImpl.class, primaryKey, _nullClassName);
780 }
781 }
782 catch (Exception e) {
783 throw processException(e);
784 }
785 finally {
786 closeSession(session);
787 }
788
789 return map;
790 }
791
792
797 @Override
798 public List<ClassName> findAll() {
799 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
800 }
801
802
813 @Override
814 public List<ClassName> findAll(int start, int end) {
815 return findAll(start, end, null);
816 }
817
818
830 @Override
831 public List<ClassName> findAll(int start, int end,
832 OrderByComparator<ClassName> orderByComparator) {
833 return findAll(start, end, orderByComparator, true);
834 }
835
836
849 @Override
850 public List<ClassName> findAll(int start, int end,
851 OrderByComparator<ClassName> orderByComparator,
852 boolean retrieveFromCache) {
853 boolean pagination = true;
854 FinderPath finderPath = null;
855 Object[] finderArgs = null;
856
857 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
858 (orderByComparator == null)) {
859 pagination = false;
860 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
861 finderArgs = FINDER_ARGS_EMPTY;
862 }
863 else {
864 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
865 finderArgs = new Object[] { start, end, orderByComparator };
866 }
867
868 List<ClassName> list = null;
869
870 if (retrieveFromCache) {
871 list = (List<ClassName>)finderCache.getResult(finderPath,
872 finderArgs, this);
873 }
874
875 if (list == null) {
876 StringBundler query = null;
877 String sql = null;
878
879 if (orderByComparator != null) {
880 query = new StringBundler(2 +
881 (orderByComparator.getOrderByFields().length * 3));
882
883 query.append(_SQL_SELECT_CLASSNAME);
884
885 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
886 orderByComparator);
887
888 sql = query.toString();
889 }
890 else {
891 sql = _SQL_SELECT_CLASSNAME;
892
893 if (pagination) {
894 sql = sql.concat(ClassNameModelImpl.ORDER_BY_JPQL);
895 }
896 }
897
898 Session session = null;
899
900 try {
901 session = openSession();
902
903 Query q = session.createQuery(sql);
904
905 if (!pagination) {
906 list = (List<ClassName>)QueryUtil.list(q, getDialect(),
907 start, end, false);
908
909 Collections.sort(list);
910
911 list = Collections.unmodifiableList(list);
912 }
913 else {
914 list = (List<ClassName>)QueryUtil.list(q, getDialect(),
915 start, end);
916 }
917
918 cacheResult(list);
919
920 finderCache.putResult(finderPath, finderArgs, list);
921 }
922 catch (Exception e) {
923 finderCache.removeResult(finderPath, finderArgs);
924
925 throw processException(e);
926 }
927 finally {
928 closeSession(session);
929 }
930 }
931
932 return list;
933 }
934
935
939 @Override
940 public void removeAll() {
941 for (ClassName className : findAll()) {
942 remove(className);
943 }
944 }
945
946
951 @Override
952 public int countAll() {
953 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
954 FINDER_ARGS_EMPTY, this);
955
956 if (count == null) {
957 Session session = null;
958
959 try {
960 session = openSession();
961
962 Query q = session.createQuery(_SQL_COUNT_CLASSNAME);
963
964 count = (Long)q.uniqueResult();
965
966 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
967 count);
968 }
969 catch (Exception e) {
970 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
971 FINDER_ARGS_EMPTY);
972
973 throw processException(e);
974 }
975 finally {
976 closeSession(session);
977 }
978 }
979
980 return count.intValue();
981 }
982
983 @Override
984 protected Map<String, Integer> getTableColumnsMap() {
985 return ClassNameModelImpl.TABLE_COLUMNS_MAP;
986 }
987
988
991 public void afterPropertiesSet() {
992 }
993
994 public void destroy() {
995 entityCache.removeCache(ClassNameImpl.class.getName());
996 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
997 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
998 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
999 }
1000
1001 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1002 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1003 private static final String _SQL_SELECT_CLASSNAME = "SELECT className FROM ClassName className";
1004 private static final String _SQL_SELECT_CLASSNAME_WHERE_PKS_IN = "SELECT className FROM ClassName className WHERE classNameId IN (";
1005 private static final String _SQL_SELECT_CLASSNAME_WHERE = "SELECT className FROM ClassName className WHERE ";
1006 private static final String _SQL_COUNT_CLASSNAME = "SELECT COUNT(className) FROM ClassName className";
1007 private static final String _SQL_COUNT_CLASSNAME_WHERE = "SELECT COUNT(className) FROM ClassName className WHERE ";
1008 private static final String _ORDER_BY_ENTITY_ALIAS = "className.";
1009 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClassName exists with the primary key ";
1010 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ClassName exists with the key {";
1011 private static final Log _log = LogFactoryUtil.getLog(ClassNamePersistenceImpl.class);
1012 private static final ClassName _nullClassName = new ClassNameImpl() {
1013 @Override
1014 public Object clone() {
1015 return this;
1016 }
1017
1018 @Override
1019 public CacheModel<ClassName> toCacheModel() {
1020 return _nullClassNameCacheModel;
1021 }
1022 };
1023
1024 private static final CacheModel<ClassName> _nullClassNameCacheModel = new NullCacheModel();
1025
1026 private static class NullCacheModel implements CacheModel<ClassName>,
1027 MVCCModel {
1028 @Override
1029 public long getMvccVersion() {
1030 return -1;
1031 }
1032
1033 @Override
1034 public void setMvccVersion(long mvccVersion) {
1035 }
1036
1037 @Override
1038 public ClassName toEntityModel() {
1039 return _nullClassName;
1040 }
1041 }
1042 }