001
014
015 package com.liferay.portlet.dynamicdatamapping.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.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
053
065 public class DDMContentPersistenceImpl extends BasePersistenceImpl<DDMContent>
066 implements DDMContentPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = DDMContentImpl.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(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
078 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.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(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
081 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
084 DDMContentModelImpl.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_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
087 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
089 new String[] {
090 String.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_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
096 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
098 new String[] { String.class.getName() },
099 DDMContentModelImpl.UUID_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
101 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
103 new String[] { String.class.getName() });
104
105
112 public List<DDMContent> findByUuid(String uuid) throws SystemException {
113 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
114 }
115
116
129 public List<DDMContent> findByUuid(String uuid, int start, int end)
130 throws SystemException {
131 return findByUuid(uuid, start, end, null);
132 }
133
134
148 public List<DDMContent> findByUuid(String uuid, int start, int end,
149 OrderByComparator orderByComparator) throws SystemException {
150 boolean pagination = true;
151 FinderPath finderPath = null;
152 Object[] finderArgs = null;
153
154 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
155 (orderByComparator == null)) {
156 pagination = false;
157 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
158 finderArgs = new Object[] { uuid };
159 }
160 else {
161 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
162 finderArgs = new Object[] { uuid, start, end, orderByComparator };
163 }
164
165 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
166 finderArgs, this);
167
168 if ((list != null) && !list.isEmpty()) {
169 for (DDMContent ddmContent : list) {
170 if (!Validator.equals(uuid, ddmContent.getUuid())) {
171 list = null;
172
173 break;
174 }
175 }
176 }
177
178 if (list == null) {
179 StringBundler query = null;
180
181 if (orderByComparator != null) {
182 query = new StringBundler(3 +
183 (orderByComparator.getOrderByFields().length * 3));
184 }
185 else {
186 query = new StringBundler(3);
187 }
188
189 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
190
191 if (uuid == null) {
192 query.append(_FINDER_COLUMN_UUID_UUID_1);
193 }
194 else {
195 if (uuid.equals(StringPool.BLANK)) {
196 query.append(_FINDER_COLUMN_UUID_UUID_3);
197 }
198 else {
199 query.append(_FINDER_COLUMN_UUID_UUID_2);
200 }
201 }
202
203 if (orderByComparator != null) {
204 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
205 orderByComparator);
206 }
207 else
208 if (pagination) {
209 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
210 }
211
212 String sql = query.toString();
213
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 Query q = session.createQuery(sql);
220
221 QueryPos qPos = QueryPos.getInstance(q);
222
223 if (uuid != null) {
224 qPos.add(uuid);
225 }
226
227 if (!pagination) {
228 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
229 start, end, false);
230
231 Collections.sort(list);
232
233 list = new UnmodifiableList<DDMContent>(list);
234 }
235 else {
236 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
237 start, end);
238 }
239
240 cacheResult(list);
241
242 FinderCacheUtil.putResult(finderPath, finderArgs, list);
243 }
244 catch (Exception e) {
245 FinderCacheUtil.removeResult(finderPath, finderArgs);
246
247 throw processException(e);
248 }
249 finally {
250 closeSession(session);
251 }
252 }
253
254 return list;
255 }
256
257
266 public DDMContent findByUuid_First(String uuid,
267 OrderByComparator orderByComparator)
268 throws NoSuchContentException, SystemException {
269 DDMContent ddmContent = fetchByUuid_First(uuid, orderByComparator);
270
271 if (ddmContent != null) {
272 return ddmContent;
273 }
274
275 StringBundler msg = new StringBundler(4);
276
277 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
278
279 msg.append("uuid=");
280 msg.append(uuid);
281
282 msg.append(StringPool.CLOSE_CURLY_BRACE);
283
284 throw new NoSuchContentException(msg.toString());
285 }
286
287
295 public DDMContent fetchByUuid_First(String uuid,
296 OrderByComparator orderByComparator) throws SystemException {
297 List<DDMContent> list = findByUuid(uuid, 0, 1, orderByComparator);
298
299 if (!list.isEmpty()) {
300 return list.get(0);
301 }
302
303 return null;
304 }
305
306
315 public DDMContent findByUuid_Last(String uuid,
316 OrderByComparator orderByComparator)
317 throws NoSuchContentException, SystemException {
318 DDMContent ddmContent = fetchByUuid_Last(uuid, orderByComparator);
319
320 if (ddmContent != null) {
321 return ddmContent;
322 }
323
324 StringBundler msg = new StringBundler(4);
325
326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327
328 msg.append("uuid=");
329 msg.append(uuid);
330
331 msg.append(StringPool.CLOSE_CURLY_BRACE);
332
333 throw new NoSuchContentException(msg.toString());
334 }
335
336
344 public DDMContent fetchByUuid_Last(String uuid,
345 OrderByComparator orderByComparator) throws SystemException {
346 int count = countByUuid(uuid);
347
348 List<DDMContent> list = findByUuid(uuid, count - 1, count,
349 orderByComparator);
350
351 if (!list.isEmpty()) {
352 return list.get(0);
353 }
354
355 return null;
356 }
357
358
368 public DDMContent[] findByUuid_PrevAndNext(long contentId, String uuid,
369 OrderByComparator orderByComparator)
370 throws NoSuchContentException, SystemException {
371 DDMContent ddmContent = findByPrimaryKey(contentId);
372
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 DDMContent[] array = new DDMContentImpl[3];
379
380 array[0] = getByUuid_PrevAndNext(session, ddmContent, uuid,
381 orderByComparator, true);
382
383 array[1] = ddmContent;
384
385 array[2] = getByUuid_PrevAndNext(session, ddmContent, uuid,
386 orderByComparator, false);
387
388 return array;
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396 }
397
398 protected DDMContent getByUuid_PrevAndNext(Session session,
399 DDMContent ddmContent, String uuid,
400 OrderByComparator orderByComparator, boolean previous) {
401 StringBundler query = null;
402
403 if (orderByComparator != null) {
404 query = new StringBundler(6 +
405 (orderByComparator.getOrderByFields().length * 6));
406 }
407 else {
408 query = new StringBundler(3);
409 }
410
411 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
412
413 if (uuid == null) {
414 query.append(_FINDER_COLUMN_UUID_UUID_1);
415 }
416 else {
417 if (uuid.equals(StringPool.BLANK)) {
418 query.append(_FINDER_COLUMN_UUID_UUID_3);
419 }
420 else {
421 query.append(_FINDER_COLUMN_UUID_UUID_2);
422 }
423 }
424
425 if (orderByComparator != null) {
426 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
427
428 if (orderByConditionFields.length > 0) {
429 query.append(WHERE_AND);
430 }
431
432 for (int i = 0; i < orderByConditionFields.length; i++) {
433 query.append(_ORDER_BY_ENTITY_ALIAS);
434 query.append(orderByConditionFields[i]);
435
436 if ((i + 1) < orderByConditionFields.length) {
437 if (orderByComparator.isAscending() ^ previous) {
438 query.append(WHERE_GREATER_THAN_HAS_NEXT);
439 }
440 else {
441 query.append(WHERE_LESSER_THAN_HAS_NEXT);
442 }
443 }
444 else {
445 if (orderByComparator.isAscending() ^ previous) {
446 query.append(WHERE_GREATER_THAN);
447 }
448 else {
449 query.append(WHERE_LESSER_THAN);
450 }
451 }
452 }
453
454 query.append(ORDER_BY_CLAUSE);
455
456 String[] orderByFields = orderByComparator.getOrderByFields();
457
458 for (int i = 0; i < orderByFields.length; i++) {
459 query.append(_ORDER_BY_ENTITY_ALIAS);
460 query.append(orderByFields[i]);
461
462 if ((i + 1) < orderByFields.length) {
463 if (orderByComparator.isAscending() ^ previous) {
464 query.append(ORDER_BY_ASC_HAS_NEXT);
465 }
466 else {
467 query.append(ORDER_BY_DESC_HAS_NEXT);
468 }
469 }
470 else {
471 if (orderByComparator.isAscending() ^ previous) {
472 query.append(ORDER_BY_ASC);
473 }
474 else {
475 query.append(ORDER_BY_DESC);
476 }
477 }
478 }
479 }
480 else {
481 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
482 }
483
484 String sql = query.toString();
485
486 Query q = session.createQuery(sql);
487
488 q.setFirstResult(0);
489 q.setMaxResults(2);
490
491 QueryPos qPos = QueryPos.getInstance(q);
492
493 if (uuid != null) {
494 qPos.add(uuid);
495 }
496
497 if (orderByComparator != null) {
498 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
499
500 for (Object value : values) {
501 qPos.add(value);
502 }
503 }
504
505 List<DDMContent> list = q.list();
506
507 if (list.size() == 2) {
508 return list.get(1);
509 }
510 else {
511 return null;
512 }
513 }
514
515
521 public void removeByUuid(String uuid) throws SystemException {
522 for (DDMContent ddmContent : findByUuid(uuid, QueryUtil.ALL_POS,
523 QueryUtil.ALL_POS, null)) {
524 remove(ddmContent);
525 }
526 }
527
528
535 public int countByUuid(String uuid) throws SystemException {
536 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
537
538 Object[] finderArgs = new Object[] { uuid };
539
540 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
541 this);
542
543 if (count == null) {
544 StringBundler query = new StringBundler(2);
545
546 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
547
548 if (uuid == null) {
549 query.append(_FINDER_COLUMN_UUID_UUID_1);
550 }
551 else {
552 if (uuid.equals(StringPool.BLANK)) {
553 query.append(_FINDER_COLUMN_UUID_UUID_3);
554 }
555 else {
556 query.append(_FINDER_COLUMN_UUID_UUID_2);
557 }
558 }
559
560 String sql = query.toString();
561
562 Session session = null;
563
564 try {
565 session = openSession();
566
567 Query q = session.createQuery(sql);
568
569 QueryPos qPos = QueryPos.getInstance(q);
570
571 if (uuid != null) {
572 qPos.add(uuid);
573 }
574
575 count = (Long)q.uniqueResult();
576
577 FinderCacheUtil.putResult(finderPath, finderArgs, count);
578 }
579 catch (Exception e) {
580 FinderCacheUtil.removeResult(finderPath, finderArgs);
581
582 throw processException(e);
583 }
584 finally {
585 closeSession(session);
586 }
587 }
588
589 return count.intValue();
590 }
591
592 private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmContent.uuid IS NULL";
593 private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmContent.uuid = ?";
594 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?)";
595 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
596 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
597 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
598 new String[] { String.class.getName(), Long.class.getName() },
599 DDMContentModelImpl.UUID_COLUMN_BITMASK |
600 DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
601 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
602 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
603 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
604 new String[] { String.class.getName(), Long.class.getName() });
605
606
615 public DDMContent findByUUID_G(String uuid, long groupId)
616 throws NoSuchContentException, SystemException {
617 DDMContent ddmContent = fetchByUUID_G(uuid, groupId);
618
619 if (ddmContent == null) {
620 StringBundler msg = new StringBundler(6);
621
622 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
623
624 msg.append("uuid=");
625 msg.append(uuid);
626
627 msg.append(", groupId=");
628 msg.append(groupId);
629
630 msg.append(StringPool.CLOSE_CURLY_BRACE);
631
632 if (_log.isWarnEnabled()) {
633 _log.warn(msg.toString());
634 }
635
636 throw new NoSuchContentException(msg.toString());
637 }
638
639 return ddmContent;
640 }
641
642
650 public DDMContent fetchByUUID_G(String uuid, long groupId)
651 throws SystemException {
652 return fetchByUUID_G(uuid, groupId, true);
653 }
654
655
664 public DDMContent fetchByUUID_G(String uuid, long groupId,
665 boolean retrieveFromCache) throws SystemException {
666 Object[] finderArgs = new Object[] { uuid, groupId };
667
668 Object result = null;
669
670 if (retrieveFromCache) {
671 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
672 finderArgs, this);
673 }
674
675 if (result instanceof DDMContent) {
676 DDMContent ddmContent = (DDMContent)result;
677
678 if (!Validator.equals(uuid, ddmContent.getUuid()) ||
679 (groupId != ddmContent.getGroupId())) {
680 result = null;
681 }
682 }
683
684 if (result == null) {
685 StringBundler query = new StringBundler(4);
686
687 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
688
689 if (uuid == null) {
690 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
691 }
692 else {
693 if (uuid.equals(StringPool.BLANK)) {
694 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
695 }
696 else {
697 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
698 }
699 }
700
701 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
702
703 String sql = query.toString();
704
705 Session session = null;
706
707 try {
708 session = openSession();
709
710 Query q = session.createQuery(sql);
711
712 QueryPos qPos = QueryPos.getInstance(q);
713
714 if (uuid != null) {
715 qPos.add(uuid);
716 }
717
718 qPos.add(groupId);
719
720 List<DDMContent> list = q.list();
721
722 if (list.isEmpty()) {
723 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
724 finderArgs, list);
725 }
726 else {
727 DDMContent ddmContent = list.get(0);
728
729 result = ddmContent;
730
731 cacheResult(ddmContent);
732
733 if ((ddmContent.getUuid() == null) ||
734 !ddmContent.getUuid().equals(uuid) ||
735 (ddmContent.getGroupId() != groupId)) {
736 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
737 finderArgs, ddmContent);
738 }
739 }
740 }
741 catch (Exception e) {
742 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
743 finderArgs);
744
745 throw processException(e);
746 }
747 finally {
748 closeSession(session);
749 }
750 }
751
752 if (result instanceof List<?>) {
753 return null;
754 }
755 else {
756 return (DDMContent)result;
757 }
758 }
759
760
768 public DDMContent removeByUUID_G(String uuid, long groupId)
769 throws NoSuchContentException, SystemException {
770 DDMContent ddmContent = findByUUID_G(uuid, groupId);
771
772 return remove(ddmContent);
773 }
774
775
783 public int countByUUID_G(String uuid, long groupId)
784 throws SystemException {
785 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
786
787 Object[] finderArgs = new Object[] { uuid, groupId };
788
789 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
790 this);
791
792 if (count == null) {
793 StringBundler query = new StringBundler(3);
794
795 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
796
797 if (uuid == null) {
798 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
799 }
800 else {
801 if (uuid.equals(StringPool.BLANK)) {
802 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
803 }
804 else {
805 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
806 }
807 }
808
809 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
810
811 String sql = query.toString();
812
813 Session session = null;
814
815 try {
816 session = openSession();
817
818 Query q = session.createQuery(sql);
819
820 QueryPos qPos = QueryPos.getInstance(q);
821
822 if (uuid != null) {
823 qPos.add(uuid);
824 }
825
826 qPos.add(groupId);
827
828 count = (Long)q.uniqueResult();
829
830 FinderCacheUtil.putResult(finderPath, finderArgs, count);
831 }
832 catch (Exception e) {
833 FinderCacheUtil.removeResult(finderPath, finderArgs);
834
835 throw processException(e);
836 }
837 finally {
838 closeSession(session);
839 }
840 }
841
842 return count.intValue();
843 }
844
845 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmContent.uuid IS NULL AND ";
846 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmContent.uuid = ? AND ";
847 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?) AND ";
848 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmContent.groupId = ?";
849 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
850 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
851 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
852 new String[] {
853 String.class.getName(), Long.class.getName(),
854
855 Integer.class.getName(), Integer.class.getName(),
856 OrderByComparator.class.getName()
857 });
858 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
859 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
860 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
861 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
862 new String[] { String.class.getName(), Long.class.getName() },
863 DDMContentModelImpl.UUID_COLUMN_BITMASK |
864 DDMContentModelImpl.COMPANYID_COLUMN_BITMASK);
865 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
866 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
867 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
868 new String[] { String.class.getName(), Long.class.getName() });
869
870
878 public List<DDMContent> findByUuid_C(String uuid, long companyId)
879 throws SystemException {
880 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
881 QueryUtil.ALL_POS, null);
882 }
883
884
898 public List<DDMContent> findByUuid_C(String uuid, long companyId,
899 int start, int end) throws SystemException {
900 return findByUuid_C(uuid, companyId, start, end, null);
901 }
902
903
918 public List<DDMContent> findByUuid_C(String uuid, long companyId,
919 int start, int end, OrderByComparator orderByComparator)
920 throws SystemException {
921 boolean pagination = true;
922 FinderPath finderPath = null;
923 Object[] finderArgs = null;
924
925 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
926 (orderByComparator == null)) {
927 pagination = false;
928 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
929 finderArgs = new Object[] { uuid, companyId };
930 }
931 else {
932 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
933 finderArgs = new Object[] {
934 uuid, companyId,
935
936 start, end, orderByComparator
937 };
938 }
939
940 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
941 finderArgs, this);
942
943 if ((list != null) && !list.isEmpty()) {
944 for (DDMContent ddmContent : list) {
945 if (!Validator.equals(uuid, ddmContent.getUuid()) ||
946 (companyId != ddmContent.getCompanyId())) {
947 list = null;
948
949 break;
950 }
951 }
952 }
953
954 if (list == null) {
955 StringBundler query = null;
956
957 if (orderByComparator != null) {
958 query = new StringBundler(4 +
959 (orderByComparator.getOrderByFields().length * 3));
960 }
961 else {
962 query = new StringBundler(4);
963 }
964
965 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
966
967 if (uuid == null) {
968 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
969 }
970 else {
971 if (uuid.equals(StringPool.BLANK)) {
972 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
973 }
974 else {
975 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
976 }
977 }
978
979 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
980
981 if (orderByComparator != null) {
982 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
983 orderByComparator);
984 }
985 else
986 if (pagination) {
987 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
988 }
989
990 String sql = query.toString();
991
992 Session session = null;
993
994 try {
995 session = openSession();
996
997 Query q = session.createQuery(sql);
998
999 QueryPos qPos = QueryPos.getInstance(q);
1000
1001 if (uuid != null) {
1002 qPos.add(uuid);
1003 }
1004
1005 qPos.add(companyId);
1006
1007 if (!pagination) {
1008 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1009 start, end, false);
1010
1011 Collections.sort(list);
1012
1013 list = new UnmodifiableList<DDMContent>(list);
1014 }
1015 else {
1016 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1017 start, end);
1018 }
1019
1020 cacheResult(list);
1021
1022 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1023 }
1024 catch (Exception e) {
1025 FinderCacheUtil.removeResult(finderPath, finderArgs);
1026
1027 throw processException(e);
1028 }
1029 finally {
1030 closeSession(session);
1031 }
1032 }
1033
1034 return list;
1035 }
1036
1037
1047 public DDMContent findByUuid_C_First(String uuid, long companyId,
1048 OrderByComparator orderByComparator)
1049 throws NoSuchContentException, SystemException {
1050 DDMContent ddmContent = fetchByUuid_C_First(uuid, companyId,
1051 orderByComparator);
1052
1053 if (ddmContent != null) {
1054 return ddmContent;
1055 }
1056
1057 StringBundler msg = new StringBundler(6);
1058
1059 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1060
1061 msg.append("uuid=");
1062 msg.append(uuid);
1063
1064 msg.append(", companyId=");
1065 msg.append(companyId);
1066
1067 msg.append(StringPool.CLOSE_CURLY_BRACE);
1068
1069 throw new NoSuchContentException(msg.toString());
1070 }
1071
1072
1081 public DDMContent fetchByUuid_C_First(String uuid, long companyId,
1082 OrderByComparator orderByComparator) throws SystemException {
1083 List<DDMContent> list = findByUuid_C(uuid, companyId, 0, 1,
1084 orderByComparator);
1085
1086 if (!list.isEmpty()) {
1087 return list.get(0);
1088 }
1089
1090 return null;
1091 }
1092
1093
1103 public DDMContent findByUuid_C_Last(String uuid, long companyId,
1104 OrderByComparator orderByComparator)
1105 throws NoSuchContentException, SystemException {
1106 DDMContent ddmContent = fetchByUuid_C_Last(uuid, companyId,
1107 orderByComparator);
1108
1109 if (ddmContent != null) {
1110 return ddmContent;
1111 }
1112
1113 StringBundler msg = new StringBundler(6);
1114
1115 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1116
1117 msg.append("uuid=");
1118 msg.append(uuid);
1119
1120 msg.append(", companyId=");
1121 msg.append(companyId);
1122
1123 msg.append(StringPool.CLOSE_CURLY_BRACE);
1124
1125 throw new NoSuchContentException(msg.toString());
1126 }
1127
1128
1137 public DDMContent fetchByUuid_C_Last(String uuid, long companyId,
1138 OrderByComparator orderByComparator) throws SystemException {
1139 int count = countByUuid_C(uuid, companyId);
1140
1141 List<DDMContent> list = findByUuid_C(uuid, companyId, count - 1, count,
1142 orderByComparator);
1143
1144 if (!list.isEmpty()) {
1145 return list.get(0);
1146 }
1147
1148 return null;
1149 }
1150
1151
1162 public DDMContent[] findByUuid_C_PrevAndNext(long contentId, String uuid,
1163 long companyId, OrderByComparator orderByComparator)
1164 throws NoSuchContentException, SystemException {
1165 DDMContent ddmContent = findByPrimaryKey(contentId);
1166
1167 Session session = null;
1168
1169 try {
1170 session = openSession();
1171
1172 DDMContent[] array = new DDMContentImpl[3];
1173
1174 array[0] = getByUuid_C_PrevAndNext(session, ddmContent, uuid,
1175 companyId, orderByComparator, true);
1176
1177 array[1] = ddmContent;
1178
1179 array[2] = getByUuid_C_PrevAndNext(session, ddmContent, uuid,
1180 companyId, orderByComparator, false);
1181
1182 return array;
1183 }
1184 catch (Exception e) {
1185 throw processException(e);
1186 }
1187 finally {
1188 closeSession(session);
1189 }
1190 }
1191
1192 protected DDMContent getByUuid_C_PrevAndNext(Session session,
1193 DDMContent ddmContent, String uuid, long companyId,
1194 OrderByComparator orderByComparator, boolean previous) {
1195 StringBundler query = null;
1196
1197 if (orderByComparator != null) {
1198 query = new StringBundler(6 +
1199 (orderByComparator.getOrderByFields().length * 6));
1200 }
1201 else {
1202 query = new StringBundler(3);
1203 }
1204
1205 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1206
1207 if (uuid == null) {
1208 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1209 }
1210 else {
1211 if (uuid.equals(StringPool.BLANK)) {
1212 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1213 }
1214 else {
1215 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1216 }
1217 }
1218
1219 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1220
1221 if (orderByComparator != null) {
1222 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1223
1224 if (orderByConditionFields.length > 0) {
1225 query.append(WHERE_AND);
1226 }
1227
1228 for (int i = 0; i < orderByConditionFields.length; i++) {
1229 query.append(_ORDER_BY_ENTITY_ALIAS);
1230 query.append(orderByConditionFields[i]);
1231
1232 if ((i + 1) < orderByConditionFields.length) {
1233 if (orderByComparator.isAscending() ^ previous) {
1234 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1235 }
1236 else {
1237 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1238 }
1239 }
1240 else {
1241 if (orderByComparator.isAscending() ^ previous) {
1242 query.append(WHERE_GREATER_THAN);
1243 }
1244 else {
1245 query.append(WHERE_LESSER_THAN);
1246 }
1247 }
1248 }
1249
1250 query.append(ORDER_BY_CLAUSE);
1251
1252 String[] orderByFields = orderByComparator.getOrderByFields();
1253
1254 for (int i = 0; i < orderByFields.length; i++) {
1255 query.append(_ORDER_BY_ENTITY_ALIAS);
1256 query.append(orderByFields[i]);
1257
1258 if ((i + 1) < orderByFields.length) {
1259 if (orderByComparator.isAscending() ^ previous) {
1260 query.append(ORDER_BY_ASC_HAS_NEXT);
1261 }
1262 else {
1263 query.append(ORDER_BY_DESC_HAS_NEXT);
1264 }
1265 }
1266 else {
1267 if (orderByComparator.isAscending() ^ previous) {
1268 query.append(ORDER_BY_ASC);
1269 }
1270 else {
1271 query.append(ORDER_BY_DESC);
1272 }
1273 }
1274 }
1275 }
1276 else {
1277 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
1278 }
1279
1280 String sql = query.toString();
1281
1282 Query q = session.createQuery(sql);
1283
1284 q.setFirstResult(0);
1285 q.setMaxResults(2);
1286
1287 QueryPos qPos = QueryPos.getInstance(q);
1288
1289 if (uuid != null) {
1290 qPos.add(uuid);
1291 }
1292
1293 qPos.add(companyId);
1294
1295 if (orderByComparator != null) {
1296 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1297
1298 for (Object value : values) {
1299 qPos.add(value);
1300 }
1301 }
1302
1303 List<DDMContent> list = q.list();
1304
1305 if (list.size() == 2) {
1306 return list.get(1);
1307 }
1308 else {
1309 return null;
1310 }
1311 }
1312
1313
1320 public void removeByUuid_C(String uuid, long companyId)
1321 throws SystemException {
1322 for (DDMContent ddmContent : findByUuid_C(uuid, companyId,
1323 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1324 remove(ddmContent);
1325 }
1326 }
1327
1328
1336 public int countByUuid_C(String uuid, long companyId)
1337 throws SystemException {
1338 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1339
1340 Object[] finderArgs = new Object[] { uuid, companyId };
1341
1342 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1343 this);
1344
1345 if (count == null) {
1346 StringBundler query = new StringBundler(3);
1347
1348 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
1349
1350 if (uuid == null) {
1351 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1352 }
1353 else {
1354 if (uuid.equals(StringPool.BLANK)) {
1355 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1356 }
1357 else {
1358 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1359 }
1360 }
1361
1362 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1363
1364 String sql = query.toString();
1365
1366 Session session = null;
1367
1368 try {
1369 session = openSession();
1370
1371 Query q = session.createQuery(sql);
1372
1373 QueryPos qPos = QueryPos.getInstance(q);
1374
1375 if (uuid != null) {
1376 qPos.add(uuid);
1377 }
1378
1379 qPos.add(companyId);
1380
1381 count = (Long)q.uniqueResult();
1382
1383 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1384 }
1385 catch (Exception e) {
1386 FinderCacheUtil.removeResult(finderPath, finderArgs);
1387
1388 throw processException(e);
1389 }
1390 finally {
1391 closeSession(session);
1392 }
1393 }
1394
1395 return count.intValue();
1396 }
1397
1398 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmContent.uuid IS NULL AND ";
1399 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmContent.uuid = ? AND ";
1400 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?) AND ";
1401 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmContent.companyId = ?";
1402 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1403 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
1404 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1405 new String[] {
1406 Long.class.getName(),
1407
1408 Integer.class.getName(), Integer.class.getName(),
1409 OrderByComparator.class.getName()
1410 });
1411 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1412 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1413 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
1414 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1415 new String[] { Long.class.getName() },
1416 DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
1417 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1418 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
1419 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1420 new String[] { Long.class.getName() });
1421
1422
1429 public List<DDMContent> findByGroupId(long groupId)
1430 throws SystemException {
1431 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1432 }
1433
1434
1447 public List<DDMContent> findByGroupId(long groupId, int start, int end)
1448 throws SystemException {
1449 return findByGroupId(groupId, start, end, null);
1450 }
1451
1452
1466 public List<DDMContent> findByGroupId(long groupId, int start, int end,
1467 OrderByComparator orderByComparator) throws SystemException {
1468 boolean pagination = true;
1469 FinderPath finderPath = null;
1470 Object[] finderArgs = null;
1471
1472 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1473 (orderByComparator == null)) {
1474 pagination = false;
1475 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1476 finderArgs = new Object[] { groupId };
1477 }
1478 else {
1479 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1480 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1481 }
1482
1483 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1484 finderArgs, this);
1485
1486 if ((list != null) && !list.isEmpty()) {
1487 for (DDMContent ddmContent : list) {
1488 if ((groupId != ddmContent.getGroupId())) {
1489 list = null;
1490
1491 break;
1492 }
1493 }
1494 }
1495
1496 if (list == null) {
1497 StringBundler query = null;
1498
1499 if (orderByComparator != null) {
1500 query = new StringBundler(3 +
1501 (orderByComparator.getOrderByFields().length * 3));
1502 }
1503 else {
1504 query = new StringBundler(3);
1505 }
1506
1507 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1508
1509 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1510
1511 if (orderByComparator != null) {
1512 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1513 orderByComparator);
1514 }
1515 else
1516 if (pagination) {
1517 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
1518 }
1519
1520 String sql = query.toString();
1521
1522 Session session = null;
1523
1524 try {
1525 session = openSession();
1526
1527 Query q = session.createQuery(sql);
1528
1529 QueryPos qPos = QueryPos.getInstance(q);
1530
1531 qPos.add(groupId);
1532
1533 if (!pagination) {
1534 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1535 start, end, false);
1536
1537 Collections.sort(list);
1538
1539 list = new UnmodifiableList<DDMContent>(list);
1540 }
1541 else {
1542 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1543 start, end);
1544 }
1545
1546 cacheResult(list);
1547
1548 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1549 }
1550 catch (Exception e) {
1551 FinderCacheUtil.removeResult(finderPath, finderArgs);
1552
1553 throw processException(e);
1554 }
1555 finally {
1556 closeSession(session);
1557 }
1558 }
1559
1560 return list;
1561 }
1562
1563
1572 public DDMContent findByGroupId_First(long groupId,
1573 OrderByComparator orderByComparator)
1574 throws NoSuchContentException, SystemException {
1575 DDMContent ddmContent = fetchByGroupId_First(groupId, orderByComparator);
1576
1577 if (ddmContent != null) {
1578 return ddmContent;
1579 }
1580
1581 StringBundler msg = new StringBundler(4);
1582
1583 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1584
1585 msg.append("groupId=");
1586 msg.append(groupId);
1587
1588 msg.append(StringPool.CLOSE_CURLY_BRACE);
1589
1590 throw new NoSuchContentException(msg.toString());
1591 }
1592
1593
1601 public DDMContent fetchByGroupId_First(long groupId,
1602 OrderByComparator orderByComparator) throws SystemException {
1603 List<DDMContent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1604
1605 if (!list.isEmpty()) {
1606 return list.get(0);
1607 }
1608
1609 return null;
1610 }
1611
1612
1621 public DDMContent findByGroupId_Last(long groupId,
1622 OrderByComparator orderByComparator)
1623 throws NoSuchContentException, SystemException {
1624 DDMContent ddmContent = fetchByGroupId_Last(groupId, orderByComparator);
1625
1626 if (ddmContent != null) {
1627 return ddmContent;
1628 }
1629
1630 StringBundler msg = new StringBundler(4);
1631
1632 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1633
1634 msg.append("groupId=");
1635 msg.append(groupId);
1636
1637 msg.append(StringPool.CLOSE_CURLY_BRACE);
1638
1639 throw new NoSuchContentException(msg.toString());
1640 }
1641
1642
1650 public DDMContent fetchByGroupId_Last(long groupId,
1651 OrderByComparator orderByComparator) throws SystemException {
1652 int count = countByGroupId(groupId);
1653
1654 List<DDMContent> list = findByGroupId(groupId, count - 1, count,
1655 orderByComparator);
1656
1657 if (!list.isEmpty()) {
1658 return list.get(0);
1659 }
1660
1661 return null;
1662 }
1663
1664
1674 public DDMContent[] findByGroupId_PrevAndNext(long contentId, long groupId,
1675 OrderByComparator orderByComparator)
1676 throws NoSuchContentException, SystemException {
1677 DDMContent ddmContent = findByPrimaryKey(contentId);
1678
1679 Session session = null;
1680
1681 try {
1682 session = openSession();
1683
1684 DDMContent[] array = new DDMContentImpl[3];
1685
1686 array[0] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1687 orderByComparator, true);
1688
1689 array[1] = ddmContent;
1690
1691 array[2] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1692 orderByComparator, false);
1693
1694 return array;
1695 }
1696 catch (Exception e) {
1697 throw processException(e);
1698 }
1699 finally {
1700 closeSession(session);
1701 }
1702 }
1703
1704 protected DDMContent getByGroupId_PrevAndNext(Session session,
1705 DDMContent ddmContent, long groupId,
1706 OrderByComparator orderByComparator, boolean previous) {
1707 StringBundler query = null;
1708
1709 if (orderByComparator != null) {
1710 query = new StringBundler(6 +
1711 (orderByComparator.getOrderByFields().length * 6));
1712 }
1713 else {
1714 query = new StringBundler(3);
1715 }
1716
1717 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1718
1719 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1720
1721 if (orderByComparator != null) {
1722 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1723
1724 if (orderByConditionFields.length > 0) {
1725 query.append(WHERE_AND);
1726 }
1727
1728 for (int i = 0; i < orderByConditionFields.length; i++) {
1729 query.append(_ORDER_BY_ENTITY_ALIAS);
1730 query.append(orderByConditionFields[i]);
1731
1732 if ((i + 1) < orderByConditionFields.length) {
1733 if (orderByComparator.isAscending() ^ previous) {
1734 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1735 }
1736 else {
1737 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1738 }
1739 }
1740 else {
1741 if (orderByComparator.isAscending() ^ previous) {
1742 query.append(WHERE_GREATER_THAN);
1743 }
1744 else {
1745 query.append(WHERE_LESSER_THAN);
1746 }
1747 }
1748 }
1749
1750 query.append(ORDER_BY_CLAUSE);
1751
1752 String[] orderByFields = orderByComparator.getOrderByFields();
1753
1754 for (int i = 0; i < orderByFields.length; i++) {
1755 query.append(_ORDER_BY_ENTITY_ALIAS);
1756 query.append(orderByFields[i]);
1757
1758 if ((i + 1) < orderByFields.length) {
1759 if (orderByComparator.isAscending() ^ previous) {
1760 query.append(ORDER_BY_ASC_HAS_NEXT);
1761 }
1762 else {
1763 query.append(ORDER_BY_DESC_HAS_NEXT);
1764 }
1765 }
1766 else {
1767 if (orderByComparator.isAscending() ^ previous) {
1768 query.append(ORDER_BY_ASC);
1769 }
1770 else {
1771 query.append(ORDER_BY_DESC);
1772 }
1773 }
1774 }
1775 }
1776 else {
1777 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
1778 }
1779
1780 String sql = query.toString();
1781
1782 Query q = session.createQuery(sql);
1783
1784 q.setFirstResult(0);
1785 q.setMaxResults(2);
1786
1787 QueryPos qPos = QueryPos.getInstance(q);
1788
1789 qPos.add(groupId);
1790
1791 if (orderByComparator != null) {
1792 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1793
1794 for (Object value : values) {
1795 qPos.add(value);
1796 }
1797 }
1798
1799 List<DDMContent> list = q.list();
1800
1801 if (list.size() == 2) {
1802 return list.get(1);
1803 }
1804 else {
1805 return null;
1806 }
1807 }
1808
1809
1815 public void removeByGroupId(long groupId) throws SystemException {
1816 for (DDMContent ddmContent : findByGroupId(groupId, QueryUtil.ALL_POS,
1817 QueryUtil.ALL_POS, null)) {
1818 remove(ddmContent);
1819 }
1820 }
1821
1822
1829 public int countByGroupId(long groupId) throws SystemException {
1830 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
1831
1832 Object[] finderArgs = new Object[] { groupId };
1833
1834 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1835 this);
1836
1837 if (count == null) {
1838 StringBundler query = new StringBundler(2);
1839
1840 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
1841
1842 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1843
1844 String sql = query.toString();
1845
1846 Session session = null;
1847
1848 try {
1849 session = openSession();
1850
1851 Query q = session.createQuery(sql);
1852
1853 QueryPos qPos = QueryPos.getInstance(q);
1854
1855 qPos.add(groupId);
1856
1857 count = (Long)q.uniqueResult();
1858
1859 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1860 }
1861 catch (Exception e) {
1862 FinderCacheUtil.removeResult(finderPath, finderArgs);
1863
1864 throw processException(e);
1865 }
1866 finally {
1867 closeSession(session);
1868 }
1869 }
1870
1871 return count.intValue();
1872 }
1873
1874 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmContent.groupId = ?";
1875 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1876 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1877 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
1878 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1879 new String[] {
1880 Long.class.getName(),
1881
1882 Integer.class.getName(), Integer.class.getName(),
1883 OrderByComparator.class.getName()
1884 });
1885 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1886 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1887 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
1888 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1889 new String[] { Long.class.getName() },
1890 DDMContentModelImpl.COMPANYID_COLUMN_BITMASK);
1891 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
1892 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
1893 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1894 new String[] { Long.class.getName() });
1895
1896
1903 public List<DDMContent> findByCompanyId(long companyId)
1904 throws SystemException {
1905 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1906 null);
1907 }
1908
1909
1922 public List<DDMContent> findByCompanyId(long companyId, int start, int end)
1923 throws SystemException {
1924 return findByCompanyId(companyId, start, end, null);
1925 }
1926
1927
1941 public List<DDMContent> findByCompanyId(long companyId, int start, int end,
1942 OrderByComparator orderByComparator) throws SystemException {
1943 boolean pagination = true;
1944 FinderPath finderPath = null;
1945 Object[] finderArgs = null;
1946
1947 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1948 (orderByComparator == null)) {
1949 pagination = false;
1950 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1951 finderArgs = new Object[] { companyId };
1952 }
1953 else {
1954 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1955 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1956 }
1957
1958 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1959 finderArgs, this);
1960
1961 if ((list != null) && !list.isEmpty()) {
1962 for (DDMContent ddmContent : list) {
1963 if ((companyId != ddmContent.getCompanyId())) {
1964 list = null;
1965
1966 break;
1967 }
1968 }
1969 }
1970
1971 if (list == null) {
1972 StringBundler query = null;
1973
1974 if (orderByComparator != null) {
1975 query = new StringBundler(3 +
1976 (orderByComparator.getOrderByFields().length * 3));
1977 }
1978 else {
1979 query = new StringBundler(3);
1980 }
1981
1982 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1983
1984 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1985
1986 if (orderByComparator != null) {
1987 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1988 orderByComparator);
1989 }
1990 else
1991 if (pagination) {
1992 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
1993 }
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(companyId);
2007
2008 if (!pagination) {
2009 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2010 start, end, false);
2011
2012 Collections.sort(list);
2013
2014 list = new UnmodifiableList<DDMContent>(list);
2015 }
2016 else {
2017 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2018 start, end);
2019 }
2020
2021 cacheResult(list);
2022
2023 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2024 }
2025 catch (Exception e) {
2026 FinderCacheUtil.removeResult(finderPath, finderArgs);
2027
2028 throw processException(e);
2029 }
2030 finally {
2031 closeSession(session);
2032 }
2033 }
2034
2035 return list;
2036 }
2037
2038
2047 public DDMContent findByCompanyId_First(long companyId,
2048 OrderByComparator orderByComparator)
2049 throws NoSuchContentException, SystemException {
2050 DDMContent ddmContent = fetchByCompanyId_First(companyId,
2051 orderByComparator);
2052
2053 if (ddmContent != null) {
2054 return ddmContent;
2055 }
2056
2057 StringBundler msg = new StringBundler(4);
2058
2059 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2060
2061 msg.append("companyId=");
2062 msg.append(companyId);
2063
2064 msg.append(StringPool.CLOSE_CURLY_BRACE);
2065
2066 throw new NoSuchContentException(msg.toString());
2067 }
2068
2069
2077 public DDMContent fetchByCompanyId_First(long companyId,
2078 OrderByComparator orderByComparator) throws SystemException {
2079 List<DDMContent> list = findByCompanyId(companyId, 0, 1,
2080 orderByComparator);
2081
2082 if (!list.isEmpty()) {
2083 return list.get(0);
2084 }
2085
2086 return null;
2087 }
2088
2089
2098 public DDMContent findByCompanyId_Last(long companyId,
2099 OrderByComparator orderByComparator)
2100 throws NoSuchContentException, SystemException {
2101 DDMContent ddmContent = fetchByCompanyId_Last(companyId,
2102 orderByComparator);
2103
2104 if (ddmContent != null) {
2105 return ddmContent;
2106 }
2107
2108 StringBundler msg = new StringBundler(4);
2109
2110 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2111
2112 msg.append("companyId=");
2113 msg.append(companyId);
2114
2115 msg.append(StringPool.CLOSE_CURLY_BRACE);
2116
2117 throw new NoSuchContentException(msg.toString());
2118 }
2119
2120
2128 public DDMContent fetchByCompanyId_Last(long companyId,
2129 OrderByComparator orderByComparator) throws SystemException {
2130 int count = countByCompanyId(companyId);
2131
2132 List<DDMContent> list = findByCompanyId(companyId, count - 1, count,
2133 orderByComparator);
2134
2135 if (!list.isEmpty()) {
2136 return list.get(0);
2137 }
2138
2139 return null;
2140 }
2141
2142
2152 public DDMContent[] findByCompanyId_PrevAndNext(long contentId,
2153 long companyId, OrderByComparator orderByComparator)
2154 throws NoSuchContentException, SystemException {
2155 DDMContent ddmContent = findByPrimaryKey(contentId);
2156
2157 Session session = null;
2158
2159 try {
2160 session = openSession();
2161
2162 DDMContent[] array = new DDMContentImpl[3];
2163
2164 array[0] = getByCompanyId_PrevAndNext(session, ddmContent,
2165 companyId, orderByComparator, true);
2166
2167 array[1] = ddmContent;
2168
2169 array[2] = getByCompanyId_PrevAndNext(session, ddmContent,
2170 companyId, orderByComparator, false);
2171
2172 return array;
2173 }
2174 catch (Exception e) {
2175 throw processException(e);
2176 }
2177 finally {
2178 closeSession(session);
2179 }
2180 }
2181
2182 protected DDMContent getByCompanyId_PrevAndNext(Session session,
2183 DDMContent ddmContent, long companyId,
2184 OrderByComparator orderByComparator, boolean previous) {
2185 StringBundler query = null;
2186
2187 if (orderByComparator != null) {
2188 query = new StringBundler(6 +
2189 (orderByComparator.getOrderByFields().length * 6));
2190 }
2191 else {
2192 query = new StringBundler(3);
2193 }
2194
2195 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
2196
2197 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2198
2199 if (orderByComparator != null) {
2200 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2201
2202 if (orderByConditionFields.length > 0) {
2203 query.append(WHERE_AND);
2204 }
2205
2206 for (int i = 0; i < orderByConditionFields.length; i++) {
2207 query.append(_ORDER_BY_ENTITY_ALIAS);
2208 query.append(orderByConditionFields[i]);
2209
2210 if ((i + 1) < orderByConditionFields.length) {
2211 if (orderByComparator.isAscending() ^ previous) {
2212 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2213 }
2214 else {
2215 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2216 }
2217 }
2218 else {
2219 if (orderByComparator.isAscending() ^ previous) {
2220 query.append(WHERE_GREATER_THAN);
2221 }
2222 else {
2223 query.append(WHERE_LESSER_THAN);
2224 }
2225 }
2226 }
2227
2228 query.append(ORDER_BY_CLAUSE);
2229
2230 String[] orderByFields = orderByComparator.getOrderByFields();
2231
2232 for (int i = 0; i < orderByFields.length; i++) {
2233 query.append(_ORDER_BY_ENTITY_ALIAS);
2234 query.append(orderByFields[i]);
2235
2236 if ((i + 1) < orderByFields.length) {
2237 if (orderByComparator.isAscending() ^ previous) {
2238 query.append(ORDER_BY_ASC_HAS_NEXT);
2239 }
2240 else {
2241 query.append(ORDER_BY_DESC_HAS_NEXT);
2242 }
2243 }
2244 else {
2245 if (orderByComparator.isAscending() ^ previous) {
2246 query.append(ORDER_BY_ASC);
2247 }
2248 else {
2249 query.append(ORDER_BY_DESC);
2250 }
2251 }
2252 }
2253 }
2254 else {
2255 query.append(DDMContentModelImpl.ORDER_BY_JPQL);
2256 }
2257
2258 String sql = query.toString();
2259
2260 Query q = session.createQuery(sql);
2261
2262 q.setFirstResult(0);
2263 q.setMaxResults(2);
2264
2265 QueryPos qPos = QueryPos.getInstance(q);
2266
2267 qPos.add(companyId);
2268
2269 if (orderByComparator != null) {
2270 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
2271
2272 for (Object value : values) {
2273 qPos.add(value);
2274 }
2275 }
2276
2277 List<DDMContent> list = q.list();
2278
2279 if (list.size() == 2) {
2280 return list.get(1);
2281 }
2282 else {
2283 return null;
2284 }
2285 }
2286
2287
2293 public void removeByCompanyId(long companyId) throws SystemException {
2294 for (DDMContent ddmContent : findByCompanyId(companyId,
2295 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2296 remove(ddmContent);
2297 }
2298 }
2299
2300
2307 public int countByCompanyId(long companyId) throws SystemException {
2308 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2309
2310 Object[] finderArgs = new Object[] { companyId };
2311
2312 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2313 this);
2314
2315 if (count == null) {
2316 StringBundler query = new StringBundler(2);
2317
2318 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2319
2320 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2321
2322 String sql = query.toString();
2323
2324 Session session = null;
2325
2326 try {
2327 session = openSession();
2328
2329 Query q = session.createQuery(sql);
2330
2331 QueryPos qPos = QueryPos.getInstance(q);
2332
2333 qPos.add(companyId);
2334
2335 count = (Long)q.uniqueResult();
2336
2337 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2338 }
2339 catch (Exception e) {
2340 FinderCacheUtil.removeResult(finderPath, finderArgs);
2341
2342 throw processException(e);
2343 }
2344 finally {
2345 closeSession(session);
2346 }
2347 }
2348
2349 return count.intValue();
2350 }
2351
2352 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "ddmContent.companyId = ?";
2353
2354
2359 public void cacheResult(DDMContent ddmContent) {
2360 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2361 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
2362
2363 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2364 new Object[] {
2365 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
2366 }, ddmContent);
2367
2368 ddmContent.resetOriginalValues();
2369 }
2370
2371
2376 public void cacheResult(List<DDMContent> ddmContents) {
2377 for (DDMContent ddmContent : ddmContents) {
2378 if (EntityCacheUtil.getResult(
2379 DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2380 DDMContentImpl.class, ddmContent.getPrimaryKey()) == null) {
2381 cacheResult(ddmContent);
2382 }
2383 else {
2384 ddmContent.resetOriginalValues();
2385 }
2386 }
2387 }
2388
2389
2396 @Override
2397 public void clearCache() {
2398 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2399 CacheRegistryUtil.clear(DDMContentImpl.class.getName());
2400 }
2401
2402 EntityCacheUtil.clearCache(DDMContentImpl.class.getName());
2403
2404 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2405 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2406 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2407 }
2408
2409
2416 @Override
2417 public void clearCache(DDMContent ddmContent) {
2418 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2419 DDMContentImpl.class, ddmContent.getPrimaryKey());
2420
2421 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2422 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2423
2424 clearUniqueFindersCache(ddmContent);
2425 }
2426
2427 @Override
2428 public void clearCache(List<DDMContent> ddmContents) {
2429 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2430 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2431
2432 for (DDMContent ddmContent : ddmContents) {
2433 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2434 DDMContentImpl.class, ddmContent.getPrimaryKey());
2435
2436 clearUniqueFindersCache(ddmContent);
2437 }
2438 }
2439
2440 protected void cacheUniqueFindersCache(DDMContent ddmContent) {
2441 if (ddmContent.isNew()) {
2442 Object[] args = new Object[] {
2443 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
2444 };
2445
2446 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2447 Long.valueOf(1));
2448 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2449 ddmContent);
2450 }
2451 else {
2452 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
2453
2454 if ((ddmContentModelImpl.getColumnBitmask() &
2455 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2456 Object[] args = new Object[] {
2457 ddmContent.getUuid(),
2458 Long.valueOf(ddmContent.getGroupId())
2459 };
2460
2461 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2462 Long.valueOf(1));
2463 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2464 ddmContent);
2465 }
2466 }
2467 }
2468
2469 protected void clearUniqueFindersCache(DDMContent ddmContent) {
2470 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
2471
2472 Object[] args = new Object[] {
2473 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
2474 };
2475
2476 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2477 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2478
2479 if ((ddmContentModelImpl.getColumnBitmask() &
2480 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2481 args = new Object[] {
2482 ddmContentModelImpl.getOriginalUuid(),
2483 Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
2484 };
2485
2486 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2487 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2488 }
2489 }
2490
2491
2497 public DDMContent create(long contentId) {
2498 DDMContent ddmContent = new DDMContentImpl();
2499
2500 ddmContent.setNew(true);
2501 ddmContent.setPrimaryKey(contentId);
2502
2503 String uuid = PortalUUIDUtil.generate();
2504
2505 ddmContent.setUuid(uuid);
2506
2507 return ddmContent;
2508 }
2509
2510
2518 public DDMContent remove(long contentId)
2519 throws NoSuchContentException, SystemException {
2520 return remove(Long.valueOf(contentId));
2521 }
2522
2523
2531 @Override
2532 public DDMContent remove(Serializable primaryKey)
2533 throws NoSuchContentException, SystemException {
2534 Session session = null;
2535
2536 try {
2537 session = openSession();
2538
2539 DDMContent ddmContent = (DDMContent)session.get(DDMContentImpl.class,
2540 primaryKey);
2541
2542 if (ddmContent == null) {
2543 if (_log.isWarnEnabled()) {
2544 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2545 }
2546
2547 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2548 primaryKey);
2549 }
2550
2551 return remove(ddmContent);
2552 }
2553 catch (NoSuchContentException nsee) {
2554 throw nsee;
2555 }
2556 catch (Exception e) {
2557 throw processException(e);
2558 }
2559 finally {
2560 closeSession(session);
2561 }
2562 }
2563
2564 @Override
2565 protected DDMContent removeImpl(DDMContent ddmContent)
2566 throws SystemException {
2567 ddmContent = toUnwrappedModel(ddmContent);
2568
2569 Session session = null;
2570
2571 try {
2572 session = openSession();
2573
2574 if (!session.contains(ddmContent)) {
2575 ddmContent = (DDMContent)session.get(DDMContentImpl.class,
2576 ddmContent.getPrimaryKeyObj());
2577 }
2578
2579 if (ddmContent != null) {
2580 session.delete(ddmContent);
2581 }
2582 }
2583 catch (Exception e) {
2584 throw processException(e);
2585 }
2586 finally {
2587 closeSession(session);
2588 }
2589
2590 if (ddmContent != null) {
2591 clearCache(ddmContent);
2592 }
2593
2594 return ddmContent;
2595 }
2596
2597 @Override
2598 public DDMContent updateImpl(
2599 com.liferay.portlet.dynamicdatamapping.model.DDMContent ddmContent)
2600 throws SystemException {
2601 ddmContent = toUnwrappedModel(ddmContent);
2602
2603 boolean isNew = ddmContent.isNew();
2604
2605 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
2606
2607 if (Validator.isNull(ddmContent.getUuid())) {
2608 String uuid = PortalUUIDUtil.generate();
2609
2610 ddmContent.setUuid(uuid);
2611 }
2612
2613 Session session = null;
2614
2615 try {
2616 session = openSession();
2617
2618 if (ddmContent.isNew()) {
2619 session.save(ddmContent);
2620
2621 ddmContent.setNew(false);
2622 }
2623 else {
2624 session.merge(ddmContent);
2625 }
2626 }
2627 catch (Exception e) {
2628 throw processException(e);
2629 }
2630 finally {
2631 closeSession(session);
2632 }
2633
2634 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2635
2636 if (isNew || !DDMContentModelImpl.COLUMN_BITMASK_ENABLED) {
2637 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2638 }
2639
2640 else {
2641 if ((ddmContentModelImpl.getColumnBitmask() &
2642 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2643 Object[] args = new Object[] {
2644 ddmContentModelImpl.getOriginalUuid()
2645 };
2646
2647 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2648 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2649 args);
2650
2651 args = new Object[] { ddmContentModelImpl.getUuid() };
2652
2653 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2654 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2655 args);
2656 }
2657
2658 if ((ddmContentModelImpl.getColumnBitmask() &
2659 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2660 Object[] args = new Object[] {
2661 ddmContentModelImpl.getOriginalUuid(),
2662 Long.valueOf(ddmContentModelImpl.getOriginalCompanyId())
2663 };
2664
2665 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2666 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2667 args);
2668
2669 args = new Object[] {
2670 ddmContentModelImpl.getUuid(),
2671 Long.valueOf(ddmContentModelImpl.getCompanyId())
2672 };
2673
2674 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2675 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2676 args);
2677 }
2678
2679 if ((ddmContentModelImpl.getColumnBitmask() &
2680 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2681 Object[] args = new Object[] {
2682 Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
2683 };
2684
2685 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2686 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2687 args);
2688
2689 args = new Object[] {
2690 Long.valueOf(ddmContentModelImpl.getGroupId())
2691 };
2692
2693 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2694 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2695 args);
2696 }
2697
2698 if ((ddmContentModelImpl.getColumnBitmask() &
2699 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2700 Object[] args = new Object[] {
2701 Long.valueOf(ddmContentModelImpl.getOriginalCompanyId())
2702 };
2703
2704 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2705 args);
2706 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2707 args);
2708
2709 args = new Object[] {
2710 Long.valueOf(ddmContentModelImpl.getCompanyId())
2711 };
2712
2713 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2714 args);
2715 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2716 args);
2717 }
2718 }
2719
2720 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2721 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
2722
2723 clearUniqueFindersCache(ddmContent);
2724 cacheUniqueFindersCache(ddmContent);
2725
2726 return ddmContent;
2727 }
2728
2729 protected DDMContent toUnwrappedModel(DDMContent ddmContent) {
2730 if (ddmContent instanceof DDMContentImpl) {
2731 return ddmContent;
2732 }
2733
2734 DDMContentImpl ddmContentImpl = new DDMContentImpl();
2735
2736 ddmContentImpl.setNew(ddmContent.isNew());
2737 ddmContentImpl.setPrimaryKey(ddmContent.getPrimaryKey());
2738
2739 ddmContentImpl.setUuid(ddmContent.getUuid());
2740 ddmContentImpl.setContentId(ddmContent.getContentId());
2741 ddmContentImpl.setGroupId(ddmContent.getGroupId());
2742 ddmContentImpl.setCompanyId(ddmContent.getCompanyId());
2743 ddmContentImpl.setUserId(ddmContent.getUserId());
2744 ddmContentImpl.setUserName(ddmContent.getUserName());
2745 ddmContentImpl.setCreateDate(ddmContent.getCreateDate());
2746 ddmContentImpl.setModifiedDate(ddmContent.getModifiedDate());
2747 ddmContentImpl.setName(ddmContent.getName());
2748 ddmContentImpl.setDescription(ddmContent.getDescription());
2749 ddmContentImpl.setXml(ddmContent.getXml());
2750
2751 return ddmContentImpl;
2752 }
2753
2754
2762 @Override
2763 public DDMContent findByPrimaryKey(Serializable primaryKey)
2764 throws NoSuchModelException, SystemException {
2765 return findByPrimaryKey(((Long)primaryKey).longValue());
2766 }
2767
2768
2776 public DDMContent findByPrimaryKey(long contentId)
2777 throws NoSuchContentException, SystemException {
2778 DDMContent ddmContent = fetchByPrimaryKey(contentId);
2779
2780 if (ddmContent == null) {
2781 if (_log.isWarnEnabled()) {
2782 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
2783 }
2784
2785 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2786 contentId);
2787 }
2788
2789 return ddmContent;
2790 }
2791
2792
2799 @Override
2800 public DDMContent fetchByPrimaryKey(Serializable primaryKey)
2801 throws SystemException {
2802 return fetchByPrimaryKey(((Long)primaryKey).longValue());
2803 }
2804
2805
2812 public DDMContent fetchByPrimaryKey(long contentId)
2813 throws SystemException {
2814 DDMContent ddmContent = (DDMContent)EntityCacheUtil.getResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2815 DDMContentImpl.class, contentId);
2816
2817 if (ddmContent == _nullDDMContent) {
2818 return null;
2819 }
2820
2821 if (ddmContent == null) {
2822 Session session = null;
2823
2824 try {
2825 session = openSession();
2826
2827 ddmContent = (DDMContent)session.get(DDMContentImpl.class,
2828 Long.valueOf(contentId));
2829
2830 if (ddmContent != null) {
2831 cacheResult(ddmContent);
2832 }
2833 else {
2834 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2835 DDMContentImpl.class, contentId, _nullDDMContent);
2836 }
2837 }
2838 catch (Exception e) {
2839 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
2840 DDMContentImpl.class, contentId);
2841
2842 throw processException(e);
2843 }
2844 finally {
2845 closeSession(session);
2846 }
2847 }
2848
2849 return ddmContent;
2850 }
2851
2852
2858 public List<DDMContent> findAll() throws SystemException {
2859 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2860 }
2861
2862
2874 public List<DDMContent> findAll(int start, int end)
2875 throws SystemException {
2876 return findAll(start, end, null);
2877 }
2878
2879
2892 public List<DDMContent> findAll(int start, int end,
2893 OrderByComparator orderByComparator) throws SystemException {
2894 boolean pagination = true;
2895 FinderPath finderPath = null;
2896 Object[] finderArgs = null;
2897
2898 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2899 (orderByComparator == null)) {
2900 pagination = false;
2901 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2902 finderArgs = FINDER_ARGS_EMPTY;
2903 }
2904 else {
2905 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2906 finderArgs = new Object[] { start, end, orderByComparator };
2907 }
2908
2909 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
2910 finderArgs, this);
2911
2912 if (list == null) {
2913 StringBundler query = null;
2914 String sql = null;
2915
2916 if (orderByComparator != null) {
2917 query = new StringBundler(2 +
2918 (orderByComparator.getOrderByFields().length * 3));
2919
2920 query.append(_SQL_SELECT_DDMCONTENT);
2921
2922 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2923 orderByComparator);
2924
2925 sql = query.toString();
2926 }
2927 else {
2928 sql = _SQL_SELECT_DDMCONTENT;
2929
2930 if (pagination) {
2931 sql = sql.concat(DDMContentModelImpl.ORDER_BY_JPQL);
2932 }
2933 }
2934
2935 Session session = null;
2936
2937 try {
2938 session = openSession();
2939
2940 Query q = session.createQuery(sql);
2941
2942 if (!pagination) {
2943 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2944 start, end, false);
2945
2946 Collections.sort(list);
2947
2948 list = new UnmodifiableList<DDMContent>(list);
2949 }
2950 else {
2951 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2952 start, end);
2953 }
2954
2955 cacheResult(list);
2956
2957 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2958 }
2959 catch (Exception e) {
2960 FinderCacheUtil.removeResult(finderPath, finderArgs);
2961
2962 throw processException(e);
2963 }
2964 finally {
2965 closeSession(session);
2966 }
2967 }
2968
2969 return list;
2970 }
2971
2972
2977 public void removeAll() throws SystemException {
2978 for (DDMContent ddmContent : findAll()) {
2979 remove(ddmContent);
2980 }
2981 }
2982
2983
2989 public int countAll() throws SystemException {
2990 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2991 FINDER_ARGS_EMPTY, this);
2992
2993 if (count == null) {
2994 Session session = null;
2995
2996 try {
2997 session = openSession();
2998
2999 Query q = session.createQuery(_SQL_COUNT_DDMCONTENT);
3000
3001 count = (Long)q.uniqueResult();
3002
3003 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3004 FINDER_ARGS_EMPTY, count);
3005 }
3006 catch (Exception e) {
3007 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3008 FINDER_ARGS_EMPTY);
3009
3010 throw processException(e);
3011 }
3012 finally {
3013 closeSession(session);
3014 }
3015 }
3016
3017 return count.intValue();
3018 }
3019
3020
3023 public void afterPropertiesSet() {
3024 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3025 com.liferay.portal.util.PropsUtil.get(
3026 "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMContent")));
3027
3028 if (listenerClassNames.length > 0) {
3029 try {
3030 List<ModelListener<DDMContent>> listenersList = new ArrayList<ModelListener<DDMContent>>();
3031
3032 for (String listenerClassName : listenerClassNames) {
3033 listenersList.add((ModelListener<DDMContent>)InstanceFactory.newInstance(
3034 listenerClassName));
3035 }
3036
3037 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3038 }
3039 catch (Exception e) {
3040 _log.error(e);
3041 }
3042 }
3043 }
3044
3045 public void destroy() {
3046 EntityCacheUtil.removeCache(DDMContentImpl.class.getName());
3047 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3048 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3049 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3050 }
3051
3052 private static final String _SQL_SELECT_DDMCONTENT = "SELECT ddmContent FROM DDMContent ddmContent";
3053 private static final String _SQL_SELECT_DDMCONTENT_WHERE = "SELECT ddmContent FROM DDMContent ddmContent WHERE ";
3054 private static final String _SQL_COUNT_DDMCONTENT = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent";
3055 private static final String _SQL_COUNT_DDMCONTENT_WHERE = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent WHERE ";
3056 private static final String _ORDER_BY_ENTITY_ALIAS = "ddmContent.";
3057 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMContent exists with the primary key ";
3058 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMContent exists with the key {";
3059 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3060 private static Log _log = LogFactoryUtil.getLog(DDMContentPersistenceImpl.class);
3061 private static DDMContent _nullDDMContent = new DDMContentImpl() {
3062 @Override
3063 public Object clone() {
3064 return this;
3065 }
3066
3067 @Override
3068 public CacheModel<DDMContent> toCacheModel() {
3069 return _nullDDMContentCacheModel;
3070 }
3071 };
3072
3073 private static CacheModel<DDMContent> _nullDDMContentCacheModel = new CacheModel<DDMContent>() {
3074 public DDMContent toEntityModel() {
3075 return _nullDDMContent;
3076 }
3077 };
3078 }