001
014
015 package com.liferay.portlet.dynamicdatamapping.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.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.dynamicdatamapping.NoSuchContentException;
043 import com.liferay.portlet.dynamicdatamapping.model.DDMContent;
044 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentImpl;
045 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052 import java.util.Set;
053
054
066 public class DDMContentPersistenceImpl extends BasePersistenceImpl<DDMContent>
067 implements DDMContentPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = DDMContentImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
079 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
082 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
085 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
088 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
090 new String[] {
091 String.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
097 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
099 new String[] { String.class.getName() },
100 DDMContentModelImpl.UUID_COLUMN_BITMASK);
101 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
102 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
104 new String[] { String.class.getName() });
105
106
113 public List<DDMContent> findByUuid(String uuid) throws SystemException {
114 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115 }
116
117
130 public List<DDMContent> findByUuid(String uuid, int start, int end)
131 throws SystemException {
132 return findByUuid(uuid, start, end, null);
133 }
134
135
149 public List<DDMContent> findByUuid(String uuid, int start, int end,
150 OrderByComparator orderByComparator) throws SystemException {
151 boolean pagination = true;
152 FinderPath finderPath = null;
153 Object[] finderArgs = null;
154
155 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156 (orderByComparator == null)) {
157 pagination = false;
158 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
159 finderArgs = new Object[] { uuid };
160 }
161 else {
162 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
163 finderArgs = new Object[] { uuid, start, end, orderByComparator };
164 }
165
166 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
167 finderArgs, this);
168
169 if ((list != null) && !list.isEmpty()) {
170 for (DDMContent ddmContent : list) {
171 if (!Validator.equals(uuid, ddmContent.getUuid())) {
172 list = null;
173
174 break;
175 }
176 }
177 }
178
179 if (list == null) {
180 StringBundler query = null;
181
182 if (orderByComparator != null) {
183 query = new StringBundler(3 +
184 (orderByComparator.getOrderByFields().length * 3));
185 }
186 else {
187 query = new StringBundler(3);
188 }
189
190 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
191
192 boolean bindUuid = false;
193
194 if (uuid == null) {
195 query.append(_FINDER_COLUMN_UUID_UUID_1);
196 }
197 else if (uuid.equals(StringPool.BLANK)) {
198 query.append(_FINDER_COLUMN_UUID_UUID_3);
199 }
200 else {
201 bindUuid = true;
202
203 query.append(_FINDER_COLUMN_UUID_UUID_2);
204 }
205
206 if (orderByComparator != null) {
207 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
208 orderByComparator);
209 }
210 else
211 if (pagination) {
212 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
213 }
214
215 String sql = query.toString();
216
217 Session session = null;
218
219 try {
220 session = openSession();
221
222 Query q = session.createQuery(sql);
223
224 QueryPos qPos = QueryPos.getInstance(q);
225
226 if (bindUuid) {
227 qPos.add(uuid);
228 }
229
230 if (!pagination) {
231 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
232 start, end, false);
233
234 Collections.sort(list);
235
236 list = new UnmodifiableList<DDMContent>(list);
237 }
238 else {
239 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
240 start, end);
241 }
242
243 cacheResult(list);
244
245 FinderCacheUtil.putResult(finderPath, finderArgs, list);
246 }
247 catch (Exception e) {
248 FinderCacheUtil.removeResult(finderPath, finderArgs);
249
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254 }
255 }
256
257 return list;
258 }
259
260
269 public DDMContent findByUuid_First(String uuid,
270 OrderByComparator orderByComparator)
271 throws NoSuchContentException, SystemException {
272 DDMContent ddmContent = fetchByUuid_First(uuid, orderByComparator);
273
274 if (ddmContent != null) {
275 return ddmContent;
276 }
277
278 StringBundler msg = new StringBundler(4);
279
280 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
281
282 msg.append("uuid=");
283 msg.append(uuid);
284
285 msg.append(StringPool.CLOSE_CURLY_BRACE);
286
287 throw new NoSuchContentException(msg.toString());
288 }
289
290
298 public DDMContent fetchByUuid_First(String uuid,
299 OrderByComparator orderByComparator) throws SystemException {
300 List<DDMContent> list = findByUuid(uuid, 0, 1, orderByComparator);
301
302 if (!list.isEmpty()) {
303 return list.get(0);
304 }
305
306 return null;
307 }
308
309
318 public DDMContent findByUuid_Last(String uuid,
319 OrderByComparator orderByComparator)
320 throws NoSuchContentException, SystemException {
321 DDMContent ddmContent = fetchByUuid_Last(uuid, orderByComparator);
322
323 if (ddmContent != null) {
324 return ddmContent;
325 }
326
327 StringBundler msg = new StringBundler(4);
328
329 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
330
331 msg.append("uuid=");
332 msg.append(uuid);
333
334 msg.append(StringPool.CLOSE_CURLY_BRACE);
335
336 throw new NoSuchContentException(msg.toString());
337 }
338
339
347 public DDMContent fetchByUuid_Last(String uuid,
348 OrderByComparator orderByComparator) throws SystemException {
349 int count = countByUuid(uuid);
350
351 List<DDMContent> list = findByUuid(uuid, count - 1, count,
352 orderByComparator);
353
354 if (!list.isEmpty()) {
355 return list.get(0);
356 }
357
358 return null;
359 }
360
361
371 public DDMContent[] findByUuid_PrevAndNext(long contentId, String uuid,
372 OrderByComparator orderByComparator)
373 throws NoSuchContentException, SystemException {
374 DDMContent ddmContent = findByPrimaryKey(contentId);
375
376 Session session = null;
377
378 try {
379 session = openSession();
380
381 DDMContent[] array = new DDMContentImpl[3];
382
383 array[0] = getByUuid_PrevAndNext(session, ddmContent, uuid,
384 orderByComparator, true);
385
386 array[1] = ddmContent;
387
388 array[2] = getByUuid_PrevAndNext(session, ddmContent, uuid,
389 orderByComparator, false);
390
391 return array;
392 }
393 catch (Exception e) {
394 throw processException(e);
395 }
396 finally {
397 closeSession(session);
398 }
399 }
400
401 protected DDMContent getByUuid_PrevAndNext(Session session,
402 DDMContent ddmContent, String uuid,
403 OrderByComparator orderByComparator, boolean previous) {
404 StringBundler query = null;
405
406 if (orderByComparator != null) {
407 query = new StringBundler(6 +
408 (orderByComparator.getOrderByFields().length * 6));
409 }
410 else {
411 query = new StringBundler(3);
412 }
413
414 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
415
416 boolean bindUuid = false;
417
418 if (uuid == null) {
419 query.append(_FINDER_COLUMN_UUID_UUID_1);
420 }
421 else if (uuid.equals(StringPool.BLANK)) {
422 query.append(_FINDER_COLUMN_UUID_UUID_3);
423 }
424 else {
425 bindUuid = true;
426
427 query.append(_FINDER_COLUMN_UUID_UUID_2);
428 }
429
430 if (orderByComparator != null) {
431 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
432
433 if (orderByConditionFields.length > 0) {
434 query.append(WHERE_AND);
435 }
436
437 for (int i = 0; i < orderByConditionFields.length; i++) {
438 query.append(_ORDER_BY_ENTITY_ALIAS);
439 query.append(orderByConditionFields[i]);
440
441 if ((i + 1) < orderByConditionFields.length) {
442 if (orderByComparator.isAscending() ^ previous) {
443 query.append(WHERE_GREATER_THAN_HAS_NEXT);
444 }
445 else {
446 query.append(WHERE_LESSER_THAN_HAS_NEXT);
447 }
448 }
449 else {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(WHERE_GREATER_THAN);
452 }
453 else {
454 query.append(WHERE_LESSER_THAN);
455 }
456 }
457 }
458
459 query.append(ORDER_BY_CLAUSE);
460
461 String[] orderByFields = orderByComparator.getOrderByFields();
462
463 for (int i = 0; i < orderByFields.length; i++) {
464 query.append(_ORDER_BY_ENTITY_ALIAS);
465 query.append(orderByFields[i]);
466
467 if ((i + 1) < orderByFields.length) {
468 if (orderByComparator.isAscending() ^ previous) {
469 query.append(ORDER_BY_ASC_HAS_NEXT);
470 }
471 else {
472 query.append(ORDER_BY_DESC_HAS_NEXT);
473 }
474 }
475 else {
476 if (orderByComparator.isAscending() ^ previous) {
477 query.append(ORDER_BY_ASC);
478 }
479 else {
480 query.append(ORDER_BY_DESC);
481 }
482 }
483 }
484 }
485 else {
486 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
487 }
488
489 String sql = query.toString();
490
491 Query q = session.createQuery(sql);
492
493 q.setFirstResult(0);
494 q.setMaxResults(2);
495
496 QueryPos qPos = QueryPos.getInstance(q);
497
498 if (bindUuid) {
499 qPos.add(uuid);
500 }
501
502 if (orderByComparator != null) {
503 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
504
505 for (Object value : values) {
506 qPos.add(value);
507 }
508 }
509
510 List<DDMContent> list = q.list();
511
512 if (list.size() == 2) {
513 return list.get(1);
514 }
515 else {
516 return null;
517 }
518 }
519
520
526 public void removeByUuid(String uuid) throws SystemException {
527 for (DDMContent ddmContent : findByUuid(uuid, QueryUtil.ALL_POS,
528 QueryUtil.ALL_POS, null)) {
529 remove(ddmContent);
530 }
531 }
532
533
540 public int countByUuid(String uuid) throws SystemException {
541 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
542
543 Object[] finderArgs = new Object[] { uuid };
544
545 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
546 this);
547
548 if (count == null) {
549 StringBundler query = new StringBundler(2);
550
551 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
552
553 boolean bindUuid = false;
554
555 if (uuid == null) {
556 query.append(_FINDER_COLUMN_UUID_UUID_1);
557 }
558 else if (uuid.equals(StringPool.BLANK)) {
559 query.append(_FINDER_COLUMN_UUID_UUID_3);
560 }
561 else {
562 bindUuid = true;
563
564 query.append(_FINDER_COLUMN_UUID_UUID_2);
565 }
566
567 String sql = query.toString();
568
569 Session session = null;
570
571 try {
572 session = openSession();
573
574 Query q = session.createQuery(sql);
575
576 QueryPos qPos = QueryPos.getInstance(q);
577
578 if (bindUuid) {
579 qPos.add(uuid);
580 }
581
582 count = (Long)q.uniqueResult();
583
584 FinderCacheUtil.putResult(finderPath, finderArgs, count);
585 }
586 catch (Exception e) {
587 FinderCacheUtil.removeResult(finderPath, finderArgs);
588
589 throw processException(e);
590 }
591 finally {
592 closeSession(session);
593 }
594 }
595
596 return count.intValue();
597 }
598
599 private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmContent.uuid IS NULL";
600 private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmContent.uuid = ?";
601 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = '')";
602 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
603 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
604 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
605 new String[] { String.class.getName(), Long.class.getName() },
606 DDMContentModelImpl.UUID_COLUMN_BITMASK |
607 DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
608 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
609 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
610 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
611 new String[] { String.class.getName(), Long.class.getName() });
612
613
622 public DDMContent findByUUID_G(String uuid, long groupId)
623 throws NoSuchContentException, SystemException {
624 DDMContent ddmContent = fetchByUUID_G(uuid, groupId);
625
626 if (ddmContent == null) {
627 StringBundler msg = new StringBundler(6);
628
629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630
631 msg.append("uuid=");
632 msg.append(uuid);
633
634 msg.append(", groupId=");
635 msg.append(groupId);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 if (_log.isWarnEnabled()) {
640 _log.warn(msg.toString());
641 }
642
643 throw new NoSuchContentException(msg.toString());
644 }
645
646 return ddmContent;
647 }
648
649
657 public DDMContent fetchByUUID_G(String uuid, long groupId)
658 throws SystemException {
659 return fetchByUUID_G(uuid, groupId, true);
660 }
661
662
671 public DDMContent fetchByUUID_G(String uuid, long groupId,
672 boolean retrieveFromCache) throws SystemException {
673 Object[] finderArgs = new Object[] { uuid, groupId };
674
675 Object result = null;
676
677 if (retrieveFromCache) {
678 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
679 finderArgs, this);
680 }
681
682 if (result instanceof DDMContent) {
683 DDMContent ddmContent = (DDMContent)result;
684
685 if (!Validator.equals(uuid, ddmContent.getUuid()) ||
686 (groupId != ddmContent.getGroupId())) {
687 result = null;
688 }
689 }
690
691 if (result == null) {
692 StringBundler query = new StringBundler(4);
693
694 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
695
696 boolean bindUuid = false;
697
698 if (uuid == null) {
699 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
700 }
701 else if (uuid.equals(StringPool.BLANK)) {
702 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
703 }
704 else {
705 bindUuid = true;
706
707 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
708 }
709
710 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
711
712 String sql = query.toString();
713
714 Session session = null;
715
716 try {
717 session = openSession();
718
719 Query q = session.createQuery(sql);
720
721 QueryPos qPos = QueryPos.getInstance(q);
722
723 if (bindUuid) {
724 qPos.add(uuid);
725 }
726
727 qPos.add(groupId);
728
729 List<DDMContent> list = q.list();
730
731 if (list.isEmpty()) {
732 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
733 finderArgs, list);
734 }
735 else {
736 DDMContent ddmContent = list.get(0);
737
738 result = ddmContent;
739
740 cacheResult(ddmContent);
741
742 if ((ddmContent.getUuid() == null) ||
743 !ddmContent.getUuid().equals(uuid) ||
744 (ddmContent.getGroupId() != groupId)) {
745 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
746 finderArgs, ddmContent);
747 }
748 }
749 }
750 catch (Exception e) {
751 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
752 finderArgs);
753
754 throw processException(e);
755 }
756 finally {
757 closeSession(session);
758 }
759 }
760
761 if (result instanceof List<?>) {
762 return null;
763 }
764 else {
765 return (DDMContent)result;
766 }
767 }
768
769
777 public DDMContent removeByUUID_G(String uuid, long groupId)
778 throws NoSuchContentException, SystemException {
779 DDMContent ddmContent = findByUUID_G(uuid, groupId);
780
781 return remove(ddmContent);
782 }
783
784
792 public int countByUUID_G(String uuid, long groupId)
793 throws SystemException {
794 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
795
796 Object[] finderArgs = new Object[] { uuid, groupId };
797
798 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
799 this);
800
801 if (count == null) {
802 StringBundler query = new StringBundler(3);
803
804 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
805
806 boolean bindUuid = false;
807
808 if (uuid == null) {
809 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
810 }
811 else if (uuid.equals(StringPool.BLANK)) {
812 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
813 }
814 else {
815 bindUuid = true;
816
817 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
818 }
819
820 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
821
822 String sql = query.toString();
823
824 Session session = null;
825
826 try {
827 session = openSession();
828
829 Query q = session.createQuery(sql);
830
831 QueryPos qPos = QueryPos.getInstance(q);
832
833 if (bindUuid) {
834 qPos.add(uuid);
835 }
836
837 qPos.add(groupId);
838
839 count = (Long)q.uniqueResult();
840
841 FinderCacheUtil.putResult(finderPath, finderArgs, count);
842 }
843 catch (Exception e) {
844 FinderCacheUtil.removeResult(finderPath, finderArgs);
845
846 throw processException(e);
847 }
848 finally {
849 closeSession(session);
850 }
851 }
852
853 return count.intValue();
854 }
855
856 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmContent.uuid IS NULL AND ";
857 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmContent.uuid = ? AND ";
858 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = '') AND ";
859 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmContent.groupId = ?";
860 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
861 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
862 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
863 new String[] {
864 String.class.getName(), Long.class.getName(),
865
866 Integer.class.getName(), Integer.class.getName(),
867 OrderByComparator.class.getName()
868 });
869 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
870 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
871 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
872 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
873 new String[] { String.class.getName(), Long.class.getName() },
874 DDMContentModelImpl.UUID_COLUMN_BITMASK |
875 DDMContentModelImpl.COMPANYID_COLUMN_BITMASK);
876 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
877 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
878 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
879 new String[] { String.class.getName(), Long.class.getName() });
880
881
889 public List<DDMContent> findByUuid_C(String uuid, long companyId)
890 throws SystemException {
891 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
892 QueryUtil.ALL_POS, null);
893 }
894
895
909 public List<DDMContent> findByUuid_C(String uuid, long companyId,
910 int start, int end) throws SystemException {
911 return findByUuid_C(uuid, companyId, start, end, null);
912 }
913
914
929 public List<DDMContent> findByUuid_C(String uuid, long companyId,
930 int start, int end, OrderByComparator orderByComparator)
931 throws SystemException {
932 boolean pagination = true;
933 FinderPath finderPath = null;
934 Object[] finderArgs = null;
935
936 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
937 (orderByComparator == null)) {
938 pagination = false;
939 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
940 finderArgs = new Object[] { uuid, companyId };
941 }
942 else {
943 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
944 finderArgs = new Object[] {
945 uuid, companyId,
946
947 start, end, orderByComparator
948 };
949 }
950
951 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
952 finderArgs, this);
953
954 if ((list != null) && !list.isEmpty()) {
955 for (DDMContent ddmContent : list) {
956 if (!Validator.equals(uuid, ddmContent.getUuid()) ||
957 (companyId != ddmContent.getCompanyId())) {
958 list = null;
959
960 break;
961 }
962 }
963 }
964
965 if (list == null) {
966 StringBundler query = null;
967
968 if (orderByComparator != null) {
969 query = new StringBundler(4 +
970 (orderByComparator.getOrderByFields().length * 3));
971 }
972 else {
973 query = new StringBundler(4);
974 }
975
976 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
977
978 boolean bindUuid = false;
979
980 if (uuid == null) {
981 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
982 }
983 else if (uuid.equals(StringPool.BLANK)) {
984 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
985 }
986 else {
987 bindUuid = true;
988
989 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
990 }
991
992 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
993
994 if (orderByComparator != null) {
995 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
996 orderByComparator);
997 }
998 else
999 if (pagination) {
1000 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
1001 }
1002
1003 String sql = query.toString();
1004
1005 Session session = null;
1006
1007 try {
1008 session = openSession();
1009
1010 Query q = session.createQuery(sql);
1011
1012 QueryPos qPos = QueryPos.getInstance(q);
1013
1014 if (bindUuid) {
1015 qPos.add(uuid);
1016 }
1017
1018 qPos.add(companyId);
1019
1020 if (!pagination) {
1021 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1022 start, end, false);
1023
1024 Collections.sort(list);
1025
1026 list = new UnmodifiableList<DDMContent>(list);
1027 }
1028 else {
1029 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1030 start, end);
1031 }
1032
1033 cacheResult(list);
1034
1035 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1036 }
1037 catch (Exception e) {
1038 FinderCacheUtil.removeResult(finderPath, finderArgs);
1039
1040 throw processException(e);
1041 }
1042 finally {
1043 closeSession(session);
1044 }
1045 }
1046
1047 return list;
1048 }
1049
1050
1060 public DDMContent findByUuid_C_First(String uuid, long companyId,
1061 OrderByComparator orderByComparator)
1062 throws NoSuchContentException, SystemException {
1063 DDMContent ddmContent = fetchByUuid_C_First(uuid, companyId,
1064 orderByComparator);
1065
1066 if (ddmContent != null) {
1067 return ddmContent;
1068 }
1069
1070 StringBundler msg = new StringBundler(6);
1071
1072 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1073
1074 msg.append("uuid=");
1075 msg.append(uuid);
1076
1077 msg.append(", companyId=");
1078 msg.append(companyId);
1079
1080 msg.append(StringPool.CLOSE_CURLY_BRACE);
1081
1082 throw new NoSuchContentException(msg.toString());
1083 }
1084
1085
1094 public DDMContent fetchByUuid_C_First(String uuid, long companyId,
1095 OrderByComparator orderByComparator) throws SystemException {
1096 List<DDMContent> list = findByUuid_C(uuid, companyId, 0, 1,
1097 orderByComparator);
1098
1099 if (!list.isEmpty()) {
1100 return list.get(0);
1101 }
1102
1103 return null;
1104 }
1105
1106
1116 public DDMContent findByUuid_C_Last(String uuid, long companyId,
1117 OrderByComparator orderByComparator)
1118 throws NoSuchContentException, SystemException {
1119 DDMContent ddmContent = fetchByUuid_C_Last(uuid, companyId,
1120 orderByComparator);
1121
1122 if (ddmContent != null) {
1123 return ddmContent;
1124 }
1125
1126 StringBundler msg = new StringBundler(6);
1127
1128 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1129
1130 msg.append("uuid=");
1131 msg.append(uuid);
1132
1133 msg.append(", companyId=");
1134 msg.append(companyId);
1135
1136 msg.append(StringPool.CLOSE_CURLY_BRACE);
1137
1138 throw new NoSuchContentException(msg.toString());
1139 }
1140
1141
1150 public DDMContent fetchByUuid_C_Last(String uuid, long companyId,
1151 OrderByComparator orderByComparator) throws SystemException {
1152 int count = countByUuid_C(uuid, companyId);
1153
1154 List<DDMContent> list = findByUuid_C(uuid, companyId, count - 1, count,
1155 orderByComparator);
1156
1157 if (!list.isEmpty()) {
1158 return list.get(0);
1159 }
1160
1161 return null;
1162 }
1163
1164
1175 public DDMContent[] findByUuid_C_PrevAndNext(long contentId, String uuid,
1176 long companyId, OrderByComparator orderByComparator)
1177 throws NoSuchContentException, SystemException {
1178 DDMContent ddmContent = findByPrimaryKey(contentId);
1179
1180 Session session = null;
1181
1182 try {
1183 session = openSession();
1184
1185 DDMContent[] array = new DDMContentImpl[3];
1186
1187 array[0] = getByUuid_C_PrevAndNext(session, ddmContent, uuid,
1188 companyId, orderByComparator, true);
1189
1190 array[1] = ddmContent;
1191
1192 array[2] = getByUuid_C_PrevAndNext(session, ddmContent, uuid,
1193 companyId, orderByComparator, false);
1194
1195 return array;
1196 }
1197 catch (Exception e) {
1198 throw processException(e);
1199 }
1200 finally {
1201 closeSession(session);
1202 }
1203 }
1204
1205 protected DDMContent getByUuid_C_PrevAndNext(Session session,
1206 DDMContent ddmContent, String uuid, long companyId,
1207 OrderByComparator orderByComparator, boolean previous) {
1208 StringBundler query = null;
1209
1210 if (orderByComparator != null) {
1211 query = new StringBundler(6 +
1212 (orderByComparator.getOrderByFields().length * 6));
1213 }
1214 else {
1215 query = new StringBundler(3);
1216 }
1217
1218 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1219
1220 boolean bindUuid = false;
1221
1222 if (uuid == null) {
1223 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1224 }
1225 else if (uuid.equals(StringPool.BLANK)) {
1226 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1227 }
1228 else {
1229 bindUuid = true;
1230
1231 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1232 }
1233
1234 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1235
1236 if (orderByComparator != null) {
1237 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1238
1239 if (orderByConditionFields.length > 0) {
1240 query.append(WHERE_AND);
1241 }
1242
1243 for (int i = 0; i < orderByConditionFields.length; i++) {
1244 query.append(_ORDER_BY_ENTITY_ALIAS);
1245 query.append(orderByConditionFields[i]);
1246
1247 if ((i + 1) < orderByConditionFields.length) {
1248 if (orderByComparator.isAscending() ^ previous) {
1249 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1250 }
1251 else {
1252 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1253 }
1254 }
1255 else {
1256 if (orderByComparator.isAscending() ^ previous) {
1257 query.append(WHERE_GREATER_THAN);
1258 }
1259 else {
1260 query.append(WHERE_LESSER_THAN);
1261 }
1262 }
1263 }
1264
1265 query.append(ORDER_BY_CLAUSE);
1266
1267 String[] orderByFields = orderByComparator.getOrderByFields();
1268
1269 for (int i = 0; i < orderByFields.length; i++) {
1270 query.append(_ORDER_BY_ENTITY_ALIAS);
1271 query.append(orderByFields[i]);
1272
1273 if ((i + 1) < orderByFields.length) {
1274 if (orderByComparator.isAscending() ^ previous) {
1275 query.append(ORDER_BY_ASC_HAS_NEXT);
1276 }
1277 else {
1278 query.append(ORDER_BY_DESC_HAS_NEXT);
1279 }
1280 }
1281 else {
1282 if (orderByComparator.isAscending() ^ previous) {
1283 query.append(ORDER_BY_ASC);
1284 }
1285 else {
1286 query.append(ORDER_BY_DESC);
1287 }
1288 }
1289 }
1290 }
1291 else {
1292 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
1293 }
1294
1295 String sql = query.toString();
1296
1297 Query q = session.createQuery(sql);
1298
1299 q.setFirstResult(0);
1300 q.setMaxResults(2);
1301
1302 QueryPos qPos = QueryPos.getInstance(q);
1303
1304 if (bindUuid) {
1305 qPos.add(uuid);
1306 }
1307
1308 qPos.add(companyId);
1309
1310 if (orderByComparator != null) {
1311 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1312
1313 for (Object value : values) {
1314 qPos.add(value);
1315 }
1316 }
1317
1318 List<DDMContent> list = q.list();
1319
1320 if (list.size() == 2) {
1321 return list.get(1);
1322 }
1323 else {
1324 return null;
1325 }
1326 }
1327
1328
1335 public void removeByUuid_C(String uuid, long companyId)
1336 throws SystemException {
1337 for (DDMContent ddmContent : findByUuid_C(uuid, companyId,
1338 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1339 remove(ddmContent);
1340 }
1341 }
1342
1343
1351 public int countByUuid_C(String uuid, long companyId)
1352 throws SystemException {
1353 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1354
1355 Object[] finderArgs = new Object[] { uuid, companyId };
1356
1357 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1358 this);
1359
1360 if (count == null) {
1361 StringBundler query = new StringBundler(3);
1362
1363 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
1364
1365 boolean bindUuid = false;
1366
1367 if (uuid == null) {
1368 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1369 }
1370 else if (uuid.equals(StringPool.BLANK)) {
1371 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1372 }
1373 else {
1374 bindUuid = true;
1375
1376 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1377 }
1378
1379 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1380
1381 String sql = query.toString();
1382
1383 Session session = null;
1384
1385 try {
1386 session = openSession();
1387
1388 Query q = session.createQuery(sql);
1389
1390 QueryPos qPos = QueryPos.getInstance(q);
1391
1392 if (bindUuid) {
1393 qPos.add(uuid);
1394 }
1395
1396 qPos.add(companyId);
1397
1398 count = (Long)q.uniqueResult();
1399
1400 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1401 }
1402 catch (Exception e) {
1403 FinderCacheUtil.removeResult(finderPath, finderArgs);
1404
1405 throw processException(e);
1406 }
1407 finally {
1408 closeSession(session);
1409 }
1410 }
1411
1412 return count.intValue();
1413 }
1414
1415 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmContent.uuid IS NULL AND ";
1416 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmContent.uuid = ? AND ";
1417 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = '') AND ";
1418 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmContent.companyId = ?";
1419 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1420 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
1421 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1422 new String[] {
1423 Long.class.getName(),
1424
1425 Integer.class.getName(), Integer.class.getName(),
1426 OrderByComparator.class.getName()
1427 });
1428 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1429 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1430 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
1431 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1432 new String[] { Long.class.getName() },
1433 DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
1434 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1435 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
1436 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1437 new String[] { Long.class.getName() });
1438
1439
1446 public List<DDMContent> findByGroupId(long groupId)
1447 throws SystemException {
1448 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1449 }
1450
1451
1464 public List<DDMContent> findByGroupId(long groupId, int start, int end)
1465 throws SystemException {
1466 return findByGroupId(groupId, start, end, null);
1467 }
1468
1469
1483 public List<DDMContent> findByGroupId(long groupId, int start, int end,
1484 OrderByComparator orderByComparator) throws SystemException {
1485 boolean pagination = true;
1486 FinderPath finderPath = null;
1487 Object[] finderArgs = null;
1488
1489 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1490 (orderByComparator == null)) {
1491 pagination = false;
1492 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1493 finderArgs = new Object[] { groupId };
1494 }
1495 else {
1496 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1497 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1498 }
1499
1500 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1501 finderArgs, this);
1502
1503 if ((list != null) && !list.isEmpty()) {
1504 for (DDMContent ddmContent : list) {
1505 if ((groupId != ddmContent.getGroupId())) {
1506 list = null;
1507
1508 break;
1509 }
1510 }
1511 }
1512
1513 if (list == null) {
1514 StringBundler query = null;
1515
1516 if (orderByComparator != null) {
1517 query = new StringBundler(3 +
1518 (orderByComparator.getOrderByFields().length * 3));
1519 }
1520 else {
1521 query = new StringBundler(3);
1522 }
1523
1524 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1525
1526 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1527
1528 if (orderByComparator != null) {
1529 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1530 orderByComparator);
1531 }
1532 else
1533 if (pagination) {
1534 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
1535 }
1536
1537 String sql = query.toString();
1538
1539 Session session = null;
1540
1541 try {
1542 session = openSession();
1543
1544 Query q = session.createQuery(sql);
1545
1546 QueryPos qPos = QueryPos.getInstance(q);
1547
1548 qPos.add(groupId);
1549
1550 if (!pagination) {
1551 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1552 start, end, false);
1553
1554 Collections.sort(list);
1555
1556 list = new UnmodifiableList<DDMContent>(list);
1557 }
1558 else {
1559 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1560 start, end);
1561 }
1562
1563 cacheResult(list);
1564
1565 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1566 }
1567 catch (Exception e) {
1568 FinderCacheUtil.removeResult(finderPath, finderArgs);
1569
1570 throw processException(e);
1571 }
1572 finally {
1573 closeSession(session);
1574 }
1575 }
1576
1577 return list;
1578 }
1579
1580
1589 public DDMContent findByGroupId_First(long groupId,
1590 OrderByComparator orderByComparator)
1591 throws NoSuchContentException, SystemException {
1592 DDMContent ddmContent = fetchByGroupId_First(groupId, orderByComparator);
1593
1594 if (ddmContent != null) {
1595 return ddmContent;
1596 }
1597
1598 StringBundler msg = new StringBundler(4);
1599
1600 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1601
1602 msg.append("groupId=");
1603 msg.append(groupId);
1604
1605 msg.append(StringPool.CLOSE_CURLY_BRACE);
1606
1607 throw new NoSuchContentException(msg.toString());
1608 }
1609
1610
1618 public DDMContent fetchByGroupId_First(long groupId,
1619 OrderByComparator orderByComparator) throws SystemException {
1620 List<DDMContent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1621
1622 if (!list.isEmpty()) {
1623 return list.get(0);
1624 }
1625
1626 return null;
1627 }
1628
1629
1638 public DDMContent findByGroupId_Last(long groupId,
1639 OrderByComparator orderByComparator)
1640 throws NoSuchContentException, SystemException {
1641 DDMContent ddmContent = fetchByGroupId_Last(groupId, orderByComparator);
1642
1643 if (ddmContent != null) {
1644 return ddmContent;
1645 }
1646
1647 StringBundler msg = new StringBundler(4);
1648
1649 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1650
1651 msg.append("groupId=");
1652 msg.append(groupId);
1653
1654 msg.append(StringPool.CLOSE_CURLY_BRACE);
1655
1656 throw new NoSuchContentException(msg.toString());
1657 }
1658
1659
1667 public DDMContent fetchByGroupId_Last(long groupId,
1668 OrderByComparator orderByComparator) throws SystemException {
1669 int count = countByGroupId(groupId);
1670
1671 List<DDMContent> list = findByGroupId(groupId, count - 1, count,
1672 orderByComparator);
1673
1674 if (!list.isEmpty()) {
1675 return list.get(0);
1676 }
1677
1678 return null;
1679 }
1680
1681
1691 public DDMContent[] findByGroupId_PrevAndNext(long contentId, long groupId,
1692 OrderByComparator orderByComparator)
1693 throws NoSuchContentException, SystemException {
1694 DDMContent ddmContent = findByPrimaryKey(contentId);
1695
1696 Session session = null;
1697
1698 try {
1699 session = openSession();
1700
1701 DDMContent[] array = new DDMContentImpl[3];
1702
1703 array[0] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1704 orderByComparator, true);
1705
1706 array[1] = ddmContent;
1707
1708 array[2] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1709 orderByComparator, false);
1710
1711 return array;
1712 }
1713 catch (Exception e) {
1714 throw processException(e);
1715 }
1716 finally {
1717 closeSession(session);
1718 }
1719 }
1720
1721 protected DDMContent getByGroupId_PrevAndNext(Session session,
1722 DDMContent ddmContent, long groupId,
1723 OrderByComparator orderByComparator, boolean previous) {
1724 StringBundler query = null;
1725
1726 if (orderByComparator != null) {
1727 query = new StringBundler(6 +
1728 (orderByComparator.getOrderByFields().length * 6));
1729 }
1730 else {
1731 query = new StringBundler(3);
1732 }
1733
1734 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1735
1736 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1737
1738 if (orderByComparator != null) {
1739 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1740
1741 if (orderByConditionFields.length > 0) {
1742 query.append(WHERE_AND);
1743 }
1744
1745 for (int i = 0; i < orderByConditionFields.length; i++) {
1746 query.append(_ORDER_BY_ENTITY_ALIAS);
1747 query.append(orderByConditionFields[i]);
1748
1749 if ((i + 1) < orderByConditionFields.length) {
1750 if (orderByComparator.isAscending() ^ previous) {
1751 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1752 }
1753 else {
1754 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1755 }
1756 }
1757 else {
1758 if (orderByComparator.isAscending() ^ previous) {
1759 query.append(WHERE_GREATER_THAN);
1760 }
1761 else {
1762 query.append(WHERE_LESSER_THAN);
1763 }
1764 }
1765 }
1766
1767 query.append(ORDER_BY_CLAUSE);
1768
1769 String[] orderByFields = orderByComparator.getOrderByFields();
1770
1771 for (int i = 0; i < orderByFields.length; i++) {
1772 query.append(_ORDER_BY_ENTITY_ALIAS);
1773 query.append(orderByFields[i]);
1774
1775 if ((i + 1) < orderByFields.length) {
1776 if (orderByComparator.isAscending() ^ previous) {
1777 query.append(ORDER_BY_ASC_HAS_NEXT);
1778 }
1779 else {
1780 query.append(ORDER_BY_DESC_HAS_NEXT);
1781 }
1782 }
1783 else {
1784 if (orderByComparator.isAscending() ^ previous) {
1785 query.append(ORDER_BY_ASC);
1786 }
1787 else {
1788 query.append(ORDER_BY_DESC);
1789 }
1790 }
1791 }
1792 }
1793 else {
1794 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
1795 }
1796
1797 String sql = query.toString();
1798
1799 Query q = session.createQuery(sql);
1800
1801 q.setFirstResult(0);
1802 q.setMaxResults(2);
1803
1804 QueryPos qPos = QueryPos.getInstance(q);
1805
1806 qPos.add(groupId);
1807
1808 if (orderByComparator != null) {
1809 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1810
1811 for (Object value : values) {
1812 qPos.add(value);
1813 }
1814 }
1815
1816 List<DDMContent> list = q.list();
1817
1818 if (list.size() == 2) {
1819 return list.get(1);
1820 }
1821 else {
1822 return null;
1823 }
1824 }
1825
1826
1832 public void removeByGroupId(long groupId) throws SystemException {
1833 for (DDMContent ddmContent : findByGroupId(groupId, QueryUtil.ALL_POS,
1834 QueryUtil.ALL_POS, null)) {
1835 remove(ddmContent);
1836 }
1837 }
1838
1839
1846 public int countByGroupId(long groupId) throws SystemException {
1847 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
1848
1849 Object[] finderArgs = new Object[] { groupId };
1850
1851 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1852 this);
1853
1854 if (count == null) {
1855 StringBundler query = new StringBundler(2);
1856
1857 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
1858
1859 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1860
1861 String sql = query.toString();
1862
1863 Session session = null;
1864
1865 try {
1866 session = openSession();
1867
1868 Query q = session.createQuery(sql);
1869
1870 QueryPos qPos = QueryPos.getInstance(q);
1871
1872 qPos.add(groupId);
1873
1874 count = (Long)q.uniqueResult();
1875
1876 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1877 }
1878 catch (Exception e) {
1879 FinderCacheUtil.removeResult(finderPath, finderArgs);
1880
1881 throw processException(e);
1882 }
1883 finally {
1884 closeSession(session);
1885 }
1886 }
1887
1888 return count.intValue();
1889 }
1890
1891 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmContent.groupId = ?";
1892 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1893 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1894 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
1895 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1896 new String[] {
1897 Long.class.getName(),
1898
1899 Integer.class.getName(), Integer.class.getName(),
1900 OrderByComparator.class.getName()
1901 });
1902 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1903 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1904 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
1905 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1906 new String[] { Long.class.getName() },
1907 DDMContentModelImpl.COMPANYID_COLUMN_BITMASK);
1908 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1909 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
1910 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1911 new String[] { Long.class.getName() });
1912
1913
1920 public List<DDMContent> findByCompanyId(long companyId)
1921 throws SystemException {
1922 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1923 null);
1924 }
1925
1926
1939 public List<DDMContent> findByCompanyId(long companyId, int start, int end)
1940 throws SystemException {
1941 return findByCompanyId(companyId, start, end, null);
1942 }
1943
1944
1958 public List<DDMContent> findByCompanyId(long companyId, int start, int end,
1959 OrderByComparator orderByComparator) throws SystemException {
1960 boolean pagination = true;
1961 FinderPath finderPath = null;
1962 Object[] finderArgs = null;
1963
1964 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1965 (orderByComparator == null)) {
1966 pagination = false;
1967 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1968 finderArgs = new Object[] { companyId };
1969 }
1970 else {
1971 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1972 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1973 }
1974
1975 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1976 finderArgs, this);
1977
1978 if ((list != null) && !list.isEmpty()) {
1979 for (DDMContent ddmContent : list) {
1980 if ((companyId != ddmContent.getCompanyId())) {
1981 list = null;
1982
1983 break;
1984 }
1985 }
1986 }
1987
1988 if (list == null) {
1989 StringBundler query = null;
1990
1991 if (orderByComparator != null) {
1992 query = new StringBundler(3 +
1993 (orderByComparator.getOrderByFields().length * 3));
1994 }
1995 else {
1996 query = new StringBundler(3);
1997 }
1998
1999 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
2000
2001 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2002
2003 if (orderByComparator != null) {
2004 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2005 orderByComparator);
2006 }
2007 else
2008 if (pagination) {
2009 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
2010 }
2011
2012 String sql = query.toString();
2013
2014 Session session = null;
2015
2016 try {
2017 session = openSession();
2018
2019 Query q = session.createQuery(sql);
2020
2021 QueryPos qPos = QueryPos.getInstance(q);
2022
2023 qPos.add(companyId);
2024
2025 if (!pagination) {
2026 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2027 start, end, false);
2028
2029 Collections.sort(list);
2030
2031 list = new UnmodifiableList<DDMContent>(list);
2032 }
2033 else {
2034 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2035 start, end);
2036 }
2037
2038 cacheResult(list);
2039
2040 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2041 }
2042 catch (Exception e) {
2043 FinderCacheUtil.removeResult(finderPath, finderArgs);
2044
2045 throw processException(e);
2046 }
2047 finally {
2048 closeSession(session);
2049 }
2050 }
2051
2052 return list;
2053 }
2054
2055
2064 public DDMContent findByCompanyId_First(long companyId,
2065 OrderByComparator orderByComparator)
2066 throws NoSuchContentException, SystemException {
2067 DDMContent ddmContent = fetchByCompanyId_First(companyId,
2068 orderByComparator);
2069
2070 if (ddmContent != null) {
2071 return ddmContent;
2072 }
2073
2074 StringBundler msg = new StringBundler(4);
2075
2076 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2077
2078 msg.append("companyId=");
2079 msg.append(companyId);
2080
2081 msg.append(StringPool.CLOSE_CURLY_BRACE);
2082
2083 throw new NoSuchContentException(msg.toString());
2084 }
2085
2086
2094 public DDMContent fetchByCompanyId_First(long companyId,
2095 OrderByComparator orderByComparator) throws SystemException {
2096 List<DDMContent> list = findByCompanyId(companyId, 0, 1,
2097 orderByComparator);
2098
2099 if (!list.isEmpty()) {
2100 return list.get(0);
2101 }
2102
2103 return null;
2104 }
2105
2106
2115 public DDMContent findByCompanyId_Last(long companyId,
2116 OrderByComparator orderByComparator)
2117 throws NoSuchContentException, SystemException {
2118 DDMContent ddmContent = fetchByCompanyId_Last(companyId,
2119 orderByComparator);
2120
2121 if (ddmContent != null) {
2122 return ddmContent;
2123 }
2124
2125 StringBundler msg = new StringBundler(4);
2126
2127 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2128
2129 msg.append("companyId=");
2130 msg.append(companyId);
2131
2132 msg.append(StringPool.CLOSE_CURLY_BRACE);
2133
2134 throw new NoSuchContentException(msg.toString());
2135 }
2136
2137
2145 public DDMContent fetchByCompanyId_Last(long companyId,
2146 OrderByComparator orderByComparator) throws SystemException {
2147 int count = countByCompanyId(companyId);
2148
2149 List<DDMContent> list = findByCompanyId(companyId, count - 1, count,
2150 orderByComparator);
2151
2152 if (!list.isEmpty()) {
2153 return list.get(0);
2154 }
2155
2156 return null;
2157 }
2158
2159
2169 public DDMContent[] findByCompanyId_PrevAndNext(long contentId,
2170 long companyId, OrderByComparator orderByComparator)
2171 throws NoSuchContentException, SystemException {
2172 DDMContent ddmContent = findByPrimaryKey(contentId);
2173
2174 Session session = null;
2175
2176 try {
2177 session = openSession();
2178
2179 DDMContent[] array = new DDMContentImpl[3];
2180
2181 array[0] = getByCompanyId_PrevAndNext(session, ddmContent,
2182 companyId, orderByComparator, true);
2183
2184 array[1] = ddmContent;
2185
2186 array[2] = getByCompanyId_PrevAndNext(session, ddmContent,
2187 companyId, orderByComparator, false);
2188
2189 return array;
2190 }
2191 catch (Exception e) {
2192 throw processException(e);
2193 }
2194 finally {
2195 closeSession(session);
2196 }
2197 }
2198
2199 protected DDMContent getByCompanyId_PrevAndNext(Session session,
2200 DDMContent ddmContent, long companyId,
2201 OrderByComparator orderByComparator, boolean previous) {
2202 StringBundler query = null;
2203
2204 if (orderByComparator != null) {
2205 query = new StringBundler(6 +
2206 (orderByComparator.getOrderByFields().length * 6));
2207 }
2208 else {
2209 query = new StringBundler(3);
2210 }
2211
2212 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
2213
2214 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2215
2216 if (orderByComparator != null) {
2217 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2218
2219 if (orderByConditionFields.length > 0) {
2220 query.append(WHERE_AND);
2221 }
2222
2223 for (int i = 0; i < orderByConditionFields.length; i++) {
2224 query.append(_ORDER_BY_ENTITY_ALIAS);
2225 query.append(orderByConditionFields[i]);
2226
2227 if ((i + 1) < orderByConditionFields.length) {
2228 if (orderByComparator.isAscending() ^ previous) {
2229 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2230 }
2231 else {
2232 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2233 }
2234 }
2235 else {
2236 if (orderByComparator.isAscending() ^ previous) {
2237 query.append(WHERE_GREATER_THAN);
2238 }
2239 else {
2240 query.append(WHERE_LESSER_THAN);
2241 }
2242 }
2243 }
2244
2245 query.append(ORDER_BY_CLAUSE);
2246
2247 String[] orderByFields = orderByComparator.getOrderByFields();
2248
2249 for (int i = 0; i < orderByFields.length; i++) {
2250 query.append(_ORDER_BY_ENTITY_ALIAS);
2251 query.append(orderByFields[i]);
2252
2253 if ((i + 1) < orderByFields.length) {
2254 if (orderByComparator.isAscending() ^ previous) {
2255 query.append(ORDER_BY_ASC_HAS_NEXT);
2256 }
2257 else {
2258 query.append(ORDER_BY_DESC_HAS_NEXT);
2259 }
2260 }
2261 else {
2262 if (orderByComparator.isAscending() ^ previous) {
2263 query.append(ORDER_BY_ASC);
2264 }
2265 else {
2266 query.append(ORDER_BY_DESC);
2267 }
2268 }
2269 }
2270 }
2271 else {
2272 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
2273 }
2274
2275 String sql = query.toString();
2276
2277 Query q = session.createQuery(sql);
2278
2279 q.setFirstResult(0);
2280 q.setMaxResults(2);
2281
2282 QueryPos qPos = QueryPos.getInstance(q);
2283
2284 qPos.add(companyId);
2285
2286 if (orderByComparator != null) {
2287 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
2288
2289 for (Object value : values) {
2290 qPos.add(value);
2291 }
2292 }
2293
2294 List<DDMContent> list = q.list();
2295
2296 if (list.size() == 2) {
2297 return list.get(1);
2298 }
2299 else {
2300 return null;
2301 }
2302 }
2303
2304
2310 public void removeByCompanyId(long companyId) throws SystemException {
2311 for (DDMContent ddmContent : findByCompanyId(companyId,
2312 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2313 remove(ddmContent);
2314 }
2315 }
2316
2317
2324 public int countByCompanyId(long companyId) throws SystemException {
2325 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2326
2327 Object[] finderArgs = new Object[] { companyId };
2328
2329 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2330 this);
2331
2332 if (count == null) {
2333 StringBundler query = new StringBundler(2);
2334
2335 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2336
2337 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2338
2339 String sql = query.toString();
2340
2341 Session session = null;
2342
2343 try {
2344 session = openSession();
2345
2346 Query q = session.createQuery(sql);
2347
2348 QueryPos qPos = QueryPos.getInstance(q);
2349
2350 qPos.add(companyId);
2351
2352 count = (Long)q.uniqueResult();
2353
2354 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2355 }
2356 catch (Exception e) {
2357 FinderCacheUtil.removeResult(finderPath, finderArgs);
2358
2359 throw processException(e);
2360 }
2361 finally {
2362 closeSession(session);
2363 }
2364 }
2365
2366 return count.intValue();
2367 }
2368
2369 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "ddmContent.companyId = ?";
2370
2371
2376 public void cacheResult(DDMContent ddmContent) {
2377 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2378 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
2379
2380 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2381 new Object[] { ddmContent.getUuid(), ddmContent.getGroupId() },
2382 ddmContent);
2383
2384 ddmContent.resetOriginalValues();
2385 }
2386
2387
2392 public void cacheResult(List<DDMContent> ddmContents) {
2393 for (DDMContent ddmContent : ddmContents) {
2394 if (EntityCacheUtil.getResult(
2395 DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2396 DDMContentImpl.class, ddmContent.getPrimaryKey()) == null) {
2397 cacheResult(ddmContent);
2398 }
2399 else {
2400 ddmContent.resetOriginalValues();
2401 }
2402 }
2403 }
2404
2405
2412 @Override
2413 public void clearCache() {
2414 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2415 CacheRegistryUtil.clear(DDMContentImpl.class.getName());
2416 }
2417
2418 EntityCacheUtil.clearCache(DDMContentImpl.class.getName());
2419
2420 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2421 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2422 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2423 }
2424
2425
2432 @Override
2433 public void clearCache(DDMContent ddmContent) {
2434 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2435 DDMContentImpl.class, ddmContent.getPrimaryKey());
2436
2437 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2438 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2439
2440 clearUniqueFindersCache(ddmContent);
2441 }
2442
2443 @Override
2444 public void clearCache(List<DDMContent> ddmContents) {
2445 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2446 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2447
2448 for (DDMContent ddmContent : ddmContents) {
2449 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2450 DDMContentImpl.class, ddmContent.getPrimaryKey());
2451
2452 clearUniqueFindersCache(ddmContent);
2453 }
2454 }
2455
2456 protected void cacheUniqueFindersCache(DDMContent ddmContent) {
2457 if (ddmContent.isNew()) {
2458 Object[] args = new Object[] {
2459 ddmContent.getUuid(), ddmContent.getGroupId()
2460 };
2461
2462 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2463 Long.valueOf(1));
2464 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2465 ddmContent);
2466 }
2467 else {
2468 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
2469
2470 if ((ddmContentModelImpl.getColumnBitmask() &
2471 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2472 Object[] args = new Object[] {
2473 ddmContent.getUuid(), ddmContent.getGroupId()
2474 };
2475
2476 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2477 Long.valueOf(1));
2478 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2479 ddmContent);
2480 }
2481 }
2482 }
2483
2484 protected void clearUniqueFindersCache(DDMContent ddmContent) {
2485 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
2486
2487 Object[] args = new Object[] {
2488 ddmContent.getUuid(), ddmContent.getGroupId()
2489 };
2490
2491 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2492 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2493
2494 if ((ddmContentModelImpl.getColumnBitmask() &
2495 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2496 args = new Object[] {
2497 ddmContentModelImpl.getOriginalUuid(),
2498 ddmContentModelImpl.getOriginalGroupId()
2499 };
2500
2501 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2502 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2503 }
2504 }
2505
2506
2512 public DDMContent create(long contentId) {
2513 DDMContent ddmContent = new DDMContentImpl();
2514
2515 ddmContent.setNew(true);
2516 ddmContent.setPrimaryKey(contentId);
2517
2518 String uuid = PortalUUIDUtil.generate();
2519
2520 ddmContent.setUuid(uuid);
2521
2522 return ddmContent;
2523 }
2524
2525
2533 public DDMContent remove(long contentId)
2534 throws NoSuchContentException, SystemException {
2535 return remove((Serializable)contentId);
2536 }
2537
2538
2546 @Override
2547 public DDMContent remove(Serializable primaryKey)
2548 throws NoSuchContentException, SystemException {
2549 Session session = null;
2550
2551 try {
2552 session = openSession();
2553
2554 DDMContent ddmContent = (DDMContent)session.get(DDMContentImpl.class,
2555 primaryKey);
2556
2557 if (ddmContent == null) {
2558 if (_log.isWarnEnabled()) {
2559 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2560 }
2561
2562 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2563 primaryKey);
2564 }
2565
2566 return remove(ddmContent);
2567 }
2568 catch (NoSuchContentException nsee) {
2569 throw nsee;
2570 }
2571 catch (Exception e) {
2572 throw processException(e);
2573 }
2574 finally {
2575 closeSession(session);
2576 }
2577 }
2578
2579 @Override
2580 protected DDMContent removeImpl(DDMContent ddmContent)
2581 throws SystemException {
2582 ddmContent = toUnwrappedModel(ddmContent);
2583
2584 Session session = null;
2585
2586 try {
2587 session = openSession();
2588
2589 if (!session.contains(ddmContent)) {
2590 ddmContent = (DDMContent)session.get(DDMContentImpl.class,
2591 ddmContent.getPrimaryKeyObj());
2592 }
2593
2594 if (ddmContent != null) {
2595 session.delete(ddmContent);
2596 }
2597 }
2598 catch (Exception e) {
2599 throw processException(e);
2600 }
2601 finally {
2602 closeSession(session);
2603 }
2604
2605 if (ddmContent != null) {
2606 clearCache(ddmContent);
2607 }
2608
2609 return ddmContent;
2610 }
2611
2612 @Override
2613 public DDMContent updateImpl(
2614 com.liferay.portlet.dynamicdatamapping.model.DDMContent ddmContent)
2615 throws SystemException {
2616 ddmContent = toUnwrappedModel(ddmContent);
2617
2618 boolean isNew = ddmContent.isNew();
2619
2620 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
2621
2622 if (Validator.isNull(ddmContent.getUuid())) {
2623 String uuid = PortalUUIDUtil.generate();
2624
2625 ddmContent.setUuid(uuid);
2626 }
2627
2628 Session session = null;
2629
2630 try {
2631 session = openSession();
2632
2633 if (ddmContent.isNew()) {
2634 session.save(ddmContent);
2635
2636 ddmContent.setNew(false);
2637 }
2638 else {
2639 session.merge(ddmContent);
2640 }
2641 }
2642 catch (Exception e) {
2643 throw processException(e);
2644 }
2645 finally {
2646 closeSession(session);
2647 }
2648
2649 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2650
2651 if (isNew || !DDMContentModelImpl.COLUMN_BITMASK_ENABLED) {
2652 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2653 }
2654
2655 else {
2656 if ((ddmContentModelImpl.getColumnBitmask() &
2657 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2658 Object[] args = new Object[] {
2659 ddmContentModelImpl.getOriginalUuid()
2660 };
2661
2662 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2663 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2664 args);
2665
2666 args = new Object[] { ddmContentModelImpl.getUuid() };
2667
2668 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2669 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2670 args);
2671 }
2672
2673 if ((ddmContentModelImpl.getColumnBitmask() &
2674 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2675 Object[] args = new Object[] {
2676 ddmContentModelImpl.getOriginalUuid(),
2677 ddmContentModelImpl.getOriginalCompanyId()
2678 };
2679
2680 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2681 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2682 args);
2683
2684 args = new Object[] {
2685 ddmContentModelImpl.getUuid(),
2686 ddmContentModelImpl.getCompanyId()
2687 };
2688
2689 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2690 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2691 args);
2692 }
2693
2694 if ((ddmContentModelImpl.getColumnBitmask() &
2695 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2696 Object[] args = new Object[] {
2697 ddmContentModelImpl.getOriginalGroupId()
2698 };
2699
2700 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2701 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2702 args);
2703
2704 args = new Object[] { ddmContentModelImpl.getGroupId() };
2705
2706 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2707 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2708 args);
2709 }
2710
2711 if ((ddmContentModelImpl.getColumnBitmask() &
2712 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2713 Object[] args = new Object[] {
2714 ddmContentModelImpl.getOriginalCompanyId()
2715 };
2716
2717 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2718 args);
2719 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2720 args);
2721
2722 args = new Object[] { ddmContentModelImpl.getCompanyId() };
2723
2724 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2725 args);
2726 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2727 args);
2728 }
2729 }
2730
2731 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2732 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
2733
2734 clearUniqueFindersCache(ddmContent);
2735 cacheUniqueFindersCache(ddmContent);
2736
2737 return ddmContent;
2738 }
2739
2740 protected DDMContent toUnwrappedModel(DDMContent ddmContent) {
2741 if (ddmContent instanceof DDMContentImpl) {
2742 return ddmContent;
2743 }
2744
2745 DDMContentImpl ddmContentImpl = new DDMContentImpl();
2746
2747 ddmContentImpl.setNew(ddmContent.isNew());
2748 ddmContentImpl.setPrimaryKey(ddmContent.getPrimaryKey());
2749
2750 ddmContentImpl.setUuid(ddmContent.getUuid());
2751 ddmContentImpl.setContentId(ddmContent.getContentId());
2752 ddmContentImpl.setGroupId(ddmContent.getGroupId());
2753 ddmContentImpl.setCompanyId(ddmContent.getCompanyId());
2754 ddmContentImpl.setUserId(ddmContent.getUserId());
2755 ddmContentImpl.setUserName(ddmContent.getUserName());
2756 ddmContentImpl.setCreateDate(ddmContent.getCreateDate());
2757 ddmContentImpl.setModifiedDate(ddmContent.getModifiedDate());
2758 ddmContentImpl.setName(ddmContent.getName());
2759 ddmContentImpl.setDescription(ddmContent.getDescription());
2760 ddmContentImpl.setXml(ddmContent.getXml());
2761
2762 return ddmContentImpl;
2763 }
2764
2765
2773 @Override
2774 public DDMContent findByPrimaryKey(Serializable primaryKey)
2775 throws NoSuchContentException, SystemException {
2776 DDMContent ddmContent = fetchByPrimaryKey(primaryKey);
2777
2778 if (ddmContent == null) {
2779 if (_log.isWarnEnabled()) {
2780 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2781 }
2782
2783 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2784 primaryKey);
2785 }
2786
2787 return ddmContent;
2788 }
2789
2790
2798 public DDMContent findByPrimaryKey(long contentId)
2799 throws NoSuchContentException, SystemException {
2800 return findByPrimaryKey((Serializable)contentId);
2801 }
2802
2803
2810 @Override
2811 public DDMContent fetchByPrimaryKey(Serializable primaryKey)
2812 throws SystemException {
2813 DDMContent ddmContent = (DDMContent)EntityCacheUtil.getResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2814 DDMContentImpl.class, primaryKey);
2815
2816 if (ddmContent == _nullDDMContent) {
2817 return null;
2818 }
2819
2820 if (ddmContent == null) {
2821 Session session = null;
2822
2823 try {
2824 session = openSession();
2825
2826 ddmContent = (DDMContent)session.get(DDMContentImpl.class,
2827 primaryKey);
2828
2829 if (ddmContent != null) {
2830 cacheResult(ddmContent);
2831 }
2832 else {
2833 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2834 DDMContentImpl.class, primaryKey, _nullDDMContent);
2835 }
2836 }
2837 catch (Exception e) {
2838 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2839 DDMContentImpl.class, primaryKey);
2840
2841 throw processException(e);
2842 }
2843 finally {
2844 closeSession(session);
2845 }
2846 }
2847
2848 return ddmContent;
2849 }
2850
2851
2858 public DDMContent fetchByPrimaryKey(long contentId)
2859 throws SystemException {
2860 return fetchByPrimaryKey((Serializable)contentId);
2861 }
2862
2863
2869 public List<DDMContent> findAll() throws SystemException {
2870 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2871 }
2872
2873
2885 public List<DDMContent> findAll(int start, int end)
2886 throws SystemException {
2887 return findAll(start, end, null);
2888 }
2889
2890
2903 public List<DDMContent> findAll(int start, int end,
2904 OrderByComparator orderByComparator) throws SystemException {
2905 boolean pagination = true;
2906 FinderPath finderPath = null;
2907 Object[] finderArgs = null;
2908
2909 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2910 (orderByComparator == null)) {
2911 pagination = false;
2912 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2913 finderArgs = FINDER_ARGS_EMPTY;
2914 }
2915 else {
2916 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2917 finderArgs = new Object[] { start, end, orderByComparator };
2918 }
2919
2920 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
2921 finderArgs, this);
2922
2923 if (list == null) {
2924 StringBundler query = null;
2925 String sql = null;
2926
2927 if (orderByComparator != null) {
2928 query = new StringBundler(2 +
2929 (orderByComparator.getOrderByFields().length * 3));
2930
2931 query.append(_SQL_SELECT_DDMCONTENT);
2932
2933 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2934 orderByComparator);
2935
2936 sql = query.toString();
2937 }
2938 else {
2939 sql = _SQL_SELECT_DDMCONTENT;
2940
2941 if (pagination) {
2942 sql = sql.concat(DDMContentModelImpl.ORDER_BY_JPQL);
2943 }
2944 }
2945
2946 Session session = null;
2947
2948 try {
2949 session = openSession();
2950
2951 Query q = session.createQuery(sql);
2952
2953 if (!pagination) {
2954 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2955 start, end, false);
2956
2957 Collections.sort(list);
2958
2959 list = new UnmodifiableList<DDMContent>(list);
2960 }
2961 else {
2962 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2963 start, end);
2964 }
2965
2966 cacheResult(list);
2967
2968 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2969 }
2970 catch (Exception e) {
2971 FinderCacheUtil.removeResult(finderPath, finderArgs);
2972
2973 throw processException(e);
2974 }
2975 finally {
2976 closeSession(session);
2977 }
2978 }
2979
2980 return list;
2981 }
2982
2983
2988 public void removeAll() throws SystemException {
2989 for (DDMContent ddmContent : findAll()) {
2990 remove(ddmContent);
2991 }
2992 }
2993
2994
3000 public int countAll() throws SystemException {
3001 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3002 FINDER_ARGS_EMPTY, this);
3003
3004 if (count == null) {
3005 Session session = null;
3006
3007 try {
3008 session = openSession();
3009
3010 Query q = session.createQuery(_SQL_COUNT_DDMCONTENT);
3011
3012 count = (Long)q.uniqueResult();
3013
3014 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3015 FINDER_ARGS_EMPTY, count);
3016 }
3017 catch (Exception e) {
3018 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3019 FINDER_ARGS_EMPTY);
3020
3021 throw processException(e);
3022 }
3023 finally {
3024 closeSession(session);
3025 }
3026 }
3027
3028 return count.intValue();
3029 }
3030
3031 @Override
3032 protected Set<String> getBadColumnNames() {
3033 return _badColumnNames;
3034 }
3035
3036
3039 public void afterPropertiesSet() {
3040 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3041 com.liferay.portal.util.PropsUtil.get(
3042 "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMContent")));
3043
3044 if (listenerClassNames.length > 0) {
3045 try {
3046 List<ModelListener<DDMContent>> listenersList = new ArrayList<ModelListener<DDMContent>>();
3047
3048 for (String listenerClassName : listenerClassNames) {
3049 listenersList.add((ModelListener<DDMContent>)InstanceFactory.newInstance(
3050 getClassLoader(), listenerClassName));
3051 }
3052
3053 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3054 }
3055 catch (Exception e) {
3056 _log.error(e);
3057 }
3058 }
3059 }
3060
3061 public void destroy() {
3062 EntityCacheUtil.removeCache(DDMContentImpl.class.getName());
3063 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3064 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3065 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3066 }
3067
3068 private static final String _SQL_SELECT_DDMCONTENT = "SELECT ddmContent FROM DDMContent ddmContent";
3069 private static final String _SQL_SELECT_DDMCONTENT_WHERE = "SELECT ddmContent FROM DDMContent ddmContent WHERE ";
3070 private static final String _SQL_COUNT_DDMCONTENT = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent";
3071 private static final String _SQL_COUNT_DDMCONTENT_WHERE = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent WHERE ";
3072 private static final String _ORDER_BY_ENTITY_ALIAS = "ddmContent.";
3073 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMContent exists with the primary key ";
3074 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMContent exists with the key {";
3075 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3076 private static Log _log = LogFactoryUtil.getLog(DDMContentPersistenceImpl.class);
3077 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3078 "uuid"
3079 });
3080 private static DDMContent _nullDDMContent = new DDMContentImpl() {
3081 @Override
3082 public Object clone() {
3083 return this;
3084 }
3085
3086 @Override
3087 public CacheModel<DDMContent> toCacheModel() {
3088 return _nullDDMContentCacheModel;
3089 }
3090 };
3091
3092 private static CacheModel<DDMContent> _nullDDMContentCacheModel = new CacheModel<DDMContent>() {
3093 public DDMContent toEntityModel() {
3094 return _nullDDMContent;
3095 }
3096 };
3097 }