001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.expando.NoSuchValueException;
042 import com.liferay.portlet.expando.model.ExpandoValue;
043 import com.liferay.portlet.expando.model.impl.ExpandoValueImpl;
044 import com.liferay.portlet.expando.model.impl.ExpandoValueModelImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051 import java.util.Set;
052
053
065 public class ExpandoValuePersistenceImpl extends BasePersistenceImpl<ExpandoValue>
066 implements ExpandoValuePersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoValueImpl.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(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
078 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.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(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
081 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
084 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
087 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTableId",
089 new String[] {
090 Long.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
096 new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
097 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTableId",
099 new String[] { Long.class.getName() },
100 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
101 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK |
102 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
104 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
106 new String[] { Long.class.getName() });
107
108
115 public List<ExpandoValue> findByTableId(long tableId)
116 throws SystemException {
117 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
133 public List<ExpandoValue> findByTableId(long tableId, int start, int end)
134 throws SystemException {
135 return findByTableId(tableId, start, end, null);
136 }
137
138
152 public List<ExpandoValue> findByTableId(long tableId, int start, int end,
153 OrderByComparator orderByComparator) throws SystemException {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
162 finderArgs = new Object[] { tableId };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
166 finderArgs = new Object[] { tableId, start, end, orderByComparator };
167 }
168
169 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
170 finderArgs, this);
171
172 if ((list != null) && !list.isEmpty()) {
173 for (ExpandoValue expandoValue : list) {
174 if ((tableId != expandoValue.getTableId())) {
175 list = null;
176
177 break;
178 }
179 }
180 }
181
182 if (list == null) {
183 StringBundler query = null;
184
185 if (orderByComparator != null) {
186 query = new StringBundler(3 +
187 (orderByComparator.getOrderByFields().length * 3));
188 }
189 else {
190 query = new StringBundler(3);
191 }
192
193 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
194
195 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
196
197 if (orderByComparator != null) {
198 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
199 orderByComparator);
200 }
201 else
202 if (pagination) {
203 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
204 }
205
206 String sql = query.toString();
207
208 Session session = null;
209
210 try {
211 session = openSession();
212
213 Query q = session.createQuery(sql);
214
215 QueryPos qPos = QueryPos.getInstance(q);
216
217 qPos.add(tableId);
218
219 if (!pagination) {
220 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
221 start, end, false);
222
223 Collections.sort(list);
224
225 list = new UnmodifiableList<ExpandoValue>(list);
226 }
227 else {
228 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
229 start, end);
230 }
231
232 cacheResult(list);
233
234 FinderCacheUtil.putResult(finderPath, finderArgs, list);
235 }
236 catch (Exception e) {
237 FinderCacheUtil.removeResult(finderPath, finderArgs);
238
239 throw processException(e);
240 }
241 finally {
242 closeSession(session);
243 }
244 }
245
246 return list;
247 }
248
249
258 public ExpandoValue findByTableId_First(long tableId,
259 OrderByComparator orderByComparator)
260 throws NoSuchValueException, SystemException {
261 ExpandoValue expandoValue = fetchByTableId_First(tableId,
262 orderByComparator);
263
264 if (expandoValue != null) {
265 return expandoValue;
266 }
267
268 StringBundler msg = new StringBundler(4);
269
270 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
271
272 msg.append("tableId=");
273 msg.append(tableId);
274
275 msg.append(StringPool.CLOSE_CURLY_BRACE);
276
277 throw new NoSuchValueException(msg.toString());
278 }
279
280
288 public ExpandoValue fetchByTableId_First(long tableId,
289 OrderByComparator orderByComparator) throws SystemException {
290 List<ExpandoValue> list = findByTableId(tableId, 0, 1, orderByComparator);
291
292 if (!list.isEmpty()) {
293 return list.get(0);
294 }
295
296 return null;
297 }
298
299
308 public ExpandoValue findByTableId_Last(long tableId,
309 OrderByComparator orderByComparator)
310 throws NoSuchValueException, SystemException {
311 ExpandoValue expandoValue = fetchByTableId_Last(tableId,
312 orderByComparator);
313
314 if (expandoValue != null) {
315 return expandoValue;
316 }
317
318 StringBundler msg = new StringBundler(4);
319
320 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
321
322 msg.append("tableId=");
323 msg.append(tableId);
324
325 msg.append(StringPool.CLOSE_CURLY_BRACE);
326
327 throw new NoSuchValueException(msg.toString());
328 }
329
330
338 public ExpandoValue fetchByTableId_Last(long tableId,
339 OrderByComparator orderByComparator) throws SystemException {
340 int count = countByTableId(tableId);
341
342 List<ExpandoValue> list = findByTableId(tableId, count - 1, count,
343 orderByComparator);
344
345 if (!list.isEmpty()) {
346 return list.get(0);
347 }
348
349 return null;
350 }
351
352
362 public ExpandoValue[] findByTableId_PrevAndNext(long valueId, long tableId,
363 OrderByComparator orderByComparator)
364 throws NoSuchValueException, SystemException {
365 ExpandoValue expandoValue = findByPrimaryKey(valueId);
366
367 Session session = null;
368
369 try {
370 session = openSession();
371
372 ExpandoValue[] array = new ExpandoValueImpl[3];
373
374 array[0] = getByTableId_PrevAndNext(session, expandoValue, tableId,
375 orderByComparator, true);
376
377 array[1] = expandoValue;
378
379 array[2] = getByTableId_PrevAndNext(session, expandoValue, tableId,
380 orderByComparator, false);
381
382 return array;
383 }
384 catch (Exception e) {
385 throw processException(e);
386 }
387 finally {
388 closeSession(session);
389 }
390 }
391
392 protected ExpandoValue getByTableId_PrevAndNext(Session session,
393 ExpandoValue expandoValue, long tableId,
394 OrderByComparator orderByComparator, boolean previous) {
395 StringBundler query = null;
396
397 if (orderByComparator != null) {
398 query = new StringBundler(6 +
399 (orderByComparator.getOrderByFields().length * 6));
400 }
401 else {
402 query = new StringBundler(3);
403 }
404
405 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
406
407 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
408
409 if (orderByComparator != null) {
410 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
411
412 if (orderByConditionFields.length > 0) {
413 query.append(WHERE_AND);
414 }
415
416 for (int i = 0; i < orderByConditionFields.length; i++) {
417 query.append(_ORDER_BY_ENTITY_ALIAS);
418 query.append(orderByConditionFields[i]);
419
420 if ((i + 1) < orderByConditionFields.length) {
421 if (orderByComparator.isAscending() ^ previous) {
422 query.append(WHERE_GREATER_THAN_HAS_NEXT);
423 }
424 else {
425 query.append(WHERE_LESSER_THAN_HAS_NEXT);
426 }
427 }
428 else {
429 if (orderByComparator.isAscending() ^ previous) {
430 query.append(WHERE_GREATER_THAN);
431 }
432 else {
433 query.append(WHERE_LESSER_THAN);
434 }
435 }
436 }
437
438 query.append(ORDER_BY_CLAUSE);
439
440 String[] orderByFields = orderByComparator.getOrderByFields();
441
442 for (int i = 0; i < orderByFields.length; i++) {
443 query.append(_ORDER_BY_ENTITY_ALIAS);
444 query.append(orderByFields[i]);
445
446 if ((i + 1) < orderByFields.length) {
447 if (orderByComparator.isAscending() ^ previous) {
448 query.append(ORDER_BY_ASC_HAS_NEXT);
449 }
450 else {
451 query.append(ORDER_BY_DESC_HAS_NEXT);
452 }
453 }
454 else {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(ORDER_BY_ASC);
457 }
458 else {
459 query.append(ORDER_BY_DESC);
460 }
461 }
462 }
463 }
464 else {
465 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
466 }
467
468 String sql = query.toString();
469
470 Query q = session.createQuery(sql);
471
472 q.setFirstResult(0);
473 q.setMaxResults(2);
474
475 QueryPos qPos = QueryPos.getInstance(q);
476
477 qPos.add(tableId);
478
479 if (orderByComparator != null) {
480 Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
481
482 for (Object value : values) {
483 qPos.add(value);
484 }
485 }
486
487 List<ExpandoValue> list = q.list();
488
489 if (list.size() == 2) {
490 return list.get(1);
491 }
492 else {
493 return null;
494 }
495 }
496
497
503 public void removeByTableId(long tableId) throws SystemException {
504 for (ExpandoValue expandoValue : findByTableId(tableId,
505 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
506 remove(expandoValue);
507 }
508 }
509
510
517 public int countByTableId(long tableId) throws SystemException {
518 FinderPath finderPath = FINDER_PATH_COUNT_BY_TABLEID;
519
520 Object[] finderArgs = new Object[] { tableId };
521
522 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
523 this);
524
525 if (count == null) {
526 StringBundler query = new StringBundler(2);
527
528 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
529
530 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
531
532 String sql = query.toString();
533
534 Session session = null;
535
536 try {
537 session = openSession();
538
539 Query q = session.createQuery(sql);
540
541 QueryPos qPos = QueryPos.getInstance(q);
542
543 qPos.add(tableId);
544
545 count = (Long)q.uniqueResult();
546
547 FinderCacheUtil.putResult(finderPath, finderArgs, count);
548 }
549 catch (Exception e) {
550 FinderCacheUtil.removeResult(finderPath, finderArgs);
551
552 throw processException(e);
553 }
554 finally {
555 closeSession(session);
556 }
557 }
558
559 return count.intValue();
560 }
561
562 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoValue.tableId = ?";
563 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
564 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
565 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByColumnId",
566 new String[] {
567 Long.class.getName(),
568
569 Integer.class.getName(), Integer.class.getName(),
570 OrderByComparator.class.getName()
571 });
572 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID =
573 new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
574 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
575 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByColumnId",
576 new String[] { Long.class.getName() },
577 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK |
578 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
579 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK);
580 public static final FinderPath FINDER_PATH_COUNT_BY_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
581 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
582 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByColumnId",
583 new String[] { Long.class.getName() });
584
585
592 public List<ExpandoValue> findByColumnId(long columnId)
593 throws SystemException {
594 return findByColumnId(columnId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
595 null);
596 }
597
598
611 public List<ExpandoValue> findByColumnId(long columnId, int start, int end)
612 throws SystemException {
613 return findByColumnId(columnId, start, end, null);
614 }
615
616
630 public List<ExpandoValue> findByColumnId(long columnId, int start, int end,
631 OrderByComparator orderByComparator) throws SystemException {
632 boolean pagination = true;
633 FinderPath finderPath = null;
634 Object[] finderArgs = null;
635
636 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
637 (orderByComparator == null)) {
638 pagination = false;
639 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID;
640 finderArgs = new Object[] { columnId };
641 }
642 else {
643 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COLUMNID;
644 finderArgs = new Object[] { columnId, start, end, orderByComparator };
645 }
646
647 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
648 finderArgs, this);
649
650 if ((list != null) && !list.isEmpty()) {
651 for (ExpandoValue expandoValue : list) {
652 if ((columnId != expandoValue.getColumnId())) {
653 list = null;
654
655 break;
656 }
657 }
658 }
659
660 if (list == null) {
661 StringBundler query = null;
662
663 if (orderByComparator != null) {
664 query = new StringBundler(3 +
665 (orderByComparator.getOrderByFields().length * 3));
666 }
667 else {
668 query = new StringBundler(3);
669 }
670
671 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
672
673 query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
674
675 if (orderByComparator != null) {
676 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
677 orderByComparator);
678 }
679 else
680 if (pagination) {
681 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
682 }
683
684 String sql = query.toString();
685
686 Session session = null;
687
688 try {
689 session = openSession();
690
691 Query q = session.createQuery(sql);
692
693 QueryPos qPos = QueryPos.getInstance(q);
694
695 qPos.add(columnId);
696
697 if (!pagination) {
698 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
699 start, end, false);
700
701 Collections.sort(list);
702
703 list = new UnmodifiableList<ExpandoValue>(list);
704 }
705 else {
706 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
707 start, end);
708 }
709
710 cacheResult(list);
711
712 FinderCacheUtil.putResult(finderPath, finderArgs, list);
713 }
714 catch (Exception e) {
715 FinderCacheUtil.removeResult(finderPath, finderArgs);
716
717 throw processException(e);
718 }
719 finally {
720 closeSession(session);
721 }
722 }
723
724 return list;
725 }
726
727
736 public ExpandoValue findByColumnId_First(long columnId,
737 OrderByComparator orderByComparator)
738 throws NoSuchValueException, SystemException {
739 ExpandoValue expandoValue = fetchByColumnId_First(columnId,
740 orderByComparator);
741
742 if (expandoValue != null) {
743 return expandoValue;
744 }
745
746 StringBundler msg = new StringBundler(4);
747
748 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
749
750 msg.append("columnId=");
751 msg.append(columnId);
752
753 msg.append(StringPool.CLOSE_CURLY_BRACE);
754
755 throw new NoSuchValueException(msg.toString());
756 }
757
758
766 public ExpandoValue fetchByColumnId_First(long columnId,
767 OrderByComparator orderByComparator) throws SystemException {
768 List<ExpandoValue> list = findByColumnId(columnId, 0, 1,
769 orderByComparator);
770
771 if (!list.isEmpty()) {
772 return list.get(0);
773 }
774
775 return null;
776 }
777
778
787 public ExpandoValue findByColumnId_Last(long columnId,
788 OrderByComparator orderByComparator)
789 throws NoSuchValueException, SystemException {
790 ExpandoValue expandoValue = fetchByColumnId_Last(columnId,
791 orderByComparator);
792
793 if (expandoValue != null) {
794 return expandoValue;
795 }
796
797 StringBundler msg = new StringBundler(4);
798
799 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
800
801 msg.append("columnId=");
802 msg.append(columnId);
803
804 msg.append(StringPool.CLOSE_CURLY_BRACE);
805
806 throw new NoSuchValueException(msg.toString());
807 }
808
809
817 public ExpandoValue fetchByColumnId_Last(long columnId,
818 OrderByComparator orderByComparator) throws SystemException {
819 int count = countByColumnId(columnId);
820
821 List<ExpandoValue> list = findByColumnId(columnId, count - 1, count,
822 orderByComparator);
823
824 if (!list.isEmpty()) {
825 return list.get(0);
826 }
827
828 return null;
829 }
830
831
841 public ExpandoValue[] findByColumnId_PrevAndNext(long valueId,
842 long columnId, OrderByComparator orderByComparator)
843 throws NoSuchValueException, SystemException {
844 ExpandoValue expandoValue = findByPrimaryKey(valueId);
845
846 Session session = null;
847
848 try {
849 session = openSession();
850
851 ExpandoValue[] array = new ExpandoValueImpl[3];
852
853 array[0] = getByColumnId_PrevAndNext(session, expandoValue,
854 columnId, orderByComparator, true);
855
856 array[1] = expandoValue;
857
858 array[2] = getByColumnId_PrevAndNext(session, expandoValue,
859 columnId, orderByComparator, false);
860
861 return array;
862 }
863 catch (Exception e) {
864 throw processException(e);
865 }
866 finally {
867 closeSession(session);
868 }
869 }
870
871 protected ExpandoValue getByColumnId_PrevAndNext(Session session,
872 ExpandoValue expandoValue, long columnId,
873 OrderByComparator orderByComparator, boolean previous) {
874 StringBundler query = null;
875
876 if (orderByComparator != null) {
877 query = new StringBundler(6 +
878 (orderByComparator.getOrderByFields().length * 6));
879 }
880 else {
881 query = new StringBundler(3);
882 }
883
884 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
885
886 query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
887
888 if (orderByComparator != null) {
889 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
890
891 if (orderByConditionFields.length > 0) {
892 query.append(WHERE_AND);
893 }
894
895 for (int i = 0; i < orderByConditionFields.length; i++) {
896 query.append(_ORDER_BY_ENTITY_ALIAS);
897 query.append(orderByConditionFields[i]);
898
899 if ((i + 1) < orderByConditionFields.length) {
900 if (orderByComparator.isAscending() ^ previous) {
901 query.append(WHERE_GREATER_THAN_HAS_NEXT);
902 }
903 else {
904 query.append(WHERE_LESSER_THAN_HAS_NEXT);
905 }
906 }
907 else {
908 if (orderByComparator.isAscending() ^ previous) {
909 query.append(WHERE_GREATER_THAN);
910 }
911 else {
912 query.append(WHERE_LESSER_THAN);
913 }
914 }
915 }
916
917 query.append(ORDER_BY_CLAUSE);
918
919 String[] orderByFields = orderByComparator.getOrderByFields();
920
921 for (int i = 0; i < orderByFields.length; i++) {
922 query.append(_ORDER_BY_ENTITY_ALIAS);
923 query.append(orderByFields[i]);
924
925 if ((i + 1) < orderByFields.length) {
926 if (orderByComparator.isAscending() ^ previous) {
927 query.append(ORDER_BY_ASC_HAS_NEXT);
928 }
929 else {
930 query.append(ORDER_BY_DESC_HAS_NEXT);
931 }
932 }
933 else {
934 if (orderByComparator.isAscending() ^ previous) {
935 query.append(ORDER_BY_ASC);
936 }
937 else {
938 query.append(ORDER_BY_DESC);
939 }
940 }
941 }
942 }
943 else {
944 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
945 }
946
947 String sql = query.toString();
948
949 Query q = session.createQuery(sql);
950
951 q.setFirstResult(0);
952 q.setMaxResults(2);
953
954 QueryPos qPos = QueryPos.getInstance(q);
955
956 qPos.add(columnId);
957
958 if (orderByComparator != null) {
959 Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
960
961 for (Object value : values) {
962 qPos.add(value);
963 }
964 }
965
966 List<ExpandoValue> list = q.list();
967
968 if (list.size() == 2) {
969 return list.get(1);
970 }
971 else {
972 return null;
973 }
974 }
975
976
982 public void removeByColumnId(long columnId) throws SystemException {
983 for (ExpandoValue expandoValue : findByColumnId(columnId,
984 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
985 remove(expandoValue);
986 }
987 }
988
989
996 public int countByColumnId(long columnId) throws SystemException {
997 FinderPath finderPath = FINDER_PATH_COUNT_BY_COLUMNID;
998
999 Object[] finderArgs = new Object[] { columnId };
1000
1001 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1002 this);
1003
1004 if (count == null) {
1005 StringBundler query = new StringBundler(2);
1006
1007 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
1008
1009 query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
1010
1011 String sql = query.toString();
1012
1013 Session session = null;
1014
1015 try {
1016 session = openSession();
1017
1018 Query q = session.createQuery(sql);
1019
1020 QueryPos qPos = QueryPos.getInstance(q);
1021
1022 qPos.add(columnId);
1023
1024 count = (Long)q.uniqueResult();
1025
1026 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1027 }
1028 catch (Exception e) {
1029 FinderCacheUtil.removeResult(finderPath, finderArgs);
1030
1031 throw processException(e);
1032 }
1033 finally {
1034 closeSession(session);
1035 }
1036 }
1037
1038 return count.intValue();
1039 }
1040
1041 private static final String _FINDER_COLUMN_COLUMNID_COLUMNID_2 = "expandoValue.columnId = ?";
1042 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
1043 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
1044 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRowId",
1045 new String[] {
1046 Long.class.getName(),
1047
1048 Integer.class.getName(), Integer.class.getName(),
1049 OrderByComparator.class.getName()
1050 });
1051 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
1052 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
1053 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRowId",
1054 new String[] { Long.class.getName() },
1055 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK |
1056 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
1057 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK);
1058 public static final FinderPath FINDER_PATH_COUNT_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
1059 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
1060 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRowId",
1061 new String[] { Long.class.getName() });
1062
1063
1070 public List<ExpandoValue> findByRowId(long rowId) throws SystemException {
1071 return findByRowId(rowId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1072 }
1073
1074
1087 public List<ExpandoValue> findByRowId(long rowId, int start, int end)
1088 throws SystemException {
1089 return findByRowId(rowId, start, end, null);
1090 }
1091
1092
1106 public List<ExpandoValue> findByRowId(long rowId, int start, int end,
1107 OrderByComparator orderByComparator) throws SystemException {
1108 boolean pagination = true;
1109 FinderPath finderPath = null;
1110 Object[] finderArgs = null;
1111
1112 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1113 (orderByComparator == null)) {
1114 pagination = false;
1115 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID;
1116 finderArgs = new Object[] { rowId };
1117 }
1118 else {
1119 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROWID;
1120 finderArgs = new Object[] { rowId, start, end, orderByComparator };
1121 }
1122
1123 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
1124 finderArgs, this);
1125
1126 if ((list != null) && !list.isEmpty()) {
1127 for (ExpandoValue expandoValue : list) {
1128 if ((rowId != expandoValue.getRowId())) {
1129 list = null;
1130
1131 break;
1132 }
1133 }
1134 }
1135
1136 if (list == null) {
1137 StringBundler query = null;
1138
1139 if (orderByComparator != null) {
1140 query = new StringBundler(3 +
1141 (orderByComparator.getOrderByFields().length * 3));
1142 }
1143 else {
1144 query = new StringBundler(3);
1145 }
1146
1147 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1148
1149 query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1150
1151 if (orderByComparator != null) {
1152 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1153 orderByComparator);
1154 }
1155 else
1156 if (pagination) {
1157 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1158 }
1159
1160 String sql = query.toString();
1161
1162 Session session = null;
1163
1164 try {
1165 session = openSession();
1166
1167 Query q = session.createQuery(sql);
1168
1169 QueryPos qPos = QueryPos.getInstance(q);
1170
1171 qPos.add(rowId);
1172
1173 if (!pagination) {
1174 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1175 start, end, false);
1176
1177 Collections.sort(list);
1178
1179 list = new UnmodifiableList<ExpandoValue>(list);
1180 }
1181 else {
1182 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1183 start, end);
1184 }
1185
1186 cacheResult(list);
1187
1188 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1189 }
1190 catch (Exception e) {
1191 FinderCacheUtil.removeResult(finderPath, finderArgs);
1192
1193 throw processException(e);
1194 }
1195 finally {
1196 closeSession(session);
1197 }
1198 }
1199
1200 return list;
1201 }
1202
1203
1212 public ExpandoValue findByRowId_First(long rowId,
1213 OrderByComparator orderByComparator)
1214 throws NoSuchValueException, SystemException {
1215 ExpandoValue expandoValue = fetchByRowId_First(rowId, orderByComparator);
1216
1217 if (expandoValue != null) {
1218 return expandoValue;
1219 }
1220
1221 StringBundler msg = new StringBundler(4);
1222
1223 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1224
1225 msg.append("rowId=");
1226 msg.append(rowId);
1227
1228 msg.append(StringPool.CLOSE_CURLY_BRACE);
1229
1230 throw new NoSuchValueException(msg.toString());
1231 }
1232
1233
1241 public ExpandoValue fetchByRowId_First(long rowId,
1242 OrderByComparator orderByComparator) throws SystemException {
1243 List<ExpandoValue> list = findByRowId(rowId, 0, 1, orderByComparator);
1244
1245 if (!list.isEmpty()) {
1246 return list.get(0);
1247 }
1248
1249 return null;
1250 }
1251
1252
1261 public ExpandoValue findByRowId_Last(long rowId,
1262 OrderByComparator orderByComparator)
1263 throws NoSuchValueException, SystemException {
1264 ExpandoValue expandoValue = fetchByRowId_Last(rowId, orderByComparator);
1265
1266 if (expandoValue != null) {
1267 return expandoValue;
1268 }
1269
1270 StringBundler msg = new StringBundler(4);
1271
1272 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1273
1274 msg.append("rowId=");
1275 msg.append(rowId);
1276
1277 msg.append(StringPool.CLOSE_CURLY_BRACE);
1278
1279 throw new NoSuchValueException(msg.toString());
1280 }
1281
1282
1290 public ExpandoValue fetchByRowId_Last(long rowId,
1291 OrderByComparator orderByComparator) throws SystemException {
1292 int count = countByRowId(rowId);
1293
1294 List<ExpandoValue> list = findByRowId(rowId, count - 1, count,
1295 orderByComparator);
1296
1297 if (!list.isEmpty()) {
1298 return list.get(0);
1299 }
1300
1301 return null;
1302 }
1303
1304
1314 public ExpandoValue[] findByRowId_PrevAndNext(long valueId, long rowId,
1315 OrderByComparator orderByComparator)
1316 throws NoSuchValueException, SystemException {
1317 ExpandoValue expandoValue = findByPrimaryKey(valueId);
1318
1319 Session session = null;
1320
1321 try {
1322 session = openSession();
1323
1324 ExpandoValue[] array = new ExpandoValueImpl[3];
1325
1326 array[0] = getByRowId_PrevAndNext(session, expandoValue, rowId,
1327 orderByComparator, true);
1328
1329 array[1] = expandoValue;
1330
1331 array[2] = getByRowId_PrevAndNext(session, expandoValue, rowId,
1332 orderByComparator, false);
1333
1334 return array;
1335 }
1336 catch (Exception e) {
1337 throw processException(e);
1338 }
1339 finally {
1340 closeSession(session);
1341 }
1342 }
1343
1344 protected ExpandoValue getByRowId_PrevAndNext(Session session,
1345 ExpandoValue expandoValue, long rowId,
1346 OrderByComparator orderByComparator, boolean previous) {
1347 StringBundler query = null;
1348
1349 if (orderByComparator != null) {
1350 query = new StringBundler(6 +
1351 (orderByComparator.getOrderByFields().length * 6));
1352 }
1353 else {
1354 query = new StringBundler(3);
1355 }
1356
1357 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1358
1359 query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1360
1361 if (orderByComparator != null) {
1362 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1363
1364 if (orderByConditionFields.length > 0) {
1365 query.append(WHERE_AND);
1366 }
1367
1368 for (int i = 0; i < orderByConditionFields.length; i++) {
1369 query.append(_ORDER_BY_ENTITY_ALIAS);
1370 query.append(orderByConditionFields[i]);
1371
1372 if ((i + 1) < orderByConditionFields.length) {
1373 if (orderByComparator.isAscending() ^ previous) {
1374 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1375 }
1376 else {
1377 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1378 }
1379 }
1380 else {
1381 if (orderByComparator.isAscending() ^ previous) {
1382 query.append(WHERE_GREATER_THAN);
1383 }
1384 else {
1385 query.append(WHERE_LESSER_THAN);
1386 }
1387 }
1388 }
1389
1390 query.append(ORDER_BY_CLAUSE);
1391
1392 String[] orderByFields = orderByComparator.getOrderByFields();
1393
1394 for (int i = 0; i < orderByFields.length; i++) {
1395 query.append(_ORDER_BY_ENTITY_ALIAS);
1396 query.append(orderByFields[i]);
1397
1398 if ((i + 1) < orderByFields.length) {
1399 if (orderByComparator.isAscending() ^ previous) {
1400 query.append(ORDER_BY_ASC_HAS_NEXT);
1401 }
1402 else {
1403 query.append(ORDER_BY_DESC_HAS_NEXT);
1404 }
1405 }
1406 else {
1407 if (orderByComparator.isAscending() ^ previous) {
1408 query.append(ORDER_BY_ASC);
1409 }
1410 else {
1411 query.append(ORDER_BY_DESC);
1412 }
1413 }
1414 }
1415 }
1416 else {
1417 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1418 }
1419
1420 String sql = query.toString();
1421
1422 Query q = session.createQuery(sql);
1423
1424 q.setFirstResult(0);
1425 q.setMaxResults(2);
1426
1427 QueryPos qPos = QueryPos.getInstance(q);
1428
1429 qPos.add(rowId);
1430
1431 if (orderByComparator != null) {
1432 Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
1433
1434 for (Object value : values) {
1435 qPos.add(value);
1436 }
1437 }
1438
1439 List<ExpandoValue> list = q.list();
1440
1441 if (list.size() == 2) {
1442 return list.get(1);
1443 }
1444 else {
1445 return null;
1446 }
1447 }
1448
1449
1455 public void removeByRowId(long rowId) throws SystemException {
1456 for (ExpandoValue expandoValue : findByRowId(rowId, QueryUtil.ALL_POS,
1457 QueryUtil.ALL_POS, null)) {
1458 remove(expandoValue);
1459 }
1460 }
1461
1462
1469 public int countByRowId(long rowId) throws SystemException {
1470 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROWID;
1471
1472 Object[] finderArgs = new Object[] { rowId };
1473
1474 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1475 this);
1476
1477 if (count == null) {
1478 StringBundler query = new StringBundler(2);
1479
1480 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
1481
1482 query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1483
1484 String sql = query.toString();
1485
1486 Session session = null;
1487
1488 try {
1489 session = openSession();
1490
1491 Query q = session.createQuery(sql);
1492
1493 QueryPos qPos = QueryPos.getInstance(q);
1494
1495 qPos.add(rowId);
1496
1497 count = (Long)q.uniqueResult();
1498
1499 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1500 }
1501 catch (Exception e) {
1502 FinderCacheUtil.removeResult(finderPath, finderArgs);
1503
1504 throw processException(e);
1505 }
1506 finally {
1507 closeSession(session);
1508 }
1509 }
1510
1511 return count.intValue();
1512 }
1513
1514 private static final String _FINDER_COLUMN_ROWID_ROWID_2 = "expandoValue.rowId = ?";
1515 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
1516 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
1517 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_C",
1518 new String[] {
1519 Long.class.getName(), Long.class.getName(),
1520
1521 Integer.class.getName(), Integer.class.getName(),
1522 OrderByComparator.class.getName()
1523 });
1524 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
1525 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
1526 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_C",
1527 new String[] { Long.class.getName(), Long.class.getName() },
1528 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
1529 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK |
1530 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK);
1531 public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
1532 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
1533 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C",
1534 new String[] { Long.class.getName(), Long.class.getName() });
1535
1536
1544 public List<ExpandoValue> findByT_C(long tableId, long columnId)
1545 throws SystemException {
1546 return findByT_C(tableId, columnId, QueryUtil.ALL_POS,
1547 QueryUtil.ALL_POS, null);
1548 }
1549
1550
1564 public List<ExpandoValue> findByT_C(long tableId, long columnId, int start,
1565 int end) throws SystemException {
1566 return findByT_C(tableId, columnId, start, end, null);
1567 }
1568
1569
1584 public List<ExpandoValue> findByT_C(long tableId, long columnId, int start,
1585 int end, OrderByComparator orderByComparator) throws SystemException {
1586 boolean pagination = true;
1587 FinderPath finderPath = null;
1588 Object[] finderArgs = null;
1589
1590 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1591 (orderByComparator == null)) {
1592 pagination = false;
1593 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C;
1594 finderArgs = new Object[] { tableId, columnId };
1595 }
1596 else {
1597 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_C;
1598 finderArgs = new Object[] {
1599 tableId, columnId,
1600
1601 start, end, orderByComparator
1602 };
1603 }
1604
1605 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
1606 finderArgs, this);
1607
1608 if ((list != null) && !list.isEmpty()) {
1609 for (ExpandoValue expandoValue : list) {
1610 if ((tableId != expandoValue.getTableId()) ||
1611 (columnId != expandoValue.getColumnId())) {
1612 list = null;
1613
1614 break;
1615 }
1616 }
1617 }
1618
1619 if (list == null) {
1620 StringBundler query = null;
1621
1622 if (orderByComparator != null) {
1623 query = new StringBundler(4 +
1624 (orderByComparator.getOrderByFields().length * 3));
1625 }
1626 else {
1627 query = new StringBundler(4);
1628 }
1629
1630 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1631
1632 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1633
1634 query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
1635
1636 if (orderByComparator != null) {
1637 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1638 orderByComparator);
1639 }
1640 else
1641 if (pagination) {
1642 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1643 }
1644
1645 String sql = query.toString();
1646
1647 Session session = null;
1648
1649 try {
1650 session = openSession();
1651
1652 Query q = session.createQuery(sql);
1653
1654 QueryPos qPos = QueryPos.getInstance(q);
1655
1656 qPos.add(tableId);
1657
1658 qPos.add(columnId);
1659
1660 if (!pagination) {
1661 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1662 start, end, false);
1663
1664 Collections.sort(list);
1665
1666 list = new UnmodifiableList<ExpandoValue>(list);
1667 }
1668 else {
1669 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1670 start, end);
1671 }
1672
1673 cacheResult(list);
1674
1675 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1676 }
1677 catch (Exception e) {
1678 FinderCacheUtil.removeResult(finderPath, finderArgs);
1679
1680 throw processException(e);
1681 }
1682 finally {
1683 closeSession(session);
1684 }
1685 }
1686
1687 return list;
1688 }
1689
1690
1700 public ExpandoValue findByT_C_First(long tableId, long columnId,
1701 OrderByComparator orderByComparator)
1702 throws NoSuchValueException, SystemException {
1703 ExpandoValue expandoValue = fetchByT_C_First(tableId, columnId,
1704 orderByComparator);
1705
1706 if (expandoValue != null) {
1707 return expandoValue;
1708 }
1709
1710 StringBundler msg = new StringBundler(6);
1711
1712 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1713
1714 msg.append("tableId=");
1715 msg.append(tableId);
1716
1717 msg.append(", columnId=");
1718 msg.append(columnId);
1719
1720 msg.append(StringPool.CLOSE_CURLY_BRACE);
1721
1722 throw new NoSuchValueException(msg.toString());
1723 }
1724
1725
1734 public ExpandoValue fetchByT_C_First(long tableId, long columnId,
1735 OrderByComparator orderByComparator) throws SystemException {
1736 List<ExpandoValue> list = findByT_C(tableId, columnId, 0, 1,
1737 orderByComparator);
1738
1739 if (!list.isEmpty()) {
1740 return list.get(0);
1741 }
1742
1743 return null;
1744 }
1745
1746
1756 public ExpandoValue findByT_C_Last(long tableId, long columnId,
1757 OrderByComparator orderByComparator)
1758 throws NoSuchValueException, SystemException {
1759 ExpandoValue expandoValue = fetchByT_C_Last(tableId, columnId,
1760 orderByComparator);
1761
1762 if (expandoValue != null) {
1763 return expandoValue;
1764 }
1765
1766 StringBundler msg = new StringBundler(6);
1767
1768 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1769
1770 msg.append("tableId=");
1771 msg.append(tableId);
1772
1773 msg.append(", columnId=");
1774 msg.append(columnId);
1775
1776 msg.append(StringPool.CLOSE_CURLY_BRACE);
1777
1778 throw new NoSuchValueException(msg.toString());
1779 }
1780
1781
1790 public ExpandoValue fetchByT_C_Last(long tableId, long columnId,
1791 OrderByComparator orderByComparator) throws SystemException {
1792 int count = countByT_C(tableId, columnId);
1793
1794 List<ExpandoValue> list = findByT_C(tableId, columnId, count - 1,
1795 count, orderByComparator);
1796
1797 if (!list.isEmpty()) {
1798 return list.get(0);
1799 }
1800
1801 return null;
1802 }
1803
1804
1815 public ExpandoValue[] findByT_C_PrevAndNext(long valueId, long tableId,
1816 long columnId, OrderByComparator orderByComparator)
1817 throws NoSuchValueException, SystemException {
1818 ExpandoValue expandoValue = findByPrimaryKey(valueId);
1819
1820 Session session = null;
1821
1822 try {
1823 session = openSession();
1824
1825 ExpandoValue[] array = new ExpandoValueImpl[3];
1826
1827 array[0] = getByT_C_PrevAndNext(session, expandoValue, tableId,
1828 columnId, orderByComparator, true);
1829
1830 array[1] = expandoValue;
1831
1832 array[2] = getByT_C_PrevAndNext(session, expandoValue, tableId,
1833 columnId, orderByComparator, false);
1834
1835 return array;
1836 }
1837 catch (Exception e) {
1838 throw processException(e);
1839 }
1840 finally {
1841 closeSession(session);
1842 }
1843 }
1844
1845 protected ExpandoValue getByT_C_PrevAndNext(Session session,
1846 ExpandoValue expandoValue, long tableId, long columnId,
1847 OrderByComparator orderByComparator, boolean previous) {
1848 StringBundler query = null;
1849
1850 if (orderByComparator != null) {
1851 query = new StringBundler(6 +
1852 (orderByComparator.getOrderByFields().length * 6));
1853 }
1854 else {
1855 query = new StringBundler(3);
1856 }
1857
1858 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1859
1860 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1861
1862 query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
1863
1864 if (orderByComparator != null) {
1865 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1866
1867 if (orderByConditionFields.length > 0) {
1868 query.append(WHERE_AND);
1869 }
1870
1871 for (int i = 0; i < orderByConditionFields.length; i++) {
1872 query.append(_ORDER_BY_ENTITY_ALIAS);
1873 query.append(orderByConditionFields[i]);
1874
1875 if ((i + 1) < orderByConditionFields.length) {
1876 if (orderByComparator.isAscending() ^ previous) {
1877 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1878 }
1879 else {
1880 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1881 }
1882 }
1883 else {
1884 if (orderByComparator.isAscending() ^ previous) {
1885 query.append(WHERE_GREATER_THAN);
1886 }
1887 else {
1888 query.append(WHERE_LESSER_THAN);
1889 }
1890 }
1891 }
1892
1893 query.append(ORDER_BY_CLAUSE);
1894
1895 String[] orderByFields = orderByComparator.getOrderByFields();
1896
1897 for (int i = 0; i < orderByFields.length; i++) {
1898 query.append(_ORDER_BY_ENTITY_ALIAS);
1899 query.append(orderByFields[i]);
1900
1901 if ((i + 1) < orderByFields.length) {
1902 if (orderByComparator.isAscending() ^ previous) {
1903 query.append(ORDER_BY_ASC_HAS_NEXT);
1904 }
1905 else {
1906 query.append(ORDER_BY_DESC_HAS_NEXT);
1907 }
1908 }
1909 else {
1910 if (orderByComparator.isAscending() ^ previous) {
1911 query.append(ORDER_BY_ASC);
1912 }
1913 else {
1914 query.append(ORDER_BY_DESC);
1915 }
1916 }
1917 }
1918 }
1919 else {
1920 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1921 }
1922
1923 String sql = query.toString();
1924
1925 Query q = session.createQuery(sql);
1926
1927 q.setFirstResult(0);
1928 q.setMaxResults(2);
1929
1930 QueryPos qPos = QueryPos.getInstance(q);
1931
1932 qPos.add(tableId);
1933
1934 qPos.add(columnId);
1935
1936 if (orderByComparator != null) {
1937 Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
1938
1939 for (Object value : values) {
1940 qPos.add(value);
1941 }
1942 }
1943
1944 List<ExpandoValue> list = q.list();
1945
1946 if (list.size() == 2) {
1947 return list.get(1);
1948 }
1949 else {
1950 return null;
1951 }
1952 }
1953
1954
1961 public void removeByT_C(long tableId, long columnId)
1962 throws SystemException {
1963 for (ExpandoValue expandoValue : findByT_C(tableId, columnId,
1964 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1965 remove(expandoValue);
1966 }
1967 }
1968
1969
1977 public int countByT_C(long tableId, long columnId)
1978 throws SystemException {
1979 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_C;
1980
1981 Object[] finderArgs = new Object[] { tableId, columnId };
1982
1983 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1984 this);
1985
1986 if (count == null) {
1987 StringBundler query = new StringBundler(3);
1988
1989 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
1990
1991 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1992
1993 query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
1994
1995 String sql = query.toString();
1996
1997 Session session = null;
1998
1999 try {
2000 session = openSession();
2001
2002 Query q = session.createQuery(sql);
2003
2004 QueryPos qPos = QueryPos.getInstance(q);
2005
2006 qPos.add(tableId);
2007
2008 qPos.add(columnId);
2009
2010 count = (Long)q.uniqueResult();
2011
2012 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2013 }
2014 catch (Exception e) {
2015 FinderCacheUtil.removeResult(finderPath, finderArgs);
2016
2017 throw processException(e);
2018 }
2019 finally {
2020 closeSession(session);
2021 }
2022 }
2023
2024 return count.intValue();
2025 }
2026
2027 private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoValue.tableId = ? AND ";
2028 private static final String _FINDER_COLUMN_T_C_COLUMNID_2 = "expandoValue.columnId = ?";
2029 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
2030 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
2031 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_CPK",
2032 new String[] {
2033 Long.class.getName(), Long.class.getName(),
2034
2035 Integer.class.getName(), Integer.class.getName(),
2036 OrderByComparator.class.getName()
2037 });
2038 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
2039 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
2040 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_CPK",
2041 new String[] { Long.class.getName(), Long.class.getName() },
2042 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
2043 ExpandoValueModelImpl.CLASSPK_COLUMN_BITMASK |
2044 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK |
2045 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK);
2046 public static final FinderPath FINDER_PATH_COUNT_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
2047 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
2048 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_CPK",
2049 new String[] { Long.class.getName(), Long.class.getName() });
2050
2051
2059 public List<ExpandoValue> findByT_CPK(long tableId, long classPK)
2060 throws SystemException {
2061 return findByT_CPK(tableId, classPK, QueryUtil.ALL_POS,
2062 QueryUtil.ALL_POS, null);
2063 }
2064
2065
2079 public List<ExpandoValue> findByT_CPK(long tableId, long classPK,
2080 int start, int end) throws SystemException {
2081 return findByT_CPK(tableId, classPK, start, end, null);
2082 }
2083
2084
2099 public List<ExpandoValue> findByT_CPK(long tableId, long classPK,
2100 int start, int end, OrderByComparator orderByComparator)
2101 throws SystemException {
2102 boolean pagination = true;
2103 FinderPath finderPath = null;
2104 Object[] finderArgs = null;
2105
2106 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2107 (orderByComparator == null)) {
2108 pagination = false;
2109 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK;
2110 finderArgs = new Object[] { tableId, classPK };
2111 }
2112 else {
2113 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_CPK;
2114 finderArgs = new Object[] {
2115 tableId, classPK,
2116
2117 start, end, orderByComparator
2118 };
2119 }
2120
2121 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
2122 finderArgs, this);
2123
2124 if ((list != null) && !list.isEmpty()) {
2125 for (ExpandoValue expandoValue : list) {
2126 if ((tableId != expandoValue.getTableId()) ||
2127 (classPK != expandoValue.getClassPK())) {
2128 list = null;
2129
2130 break;
2131 }
2132 }
2133 }
2134
2135 if (list == null) {
2136 StringBundler query = null;
2137
2138 if (orderByComparator != null) {
2139 query = new StringBundler(4 +
2140 (orderByComparator.getOrderByFields().length * 3));
2141 }
2142 else {
2143 query = new StringBundler(4);
2144 }
2145
2146 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2147
2148 query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
2149
2150 query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
2151
2152 if (orderByComparator != null) {
2153 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2154 orderByComparator);
2155 }
2156 else
2157 if (pagination) {
2158 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2159 }
2160
2161 String sql = query.toString();
2162
2163 Session session = null;
2164
2165 try {
2166 session = openSession();
2167
2168 Query q = session.createQuery(sql);
2169
2170 QueryPos qPos = QueryPos.getInstance(q);
2171
2172 qPos.add(tableId);
2173
2174 qPos.add(classPK);
2175
2176 if (!pagination) {
2177 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2178 start, end, false);
2179
2180 Collections.sort(list);
2181
2182 list = new UnmodifiableList<ExpandoValue>(list);
2183 }
2184 else {
2185 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2186 start, end);
2187 }
2188
2189 cacheResult(list);
2190
2191 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2192 }
2193 catch (Exception e) {
2194 FinderCacheUtil.removeResult(finderPath, finderArgs);
2195
2196 throw processException(e);
2197 }
2198 finally {
2199 closeSession(session);
2200 }
2201 }
2202
2203 return list;
2204 }
2205
2206
2216 public ExpandoValue findByT_CPK_First(long tableId, long classPK,
2217 OrderByComparator orderByComparator)
2218 throws NoSuchValueException, SystemException {
2219 ExpandoValue expandoValue = fetchByT_CPK_First(tableId, classPK,
2220 orderByComparator);
2221
2222 if (expandoValue != null) {
2223 return expandoValue;
2224 }
2225
2226 StringBundler msg = new StringBundler(6);
2227
2228 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2229
2230 msg.append("tableId=");
2231 msg.append(tableId);
2232
2233 msg.append(", classPK=");
2234 msg.append(classPK);
2235
2236 msg.append(StringPool.CLOSE_CURLY_BRACE);
2237
2238 throw new NoSuchValueException(msg.toString());
2239 }
2240
2241
2250 public ExpandoValue fetchByT_CPK_First(long tableId, long classPK,
2251 OrderByComparator orderByComparator) throws SystemException {
2252 List<ExpandoValue> list = findByT_CPK(tableId, classPK, 0, 1,
2253 orderByComparator);
2254
2255 if (!list.isEmpty()) {
2256 return list.get(0);
2257 }
2258
2259 return null;
2260 }
2261
2262
2272 public ExpandoValue findByT_CPK_Last(long tableId, long classPK,
2273 OrderByComparator orderByComparator)
2274 throws NoSuchValueException, SystemException {
2275 ExpandoValue expandoValue = fetchByT_CPK_Last(tableId, classPK,
2276 orderByComparator);
2277
2278 if (expandoValue != null) {
2279 return expandoValue;
2280 }
2281
2282 StringBundler msg = new StringBundler(6);
2283
2284 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2285
2286 msg.append("tableId=");
2287 msg.append(tableId);
2288
2289 msg.append(", classPK=");
2290 msg.append(classPK);
2291
2292 msg.append(StringPool.CLOSE_CURLY_BRACE);
2293
2294 throw new NoSuchValueException(msg.toString());
2295 }
2296
2297
2306 public ExpandoValue fetchByT_CPK_Last(long tableId, long classPK,
2307 OrderByComparator orderByComparator) throws SystemException {
2308 int count = countByT_CPK(tableId, classPK);
2309
2310 List<ExpandoValue> list = findByT_CPK(tableId, classPK, count - 1,
2311 count, orderByComparator);
2312
2313 if (!list.isEmpty()) {
2314 return list.get(0);
2315 }
2316
2317 return null;
2318 }
2319
2320
2331 public ExpandoValue[] findByT_CPK_PrevAndNext(long valueId, long tableId,
2332 long classPK, OrderByComparator orderByComparator)
2333 throws NoSuchValueException, SystemException {
2334 ExpandoValue expandoValue = findByPrimaryKey(valueId);
2335
2336 Session session = null;
2337
2338 try {
2339 session = openSession();
2340
2341 ExpandoValue[] array = new ExpandoValueImpl[3];
2342
2343 array[0] = getByT_CPK_PrevAndNext(session, expandoValue, tableId,
2344 classPK, orderByComparator, true);
2345
2346 array[1] = expandoValue;
2347
2348 array[2] = getByT_CPK_PrevAndNext(session, expandoValue, tableId,
2349 classPK, orderByComparator, false);
2350
2351 return array;
2352 }
2353 catch (Exception e) {
2354 throw processException(e);
2355 }
2356 finally {
2357 closeSession(session);
2358 }
2359 }
2360
2361 protected ExpandoValue getByT_CPK_PrevAndNext(Session session,
2362 ExpandoValue expandoValue, long tableId, long classPK,
2363 OrderByComparator orderByComparator, boolean previous) {
2364 StringBundler query = null;
2365
2366 if (orderByComparator != null) {
2367 query = new StringBundler(6 +
2368 (orderByComparator.getOrderByFields().length * 6));
2369 }
2370 else {
2371 query = new StringBundler(3);
2372 }
2373
2374 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2375
2376 query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
2377
2378 query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
2379
2380 if (orderByComparator != null) {
2381 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2382
2383 if (orderByConditionFields.length > 0) {
2384 query.append(WHERE_AND);
2385 }
2386
2387 for (int i = 0; i < orderByConditionFields.length; i++) {
2388 query.append(_ORDER_BY_ENTITY_ALIAS);
2389 query.append(orderByConditionFields[i]);
2390
2391 if ((i + 1) < orderByConditionFields.length) {
2392 if (orderByComparator.isAscending() ^ previous) {
2393 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2394 }
2395 else {
2396 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2397 }
2398 }
2399 else {
2400 if (orderByComparator.isAscending() ^ previous) {
2401 query.append(WHERE_GREATER_THAN);
2402 }
2403 else {
2404 query.append(WHERE_LESSER_THAN);
2405 }
2406 }
2407 }
2408
2409 query.append(ORDER_BY_CLAUSE);
2410
2411 String[] orderByFields = orderByComparator.getOrderByFields();
2412
2413 for (int i = 0; i < orderByFields.length; i++) {
2414 query.append(_ORDER_BY_ENTITY_ALIAS);
2415 query.append(orderByFields[i]);
2416
2417 if ((i + 1) < orderByFields.length) {
2418 if (orderByComparator.isAscending() ^ previous) {
2419 query.append(ORDER_BY_ASC_HAS_NEXT);
2420 }
2421 else {
2422 query.append(ORDER_BY_DESC_HAS_NEXT);
2423 }
2424 }
2425 else {
2426 if (orderByComparator.isAscending() ^ previous) {
2427 query.append(ORDER_BY_ASC);
2428 }
2429 else {
2430 query.append(ORDER_BY_DESC);
2431 }
2432 }
2433 }
2434 }
2435 else {
2436 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2437 }
2438
2439 String sql = query.toString();
2440
2441 Query q = session.createQuery(sql);
2442
2443 q.setFirstResult(0);
2444 q.setMaxResults(2);
2445
2446 QueryPos qPos = QueryPos.getInstance(q);
2447
2448 qPos.add(tableId);
2449
2450 qPos.add(classPK);
2451
2452 if (orderByComparator != null) {
2453 Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
2454
2455 for (Object value : values) {
2456 qPos.add(value);
2457 }
2458 }
2459
2460 List<ExpandoValue> list = q.list();
2461
2462 if (list.size() == 2) {
2463 return list.get(1);
2464 }
2465 else {
2466 return null;
2467 }
2468 }
2469
2470
2477 public void removeByT_CPK(long tableId, long classPK)
2478 throws SystemException {
2479 for (ExpandoValue expandoValue : findByT_CPK(tableId, classPK,
2480 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2481 remove(expandoValue);
2482 }
2483 }
2484
2485
2493 public int countByT_CPK(long tableId, long classPK)
2494 throws SystemException {
2495 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_CPK;
2496
2497 Object[] finderArgs = new Object[] { tableId, classPK };
2498
2499 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2500 this);
2501
2502 if (count == null) {
2503 StringBundler query = new StringBundler(3);
2504
2505 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
2506
2507 query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
2508
2509 query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
2510
2511 String sql = query.toString();
2512
2513 Session session = null;
2514
2515 try {
2516 session = openSession();
2517
2518 Query q = session.createQuery(sql);
2519
2520 QueryPos qPos = QueryPos.getInstance(q);
2521
2522 qPos.add(tableId);
2523
2524 qPos.add(classPK);
2525
2526 count = (Long)q.uniqueResult();
2527
2528 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2529 }
2530 catch (Exception e) {
2531 FinderCacheUtil.removeResult(finderPath, finderArgs);
2532
2533 throw processException(e);
2534 }
2535 finally {
2536 closeSession(session);
2537 }
2538 }
2539
2540 return count.intValue();
2541 }
2542
2543 private static final String _FINDER_COLUMN_T_CPK_TABLEID_2 = "expandoValue.tableId = ? AND ";
2544 private static final String _FINDER_COLUMN_T_CPK_CLASSPK_2 = "expandoValue.classPK = ?";
2545 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
2546 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
2547 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_R",
2548 new String[] {
2549 Long.class.getName(), Long.class.getName(),
2550
2551 Integer.class.getName(), Integer.class.getName(),
2552 OrderByComparator.class.getName()
2553 });
2554 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
2555 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
2556 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_R",
2557 new String[] { Long.class.getName(), Long.class.getName() },
2558 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
2559 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK |
2560 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK);
2561 public static final FinderPath FINDER_PATH_COUNT_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
2562 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
2563 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_R",
2564 new String[] { Long.class.getName(), Long.class.getName() });
2565
2566
2574 public List<ExpandoValue> findByT_R(long tableId, long rowId)
2575 throws SystemException {
2576 return findByT_R(tableId, rowId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2577 null);
2578 }
2579
2580
2594 public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
2595 int end) throws SystemException {
2596 return findByT_R(tableId, rowId, start, end, null);
2597 }
2598
2599
2614 public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
2615 int end, OrderByComparator orderByComparator) throws SystemException {
2616 boolean pagination = true;
2617 FinderPath finderPath = null;
2618 Object[] finderArgs = null;
2619
2620 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2621 (orderByComparator == null)) {
2622 pagination = false;
2623 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R;
2624 finderArgs = new Object[] { tableId, rowId };
2625 }
2626 else {
2627 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_R;
2628 finderArgs = new Object[] {
2629 tableId, rowId,
2630
2631 start, end, orderByComparator
2632 };
2633 }
2634
2635 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
2636 finderArgs, this);
2637
2638 if ((list != null) && !list.isEmpty()) {
2639 for (ExpandoValue expandoValue : list) {
2640 if ((tableId != expandoValue.getTableId()) ||
2641 (rowId != expandoValue.getRowId())) {
2642 list = null;
2643
2644 break;
2645 }
2646 }
2647 }
2648
2649 if (list == null) {
2650 StringBundler query = null;
2651
2652 if (orderByComparator != null) {
2653 query = new StringBundler(4 +
2654 (orderByComparator.getOrderByFields().length * 3));
2655 }
2656 else {
2657 query = new StringBundler(4);
2658 }
2659
2660 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2661
2662 query.append(_FINDER_COLUMN_T_R_TABLEID_2);
2663
2664 query.append(_FINDER_COLUMN_T_R_ROWID_2);
2665
2666 if (orderByComparator != null) {
2667 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2668 orderByComparator);
2669 }
2670 else
2671 if (pagination) {
2672 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2673 }
2674
2675 String sql = query.toString();
2676
2677 Session session = null;
2678
2679 try {
2680 session = openSession();
2681
2682 Query q = session.createQuery(sql);
2683
2684 QueryPos qPos = QueryPos.getInstance(q);
2685
2686 qPos.add(tableId);
2687
2688 qPos.add(rowId);
2689
2690 if (!pagination) {
2691 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2692 start, end, false);
2693
2694 Collections.sort(list);
2695
2696 list = new UnmodifiableList<ExpandoValue>(list);
2697 }
2698 else {
2699 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2700 start, end);
2701 }
2702
2703 cacheResult(list);
2704
2705 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2706 }
2707 catch (Exception e) {
2708 FinderCacheUtil.removeResult(finderPath, finderArgs);
2709
2710 throw processException(e);
2711 }
2712 finally {
2713 closeSession(session);
2714 }
2715 }
2716
2717 return list;
2718 }
2719
2720
2730 public ExpandoValue findByT_R_First(long tableId, long rowId,
2731 OrderByComparator orderByComparator)
2732 throws NoSuchValueException, SystemException {
2733 ExpandoValue expandoValue = fetchByT_R_First(tableId, rowId,
2734 orderByComparator);
2735
2736 if (expandoValue != null) {
2737 return expandoValue;
2738 }
2739
2740 StringBundler msg = new StringBundler(6);
2741
2742 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2743
2744 msg.append("tableId=");
2745 msg.append(tableId);
2746
2747 msg.append(", rowId=");
2748 msg.append(rowId);
2749
2750 msg.append(StringPool.CLOSE_CURLY_BRACE);
2751
2752 throw new NoSuchValueException(msg.toString());
2753 }
2754
2755
2764 public ExpandoValue fetchByT_R_First(long tableId, long rowId,
2765 OrderByComparator orderByComparator) throws SystemException {
2766 List<ExpandoValue> list = findByT_R(tableId, rowId, 0, 1,
2767 orderByComparator);
2768
2769 if (!list.isEmpty()) {
2770 return list.get(0);
2771 }
2772
2773 return null;
2774 }
2775
2776
2786 public ExpandoValue findByT_R_Last(long tableId, long rowId,
2787 OrderByComparator orderByComparator)
2788 throws NoSuchValueException, SystemException {
2789 ExpandoValue expandoValue = fetchByT_R_Last(tableId, rowId,
2790 orderByComparator);
2791
2792 if (expandoValue != null) {
2793 return expandoValue;
2794 }
2795
2796 StringBundler msg = new StringBundler(6);
2797
2798 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2799
2800 msg.append("tableId=");
2801 msg.append(tableId);
2802
2803 msg.append(", rowId=");
2804 msg.append(rowId);
2805
2806 msg.append(StringPool.CLOSE_CURLY_BRACE);
2807
2808 throw new NoSuchValueException(msg.toString());
2809 }
2810
2811
2820 public ExpandoValue fetchByT_R_Last(long tableId, long rowId,
2821 OrderByComparator orderByComparator) throws SystemException {
2822 int count = countByT_R(tableId, rowId);
2823
2824 List<ExpandoValue> list = findByT_R(tableId, rowId, count - 1, count,
2825 orderByComparator);
2826
2827 if (!list.isEmpty()) {
2828 return list.get(0);
2829 }
2830
2831 return null;
2832 }
2833
2834
2845 public ExpandoValue[] findByT_R_PrevAndNext(long valueId, long tableId,
2846 long rowId, OrderByComparator orderByComparator)
2847 throws NoSuchValueException, SystemException {
2848 ExpandoValue expandoValue = findByPrimaryKey(valueId);
2849
2850 Session session = null;
2851
2852 try {
2853 session = openSession();
2854
2855 ExpandoValue[] array = new ExpandoValueImpl[3];
2856
2857 array[0] = getByT_R_PrevAndNext(session, expandoValue, tableId,
2858 rowId, orderByComparator, true);
2859
2860 array[1] = expandoValue;
2861
2862 array[2] = getByT_R_PrevAndNext(session, expandoValue, tableId,
2863 rowId, orderByComparator, false);
2864
2865 return array;
2866 }
2867 catch (Exception e) {
2868 throw processException(e);
2869 }
2870 finally {
2871 closeSession(session);
2872 }
2873 }
2874
2875 protected ExpandoValue getByT_R_PrevAndNext(Session session,
2876 ExpandoValue expandoValue, long tableId, long rowId,
2877 OrderByComparator orderByComparator, boolean previous) {
2878 StringBundler query = null;
2879
2880 if (orderByComparator != null) {
2881 query = new StringBundler(6 +
2882 (orderByComparator.getOrderByFields().length * 6));
2883 }
2884 else {
2885 query = new StringBundler(3);
2886 }
2887
2888 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2889
2890 query.append(_FINDER_COLUMN_T_R_TABLEID_2);
2891
2892 query.append(_FINDER_COLUMN_T_R_ROWID_2);
2893
2894 if (orderByComparator != null) {
2895 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2896
2897 if (orderByConditionFields.length > 0) {
2898 query.append(WHERE_AND);
2899 }
2900
2901 for (int i = 0; i < orderByConditionFields.length; i++) {
2902 query.append(_ORDER_BY_ENTITY_ALIAS);
2903 query.append(orderByConditionFields[i]);
2904
2905 if ((i + 1) < orderByConditionFields.length) {
2906 if (orderByComparator.isAscending() ^ previous) {
2907 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2908 }
2909 else {
2910 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2911 }
2912 }
2913 else {
2914 if (orderByComparator.isAscending() ^ previous) {
2915 query.append(WHERE_GREATER_THAN);
2916 }
2917 else {
2918 query.append(WHERE_LESSER_THAN);
2919 }
2920 }
2921 }
2922
2923 query.append(ORDER_BY_CLAUSE);
2924
2925 String[] orderByFields = orderByComparator.getOrderByFields();
2926
2927 for (int i = 0; i < orderByFields.length; i++) {
2928 query.append(_ORDER_BY_ENTITY_ALIAS);
2929 query.append(orderByFields[i]);
2930
2931 if ((i + 1) < orderByFields.length) {
2932 if (orderByComparator.isAscending() ^ previous) {
2933 query.append(ORDER_BY_ASC_HAS_NEXT);
2934 }
2935 else {
2936 query.append(ORDER_BY_DESC_HAS_NEXT);
2937 }
2938 }
2939 else {
2940 if (orderByComparator.isAscending() ^ previous) {
2941 query.append(ORDER_BY_ASC);
2942 }
2943 else {
2944 query.append(ORDER_BY_DESC);
2945 }
2946 }
2947 }
2948 }
2949 else {
2950 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2951 }
2952
2953 String sql = query.toString();
2954
2955 Query q = session.createQuery(sql);
2956
2957 q.setFirstResult(0);
2958 q.setMaxResults(2);
2959
2960 QueryPos qPos = QueryPos.getInstance(q);
2961
2962 qPos.add(tableId);
2963
2964 qPos.add(rowId);
2965
2966 if (orderByComparator != null) {
2967 Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
2968
2969 for (Object value : values) {
2970 qPos.add(value);
2971 }
2972 }
2973
2974 List<ExpandoValue> list = q.list();
2975
2976 if (list.size() == 2) {
2977 return list.get(1);
2978 }
2979 else {
2980 return null;
2981 }
2982 }
2983
2984
2991 public void removeByT_R(long tableId, long rowId) throws SystemException {
2992 for (ExpandoValue expandoValue : findByT_R(tableId, rowId,
2993 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2994 remove(expandoValue);
2995 }
2996 }
2997
2998
3006 public int countByT_R(long tableId, long rowId) throws SystemException {
3007 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_R;
3008
3009 Object[] finderArgs = new Object[] { tableId, rowId };
3010
3011 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3012 this);
3013
3014 if (count == null) {
3015 StringBundler query = new StringBundler(3);
3016
3017 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3018
3019 query.append(_FINDER_COLUMN_T_R_TABLEID_2);
3020
3021 query.append(_FINDER_COLUMN_T_R_ROWID_2);
3022
3023 String sql = query.toString();
3024
3025 Session session = null;
3026
3027 try {
3028 session = openSession();
3029
3030 Query q = session.createQuery(sql);
3031
3032 QueryPos qPos = QueryPos.getInstance(q);
3033
3034 qPos.add(tableId);
3035
3036 qPos.add(rowId);
3037
3038 count = (Long)q.uniqueResult();
3039
3040 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3041 }
3042 catch (Exception e) {
3043 FinderCacheUtil.removeResult(finderPath, finderArgs);
3044
3045 throw processException(e);
3046 }
3047 finally {
3048 closeSession(session);
3049 }
3050 }
3051
3052 return count.intValue();
3053 }
3054
3055 private static final String _FINDER_COLUMN_T_R_TABLEID_2 = "expandoValue.tableId = ? AND ";
3056 private static final String _FINDER_COLUMN_T_R_ROWID_2 = "expandoValue.rowId = ?";
3057 public static final FinderPath FINDER_PATH_FETCH_BY_C_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
3058 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
3059 FINDER_CLASS_NAME_ENTITY, "fetchByC_R",
3060 new String[] { Long.class.getName(), Long.class.getName() },
3061 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK |
3062 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK);
3063 public static final FinderPath FINDER_PATH_COUNT_BY_C_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
3064 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
3065 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R",
3066 new String[] { Long.class.getName(), Long.class.getName() });
3067
3068
3077 public ExpandoValue findByC_R(long columnId, long rowId)
3078 throws NoSuchValueException, SystemException {
3079 ExpandoValue expandoValue = fetchByC_R(columnId, rowId);
3080
3081 if (expandoValue == null) {
3082 StringBundler msg = new StringBundler(6);
3083
3084 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3085
3086 msg.append("columnId=");
3087 msg.append(columnId);
3088
3089 msg.append(", rowId=");
3090 msg.append(rowId);
3091
3092 msg.append(StringPool.CLOSE_CURLY_BRACE);
3093
3094 if (_log.isWarnEnabled()) {
3095 _log.warn(msg.toString());
3096 }
3097
3098 throw new NoSuchValueException(msg.toString());
3099 }
3100
3101 return expandoValue;
3102 }
3103
3104
3112 public ExpandoValue fetchByC_R(long columnId, long rowId)
3113 throws SystemException {
3114 return fetchByC_R(columnId, rowId, true);
3115 }
3116
3117
3126 public ExpandoValue fetchByC_R(long columnId, long rowId,
3127 boolean retrieveFromCache) throws SystemException {
3128 Object[] finderArgs = new Object[] { columnId, rowId };
3129
3130 Object result = null;
3131
3132 if (retrieveFromCache) {
3133 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_R,
3134 finderArgs, this);
3135 }
3136
3137 if (result instanceof ExpandoValue) {
3138 ExpandoValue expandoValue = (ExpandoValue)result;
3139
3140 if ((columnId != expandoValue.getColumnId()) ||
3141 (rowId != expandoValue.getRowId())) {
3142 result = null;
3143 }
3144 }
3145
3146 if (result == null) {
3147 StringBundler query = new StringBundler(4);
3148
3149 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3150
3151 query.append(_FINDER_COLUMN_C_R_COLUMNID_2);
3152
3153 query.append(_FINDER_COLUMN_C_R_ROWID_2);
3154
3155 String sql = query.toString();
3156
3157 Session session = null;
3158
3159 try {
3160 session = openSession();
3161
3162 Query q = session.createQuery(sql);
3163
3164 QueryPos qPos = QueryPos.getInstance(q);
3165
3166 qPos.add(columnId);
3167
3168 qPos.add(rowId);
3169
3170 List<ExpandoValue> list = q.list();
3171
3172 if (list.isEmpty()) {
3173 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
3174 finderArgs, list);
3175 }
3176 else {
3177 ExpandoValue expandoValue = list.get(0);
3178
3179 result = expandoValue;
3180
3181 cacheResult(expandoValue);
3182
3183 if ((expandoValue.getColumnId() != columnId) ||
3184 (expandoValue.getRowId() != rowId)) {
3185 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
3186 finderArgs, expandoValue);
3187 }
3188 }
3189 }
3190 catch (Exception e) {
3191 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R,
3192 finderArgs);
3193
3194 throw processException(e);
3195 }
3196 finally {
3197 closeSession(session);
3198 }
3199 }
3200
3201 if (result instanceof List<?>) {
3202 return null;
3203 }
3204 else {
3205 return (ExpandoValue)result;
3206 }
3207 }
3208
3209
3217 public ExpandoValue removeByC_R(long columnId, long rowId)
3218 throws NoSuchValueException, SystemException {
3219 ExpandoValue expandoValue = findByC_R(columnId, rowId);
3220
3221 return remove(expandoValue);
3222 }
3223
3224
3232 public int countByC_R(long columnId, long rowId) throws SystemException {
3233 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_R;
3234
3235 Object[] finderArgs = new Object[] { columnId, rowId };
3236
3237 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3238 this);
3239
3240 if (count == null) {
3241 StringBundler query = new StringBundler(3);
3242
3243 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3244
3245 query.append(_FINDER_COLUMN_C_R_COLUMNID_2);
3246
3247 query.append(_FINDER_COLUMN_C_R_ROWID_2);
3248
3249 String sql = query.toString();
3250
3251 Session session = null;
3252
3253 try {
3254 session = openSession();
3255
3256 Query q = session.createQuery(sql);
3257
3258 QueryPos qPos = QueryPos.getInstance(q);
3259
3260 qPos.add(columnId);
3261
3262 qPos.add(rowId);
3263
3264 count = (Long)q.uniqueResult();
3265
3266 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3267 }
3268 catch (Exception e) {
3269 FinderCacheUtil.removeResult(finderPath, finderArgs);
3270
3271 throw processException(e);
3272 }
3273 finally {
3274 closeSession(session);
3275 }
3276 }
3277
3278 return count.intValue();
3279 }
3280
3281 private static final String _FINDER_COLUMN_C_R_COLUMNID_2 = "expandoValue.columnId = ? AND ";
3282 private static final String _FINDER_COLUMN_C_R_ROWID_2 = "expandoValue.rowId = ?";
3283 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
3284 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
3285 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
3286 new String[] {
3287 Long.class.getName(), Long.class.getName(),
3288
3289 Integer.class.getName(), Integer.class.getName(),
3290 OrderByComparator.class.getName()
3291 });
3292 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
3293 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
3294 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
3295 new String[] { Long.class.getName(), Long.class.getName() },
3296 ExpandoValueModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3297 ExpandoValueModelImpl.CLASSPK_COLUMN_BITMASK |
3298 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
3299 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK |
3300 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK);
3301 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
3302 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
3303 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
3304 new String[] { Long.class.getName(), Long.class.getName() });
3305
3306
3314 public List<ExpandoValue> findByC_C(long classNameId, long classPK)
3315 throws SystemException {
3316 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
3317 QueryUtil.ALL_POS, null);
3318 }
3319
3320
3334 public List<ExpandoValue> findByC_C(long classNameId, long classPK,
3335 int start, int end) throws SystemException {
3336 return findByC_C(classNameId, classPK, start, end, null);
3337 }
3338
3339
3354 public List<ExpandoValue> findByC_C(long classNameId, long classPK,
3355 int start, int end, OrderByComparator orderByComparator)
3356 throws SystemException {
3357 boolean pagination = true;
3358 FinderPath finderPath = null;
3359 Object[] finderArgs = null;
3360
3361 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3362 (orderByComparator == null)) {
3363 pagination = false;
3364 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
3365 finderArgs = new Object[] { classNameId, classPK };
3366 }
3367 else {
3368 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
3369 finderArgs = new Object[] {
3370 classNameId, classPK,
3371
3372 start, end, orderByComparator
3373 };
3374 }
3375
3376 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
3377 finderArgs, this);
3378
3379 if ((list != null) && !list.isEmpty()) {
3380 for (ExpandoValue expandoValue : list) {
3381 if ((classNameId != expandoValue.getClassNameId()) ||
3382 (classPK != expandoValue.getClassPK())) {
3383 list = null;
3384
3385 break;
3386 }
3387 }
3388 }
3389
3390 if (list == null) {
3391 StringBundler query = null;
3392
3393 if (orderByComparator != null) {
3394 query = new StringBundler(4 +
3395 (orderByComparator.getOrderByFields().length * 3));
3396 }
3397 else {
3398 query = new StringBundler(4);
3399 }
3400
3401 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3402
3403 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3404
3405 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3406
3407 if (orderByComparator != null) {
3408 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3409 orderByComparator);
3410 }
3411 else
3412 if (pagination) {
3413 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
3414 }
3415
3416 String sql = query.toString();
3417
3418 Session session = null;
3419
3420 try {
3421 session = openSession();
3422
3423 Query q = session.createQuery(sql);
3424
3425 QueryPos qPos = QueryPos.getInstance(q);
3426
3427 qPos.add(classNameId);
3428
3429 qPos.add(classPK);
3430
3431 if (!pagination) {
3432 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
3433 start, end, false);
3434
3435 Collections.sort(list);
3436
3437 list = new UnmodifiableList<ExpandoValue>(list);
3438 }
3439 else {
3440 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
3441 start, end);
3442 }
3443
3444 cacheResult(list);
3445
3446 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3447 }
3448 catch (Exception e) {
3449 FinderCacheUtil.removeResult(finderPath, finderArgs);
3450
3451 throw processException(e);
3452 }
3453 finally {
3454 closeSession(session);
3455 }
3456 }
3457
3458 return list;
3459 }
3460
3461
3471 public ExpandoValue findByC_C_First(long classNameId, long classPK,
3472 OrderByComparator orderByComparator)
3473 throws NoSuchValueException, SystemException {
3474 ExpandoValue expandoValue = fetchByC_C_First(classNameId, classPK,
3475 orderByComparator);
3476
3477 if (expandoValue != null) {
3478 return expandoValue;
3479 }
3480
3481 StringBundler msg = new StringBundler(6);
3482
3483 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3484
3485 msg.append("classNameId=");
3486 msg.append(classNameId);
3487
3488 msg.append(", classPK=");
3489 msg.append(classPK);
3490
3491 msg.append(StringPool.CLOSE_CURLY_BRACE);
3492
3493 throw new NoSuchValueException(msg.toString());
3494 }
3495
3496
3505 public ExpandoValue fetchByC_C_First(long classNameId, long classPK,
3506 OrderByComparator orderByComparator) throws SystemException {
3507 List<ExpandoValue> list = findByC_C(classNameId, classPK, 0, 1,
3508 orderByComparator);
3509
3510 if (!list.isEmpty()) {
3511 return list.get(0);
3512 }
3513
3514 return null;
3515 }
3516
3517
3527 public ExpandoValue findByC_C_Last(long classNameId, long classPK,
3528 OrderByComparator orderByComparator)
3529 throws NoSuchValueException, SystemException {
3530 ExpandoValue expandoValue = fetchByC_C_Last(classNameId, classPK,
3531 orderByComparator);
3532
3533 if (expandoValue != null) {
3534 return expandoValue;
3535 }
3536
3537 StringBundler msg = new StringBundler(6);
3538
3539 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3540
3541 msg.append("classNameId=");
3542 msg.append(classNameId);
3543
3544 msg.append(", classPK=");
3545 msg.append(classPK);
3546
3547 msg.append(StringPool.CLOSE_CURLY_BRACE);
3548
3549 throw new NoSuchValueException(msg.toString());
3550 }
3551
3552
3561 public ExpandoValue fetchByC_C_Last(long classNameId, long classPK,
3562 OrderByComparator orderByComparator) throws SystemException {
3563 int count = countByC_C(classNameId, classPK);
3564
3565 List<ExpandoValue> list = findByC_C(classNameId, classPK, count - 1,
3566 count, orderByComparator);
3567
3568 if (!list.isEmpty()) {
3569 return list.get(0);
3570 }
3571
3572 return null;
3573 }
3574
3575
3586 public ExpandoValue[] findByC_C_PrevAndNext(long valueId, long classNameId,
3587 long classPK, OrderByComparator orderByComparator)
3588 throws NoSuchValueException, SystemException {
3589 ExpandoValue expandoValue = findByPrimaryKey(valueId);
3590
3591 Session session = null;
3592
3593 try {
3594 session = openSession();
3595
3596 ExpandoValue[] array = new ExpandoValueImpl[3];
3597
3598 array[0] = getByC_C_PrevAndNext(session, expandoValue, classNameId,
3599 classPK, orderByComparator, true);
3600
3601 array[1] = expandoValue;
3602
3603 array[2] = getByC_C_PrevAndNext(session, expandoValue, classNameId,
3604 classPK, orderByComparator, false);
3605
3606 return array;
3607 }
3608 catch (Exception e) {
3609 throw processException(e);
3610 }
3611 finally {
3612 closeSession(session);
3613 }
3614 }
3615
3616 protected ExpandoValue getByC_C_PrevAndNext(Session session,
3617 ExpandoValue expandoValue, long classNameId, long classPK,
3618 OrderByComparator orderByComparator, boolean previous) {
3619 StringBundler query = null;
3620
3621 if (orderByComparator != null) {
3622 query = new StringBundler(6 +
3623 (orderByComparator.getOrderByFields().length * 6));
3624 }
3625 else {
3626 query = new StringBundler(3);
3627 }
3628
3629 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3630
3631 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3632
3633 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3634
3635 if (orderByComparator != null) {
3636 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3637
3638 if (orderByConditionFields.length > 0) {
3639 query.append(WHERE_AND);
3640 }
3641
3642 for (int i = 0; i < orderByConditionFields.length; i++) {
3643 query.append(_ORDER_BY_ENTITY_ALIAS);
3644 query.append(orderByConditionFields[i]);
3645
3646 if ((i + 1) < orderByConditionFields.length) {
3647 if (orderByComparator.isAscending() ^ previous) {
3648 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3649 }
3650 else {
3651 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3652 }
3653 }
3654 else {
3655 if (orderByComparator.isAscending() ^ previous) {
3656 query.append(WHERE_GREATER_THAN);
3657 }
3658 else {
3659 query.append(WHERE_LESSER_THAN);
3660 }
3661 }
3662 }
3663
3664 query.append(ORDER_BY_CLAUSE);
3665
3666 String[] orderByFields = orderByComparator.getOrderByFields();
3667
3668 for (int i = 0; i < orderByFields.length; i++) {
3669 query.append(_ORDER_BY_ENTITY_ALIAS);
3670 query.append(orderByFields[i]);
3671
3672 if ((i + 1) < orderByFields.length) {
3673 if (orderByComparator.isAscending() ^ previous) {
3674 query.append(ORDER_BY_ASC_HAS_NEXT);
3675 }
3676 else {
3677 query.append(ORDER_BY_DESC_HAS_NEXT);
3678 }
3679 }
3680 else {
3681 if (orderByComparator.isAscending() ^ previous) {
3682 query.append(ORDER_BY_ASC);
3683 }
3684 else {
3685 query.append(ORDER_BY_DESC);
3686 }
3687 }
3688 }
3689 }
3690 else {
3691 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
3692 }
3693
3694 String sql = query.toString();
3695
3696 Query q = session.createQuery(sql);
3697
3698 q.setFirstResult(0);
3699 q.setMaxResults(2);
3700
3701 QueryPos qPos = QueryPos.getInstance(q);
3702
3703 qPos.add(classNameId);
3704
3705 qPos.add(classPK);
3706
3707 if (orderByComparator != null) {
3708 Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
3709
3710 for (Object value : values) {
3711 qPos.add(value);
3712 }
3713 }
3714
3715 List<ExpandoValue> list = q.list();
3716
3717 if (list.size() == 2) {
3718 return list.get(1);
3719 }
3720 else {
3721 return null;
3722 }
3723 }
3724
3725
3732 public void removeByC_C(long classNameId, long classPK)
3733 throws SystemException {
3734 for (ExpandoValue expandoValue : findByC_C(classNameId, classPK,
3735 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3736 remove(expandoValue);
3737 }
3738 }
3739
3740
3748 public int countByC_C(long classNameId, long classPK)
3749 throws SystemException {
3750 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
3751
3752 Object[] finderArgs = new Object[] { classNameId, classPK };
3753
3754 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3755 this);
3756
3757 if (count == null) {
3758 StringBundler query = new StringBundler(3);
3759
3760 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3761
3762 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3763
3764 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3765
3766 String sql = query.toString();
3767
3768 Session session = null;
3769
3770 try {
3771 session = openSession();
3772
3773 Query q = session.createQuery(sql);
3774
3775 QueryPos qPos = QueryPos.getInstance(q);
3776
3777 qPos.add(classNameId);
3778
3779 qPos.add(classPK);
3780
3781 count = (Long)q.uniqueResult();
3782
3783 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3784 }
3785 catch (Exception e) {
3786 FinderCacheUtil.removeResult(finderPath, finderArgs);
3787
3788 throw processException(e);
3789 }
3790 finally {
3791 closeSession(session);
3792 }
3793 }
3794
3795 return count.intValue();
3796 }
3797
3798 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoValue.classNameId = ? AND ";
3799 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "expandoValue.classPK = ?";
3800 public static final FinderPath FINDER_PATH_FETCH_BY_T_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
3801 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
3802 FINDER_CLASS_NAME_ENTITY, "fetchByT_C_C",
3803 new String[] {
3804 Long.class.getName(), Long.class.getName(), Long.class.getName()
3805 },
3806 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
3807 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK |
3808 ExpandoValueModelImpl.CLASSPK_COLUMN_BITMASK);
3809 public static final FinderPath FINDER_PATH_COUNT_BY_T_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
3810 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
3811 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C_C",
3812 new String[] {
3813 Long.class.getName(), Long.class.getName(), Long.class.getName()
3814 });
3815
3816
3826 public ExpandoValue findByT_C_C(long tableId, long columnId, long classPK)
3827 throws NoSuchValueException, SystemException {
3828 ExpandoValue expandoValue = fetchByT_C_C(tableId, columnId, classPK);
3829
3830 if (expandoValue == null) {
3831 StringBundler msg = new StringBundler(8);
3832
3833 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3834
3835 msg.append("tableId=");
3836 msg.append(tableId);
3837
3838 msg.append(", columnId=");
3839 msg.append(columnId);
3840
3841 msg.append(", classPK=");
3842 msg.append(classPK);
3843
3844 msg.append(StringPool.CLOSE_CURLY_BRACE);
3845
3846 if (_log.isWarnEnabled()) {
3847 _log.warn(msg.toString());
3848 }
3849
3850 throw new NoSuchValueException(msg.toString());
3851 }
3852
3853 return expandoValue;
3854 }
3855
3856
3865 public ExpandoValue fetchByT_C_C(long tableId, long columnId, long classPK)
3866 throws SystemException {
3867 return fetchByT_C_C(tableId, columnId, classPK, true);
3868 }
3869
3870
3880 public ExpandoValue fetchByT_C_C(long tableId, long columnId, long classPK,
3881 boolean retrieveFromCache) throws SystemException {
3882 Object[] finderArgs = new Object[] { tableId, columnId, classPK };
3883
3884 Object result = null;
3885
3886 if (retrieveFromCache) {
3887 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C_C,
3888 finderArgs, this);
3889 }
3890
3891 if (result instanceof ExpandoValue) {
3892 ExpandoValue expandoValue = (ExpandoValue)result;
3893
3894 if ((tableId != expandoValue.getTableId()) ||
3895 (columnId != expandoValue.getColumnId()) ||
3896 (classPK != expandoValue.getClassPK())) {
3897 result = null;
3898 }
3899 }
3900
3901 if (result == null) {
3902 StringBundler query = new StringBundler(5);
3903
3904 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3905
3906 query.append(_FINDER_COLUMN_T_C_C_TABLEID_2);
3907
3908 query.append(_FINDER_COLUMN_T_C_C_COLUMNID_2);
3909
3910 query.append(_FINDER_COLUMN_T_C_C_CLASSPK_2);
3911
3912 String sql = query.toString();
3913
3914 Session session = null;
3915
3916 try {
3917 session = openSession();
3918
3919 Query q = session.createQuery(sql);
3920
3921 QueryPos qPos = QueryPos.getInstance(q);
3922
3923 qPos.add(tableId);
3924
3925 qPos.add(columnId);
3926
3927 qPos.add(classPK);
3928
3929 List<ExpandoValue> list = q.list();
3930
3931 if (list.isEmpty()) {
3932 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
3933 finderArgs, list);
3934 }
3935 else {
3936 ExpandoValue expandoValue = list.get(0);
3937
3938 result = expandoValue;
3939
3940 cacheResult(expandoValue);
3941
3942 if ((expandoValue.getTableId() != tableId) ||
3943 (expandoValue.getColumnId() != columnId) ||
3944 (expandoValue.getClassPK() != classPK)) {
3945 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
3946 finderArgs, expandoValue);
3947 }
3948 }
3949 }
3950 catch (Exception e) {
3951 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C,
3952 finderArgs);
3953
3954 throw processException(e);
3955 }
3956 finally {
3957 closeSession(session);
3958 }
3959 }
3960
3961 if (result instanceof List<?>) {
3962 return null;
3963 }
3964 else {
3965 return (ExpandoValue)result;
3966 }
3967 }
3968
3969
3978 public ExpandoValue removeByT_C_C(long tableId, long columnId, long classPK)
3979 throws NoSuchValueException, SystemException {
3980 ExpandoValue expandoValue = findByT_C_C(tableId, columnId, classPK);
3981
3982 return remove(expandoValue);
3983 }
3984
3985
3994 public int countByT_C_C(long tableId, long columnId, long classPK)
3995 throws SystemException {
3996 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_C_C;
3997
3998 Object[] finderArgs = new Object[] { tableId, columnId, classPK };
3999
4000 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4001 this);
4002
4003 if (count == null) {
4004 StringBundler query = new StringBundler(4);
4005
4006 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
4007
4008 query.append(_FINDER_COLUMN_T_C_C_TABLEID_2);
4009
4010 query.append(_FINDER_COLUMN_T_C_C_COLUMNID_2);
4011
4012 query.append(_FINDER_COLUMN_T_C_C_CLASSPK_2);
4013
4014 String sql = query.toString();
4015
4016 Session session = null;
4017
4018 try {
4019 session = openSession();
4020
4021 Query q = session.createQuery(sql);
4022
4023 QueryPos qPos = QueryPos.getInstance(q);
4024
4025 qPos.add(tableId);
4026
4027 qPos.add(columnId);
4028
4029 qPos.add(classPK);
4030
4031 count = (Long)q.uniqueResult();
4032
4033 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4034 }
4035 catch (Exception e) {
4036 FinderCacheUtil.removeResult(finderPath, finderArgs);
4037
4038 throw processException(e);
4039 }
4040 finally {
4041 closeSession(session);
4042 }
4043 }
4044
4045 return count.intValue();
4046 }
4047
4048 private static final String _FINDER_COLUMN_T_C_C_TABLEID_2 = "expandoValue.tableId = ? AND ";
4049 private static final String _FINDER_COLUMN_T_C_C_COLUMNID_2 = "expandoValue.columnId = ? AND ";
4050 private static final String _FINDER_COLUMN_T_C_C_CLASSPK_2 = "expandoValue.classPK = ?";
4051 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
4052 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
4053 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_C_D",
4054 new String[] {
4055 Long.class.getName(), Long.class.getName(),
4056 String.class.getName(),
4057
4058 Integer.class.getName(), Integer.class.getName(),
4059 OrderByComparator.class.getName()
4060 });
4061 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
4062 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
4063 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_C_D",
4064 new String[] {
4065 Long.class.getName(), Long.class.getName(),
4066 String.class.getName()
4067 },
4068 ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
4069 ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK |
4070 ExpandoValueModelImpl.DATA_COLUMN_BITMASK |
4071 ExpandoValueModelImpl.ROWID_COLUMN_BITMASK);
4072 public static final FinderPath FINDER_PATH_COUNT_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
4073 ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
4074 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C_D",
4075 new String[] {
4076 Long.class.getName(), Long.class.getName(),
4077 String.class.getName()
4078 });
4079
4080
4089 public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
4090 String data) throws SystemException {
4091 return findByT_C_D(tableId, columnId, data, QueryUtil.ALL_POS,
4092 QueryUtil.ALL_POS, null);
4093 }
4094
4095
4110 public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
4111 String data, int start, int end) throws SystemException {
4112 return findByT_C_D(tableId, columnId, data, start, end, null);
4113 }
4114
4115
4131 public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
4132 String data, int start, int end, OrderByComparator orderByComparator)
4133 throws SystemException {
4134 boolean pagination = true;
4135 FinderPath finderPath = null;
4136 Object[] finderArgs = null;
4137
4138 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4139 (orderByComparator == null)) {
4140 pagination = false;
4141 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D;
4142 finderArgs = new Object[] { tableId, columnId, data };
4143 }
4144 else {
4145 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_C_D;
4146 finderArgs = new Object[] {
4147 tableId, columnId, data,
4148
4149 start, end, orderByComparator
4150 };
4151 }
4152
4153 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
4154 finderArgs, this);
4155
4156 if ((list != null) && !list.isEmpty()) {
4157 for (ExpandoValue expandoValue : list) {
4158 if ((tableId != expandoValue.getTableId()) ||
4159 (columnId != expandoValue.getColumnId()) ||
4160 !Validator.equals(data, expandoValue.getData())) {
4161 list = null;
4162
4163 break;
4164 }
4165 }
4166 }
4167
4168 if (list == null) {
4169 StringBundler query = null;
4170
4171 if (orderByComparator != null) {
4172 query = new StringBundler(5 +
4173 (orderByComparator.getOrderByFields().length * 3));
4174 }
4175 else {
4176 query = new StringBundler(5);
4177 }
4178
4179 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
4180
4181 query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
4182
4183 query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
4184
4185 boolean bindData = false;
4186
4187 if (data == null) {
4188 query.append(_FINDER_COLUMN_T_C_D_DATA_1);
4189 }
4190 else if (data.equals(StringPool.BLANK)) {
4191 query.append(_FINDER_COLUMN_T_C_D_DATA_3);
4192 }
4193 else {
4194 bindData = true;
4195
4196 query.append(_FINDER_COLUMN_T_C_D_DATA_2);
4197 }
4198
4199 if (orderByComparator != null) {
4200 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4201 orderByComparator);
4202 }
4203 else
4204 if (pagination) {
4205 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
4206 }
4207
4208 String sql = query.toString();
4209
4210 Session session = null;
4211
4212 try {
4213 session = openSession();
4214
4215 Query q = session.createQuery(sql);
4216
4217 QueryPos qPos = QueryPos.getInstance(q);
4218
4219 qPos.add(tableId);
4220
4221 qPos.add(columnId);
4222
4223 if (bindData) {
4224 qPos.add(data);
4225 }
4226
4227 if (!pagination) {
4228 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
4229 start, end, false);
4230
4231 Collections.sort(list);
4232
4233 list = new UnmodifiableList<ExpandoValue>(list);
4234 }
4235 else {
4236 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
4237 start, end);
4238 }
4239
4240 cacheResult(list);
4241
4242 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4243 }
4244 catch (Exception e) {
4245 FinderCacheUtil.removeResult(finderPath, finderArgs);
4246
4247 throw processException(e);
4248 }
4249 finally {
4250 closeSession(session);
4251 }
4252 }
4253
4254 return list;
4255 }
4256
4257
4268 public ExpandoValue findByT_C_D_First(long tableId, long columnId,
4269 String data, OrderByComparator orderByComparator)
4270 throws NoSuchValueException, SystemException {
4271 ExpandoValue expandoValue = fetchByT_C_D_First(tableId, columnId, data,
4272 orderByComparator);
4273
4274 if (expandoValue != null) {
4275 return expandoValue;
4276 }
4277
4278 StringBundler msg = new StringBundler(8);
4279
4280 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4281
4282 msg.append("tableId=");
4283 msg.append(tableId);
4284
4285 msg.append(", columnId=");
4286 msg.append(columnId);
4287
4288 msg.append(", data=");
4289 msg.append(data);
4290
4291 msg.append(StringPool.CLOSE_CURLY_BRACE);
4292
4293 throw new NoSuchValueException(msg.toString());
4294 }
4295
4296
4306 public ExpandoValue fetchByT_C_D_First(long tableId, long columnId,
4307 String data, OrderByComparator orderByComparator)
4308 throws SystemException {
4309 List<ExpandoValue> list = findByT_C_D(tableId, columnId, data, 0, 1,
4310 orderByComparator);
4311
4312 if (!list.isEmpty()) {
4313 return list.get(0);
4314 }
4315
4316 return null;
4317 }
4318
4319
4330 public ExpandoValue findByT_C_D_Last(long tableId, long columnId,
4331 String data, OrderByComparator orderByComparator)
4332 throws NoSuchValueException, SystemException {
4333 ExpandoValue expandoValue = fetchByT_C_D_Last(tableId, columnId, data,
4334 orderByComparator);
4335
4336 if (expandoValue != null) {
4337 return expandoValue;
4338 }
4339
4340 StringBundler msg = new StringBundler(8);
4341
4342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4343
4344 msg.append("tableId=");
4345 msg.append(tableId);
4346
4347 msg.append(", columnId=");
4348 msg.append(columnId);
4349
4350 msg.append(", data=");
4351 msg.append(data);
4352
4353 msg.append(StringPool.CLOSE_CURLY_BRACE);
4354
4355 throw new NoSuchValueException(msg.toString());
4356 }
4357
4358
4368 public ExpandoValue fetchByT_C_D_Last(long tableId, long columnId,
4369 String data, OrderByComparator orderByComparator)
4370 throws SystemException {
4371 int count = countByT_C_D(tableId, columnId, data);
4372
4373 List<ExpandoValue> list = findByT_C_D(tableId, columnId, data,
4374 count - 1, count, orderByComparator);
4375
4376 if (!list.isEmpty()) {
4377 return list.get(0);
4378 }
4379
4380 return null;
4381 }
4382
4383
4395 public ExpandoValue[] findByT_C_D_PrevAndNext(long valueId, long tableId,
4396 long columnId, String data, OrderByComparator orderByComparator)
4397 throws NoSuchValueException, SystemException {
4398 ExpandoValue expandoValue = findByPrimaryKey(valueId);
4399
4400 Session session = null;
4401
4402 try {
4403 session = openSession();
4404
4405 ExpandoValue[] array = new ExpandoValueImpl[3];
4406
4407 array[0] = getByT_C_D_PrevAndNext(session, expandoValue, tableId,
4408 columnId, data, orderByComparator, true);
4409
4410 array[1] = expandoValue;
4411
4412 array[2] = getByT_C_D_PrevAndNext(session, expandoValue, tableId,
4413 columnId, data, orderByComparator, false);
4414
4415 return array;
4416 }
4417 catch (Exception e) {
4418 throw processException(e);
4419 }
4420 finally {
4421 closeSession(session);
4422 }
4423 }
4424
4425 protected ExpandoValue getByT_C_D_PrevAndNext(Session session,
4426 ExpandoValue expandoValue, long tableId, long columnId, String data,
4427 OrderByComparator orderByComparator, boolean previous) {
4428 StringBundler query = null;
4429
4430 if (orderByComparator != null) {
4431 query = new StringBundler(6 +
4432 (orderByComparator.getOrderByFields().length * 6));
4433 }
4434 else {
4435 query = new StringBundler(3);
4436 }
4437
4438 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
4439
4440 query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
4441
4442 query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
4443
4444 boolean bindData = false;
4445
4446 if (data == null) {
4447 query.append(_FINDER_COLUMN_T_C_D_DATA_1);
4448 }
4449 else if (data.equals(StringPool.BLANK)) {
4450 query.append(_FINDER_COLUMN_T_C_D_DATA_3);
4451 }
4452 else {
4453 bindData = true;
4454
4455 query.append(_FINDER_COLUMN_T_C_D_DATA_2);
4456 }
4457
4458 if (orderByComparator != null) {
4459 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4460
4461 if (orderByConditionFields.length > 0) {
4462 query.append(WHERE_AND);
4463 }
4464
4465 for (int i = 0; i < orderByConditionFields.length; i++) {
4466 query.append(_ORDER_BY_ENTITY_ALIAS);
4467 query.append(orderByConditionFields[i]);
4468
4469 if ((i + 1) < orderByConditionFields.length) {
4470 if (orderByComparator.isAscending() ^ previous) {
4471 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4472 }
4473 else {
4474 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4475 }
4476 }
4477 else {
4478 if (orderByComparator.isAscending() ^ previous) {
4479 query.append(WHERE_GREATER_THAN);
4480 }
4481 else {
4482 query.append(WHERE_LESSER_THAN);
4483 }
4484 }
4485 }
4486
4487 query.append(ORDER_BY_CLAUSE);
4488
4489 String[] orderByFields = orderByComparator.getOrderByFields();
4490
4491 for (int i = 0; i < orderByFields.length; i++) {
4492 query.append(_ORDER_BY_ENTITY_ALIAS);
4493 query.append(orderByFields[i]);
4494
4495 if ((i + 1) < orderByFields.length) {
4496 if (orderByComparator.isAscending() ^ previous) {
4497 query.append(ORDER_BY_ASC_HAS_NEXT);
4498 }
4499 else {
4500 query.append(ORDER_BY_DESC_HAS_NEXT);
4501 }
4502 }
4503 else {
4504 if (orderByComparator.isAscending() ^ previous) {
4505 query.append(ORDER_BY_ASC);
4506 }
4507 else {
4508 query.append(ORDER_BY_DESC);
4509 }
4510 }
4511 }
4512 }
4513 else {
4514 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
4515 }
4516
4517 String sql = query.toString();
4518
4519 Query q = session.createQuery(sql);
4520
4521 q.setFirstResult(0);
4522 q.setMaxResults(2);
4523
4524 QueryPos qPos = QueryPos.getInstance(q);
4525
4526 qPos.add(tableId);
4527
4528 qPos.add(columnId);
4529
4530 if (bindData) {
4531 qPos.add(data);
4532 }
4533
4534 if (orderByComparator != null) {
4535 Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
4536
4537 for (Object value : values) {
4538 qPos.add(value);
4539 }
4540 }
4541
4542 List<ExpandoValue> list = q.list();
4543
4544 if (list.size() == 2) {
4545 return list.get(1);
4546 }
4547 else {
4548 return null;
4549 }
4550 }
4551
4552
4560 public void removeByT_C_D(long tableId, long columnId, String data)
4561 throws SystemException {
4562 for (ExpandoValue expandoValue : findByT_C_D(tableId, columnId, data,
4563 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4564 remove(expandoValue);
4565 }
4566 }
4567
4568
4577 public int countByT_C_D(long tableId, long columnId, String data)
4578 throws SystemException {
4579 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_C_D;
4580
4581 Object[] finderArgs = new Object[] { tableId, columnId, data };
4582
4583 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4584 this);
4585
4586 if (count == null) {
4587 StringBundler query = new StringBundler(4);
4588
4589 query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
4590
4591 query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
4592
4593 query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
4594
4595 boolean bindData = false;
4596
4597 if (data == null) {
4598 query.append(_FINDER_COLUMN_T_C_D_DATA_1);
4599 }
4600 else if (data.equals(StringPool.BLANK)) {
4601 query.append(_FINDER_COLUMN_T_C_D_DATA_3);
4602 }
4603 else {
4604 bindData = true;
4605
4606 query.append(_FINDER_COLUMN_T_C_D_DATA_2);
4607 }
4608
4609 String sql = query.toString();
4610
4611 Session session = null;
4612
4613 try {
4614 session = openSession();
4615
4616 Query q = session.createQuery(sql);
4617
4618 QueryPos qPos = QueryPos.getInstance(q);
4619
4620 qPos.add(tableId);
4621
4622 qPos.add(columnId);
4623
4624 if (bindData) {
4625 qPos.add(data);
4626 }
4627
4628 count = (Long)q.uniqueResult();
4629
4630 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4631 }
4632 catch (Exception e) {
4633 FinderCacheUtil.removeResult(finderPath, finderArgs);
4634
4635 throw processException(e);
4636 }
4637 finally {
4638 closeSession(session);
4639 }
4640 }
4641
4642 return count.intValue();
4643 }
4644
4645 private static final String _FINDER_COLUMN_T_C_D_TABLEID_2 = "expandoValue.tableId = ? AND ";
4646 private static final String _FINDER_COLUMN_T_C_D_COLUMNID_2 = "expandoValue.columnId = ? AND ";
4647 private static final String _FINDER_COLUMN_T_C_D_DATA_1 = "expandoValue.data IS NULL";
4648 private static final String _FINDER_COLUMN_T_C_D_DATA_2 = "expandoValue.data = ?";
4649 private static final String _FINDER_COLUMN_T_C_D_DATA_3 = "(expandoValue.data IS NULL OR expandoValue.data = '')";
4650
4651
4656 public void cacheResult(ExpandoValue expandoValue) {
4657 EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
4658 ExpandoValueImpl.class, expandoValue.getPrimaryKey(), expandoValue);
4659
4660 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
4661 new Object[] { expandoValue.getColumnId(), expandoValue.getRowId() },
4662 expandoValue);
4663
4664 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
4665 new Object[] {
4666 expandoValue.getTableId(), expandoValue.getColumnId(),
4667 expandoValue.getClassPK()
4668 }, expandoValue);
4669
4670 expandoValue.resetOriginalValues();
4671 }
4672
4673
4678 public void cacheResult(List<ExpandoValue> expandoValues) {
4679 for (ExpandoValue expandoValue : expandoValues) {
4680 if (EntityCacheUtil.getResult(
4681 ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
4682 ExpandoValueImpl.class, expandoValue.getPrimaryKey()) == null) {
4683 cacheResult(expandoValue);
4684 }
4685 else {
4686 expandoValue.resetOriginalValues();
4687 }
4688 }
4689 }
4690
4691
4698 @Override
4699 public void clearCache() {
4700 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4701 CacheRegistryUtil.clear(ExpandoValueImpl.class.getName());
4702 }
4703
4704 EntityCacheUtil.clearCache(ExpandoValueImpl.class.getName());
4705
4706 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4707 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4708 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4709 }
4710
4711
4718 @Override
4719 public void clearCache(ExpandoValue expandoValue) {
4720 EntityCacheUtil.removeResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
4721 ExpandoValueImpl.class, expandoValue.getPrimaryKey());
4722
4723 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4724 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4725
4726 clearUniqueFindersCache(expandoValue);
4727 }
4728
4729 @Override
4730 public void clearCache(List<ExpandoValue> expandoValues) {
4731 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4732 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4733
4734 for (ExpandoValue expandoValue : expandoValues) {
4735 EntityCacheUtil.removeResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
4736 ExpandoValueImpl.class, expandoValue.getPrimaryKey());
4737
4738 clearUniqueFindersCache(expandoValue);
4739 }
4740 }
4741
4742 protected void cacheUniqueFindersCache(ExpandoValue expandoValue) {
4743 if (expandoValue.isNew()) {
4744 Object[] args = new Object[] {
4745 expandoValue.getColumnId(), expandoValue.getRowId()
4746 };
4747
4748 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R, args,
4749 Long.valueOf(1));
4750 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R, args,
4751 expandoValue);
4752
4753 args = new Object[] {
4754 expandoValue.getTableId(), expandoValue.getColumnId(),
4755 expandoValue.getClassPK()
4756 };
4757
4758 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C_C, args,
4759 Long.valueOf(1));
4760 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C, args,
4761 expandoValue);
4762 }
4763 else {
4764 ExpandoValueModelImpl expandoValueModelImpl = (ExpandoValueModelImpl)expandoValue;
4765
4766 if ((expandoValueModelImpl.getColumnBitmask() &
4767 FINDER_PATH_FETCH_BY_C_R.getColumnBitmask()) != 0) {
4768 Object[] args = new Object[] {
4769 expandoValue.getColumnId(), expandoValue.getRowId()
4770 };
4771
4772 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R, args,
4773 Long.valueOf(1));
4774 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R, args,
4775 expandoValue);
4776 }
4777
4778 if ((expandoValueModelImpl.getColumnBitmask() &
4779 FINDER_PATH_FETCH_BY_T_C_C.getColumnBitmask()) != 0) {
4780 Object[] args = new Object[] {
4781 expandoValue.getTableId(), expandoValue.getColumnId(),
4782 expandoValue.getClassPK()
4783 };
4784
4785 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C_C, args,
4786 Long.valueOf(1));
4787 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C, args,
4788 expandoValue);
4789 }
4790 }
4791 }
4792
4793 protected void clearUniqueFindersCache(ExpandoValue expandoValue) {
4794 ExpandoValueModelImpl expandoValueModelImpl = (ExpandoValueModelImpl)expandoValue;
4795
4796 Object[] args = new Object[] {
4797 expandoValue.getColumnId(), expandoValue.getRowId()
4798 };
4799
4800 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
4801 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R, args);
4802
4803 if ((expandoValueModelImpl.getColumnBitmask() &
4804 FINDER_PATH_FETCH_BY_C_R.getColumnBitmask()) != 0) {
4805 args = new Object[] {
4806 expandoValueModelImpl.getOriginalColumnId(),
4807 expandoValueModelImpl.getOriginalRowId()
4808 };
4809
4810 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
4811 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R, args);
4812 }
4813
4814 args = new Object[] {
4815 expandoValue.getTableId(), expandoValue.getColumnId(),
4816 expandoValue.getClassPK()
4817 };
4818
4819 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C_C, args);
4820 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C, args);
4821
4822 if ((expandoValueModelImpl.getColumnBitmask() &
4823 FINDER_PATH_FETCH_BY_T_C_C.getColumnBitmask()) != 0) {
4824 args = new Object[] {
4825 expandoValueModelImpl.getOriginalTableId(),
4826 expandoValueModelImpl.getOriginalColumnId(),
4827 expandoValueModelImpl.getOriginalClassPK()
4828 };
4829
4830 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C_C, args);
4831 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C, args);
4832 }
4833 }
4834
4835
4841 public ExpandoValue create(long valueId) {
4842 ExpandoValue expandoValue = new ExpandoValueImpl();
4843
4844 expandoValue.setNew(true);
4845 expandoValue.setPrimaryKey(valueId);
4846
4847 return expandoValue;
4848 }
4849
4850
4858 public ExpandoValue remove(long valueId)
4859 throws NoSuchValueException, SystemException {
4860 return remove((Serializable)valueId);
4861 }
4862
4863
4871 @Override
4872 public ExpandoValue remove(Serializable primaryKey)
4873 throws NoSuchValueException, SystemException {
4874 Session session = null;
4875
4876 try {
4877 session = openSession();
4878
4879 ExpandoValue expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
4880 primaryKey);
4881
4882 if (expandoValue == null) {
4883 if (_log.isWarnEnabled()) {
4884 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4885 }
4886
4887 throw new NoSuchValueException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4888 primaryKey);
4889 }
4890
4891 return remove(expandoValue);
4892 }
4893 catch (NoSuchValueException nsee) {
4894 throw nsee;
4895 }
4896 catch (Exception e) {
4897 throw processException(e);
4898 }
4899 finally {
4900 closeSession(session);
4901 }
4902 }
4903
4904 @Override
4905 protected ExpandoValue removeImpl(ExpandoValue expandoValue)
4906 throws SystemException {
4907 expandoValue = toUnwrappedModel(expandoValue);
4908
4909 Session session = null;
4910
4911 try {
4912 session = openSession();
4913
4914 if (!session.contains(expandoValue)) {
4915 expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
4916 expandoValue.getPrimaryKeyObj());
4917 }
4918
4919 if (expandoValue != null) {
4920 session.delete(expandoValue);
4921 }
4922 }
4923 catch (Exception e) {
4924 throw processException(e);
4925 }
4926 finally {
4927 closeSession(session);
4928 }
4929
4930 if (expandoValue != null) {
4931 clearCache(expandoValue);
4932 }
4933
4934 return expandoValue;
4935 }
4936
4937 @Override
4938 public ExpandoValue updateImpl(
4939 com.liferay.portlet.expando.model.ExpandoValue expandoValue)
4940 throws SystemException {
4941 expandoValue = toUnwrappedModel(expandoValue);
4942
4943 boolean isNew = expandoValue.isNew();
4944
4945 ExpandoValueModelImpl expandoValueModelImpl = (ExpandoValueModelImpl)expandoValue;
4946
4947 Session session = null;
4948
4949 try {
4950 session = openSession();
4951
4952 if (expandoValue.isNew()) {
4953 session.save(expandoValue);
4954
4955 expandoValue.setNew(false);
4956 }
4957 else {
4958 session.merge(expandoValue);
4959 }
4960 }
4961 catch (Exception e) {
4962 throw processException(e);
4963 }
4964 finally {
4965 closeSession(session);
4966 }
4967
4968 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4969
4970 if (isNew || !ExpandoValueModelImpl.COLUMN_BITMASK_ENABLED) {
4971 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4972 }
4973
4974 else {
4975 if ((expandoValueModelImpl.getColumnBitmask() &
4976 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
4977 Object[] args = new Object[] {
4978 expandoValueModelImpl.getOriginalTableId()
4979 };
4980
4981 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
4982 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
4983 args);
4984
4985 args = new Object[] { expandoValueModelImpl.getTableId() };
4986
4987 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
4988 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
4989 args);
4990 }
4991
4992 if ((expandoValueModelImpl.getColumnBitmask() &
4993 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID.getColumnBitmask()) != 0) {
4994 Object[] args = new Object[] {
4995 expandoValueModelImpl.getOriginalColumnId()
4996 };
4997
4998 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COLUMNID, args);
4999 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID,
5000 args);
5001
5002 args = new Object[] { expandoValueModelImpl.getColumnId() };
5003
5004 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COLUMNID, args);
5005 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID,
5006 args);
5007 }
5008
5009 if ((expandoValueModelImpl.getColumnBitmask() &
5010 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID.getColumnBitmask()) != 0) {
5011 Object[] args = new Object[] {
5012 expandoValueModelImpl.getOriginalRowId()
5013 };
5014
5015 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROWID, args);
5016 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID,
5017 args);
5018
5019 args = new Object[] { expandoValueModelImpl.getRowId() };
5020
5021 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROWID, args);
5022 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID,
5023 args);
5024 }
5025
5026 if ((expandoValueModelImpl.getColumnBitmask() &
5027 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C.getColumnBitmask()) != 0) {
5028 Object[] args = new Object[] {
5029 expandoValueModelImpl.getOriginalTableId(),
5030 expandoValueModelImpl.getOriginalColumnId()
5031 };
5032
5033 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
5034 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C,
5035 args);
5036
5037 args = new Object[] {
5038 expandoValueModelImpl.getTableId(),
5039 expandoValueModelImpl.getColumnId()
5040 };
5041
5042 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
5043 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C,
5044 args);
5045 }
5046
5047 if ((expandoValueModelImpl.getColumnBitmask() &
5048 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK.getColumnBitmask()) != 0) {
5049 Object[] args = new Object[] {
5050 expandoValueModelImpl.getOriginalTableId(),
5051 expandoValueModelImpl.getOriginalClassPK()
5052 };
5053
5054 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_CPK, args);
5055 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK,
5056 args);
5057
5058 args = new Object[] {
5059 expandoValueModelImpl.getTableId(),
5060 expandoValueModelImpl.getClassPK()
5061 };
5062
5063 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_CPK, args);
5064 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK,
5065 args);
5066 }
5067
5068 if ((expandoValueModelImpl.getColumnBitmask() &
5069 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R.getColumnBitmask()) != 0) {
5070 Object[] args = new Object[] {
5071 expandoValueModelImpl.getOriginalTableId(),
5072 expandoValueModelImpl.getOriginalRowId()
5073 };
5074
5075 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_R, args);
5076 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R,
5077 args);
5078
5079 args = new Object[] {
5080 expandoValueModelImpl.getTableId(),
5081 expandoValueModelImpl.getRowId()
5082 };
5083
5084 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_R, args);
5085 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R,
5086 args);
5087 }
5088
5089 if ((expandoValueModelImpl.getColumnBitmask() &
5090 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
5091 Object[] args = new Object[] {
5092 expandoValueModelImpl.getOriginalClassNameId(),
5093 expandoValueModelImpl.getOriginalClassPK()
5094 };
5095
5096 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
5097 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
5098 args);
5099
5100 args = new Object[] {
5101 expandoValueModelImpl.getClassNameId(),
5102 expandoValueModelImpl.getClassPK()
5103 };
5104
5105 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
5106 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
5107 args);
5108 }
5109
5110 if ((expandoValueModelImpl.getColumnBitmask() &
5111 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D.getColumnBitmask()) != 0) {
5112 Object[] args = new Object[] {
5113 expandoValueModelImpl.getOriginalTableId(),
5114 expandoValueModelImpl.getOriginalColumnId(),
5115 expandoValueModelImpl.getOriginalData()
5116 };
5117
5118 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C_D, args);
5119 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D,
5120 args);
5121
5122 args = new Object[] {
5123 expandoValueModelImpl.getTableId(),
5124 expandoValueModelImpl.getColumnId(),
5125 expandoValueModelImpl.getData()
5126 };
5127
5128 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C_D, args);
5129 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D,
5130 args);
5131 }
5132 }
5133
5134 EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
5135 ExpandoValueImpl.class, expandoValue.getPrimaryKey(), expandoValue);
5136
5137 clearUniqueFindersCache(expandoValue);
5138 cacheUniqueFindersCache(expandoValue);
5139
5140 return expandoValue;
5141 }
5142
5143 protected ExpandoValue toUnwrappedModel(ExpandoValue expandoValue) {
5144 if (expandoValue instanceof ExpandoValueImpl) {
5145 return expandoValue;
5146 }
5147
5148 ExpandoValueImpl expandoValueImpl = new ExpandoValueImpl();
5149
5150 expandoValueImpl.setNew(expandoValue.isNew());
5151 expandoValueImpl.setPrimaryKey(expandoValue.getPrimaryKey());
5152
5153 expandoValueImpl.setValueId(expandoValue.getValueId());
5154 expandoValueImpl.setCompanyId(expandoValue.getCompanyId());
5155 expandoValueImpl.setTableId(expandoValue.getTableId());
5156 expandoValueImpl.setColumnId(expandoValue.getColumnId());
5157 expandoValueImpl.setRowId(expandoValue.getRowId());
5158 expandoValueImpl.setClassNameId(expandoValue.getClassNameId());
5159 expandoValueImpl.setClassPK(expandoValue.getClassPK());
5160 expandoValueImpl.setData(expandoValue.getData());
5161
5162 return expandoValueImpl;
5163 }
5164
5165
5173 @Override
5174 public ExpandoValue findByPrimaryKey(Serializable primaryKey)
5175 throws NoSuchValueException, SystemException {
5176 ExpandoValue expandoValue = fetchByPrimaryKey(primaryKey);
5177
5178 if (expandoValue == null) {
5179 if (_log.isWarnEnabled()) {
5180 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5181 }
5182
5183 throw new NoSuchValueException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5184 primaryKey);
5185 }
5186
5187 return expandoValue;
5188 }
5189
5190
5198 public ExpandoValue findByPrimaryKey(long valueId)
5199 throws NoSuchValueException, SystemException {
5200 return findByPrimaryKey((Serializable)valueId);
5201 }
5202
5203
5210 @Override
5211 public ExpandoValue fetchByPrimaryKey(Serializable primaryKey)
5212 throws SystemException {
5213 ExpandoValue expandoValue = (ExpandoValue)EntityCacheUtil.getResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
5214 ExpandoValueImpl.class, primaryKey);
5215
5216 if (expandoValue == _nullExpandoValue) {
5217 return null;
5218 }
5219
5220 if (expandoValue == null) {
5221 Session session = null;
5222
5223 try {
5224 session = openSession();
5225
5226 expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
5227 primaryKey);
5228
5229 if (expandoValue != null) {
5230 cacheResult(expandoValue);
5231 }
5232 else {
5233 EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
5234 ExpandoValueImpl.class, primaryKey, _nullExpandoValue);
5235 }
5236 }
5237 catch (Exception e) {
5238 EntityCacheUtil.removeResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
5239 ExpandoValueImpl.class, primaryKey);
5240
5241 throw processException(e);
5242 }
5243 finally {
5244 closeSession(session);
5245 }
5246 }
5247
5248 return expandoValue;
5249 }
5250
5251
5258 public ExpandoValue fetchByPrimaryKey(long valueId)
5259 throws SystemException {
5260 return fetchByPrimaryKey((Serializable)valueId);
5261 }
5262
5263
5269 public List<ExpandoValue> findAll() throws SystemException {
5270 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5271 }
5272
5273
5285 public List<ExpandoValue> findAll(int start, int end)
5286 throws SystemException {
5287 return findAll(start, end, null);
5288 }
5289
5290
5303 public List<ExpandoValue> findAll(int start, int end,
5304 OrderByComparator orderByComparator) throws SystemException {
5305 boolean pagination = true;
5306 FinderPath finderPath = null;
5307 Object[] finderArgs = null;
5308
5309 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5310 (orderByComparator == null)) {
5311 pagination = false;
5312 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5313 finderArgs = FINDER_ARGS_EMPTY;
5314 }
5315 else {
5316 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5317 finderArgs = new Object[] { start, end, orderByComparator };
5318 }
5319
5320 List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
5321 finderArgs, this);
5322
5323 if (list == null) {
5324 StringBundler query = null;
5325 String sql = null;
5326
5327 if (orderByComparator != null) {
5328 query = new StringBundler(2 +
5329 (orderByComparator.getOrderByFields().length * 3));
5330
5331 query.append(_SQL_SELECT_EXPANDOVALUE);
5332
5333 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5334 orderByComparator);
5335
5336 sql = query.toString();
5337 }
5338 else {
5339 sql = _SQL_SELECT_EXPANDOVALUE;
5340
5341 if (pagination) {
5342 sql = sql.concat(ExpandoValueModelImpl.ORDER_BY_JPQL);
5343 }
5344 }
5345
5346 Session session = null;
5347
5348 try {
5349 session = openSession();
5350
5351 Query q = session.createQuery(sql);
5352
5353 if (!pagination) {
5354 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
5355 start, end, false);
5356
5357 Collections.sort(list);
5358
5359 list = new UnmodifiableList<ExpandoValue>(list);
5360 }
5361 else {
5362 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
5363 start, end);
5364 }
5365
5366 cacheResult(list);
5367
5368 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5369 }
5370 catch (Exception e) {
5371 FinderCacheUtil.removeResult(finderPath, finderArgs);
5372
5373 throw processException(e);
5374 }
5375 finally {
5376 closeSession(session);
5377 }
5378 }
5379
5380 return list;
5381 }
5382
5383
5388 public void removeAll() throws SystemException {
5389 for (ExpandoValue expandoValue : findAll()) {
5390 remove(expandoValue);
5391 }
5392 }
5393
5394
5400 public int countAll() throws SystemException {
5401 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5402 FINDER_ARGS_EMPTY, this);
5403
5404 if (count == null) {
5405 Session session = null;
5406
5407 try {
5408 session = openSession();
5409
5410 Query q = session.createQuery(_SQL_COUNT_EXPANDOVALUE);
5411
5412 count = (Long)q.uniqueResult();
5413
5414 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5415 FINDER_ARGS_EMPTY, count);
5416 }
5417 catch (Exception e) {
5418 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5419 FINDER_ARGS_EMPTY);
5420
5421 throw processException(e);
5422 }
5423 finally {
5424 closeSession(session);
5425 }
5426 }
5427
5428 return count.intValue();
5429 }
5430
5431 @Override
5432 protected Set<String> getBadColumnNames() {
5433 return _badColumnNames;
5434 }
5435
5436
5439 public void afterPropertiesSet() {
5440 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5441 com.liferay.portal.util.PropsUtil.get(
5442 "value.object.listener.com.liferay.portlet.expando.model.ExpandoValue")));
5443
5444 if (listenerClassNames.length > 0) {
5445 try {
5446 List<ModelListener<ExpandoValue>> listenersList = new ArrayList<ModelListener<ExpandoValue>>();
5447
5448 for (String listenerClassName : listenerClassNames) {
5449 listenersList.add((ModelListener<ExpandoValue>)InstanceFactory.newInstance(
5450 getClassLoader(), listenerClassName));
5451 }
5452
5453 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5454 }
5455 catch (Exception e) {
5456 _log.error(e);
5457 }
5458 }
5459 }
5460
5461 public void destroy() {
5462 EntityCacheUtil.removeCache(ExpandoValueImpl.class.getName());
5463 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5464 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5465 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5466 }
5467
5468 private static final String _SQL_SELECT_EXPANDOVALUE = "SELECT expandoValue FROM ExpandoValue expandoValue";
5469 private static final String _SQL_SELECT_EXPANDOVALUE_WHERE = "SELECT expandoValue FROM ExpandoValue expandoValue WHERE ";
5470 private static final String _SQL_COUNT_EXPANDOVALUE = "SELECT COUNT(expandoValue) FROM ExpandoValue expandoValue";
5471 private static final String _SQL_COUNT_EXPANDOVALUE_WHERE = "SELECT COUNT(expandoValue) FROM ExpandoValue expandoValue WHERE ";
5472 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoValue.";
5473 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoValue exists with the primary key ";
5474 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoValue exists with the key {";
5475 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5476 private static Log _log = LogFactoryUtil.getLog(ExpandoValuePersistenceImpl.class);
5477 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
5478 "rowId", "data"
5479 });
5480 private static ExpandoValue _nullExpandoValue = new ExpandoValueImpl() {
5481 @Override
5482 public Object clone() {
5483 return this;
5484 }
5485
5486 @Override
5487 public CacheModel<ExpandoValue> toCacheModel() {
5488 return _nullExpandoValueCacheModel;
5489 }
5490 };
5491
5492 private static CacheModel<ExpandoValue> _nullExpandoValueCacheModel = new CacheModel<ExpandoValue>() {
5493 public ExpandoValue toEntityModel() {
5494 return _nullExpandoValue;
5495 }
5496 };
5497 }