001
014
015 package com.liferay.portlet.dynamicdatamapping.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
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.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.dynamicdatamapping.NoSuchContentException;
044 import com.liferay.portlet.dynamicdatamapping.model.DDMContent;
045 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentImpl;
046 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
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_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
079 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
081 new String[] {
082 String.class.getName(),
083
084 "java.lang.Integer", "java.lang.Integer",
085 "com.liferay.portal.kernel.util.OrderByComparator"
086 });
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
088 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
090 new String[] { String.class.getName() },
091 DDMContentModelImpl.UUID_COLUMN_BITMASK);
092 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
093 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
095 new String[] { String.class.getName() });
096 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
097 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
098 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
099 new String[] { String.class.getName(), Long.class.getName() },
100 DDMContentModelImpl.UUID_COLUMN_BITMASK |
101 DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
103 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
105 new String[] { String.class.getName(), Long.class.getName() });
106 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
107 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
108 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
109 new String[] {
110 String.class.getName(), Long.class.getName(),
111
112 "java.lang.Integer", "java.lang.Integer",
113 "com.liferay.portal.kernel.util.OrderByComparator"
114 });
115 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
116 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
117 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
118 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
119 new String[] { String.class.getName(), Long.class.getName() },
120 DDMContentModelImpl.UUID_COLUMN_BITMASK |
121 DDMContentModelImpl.COMPANYID_COLUMN_BITMASK);
122 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
123 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
124 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
125 new String[] { String.class.getName(), Long.class.getName() });
126 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
127 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
128 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
129 new String[] {
130 Long.class.getName(),
131
132 "java.lang.Integer", "java.lang.Integer",
133 "com.liferay.portal.kernel.util.OrderByComparator"
134 });
135 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
136 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
137 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
138 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
139 new String[] { Long.class.getName() },
140 DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
141 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
142 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
143 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
144 new String[] { Long.class.getName() });
145 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
146 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
147 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
148 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
149 new String[] {
150 Long.class.getName(),
151
152 "java.lang.Integer", "java.lang.Integer",
153 "com.liferay.portal.kernel.util.OrderByComparator"
154 });
155 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
156 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
157 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
158 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
159 new String[] { Long.class.getName() },
160 DDMContentModelImpl.COMPANYID_COLUMN_BITMASK);
161 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
162 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
163 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
164 new String[] { Long.class.getName() });
165 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
166 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
167 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
168 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
169 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
170 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
171 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
172 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
173 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
174
175
180 public void cacheResult(DDMContent ddmContent) {
181 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
182 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
183
184 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
185 new Object[] {
186 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
187 }, ddmContent);
188
189 ddmContent.resetOriginalValues();
190 }
191
192
197 public void cacheResult(List<DDMContent> ddmContents) {
198 for (DDMContent ddmContent : ddmContents) {
199 if (EntityCacheUtil.getResult(
200 DDMContentModelImpl.ENTITY_CACHE_ENABLED,
201 DDMContentImpl.class, ddmContent.getPrimaryKey()) == null) {
202 cacheResult(ddmContent);
203 }
204 else {
205 ddmContent.resetOriginalValues();
206 }
207 }
208 }
209
210
217 @Override
218 public void clearCache() {
219 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
220 CacheRegistryUtil.clear(DDMContentImpl.class.getName());
221 }
222
223 EntityCacheUtil.clearCache(DDMContentImpl.class.getName());
224
225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
226 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
227 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
228 }
229
230
237 @Override
238 public void clearCache(DDMContent ddmContent) {
239 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
240 DDMContentImpl.class, ddmContent.getPrimaryKey());
241
242 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
243 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
244
245 clearUniqueFindersCache(ddmContent);
246 }
247
248 @Override
249 public void clearCache(List<DDMContent> ddmContents) {
250 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
251 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
252
253 for (DDMContent ddmContent : ddmContents) {
254 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
255 DDMContentImpl.class, ddmContent.getPrimaryKey());
256
257 clearUniqueFindersCache(ddmContent);
258 }
259 }
260
261 protected void clearUniqueFindersCache(DDMContent ddmContent) {
262 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
263 new Object[] {
264 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
265 });
266 }
267
268
274 public DDMContent create(long contentId) {
275 DDMContent ddmContent = new DDMContentImpl();
276
277 ddmContent.setNew(true);
278 ddmContent.setPrimaryKey(contentId);
279
280 String uuid = PortalUUIDUtil.generate();
281
282 ddmContent.setUuid(uuid);
283
284 return ddmContent;
285 }
286
287
295 public DDMContent remove(long contentId)
296 throws NoSuchContentException, SystemException {
297 return remove(Long.valueOf(contentId));
298 }
299
300
308 @Override
309 public DDMContent remove(Serializable primaryKey)
310 throws NoSuchContentException, SystemException {
311 Session session = null;
312
313 try {
314 session = openSession();
315
316 DDMContent ddmContent = (DDMContent)session.get(DDMContentImpl.class,
317 primaryKey);
318
319 if (ddmContent == null) {
320 if (_log.isWarnEnabled()) {
321 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
322 }
323
324 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
325 primaryKey);
326 }
327
328 return remove(ddmContent);
329 }
330 catch (NoSuchContentException nsee) {
331 throw nsee;
332 }
333 catch (Exception e) {
334 throw processException(e);
335 }
336 finally {
337 closeSession(session);
338 }
339 }
340
341 @Override
342 protected DDMContent removeImpl(DDMContent ddmContent)
343 throws SystemException {
344 ddmContent = toUnwrappedModel(ddmContent);
345
346 Session session = null;
347
348 try {
349 session = openSession();
350
351 if (ddmContent.isCachedModel()) {
352 ddmContent = (DDMContent)session.get(DDMContentImpl.class,
353 ddmContent.getPrimaryKeyObj());
354 }
355
356 session.delete(ddmContent);
357 }
358 catch (Exception e) {
359 throw processException(e);
360 }
361 finally {
362 closeSession(session);
363 }
364
365 clearCache(ddmContent);
366
367 return ddmContent;
368 }
369
370 @Override
371 public DDMContent updateImpl(
372 com.liferay.portlet.dynamicdatamapping.model.DDMContent ddmContent)
373 throws SystemException {
374 ddmContent = toUnwrappedModel(ddmContent);
375
376 boolean isNew = ddmContent.isNew();
377
378 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
379
380 if (Validator.isNull(ddmContent.getUuid())) {
381 String uuid = PortalUUIDUtil.generate();
382
383 ddmContent.setUuid(uuid);
384 }
385
386 Session session = null;
387
388 try {
389 session = openSession();
390
391 if (ddmContent.isNew()) {
392 session.save(ddmContent);
393
394 ddmContent.setNew(false);
395 }
396 else {
397 session.merge(ddmContent);
398 }
399 }
400 catch (Exception e) {
401 throw processException(e);
402 }
403 finally {
404 closeSession(session);
405 }
406
407 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
408
409 if (isNew || !DDMContentModelImpl.COLUMN_BITMASK_ENABLED) {
410 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
411 }
412
413 else {
414 if ((ddmContentModelImpl.getColumnBitmask() &
415 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
416 Object[] args = new Object[] {
417 ddmContentModelImpl.getOriginalUuid()
418 };
419
420 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
421 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
422 args);
423
424 args = new Object[] { ddmContentModelImpl.getUuid() };
425
426 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
427 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
428 args);
429 }
430
431 if ((ddmContentModelImpl.getColumnBitmask() &
432 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
433 Object[] args = new Object[] {
434 ddmContentModelImpl.getOriginalUuid(),
435 Long.valueOf(ddmContentModelImpl.getOriginalCompanyId())
436 };
437
438 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
439 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
440 args);
441
442 args = new Object[] {
443 ddmContentModelImpl.getUuid(),
444 Long.valueOf(ddmContentModelImpl.getCompanyId())
445 };
446
447 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
448 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
449 args);
450 }
451
452 if ((ddmContentModelImpl.getColumnBitmask() &
453 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
454 Object[] args = new Object[] {
455 Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
456 };
457
458 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
459 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
460 args);
461
462 args = new Object[] {
463 Long.valueOf(ddmContentModelImpl.getGroupId())
464 };
465
466 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
467 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
468 args);
469 }
470
471 if ((ddmContentModelImpl.getColumnBitmask() &
472 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
473 Object[] args = new Object[] {
474 Long.valueOf(ddmContentModelImpl.getOriginalCompanyId())
475 };
476
477 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
478 args);
479 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
480 args);
481
482 args = new Object[] {
483 Long.valueOf(ddmContentModelImpl.getCompanyId())
484 };
485
486 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
487 args);
488 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
489 args);
490 }
491 }
492
493 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
494 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
495
496 if (isNew) {
497 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
498 new Object[] {
499 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
500 }, ddmContent);
501 }
502 else {
503 if ((ddmContentModelImpl.getColumnBitmask() &
504 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
505 Object[] args = new Object[] {
506 ddmContentModelImpl.getOriginalUuid(),
507 Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
508 };
509
510 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
511
512 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
513
514 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
515 new Object[] {
516 ddmContent.getUuid(),
517 Long.valueOf(ddmContent.getGroupId())
518 }, ddmContent);
519 }
520 }
521
522 return ddmContent;
523 }
524
525 protected DDMContent toUnwrappedModel(DDMContent ddmContent) {
526 if (ddmContent instanceof DDMContentImpl) {
527 return ddmContent;
528 }
529
530 DDMContentImpl ddmContentImpl = new DDMContentImpl();
531
532 ddmContentImpl.setNew(ddmContent.isNew());
533 ddmContentImpl.setPrimaryKey(ddmContent.getPrimaryKey());
534
535 ddmContentImpl.setUuid(ddmContent.getUuid());
536 ddmContentImpl.setContentId(ddmContent.getContentId());
537 ddmContentImpl.setGroupId(ddmContent.getGroupId());
538 ddmContentImpl.setCompanyId(ddmContent.getCompanyId());
539 ddmContentImpl.setUserId(ddmContent.getUserId());
540 ddmContentImpl.setUserName(ddmContent.getUserName());
541 ddmContentImpl.setCreateDate(ddmContent.getCreateDate());
542 ddmContentImpl.setModifiedDate(ddmContent.getModifiedDate());
543 ddmContentImpl.setName(ddmContent.getName());
544 ddmContentImpl.setDescription(ddmContent.getDescription());
545 ddmContentImpl.setXml(ddmContent.getXml());
546
547 return ddmContentImpl;
548 }
549
550
558 @Override
559 public DDMContent findByPrimaryKey(Serializable primaryKey)
560 throws NoSuchModelException, SystemException {
561 return findByPrimaryKey(((Long)primaryKey).longValue());
562 }
563
564
572 public DDMContent findByPrimaryKey(long contentId)
573 throws NoSuchContentException, SystemException {
574 DDMContent ddmContent = fetchByPrimaryKey(contentId);
575
576 if (ddmContent == null) {
577 if (_log.isWarnEnabled()) {
578 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
579 }
580
581 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
582 contentId);
583 }
584
585 return ddmContent;
586 }
587
588
595 @Override
596 public DDMContent fetchByPrimaryKey(Serializable primaryKey)
597 throws SystemException {
598 return fetchByPrimaryKey(((Long)primaryKey).longValue());
599 }
600
601
608 public DDMContent fetchByPrimaryKey(long contentId)
609 throws SystemException {
610 DDMContent ddmContent = (DDMContent)EntityCacheUtil.getResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
611 DDMContentImpl.class, contentId);
612
613 if (ddmContent == _nullDDMContent) {
614 return null;
615 }
616
617 if (ddmContent == null) {
618 Session session = null;
619
620 boolean hasException = false;
621
622 try {
623 session = openSession();
624
625 ddmContent = (DDMContent)session.get(DDMContentImpl.class,
626 Long.valueOf(contentId));
627 }
628 catch (Exception e) {
629 hasException = true;
630
631 throw processException(e);
632 }
633 finally {
634 if (ddmContent != null) {
635 cacheResult(ddmContent);
636 }
637 else if (!hasException) {
638 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
639 DDMContentImpl.class, contentId, _nullDDMContent);
640 }
641
642 closeSession(session);
643 }
644 }
645
646 return ddmContent;
647 }
648
649
656 public List<DDMContent> findByUuid(String uuid) throws SystemException {
657 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
658 }
659
660
673 public List<DDMContent> findByUuid(String uuid, int start, int end)
674 throws SystemException {
675 return findByUuid(uuid, start, end, null);
676 }
677
678
692 public List<DDMContent> findByUuid(String uuid, int start, int end,
693 OrderByComparator orderByComparator) throws SystemException {
694 FinderPath finderPath = null;
695 Object[] finderArgs = null;
696
697 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
698 (orderByComparator == null)) {
699 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
700 finderArgs = new Object[] { uuid };
701 }
702 else {
703 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
704 finderArgs = new Object[] { uuid, start, end, orderByComparator };
705 }
706
707 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
708 finderArgs, this);
709
710 if ((list != null) && !list.isEmpty()) {
711 for (DDMContent ddmContent : list) {
712 if (!Validator.equals(uuid, ddmContent.getUuid())) {
713 list = null;
714
715 break;
716 }
717 }
718 }
719
720 if (list == null) {
721 StringBundler query = null;
722
723 if (orderByComparator != null) {
724 query = new StringBundler(3 +
725 (orderByComparator.getOrderByFields().length * 3));
726 }
727 else {
728 query = new StringBundler(2);
729 }
730
731 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
732
733 if (uuid == null) {
734 query.append(_FINDER_COLUMN_UUID_UUID_1);
735 }
736 else {
737 if (uuid.equals(StringPool.BLANK)) {
738 query.append(_FINDER_COLUMN_UUID_UUID_3);
739 }
740 else {
741 query.append(_FINDER_COLUMN_UUID_UUID_2);
742 }
743 }
744
745 if (orderByComparator != null) {
746 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
747 orderByComparator);
748 }
749
750 String sql = query.toString();
751
752 Session session = null;
753
754 try {
755 session = openSession();
756
757 Query q = session.createQuery(sql);
758
759 QueryPos qPos = QueryPos.getInstance(q);
760
761 if (uuid != null) {
762 qPos.add(uuid);
763 }
764
765 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
766 end);
767 }
768 catch (Exception e) {
769 throw processException(e);
770 }
771 finally {
772 if (list == null) {
773 FinderCacheUtil.removeResult(finderPath, finderArgs);
774 }
775 else {
776 cacheResult(list);
777
778 FinderCacheUtil.putResult(finderPath, finderArgs, list);
779 }
780
781 closeSession(session);
782 }
783 }
784
785 return list;
786 }
787
788
797 public DDMContent findByUuid_First(String uuid,
798 OrderByComparator orderByComparator)
799 throws NoSuchContentException, SystemException {
800 DDMContent ddmContent = fetchByUuid_First(uuid, orderByComparator);
801
802 if (ddmContent != null) {
803 return ddmContent;
804 }
805
806 StringBundler msg = new StringBundler(4);
807
808 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
809
810 msg.append("uuid=");
811 msg.append(uuid);
812
813 msg.append(StringPool.CLOSE_CURLY_BRACE);
814
815 throw new NoSuchContentException(msg.toString());
816 }
817
818
826 public DDMContent fetchByUuid_First(String uuid,
827 OrderByComparator orderByComparator) throws SystemException {
828 List<DDMContent> list = findByUuid(uuid, 0, 1, orderByComparator);
829
830 if (!list.isEmpty()) {
831 return list.get(0);
832 }
833
834 return null;
835 }
836
837
846 public DDMContent findByUuid_Last(String uuid,
847 OrderByComparator orderByComparator)
848 throws NoSuchContentException, SystemException {
849 DDMContent ddmContent = fetchByUuid_Last(uuid, orderByComparator);
850
851 if (ddmContent != null) {
852 return ddmContent;
853 }
854
855 StringBundler msg = new StringBundler(4);
856
857 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
858
859 msg.append("uuid=");
860 msg.append(uuid);
861
862 msg.append(StringPool.CLOSE_CURLY_BRACE);
863
864 throw new NoSuchContentException(msg.toString());
865 }
866
867
875 public DDMContent fetchByUuid_Last(String uuid,
876 OrderByComparator orderByComparator) throws SystemException {
877 int count = countByUuid(uuid);
878
879 List<DDMContent> list = findByUuid(uuid, count - 1, count,
880 orderByComparator);
881
882 if (!list.isEmpty()) {
883 return list.get(0);
884 }
885
886 return null;
887 }
888
889
899 public DDMContent[] findByUuid_PrevAndNext(long contentId, String uuid,
900 OrderByComparator orderByComparator)
901 throws NoSuchContentException, SystemException {
902 DDMContent ddmContent = findByPrimaryKey(contentId);
903
904 Session session = null;
905
906 try {
907 session = openSession();
908
909 DDMContent[] array = new DDMContentImpl[3];
910
911 array[0] = getByUuid_PrevAndNext(session, ddmContent, uuid,
912 orderByComparator, true);
913
914 array[1] = ddmContent;
915
916 array[2] = getByUuid_PrevAndNext(session, ddmContent, uuid,
917 orderByComparator, false);
918
919 return array;
920 }
921 catch (Exception e) {
922 throw processException(e);
923 }
924 finally {
925 closeSession(session);
926 }
927 }
928
929 protected DDMContent getByUuid_PrevAndNext(Session session,
930 DDMContent ddmContent, String uuid,
931 OrderByComparator orderByComparator, boolean previous) {
932 StringBundler query = null;
933
934 if (orderByComparator != null) {
935 query = new StringBundler(6 +
936 (orderByComparator.getOrderByFields().length * 6));
937 }
938 else {
939 query = new StringBundler(3);
940 }
941
942 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
943
944 if (uuid == null) {
945 query.append(_FINDER_COLUMN_UUID_UUID_1);
946 }
947 else {
948 if (uuid.equals(StringPool.BLANK)) {
949 query.append(_FINDER_COLUMN_UUID_UUID_3);
950 }
951 else {
952 query.append(_FINDER_COLUMN_UUID_UUID_2);
953 }
954 }
955
956 if (orderByComparator != null) {
957 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
958
959 if (orderByConditionFields.length > 0) {
960 query.append(WHERE_AND);
961 }
962
963 for (int i = 0; i < orderByConditionFields.length; i++) {
964 query.append(_ORDER_BY_ENTITY_ALIAS);
965 query.append(orderByConditionFields[i]);
966
967 if ((i + 1) < orderByConditionFields.length) {
968 if (orderByComparator.isAscending() ^ previous) {
969 query.append(WHERE_GREATER_THAN_HAS_NEXT);
970 }
971 else {
972 query.append(WHERE_LESSER_THAN_HAS_NEXT);
973 }
974 }
975 else {
976 if (orderByComparator.isAscending() ^ previous) {
977 query.append(WHERE_GREATER_THAN);
978 }
979 else {
980 query.append(WHERE_LESSER_THAN);
981 }
982 }
983 }
984
985 query.append(ORDER_BY_CLAUSE);
986
987 String[] orderByFields = orderByComparator.getOrderByFields();
988
989 for (int i = 0; i < orderByFields.length; i++) {
990 query.append(_ORDER_BY_ENTITY_ALIAS);
991 query.append(orderByFields[i]);
992
993 if ((i + 1) < orderByFields.length) {
994 if (orderByComparator.isAscending() ^ previous) {
995 query.append(ORDER_BY_ASC_HAS_NEXT);
996 }
997 else {
998 query.append(ORDER_BY_DESC_HAS_NEXT);
999 }
1000 }
1001 else {
1002 if (orderByComparator.isAscending() ^ previous) {
1003 query.append(ORDER_BY_ASC);
1004 }
1005 else {
1006 query.append(ORDER_BY_DESC);
1007 }
1008 }
1009 }
1010 }
1011
1012 String sql = query.toString();
1013
1014 Query q = session.createQuery(sql);
1015
1016 q.setFirstResult(0);
1017 q.setMaxResults(2);
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 if (uuid != null) {
1022 qPos.add(uuid);
1023 }
1024
1025 if (orderByComparator != null) {
1026 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1027
1028 for (Object value : values) {
1029 qPos.add(value);
1030 }
1031 }
1032
1033 List<DDMContent> list = q.list();
1034
1035 if (list.size() == 2) {
1036 return list.get(1);
1037 }
1038 else {
1039 return null;
1040 }
1041 }
1042
1043
1052 public DDMContent findByUUID_G(String uuid, long groupId)
1053 throws NoSuchContentException, SystemException {
1054 DDMContent ddmContent = fetchByUUID_G(uuid, groupId);
1055
1056 if (ddmContent == null) {
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(", groupId=");
1065 msg.append(groupId);
1066
1067 msg.append(StringPool.CLOSE_CURLY_BRACE);
1068
1069 if (_log.isWarnEnabled()) {
1070 _log.warn(msg.toString());
1071 }
1072
1073 throw new NoSuchContentException(msg.toString());
1074 }
1075
1076 return ddmContent;
1077 }
1078
1079
1087 public DDMContent fetchByUUID_G(String uuid, long groupId)
1088 throws SystemException {
1089 return fetchByUUID_G(uuid, groupId, true);
1090 }
1091
1092
1101 public DDMContent fetchByUUID_G(String uuid, long groupId,
1102 boolean retrieveFromCache) throws SystemException {
1103 Object[] finderArgs = new Object[] { uuid, groupId };
1104
1105 Object result = null;
1106
1107 if (retrieveFromCache) {
1108 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1109 finderArgs, this);
1110 }
1111
1112 if (result instanceof DDMContent) {
1113 DDMContent ddmContent = (DDMContent)result;
1114
1115 if (!Validator.equals(uuid, ddmContent.getUuid()) ||
1116 (groupId != ddmContent.getGroupId())) {
1117 result = null;
1118 }
1119 }
1120
1121 if (result == null) {
1122 StringBundler query = new StringBundler(3);
1123
1124 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1125
1126 if (uuid == null) {
1127 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1128 }
1129 else {
1130 if (uuid.equals(StringPool.BLANK)) {
1131 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1132 }
1133 else {
1134 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1135 }
1136 }
1137
1138 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1139
1140 String sql = query.toString();
1141
1142 Session session = null;
1143
1144 try {
1145 session = openSession();
1146
1147 Query q = session.createQuery(sql);
1148
1149 QueryPos qPos = QueryPos.getInstance(q);
1150
1151 if (uuid != null) {
1152 qPos.add(uuid);
1153 }
1154
1155 qPos.add(groupId);
1156
1157 List<DDMContent> list = q.list();
1158
1159 result = list;
1160
1161 DDMContent ddmContent = null;
1162
1163 if (list.isEmpty()) {
1164 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1165 finderArgs, list);
1166 }
1167 else {
1168 ddmContent = list.get(0);
1169
1170 cacheResult(ddmContent);
1171
1172 if ((ddmContent.getUuid() == null) ||
1173 !ddmContent.getUuid().equals(uuid) ||
1174 (ddmContent.getGroupId() != groupId)) {
1175 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1176 finderArgs, ddmContent);
1177 }
1178 }
1179
1180 return ddmContent;
1181 }
1182 catch (Exception e) {
1183 throw processException(e);
1184 }
1185 finally {
1186 if (result == null) {
1187 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1188 finderArgs);
1189 }
1190
1191 closeSession(session);
1192 }
1193 }
1194 else {
1195 if (result instanceof List<?>) {
1196 return null;
1197 }
1198 else {
1199 return (DDMContent)result;
1200 }
1201 }
1202 }
1203
1204
1212 public List<DDMContent> findByUuid_C(String uuid, long companyId)
1213 throws SystemException {
1214 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1215 QueryUtil.ALL_POS, null);
1216 }
1217
1218
1232 public List<DDMContent> findByUuid_C(String uuid, long companyId,
1233 int start, int end) throws SystemException {
1234 return findByUuid_C(uuid, companyId, start, end, null);
1235 }
1236
1237
1252 public List<DDMContent> findByUuid_C(String uuid, long companyId,
1253 int start, int end, OrderByComparator orderByComparator)
1254 throws SystemException {
1255 FinderPath finderPath = null;
1256 Object[] finderArgs = null;
1257
1258 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1259 (orderByComparator == null)) {
1260 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1261 finderArgs = new Object[] { uuid, companyId };
1262 }
1263 else {
1264 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1265 finderArgs = new Object[] {
1266 uuid, companyId,
1267
1268 start, end, orderByComparator
1269 };
1270 }
1271
1272 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1273 finderArgs, this);
1274
1275 if ((list != null) && !list.isEmpty()) {
1276 for (DDMContent ddmContent : list) {
1277 if (!Validator.equals(uuid, ddmContent.getUuid()) ||
1278 (companyId != ddmContent.getCompanyId())) {
1279 list = null;
1280
1281 break;
1282 }
1283 }
1284 }
1285
1286 if (list == null) {
1287 StringBundler query = null;
1288
1289 if (orderByComparator != null) {
1290 query = new StringBundler(4 +
1291 (orderByComparator.getOrderByFields().length * 3));
1292 }
1293 else {
1294 query = new StringBundler(3);
1295 }
1296
1297 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1298
1299 if (uuid == null) {
1300 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1301 }
1302 else {
1303 if (uuid.equals(StringPool.BLANK)) {
1304 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1305 }
1306 else {
1307 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1308 }
1309 }
1310
1311 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1312
1313 if (orderByComparator != null) {
1314 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1315 orderByComparator);
1316 }
1317
1318 String sql = query.toString();
1319
1320 Session session = null;
1321
1322 try {
1323 session = openSession();
1324
1325 Query q = session.createQuery(sql);
1326
1327 QueryPos qPos = QueryPos.getInstance(q);
1328
1329 if (uuid != null) {
1330 qPos.add(uuid);
1331 }
1332
1333 qPos.add(companyId);
1334
1335 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1336 end);
1337 }
1338 catch (Exception e) {
1339 throw processException(e);
1340 }
1341 finally {
1342 if (list == null) {
1343 FinderCacheUtil.removeResult(finderPath, finderArgs);
1344 }
1345 else {
1346 cacheResult(list);
1347
1348 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1349 }
1350
1351 closeSession(session);
1352 }
1353 }
1354
1355 return list;
1356 }
1357
1358
1368 public DDMContent findByUuid_C_First(String uuid, long companyId,
1369 OrderByComparator orderByComparator)
1370 throws NoSuchContentException, SystemException {
1371 DDMContent ddmContent = fetchByUuid_C_First(uuid, companyId,
1372 orderByComparator);
1373
1374 if (ddmContent != null) {
1375 return ddmContent;
1376 }
1377
1378 StringBundler msg = new StringBundler(6);
1379
1380 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1381
1382 msg.append("uuid=");
1383 msg.append(uuid);
1384
1385 msg.append(", companyId=");
1386 msg.append(companyId);
1387
1388 msg.append(StringPool.CLOSE_CURLY_BRACE);
1389
1390 throw new NoSuchContentException(msg.toString());
1391 }
1392
1393
1402 public DDMContent fetchByUuid_C_First(String uuid, long companyId,
1403 OrderByComparator orderByComparator) throws SystemException {
1404 List<DDMContent> list = findByUuid_C(uuid, companyId, 0, 1,
1405 orderByComparator);
1406
1407 if (!list.isEmpty()) {
1408 return list.get(0);
1409 }
1410
1411 return null;
1412 }
1413
1414
1424 public DDMContent findByUuid_C_Last(String uuid, long companyId,
1425 OrderByComparator orderByComparator)
1426 throws NoSuchContentException, SystemException {
1427 DDMContent ddmContent = fetchByUuid_C_Last(uuid, companyId,
1428 orderByComparator);
1429
1430 if (ddmContent != null) {
1431 return ddmContent;
1432 }
1433
1434 StringBundler msg = new StringBundler(6);
1435
1436 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1437
1438 msg.append("uuid=");
1439 msg.append(uuid);
1440
1441 msg.append(", companyId=");
1442 msg.append(companyId);
1443
1444 msg.append(StringPool.CLOSE_CURLY_BRACE);
1445
1446 throw new NoSuchContentException(msg.toString());
1447 }
1448
1449
1458 public DDMContent fetchByUuid_C_Last(String uuid, long companyId,
1459 OrderByComparator orderByComparator) throws SystemException {
1460 int count = countByUuid_C(uuid, companyId);
1461
1462 List<DDMContent> list = findByUuid_C(uuid, companyId, count - 1, count,
1463 orderByComparator);
1464
1465 if (!list.isEmpty()) {
1466 return list.get(0);
1467 }
1468
1469 return null;
1470 }
1471
1472
1483 public DDMContent[] findByUuid_C_PrevAndNext(long contentId, String uuid,
1484 long companyId, OrderByComparator orderByComparator)
1485 throws NoSuchContentException, SystemException {
1486 DDMContent ddmContent = findByPrimaryKey(contentId);
1487
1488 Session session = null;
1489
1490 try {
1491 session = openSession();
1492
1493 DDMContent[] array = new DDMContentImpl[3];
1494
1495 array[0] = getByUuid_C_PrevAndNext(session, ddmContent, uuid,
1496 companyId, orderByComparator, true);
1497
1498 array[1] = ddmContent;
1499
1500 array[2] = getByUuid_C_PrevAndNext(session, ddmContent, uuid,
1501 companyId, orderByComparator, false);
1502
1503 return array;
1504 }
1505 catch (Exception e) {
1506 throw processException(e);
1507 }
1508 finally {
1509 closeSession(session);
1510 }
1511 }
1512
1513 protected DDMContent getByUuid_C_PrevAndNext(Session session,
1514 DDMContent ddmContent, String uuid, long companyId,
1515 OrderByComparator orderByComparator, boolean previous) {
1516 StringBundler query = null;
1517
1518 if (orderByComparator != null) {
1519 query = new StringBundler(6 +
1520 (orderByComparator.getOrderByFields().length * 6));
1521 }
1522 else {
1523 query = new StringBundler(3);
1524 }
1525
1526 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1527
1528 if (uuid == null) {
1529 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1530 }
1531 else {
1532 if (uuid.equals(StringPool.BLANK)) {
1533 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1534 }
1535 else {
1536 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1537 }
1538 }
1539
1540 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1541
1542 if (orderByComparator != null) {
1543 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1544
1545 if (orderByConditionFields.length > 0) {
1546 query.append(WHERE_AND);
1547 }
1548
1549 for (int i = 0; i < orderByConditionFields.length; i++) {
1550 query.append(_ORDER_BY_ENTITY_ALIAS);
1551 query.append(orderByConditionFields[i]);
1552
1553 if ((i + 1) < orderByConditionFields.length) {
1554 if (orderByComparator.isAscending() ^ previous) {
1555 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1556 }
1557 else {
1558 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1559 }
1560 }
1561 else {
1562 if (orderByComparator.isAscending() ^ previous) {
1563 query.append(WHERE_GREATER_THAN);
1564 }
1565 else {
1566 query.append(WHERE_LESSER_THAN);
1567 }
1568 }
1569 }
1570
1571 query.append(ORDER_BY_CLAUSE);
1572
1573 String[] orderByFields = orderByComparator.getOrderByFields();
1574
1575 for (int i = 0; i < orderByFields.length; i++) {
1576 query.append(_ORDER_BY_ENTITY_ALIAS);
1577 query.append(orderByFields[i]);
1578
1579 if ((i + 1) < orderByFields.length) {
1580 if (orderByComparator.isAscending() ^ previous) {
1581 query.append(ORDER_BY_ASC_HAS_NEXT);
1582 }
1583 else {
1584 query.append(ORDER_BY_DESC_HAS_NEXT);
1585 }
1586 }
1587 else {
1588 if (orderByComparator.isAscending() ^ previous) {
1589 query.append(ORDER_BY_ASC);
1590 }
1591 else {
1592 query.append(ORDER_BY_DESC);
1593 }
1594 }
1595 }
1596 }
1597
1598 String sql = query.toString();
1599
1600 Query q = session.createQuery(sql);
1601
1602 q.setFirstResult(0);
1603 q.setMaxResults(2);
1604
1605 QueryPos qPos = QueryPos.getInstance(q);
1606
1607 if (uuid != null) {
1608 qPos.add(uuid);
1609 }
1610
1611 qPos.add(companyId);
1612
1613 if (orderByComparator != null) {
1614 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1615
1616 for (Object value : values) {
1617 qPos.add(value);
1618 }
1619 }
1620
1621 List<DDMContent> list = q.list();
1622
1623 if (list.size() == 2) {
1624 return list.get(1);
1625 }
1626 else {
1627 return null;
1628 }
1629 }
1630
1631
1638 public List<DDMContent> findByGroupId(long groupId)
1639 throws SystemException {
1640 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1641 }
1642
1643
1656 public List<DDMContent> findByGroupId(long groupId, int start, int end)
1657 throws SystemException {
1658 return findByGroupId(groupId, start, end, null);
1659 }
1660
1661
1675 public List<DDMContent> findByGroupId(long groupId, int start, int end,
1676 OrderByComparator orderByComparator) throws SystemException {
1677 FinderPath finderPath = null;
1678 Object[] finderArgs = null;
1679
1680 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1681 (orderByComparator == null)) {
1682 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1683 finderArgs = new Object[] { groupId };
1684 }
1685 else {
1686 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1687 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1688 }
1689
1690 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1691 finderArgs, this);
1692
1693 if ((list != null) && !list.isEmpty()) {
1694 for (DDMContent ddmContent : list) {
1695 if ((groupId != ddmContent.getGroupId())) {
1696 list = null;
1697
1698 break;
1699 }
1700 }
1701 }
1702
1703 if (list == null) {
1704 StringBundler query = null;
1705
1706 if (orderByComparator != null) {
1707 query = new StringBundler(3 +
1708 (orderByComparator.getOrderByFields().length * 3));
1709 }
1710 else {
1711 query = new StringBundler(2);
1712 }
1713
1714 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1715
1716 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1717
1718 if (orderByComparator != null) {
1719 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1720 orderByComparator);
1721 }
1722
1723 String sql = query.toString();
1724
1725 Session session = null;
1726
1727 try {
1728 session = openSession();
1729
1730 Query q = session.createQuery(sql);
1731
1732 QueryPos qPos = QueryPos.getInstance(q);
1733
1734 qPos.add(groupId);
1735
1736 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1737 end);
1738 }
1739 catch (Exception e) {
1740 throw processException(e);
1741 }
1742 finally {
1743 if (list == null) {
1744 FinderCacheUtil.removeResult(finderPath, finderArgs);
1745 }
1746 else {
1747 cacheResult(list);
1748
1749 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1750 }
1751
1752 closeSession(session);
1753 }
1754 }
1755
1756 return list;
1757 }
1758
1759
1768 public DDMContent findByGroupId_First(long groupId,
1769 OrderByComparator orderByComparator)
1770 throws NoSuchContentException, SystemException {
1771 DDMContent ddmContent = fetchByGroupId_First(groupId, orderByComparator);
1772
1773 if (ddmContent != null) {
1774 return ddmContent;
1775 }
1776
1777 StringBundler msg = new StringBundler(4);
1778
1779 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1780
1781 msg.append("groupId=");
1782 msg.append(groupId);
1783
1784 msg.append(StringPool.CLOSE_CURLY_BRACE);
1785
1786 throw new NoSuchContentException(msg.toString());
1787 }
1788
1789
1797 public DDMContent fetchByGroupId_First(long groupId,
1798 OrderByComparator orderByComparator) throws SystemException {
1799 List<DDMContent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1800
1801 if (!list.isEmpty()) {
1802 return list.get(0);
1803 }
1804
1805 return null;
1806 }
1807
1808
1817 public DDMContent findByGroupId_Last(long groupId,
1818 OrderByComparator orderByComparator)
1819 throws NoSuchContentException, SystemException {
1820 DDMContent ddmContent = fetchByGroupId_Last(groupId, orderByComparator);
1821
1822 if (ddmContent != null) {
1823 return ddmContent;
1824 }
1825
1826 StringBundler msg = new StringBundler(4);
1827
1828 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1829
1830 msg.append("groupId=");
1831 msg.append(groupId);
1832
1833 msg.append(StringPool.CLOSE_CURLY_BRACE);
1834
1835 throw new NoSuchContentException(msg.toString());
1836 }
1837
1838
1846 public DDMContent fetchByGroupId_Last(long groupId,
1847 OrderByComparator orderByComparator) throws SystemException {
1848 int count = countByGroupId(groupId);
1849
1850 List<DDMContent> list = findByGroupId(groupId, count - 1, count,
1851 orderByComparator);
1852
1853 if (!list.isEmpty()) {
1854 return list.get(0);
1855 }
1856
1857 return null;
1858 }
1859
1860
1870 public DDMContent[] findByGroupId_PrevAndNext(long contentId, long groupId,
1871 OrderByComparator orderByComparator)
1872 throws NoSuchContentException, SystemException {
1873 DDMContent ddmContent = findByPrimaryKey(contentId);
1874
1875 Session session = null;
1876
1877 try {
1878 session = openSession();
1879
1880 DDMContent[] array = new DDMContentImpl[3];
1881
1882 array[0] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1883 orderByComparator, true);
1884
1885 array[1] = ddmContent;
1886
1887 array[2] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1888 orderByComparator, false);
1889
1890 return array;
1891 }
1892 catch (Exception e) {
1893 throw processException(e);
1894 }
1895 finally {
1896 closeSession(session);
1897 }
1898 }
1899
1900 protected DDMContent getByGroupId_PrevAndNext(Session session,
1901 DDMContent ddmContent, long groupId,
1902 OrderByComparator orderByComparator, boolean previous) {
1903 StringBundler query = null;
1904
1905 if (orderByComparator != null) {
1906 query = new StringBundler(6 +
1907 (orderByComparator.getOrderByFields().length * 6));
1908 }
1909 else {
1910 query = new StringBundler(3);
1911 }
1912
1913 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1914
1915 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1916
1917 if (orderByComparator != null) {
1918 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1919
1920 if (orderByConditionFields.length > 0) {
1921 query.append(WHERE_AND);
1922 }
1923
1924 for (int i = 0; i < orderByConditionFields.length; i++) {
1925 query.append(_ORDER_BY_ENTITY_ALIAS);
1926 query.append(orderByConditionFields[i]);
1927
1928 if ((i + 1) < orderByConditionFields.length) {
1929 if (orderByComparator.isAscending() ^ previous) {
1930 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1931 }
1932 else {
1933 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1934 }
1935 }
1936 else {
1937 if (orderByComparator.isAscending() ^ previous) {
1938 query.append(WHERE_GREATER_THAN);
1939 }
1940 else {
1941 query.append(WHERE_LESSER_THAN);
1942 }
1943 }
1944 }
1945
1946 query.append(ORDER_BY_CLAUSE);
1947
1948 String[] orderByFields = orderByComparator.getOrderByFields();
1949
1950 for (int i = 0; i < orderByFields.length; i++) {
1951 query.append(_ORDER_BY_ENTITY_ALIAS);
1952 query.append(orderByFields[i]);
1953
1954 if ((i + 1) < orderByFields.length) {
1955 if (orderByComparator.isAscending() ^ previous) {
1956 query.append(ORDER_BY_ASC_HAS_NEXT);
1957 }
1958 else {
1959 query.append(ORDER_BY_DESC_HAS_NEXT);
1960 }
1961 }
1962 else {
1963 if (orderByComparator.isAscending() ^ previous) {
1964 query.append(ORDER_BY_ASC);
1965 }
1966 else {
1967 query.append(ORDER_BY_DESC);
1968 }
1969 }
1970 }
1971 }
1972
1973 String sql = query.toString();
1974
1975 Query q = session.createQuery(sql);
1976
1977 q.setFirstResult(0);
1978 q.setMaxResults(2);
1979
1980 QueryPos qPos = QueryPos.getInstance(q);
1981
1982 qPos.add(groupId);
1983
1984 if (orderByComparator != null) {
1985 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1986
1987 for (Object value : values) {
1988 qPos.add(value);
1989 }
1990 }
1991
1992 List<DDMContent> list = q.list();
1993
1994 if (list.size() == 2) {
1995 return list.get(1);
1996 }
1997 else {
1998 return null;
1999 }
2000 }
2001
2002
2009 public List<DDMContent> findByCompanyId(long companyId)
2010 throws SystemException {
2011 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2012 null);
2013 }
2014
2015
2028 public List<DDMContent> findByCompanyId(long companyId, int start, int end)
2029 throws SystemException {
2030 return findByCompanyId(companyId, start, end, null);
2031 }
2032
2033
2047 public List<DDMContent> findByCompanyId(long companyId, int start, int end,
2048 OrderByComparator orderByComparator) throws SystemException {
2049 FinderPath finderPath = null;
2050 Object[] finderArgs = null;
2051
2052 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2053 (orderByComparator == null)) {
2054 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2055 finderArgs = new Object[] { companyId };
2056 }
2057 else {
2058 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2059 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2060 }
2061
2062 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
2063 finderArgs, this);
2064
2065 if ((list != null) && !list.isEmpty()) {
2066 for (DDMContent ddmContent : list) {
2067 if ((companyId != ddmContent.getCompanyId())) {
2068 list = null;
2069
2070 break;
2071 }
2072 }
2073 }
2074
2075 if (list == null) {
2076 StringBundler query = null;
2077
2078 if (orderByComparator != null) {
2079 query = new StringBundler(3 +
2080 (orderByComparator.getOrderByFields().length * 3));
2081 }
2082 else {
2083 query = new StringBundler(2);
2084 }
2085
2086 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
2087
2088 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2089
2090 if (orderByComparator != null) {
2091 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2092 orderByComparator);
2093 }
2094
2095 String sql = query.toString();
2096
2097 Session session = null;
2098
2099 try {
2100 session = openSession();
2101
2102 Query q = session.createQuery(sql);
2103
2104 QueryPos qPos = QueryPos.getInstance(q);
2105
2106 qPos.add(companyId);
2107
2108 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
2109 end);
2110 }
2111 catch (Exception e) {
2112 throw processException(e);
2113 }
2114 finally {
2115 if (list == null) {
2116 FinderCacheUtil.removeResult(finderPath, finderArgs);
2117 }
2118 else {
2119 cacheResult(list);
2120
2121 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2122 }
2123
2124 closeSession(session);
2125 }
2126 }
2127
2128 return list;
2129 }
2130
2131
2140 public DDMContent findByCompanyId_First(long companyId,
2141 OrderByComparator orderByComparator)
2142 throws NoSuchContentException, SystemException {
2143 DDMContent ddmContent = fetchByCompanyId_First(companyId,
2144 orderByComparator);
2145
2146 if (ddmContent != null) {
2147 return ddmContent;
2148 }
2149
2150 StringBundler msg = new StringBundler(4);
2151
2152 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2153
2154 msg.append("companyId=");
2155 msg.append(companyId);
2156
2157 msg.append(StringPool.CLOSE_CURLY_BRACE);
2158
2159 throw new NoSuchContentException(msg.toString());
2160 }
2161
2162
2170 public DDMContent fetchByCompanyId_First(long companyId,
2171 OrderByComparator orderByComparator) throws SystemException {
2172 List<DDMContent> list = findByCompanyId(companyId, 0, 1,
2173 orderByComparator);
2174
2175 if (!list.isEmpty()) {
2176 return list.get(0);
2177 }
2178
2179 return null;
2180 }
2181
2182
2191 public DDMContent findByCompanyId_Last(long companyId,
2192 OrderByComparator orderByComparator)
2193 throws NoSuchContentException, SystemException {
2194 DDMContent ddmContent = fetchByCompanyId_Last(companyId,
2195 orderByComparator);
2196
2197 if (ddmContent != null) {
2198 return ddmContent;
2199 }
2200
2201 StringBundler msg = new StringBundler(4);
2202
2203 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2204
2205 msg.append("companyId=");
2206 msg.append(companyId);
2207
2208 msg.append(StringPool.CLOSE_CURLY_BRACE);
2209
2210 throw new NoSuchContentException(msg.toString());
2211 }
2212
2213
2221 public DDMContent fetchByCompanyId_Last(long companyId,
2222 OrderByComparator orderByComparator) throws SystemException {
2223 int count = countByCompanyId(companyId);
2224
2225 List<DDMContent> list = findByCompanyId(companyId, count - 1, count,
2226 orderByComparator);
2227
2228 if (!list.isEmpty()) {
2229 return list.get(0);
2230 }
2231
2232 return null;
2233 }
2234
2235
2245 public DDMContent[] findByCompanyId_PrevAndNext(long contentId,
2246 long companyId, OrderByComparator orderByComparator)
2247 throws NoSuchContentException, SystemException {
2248 DDMContent ddmContent = findByPrimaryKey(contentId);
2249
2250 Session session = null;
2251
2252 try {
2253 session = openSession();
2254
2255 DDMContent[] array = new DDMContentImpl[3];
2256
2257 array[0] = getByCompanyId_PrevAndNext(session, ddmContent,
2258 companyId, orderByComparator, true);
2259
2260 array[1] = ddmContent;
2261
2262 array[2] = getByCompanyId_PrevAndNext(session, ddmContent,
2263 companyId, orderByComparator, false);
2264
2265 return array;
2266 }
2267 catch (Exception e) {
2268 throw processException(e);
2269 }
2270 finally {
2271 closeSession(session);
2272 }
2273 }
2274
2275 protected DDMContent getByCompanyId_PrevAndNext(Session session,
2276 DDMContent ddmContent, long companyId,
2277 OrderByComparator orderByComparator, boolean previous) {
2278 StringBundler query = null;
2279
2280 if (orderByComparator != null) {
2281 query = new StringBundler(6 +
2282 (orderByComparator.getOrderByFields().length * 6));
2283 }
2284 else {
2285 query = new StringBundler(3);
2286 }
2287
2288 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
2289
2290 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2291
2292 if (orderByComparator != null) {
2293 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2294
2295 if (orderByConditionFields.length > 0) {
2296 query.append(WHERE_AND);
2297 }
2298
2299 for (int i = 0; i < orderByConditionFields.length; i++) {
2300 query.append(_ORDER_BY_ENTITY_ALIAS);
2301 query.append(orderByConditionFields[i]);
2302
2303 if ((i + 1) < orderByConditionFields.length) {
2304 if (orderByComparator.isAscending() ^ previous) {
2305 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2306 }
2307 else {
2308 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2309 }
2310 }
2311 else {
2312 if (orderByComparator.isAscending() ^ previous) {
2313 query.append(WHERE_GREATER_THAN);
2314 }
2315 else {
2316 query.append(WHERE_LESSER_THAN);
2317 }
2318 }
2319 }
2320
2321 query.append(ORDER_BY_CLAUSE);
2322
2323 String[] orderByFields = orderByComparator.getOrderByFields();
2324
2325 for (int i = 0; i < orderByFields.length; i++) {
2326 query.append(_ORDER_BY_ENTITY_ALIAS);
2327 query.append(orderByFields[i]);
2328
2329 if ((i + 1) < orderByFields.length) {
2330 if (orderByComparator.isAscending() ^ previous) {
2331 query.append(ORDER_BY_ASC_HAS_NEXT);
2332 }
2333 else {
2334 query.append(ORDER_BY_DESC_HAS_NEXT);
2335 }
2336 }
2337 else {
2338 if (orderByComparator.isAscending() ^ previous) {
2339 query.append(ORDER_BY_ASC);
2340 }
2341 else {
2342 query.append(ORDER_BY_DESC);
2343 }
2344 }
2345 }
2346 }
2347
2348 String sql = query.toString();
2349
2350 Query q = session.createQuery(sql);
2351
2352 q.setFirstResult(0);
2353 q.setMaxResults(2);
2354
2355 QueryPos qPos = QueryPos.getInstance(q);
2356
2357 qPos.add(companyId);
2358
2359 if (orderByComparator != null) {
2360 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
2361
2362 for (Object value : values) {
2363 qPos.add(value);
2364 }
2365 }
2366
2367 List<DDMContent> list = q.list();
2368
2369 if (list.size() == 2) {
2370 return list.get(1);
2371 }
2372 else {
2373 return null;
2374 }
2375 }
2376
2377
2383 public List<DDMContent> findAll() throws SystemException {
2384 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2385 }
2386
2387
2399 public List<DDMContent> findAll(int start, int end)
2400 throws SystemException {
2401 return findAll(start, end, null);
2402 }
2403
2404
2417 public List<DDMContent> findAll(int start, int end,
2418 OrderByComparator orderByComparator) throws SystemException {
2419 FinderPath finderPath = null;
2420 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2421
2422 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2423 (orderByComparator == null)) {
2424 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2425 finderArgs = FINDER_ARGS_EMPTY;
2426 }
2427 else {
2428 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2429 finderArgs = new Object[] { start, end, orderByComparator };
2430 }
2431
2432 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
2433 finderArgs, this);
2434
2435 if (list == null) {
2436 StringBundler query = null;
2437 String sql = null;
2438
2439 if (orderByComparator != null) {
2440 query = new StringBundler(2 +
2441 (orderByComparator.getOrderByFields().length * 3));
2442
2443 query.append(_SQL_SELECT_DDMCONTENT);
2444
2445 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2446 orderByComparator);
2447
2448 sql = query.toString();
2449 }
2450 else {
2451 sql = _SQL_SELECT_DDMCONTENT;
2452 }
2453
2454 Session session = null;
2455
2456 try {
2457 session = openSession();
2458
2459 Query q = session.createQuery(sql);
2460
2461 if (orderByComparator == null) {
2462 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2463 start, end, false);
2464
2465 Collections.sort(list);
2466 }
2467 else {
2468 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2469 start, end);
2470 }
2471 }
2472 catch (Exception e) {
2473 throw processException(e);
2474 }
2475 finally {
2476 if (list == null) {
2477 FinderCacheUtil.removeResult(finderPath, finderArgs);
2478 }
2479 else {
2480 cacheResult(list);
2481
2482 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2483 }
2484
2485 closeSession(session);
2486 }
2487 }
2488
2489 return list;
2490 }
2491
2492
2498 public void removeByUuid(String uuid) throws SystemException {
2499 for (DDMContent ddmContent : findByUuid(uuid)) {
2500 remove(ddmContent);
2501 }
2502 }
2503
2504
2512 public DDMContent removeByUUID_G(String uuid, long groupId)
2513 throws NoSuchContentException, SystemException {
2514 DDMContent ddmContent = findByUUID_G(uuid, groupId);
2515
2516 return remove(ddmContent);
2517 }
2518
2519
2526 public void removeByUuid_C(String uuid, long companyId)
2527 throws SystemException {
2528 for (DDMContent ddmContent : findByUuid_C(uuid, companyId)) {
2529 remove(ddmContent);
2530 }
2531 }
2532
2533
2539 public void removeByGroupId(long groupId) throws SystemException {
2540 for (DDMContent ddmContent : findByGroupId(groupId)) {
2541 remove(ddmContent);
2542 }
2543 }
2544
2545
2551 public void removeByCompanyId(long companyId) throws SystemException {
2552 for (DDMContent ddmContent : findByCompanyId(companyId)) {
2553 remove(ddmContent);
2554 }
2555 }
2556
2557
2562 public void removeAll() throws SystemException {
2563 for (DDMContent ddmContent : findAll()) {
2564 remove(ddmContent);
2565 }
2566 }
2567
2568
2575 public int countByUuid(String uuid) throws SystemException {
2576 Object[] finderArgs = new Object[] { uuid };
2577
2578 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2579 finderArgs, this);
2580
2581 if (count == null) {
2582 StringBundler query = new StringBundler(2);
2583
2584 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2585
2586 if (uuid == null) {
2587 query.append(_FINDER_COLUMN_UUID_UUID_1);
2588 }
2589 else {
2590 if (uuid.equals(StringPool.BLANK)) {
2591 query.append(_FINDER_COLUMN_UUID_UUID_3);
2592 }
2593 else {
2594 query.append(_FINDER_COLUMN_UUID_UUID_2);
2595 }
2596 }
2597
2598 String sql = query.toString();
2599
2600 Session session = null;
2601
2602 try {
2603 session = openSession();
2604
2605 Query q = session.createQuery(sql);
2606
2607 QueryPos qPos = QueryPos.getInstance(q);
2608
2609 if (uuid != null) {
2610 qPos.add(uuid);
2611 }
2612
2613 count = (Long)q.uniqueResult();
2614 }
2615 catch (Exception e) {
2616 throw processException(e);
2617 }
2618 finally {
2619 if (count == null) {
2620 count = Long.valueOf(0);
2621 }
2622
2623 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2624 finderArgs, count);
2625
2626 closeSession(session);
2627 }
2628 }
2629
2630 return count.intValue();
2631 }
2632
2633
2641 public int countByUUID_G(String uuid, long groupId)
2642 throws SystemException {
2643 Object[] finderArgs = new Object[] { uuid, groupId };
2644
2645 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2646 finderArgs, this);
2647
2648 if (count == null) {
2649 StringBundler query = new StringBundler(3);
2650
2651 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2652
2653 if (uuid == null) {
2654 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2655 }
2656 else {
2657 if (uuid.equals(StringPool.BLANK)) {
2658 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2659 }
2660 else {
2661 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2662 }
2663 }
2664
2665 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2666
2667 String sql = query.toString();
2668
2669 Session session = null;
2670
2671 try {
2672 session = openSession();
2673
2674 Query q = session.createQuery(sql);
2675
2676 QueryPos qPos = QueryPos.getInstance(q);
2677
2678 if (uuid != null) {
2679 qPos.add(uuid);
2680 }
2681
2682 qPos.add(groupId);
2683
2684 count = (Long)q.uniqueResult();
2685 }
2686 catch (Exception e) {
2687 throw processException(e);
2688 }
2689 finally {
2690 if (count == null) {
2691 count = Long.valueOf(0);
2692 }
2693
2694 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2695 finderArgs, count);
2696
2697 closeSession(session);
2698 }
2699 }
2700
2701 return count.intValue();
2702 }
2703
2704
2712 public int countByUuid_C(String uuid, long companyId)
2713 throws SystemException {
2714 Object[] finderArgs = new Object[] { uuid, companyId };
2715
2716 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
2717 finderArgs, this);
2718
2719 if (count == null) {
2720 StringBundler query = new StringBundler(3);
2721
2722 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2723
2724 if (uuid == null) {
2725 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
2726 }
2727 else {
2728 if (uuid.equals(StringPool.BLANK)) {
2729 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
2730 }
2731 else {
2732 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
2733 }
2734 }
2735
2736 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2737
2738 String sql = query.toString();
2739
2740 Session session = null;
2741
2742 try {
2743 session = openSession();
2744
2745 Query q = session.createQuery(sql);
2746
2747 QueryPos qPos = QueryPos.getInstance(q);
2748
2749 if (uuid != null) {
2750 qPos.add(uuid);
2751 }
2752
2753 qPos.add(companyId);
2754
2755 count = (Long)q.uniqueResult();
2756 }
2757 catch (Exception e) {
2758 throw processException(e);
2759 }
2760 finally {
2761 if (count == null) {
2762 count = Long.valueOf(0);
2763 }
2764
2765 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
2766 finderArgs, count);
2767
2768 closeSession(session);
2769 }
2770 }
2771
2772 return count.intValue();
2773 }
2774
2775
2782 public int countByGroupId(long groupId) throws SystemException {
2783 Object[] finderArgs = new Object[] { groupId };
2784
2785 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2786 finderArgs, this);
2787
2788 if (count == null) {
2789 StringBundler query = new StringBundler(2);
2790
2791 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2792
2793 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2794
2795 String sql = query.toString();
2796
2797 Session session = null;
2798
2799 try {
2800 session = openSession();
2801
2802 Query q = session.createQuery(sql);
2803
2804 QueryPos qPos = QueryPos.getInstance(q);
2805
2806 qPos.add(groupId);
2807
2808 count = (Long)q.uniqueResult();
2809 }
2810 catch (Exception e) {
2811 throw processException(e);
2812 }
2813 finally {
2814 if (count == null) {
2815 count = Long.valueOf(0);
2816 }
2817
2818 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2819 finderArgs, count);
2820
2821 closeSession(session);
2822 }
2823 }
2824
2825 return count.intValue();
2826 }
2827
2828
2835 public int countByCompanyId(long companyId) throws SystemException {
2836 Object[] finderArgs = new Object[] { companyId };
2837
2838 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2839 finderArgs, this);
2840
2841 if (count == null) {
2842 StringBundler query = new StringBundler(2);
2843
2844 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2845
2846 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2847
2848 String sql = query.toString();
2849
2850 Session session = null;
2851
2852 try {
2853 session = openSession();
2854
2855 Query q = session.createQuery(sql);
2856
2857 QueryPos qPos = QueryPos.getInstance(q);
2858
2859 qPos.add(companyId);
2860
2861 count = (Long)q.uniqueResult();
2862 }
2863 catch (Exception e) {
2864 throw processException(e);
2865 }
2866 finally {
2867 if (count == null) {
2868 count = Long.valueOf(0);
2869 }
2870
2871 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2872 finderArgs, count);
2873
2874 closeSession(session);
2875 }
2876 }
2877
2878 return count.intValue();
2879 }
2880
2881
2887 public int countAll() throws SystemException {
2888 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2889 FINDER_ARGS_EMPTY, this);
2890
2891 if (count == null) {
2892 Session session = null;
2893
2894 try {
2895 session = openSession();
2896
2897 Query q = session.createQuery(_SQL_COUNT_DDMCONTENT);
2898
2899 count = (Long)q.uniqueResult();
2900 }
2901 catch (Exception e) {
2902 throw processException(e);
2903 }
2904 finally {
2905 if (count == null) {
2906 count = Long.valueOf(0);
2907 }
2908
2909 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2910 FINDER_ARGS_EMPTY, count);
2911
2912 closeSession(session);
2913 }
2914 }
2915
2916 return count.intValue();
2917 }
2918
2919
2922 public void afterPropertiesSet() {
2923 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2924 com.liferay.portal.util.PropsUtil.get(
2925 "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMContent")));
2926
2927 if (listenerClassNames.length > 0) {
2928 try {
2929 List<ModelListener<DDMContent>> listenersList = new ArrayList<ModelListener<DDMContent>>();
2930
2931 for (String listenerClassName : listenerClassNames) {
2932 listenersList.add((ModelListener<DDMContent>)InstanceFactory.newInstance(
2933 listenerClassName));
2934 }
2935
2936 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2937 }
2938 catch (Exception e) {
2939 _log.error(e);
2940 }
2941 }
2942 }
2943
2944 public void destroy() {
2945 EntityCacheUtil.removeCache(DDMContentImpl.class.getName());
2946 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2947 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2948 }
2949
2950 @BeanReference(type = DDMContentPersistence.class)
2951 protected DDMContentPersistence ddmContentPersistence;
2952 @BeanReference(type = DDMStorageLinkPersistence.class)
2953 protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
2954 @BeanReference(type = DDMStructurePersistence.class)
2955 protected DDMStructurePersistence ddmStructurePersistence;
2956 @BeanReference(type = DDMStructureLinkPersistence.class)
2957 protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
2958 @BeanReference(type = DDMTemplatePersistence.class)
2959 protected DDMTemplatePersistence ddmTemplatePersistence;
2960 @BeanReference(type = UserPersistence.class)
2961 protected UserPersistence userPersistence;
2962 private static final String _SQL_SELECT_DDMCONTENT = "SELECT ddmContent FROM DDMContent ddmContent";
2963 private static final String _SQL_SELECT_DDMCONTENT_WHERE = "SELECT ddmContent FROM DDMContent ddmContent WHERE ";
2964 private static final String _SQL_COUNT_DDMCONTENT = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent";
2965 private static final String _SQL_COUNT_DDMCONTENT_WHERE = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent WHERE ";
2966 private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmContent.uuid IS NULL";
2967 private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmContent.uuid = ?";
2968 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?)";
2969 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmContent.uuid IS NULL AND ";
2970 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmContent.uuid = ? AND ";
2971 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?) AND ";
2972 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmContent.groupId = ?";
2973 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmContent.uuid IS NULL AND ";
2974 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmContent.uuid = ? AND ";
2975 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?) AND ";
2976 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmContent.companyId = ?";
2977 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmContent.groupId = ?";
2978 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "ddmContent.companyId = ?";
2979 private static final String _ORDER_BY_ENTITY_ALIAS = "ddmContent.";
2980 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMContent exists with the primary key ";
2981 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMContent exists with the key {";
2982 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2983 private static Log _log = LogFactoryUtil.getLog(DDMContentPersistenceImpl.class);
2984 private static DDMContent _nullDDMContent = new DDMContentImpl() {
2985 @Override
2986 public Object clone() {
2987 return this;
2988 }
2989
2990 @Override
2991 public CacheModel<DDMContent> toCacheModel() {
2992 return _nullDDMContentCacheModel;
2993 }
2994 };
2995
2996 private static CacheModel<DDMContent> _nullDDMContentCacheModel = new CacheModel<DDMContent>() {
2997 public DDMContent toEntityModel() {
2998 return _nullDDMContent;
2999 }
3000 };
3001 }