001
014
015 package com.liferay.portlet.dynamicdatamapping.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.SQLQuery;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.ArrayUtil;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.SetUtil;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042 import com.liferay.portal.service.persistence.impl.TableMapper;
043 import com.liferay.portal.service.persistence.impl.TableMapperFactory;
044
045 import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryTypePersistence;
046 import com.liferay.portlet.dynamicdatamapping.NoSuchStructureException;
047 import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
048 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureImpl;
049 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl;
050 import com.liferay.portlet.dynamicdatamapping.service.persistence.DDMStructurePersistence;
051 import com.liferay.portlet.journal.service.persistence.JournalFolderPersistence;
052
053 import java.io.Serializable;
054
055 import java.util.Collections;
056 import java.util.HashMap;
057 import java.util.HashSet;
058 import java.util.Iterator;
059 import java.util.List;
060 import java.util.Map;
061 import java.util.Set;
062
063
075 @ProviderType
076 public class DDMStructurePersistenceImpl extends BasePersistenceImpl<DDMStructure>
077 implements DDMStructurePersistence {
078
083 public static final String FINDER_CLASS_NAME_ENTITY = DDMStructureImpl.class.getName();
084 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085 ".List1";
086 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
087 ".List2";
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
089 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
090 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
092 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
094 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
095 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
097 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
098 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
099 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
100 new String[] {
101 String.class.getName(),
102
103 Integer.class.getName(), Integer.class.getName(),
104 OrderByComparator.class.getName()
105 });
106 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
107 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
109 new String[] { String.class.getName() },
110 DDMStructureModelImpl.UUID_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
112 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
114 new String[] { String.class.getName() });
115
116
122 @Override
123 public List<DDMStructure> findByUuid(String uuid) {
124 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125 }
126
127
139 @Override
140 public List<DDMStructure> findByUuid(String uuid, int start, int end) {
141 return findByUuid(uuid, start, end, null);
142 }
143
144
157 @Override
158 public List<DDMStructure> findByUuid(String uuid, int start, int end,
159 OrderByComparator<DDMStructure> orderByComparator) {
160 boolean pagination = true;
161 FinderPath finderPath = null;
162 Object[] finderArgs = null;
163
164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165 (orderByComparator == null)) {
166 pagination = false;
167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid };
169 }
170 else {
171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
172 finderArgs = new Object[] { uuid, start, end, orderByComparator };
173 }
174
175 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
176 finderArgs, this);
177
178 if ((list != null) && !list.isEmpty()) {
179 for (DDMStructure ddmStructure : list) {
180 if (!Validator.equals(uuid, ddmStructure.getUuid())) {
181 list = null;
182
183 break;
184 }
185 }
186 }
187
188 if (list == null) {
189 StringBundler query = null;
190
191 if (orderByComparator != null) {
192 query = new StringBundler(3 +
193 (orderByComparator.getOrderByFields().length * 3));
194 }
195 else {
196 query = new StringBundler(3);
197 }
198
199 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
200
201 boolean bindUuid = false;
202
203 if (uuid == null) {
204 query.append(_FINDER_COLUMN_UUID_UUID_1);
205 }
206 else if (uuid.equals(StringPool.BLANK)) {
207 query.append(_FINDER_COLUMN_UUID_UUID_3);
208 }
209 else {
210 bindUuid = true;
211
212 query.append(_FINDER_COLUMN_UUID_UUID_2);
213 }
214
215 if (orderByComparator != null) {
216 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
217 orderByComparator);
218 }
219 else
220 if (pagination) {
221 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
222 }
223
224 String sql = query.toString();
225
226 Session session = null;
227
228 try {
229 session = openSession();
230
231 Query q = session.createQuery(sql);
232
233 QueryPos qPos = QueryPos.getInstance(q);
234
235 if (bindUuid) {
236 qPos.add(uuid);
237 }
238
239 if (!pagination) {
240 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
241 start, end, false);
242
243 Collections.sort(list);
244
245 list = Collections.unmodifiableList(list);
246 }
247 else {
248 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
249 start, end);
250 }
251
252 cacheResult(list);
253
254 FinderCacheUtil.putResult(finderPath, finderArgs, list);
255 }
256 catch (Exception e) {
257 FinderCacheUtil.removeResult(finderPath, finderArgs);
258
259 throw processException(e);
260 }
261 finally {
262 closeSession(session);
263 }
264 }
265
266 return list;
267 }
268
269
277 @Override
278 public DDMStructure findByUuid_First(String uuid,
279 OrderByComparator<DDMStructure> orderByComparator)
280 throws NoSuchStructureException {
281 DDMStructure ddmStructure = fetchByUuid_First(uuid, orderByComparator);
282
283 if (ddmStructure != null) {
284 return ddmStructure;
285 }
286
287 StringBundler msg = new StringBundler(4);
288
289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
290
291 msg.append("uuid=");
292 msg.append(uuid);
293
294 msg.append(StringPool.CLOSE_CURLY_BRACE);
295
296 throw new NoSuchStructureException(msg.toString());
297 }
298
299
306 @Override
307 public DDMStructure fetchByUuid_First(String uuid,
308 OrderByComparator<DDMStructure> orderByComparator) {
309 List<DDMStructure> list = findByUuid(uuid, 0, 1, orderByComparator);
310
311 if (!list.isEmpty()) {
312 return list.get(0);
313 }
314
315 return null;
316 }
317
318
326 @Override
327 public DDMStructure findByUuid_Last(String uuid,
328 OrderByComparator<DDMStructure> orderByComparator)
329 throws NoSuchStructureException {
330 DDMStructure ddmStructure = fetchByUuid_Last(uuid, orderByComparator);
331
332 if (ddmStructure != null) {
333 return ddmStructure;
334 }
335
336 StringBundler msg = new StringBundler(4);
337
338 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
339
340 msg.append("uuid=");
341 msg.append(uuid);
342
343 msg.append(StringPool.CLOSE_CURLY_BRACE);
344
345 throw new NoSuchStructureException(msg.toString());
346 }
347
348
355 @Override
356 public DDMStructure fetchByUuid_Last(String uuid,
357 OrderByComparator<DDMStructure> orderByComparator) {
358 int count = countByUuid(uuid);
359
360 if (count == 0) {
361 return null;
362 }
363
364 List<DDMStructure> list = findByUuid(uuid, count - 1, count,
365 orderByComparator);
366
367 if (!list.isEmpty()) {
368 return list.get(0);
369 }
370
371 return null;
372 }
373
374
383 @Override
384 public DDMStructure[] findByUuid_PrevAndNext(long structureId, String uuid,
385 OrderByComparator<DDMStructure> orderByComparator)
386 throws NoSuchStructureException {
387 DDMStructure ddmStructure = findByPrimaryKey(structureId);
388
389 Session session = null;
390
391 try {
392 session = openSession();
393
394 DDMStructure[] array = new DDMStructureImpl[3];
395
396 array[0] = getByUuid_PrevAndNext(session, ddmStructure, uuid,
397 orderByComparator, true);
398
399 array[1] = ddmStructure;
400
401 array[2] = getByUuid_PrevAndNext(session, ddmStructure, uuid,
402 orderByComparator, false);
403
404 return array;
405 }
406 catch (Exception e) {
407 throw processException(e);
408 }
409 finally {
410 closeSession(session);
411 }
412 }
413
414 protected DDMStructure getByUuid_PrevAndNext(Session session,
415 DDMStructure ddmStructure, String uuid,
416 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
417 StringBundler query = null;
418
419 if (orderByComparator != null) {
420 query = new StringBundler(6 +
421 (orderByComparator.getOrderByFields().length * 6));
422 }
423 else {
424 query = new StringBundler(3);
425 }
426
427 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
428
429 boolean bindUuid = false;
430
431 if (uuid == null) {
432 query.append(_FINDER_COLUMN_UUID_UUID_1);
433 }
434 else if (uuid.equals(StringPool.BLANK)) {
435 query.append(_FINDER_COLUMN_UUID_UUID_3);
436 }
437 else {
438 bindUuid = true;
439
440 query.append(_FINDER_COLUMN_UUID_UUID_2);
441 }
442
443 if (orderByComparator != null) {
444 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
445
446 if (orderByConditionFields.length > 0) {
447 query.append(WHERE_AND);
448 }
449
450 for (int i = 0; i < orderByConditionFields.length; i++) {
451 query.append(_ORDER_BY_ENTITY_ALIAS);
452 query.append(orderByConditionFields[i]);
453
454 if ((i + 1) < orderByConditionFields.length) {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(WHERE_GREATER_THAN_HAS_NEXT);
457 }
458 else {
459 query.append(WHERE_LESSER_THAN_HAS_NEXT);
460 }
461 }
462 else {
463 if (orderByComparator.isAscending() ^ previous) {
464 query.append(WHERE_GREATER_THAN);
465 }
466 else {
467 query.append(WHERE_LESSER_THAN);
468 }
469 }
470 }
471
472 query.append(ORDER_BY_CLAUSE);
473
474 String[] orderByFields = orderByComparator.getOrderByFields();
475
476 for (int i = 0; i < orderByFields.length; i++) {
477 query.append(_ORDER_BY_ENTITY_ALIAS);
478 query.append(orderByFields[i]);
479
480 if ((i + 1) < orderByFields.length) {
481 if (orderByComparator.isAscending() ^ previous) {
482 query.append(ORDER_BY_ASC_HAS_NEXT);
483 }
484 else {
485 query.append(ORDER_BY_DESC_HAS_NEXT);
486 }
487 }
488 else {
489 if (orderByComparator.isAscending() ^ previous) {
490 query.append(ORDER_BY_ASC);
491 }
492 else {
493 query.append(ORDER_BY_DESC);
494 }
495 }
496 }
497 }
498 else {
499 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
500 }
501
502 String sql = query.toString();
503
504 Query q = session.createQuery(sql);
505
506 q.setFirstResult(0);
507 q.setMaxResults(2);
508
509 QueryPos qPos = QueryPos.getInstance(q);
510
511 if (bindUuid) {
512 qPos.add(uuid);
513 }
514
515 if (orderByComparator != null) {
516 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
517
518 for (Object value : values) {
519 qPos.add(value);
520 }
521 }
522
523 List<DDMStructure> list = q.list();
524
525 if (list.size() == 2) {
526 return list.get(1);
527 }
528 else {
529 return null;
530 }
531 }
532
533
538 @Override
539 public void removeByUuid(String uuid) {
540 for (DDMStructure ddmStructure : findByUuid(uuid, QueryUtil.ALL_POS,
541 QueryUtil.ALL_POS, null)) {
542 remove(ddmStructure);
543 }
544 }
545
546
552 @Override
553 public int countByUuid(String uuid) {
554 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
555
556 Object[] finderArgs = new Object[] { uuid };
557
558 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
559 this);
560
561 if (count == null) {
562 StringBundler query = new StringBundler(2);
563
564 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
565
566 boolean bindUuid = false;
567
568 if (uuid == null) {
569 query.append(_FINDER_COLUMN_UUID_UUID_1);
570 }
571 else if (uuid.equals(StringPool.BLANK)) {
572 query.append(_FINDER_COLUMN_UUID_UUID_3);
573 }
574 else {
575 bindUuid = true;
576
577 query.append(_FINDER_COLUMN_UUID_UUID_2);
578 }
579
580 String sql = query.toString();
581
582 Session session = null;
583
584 try {
585 session = openSession();
586
587 Query q = session.createQuery(sql);
588
589 QueryPos qPos = QueryPos.getInstance(q);
590
591 if (bindUuid) {
592 qPos.add(uuid);
593 }
594
595 count = (Long)q.uniqueResult();
596
597 FinderCacheUtil.putResult(finderPath, finderArgs, count);
598 }
599 catch (Exception e) {
600 FinderCacheUtil.removeResult(finderPath, finderArgs);
601
602 throw processException(e);
603 }
604 finally {
605 closeSession(session);
606 }
607 }
608
609 return count.intValue();
610 }
611
612 private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmStructure.uuid IS NULL";
613 private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmStructure.uuid = ?";
614 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '')";
615 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
616 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
617 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
618 new String[] { String.class.getName(), Long.class.getName() },
619 DDMStructureModelImpl.UUID_COLUMN_BITMASK |
620 DDMStructureModelImpl.GROUPID_COLUMN_BITMASK);
621 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
622 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
623 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
624 new String[] { String.class.getName(), Long.class.getName() });
625
626
634 @Override
635 public DDMStructure findByUUID_G(String uuid, long groupId)
636 throws NoSuchStructureException {
637 DDMStructure ddmStructure = fetchByUUID_G(uuid, groupId);
638
639 if (ddmStructure == null) {
640 StringBundler msg = new StringBundler(6);
641
642 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
643
644 msg.append("uuid=");
645 msg.append(uuid);
646
647 msg.append(", groupId=");
648 msg.append(groupId);
649
650 msg.append(StringPool.CLOSE_CURLY_BRACE);
651
652 if (_log.isWarnEnabled()) {
653 _log.warn(msg.toString());
654 }
655
656 throw new NoSuchStructureException(msg.toString());
657 }
658
659 return ddmStructure;
660 }
661
662
669 @Override
670 public DDMStructure fetchByUUID_G(String uuid, long groupId) {
671 return fetchByUUID_G(uuid, groupId, true);
672 }
673
674
682 @Override
683 public DDMStructure fetchByUUID_G(String uuid, long groupId,
684 boolean retrieveFromCache) {
685 Object[] finderArgs = new Object[] { uuid, groupId };
686
687 Object result = null;
688
689 if (retrieveFromCache) {
690 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
691 finderArgs, this);
692 }
693
694 if (result instanceof DDMStructure) {
695 DDMStructure ddmStructure = (DDMStructure)result;
696
697 if (!Validator.equals(uuid, ddmStructure.getUuid()) ||
698 (groupId != ddmStructure.getGroupId())) {
699 result = null;
700 }
701 }
702
703 if (result == null) {
704 StringBundler query = new StringBundler(4);
705
706 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
707
708 boolean bindUuid = false;
709
710 if (uuid == null) {
711 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
712 }
713 else if (uuid.equals(StringPool.BLANK)) {
714 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
715 }
716 else {
717 bindUuid = true;
718
719 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
720 }
721
722 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
723
724 String sql = query.toString();
725
726 Session session = null;
727
728 try {
729 session = openSession();
730
731 Query q = session.createQuery(sql);
732
733 QueryPos qPos = QueryPos.getInstance(q);
734
735 if (bindUuid) {
736 qPos.add(uuid);
737 }
738
739 qPos.add(groupId);
740
741 List<DDMStructure> list = q.list();
742
743 if (list.isEmpty()) {
744 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
745 finderArgs, list);
746 }
747 else {
748 DDMStructure ddmStructure = list.get(0);
749
750 result = ddmStructure;
751
752 cacheResult(ddmStructure);
753
754 if ((ddmStructure.getUuid() == null) ||
755 !ddmStructure.getUuid().equals(uuid) ||
756 (ddmStructure.getGroupId() != groupId)) {
757 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
758 finderArgs, ddmStructure);
759 }
760 }
761 }
762 catch (Exception e) {
763 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
764 finderArgs);
765
766 throw processException(e);
767 }
768 finally {
769 closeSession(session);
770 }
771 }
772
773 if (result instanceof List<?>) {
774 return null;
775 }
776 else {
777 return (DDMStructure)result;
778 }
779 }
780
781
788 @Override
789 public DDMStructure removeByUUID_G(String uuid, long groupId)
790 throws NoSuchStructureException {
791 DDMStructure ddmStructure = findByUUID_G(uuid, groupId);
792
793 return remove(ddmStructure);
794 }
795
796
803 @Override
804 public int countByUUID_G(String uuid, long groupId) {
805 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
806
807 Object[] finderArgs = new Object[] { uuid, groupId };
808
809 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
810 this);
811
812 if (count == null) {
813 StringBundler query = new StringBundler(3);
814
815 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
816
817 boolean bindUuid = false;
818
819 if (uuid == null) {
820 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
821 }
822 else if (uuid.equals(StringPool.BLANK)) {
823 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
824 }
825 else {
826 bindUuid = true;
827
828 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
829 }
830
831 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
832
833 String sql = query.toString();
834
835 Session session = null;
836
837 try {
838 session = openSession();
839
840 Query q = session.createQuery(sql);
841
842 QueryPos qPos = QueryPos.getInstance(q);
843
844 if (bindUuid) {
845 qPos.add(uuid);
846 }
847
848 qPos.add(groupId);
849
850 count = (Long)q.uniqueResult();
851
852 FinderCacheUtil.putResult(finderPath, finderArgs, count);
853 }
854 catch (Exception e) {
855 FinderCacheUtil.removeResult(finderPath, finderArgs);
856
857 throw processException(e);
858 }
859 finally {
860 closeSession(session);
861 }
862 }
863
864 return count.intValue();
865 }
866
867 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmStructure.uuid IS NULL AND ";
868 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmStructure.uuid = ? AND ";
869 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '') AND ";
870 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmStructure.groupId = ?";
871 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
872 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
873 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
874 new String[] {
875 String.class.getName(), Long.class.getName(),
876
877 Integer.class.getName(), Integer.class.getName(),
878 OrderByComparator.class.getName()
879 });
880 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
881 new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
882 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
883 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
884 new String[] { String.class.getName(), Long.class.getName() },
885 DDMStructureModelImpl.UUID_COLUMN_BITMASK |
886 DDMStructureModelImpl.COMPANYID_COLUMN_BITMASK);
887 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
888 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
889 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
890 new String[] { String.class.getName(), Long.class.getName() });
891
892
899 @Override
900 public List<DDMStructure> findByUuid_C(String uuid, long companyId) {
901 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
902 QueryUtil.ALL_POS, null);
903 }
904
905
918 @Override
919 public List<DDMStructure> findByUuid_C(String uuid, long companyId,
920 int start, int end) {
921 return findByUuid_C(uuid, companyId, start, end, null);
922 }
923
924
938 @Override
939 public List<DDMStructure> findByUuid_C(String uuid, long companyId,
940 int start, int end, OrderByComparator<DDMStructure> orderByComparator) {
941 boolean pagination = true;
942 FinderPath finderPath = null;
943 Object[] finderArgs = null;
944
945 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
946 (orderByComparator == null)) {
947 pagination = false;
948 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
949 finderArgs = new Object[] { uuid, companyId };
950 }
951 else {
952 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
953 finderArgs = new Object[] {
954 uuid, companyId,
955
956 start, end, orderByComparator
957 };
958 }
959
960 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
961 finderArgs, this);
962
963 if ((list != null) && !list.isEmpty()) {
964 for (DDMStructure ddmStructure : list) {
965 if (!Validator.equals(uuid, ddmStructure.getUuid()) ||
966 (companyId != ddmStructure.getCompanyId())) {
967 list = null;
968
969 break;
970 }
971 }
972 }
973
974 if (list == null) {
975 StringBundler query = null;
976
977 if (orderByComparator != null) {
978 query = new StringBundler(4 +
979 (orderByComparator.getOrderByFields().length * 3));
980 }
981 else {
982 query = new StringBundler(4);
983 }
984
985 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
986
987 boolean bindUuid = false;
988
989 if (uuid == null) {
990 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
991 }
992 else if (uuid.equals(StringPool.BLANK)) {
993 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
994 }
995 else {
996 bindUuid = true;
997
998 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
999 }
1000
1001 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1002
1003 if (orderByComparator != null) {
1004 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1005 orderByComparator);
1006 }
1007 else
1008 if (pagination) {
1009 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1010 }
1011
1012 String sql = query.toString();
1013
1014 Session session = null;
1015
1016 try {
1017 session = openSession();
1018
1019 Query q = session.createQuery(sql);
1020
1021 QueryPos qPos = QueryPos.getInstance(q);
1022
1023 if (bindUuid) {
1024 qPos.add(uuid);
1025 }
1026
1027 qPos.add(companyId);
1028
1029 if (!pagination) {
1030 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1031 start, end, false);
1032
1033 Collections.sort(list);
1034
1035 list = Collections.unmodifiableList(list);
1036 }
1037 else {
1038 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1039 start, end);
1040 }
1041
1042 cacheResult(list);
1043
1044 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1045 }
1046 catch (Exception e) {
1047 FinderCacheUtil.removeResult(finderPath, finderArgs);
1048
1049 throw processException(e);
1050 }
1051 finally {
1052 closeSession(session);
1053 }
1054 }
1055
1056 return list;
1057 }
1058
1059
1068 @Override
1069 public DDMStructure findByUuid_C_First(String uuid, long companyId,
1070 OrderByComparator<DDMStructure> orderByComparator)
1071 throws NoSuchStructureException {
1072 DDMStructure ddmStructure = fetchByUuid_C_First(uuid, companyId,
1073 orderByComparator);
1074
1075 if (ddmStructure != null) {
1076 return ddmStructure;
1077 }
1078
1079 StringBundler msg = new StringBundler(6);
1080
1081 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1082
1083 msg.append("uuid=");
1084 msg.append(uuid);
1085
1086 msg.append(", companyId=");
1087 msg.append(companyId);
1088
1089 msg.append(StringPool.CLOSE_CURLY_BRACE);
1090
1091 throw new NoSuchStructureException(msg.toString());
1092 }
1093
1094
1102 @Override
1103 public DDMStructure fetchByUuid_C_First(String uuid, long companyId,
1104 OrderByComparator<DDMStructure> orderByComparator) {
1105 List<DDMStructure> list = findByUuid_C(uuid, companyId, 0, 1,
1106 orderByComparator);
1107
1108 if (!list.isEmpty()) {
1109 return list.get(0);
1110 }
1111
1112 return null;
1113 }
1114
1115
1124 @Override
1125 public DDMStructure findByUuid_C_Last(String uuid, long companyId,
1126 OrderByComparator<DDMStructure> orderByComparator)
1127 throws NoSuchStructureException {
1128 DDMStructure ddmStructure = fetchByUuid_C_Last(uuid, companyId,
1129 orderByComparator);
1130
1131 if (ddmStructure != null) {
1132 return ddmStructure;
1133 }
1134
1135 StringBundler msg = new StringBundler(6);
1136
1137 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1138
1139 msg.append("uuid=");
1140 msg.append(uuid);
1141
1142 msg.append(", companyId=");
1143 msg.append(companyId);
1144
1145 msg.append(StringPool.CLOSE_CURLY_BRACE);
1146
1147 throw new NoSuchStructureException(msg.toString());
1148 }
1149
1150
1158 @Override
1159 public DDMStructure fetchByUuid_C_Last(String uuid, long companyId,
1160 OrderByComparator<DDMStructure> orderByComparator) {
1161 int count = countByUuid_C(uuid, companyId);
1162
1163 if (count == 0) {
1164 return null;
1165 }
1166
1167 List<DDMStructure> list = findByUuid_C(uuid, companyId, count - 1,
1168 count, orderByComparator);
1169
1170 if (!list.isEmpty()) {
1171 return list.get(0);
1172 }
1173
1174 return null;
1175 }
1176
1177
1187 @Override
1188 public DDMStructure[] findByUuid_C_PrevAndNext(long structureId,
1189 String uuid, long companyId,
1190 OrderByComparator<DDMStructure> orderByComparator)
1191 throws NoSuchStructureException {
1192 DDMStructure ddmStructure = findByPrimaryKey(structureId);
1193
1194 Session session = null;
1195
1196 try {
1197 session = openSession();
1198
1199 DDMStructure[] array = new DDMStructureImpl[3];
1200
1201 array[0] = getByUuid_C_PrevAndNext(session, ddmStructure, uuid,
1202 companyId, orderByComparator, true);
1203
1204 array[1] = ddmStructure;
1205
1206 array[2] = getByUuid_C_PrevAndNext(session, ddmStructure, uuid,
1207 companyId, orderByComparator, false);
1208
1209 return array;
1210 }
1211 catch (Exception e) {
1212 throw processException(e);
1213 }
1214 finally {
1215 closeSession(session);
1216 }
1217 }
1218
1219 protected DDMStructure getByUuid_C_PrevAndNext(Session session,
1220 DDMStructure ddmStructure, String uuid, long companyId,
1221 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
1222 StringBundler query = null;
1223
1224 if (orderByComparator != null) {
1225 query = new StringBundler(6 +
1226 (orderByComparator.getOrderByFields().length * 6));
1227 }
1228 else {
1229 query = new StringBundler(3);
1230 }
1231
1232 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1233
1234 boolean bindUuid = false;
1235
1236 if (uuid == null) {
1237 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1238 }
1239 else if (uuid.equals(StringPool.BLANK)) {
1240 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1241 }
1242 else {
1243 bindUuid = true;
1244
1245 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1246 }
1247
1248 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1249
1250 if (orderByComparator != null) {
1251 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1252
1253 if (orderByConditionFields.length > 0) {
1254 query.append(WHERE_AND);
1255 }
1256
1257 for (int i = 0; i < orderByConditionFields.length; i++) {
1258 query.append(_ORDER_BY_ENTITY_ALIAS);
1259 query.append(orderByConditionFields[i]);
1260
1261 if ((i + 1) < orderByConditionFields.length) {
1262 if (orderByComparator.isAscending() ^ previous) {
1263 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1264 }
1265 else {
1266 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1267 }
1268 }
1269 else {
1270 if (orderByComparator.isAscending() ^ previous) {
1271 query.append(WHERE_GREATER_THAN);
1272 }
1273 else {
1274 query.append(WHERE_LESSER_THAN);
1275 }
1276 }
1277 }
1278
1279 query.append(ORDER_BY_CLAUSE);
1280
1281 String[] orderByFields = orderByComparator.getOrderByFields();
1282
1283 for (int i = 0; i < orderByFields.length; i++) {
1284 query.append(_ORDER_BY_ENTITY_ALIAS);
1285 query.append(orderByFields[i]);
1286
1287 if ((i + 1) < orderByFields.length) {
1288 if (orderByComparator.isAscending() ^ previous) {
1289 query.append(ORDER_BY_ASC_HAS_NEXT);
1290 }
1291 else {
1292 query.append(ORDER_BY_DESC_HAS_NEXT);
1293 }
1294 }
1295 else {
1296 if (orderByComparator.isAscending() ^ previous) {
1297 query.append(ORDER_BY_ASC);
1298 }
1299 else {
1300 query.append(ORDER_BY_DESC);
1301 }
1302 }
1303 }
1304 }
1305 else {
1306 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1307 }
1308
1309 String sql = query.toString();
1310
1311 Query q = session.createQuery(sql);
1312
1313 q.setFirstResult(0);
1314 q.setMaxResults(2);
1315
1316 QueryPos qPos = QueryPos.getInstance(q);
1317
1318 if (bindUuid) {
1319 qPos.add(uuid);
1320 }
1321
1322 qPos.add(companyId);
1323
1324 if (orderByComparator != null) {
1325 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1326
1327 for (Object value : values) {
1328 qPos.add(value);
1329 }
1330 }
1331
1332 List<DDMStructure> list = q.list();
1333
1334 if (list.size() == 2) {
1335 return list.get(1);
1336 }
1337 else {
1338 return null;
1339 }
1340 }
1341
1342
1348 @Override
1349 public void removeByUuid_C(String uuid, long companyId) {
1350 for (DDMStructure ddmStructure : findByUuid_C(uuid, companyId,
1351 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1352 remove(ddmStructure);
1353 }
1354 }
1355
1356
1363 @Override
1364 public int countByUuid_C(String uuid, long companyId) {
1365 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1366
1367 Object[] finderArgs = new Object[] { uuid, companyId };
1368
1369 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1370 this);
1371
1372 if (count == null) {
1373 StringBundler query = new StringBundler(3);
1374
1375 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
1376
1377 boolean bindUuid = false;
1378
1379 if (uuid == null) {
1380 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1381 }
1382 else if (uuid.equals(StringPool.BLANK)) {
1383 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1384 }
1385 else {
1386 bindUuid = true;
1387
1388 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1389 }
1390
1391 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1392
1393 String sql = query.toString();
1394
1395 Session session = null;
1396
1397 try {
1398 session = openSession();
1399
1400 Query q = session.createQuery(sql);
1401
1402 QueryPos qPos = QueryPos.getInstance(q);
1403
1404 if (bindUuid) {
1405 qPos.add(uuid);
1406 }
1407
1408 qPos.add(companyId);
1409
1410 count = (Long)q.uniqueResult();
1411
1412 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1413 }
1414 catch (Exception e) {
1415 FinderCacheUtil.removeResult(finderPath, finderArgs);
1416
1417 throw processException(e);
1418 }
1419 finally {
1420 closeSession(session);
1421 }
1422 }
1423
1424 return count.intValue();
1425 }
1426
1427 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmStructure.uuid IS NULL AND ";
1428 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmStructure.uuid = ? AND ";
1429 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '') AND ";
1430 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmStructure.companyId = ?";
1431 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1432 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
1433 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1434 new String[] {
1435 Long.class.getName(),
1436
1437 Integer.class.getName(), Integer.class.getName(),
1438 OrderByComparator.class.getName()
1439 });
1440 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1441 new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1442 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
1443 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1444 new String[] { Long.class.getName() },
1445 DDMStructureModelImpl.GROUPID_COLUMN_BITMASK);
1446 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1447 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
1448 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1449 new String[] { Long.class.getName() });
1450 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1451 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
1452 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByGroupId",
1453 new String[] { Long.class.getName() });
1454
1455
1461 @Override
1462 public List<DDMStructure> findByGroupId(long groupId) {
1463 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1464 }
1465
1466
1478 @Override
1479 public List<DDMStructure> findByGroupId(long groupId, int start, int end) {
1480 return findByGroupId(groupId, start, end, null);
1481 }
1482
1483
1496 @Override
1497 public List<DDMStructure> findByGroupId(long groupId, int start, int end,
1498 OrderByComparator<DDMStructure> orderByComparator) {
1499 boolean pagination = true;
1500 FinderPath finderPath = null;
1501 Object[] finderArgs = null;
1502
1503 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1504 (orderByComparator == null)) {
1505 pagination = false;
1506 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1507 finderArgs = new Object[] { groupId };
1508 }
1509 else {
1510 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1511 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1512 }
1513
1514 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
1515 finderArgs, this);
1516
1517 if ((list != null) && !list.isEmpty()) {
1518 for (DDMStructure ddmStructure : list) {
1519 if ((groupId != ddmStructure.getGroupId())) {
1520 list = null;
1521
1522 break;
1523 }
1524 }
1525 }
1526
1527 if (list == null) {
1528 StringBundler query = null;
1529
1530 if (orderByComparator != null) {
1531 query = new StringBundler(3 +
1532 (orderByComparator.getOrderByFields().length * 3));
1533 }
1534 else {
1535 query = new StringBundler(3);
1536 }
1537
1538 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1539
1540 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1541
1542 if (orderByComparator != null) {
1543 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1544 orderByComparator);
1545 }
1546 else
1547 if (pagination) {
1548 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1549 }
1550
1551 String sql = query.toString();
1552
1553 Session session = null;
1554
1555 try {
1556 session = openSession();
1557
1558 Query q = session.createQuery(sql);
1559
1560 QueryPos qPos = QueryPos.getInstance(q);
1561
1562 qPos.add(groupId);
1563
1564 if (!pagination) {
1565 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1566 start, end, false);
1567
1568 Collections.sort(list);
1569
1570 list = Collections.unmodifiableList(list);
1571 }
1572 else {
1573 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1574 start, end);
1575 }
1576
1577 cacheResult(list);
1578
1579 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1580 }
1581 catch (Exception e) {
1582 FinderCacheUtil.removeResult(finderPath, finderArgs);
1583
1584 throw processException(e);
1585 }
1586 finally {
1587 closeSession(session);
1588 }
1589 }
1590
1591 return list;
1592 }
1593
1594
1602 @Override
1603 public DDMStructure findByGroupId_First(long groupId,
1604 OrderByComparator<DDMStructure> orderByComparator)
1605 throws NoSuchStructureException {
1606 DDMStructure ddmStructure = fetchByGroupId_First(groupId,
1607 orderByComparator);
1608
1609 if (ddmStructure != null) {
1610 return ddmStructure;
1611 }
1612
1613 StringBundler msg = new StringBundler(4);
1614
1615 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1616
1617 msg.append("groupId=");
1618 msg.append(groupId);
1619
1620 msg.append(StringPool.CLOSE_CURLY_BRACE);
1621
1622 throw new NoSuchStructureException(msg.toString());
1623 }
1624
1625
1632 @Override
1633 public DDMStructure fetchByGroupId_First(long groupId,
1634 OrderByComparator<DDMStructure> orderByComparator) {
1635 List<DDMStructure> list = findByGroupId(groupId, 0, 1, orderByComparator);
1636
1637 if (!list.isEmpty()) {
1638 return list.get(0);
1639 }
1640
1641 return null;
1642 }
1643
1644
1652 @Override
1653 public DDMStructure findByGroupId_Last(long groupId,
1654 OrderByComparator<DDMStructure> orderByComparator)
1655 throws NoSuchStructureException {
1656 DDMStructure ddmStructure = fetchByGroupId_Last(groupId,
1657 orderByComparator);
1658
1659 if (ddmStructure != null) {
1660 return ddmStructure;
1661 }
1662
1663 StringBundler msg = new StringBundler(4);
1664
1665 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1666
1667 msg.append("groupId=");
1668 msg.append(groupId);
1669
1670 msg.append(StringPool.CLOSE_CURLY_BRACE);
1671
1672 throw new NoSuchStructureException(msg.toString());
1673 }
1674
1675
1682 @Override
1683 public DDMStructure fetchByGroupId_Last(long groupId,
1684 OrderByComparator<DDMStructure> orderByComparator) {
1685 int count = countByGroupId(groupId);
1686
1687 if (count == 0) {
1688 return null;
1689 }
1690
1691 List<DDMStructure> list = findByGroupId(groupId, count - 1, count,
1692 orderByComparator);
1693
1694 if (!list.isEmpty()) {
1695 return list.get(0);
1696 }
1697
1698 return null;
1699 }
1700
1701
1710 @Override
1711 public DDMStructure[] findByGroupId_PrevAndNext(long structureId,
1712 long groupId, OrderByComparator<DDMStructure> orderByComparator)
1713 throws NoSuchStructureException {
1714 DDMStructure ddmStructure = findByPrimaryKey(structureId);
1715
1716 Session session = null;
1717
1718 try {
1719 session = openSession();
1720
1721 DDMStructure[] array = new DDMStructureImpl[3];
1722
1723 array[0] = getByGroupId_PrevAndNext(session, ddmStructure, groupId,
1724 orderByComparator, true);
1725
1726 array[1] = ddmStructure;
1727
1728 array[2] = getByGroupId_PrevAndNext(session, ddmStructure, groupId,
1729 orderByComparator, false);
1730
1731 return array;
1732 }
1733 catch (Exception e) {
1734 throw processException(e);
1735 }
1736 finally {
1737 closeSession(session);
1738 }
1739 }
1740
1741 protected DDMStructure getByGroupId_PrevAndNext(Session session,
1742 DDMStructure ddmStructure, long groupId,
1743 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
1744 StringBundler query = null;
1745
1746 if (orderByComparator != null) {
1747 query = new StringBundler(6 +
1748 (orderByComparator.getOrderByFields().length * 6));
1749 }
1750 else {
1751 query = new StringBundler(3);
1752 }
1753
1754 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1755
1756 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1757
1758 if (orderByComparator != null) {
1759 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1760
1761 if (orderByConditionFields.length > 0) {
1762 query.append(WHERE_AND);
1763 }
1764
1765 for (int i = 0; i < orderByConditionFields.length; i++) {
1766 query.append(_ORDER_BY_ENTITY_ALIAS);
1767 query.append(orderByConditionFields[i]);
1768
1769 if ((i + 1) < orderByConditionFields.length) {
1770 if (orderByComparator.isAscending() ^ previous) {
1771 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1772 }
1773 else {
1774 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1775 }
1776 }
1777 else {
1778 if (orderByComparator.isAscending() ^ previous) {
1779 query.append(WHERE_GREATER_THAN);
1780 }
1781 else {
1782 query.append(WHERE_LESSER_THAN);
1783 }
1784 }
1785 }
1786
1787 query.append(ORDER_BY_CLAUSE);
1788
1789 String[] orderByFields = orderByComparator.getOrderByFields();
1790
1791 for (int i = 0; i < orderByFields.length; i++) {
1792 query.append(_ORDER_BY_ENTITY_ALIAS);
1793 query.append(orderByFields[i]);
1794
1795 if ((i + 1) < orderByFields.length) {
1796 if (orderByComparator.isAscending() ^ previous) {
1797 query.append(ORDER_BY_ASC_HAS_NEXT);
1798 }
1799 else {
1800 query.append(ORDER_BY_DESC_HAS_NEXT);
1801 }
1802 }
1803 else {
1804 if (orderByComparator.isAscending() ^ previous) {
1805 query.append(ORDER_BY_ASC);
1806 }
1807 else {
1808 query.append(ORDER_BY_DESC);
1809 }
1810 }
1811 }
1812 }
1813 else {
1814 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1815 }
1816
1817 String sql = query.toString();
1818
1819 Query q = session.createQuery(sql);
1820
1821 q.setFirstResult(0);
1822 q.setMaxResults(2);
1823
1824 QueryPos qPos = QueryPos.getInstance(q);
1825
1826 qPos.add(groupId);
1827
1828 if (orderByComparator != null) {
1829 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1830
1831 for (Object value : values) {
1832 qPos.add(value);
1833 }
1834 }
1835
1836 List<DDMStructure> list = q.list();
1837
1838 if (list.size() == 2) {
1839 return list.get(1);
1840 }
1841 else {
1842 return null;
1843 }
1844 }
1845
1846
1852 @Override
1853 public List<DDMStructure> filterFindByGroupId(long groupId) {
1854 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1855 QueryUtil.ALL_POS, null);
1856 }
1857
1858
1870 @Override
1871 public List<DDMStructure> filterFindByGroupId(long groupId, int start,
1872 int end) {
1873 return filterFindByGroupId(groupId, start, end, null);
1874 }
1875
1876
1889 @Override
1890 public List<DDMStructure> filterFindByGroupId(long groupId, int start,
1891 int end, OrderByComparator<DDMStructure> orderByComparator) {
1892 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1893 return findByGroupId(groupId, start, end, orderByComparator);
1894 }
1895
1896 StringBundler query = null;
1897
1898 if (orderByComparator != null) {
1899 query = new StringBundler(3 +
1900 (orderByComparator.getOrderByFields().length * 3));
1901 }
1902 else {
1903 query = new StringBundler(3);
1904 }
1905
1906 if (getDB().isSupportsInlineDistinct()) {
1907 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
1908 }
1909 else {
1910 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
1911 }
1912
1913 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1914
1915 if (!getDB().isSupportsInlineDistinct()) {
1916 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
1917 }
1918
1919 if (orderByComparator != null) {
1920 if (getDB().isSupportsInlineDistinct()) {
1921 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1922 orderByComparator, true);
1923 }
1924 else {
1925 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1926 orderByComparator, true);
1927 }
1928 }
1929 else {
1930 if (getDB().isSupportsInlineDistinct()) {
1931 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1932 }
1933 else {
1934 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
1935 }
1936 }
1937
1938 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1939 DDMStructure.class.getName(),
1940 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1941
1942 Session session = null;
1943
1944 try {
1945 session = openSession();
1946
1947 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1948
1949 if (getDB().isSupportsInlineDistinct()) {
1950 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
1951 }
1952 else {
1953 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
1954 }
1955
1956 QueryPos qPos = QueryPos.getInstance(q);
1957
1958 qPos.add(groupId);
1959
1960 return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
1961 end);
1962 }
1963 catch (Exception e) {
1964 throw processException(e);
1965 }
1966 finally {
1967 closeSession(session);
1968 }
1969 }
1970
1971
1980 @Override
1981 public DDMStructure[] filterFindByGroupId_PrevAndNext(long structureId,
1982 long groupId, OrderByComparator<DDMStructure> orderByComparator)
1983 throws NoSuchStructureException {
1984 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1985 return findByGroupId_PrevAndNext(structureId, groupId,
1986 orderByComparator);
1987 }
1988
1989 DDMStructure ddmStructure = findByPrimaryKey(structureId);
1990
1991 Session session = null;
1992
1993 try {
1994 session = openSession();
1995
1996 DDMStructure[] array = new DDMStructureImpl[3];
1997
1998 array[0] = filterGetByGroupId_PrevAndNext(session, ddmStructure,
1999 groupId, orderByComparator, true);
2000
2001 array[1] = ddmStructure;
2002
2003 array[2] = filterGetByGroupId_PrevAndNext(session, ddmStructure,
2004 groupId, orderByComparator, false);
2005
2006 return array;
2007 }
2008 catch (Exception e) {
2009 throw processException(e);
2010 }
2011 finally {
2012 closeSession(session);
2013 }
2014 }
2015
2016 protected DDMStructure filterGetByGroupId_PrevAndNext(Session session,
2017 DDMStructure ddmStructure, long groupId,
2018 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
2019 StringBundler query = null;
2020
2021 if (orderByComparator != null) {
2022 query = new StringBundler(6 +
2023 (orderByComparator.getOrderByFields().length * 6));
2024 }
2025 else {
2026 query = new StringBundler(3);
2027 }
2028
2029 if (getDB().isSupportsInlineDistinct()) {
2030 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
2031 }
2032 else {
2033 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
2034 }
2035
2036 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2037
2038 if (!getDB().isSupportsInlineDistinct()) {
2039 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
2040 }
2041
2042 if (orderByComparator != null) {
2043 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2044
2045 if (orderByConditionFields.length > 0) {
2046 query.append(WHERE_AND);
2047 }
2048
2049 for (int i = 0; i < orderByConditionFields.length; i++) {
2050 if (getDB().isSupportsInlineDistinct()) {
2051 query.append(_ORDER_BY_ENTITY_ALIAS);
2052 }
2053 else {
2054 query.append(_ORDER_BY_ENTITY_TABLE);
2055 }
2056
2057 query.append(orderByConditionFields[i]);
2058
2059 if ((i + 1) < orderByConditionFields.length) {
2060 if (orderByComparator.isAscending() ^ previous) {
2061 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2062 }
2063 else {
2064 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2065 }
2066 }
2067 else {
2068 if (orderByComparator.isAscending() ^ previous) {
2069 query.append(WHERE_GREATER_THAN);
2070 }
2071 else {
2072 query.append(WHERE_LESSER_THAN);
2073 }
2074 }
2075 }
2076
2077 query.append(ORDER_BY_CLAUSE);
2078
2079 String[] orderByFields = orderByComparator.getOrderByFields();
2080
2081 for (int i = 0; i < orderByFields.length; i++) {
2082 if (getDB().isSupportsInlineDistinct()) {
2083 query.append(_ORDER_BY_ENTITY_ALIAS);
2084 }
2085 else {
2086 query.append(_ORDER_BY_ENTITY_TABLE);
2087 }
2088
2089 query.append(orderByFields[i]);
2090
2091 if ((i + 1) < orderByFields.length) {
2092 if (orderByComparator.isAscending() ^ previous) {
2093 query.append(ORDER_BY_ASC_HAS_NEXT);
2094 }
2095 else {
2096 query.append(ORDER_BY_DESC_HAS_NEXT);
2097 }
2098 }
2099 else {
2100 if (orderByComparator.isAscending() ^ previous) {
2101 query.append(ORDER_BY_ASC);
2102 }
2103 else {
2104 query.append(ORDER_BY_DESC);
2105 }
2106 }
2107 }
2108 }
2109 else {
2110 if (getDB().isSupportsInlineDistinct()) {
2111 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2112 }
2113 else {
2114 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
2115 }
2116 }
2117
2118 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2119 DDMStructure.class.getName(),
2120 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2121
2122 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2123
2124 q.setFirstResult(0);
2125 q.setMaxResults(2);
2126
2127 if (getDB().isSupportsInlineDistinct()) {
2128 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
2129 }
2130 else {
2131 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
2132 }
2133
2134 QueryPos qPos = QueryPos.getInstance(q);
2135
2136 qPos.add(groupId);
2137
2138 if (orderByComparator != null) {
2139 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
2140
2141 for (Object value : values) {
2142 qPos.add(value);
2143 }
2144 }
2145
2146 List<DDMStructure> list = q.list();
2147
2148 if (list.size() == 2) {
2149 return list.get(1);
2150 }
2151 else {
2152 return null;
2153 }
2154 }
2155
2156
2162 @Override
2163 public List<DDMStructure> filterFindByGroupId(long[] groupIds) {
2164 return filterFindByGroupId(groupIds, QueryUtil.ALL_POS,
2165 QueryUtil.ALL_POS, null);
2166 }
2167
2168
2180 @Override
2181 public List<DDMStructure> filterFindByGroupId(long[] groupIds, int start,
2182 int end) {
2183 return filterFindByGroupId(groupIds, start, end, null);
2184 }
2185
2186
2199 @Override
2200 public List<DDMStructure> filterFindByGroupId(long[] groupIds, int start,
2201 int end, OrderByComparator<DDMStructure> orderByComparator) {
2202 if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2203 return findByGroupId(groupIds, start, end, orderByComparator);
2204 }
2205
2206 if (groupIds == null) {
2207 groupIds = new long[0];
2208 }
2209 else {
2210 groupIds = ArrayUtil.unique(groupIds);
2211 }
2212
2213 StringBundler query = new StringBundler();
2214
2215 if (getDB().isSupportsInlineDistinct()) {
2216 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
2217 }
2218 else {
2219 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
2220 }
2221
2222 if (groupIds.length > 0) {
2223 query.append(StringPool.OPEN_PARENTHESIS);
2224
2225 query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
2226
2227 query.append(StringUtil.merge(groupIds));
2228
2229 query.append(StringPool.CLOSE_PARENTHESIS);
2230
2231 query.append(StringPool.CLOSE_PARENTHESIS);
2232 }
2233
2234 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
2235 query.index() - 1);
2236
2237 if (!getDB().isSupportsInlineDistinct()) {
2238 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
2239 }
2240
2241 if (orderByComparator != null) {
2242 if (getDB().isSupportsInlineDistinct()) {
2243 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2244 orderByComparator, true);
2245 }
2246 else {
2247 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2248 orderByComparator, true);
2249 }
2250 }
2251 else {
2252 if (getDB().isSupportsInlineDistinct()) {
2253 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2254 }
2255 else {
2256 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
2257 }
2258 }
2259
2260 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2261 DDMStructure.class.getName(),
2262 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2263
2264 Session session = null;
2265
2266 try {
2267 session = openSession();
2268
2269 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2270
2271 if (getDB().isSupportsInlineDistinct()) {
2272 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
2273 }
2274 else {
2275 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
2276 }
2277
2278 return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
2279 end);
2280 }
2281 catch (Exception e) {
2282 throw processException(e);
2283 }
2284 finally {
2285 closeSession(session);
2286 }
2287 }
2288
2289
2299 @Override
2300 public List<DDMStructure> findByGroupId(long[] groupIds) {
2301 return findByGroupId(groupIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2302 null);
2303 }
2304
2305
2317 @Override
2318 public List<DDMStructure> findByGroupId(long[] groupIds, int start, int end) {
2319 return findByGroupId(groupIds, start, end, null);
2320 }
2321
2322
2335 @Override
2336 public List<DDMStructure> findByGroupId(long[] groupIds, int start,
2337 int end, OrderByComparator<DDMStructure> orderByComparator) {
2338 if (groupIds == null) {
2339 groupIds = new long[0];
2340 }
2341 else {
2342 groupIds = ArrayUtil.unique(groupIds);
2343 }
2344
2345 if (groupIds.length == 1) {
2346 return findByGroupId(groupIds[0], start, end, orderByComparator);
2347 }
2348
2349 boolean pagination = true;
2350 Object[] finderArgs = null;
2351
2352 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2353 (orderByComparator == null)) {
2354 pagination = false;
2355 finderArgs = new Object[] { StringUtil.merge(groupIds) };
2356 }
2357 else {
2358 finderArgs = new Object[] {
2359 StringUtil.merge(groupIds),
2360
2361 start, end, orderByComparator
2362 };
2363 }
2364
2365 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2366 finderArgs, this);
2367
2368 if ((list != null) && !list.isEmpty()) {
2369 for (DDMStructure ddmStructure : list) {
2370 if (!ArrayUtil.contains(groupIds, ddmStructure.getGroupId())) {
2371 list = null;
2372
2373 break;
2374 }
2375 }
2376 }
2377
2378 if (list == null) {
2379 StringBundler query = new StringBundler();
2380
2381 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2382
2383 if (groupIds.length > 0) {
2384 query.append(StringPool.OPEN_PARENTHESIS);
2385
2386 query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
2387
2388 query.append(StringUtil.merge(groupIds));
2389
2390 query.append(StringPool.CLOSE_PARENTHESIS);
2391
2392 query.append(StringPool.CLOSE_PARENTHESIS);
2393 }
2394
2395 query.setStringAt(removeConjunction(query.stringAt(query.index() -
2396 1)), query.index() - 1);
2397
2398 if (orderByComparator != null) {
2399 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2400 orderByComparator);
2401 }
2402 else
2403 if (pagination) {
2404 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2405 }
2406
2407 String sql = query.toString();
2408
2409 Session session = null;
2410
2411 try {
2412 session = openSession();
2413
2414 Query q = session.createQuery(sql);
2415
2416 if (!pagination) {
2417 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2418 start, end, false);
2419
2420 Collections.sort(list);
2421
2422 list = Collections.unmodifiableList(list);
2423 }
2424 else {
2425 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2426 start, end);
2427 }
2428
2429 cacheResult(list);
2430
2431 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2432 finderArgs, list);
2433 }
2434 catch (Exception e) {
2435 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2436 finderArgs);
2437
2438 throw processException(e);
2439 }
2440 finally {
2441 closeSession(session);
2442 }
2443 }
2444
2445 return list;
2446 }
2447
2448
2453 @Override
2454 public void removeByGroupId(long groupId) {
2455 for (DDMStructure ddmStructure : findByGroupId(groupId,
2456 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2457 remove(ddmStructure);
2458 }
2459 }
2460
2461
2467 @Override
2468 public int countByGroupId(long groupId) {
2469 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2470
2471 Object[] finderArgs = new Object[] { groupId };
2472
2473 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2474 this);
2475
2476 if (count == null) {
2477 StringBundler query = new StringBundler(2);
2478
2479 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
2480
2481 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2482
2483 String sql = query.toString();
2484
2485 Session session = null;
2486
2487 try {
2488 session = openSession();
2489
2490 Query q = session.createQuery(sql);
2491
2492 QueryPos qPos = QueryPos.getInstance(q);
2493
2494 qPos.add(groupId);
2495
2496 count = (Long)q.uniqueResult();
2497
2498 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2499 }
2500 catch (Exception e) {
2501 FinderCacheUtil.removeResult(finderPath, finderArgs);
2502
2503 throw processException(e);
2504 }
2505 finally {
2506 closeSession(session);
2507 }
2508 }
2509
2510 return count.intValue();
2511 }
2512
2513
2519 @Override
2520 public int countByGroupId(long[] groupIds) {
2521 if (groupIds == null) {
2522 groupIds = new long[0];
2523 }
2524 else {
2525 groupIds = ArrayUtil.unique(groupIds);
2526 }
2527
2528 Object[] finderArgs = new Object[] { StringUtil.merge(groupIds) };
2529
2530 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2531 finderArgs, this);
2532
2533 if (count == null) {
2534 StringBundler query = new StringBundler();
2535
2536 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
2537
2538 if (groupIds.length > 0) {
2539 query.append(StringPool.OPEN_PARENTHESIS);
2540
2541 query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
2542
2543 query.append(StringUtil.merge(groupIds));
2544
2545 query.append(StringPool.CLOSE_PARENTHESIS);
2546
2547 query.append(StringPool.CLOSE_PARENTHESIS);
2548 }
2549
2550 query.setStringAt(removeConjunction(query.stringAt(query.index() -
2551 1)), query.index() - 1);
2552
2553 String sql = query.toString();
2554
2555 Session session = null;
2556
2557 try {
2558 session = openSession();
2559
2560 Query q = session.createQuery(sql);
2561
2562 count = (Long)q.uniqueResult();
2563
2564 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2565 finderArgs, count);
2566 }
2567 catch (Exception e) {
2568 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2569 finderArgs);
2570
2571 throw processException(e);
2572 }
2573 finally {
2574 closeSession(session);
2575 }
2576 }
2577
2578 return count.intValue();
2579 }
2580
2581
2587 @Override
2588 public int filterCountByGroupId(long groupId) {
2589 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2590 return countByGroupId(groupId);
2591 }
2592
2593 StringBundler query = new StringBundler(2);
2594
2595 query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
2596
2597 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2598
2599 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2600 DDMStructure.class.getName(),
2601 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2602
2603 Session session = null;
2604
2605 try {
2606 session = openSession();
2607
2608 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2609
2610 q.addScalar(COUNT_COLUMN_NAME,
2611 com.liferay.portal.kernel.dao.orm.Type.LONG);
2612
2613 QueryPos qPos = QueryPos.getInstance(q);
2614
2615 qPos.add(groupId);
2616
2617 Long count = (Long)q.uniqueResult();
2618
2619 return count.intValue();
2620 }
2621 catch (Exception e) {
2622 throw processException(e);
2623 }
2624 finally {
2625 closeSession(session);
2626 }
2627 }
2628
2629
2635 @Override
2636 public int filterCountByGroupId(long[] groupIds) {
2637 if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2638 return countByGroupId(groupIds);
2639 }
2640
2641 if (groupIds == null) {
2642 groupIds = new long[0];
2643 }
2644 else {
2645 groupIds = ArrayUtil.unique(groupIds);
2646 }
2647
2648 StringBundler query = new StringBundler();
2649
2650 query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
2651
2652 if (groupIds.length > 0) {
2653 query.append(StringPool.OPEN_PARENTHESIS);
2654
2655 query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
2656
2657 query.append(StringUtil.merge(groupIds));
2658
2659 query.append(StringPool.CLOSE_PARENTHESIS);
2660
2661 query.append(StringPool.CLOSE_PARENTHESIS);
2662 }
2663
2664 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
2665 query.index() - 1);
2666
2667 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2668 DDMStructure.class.getName(),
2669 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2670
2671 Session session = null;
2672
2673 try {
2674 session = openSession();
2675
2676 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2677
2678 q.addScalar(COUNT_COLUMN_NAME,
2679 com.liferay.portal.kernel.dao.orm.Type.LONG);
2680
2681 Long count = (Long)q.uniqueResult();
2682
2683 return count.intValue();
2684 }
2685 catch (Exception e) {
2686 throw processException(e);
2687 }
2688 finally {
2689 closeSession(session);
2690 }
2691 }
2692
2693 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmStructure.groupId = ?";
2694 private static final String _FINDER_COLUMN_GROUPID_GROUPID_7 = "ddmStructure.groupId IN (";
2695 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTSTRUCTUREID =
2696 new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2697 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
2698 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByParentStructureId",
2699 new String[] {
2700 Long.class.getName(),
2701
2702 Integer.class.getName(), Integer.class.getName(),
2703 OrderByComparator.class.getName()
2704 });
2705 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID =
2706 new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2707 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
2708 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2709 "findByParentStructureId", new String[] { Long.class.getName() },
2710 DDMStructureModelImpl.PARENTSTRUCTUREID_COLUMN_BITMASK);
2711 public static final FinderPath FINDER_PATH_COUNT_BY_PARENTSTRUCTUREID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2712 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
2713 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2714 "countByParentStructureId", new String[] { Long.class.getName() });
2715
2716
2722 @Override
2723 public List<DDMStructure> findByParentStructureId(long parentStructureId) {
2724 return findByParentStructureId(parentStructureId, QueryUtil.ALL_POS,
2725 QueryUtil.ALL_POS, null);
2726 }
2727
2728
2740 @Override
2741 public List<DDMStructure> findByParentStructureId(long parentStructureId,
2742 int start, int end) {
2743 return findByParentStructureId(parentStructureId, start, end, null);
2744 }
2745
2746
2759 @Override
2760 public List<DDMStructure> findByParentStructureId(long parentStructureId,
2761 int start, int end, OrderByComparator<DDMStructure> orderByComparator) {
2762 boolean pagination = true;
2763 FinderPath finderPath = null;
2764 Object[] finderArgs = null;
2765
2766 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2767 (orderByComparator == null)) {
2768 pagination = false;
2769 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID;
2770 finderArgs = new Object[] { parentStructureId };
2771 }
2772 else {
2773 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTSTRUCTUREID;
2774 finderArgs = new Object[] {
2775 parentStructureId,
2776
2777 start, end, orderByComparator
2778 };
2779 }
2780
2781 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
2782 finderArgs, this);
2783
2784 if ((list != null) && !list.isEmpty()) {
2785 for (DDMStructure ddmStructure : list) {
2786 if ((parentStructureId != ddmStructure.getParentStructureId())) {
2787 list = null;
2788
2789 break;
2790 }
2791 }
2792 }
2793
2794 if (list == null) {
2795 StringBundler query = null;
2796
2797 if (orderByComparator != null) {
2798 query = new StringBundler(3 +
2799 (orderByComparator.getOrderByFields().length * 3));
2800 }
2801 else {
2802 query = new StringBundler(3);
2803 }
2804
2805 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2806
2807 query.append(_FINDER_COLUMN_PARENTSTRUCTUREID_PARENTSTRUCTUREID_2);
2808
2809 if (orderByComparator != null) {
2810 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2811 orderByComparator);
2812 }
2813 else
2814 if (pagination) {
2815 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2816 }
2817
2818 String sql = query.toString();
2819
2820 Session session = null;
2821
2822 try {
2823 session = openSession();
2824
2825 Query q = session.createQuery(sql);
2826
2827 QueryPos qPos = QueryPos.getInstance(q);
2828
2829 qPos.add(parentStructureId);
2830
2831 if (!pagination) {
2832 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2833 start, end, false);
2834
2835 Collections.sort(list);
2836
2837 list = Collections.unmodifiableList(list);
2838 }
2839 else {
2840 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2841 start, end);
2842 }
2843
2844 cacheResult(list);
2845
2846 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2847 }
2848 catch (Exception e) {
2849 FinderCacheUtil.removeResult(finderPath, finderArgs);
2850
2851 throw processException(e);
2852 }
2853 finally {
2854 closeSession(session);
2855 }
2856 }
2857
2858 return list;
2859 }
2860
2861
2869 @Override
2870 public DDMStructure findByParentStructureId_First(long parentStructureId,
2871 OrderByComparator<DDMStructure> orderByComparator)
2872 throws NoSuchStructureException {
2873 DDMStructure ddmStructure = fetchByParentStructureId_First(parentStructureId,
2874 orderByComparator);
2875
2876 if (ddmStructure != null) {
2877 return ddmStructure;
2878 }
2879
2880 StringBundler msg = new StringBundler(4);
2881
2882 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2883
2884 msg.append("parentStructureId=");
2885 msg.append(parentStructureId);
2886
2887 msg.append(StringPool.CLOSE_CURLY_BRACE);
2888
2889 throw new NoSuchStructureException(msg.toString());
2890 }
2891
2892
2899 @Override
2900 public DDMStructure fetchByParentStructureId_First(long parentStructureId,
2901 OrderByComparator<DDMStructure> orderByComparator) {
2902 List<DDMStructure> list = findByParentStructureId(parentStructureId, 0,
2903 1, orderByComparator);
2904
2905 if (!list.isEmpty()) {
2906 return list.get(0);
2907 }
2908
2909 return null;
2910 }
2911
2912
2920 @Override
2921 public DDMStructure findByParentStructureId_Last(long parentStructureId,
2922 OrderByComparator<DDMStructure> orderByComparator)
2923 throws NoSuchStructureException {
2924 DDMStructure ddmStructure = fetchByParentStructureId_Last(parentStructureId,
2925 orderByComparator);
2926
2927 if (ddmStructure != null) {
2928 return ddmStructure;
2929 }
2930
2931 StringBundler msg = new StringBundler(4);
2932
2933 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2934
2935 msg.append("parentStructureId=");
2936 msg.append(parentStructureId);
2937
2938 msg.append(StringPool.CLOSE_CURLY_BRACE);
2939
2940 throw new NoSuchStructureException(msg.toString());
2941 }
2942
2943
2950 @Override
2951 public DDMStructure fetchByParentStructureId_Last(long parentStructureId,
2952 OrderByComparator<DDMStructure> orderByComparator) {
2953 int count = countByParentStructureId(parentStructureId);
2954
2955 if (count == 0) {
2956 return null;
2957 }
2958
2959 List<DDMStructure> list = findByParentStructureId(parentStructureId,
2960 count - 1, count, orderByComparator);
2961
2962 if (!list.isEmpty()) {
2963 return list.get(0);
2964 }
2965
2966 return null;
2967 }
2968
2969
2978 @Override
2979 public DDMStructure[] findByParentStructureId_PrevAndNext(
2980 long structureId, long parentStructureId,
2981 OrderByComparator<DDMStructure> orderByComparator)
2982 throws NoSuchStructureException {
2983 DDMStructure ddmStructure = findByPrimaryKey(structureId);
2984
2985 Session session = null;
2986
2987 try {
2988 session = openSession();
2989
2990 DDMStructure[] array = new DDMStructureImpl[3];
2991
2992 array[0] = getByParentStructureId_PrevAndNext(session,
2993 ddmStructure, parentStructureId, orderByComparator, true);
2994
2995 array[1] = ddmStructure;
2996
2997 array[2] = getByParentStructureId_PrevAndNext(session,
2998 ddmStructure, parentStructureId, orderByComparator, false);
2999
3000 return array;
3001 }
3002 catch (Exception e) {
3003 throw processException(e);
3004 }
3005 finally {
3006 closeSession(session);
3007 }
3008 }
3009
3010 protected DDMStructure getByParentStructureId_PrevAndNext(Session session,
3011 DDMStructure ddmStructure, long parentStructureId,
3012 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
3013 StringBundler query = null;
3014
3015 if (orderByComparator != null) {
3016 query = new StringBundler(6 +
3017 (orderByComparator.getOrderByFields().length * 6));
3018 }
3019 else {
3020 query = new StringBundler(3);
3021 }
3022
3023 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3024
3025 query.append(_FINDER_COLUMN_PARENTSTRUCTUREID_PARENTSTRUCTUREID_2);
3026
3027 if (orderByComparator != null) {
3028 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3029
3030 if (orderByConditionFields.length > 0) {
3031 query.append(WHERE_AND);
3032 }
3033
3034 for (int i = 0; i < orderByConditionFields.length; i++) {
3035 query.append(_ORDER_BY_ENTITY_ALIAS);
3036 query.append(orderByConditionFields[i]);
3037
3038 if ((i + 1) < orderByConditionFields.length) {
3039 if (orderByComparator.isAscending() ^ previous) {
3040 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3041 }
3042 else {
3043 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3044 }
3045 }
3046 else {
3047 if (orderByComparator.isAscending() ^ previous) {
3048 query.append(WHERE_GREATER_THAN);
3049 }
3050 else {
3051 query.append(WHERE_LESSER_THAN);
3052 }
3053 }
3054 }
3055
3056 query.append(ORDER_BY_CLAUSE);
3057
3058 String[] orderByFields = orderByComparator.getOrderByFields();
3059
3060 for (int i = 0; i < orderByFields.length; i++) {
3061 query.append(_ORDER_BY_ENTITY_ALIAS);
3062 query.append(orderByFields[i]);
3063
3064 if ((i + 1) < orderByFields.length) {
3065 if (orderByComparator.isAscending() ^ previous) {
3066 query.append(ORDER_BY_ASC_HAS_NEXT);
3067 }
3068 else {
3069 query.append(ORDER_BY_DESC_HAS_NEXT);
3070 }
3071 }
3072 else {
3073 if (orderByComparator.isAscending() ^ previous) {
3074 query.append(ORDER_BY_ASC);
3075 }
3076 else {
3077 query.append(ORDER_BY_DESC);
3078 }
3079 }
3080 }
3081 }
3082 else {
3083 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3084 }
3085
3086 String sql = query.toString();
3087
3088 Query q = session.createQuery(sql);
3089
3090 q.setFirstResult(0);
3091 q.setMaxResults(2);
3092
3093 QueryPos qPos = QueryPos.getInstance(q);
3094
3095 qPos.add(parentStructureId);
3096
3097 if (orderByComparator != null) {
3098 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
3099
3100 for (Object value : values) {
3101 qPos.add(value);
3102 }
3103 }
3104
3105 List<DDMStructure> list = q.list();
3106
3107 if (list.size() == 2) {
3108 return list.get(1);
3109 }
3110 else {
3111 return null;
3112 }
3113 }
3114
3115
3120 @Override
3121 public void removeByParentStructureId(long parentStructureId) {
3122 for (DDMStructure ddmStructure : findByParentStructureId(
3123 parentStructureId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3124 remove(ddmStructure);
3125 }
3126 }
3127
3128
3134 @Override
3135 public int countByParentStructureId(long parentStructureId) {
3136 FinderPath finderPath = FINDER_PATH_COUNT_BY_PARENTSTRUCTUREID;
3137
3138 Object[] finderArgs = new Object[] { parentStructureId };
3139
3140 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3141 this);
3142
3143 if (count == null) {
3144 StringBundler query = new StringBundler(2);
3145
3146 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3147
3148 query.append(_FINDER_COLUMN_PARENTSTRUCTUREID_PARENTSTRUCTUREID_2);
3149
3150 String sql = query.toString();
3151
3152 Session session = null;
3153
3154 try {
3155 session = openSession();
3156
3157 Query q = session.createQuery(sql);
3158
3159 QueryPos qPos = QueryPos.getInstance(q);
3160
3161 qPos.add(parentStructureId);
3162
3163 count = (Long)q.uniqueResult();
3164
3165 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3166 }
3167 catch (Exception e) {
3168 FinderCacheUtil.removeResult(finderPath, finderArgs);
3169
3170 throw processException(e);
3171 }
3172 finally {
3173 closeSession(session);
3174 }
3175 }
3176
3177 return count.intValue();
3178 }
3179
3180 private static final String _FINDER_COLUMN_PARENTSTRUCTUREID_PARENTSTRUCTUREID_2 =
3181 "ddmStructure.parentStructureId = ?";
3182 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
3183 new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3184 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3185 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassNameId",
3186 new String[] {
3187 Long.class.getName(),
3188
3189 Integer.class.getName(), Integer.class.getName(),
3190 OrderByComparator.class.getName()
3191 });
3192 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
3193 new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3194 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3195 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
3196 new String[] { Long.class.getName() },
3197 DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
3198 public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3199 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
3200 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
3201 new String[] { Long.class.getName() });
3202
3203
3209 @Override
3210 public List<DDMStructure> findByClassNameId(long classNameId) {
3211 return findByClassNameId(classNameId, QueryUtil.ALL_POS,
3212 QueryUtil.ALL_POS, null);
3213 }
3214
3215
3227 @Override
3228 public List<DDMStructure> findByClassNameId(long classNameId, int start,
3229 int end) {
3230 return findByClassNameId(classNameId, start, end, null);
3231 }
3232
3233
3246 @Override
3247 public List<DDMStructure> findByClassNameId(long classNameId, int start,
3248 int end, OrderByComparator<DDMStructure> orderByComparator) {
3249 boolean pagination = true;
3250 FinderPath finderPath = null;
3251 Object[] finderArgs = null;
3252
3253 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3254 (orderByComparator == null)) {
3255 pagination = false;
3256 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
3257 finderArgs = new Object[] { classNameId };
3258 }
3259 else {
3260 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
3261 finderArgs = new Object[] { classNameId, start, end, orderByComparator };
3262 }
3263
3264 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
3265 finderArgs, this);
3266
3267 if ((list != null) && !list.isEmpty()) {
3268 for (DDMStructure ddmStructure : list) {
3269 if ((classNameId != ddmStructure.getClassNameId())) {
3270 list = null;
3271
3272 break;
3273 }
3274 }
3275 }
3276
3277 if (list == null) {
3278 StringBundler query = null;
3279
3280 if (orderByComparator != null) {
3281 query = new StringBundler(3 +
3282 (orderByComparator.getOrderByFields().length * 3));
3283 }
3284 else {
3285 query = new StringBundler(3);
3286 }
3287
3288 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3289
3290 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3291
3292 if (orderByComparator != null) {
3293 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3294 orderByComparator);
3295 }
3296 else
3297 if (pagination) {
3298 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3299 }
3300
3301 String sql = query.toString();
3302
3303 Session session = null;
3304
3305 try {
3306 session = openSession();
3307
3308 Query q = session.createQuery(sql);
3309
3310 QueryPos qPos = QueryPos.getInstance(q);
3311
3312 qPos.add(classNameId);
3313
3314 if (!pagination) {
3315 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3316 start, end, false);
3317
3318 Collections.sort(list);
3319
3320 list = Collections.unmodifiableList(list);
3321 }
3322 else {
3323 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3324 start, end);
3325 }
3326
3327 cacheResult(list);
3328
3329 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3330 }
3331 catch (Exception e) {
3332 FinderCacheUtil.removeResult(finderPath, finderArgs);
3333
3334 throw processException(e);
3335 }
3336 finally {
3337 closeSession(session);
3338 }
3339 }
3340
3341 return list;
3342 }
3343
3344
3352 @Override
3353 public DDMStructure findByClassNameId_First(long classNameId,
3354 OrderByComparator<DDMStructure> orderByComparator)
3355 throws NoSuchStructureException {
3356 DDMStructure ddmStructure = fetchByClassNameId_First(classNameId,
3357 orderByComparator);
3358
3359 if (ddmStructure != null) {
3360 return ddmStructure;
3361 }
3362
3363 StringBundler msg = new StringBundler(4);
3364
3365 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3366
3367 msg.append("classNameId=");
3368 msg.append(classNameId);
3369
3370 msg.append(StringPool.CLOSE_CURLY_BRACE);
3371
3372 throw new NoSuchStructureException(msg.toString());
3373 }
3374
3375
3382 @Override
3383 public DDMStructure fetchByClassNameId_First(long classNameId,
3384 OrderByComparator<DDMStructure> orderByComparator) {
3385 List<DDMStructure> list = findByClassNameId(classNameId, 0, 1,
3386 orderByComparator);
3387
3388 if (!list.isEmpty()) {
3389 return list.get(0);
3390 }
3391
3392 return null;
3393 }
3394
3395
3403 @Override
3404 public DDMStructure findByClassNameId_Last(long classNameId,
3405 OrderByComparator<DDMStructure> orderByComparator)
3406 throws NoSuchStructureException {
3407 DDMStructure ddmStructure = fetchByClassNameId_Last(classNameId,
3408 orderByComparator);
3409
3410 if (ddmStructure != null) {
3411 return ddmStructure;
3412 }
3413
3414 StringBundler msg = new StringBundler(4);
3415
3416 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3417
3418 msg.append("classNameId=");
3419 msg.append(classNameId);
3420
3421 msg.append(StringPool.CLOSE_CURLY_BRACE);
3422
3423 throw new NoSuchStructureException(msg.toString());
3424 }
3425
3426
3433 @Override
3434 public DDMStructure fetchByClassNameId_Last(long classNameId,
3435 OrderByComparator<DDMStructure> orderByComparator) {
3436 int count = countByClassNameId(classNameId);
3437
3438 if (count == 0) {
3439 return null;
3440 }
3441
3442 List<DDMStructure> list = findByClassNameId(classNameId, count - 1,
3443 count, orderByComparator);
3444
3445 if (!list.isEmpty()) {
3446 return list.get(0);
3447 }
3448
3449 return null;
3450 }
3451
3452
3461 @Override
3462 public DDMStructure[] findByClassNameId_PrevAndNext(long structureId,
3463 long classNameId, OrderByComparator<DDMStructure> orderByComparator)
3464 throws NoSuchStructureException {
3465 DDMStructure ddmStructure = findByPrimaryKey(structureId);
3466
3467 Session session = null;
3468
3469 try {
3470 session = openSession();
3471
3472 DDMStructure[] array = new DDMStructureImpl[3];
3473
3474 array[0] = getByClassNameId_PrevAndNext(session, ddmStructure,
3475 classNameId, orderByComparator, true);
3476
3477 array[1] = ddmStructure;
3478
3479 array[2] = getByClassNameId_PrevAndNext(session, ddmStructure,
3480 classNameId, orderByComparator, false);
3481
3482 return array;
3483 }
3484 catch (Exception e) {
3485 throw processException(e);
3486 }
3487 finally {
3488 closeSession(session);
3489 }
3490 }
3491
3492 protected DDMStructure getByClassNameId_PrevAndNext(Session session,
3493 DDMStructure ddmStructure, long classNameId,
3494 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
3495 StringBundler query = null;
3496
3497 if (orderByComparator != null) {
3498 query = new StringBundler(6 +
3499 (orderByComparator.getOrderByFields().length * 6));
3500 }
3501 else {
3502 query = new StringBundler(3);
3503 }
3504
3505 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3506
3507 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3508
3509 if (orderByComparator != null) {
3510 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3511
3512 if (orderByConditionFields.length > 0) {
3513 query.append(WHERE_AND);
3514 }
3515
3516 for (int i = 0; i < orderByConditionFields.length; i++) {
3517 query.append(_ORDER_BY_ENTITY_ALIAS);
3518 query.append(orderByConditionFields[i]);
3519
3520 if ((i + 1) < orderByConditionFields.length) {
3521 if (orderByComparator.isAscending() ^ previous) {
3522 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3523 }
3524 else {
3525 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3526 }
3527 }
3528 else {
3529 if (orderByComparator.isAscending() ^ previous) {
3530 query.append(WHERE_GREATER_THAN);
3531 }
3532 else {
3533 query.append(WHERE_LESSER_THAN);
3534 }
3535 }
3536 }
3537
3538 query.append(ORDER_BY_CLAUSE);
3539
3540 String[] orderByFields = orderByComparator.getOrderByFields();
3541
3542 for (int i = 0; i < orderByFields.length; i++) {
3543 query.append(_ORDER_BY_ENTITY_ALIAS);
3544 query.append(orderByFields[i]);
3545
3546 if ((i + 1) < orderByFields.length) {
3547 if (orderByComparator.isAscending() ^ previous) {
3548 query.append(ORDER_BY_ASC_HAS_NEXT);
3549 }
3550 else {
3551 query.append(ORDER_BY_DESC_HAS_NEXT);
3552 }
3553 }
3554 else {
3555 if (orderByComparator.isAscending() ^ previous) {
3556 query.append(ORDER_BY_ASC);
3557 }
3558 else {
3559 query.append(ORDER_BY_DESC);
3560 }
3561 }
3562 }
3563 }
3564 else {
3565 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3566 }
3567
3568 String sql = query.toString();
3569
3570 Query q = session.createQuery(sql);
3571
3572 q.setFirstResult(0);
3573 q.setMaxResults(2);
3574
3575 QueryPos qPos = QueryPos.getInstance(q);
3576
3577 qPos.add(classNameId);
3578
3579 if (orderByComparator != null) {
3580 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
3581
3582 for (Object value : values) {
3583 qPos.add(value);
3584 }
3585 }
3586
3587 List<DDMStructure> list = q.list();
3588
3589 if (list.size() == 2) {
3590 return list.get(1);
3591 }
3592 else {
3593 return null;
3594 }
3595 }
3596
3597
3602 @Override
3603 public void removeByClassNameId(long classNameId) {
3604 for (DDMStructure ddmStructure : findByClassNameId(classNameId,
3605 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3606 remove(ddmStructure);
3607 }
3608 }
3609
3610
3616 @Override
3617 public int countByClassNameId(long classNameId) {
3618 FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSNAMEID;
3619
3620 Object[] finderArgs = new Object[] { classNameId };
3621
3622 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3623 this);
3624
3625 if (count == null) {
3626 StringBundler query = new StringBundler(2);
3627
3628 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3629
3630 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3631
3632 String sql = query.toString();
3633
3634 Session session = null;
3635
3636 try {
3637 session = openSession();
3638
3639 Query q = session.createQuery(sql);
3640
3641 QueryPos qPos = QueryPos.getInstance(q);
3642
3643 qPos.add(classNameId);
3644
3645 count = (Long)q.uniqueResult();
3646
3647 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3648 }
3649 catch (Exception e) {
3650 FinderCacheUtil.removeResult(finderPath, finderArgs);
3651
3652 throw processException(e);
3653 }
3654 finally {
3655 closeSession(session);
3656 }
3657 }
3658
3659 return count.intValue();
3660 }
3661
3662 private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
3663 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREKEY =
3664 new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3665 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3666 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByStructureKey",
3667 new String[] {
3668 String.class.getName(),
3669
3670 Integer.class.getName(), Integer.class.getName(),
3671 OrderByComparator.class.getName()
3672 });
3673 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY =
3674 new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3675 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3676 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureKey",
3677 new String[] { String.class.getName() },
3678 DDMStructureModelImpl.STRUCTUREKEY_COLUMN_BITMASK);
3679 public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREKEY = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3680 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
3681 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureKey",
3682 new String[] { String.class.getName() });
3683
3684
3690 @Override
3691 public List<DDMStructure> findByStructureKey(String structureKey) {
3692 return findByStructureKey(structureKey, QueryUtil.ALL_POS,
3693 QueryUtil.ALL_POS, null);
3694 }
3695
3696
3708 @Override
3709 public List<DDMStructure> findByStructureKey(String structureKey,
3710 int start, int end) {
3711 return findByStructureKey(structureKey, start, end, null);
3712 }
3713
3714
3727 @Override
3728 public List<DDMStructure> findByStructureKey(String structureKey,
3729 int start, int end, OrderByComparator<DDMStructure> orderByComparator) {
3730 boolean pagination = true;
3731 FinderPath finderPath = null;
3732 Object[] finderArgs = null;
3733
3734 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3735 (orderByComparator == null)) {
3736 pagination = false;
3737 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY;
3738 finderArgs = new Object[] { structureKey };
3739 }
3740 else {
3741 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREKEY;
3742 finderArgs = new Object[] {
3743 structureKey,
3744
3745 start, end, orderByComparator
3746 };
3747 }
3748
3749 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
3750 finderArgs, this);
3751
3752 if ((list != null) && !list.isEmpty()) {
3753 for (DDMStructure ddmStructure : list) {
3754 if (!Validator.equals(structureKey,
3755 ddmStructure.getStructureKey())) {
3756 list = null;
3757
3758 break;
3759 }
3760 }
3761 }
3762
3763 if (list == null) {
3764 StringBundler query = null;
3765
3766 if (orderByComparator != null) {
3767 query = new StringBundler(3 +
3768 (orderByComparator.getOrderByFields().length * 3));
3769 }
3770 else {
3771 query = new StringBundler(3);
3772 }
3773
3774 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3775
3776 boolean bindStructureKey = false;
3777
3778 if (structureKey == null) {
3779 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
3780 }
3781 else if (structureKey.equals(StringPool.BLANK)) {
3782 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
3783 }
3784 else {
3785 bindStructureKey = true;
3786
3787 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
3788 }
3789
3790 if (orderByComparator != null) {
3791 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3792 orderByComparator);
3793 }
3794 else
3795 if (pagination) {
3796 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3797 }
3798
3799 String sql = query.toString();
3800
3801 Session session = null;
3802
3803 try {
3804 session = openSession();
3805
3806 Query q = session.createQuery(sql);
3807
3808 QueryPos qPos = QueryPos.getInstance(q);
3809
3810 if (bindStructureKey) {
3811 qPos.add(structureKey);
3812 }
3813
3814 if (!pagination) {
3815 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3816 start, end, false);
3817
3818 Collections.sort(list);
3819
3820 list = Collections.unmodifiableList(list);
3821 }
3822 else {
3823 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3824 start, end);
3825 }
3826
3827 cacheResult(list);
3828
3829 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3830 }
3831 catch (Exception e) {
3832 FinderCacheUtil.removeResult(finderPath, finderArgs);
3833
3834 throw processException(e);
3835 }
3836 finally {
3837 closeSession(session);
3838 }
3839 }
3840
3841 return list;
3842 }
3843
3844
3852 @Override
3853 public DDMStructure findByStructureKey_First(String structureKey,
3854 OrderByComparator<DDMStructure> orderByComparator)
3855 throws NoSuchStructureException {
3856 DDMStructure ddmStructure = fetchByStructureKey_First(structureKey,
3857 orderByComparator);
3858
3859 if (ddmStructure != null) {
3860 return ddmStructure;
3861 }
3862
3863 StringBundler msg = new StringBundler(4);
3864
3865 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3866
3867 msg.append("structureKey=");
3868 msg.append(structureKey);
3869
3870 msg.append(StringPool.CLOSE_CURLY_BRACE);
3871
3872 throw new NoSuchStructureException(msg.toString());
3873 }
3874
3875
3882 @Override
3883 public DDMStructure fetchByStructureKey_First(String structureKey,
3884 OrderByComparator<DDMStructure> orderByComparator) {
3885 List<DDMStructure> list = findByStructureKey(structureKey, 0, 1,
3886 orderByComparator);
3887
3888 if (!list.isEmpty()) {
3889 return list.get(0);
3890 }
3891
3892 return null;
3893 }
3894
3895
3903 @Override
3904 public DDMStructure findByStructureKey_Last(String structureKey,
3905 OrderByComparator<DDMStructure> orderByComparator)
3906 throws NoSuchStructureException {
3907 DDMStructure ddmStructure = fetchByStructureKey_Last(structureKey,
3908 orderByComparator);
3909
3910 if (ddmStructure != null) {
3911 return ddmStructure;
3912 }
3913
3914 StringBundler msg = new StringBundler(4);
3915
3916 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3917
3918 msg.append("structureKey=");
3919 msg.append(structureKey);
3920
3921 msg.append(StringPool.CLOSE_CURLY_BRACE);
3922
3923 throw new NoSuchStructureException(msg.toString());
3924 }
3925
3926
3933 @Override
3934 public DDMStructure fetchByStructureKey_Last(String structureKey,
3935 OrderByComparator<DDMStructure> orderByComparator) {
3936 int count = countByStructureKey(structureKey);
3937
3938 if (count == 0) {
3939 return null;
3940 }
3941
3942 List<DDMStructure> list = findByStructureKey(structureKey, count - 1,
3943 count, orderByComparator);
3944
3945 if (!list.isEmpty()) {
3946 return list.get(0);
3947 }
3948
3949 return null;
3950 }
3951
3952
3961 @Override
3962 public DDMStructure[] findByStructureKey_PrevAndNext(long structureId,
3963 String structureKey, OrderByComparator<DDMStructure> orderByComparator)
3964 throws NoSuchStructureException {
3965 DDMStructure ddmStructure = findByPrimaryKey(structureId);
3966
3967 Session session = null;
3968
3969 try {
3970 session = openSession();
3971
3972 DDMStructure[] array = new DDMStructureImpl[3];
3973
3974 array[0] = getByStructureKey_PrevAndNext(session, ddmStructure,
3975 structureKey, orderByComparator, true);
3976
3977 array[1] = ddmStructure;
3978
3979 array[2] = getByStructureKey_PrevAndNext(session, ddmStructure,
3980 structureKey, orderByComparator, false);
3981
3982 return array;
3983 }
3984 catch (Exception e) {
3985 throw processException(e);
3986 }
3987 finally {
3988 closeSession(session);
3989 }
3990 }
3991
3992 protected DDMStructure getByStructureKey_PrevAndNext(Session session,
3993 DDMStructure ddmStructure, String structureKey,
3994 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
3995 StringBundler query = null;
3996
3997 if (orderByComparator != null) {
3998 query = new StringBundler(6 +
3999 (orderByComparator.getOrderByFields().length * 6));
4000 }
4001 else {
4002 query = new StringBundler(3);
4003 }
4004
4005 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4006
4007 boolean bindStructureKey = false;
4008
4009 if (structureKey == null) {
4010 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
4011 }
4012 else if (structureKey.equals(StringPool.BLANK)) {
4013 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
4014 }
4015 else {
4016 bindStructureKey = true;
4017
4018 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
4019 }
4020
4021 if (orderByComparator != null) {
4022 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4023
4024 if (orderByConditionFields.length > 0) {
4025 query.append(WHERE_AND);
4026 }
4027
4028 for (int i = 0; i < orderByConditionFields.length; i++) {
4029 query.append(_ORDER_BY_ENTITY_ALIAS);
4030 query.append(orderByConditionFields[i]);
4031
4032 if ((i + 1) < orderByConditionFields.length) {
4033 if (orderByComparator.isAscending() ^ previous) {
4034 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4035 }
4036 else {
4037 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4038 }
4039 }
4040 else {
4041 if (orderByComparator.isAscending() ^ previous) {
4042 query.append(WHERE_GREATER_THAN);
4043 }
4044 else {
4045 query.append(WHERE_LESSER_THAN);
4046 }
4047 }
4048 }
4049
4050 query.append(ORDER_BY_CLAUSE);
4051
4052 String[] orderByFields = orderByComparator.getOrderByFields();
4053
4054 for (int i = 0; i < orderByFields.length; i++) {
4055 query.append(_ORDER_BY_ENTITY_ALIAS);
4056 query.append(orderByFields[i]);
4057
4058 if ((i + 1) < orderByFields.length) {
4059 if (orderByComparator.isAscending() ^ previous) {
4060 query.append(ORDER_BY_ASC_HAS_NEXT);
4061 }
4062 else {
4063 query.append(ORDER_BY_DESC_HAS_NEXT);
4064 }
4065 }
4066 else {
4067 if (orderByComparator.isAscending() ^ previous) {
4068 query.append(ORDER_BY_ASC);
4069 }
4070 else {
4071 query.append(ORDER_BY_DESC);
4072 }
4073 }
4074 }
4075 }
4076 else {
4077 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4078 }
4079
4080 String sql = query.toString();
4081
4082 Query q = session.createQuery(sql);
4083
4084 q.setFirstResult(0);
4085 q.setMaxResults(2);
4086
4087 QueryPos qPos = QueryPos.getInstance(q);
4088
4089 if (bindStructureKey) {
4090 qPos.add(structureKey);
4091 }
4092
4093 if (orderByComparator != null) {
4094 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
4095
4096 for (Object value : values) {
4097 qPos.add(value);
4098 }
4099 }
4100
4101 List<DDMStructure> list = q.list();
4102
4103 if (list.size() == 2) {
4104 return list.get(1);
4105 }
4106 else {
4107 return null;
4108 }
4109 }
4110
4111
4116 @Override
4117 public void removeByStructureKey(String structureKey) {
4118 for (DDMStructure ddmStructure : findByStructureKey(structureKey,
4119 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4120 remove(ddmStructure);
4121 }
4122 }
4123
4124
4130 @Override
4131 public int countByStructureKey(String structureKey) {
4132 FinderPath finderPath = FINDER_PATH_COUNT_BY_STRUCTUREKEY;
4133
4134 Object[] finderArgs = new Object[] { structureKey };
4135
4136 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4137 this);
4138
4139 if (count == null) {
4140 StringBundler query = new StringBundler(2);
4141
4142 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
4143
4144 boolean bindStructureKey = false;
4145
4146 if (structureKey == null) {
4147 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
4148 }
4149 else if (structureKey.equals(StringPool.BLANK)) {
4150 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
4151 }
4152 else {
4153 bindStructureKey = true;
4154
4155 query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
4156 }
4157
4158 String sql = query.toString();
4159
4160 Session session = null;
4161
4162 try {
4163 session = openSession();
4164
4165 Query q = session.createQuery(sql);
4166
4167 QueryPos qPos = QueryPos.getInstance(q);
4168
4169 if (bindStructureKey) {
4170 qPos.add(structureKey);
4171 }
4172
4173 count = (Long)q.uniqueResult();
4174
4175 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4176 }
4177 catch (Exception e) {
4178 FinderCacheUtil.removeResult(finderPath, finderArgs);
4179
4180 throw processException(e);
4181 }
4182 finally {
4183 closeSession(session);
4184 }
4185 }
4186
4187 return count.intValue();
4188 }
4189
4190 private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1 = "ddmStructure.structureKey IS NULL";
4191 private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2 = "ddmStructure.structureKey = ?";
4192 private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3 = "(ddmStructure.structureKey IS NULL OR ddmStructure.structureKey = '')";
4193 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4194 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
4195 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
4196 new String[] {
4197 Long.class.getName(), Long.class.getName(),
4198
4199 Integer.class.getName(), Integer.class.getName(),
4200 OrderByComparator.class.getName()
4201 });
4202 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4203 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
4204 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
4205 new String[] { Long.class.getName(), Long.class.getName() },
4206 DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
4207 DDMStructureModelImpl.PARENTSTRUCTUREID_COLUMN_BITMASK);
4208 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4209 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
4210 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
4211 new String[] { Long.class.getName(), Long.class.getName() });
4212
4213
4220 @Override
4221 public List<DDMStructure> findByG_P(long groupId, long parentStructureId) {
4222 return findByG_P(groupId, parentStructureId, QueryUtil.ALL_POS,
4223 QueryUtil.ALL_POS, null);
4224 }
4225
4226
4239 @Override
4240 public List<DDMStructure> findByG_P(long groupId, long parentStructureId,
4241 int start, int end) {
4242 return findByG_P(groupId, parentStructureId, start, end, null);
4243 }
4244
4245
4259 @Override
4260 public List<DDMStructure> findByG_P(long groupId, long parentStructureId,
4261 int start, int end, OrderByComparator<DDMStructure> orderByComparator) {
4262 boolean pagination = true;
4263 FinderPath finderPath = null;
4264 Object[] finderArgs = null;
4265
4266 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4267 (orderByComparator == null)) {
4268 pagination = false;
4269 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
4270 finderArgs = new Object[] { groupId, parentStructureId };
4271 }
4272 else {
4273 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
4274 finderArgs = new Object[] {
4275 groupId, parentStructureId,
4276
4277 start, end, orderByComparator
4278 };
4279 }
4280
4281 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
4282 finderArgs, this);
4283
4284 if ((list != null) && !list.isEmpty()) {
4285 for (DDMStructure ddmStructure : list) {
4286 if ((groupId != ddmStructure.getGroupId()) ||
4287 (parentStructureId != ddmStructure.getParentStructureId())) {
4288 list = null;
4289
4290 break;
4291 }
4292 }
4293 }
4294
4295 if (list == null) {
4296 StringBundler query = null;
4297
4298 if (orderByComparator != null) {
4299 query = new StringBundler(4 +
4300 (orderByComparator.getOrderByFields().length * 3));
4301 }
4302 else {
4303 query = new StringBundler(4);
4304 }
4305
4306 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4307
4308 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4309
4310 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4311
4312 if (orderByComparator != null) {
4313 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4314 orderByComparator);
4315 }
4316 else
4317 if (pagination) {
4318 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4319 }
4320
4321 String sql = query.toString();
4322
4323 Session session = null;
4324
4325 try {
4326 session = openSession();
4327
4328 Query q = session.createQuery(sql);
4329
4330 QueryPos qPos = QueryPos.getInstance(q);
4331
4332 qPos.add(groupId);
4333
4334 qPos.add(parentStructureId);
4335
4336 if (!pagination) {
4337 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
4338 start, end, false);
4339
4340 Collections.sort(list);
4341
4342 list = Collections.unmodifiableList(list);
4343 }
4344 else {
4345 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
4346 start, end);
4347 }
4348
4349 cacheResult(list);
4350
4351 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4352 }
4353 catch (Exception e) {
4354 FinderCacheUtil.removeResult(finderPath, finderArgs);
4355
4356 throw processException(e);
4357 }
4358 finally {
4359 closeSession(session);
4360 }
4361 }
4362
4363 return list;
4364 }
4365
4366
4375 @Override
4376 public DDMStructure findByG_P_First(long groupId, long parentStructureId,
4377 OrderByComparator<DDMStructure> orderByComparator)
4378 throws NoSuchStructureException {
4379 DDMStructure ddmStructure = fetchByG_P_First(groupId,
4380 parentStructureId, orderByComparator);
4381
4382 if (ddmStructure != null) {
4383 return ddmStructure;
4384 }
4385
4386 StringBundler msg = new StringBundler(6);
4387
4388 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4389
4390 msg.append("groupId=");
4391 msg.append(groupId);
4392
4393 msg.append(", parentStructureId=");
4394 msg.append(parentStructureId);
4395
4396 msg.append(StringPool.CLOSE_CURLY_BRACE);
4397
4398 throw new NoSuchStructureException(msg.toString());
4399 }
4400
4401
4409 @Override
4410 public DDMStructure fetchByG_P_First(long groupId, long parentStructureId,
4411 OrderByComparator<DDMStructure> orderByComparator) {
4412 List<DDMStructure> list = findByG_P(groupId, parentStructureId, 0, 1,
4413 orderByComparator);
4414
4415 if (!list.isEmpty()) {
4416 return list.get(0);
4417 }
4418
4419 return null;
4420 }
4421
4422
4431 @Override
4432 public DDMStructure findByG_P_Last(long groupId, long parentStructureId,
4433 OrderByComparator<DDMStructure> orderByComparator)
4434 throws NoSuchStructureException {
4435 DDMStructure ddmStructure = fetchByG_P_Last(groupId, parentStructureId,
4436 orderByComparator);
4437
4438 if (ddmStructure != null) {
4439 return ddmStructure;
4440 }
4441
4442 StringBundler msg = new StringBundler(6);
4443
4444 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4445
4446 msg.append("groupId=");
4447 msg.append(groupId);
4448
4449 msg.append(", parentStructureId=");
4450 msg.append(parentStructureId);
4451
4452 msg.append(StringPool.CLOSE_CURLY_BRACE);
4453
4454 throw new NoSuchStructureException(msg.toString());
4455 }
4456
4457
4465 @Override
4466 public DDMStructure fetchByG_P_Last(long groupId, long parentStructureId,
4467 OrderByComparator<DDMStructure> orderByComparator) {
4468 int count = countByG_P(groupId, parentStructureId);
4469
4470 if (count == 0) {
4471 return null;
4472 }
4473
4474 List<DDMStructure> list = findByG_P(groupId, parentStructureId,
4475 count - 1, count, orderByComparator);
4476
4477 if (!list.isEmpty()) {
4478 return list.get(0);
4479 }
4480
4481 return null;
4482 }
4483
4484
4494 @Override
4495 public DDMStructure[] findByG_P_PrevAndNext(long structureId, long groupId,
4496 long parentStructureId,
4497 OrderByComparator<DDMStructure> orderByComparator)
4498 throws NoSuchStructureException {
4499 DDMStructure ddmStructure = findByPrimaryKey(structureId);
4500
4501 Session session = null;
4502
4503 try {
4504 session = openSession();
4505
4506 DDMStructure[] array = new DDMStructureImpl[3];
4507
4508 array[0] = getByG_P_PrevAndNext(session, ddmStructure, groupId,
4509 parentStructureId, orderByComparator, true);
4510
4511 array[1] = ddmStructure;
4512
4513 array[2] = getByG_P_PrevAndNext(session, ddmStructure, groupId,
4514 parentStructureId, orderByComparator, false);
4515
4516 return array;
4517 }
4518 catch (Exception e) {
4519 throw processException(e);
4520 }
4521 finally {
4522 closeSession(session);
4523 }
4524 }
4525
4526 protected DDMStructure getByG_P_PrevAndNext(Session session,
4527 DDMStructure ddmStructure, long groupId, long parentStructureId,
4528 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
4529 StringBundler query = null;
4530
4531 if (orderByComparator != null) {
4532 query = new StringBundler(6 +
4533 (orderByComparator.getOrderByFields().length * 6));
4534 }
4535 else {
4536 query = new StringBundler(3);
4537 }
4538
4539 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4540
4541 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4542
4543 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4544
4545 if (orderByComparator != null) {
4546 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4547
4548 if (orderByConditionFields.length > 0) {
4549 query.append(WHERE_AND);
4550 }
4551
4552 for (int i = 0; i < orderByConditionFields.length; i++) {
4553 query.append(_ORDER_BY_ENTITY_ALIAS);
4554 query.append(orderByConditionFields[i]);
4555
4556 if ((i + 1) < orderByConditionFields.length) {
4557 if (orderByComparator.isAscending() ^ previous) {
4558 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4559 }
4560 else {
4561 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4562 }
4563 }
4564 else {
4565 if (orderByComparator.isAscending() ^ previous) {
4566 query.append(WHERE_GREATER_THAN);
4567 }
4568 else {
4569 query.append(WHERE_LESSER_THAN);
4570 }
4571 }
4572 }
4573
4574 query.append(ORDER_BY_CLAUSE);
4575
4576 String[] orderByFields = orderByComparator.getOrderByFields();
4577
4578 for (int i = 0; i < orderByFields.length; i++) {
4579 query.append(_ORDER_BY_ENTITY_ALIAS);
4580 query.append(orderByFields[i]);
4581
4582 if ((i + 1) < orderByFields.length) {
4583 if (orderByComparator.isAscending() ^ previous) {
4584 query.append(ORDER_BY_ASC_HAS_NEXT);
4585 }
4586 else {
4587 query.append(ORDER_BY_DESC_HAS_NEXT);
4588 }
4589 }
4590 else {
4591 if (orderByComparator.isAscending() ^ previous) {
4592 query.append(ORDER_BY_ASC);
4593 }
4594 else {
4595 query.append(ORDER_BY_DESC);
4596 }
4597 }
4598 }
4599 }
4600 else {
4601 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4602 }
4603
4604 String sql = query.toString();
4605
4606 Query q = session.createQuery(sql);
4607
4608 q.setFirstResult(0);
4609 q.setMaxResults(2);
4610
4611 QueryPos qPos = QueryPos.getInstance(q);
4612
4613 qPos.add(groupId);
4614
4615 qPos.add(parentStructureId);
4616
4617 if (orderByComparator != null) {
4618 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
4619
4620 for (Object value : values) {
4621 qPos.add(value);
4622 }
4623 }
4624
4625 List<DDMStructure> list = q.list();
4626
4627 if (list.size() == 2) {
4628 return list.get(1);
4629 }
4630 else {
4631 return null;
4632 }
4633 }
4634
4635
4642 @Override
4643 public List<DDMStructure> filterFindByG_P(long groupId,
4644 long parentStructureId) {
4645 return filterFindByG_P(groupId, parentStructureId, QueryUtil.ALL_POS,
4646 QueryUtil.ALL_POS, null);
4647 }
4648
4649
4662 @Override
4663 public List<DDMStructure> filterFindByG_P(long groupId,
4664 long parentStructureId, int start, int end) {
4665 return filterFindByG_P(groupId, parentStructureId, start, end, null);
4666 }
4667
4668
4682 @Override
4683 public List<DDMStructure> filterFindByG_P(long groupId,
4684 long parentStructureId, int start, int end,
4685 OrderByComparator<DDMStructure> orderByComparator) {
4686 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4687 return findByG_P(groupId, parentStructureId, start, end,
4688 orderByComparator);
4689 }
4690
4691 StringBundler query = null;
4692
4693 if (orderByComparator != null) {
4694 query = new StringBundler(4 +
4695 (orderByComparator.getOrderByFields().length * 3));
4696 }
4697 else {
4698 query = new StringBundler(4);
4699 }
4700
4701 if (getDB().isSupportsInlineDistinct()) {
4702 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
4703 }
4704 else {
4705 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
4706 }
4707
4708 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4709
4710 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4711
4712 if (!getDB().isSupportsInlineDistinct()) {
4713 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
4714 }
4715
4716 if (orderByComparator != null) {
4717 if (getDB().isSupportsInlineDistinct()) {
4718 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4719 orderByComparator, true);
4720 }
4721 else {
4722 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4723 orderByComparator, true);
4724 }
4725 }
4726 else {
4727 if (getDB().isSupportsInlineDistinct()) {
4728 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4729 }
4730 else {
4731 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
4732 }
4733 }
4734
4735 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4736 DDMStructure.class.getName(),
4737 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4738
4739 Session session = null;
4740
4741 try {
4742 session = openSession();
4743
4744 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4745
4746 if (getDB().isSupportsInlineDistinct()) {
4747 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
4748 }
4749 else {
4750 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
4751 }
4752
4753 QueryPos qPos = QueryPos.getInstance(q);
4754
4755 qPos.add(groupId);
4756
4757 qPos.add(parentStructureId);
4758
4759 return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
4760 end);
4761 }
4762 catch (Exception e) {
4763 throw processException(e);
4764 }
4765 finally {
4766 closeSession(session);
4767 }
4768 }
4769
4770
4780 @Override
4781 public DDMStructure[] filterFindByG_P_PrevAndNext(long structureId,
4782 long groupId, long parentStructureId,
4783 OrderByComparator<DDMStructure> orderByComparator)
4784 throws NoSuchStructureException {
4785 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4786 return findByG_P_PrevAndNext(structureId, groupId,
4787 parentStructureId, orderByComparator);
4788 }
4789
4790 DDMStructure ddmStructure = findByPrimaryKey(structureId);
4791
4792 Session session = null;
4793
4794 try {
4795 session = openSession();
4796
4797 DDMStructure[] array = new DDMStructureImpl[3];
4798
4799 array[0] = filterGetByG_P_PrevAndNext(session, ddmStructure,
4800 groupId, parentStructureId, orderByComparator, true);
4801
4802 array[1] = ddmStructure;
4803
4804 array[2] = filterGetByG_P_PrevAndNext(session, ddmStructure,
4805 groupId, parentStructureId, orderByComparator, false);
4806
4807 return array;
4808 }
4809 catch (Exception e) {
4810 throw processException(e);
4811 }
4812 finally {
4813 closeSession(session);
4814 }
4815 }
4816
4817 protected DDMStructure filterGetByG_P_PrevAndNext(Session session,
4818 DDMStructure ddmStructure, long groupId, long parentStructureId,
4819 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
4820 StringBundler query = null;
4821
4822 if (orderByComparator != null) {
4823 query = new StringBundler(6 +
4824 (orderByComparator.getOrderByFields().length * 6));
4825 }
4826 else {
4827 query = new StringBundler(3);
4828 }
4829
4830 if (getDB().isSupportsInlineDistinct()) {
4831 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
4832 }
4833 else {
4834 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
4835 }
4836
4837 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4838
4839 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4840
4841 if (!getDB().isSupportsInlineDistinct()) {
4842 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
4843 }
4844
4845 if (orderByComparator != null) {
4846 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4847
4848 if (orderByConditionFields.length > 0) {
4849 query.append(WHERE_AND);
4850 }
4851
4852 for (int i = 0; i < orderByConditionFields.length; i++) {
4853 if (getDB().isSupportsInlineDistinct()) {
4854 query.append(_ORDER_BY_ENTITY_ALIAS);
4855 }
4856 else {
4857 query.append(_ORDER_BY_ENTITY_TABLE);
4858 }
4859
4860 query.append(orderByConditionFields[i]);
4861
4862 if ((i + 1) < orderByConditionFields.length) {
4863 if (orderByComparator.isAscending() ^ previous) {
4864 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4865 }
4866 else {
4867 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4868 }
4869 }
4870 else {
4871 if (orderByComparator.isAscending() ^ previous) {
4872 query.append(WHERE_GREATER_THAN);
4873 }
4874 else {
4875 query.append(WHERE_LESSER_THAN);
4876 }
4877 }
4878 }
4879
4880 query.append(ORDER_BY_CLAUSE);
4881
4882 String[] orderByFields = orderByComparator.getOrderByFields();
4883
4884 for (int i = 0; i < orderByFields.length; i++) {
4885 if (getDB().isSupportsInlineDistinct()) {
4886 query.append(_ORDER_BY_ENTITY_ALIAS);
4887 }
4888 else {
4889 query.append(_ORDER_BY_ENTITY_TABLE);
4890 }
4891
4892 query.append(orderByFields[i]);
4893
4894 if ((i + 1) < orderByFields.length) {
4895 if (orderByComparator.isAscending() ^ previous) {
4896 query.append(ORDER_BY_ASC_HAS_NEXT);
4897 }
4898 else {
4899 query.append(ORDER_BY_DESC_HAS_NEXT);
4900 }
4901 }
4902 else {
4903 if (orderByComparator.isAscending() ^ previous) {
4904 query.append(ORDER_BY_ASC);
4905 }
4906 else {
4907 query.append(ORDER_BY_DESC);
4908 }
4909 }
4910 }
4911 }
4912 else {
4913 if (getDB().isSupportsInlineDistinct()) {
4914 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4915 }
4916 else {
4917 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
4918 }
4919 }
4920
4921 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4922 DDMStructure.class.getName(),
4923 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4924
4925 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4926
4927 q.setFirstResult(0);
4928 q.setMaxResults(2);
4929
4930 if (getDB().isSupportsInlineDistinct()) {
4931 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
4932 }
4933 else {
4934 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
4935 }
4936
4937 QueryPos qPos = QueryPos.getInstance(q);
4938
4939 qPos.add(groupId);
4940
4941 qPos.add(parentStructureId);
4942
4943 if (orderByComparator != null) {
4944 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
4945
4946 for (Object value : values) {
4947 qPos.add(value);
4948 }
4949 }
4950
4951 List<DDMStructure> list = q.list();
4952
4953 if (list.size() == 2) {
4954 return list.get(1);
4955 }
4956 else {
4957 return null;
4958 }
4959 }
4960
4961
4967 @Override
4968 public void removeByG_P(long groupId, long parentStructureId) {
4969 for (DDMStructure ddmStructure : findByG_P(groupId, parentStructureId,
4970 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4971 remove(ddmStructure);
4972 }
4973 }
4974
4975
4982 @Override
4983 public int countByG_P(long groupId, long parentStructureId) {
4984 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
4985
4986 Object[] finderArgs = new Object[] { groupId, parentStructureId };
4987
4988 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4989 this);
4990
4991 if (count == null) {
4992 StringBundler query = new StringBundler(3);
4993
4994 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
4995
4996 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4997
4998 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4999
5000 String sql = query.toString();
5001
5002 Session session = null;
5003
5004 try {
5005 session = openSession();
5006
5007 Query q = session.createQuery(sql);
5008
5009 QueryPos qPos = QueryPos.getInstance(q);
5010
5011 qPos.add(groupId);
5012
5013 qPos.add(parentStructureId);
5014
5015 count = (Long)q.uniqueResult();
5016
5017 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5018 }
5019 catch (Exception e) {
5020 FinderCacheUtil.removeResult(finderPath, finderArgs);
5021
5022 throw processException(e);
5023 }
5024 finally {
5025 closeSession(session);
5026 }
5027 }
5028
5029 return count.intValue();
5030 }
5031
5032
5039 @Override
5040 public int filterCountByG_P(long groupId, long parentStructureId) {
5041 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5042 return countByG_P(groupId, parentStructureId);
5043 }
5044
5045 StringBundler query = new StringBundler(3);
5046
5047 query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
5048
5049 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
5050
5051 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
5052
5053 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5054 DDMStructure.class.getName(),
5055 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5056
5057 Session session = null;
5058
5059 try {
5060 session = openSession();
5061
5062 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5063
5064 q.addScalar(COUNT_COLUMN_NAME,
5065 com.liferay.portal.kernel.dao.orm.Type.LONG);
5066
5067 QueryPos qPos = QueryPos.getInstance(q);
5068
5069 qPos.add(groupId);
5070
5071 qPos.add(parentStructureId);
5072
5073 Long count = (Long)q.uniqueResult();
5074
5075 return count.intValue();
5076 }
5077 catch (Exception e) {
5078 throw processException(e);
5079 }
5080 finally {
5081 closeSession(session);
5082 }
5083 }
5084
5085 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "ddmStructure.groupId = ? AND ";
5086 private static final String _FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2 = "ddmStructure.parentStructureId = ?";
5087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5088 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
5089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5090 new String[] {
5091 Long.class.getName(), Long.class.getName(),
5092
5093 Integer.class.getName(), Integer.class.getName(),
5094 OrderByComparator.class.getName()
5095 });
5096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5097 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
5098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5099 new String[] { Long.class.getName(), Long.class.getName() },
5100 DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
5101 DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
5102 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5103 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
5104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5105 new String[] { Long.class.getName(), Long.class.getName() });
5106 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5107 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
5108 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
5109 new String[] { Long.class.getName(), Long.class.getName() });
5110
5111
5118 @Override
5119 public List<DDMStructure> findByG_C(long groupId, long classNameId) {
5120 return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
5121 QueryUtil.ALL_POS, null);
5122 }
5123
5124
5137 @Override
5138 public List<DDMStructure> findByG_C(long groupId, long classNameId,
5139 int start, int end) {
5140 return findByG_C(groupId, classNameId, start, end, null);
5141 }
5142
5143
5157 @Override
5158 public List<DDMStructure> findByG_C(long groupId, long classNameId,
5159 int start, int end, OrderByComparator<DDMStructure> orderByComparator) {
5160 boolean pagination = true;
5161 FinderPath finderPath = null;
5162 Object[] finderArgs = null;
5163
5164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5165 (orderByComparator == null)) {
5166 pagination = false;
5167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5168 finderArgs = new Object[] { groupId, classNameId };
5169 }
5170 else {
5171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5172 finderArgs = new Object[] {
5173 groupId, classNameId,
5174
5175 start, end, orderByComparator
5176 };
5177 }
5178
5179 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
5180 finderArgs, this);
5181
5182 if ((list != null) && !list.isEmpty()) {
5183 for (DDMStructure ddmStructure : list) {
5184 if ((groupId != ddmStructure.getGroupId()) ||
5185 (classNameId != ddmStructure.getClassNameId())) {
5186 list = null;
5187
5188 break;
5189 }
5190 }
5191 }
5192
5193 if (list == null) {
5194 StringBundler query = null;
5195
5196 if (orderByComparator != null) {
5197 query = new StringBundler(4 +
5198 (orderByComparator.getOrderByFields().length * 3));
5199 }
5200 else {
5201 query = new StringBundler(4);
5202 }
5203
5204 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
5205
5206 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5207
5208 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5209
5210 if (orderByComparator != null) {
5211 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5212 orderByComparator);
5213 }
5214 else
5215 if (pagination) {
5216 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5217 }
5218
5219 String sql = query.toString();
5220
5221 Session session = null;
5222
5223 try {
5224 session = openSession();
5225
5226 Query q = session.createQuery(sql);
5227
5228 QueryPos qPos = QueryPos.getInstance(q);
5229
5230 qPos.add(groupId);
5231
5232 qPos.add(classNameId);
5233
5234 if (!pagination) {
5235 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
5236 start, end, false);
5237
5238 Collections.sort(list);
5239
5240 list = Collections.unmodifiableList(list);
5241 }
5242 else {
5243 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
5244 start, end);
5245 }
5246
5247 cacheResult(list);
5248
5249 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5250 }
5251 catch (Exception e) {
5252 FinderCacheUtil.removeResult(finderPath, finderArgs);
5253
5254 throw processException(e);
5255 }
5256 finally {
5257 closeSession(session);
5258 }
5259 }
5260
5261 return list;
5262 }
5263
5264
5273 @Override
5274 public DDMStructure findByG_C_First(long groupId, long classNameId,
5275 OrderByComparator<DDMStructure> orderByComparator)
5276 throws NoSuchStructureException {
5277 DDMStructure ddmStructure = fetchByG_C_First(groupId, classNameId,
5278 orderByComparator);
5279
5280 if (ddmStructure != null) {
5281 return ddmStructure;
5282 }
5283
5284 StringBundler msg = new StringBundler(6);
5285
5286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5287
5288 msg.append("groupId=");
5289 msg.append(groupId);
5290
5291 msg.append(", classNameId=");
5292 msg.append(classNameId);
5293
5294 msg.append(StringPool.CLOSE_CURLY_BRACE);
5295
5296 throw new NoSuchStructureException(msg.toString());
5297 }
5298
5299
5307 @Override
5308 public DDMStructure fetchByG_C_First(long groupId, long classNameId,
5309 OrderByComparator<DDMStructure> orderByComparator) {
5310 List<DDMStructure> list = findByG_C(groupId, classNameId, 0, 1,
5311 orderByComparator);
5312
5313 if (!list.isEmpty()) {
5314 return list.get(0);
5315 }
5316
5317 return null;
5318 }
5319
5320
5329 @Override
5330 public DDMStructure findByG_C_Last(long groupId, long classNameId,
5331 OrderByComparator<DDMStructure> orderByComparator)
5332 throws NoSuchStructureException {
5333 DDMStructure ddmStructure = fetchByG_C_Last(groupId, classNameId,
5334 orderByComparator);
5335
5336 if (ddmStructure != null) {
5337 return ddmStructure;
5338 }
5339
5340 StringBundler msg = new StringBundler(6);
5341
5342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5343
5344 msg.append("groupId=");
5345 msg.append(groupId);
5346
5347 msg.append(", classNameId=");
5348 msg.append(classNameId);
5349
5350 msg.append(StringPool.CLOSE_CURLY_BRACE);
5351
5352 throw new NoSuchStructureException(msg.toString());
5353 }
5354
5355
5363 @Override
5364 public DDMStructure fetchByG_C_Last(long groupId, long classNameId,
5365 OrderByComparator<DDMStructure> orderByComparator) {
5366 int count = countByG_C(groupId, classNameId);
5367
5368 if (count == 0) {
5369 return null;
5370 }
5371
5372 List<DDMStructure> list = findByG_C(groupId, classNameId, count - 1,
5373 count, orderByComparator);
5374
5375 if (!list.isEmpty()) {
5376 return list.get(0);
5377 }
5378
5379 return null;
5380 }
5381
5382
5392 @Override
5393 public DDMStructure[] findByG_C_PrevAndNext(long structureId, long groupId,
5394 long classNameId, OrderByComparator<DDMStructure> orderByComparator)
5395 throws NoSuchStructureException {
5396 DDMStructure ddmStructure = findByPrimaryKey(structureId);
5397
5398 Session session = null;
5399
5400 try {
5401 session = openSession();
5402
5403 DDMStructure[] array = new DDMStructureImpl[3];
5404
5405 array[0] = getByG_C_PrevAndNext(session, ddmStructure, groupId,
5406 classNameId, orderByComparator, true);
5407
5408 array[1] = ddmStructure;
5409
5410 array[2] = getByG_C_PrevAndNext(session, ddmStructure, groupId,
5411 classNameId, orderByComparator, false);
5412
5413 return array;
5414 }
5415 catch (Exception e) {
5416 throw processException(e);
5417 }
5418 finally {
5419 closeSession(session);
5420 }
5421 }
5422
5423 protected DDMStructure getByG_C_PrevAndNext(Session session,
5424 DDMStructure ddmStructure, long groupId, long classNameId,
5425 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
5426 StringBundler query = null;
5427
5428 if (orderByComparator != null) {
5429 query = new StringBundler(6 +
5430 (orderByComparator.getOrderByFields().length * 6));
5431 }
5432 else {
5433 query = new StringBundler(3);
5434 }
5435
5436 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
5437
5438 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5439
5440 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5441
5442 if (orderByComparator != null) {
5443 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5444
5445 if (orderByConditionFields.length > 0) {
5446 query.append(WHERE_AND);
5447 }
5448
5449 for (int i = 0; i < orderByConditionFields.length; i++) {
5450 query.append(_ORDER_BY_ENTITY_ALIAS);
5451 query.append(orderByConditionFields[i]);
5452
5453 if ((i + 1) < orderByConditionFields.length) {
5454 if (orderByComparator.isAscending() ^ previous) {
5455 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5456 }
5457 else {
5458 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5459 }
5460 }
5461 else {
5462 if (orderByComparator.isAscending() ^ previous) {
5463 query.append(WHERE_GREATER_THAN);
5464 }
5465 else {
5466 query.append(WHERE_LESSER_THAN);
5467 }
5468 }
5469 }
5470
5471 query.append(ORDER_BY_CLAUSE);
5472
5473 String[] orderByFields = orderByComparator.getOrderByFields();
5474
5475 for (int i = 0; i < orderByFields.length; i++) {
5476 query.append(_ORDER_BY_ENTITY_ALIAS);
5477 query.append(orderByFields[i]);
5478
5479 if ((i + 1) < orderByFields.length) {
5480 if (orderByComparator.isAscending() ^ previous) {
5481 query.append(ORDER_BY_ASC_HAS_NEXT);
5482 }
5483 else {
5484 query.append(ORDER_BY_DESC_HAS_NEXT);
5485 }
5486 }
5487 else {
5488 if (orderByComparator.isAscending() ^ previous) {
5489 query.append(ORDER_BY_ASC);
5490 }
5491 else {
5492 query.append(ORDER_BY_DESC);
5493 }
5494 }
5495 }
5496 }
5497 else {
5498 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5499 }
5500
5501 String sql = query.toString();
5502
5503 Query q = session.createQuery(sql);
5504
5505 q.setFirstResult(0);
5506 q.setMaxResults(2);
5507
5508 QueryPos qPos = QueryPos.getInstance(q);
5509
5510 qPos.add(groupId);
5511
5512 qPos.add(classNameId);
5513
5514 if (orderByComparator != null) {
5515 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
5516
5517 for (Object value : values) {
5518 qPos.add(value);
5519 }
5520 }
5521
5522 List<DDMStructure> list = q.list();
5523
5524 if (list.size() == 2) {
5525 return list.get(1);
5526 }
5527 else {
5528 return null;
5529 }
5530 }
5531
5532
5539 @Override
5540 public List<DDMStructure> filterFindByG_C(long groupId, long classNameId) {
5541 return filterFindByG_C(groupId, classNameId, QueryUtil.ALL_POS,
5542 QueryUtil.ALL_POS, null);
5543 }
5544
5545
5558 @Override
5559 public List<DDMStructure> filterFindByG_C(long groupId, long classNameId,
5560 int start, int end) {
5561 return filterFindByG_C(groupId, classNameId, start, end, null);
5562 }
5563
5564
5578 @Override
5579 public List<DDMStructure> filterFindByG_C(long groupId, long classNameId,
5580 int start, int end, OrderByComparator<DDMStructure> orderByComparator) {
5581 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5582 return findByG_C(groupId, classNameId, start, end, orderByComparator);
5583 }
5584
5585 StringBundler query = null;
5586
5587 if (orderByComparator != null) {
5588 query = new StringBundler(4 +
5589 (orderByComparator.getOrderByFields().length * 3));
5590 }
5591 else {
5592 query = new StringBundler(4);
5593 }
5594
5595 if (getDB().isSupportsInlineDistinct()) {
5596 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
5597 }
5598 else {
5599 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
5600 }
5601
5602 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5603
5604 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5605
5606 if (!getDB().isSupportsInlineDistinct()) {
5607 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
5608 }
5609
5610 if (orderByComparator != null) {
5611 if (getDB().isSupportsInlineDistinct()) {
5612 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5613 orderByComparator, true);
5614 }
5615 else {
5616 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5617 orderByComparator, true);
5618 }
5619 }
5620 else {
5621 if (getDB().isSupportsInlineDistinct()) {
5622 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5623 }
5624 else {
5625 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
5626 }
5627 }
5628
5629 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5630 DDMStructure.class.getName(),
5631 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5632
5633 Session session = null;
5634
5635 try {
5636 session = openSession();
5637
5638 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5639
5640 if (getDB().isSupportsInlineDistinct()) {
5641 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
5642 }
5643 else {
5644 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
5645 }
5646
5647 QueryPos qPos = QueryPos.getInstance(q);
5648
5649 qPos.add(groupId);
5650
5651 qPos.add(classNameId);
5652
5653 return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
5654 end);
5655 }
5656 catch (Exception e) {
5657 throw processException(e);
5658 }
5659 finally {
5660 closeSession(session);
5661 }
5662 }
5663
5664
5674 @Override
5675 public DDMStructure[] filterFindByG_C_PrevAndNext(long structureId,
5676 long groupId, long classNameId,
5677 OrderByComparator<DDMStructure> orderByComparator)
5678 throws NoSuchStructureException {
5679 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5680 return findByG_C_PrevAndNext(structureId, groupId, classNameId,
5681 orderByComparator);
5682 }
5683
5684 DDMStructure ddmStructure = findByPrimaryKey(structureId);
5685
5686 Session session = null;
5687
5688 try {
5689 session = openSession();
5690
5691 DDMStructure[] array = new DDMStructureImpl[3];
5692
5693 array[0] = filterGetByG_C_PrevAndNext(session, ddmStructure,
5694 groupId, classNameId, orderByComparator, true);
5695
5696 array[1] = ddmStructure;
5697
5698 array[2] = filterGetByG_C_PrevAndNext(session, ddmStructure,
5699 groupId, classNameId, orderByComparator, false);
5700
5701 return array;
5702 }
5703 catch (Exception e) {
5704 throw processException(e);
5705 }
5706 finally {
5707 closeSession(session);
5708 }
5709 }
5710
5711 protected DDMStructure filterGetByG_C_PrevAndNext(Session session,
5712 DDMStructure ddmStructure, long groupId, long classNameId,
5713 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
5714 StringBundler query = null;
5715
5716 if (orderByComparator != null) {
5717 query = new StringBundler(6 +
5718 (orderByComparator.getOrderByFields().length * 6));
5719 }
5720 else {
5721 query = new StringBundler(3);
5722 }
5723
5724 if (getDB().isSupportsInlineDistinct()) {
5725 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
5726 }
5727 else {
5728 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
5729 }
5730
5731 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5732
5733 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5734
5735 if (!getDB().isSupportsInlineDistinct()) {
5736 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
5737 }
5738
5739 if (orderByComparator != null) {
5740 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5741
5742 if (orderByConditionFields.length > 0) {
5743 query.append(WHERE_AND);
5744 }
5745
5746 for (int i = 0; i < orderByConditionFields.length; i++) {
5747 if (getDB().isSupportsInlineDistinct()) {
5748 query.append(_ORDER_BY_ENTITY_ALIAS);
5749 }
5750 else {
5751 query.append(_ORDER_BY_ENTITY_TABLE);
5752 }
5753
5754 query.append(orderByConditionFields[i]);
5755
5756 if ((i + 1) < orderByConditionFields.length) {
5757 if (orderByComparator.isAscending() ^ previous) {
5758 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5759 }
5760 else {
5761 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5762 }
5763 }
5764 else {
5765 if (orderByComparator.isAscending() ^ previous) {
5766 query.append(WHERE_GREATER_THAN);
5767 }
5768 else {
5769 query.append(WHERE_LESSER_THAN);
5770 }
5771 }
5772 }
5773
5774 query.append(ORDER_BY_CLAUSE);
5775
5776 String[] orderByFields = orderByComparator.getOrderByFields();
5777
5778 for (int i = 0; i < orderByFields.length; i++) {
5779 if (getDB().isSupportsInlineDistinct()) {
5780 query.append(_ORDER_BY_ENTITY_ALIAS);
5781 }
5782 else {
5783 query.append(_ORDER_BY_ENTITY_TABLE);
5784 }
5785
5786 query.append(orderByFields[i]);
5787
5788 if ((i + 1) < orderByFields.length) {
5789 if (orderByComparator.isAscending() ^ previous) {
5790 query.append(ORDER_BY_ASC_HAS_NEXT);
5791 }
5792 else {
5793 query.append(ORDER_BY_DESC_HAS_NEXT);
5794 }
5795 }
5796 else {
5797 if (orderByComparator.isAscending() ^ previous) {
5798 query.append(ORDER_BY_ASC);
5799 }
5800 else {
5801 query.append(ORDER_BY_DESC);
5802 }
5803 }
5804 }
5805 }
5806 else {
5807 if (getDB().isSupportsInlineDistinct()) {
5808 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5809 }
5810 else {
5811 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
5812 }
5813 }
5814
5815 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5816 DDMStructure.class.getName(),
5817 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5818
5819 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5820
5821 q.setFirstResult(0);
5822 q.setMaxResults(2);
5823
5824 if (getDB().isSupportsInlineDistinct()) {
5825 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
5826 }
5827 else {
5828 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
5829 }
5830
5831 QueryPos qPos = QueryPos.getInstance(q);
5832
5833 qPos.add(groupId);
5834
5835 qPos.add(classNameId);
5836
5837 if (orderByComparator != null) {
5838 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
5839
5840 for (Object value : values) {
5841 qPos.add(value);
5842 }
5843 }
5844
5845 List<DDMStructure> list = q.list();
5846
5847 if (list.size() == 2) {
5848 return list.get(1);
5849 }
5850 else {
5851 return null;
5852 }
5853 }
5854
5855
5862 @Override
5863 public List<DDMStructure> filterFindByG_C(long[] groupIds, long classNameId) {
5864 return filterFindByG_C(groupIds, classNameId, QueryUtil.ALL_POS,
5865 QueryUtil.ALL_POS, null);
5866 }
5867
5868
5881 @Override
5882 public List<DDMStructure> filterFindByG_C(long[] groupIds,
5883 long classNameId, int start, int end) {
5884 return filterFindByG_C(groupIds, classNameId, start, end, null);
5885 }
5886
5887
5901 @Override
5902 public List<DDMStructure> filterFindByG_C(long[] groupIds,
5903 long classNameId, int start, int end,
5904 OrderByComparator<DDMStructure> orderByComparator) {
5905 if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
5906 return findByG_C(groupIds, classNameId, start, end,
5907 orderByComparator);
5908 }
5909
5910 if (groupIds == null) {
5911 groupIds = new long[0];
5912 }
5913 else {
5914 groupIds = ArrayUtil.unique(groupIds);
5915 }
5916
5917 StringBundler query = new StringBundler();
5918
5919 if (getDB().isSupportsInlineDistinct()) {
5920 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
5921 }
5922 else {
5923 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
5924 }
5925
5926 if (groupIds.length > 0) {
5927 query.append(StringPool.OPEN_PARENTHESIS);
5928
5929 query.append(_FINDER_COLUMN_G_C_GROUPID_7);
5930
5931 query.append(StringUtil.merge(groupIds));
5932
5933 query.append(StringPool.CLOSE_PARENTHESIS);
5934
5935 query.append(StringPool.CLOSE_PARENTHESIS);
5936
5937 query.append(WHERE_AND);
5938 }
5939
5940 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5941
5942 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
5943 query.index() - 1);
5944
5945 if (!getDB().isSupportsInlineDistinct()) {
5946 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
5947 }
5948
5949 if (orderByComparator != null) {
5950 if (getDB().isSupportsInlineDistinct()) {
5951 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5952 orderByComparator, true);
5953 }
5954 else {
5955 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5956 orderByComparator, true);
5957 }
5958 }
5959 else {
5960 if (getDB().isSupportsInlineDistinct()) {
5961 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5962 }
5963 else {
5964 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
5965 }
5966 }
5967
5968 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5969 DDMStructure.class.getName(),
5970 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
5971
5972 Session session = null;
5973
5974 try {
5975 session = openSession();
5976
5977 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5978
5979 if (getDB().isSupportsInlineDistinct()) {
5980 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
5981 }
5982 else {
5983 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
5984 }
5985
5986 QueryPos qPos = QueryPos.getInstance(q);
5987
5988 qPos.add(classNameId);
5989
5990 return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
5991 end);
5992 }
5993 catch (Exception e) {
5994 throw processException(e);
5995 }
5996 finally {
5997 closeSession(session);
5998 }
5999 }
6000
6001
6012 @Override
6013 public List<DDMStructure> findByG_C(long[] groupIds, long classNameId) {
6014 return findByG_C(groupIds, classNameId, QueryUtil.ALL_POS,
6015 QueryUtil.ALL_POS, null);
6016 }
6017
6018
6031 @Override
6032 public List<DDMStructure> findByG_C(long[] groupIds, long classNameId,
6033 int start, int end) {
6034 return findByG_C(groupIds, classNameId, start, end, null);
6035 }
6036
6037
6051 @Override
6052 public List<DDMStructure> findByG_C(long[] groupIds, long classNameId,
6053 int start, int end, OrderByComparator<DDMStructure> orderByComparator) {
6054 if (groupIds == null) {
6055 groupIds = new long[0];
6056 }
6057 else {
6058 groupIds = ArrayUtil.unique(groupIds);
6059 }
6060
6061 if (groupIds.length == 1) {
6062 return findByG_C(groupIds[0], classNameId, start, end,
6063 orderByComparator);
6064 }
6065
6066 boolean pagination = true;
6067 Object[] finderArgs = null;
6068
6069 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6070 (orderByComparator == null)) {
6071 pagination = false;
6072 finderArgs = new Object[] { StringUtil.merge(groupIds), classNameId };
6073 }
6074 else {
6075 finderArgs = new Object[] {
6076 StringUtil.merge(groupIds), classNameId,
6077
6078 start, end, orderByComparator
6079 };
6080 }
6081
6082 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
6083 finderArgs, this);
6084
6085 if ((list != null) && !list.isEmpty()) {
6086 for (DDMStructure ddmStructure : list) {
6087 if (!ArrayUtil.contains(groupIds, ddmStructure.getGroupId()) ||
6088 (classNameId != ddmStructure.getClassNameId())) {
6089 list = null;
6090
6091 break;
6092 }
6093 }
6094 }
6095
6096 if (list == null) {
6097 StringBundler query = new StringBundler();
6098
6099 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
6100
6101 if (groupIds.length > 0) {
6102 query.append(StringPool.OPEN_PARENTHESIS);
6103
6104 query.append(_FINDER_COLUMN_G_C_GROUPID_7);
6105
6106 query.append(StringUtil.merge(groupIds));
6107
6108 query.append(StringPool.CLOSE_PARENTHESIS);
6109
6110 query.append(StringPool.CLOSE_PARENTHESIS);
6111
6112 query.append(WHERE_AND);
6113 }
6114
6115 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
6116
6117 query.setStringAt(removeConjunction(query.stringAt(query.index() -
6118 1)), query.index() - 1);
6119
6120 if (orderByComparator != null) {
6121 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6122 orderByComparator);
6123 }
6124 else
6125 if (pagination) {
6126 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
6127 }
6128
6129 String sql = query.toString();
6130
6131 Session session = null;
6132
6133 try {
6134 session = openSession();
6135
6136 Query q = session.createQuery(sql);
6137
6138 QueryPos qPos = QueryPos.getInstance(q);
6139
6140 qPos.add(classNameId);
6141
6142 if (!pagination) {
6143 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
6144 start, end, false);
6145
6146 Collections.sort(list);
6147
6148 list = Collections.unmodifiableList(list);
6149 }
6150 else {
6151 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
6152 start, end);
6153 }
6154
6155 cacheResult(list);
6156
6157 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
6158 finderArgs, list);
6159 }
6160 catch (Exception e) {
6161 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
6162 finderArgs);
6163
6164 throw processException(e);
6165 }
6166 finally {
6167 closeSession(session);
6168 }
6169 }
6170
6171 return list;
6172 }
6173
6174
6180 @Override
6181 public void removeByG_C(long groupId, long classNameId) {
6182 for (DDMStructure ddmStructure : findByG_C(groupId, classNameId,
6183 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6184 remove(ddmStructure);
6185 }
6186 }
6187
6188
6195 @Override
6196 public int countByG_C(long groupId, long classNameId) {
6197 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
6198
6199 Object[] finderArgs = new Object[] { groupId, classNameId };
6200
6201 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6202 this);
6203
6204 if (count == null) {
6205 StringBundler query = new StringBundler(3);
6206
6207 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
6208
6209 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6210
6211 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
6212
6213 String sql = query.toString();
6214
6215 Session session = null;
6216
6217 try {
6218 session = openSession();
6219
6220 Query q = session.createQuery(sql);
6221
6222 QueryPos qPos = QueryPos.getInstance(q);
6223
6224 qPos.add(groupId);
6225
6226 qPos.add(classNameId);
6227
6228 count = (Long)q.uniqueResult();
6229
6230 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6231 }
6232 catch (Exception e) {
6233 FinderCacheUtil.removeResult(finderPath, finderArgs);
6234
6235 throw processException(e);
6236 }
6237 finally {
6238 closeSession(session);
6239 }
6240 }
6241
6242 return count.intValue();
6243 }
6244
6245
6252 @Override
6253 public int countByG_C(long[] groupIds, long classNameId) {
6254 if (groupIds == null) {
6255 groupIds = new long[0];
6256 }
6257 else {
6258 groupIds = ArrayUtil.unique(groupIds);
6259 }
6260
6261 Object[] finderArgs = new Object[] {
6262 StringUtil.merge(groupIds), classNameId
6263 };
6264
6265 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
6266 finderArgs, this);
6267
6268 if (count == null) {
6269 StringBundler query = new StringBundler();
6270
6271 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
6272
6273 if (groupIds.length > 0) {
6274 query.append(StringPool.OPEN_PARENTHESIS);
6275
6276 query.append(_FINDER_COLUMN_G_C_GROUPID_7);
6277
6278 query.append(StringUtil.merge(groupIds));
6279
6280 query.append(StringPool.CLOSE_PARENTHESIS);
6281
6282 query.append(StringPool.CLOSE_PARENTHESIS);
6283
6284 query.append(WHERE_AND);
6285 }
6286
6287 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
6288
6289 query.setStringAt(removeConjunction(query.stringAt(query.index() -
6290 1)), query.index() - 1);
6291
6292 String sql = query.toString();
6293
6294 Session session = null;
6295
6296 try {
6297 session = openSession();
6298
6299 Query q = session.createQuery(sql);
6300
6301 QueryPos qPos = QueryPos.getInstance(q);
6302
6303 qPos.add(classNameId);
6304
6305 count = (Long)q.uniqueResult();
6306
6307 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
6308 finderArgs, count);
6309 }
6310 catch (Exception e) {
6311 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
6312 finderArgs);
6313
6314 throw processException(e);
6315 }
6316 finally {
6317 closeSession(session);
6318 }
6319 }
6320
6321 return count.intValue();
6322 }
6323
6324
6331 @Override
6332 public int filterCountByG_C(long groupId, long classNameId) {
6333 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6334 return countByG_C(groupId, classNameId);
6335 }
6336
6337 StringBundler query = new StringBundler(3);
6338
6339 query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
6340
6341 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6342
6343 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
6344
6345 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6346 DDMStructure.class.getName(),
6347 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6348
6349 Session session = null;
6350
6351 try {
6352 session = openSession();
6353
6354 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6355
6356 q.addScalar(COUNT_COLUMN_NAME,
6357 com.liferay.portal.kernel.dao.orm.Type.LONG);
6358
6359 QueryPos qPos = QueryPos.getInstance(q);
6360
6361 qPos.add(groupId);
6362
6363 qPos.add(classNameId);
6364
6365 Long count = (Long)q.uniqueResult();
6366
6367 return count.intValue();
6368 }
6369 catch (Exception e) {
6370 throw processException(e);
6371 }
6372 finally {
6373 closeSession(session);
6374 }
6375 }
6376
6377
6384 @Override
6385 public int filterCountByG_C(long[] groupIds, long classNameId) {
6386 if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
6387 return countByG_C(groupIds, classNameId);
6388 }
6389
6390 if (groupIds == null) {
6391 groupIds = new long[0];
6392 }
6393 else {
6394 groupIds = ArrayUtil.unique(groupIds);
6395 }
6396
6397 StringBundler query = new StringBundler();
6398
6399 query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
6400
6401 if (groupIds.length > 0) {
6402 query.append(StringPool.OPEN_PARENTHESIS);
6403
6404 query.append(_FINDER_COLUMN_G_C_GROUPID_7);
6405
6406 query.append(StringUtil.merge(groupIds));
6407
6408 query.append(StringPool.CLOSE_PARENTHESIS);
6409
6410 query.append(StringPool.CLOSE_PARENTHESIS);
6411
6412 query.append(WHERE_AND);
6413 }
6414
6415 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
6416
6417 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6418 query.index() - 1);
6419
6420 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6421 DDMStructure.class.getName(),
6422 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
6423
6424 Session session = null;
6425
6426 try {
6427 session = openSession();
6428
6429 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6430
6431 q.addScalar(COUNT_COLUMN_NAME,
6432 com.liferay.portal.kernel.dao.orm.Type.LONG);
6433
6434 QueryPos qPos = QueryPos.getInstance(q);
6435
6436 qPos.add(classNameId);
6437
6438 Long count = (Long)q.uniqueResult();
6439
6440 return count.intValue();
6441 }
6442 catch (Exception e) {
6443 throw processException(e);
6444 }
6445 finally {
6446 closeSession(session);
6447 }
6448 }
6449
6450 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "ddmStructure.groupId = ? AND ";
6451 private static final String _FINDER_COLUMN_G_C_GROUPID_7 = "ddmStructure.groupId IN (";
6452 private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
6453 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6454 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
6455 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
6456 new String[] {
6457 Long.class.getName(), Long.class.getName(),
6458
6459 Integer.class.getName(), Integer.class.getName(),
6460 OrderByComparator.class.getName()
6461 });
6462 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6463 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
6464 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
6465 new String[] { Long.class.getName(), Long.class.getName() },
6466 DDMStructureModelImpl.COMPANYID_COLUMN_BITMASK |
6467 DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
6468 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6469 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
6470 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
6471 new String[] { Long.class.getName(), Long.class.getName() });
6472
6473
6480 @Override
6481 public List<DDMStructure> findByC_C(long companyId, long classNameId) {
6482 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
6483 QueryUtil.ALL_POS, null);
6484 }
6485
6486
6499 @Override
6500 public List<DDMStructure> findByC_C(long companyId, long classNameId,
6501 int start, int end) {
6502 return findByC_C(companyId, classNameId, start, end, null);
6503 }
6504
6505
6519 @Override
6520 public List<DDMStructure> findByC_C(long companyId, long classNameId,
6521 int start, int end, OrderByComparator<DDMStructure> orderByComparator) {
6522 boolean pagination = true;
6523 FinderPath finderPath = null;
6524 Object[] finderArgs = null;
6525
6526 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6527 (orderByComparator == null)) {
6528 pagination = false;
6529 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
6530 finderArgs = new Object[] { companyId, classNameId };
6531 }
6532 else {
6533 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
6534 finderArgs = new Object[] {
6535 companyId, classNameId,
6536
6537 start, end, orderByComparator
6538 };
6539 }
6540
6541 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
6542 finderArgs, this);
6543
6544 if ((list != null) && !list.isEmpty()) {
6545 for (DDMStructure ddmStructure : list) {
6546 if ((companyId != ddmStructure.getCompanyId()) ||
6547 (classNameId != ddmStructure.getClassNameId())) {
6548 list = null;
6549
6550 break;
6551 }
6552 }
6553 }
6554
6555 if (list == null) {
6556 StringBundler query = null;
6557
6558 if (orderByComparator != null) {
6559 query = new StringBundler(4 +
6560 (orderByComparator.getOrderByFields().length * 3));
6561 }
6562 else {
6563 query = new StringBundler(4);
6564 }
6565
6566 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
6567
6568 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
6569
6570 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
6571
6572 if (orderByComparator != null) {
6573 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6574 orderByComparator);
6575 }
6576 else
6577 if (pagination) {
6578 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
6579 }
6580
6581 String sql = query.toString();
6582
6583 Session session = null;
6584
6585 try {
6586 session = openSession();
6587
6588 Query q = session.createQuery(sql);
6589
6590 QueryPos qPos = QueryPos.getInstance(q);
6591
6592 qPos.add(companyId);
6593
6594 qPos.add(classNameId);
6595
6596 if (!pagination) {
6597 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
6598 start, end, false);
6599
6600 Collections.sort(list);
6601
6602 list = Collections.unmodifiableList(list);
6603 }
6604 else {
6605 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
6606 start, end);
6607 }
6608
6609 cacheResult(list);
6610
6611 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6612 }
6613 catch (Exception e) {
6614 FinderCacheUtil.removeResult(finderPath, finderArgs);
6615
6616 throw processException(e);
6617 }
6618 finally {
6619 closeSession(session);
6620 }
6621 }
6622
6623 return list;
6624 }
6625
6626
6635 @Override
6636 public DDMStructure findByC_C_First(long companyId, long classNameId,
6637 OrderByComparator<DDMStructure> orderByComparator)
6638 throws NoSuchStructureException {
6639 DDMStructure ddmStructure = fetchByC_C_First(companyId, classNameId,
6640 orderByComparator);
6641
6642 if (ddmStructure != null) {
6643 return ddmStructure;
6644 }
6645
6646 StringBundler msg = new StringBundler(6);
6647
6648 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6649
6650 msg.append("companyId=");
6651 msg.append(companyId);
6652
6653 msg.append(", classNameId=");
6654 msg.append(classNameId);
6655
6656 msg.append(StringPool.CLOSE_CURLY_BRACE);
6657
6658 throw new NoSuchStructureException(msg.toString());
6659 }
6660
6661
6669 @Override
6670 public DDMStructure fetchByC_C_First(long companyId, long classNameId,
6671 OrderByComparator<DDMStructure> orderByComparator) {
6672 List<DDMStructure> list = findByC_C(companyId, classNameId, 0, 1,
6673 orderByComparator);
6674
6675 if (!list.isEmpty()) {
6676 return list.get(0);
6677 }
6678
6679 return null;
6680 }
6681
6682
6691 @Override
6692 public DDMStructure findByC_C_Last(long companyId, long classNameId,
6693 OrderByComparator<DDMStructure> orderByComparator)
6694 throws NoSuchStructureException {
6695 DDMStructure ddmStructure = fetchByC_C_Last(companyId, classNameId,
6696 orderByComparator);
6697
6698 if (ddmStructure != null) {
6699 return ddmStructure;
6700 }
6701
6702 StringBundler msg = new StringBundler(6);
6703
6704 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6705
6706 msg.append("companyId=");
6707 msg.append(companyId);
6708
6709 msg.append(", classNameId=");
6710 msg.append(classNameId);
6711
6712 msg.append(StringPool.CLOSE_CURLY_BRACE);
6713
6714 throw new NoSuchStructureException(msg.toString());
6715 }
6716
6717
6725 @Override
6726 public DDMStructure fetchByC_C_Last(long companyId, long classNameId,
6727 OrderByComparator<DDMStructure> orderByComparator) {
6728 int count = countByC_C(companyId, classNameId);
6729
6730 if (count == 0) {
6731 return null;
6732 }
6733
6734 List<DDMStructure> list = findByC_C(companyId, classNameId, count - 1,
6735 count, orderByComparator);
6736
6737 if (!list.isEmpty()) {
6738 return list.get(0);
6739 }
6740
6741 return null;
6742 }
6743
6744
6754 @Override
6755 public DDMStructure[] findByC_C_PrevAndNext(long structureId,
6756 long companyId, long classNameId,
6757 OrderByComparator<DDMStructure> orderByComparator)
6758 throws NoSuchStructureException {
6759 DDMStructure ddmStructure = findByPrimaryKey(structureId);
6760
6761 Session session = null;
6762
6763 try {
6764 session = openSession();
6765
6766 DDMStructure[] array = new DDMStructureImpl[3];
6767
6768 array[0] = getByC_C_PrevAndNext(session, ddmStructure, companyId,
6769 classNameId, orderByComparator, true);
6770
6771 array[1] = ddmStructure;
6772
6773 array[2] = getByC_C_PrevAndNext(session, ddmStructure, companyId,
6774 classNameId, orderByComparator, false);
6775
6776 return array;
6777 }
6778 catch (Exception e) {
6779 throw processException(e);
6780 }
6781 finally {
6782 closeSession(session);
6783 }
6784 }
6785
6786 protected DDMStructure getByC_C_PrevAndNext(Session session,
6787 DDMStructure ddmStructure, long companyId, long classNameId,
6788 OrderByComparator<DDMStructure> orderByComparator, boolean previous) {
6789 StringBundler query = null;
6790
6791 if (orderByComparator != null) {
6792 query = new StringBundler(6 +
6793 (orderByComparator.getOrderByFields().length * 6));
6794 }
6795 else {
6796 query = new StringBundler(3);
6797 }
6798
6799 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
6800
6801 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
6802
6803 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
6804
6805 if (orderByComparator != null) {
6806 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6807
6808 if (orderByConditionFields.length > 0) {
6809 query.append(WHERE_AND);
6810 }
6811
6812 for (int i = 0; i < orderByConditionFields.length; i++) {
6813 query.append(_ORDER_BY_ENTITY_ALIAS);
6814 query.append(orderByConditionFields[i]);
6815
6816 if ((i + 1) < orderByConditionFields.length) {
6817 if (orderByComparator.isAscending() ^ previous) {
6818 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6819 }
6820 else {
6821 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6822 }
6823 }
6824 else {
6825 if (orderByComparator.isAscending() ^ previous) {
6826 query.append(WHERE_GREATER_THAN);
6827 }
6828 else {
6829 query.append(WHERE_LESSER_THAN);
6830 }
6831 }
6832 }
6833
6834 query.append(ORDER_BY_CLAUSE);
6835
6836 String[] orderByFields = orderByComparator.getOrderByFields();
6837
6838 for (int i = 0; i < orderByFields.length; i++) {
6839 query.append(_ORDER_BY_ENTITY_ALIAS);
6840 query.append(orderByFields[i]);
6841
6842 if ((i + 1) < orderByFields.length) {
6843 if (orderByComparator.isAscending() ^ previous) {
6844 query.append(ORDER_BY_ASC_HAS_NEXT);
6845 }
6846 else {
6847 query.append(ORDER_BY_DESC_HAS_NEXT);
6848 }
6849 }
6850 else {
6851 if (orderByComparator.isAscending() ^ previous) {
6852 query.append(ORDER_BY_ASC);
6853 }
6854 else {
6855 query.append(ORDER_BY_DESC);
6856 }
6857 }
6858 }
6859 }
6860 else {
6861 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
6862 }
6863
6864 String sql = query.toString();
6865
6866 Query q = session.createQuery(sql);
6867
6868 q.setFirstResult(0);
6869 q.setMaxResults(2);
6870
6871 QueryPos qPos = QueryPos.getInstance(q);
6872
6873 qPos.add(companyId);
6874
6875 qPos.add(classNameId);
6876
6877 if (orderByComparator != null) {
6878 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
6879
6880 for (Object value : values) {
6881 qPos.add(value);
6882 }
6883 }
6884
6885 List<DDMStructure> list = q.list();
6886
6887 if (list.size() == 2) {
6888 return list.get(1);
6889 }
6890 else {
6891 return null;
6892 }
6893 }
6894
6895
6901 @Override
6902 public void removeByC_C(long companyId, long classNameId) {
6903 for (DDMStructure ddmStructure : findByC_C(companyId, classNameId,
6904 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6905 remove(ddmStructure);
6906 }
6907 }
6908
6909
6916 @Override
6917 public int countByC_C(long companyId, long classNameId) {
6918 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
6919
6920 Object[] finderArgs = new Object[] { companyId, classNameId };
6921
6922 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6923 this);
6924
6925 if (count == null) {
6926 StringBundler query = new StringBundler(3);
6927
6928 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
6929
6930 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
6931
6932 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
6933
6934 String sql = query.toString();
6935
6936 Session session = null;
6937
6938 try {
6939 session = openSession();
6940
6941 Query q = session.createQuery(sql);
6942
6943 QueryPos qPos = QueryPos.getInstance(q);
6944
6945 qPos.add(companyId);
6946
6947 qPos.add(classNameId);
6948
6949 count = (Long)q.uniqueResult();
6950
6951 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6952 }
6953 catch (Exception e) {
6954 FinderCacheUtil.removeResult(finderPath, finderArgs);
6955
6956 throw processException(e);
6957 }
6958 finally {
6959 closeSession(session);
6960 }
6961 }
6962
6963 return count.intValue();
6964 }
6965
6966 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "ddmStructure.companyId = ? AND ";
6967 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
6968 public static final FinderPath FINDER_PATH_FETCH_BY_G_C_S = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6969 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
6970 FINDER_CLASS_NAME_ENTITY, "fetchByG_C_S",
6971 new String[] {
6972 Long.class.getName(), Long.class.getName(),
6973 String.class.getName()
6974 },
6975 DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
6976 DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK |
6977 DDMStructureModelImpl.STRUCTUREKEY_COLUMN_BITMASK);
6978 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6979 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
6980 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
6981 new String[] {
6982 Long.class.getName(), Long.class.getName(),
6983 String.class.getName()
6984 });
6985
6986
6995 @Override
6996 public DDMStructure findByG_C_S(long groupId, long classNameId,
6997 String structureKey) throws NoSuchStructureException {
6998 DDMStructure ddmStructure = fetchByG_C_S(groupId, classNameId,
6999 structureKey);
7000
7001 if (ddmStructure == null) {
7002 StringBundler msg = new StringBundler(8);
7003
7004 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7005
7006 msg.append("groupId=");
7007 msg.append(groupId);
7008
7009 msg.append(", classNameId=");
7010 msg.append(classNameId);
7011
7012 msg.append(", structureKey=");
7013 msg.append(structureKey);
7014
7015 msg.append(StringPool.CLOSE_CURLY_BRACE);
7016
7017 if (_log.isWarnEnabled()) {
7018 _log.warn(msg.toString());
7019 }
7020
7021 throw new NoSuchStructureException(msg.toString());
7022 }
7023
7024 return ddmStructure;
7025 }
7026
7027
7035 @Override
7036 public DDMStructure fetchByG_C_S(long groupId, long classNameId,
7037 String structureKey) {
7038 return fetchByG_C_S(groupId, classNameId, structureKey, true);
7039 }
7040
7041
7050 @Override
7051 public DDMStructure fetchByG_C_S(long groupId, long classNameId,
7052 String structureKey, boolean retrieveFromCache) {
7053 Object[] finderArgs = new Object[] { groupId, classNameId, structureKey };
7054
7055 Object result = null;
7056
7057 if (retrieveFromCache) {
7058 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_S,
7059 finderArgs, this);
7060 }
7061
7062 if (result instanceof DDMStructure) {
7063 DDMStructure ddmStructure = (DDMStructure)result;
7064
7065 if ((groupId != ddmStructure.getGroupId()) ||
7066 (classNameId != ddmStructure.getClassNameId()) ||
7067 !Validator.equals(structureKey,
7068 ddmStructure.getStructureKey())) {
7069 result = null;
7070 }
7071 }
7072
7073 if (result == null) {
7074 StringBundler query = new StringBundler(5);
7075
7076 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
7077
7078 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7079
7080 query.append(_FINDER_COLUMN_G_C_S_CLASSNAMEID_2);
7081
7082 boolean bindStructureKey = false;
7083
7084 if (structureKey == null) {
7085 query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_1);
7086 }
7087 else if (structureKey.equals(StringPool.BLANK)) {
7088 query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_3);
7089 }
7090 else {
7091 bindStructureKey = true;
7092
7093 query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_2);
7094 }
7095
7096 String sql = query.toString();
7097
7098 Session session = null;
7099
7100 try {
7101 session = openSession();
7102
7103 Query q = session.createQuery(sql);
7104
7105 QueryPos qPos = QueryPos.getInstance(q);
7106
7107 qPos.add(groupId);
7108
7109 qPos.add(classNameId);
7110
7111 if (bindStructureKey) {
7112 qPos.add(structureKey);
7113 }
7114
7115 List<DDMStructure> list = q.list();
7116
7117 if (list.isEmpty()) {
7118 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
7119 finderArgs, list);
7120 }
7121 else {
7122 DDMStructure ddmStructure = list.get(0);
7123
7124 result = ddmStructure;
7125
7126 cacheResult(ddmStructure);
7127
7128 if ((ddmStructure.getGroupId() != groupId) ||
7129 (ddmStructure.getClassNameId() != classNameId) ||
7130 (ddmStructure.getStructureKey() == null) ||
7131 !ddmStructure.getStructureKey().equals(structureKey)) {
7132 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
7133 finderArgs, ddmStructure);
7134 }
7135 }
7136 }
7137 catch (Exception e) {
7138 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S,
7139 finderArgs);
7140
7141 throw processException(e);
7142 }
7143 finally {
7144 closeSession(session);
7145 }
7146 }
7147
7148 if (result instanceof List<?>) {
7149 return null;
7150 }
7151 else {
7152 return (DDMStructure)result;
7153 }
7154 }
7155
7156
7164 @Override
7165 public DDMStructure removeByG_C_S(long groupId, long classNameId,
7166 String structureKey) throws NoSuchStructureException {
7167 DDMStructure ddmStructure = findByG_C_S(groupId, classNameId,
7168 structureKey);
7169
7170 return remove(ddmStructure);
7171 }
7172
7173
7181 @Override
7182 public int countByG_C_S(long groupId, long classNameId, String structureKey) {
7183 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
7184
7185 Object[] finderArgs = new Object[] { groupId, classNameId, structureKey };
7186
7187 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7188 this);
7189
7190 if (count == null) {
7191 StringBundler query = new StringBundler(4);
7192
7193 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
7194
7195 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7196
7197 query.append(_FINDER_COLUMN_G_C_S_CLASSNAMEID_2);
7198
7199 boolean bindStructureKey = false;
7200
7201 if (structureKey == null) {
7202 query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_1);
7203 }
7204 else if (structureKey.equals(StringPool.BLANK)) {
7205 query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_3);
7206 }
7207 else {
7208 bindStructureKey = true;
7209
7210 query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_2);
7211 }
7212
7213 String sql = query.toString();
7214
7215 Session session = null;
7216
7217 try {
7218 session = openSession();
7219
7220 Query q = session.createQuery(sql);
7221
7222 QueryPos qPos = QueryPos.getInstance(q);
7223
7224 qPos.add(groupId);
7225
7226 qPos.add(classNameId);
7227
7228 if (bindStructureKey) {
7229 qPos.add(structureKey);
7230 }
7231
7232 count = (Long)q.uniqueResult();
7233
7234 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7235 }
7236 catch (Exception e) {
7237 FinderCacheUtil.removeResult(finderPath, finderArgs);
7238
7239 throw processException(e);
7240 }
7241 finally {
7242 closeSession(session);
7243 }
7244 }
7245
7246 return count.intValue();
7247 }
7248
7249 private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "ddmStructure.groupId = ? AND ";
7250 private static final String _FINDER_COLUMN_G_C_S_CLASSNAMEID_2 = "ddmStructure.classNameId = ? AND ";
7251 private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_1 = "ddmStructure.structureKey IS NULL";
7252 private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_2 = "ddmStructure.structureKey = ?";
7253 private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_3 = "(ddmStructure.structureKey IS NULL OR ddmStructure.structureKey = '')";
7254 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7255 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
7256 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_D",
7257 new String[] {
7258 Long.class.getName(), String.class.getName(),
7259 String.class.getName(),
7260
7261 Integer.class.getName(), Integer.class.getName(),
7262 OrderByComparator.class.getName()
7263 });
7264 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7265 DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
7266 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_D",
7267 new String[] {
7268 Long.class.getName(), String.class.getName(),
7269 String.class.getName()
7270 },
7271 DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
7272 DDMStructureModelImpl.NAME_COLUMN_BITMASK |
7273 DDMStructureModelImpl.DESCRIPTION_COLUMN_BITMASK);
7274 public static final FinderPath FINDER_PATH_COUNT_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7275 DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
7276 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_D",
7277 new String[] {
7278 Long.class.getName(), String.class.getName(),
7279 String.class.getName()
7280 });
7281
7282
7290 @Override
7291 public List<DDMStructure> findByG_N_D(long groupId, String name,
7292 String description) {
7293 return findByG_N_D(groupId, name, description, QueryUtil.ALL_POS,
7294 QueryUtil.ALL_POS, null);
7295 }
7296
7297
7311 @Override
7312 public List<DDMStructure> findByG_N_D(long groupId, String name,
7313 String description, int start, int end) {
7314 return findByG_N_D(groupId, name, description, start, end, null);
7315 }
7316
7317
7332 @Override
7333 public List<DDMStructure> findByG_N_D(long groupId, String name,
7334 String description, int start, int end,
7335 OrderByComparator<DDMStructure> orderByComparator) {
7336 boolean pagination = true;
7337 FinderPath finderPath = null;
7338 Object[] finderArgs = null;
7339
7340 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7341 (orderByComparator == null)) {
7342 pagination = false;
7343 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D;
7344 finderArgs = new Object[] { groupId, name, description };
7345 }
7346 else {
7347 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_D;
7348 finderArgs = new Object[] {
7349 groupId, name, description,
7350
7351 start, end, orderByComparator
7352 };
7353 }
7354
7355 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
7356 finderArgs, this);
7357
7358 if ((list != null) && !list.isEmpty()) {
7359 for (DDMStructure ddmStructure : list) {
7360 if ((groupId != ddmStructure.getGroupId()) ||
7361 !Validator.equals(name, ddmStructure.getName()) ||
7362 !Validator.equals(description,
7363 ddmStructure.getDescription())) {
7364 list = null;
7365
7366 break;
7367 }
7368 }
7369 }
7370
7371 if (list == null) {
7372 StringBundler query = null;
7373
7374 if (orderByComparator != null) {
7375 query = new StringBundler(5 +
7376 (orderByComparator.getOrderByFields().length * 3));
7377 }
7378 else {
7379 query = new StringBundler(5);
7380 }
7381
7382 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
7383
7384 query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
7385
7386 boolean bindName = false;
7387
7388 if (name == null) {
7389 query.append(_FINDER_COLUMN_G_N_D_NAME_1);
7390 }
7391 else if (name.equals(StringPool.BLANK)) {
7392 query.append(_FINDER_COLUMN_G_N_D_NAME_3);
7393 }
7394 else {
7395 bindName = true;
7396
7397 query.append(_FINDER_COLUMN_G_N_D_NAME_2);
7398 }
7399
7400 boolean bindDescription = false;
7401
7402 if (description == null) {
7403 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
7404 }
7405 else if (description.equals(StringPool.BLANK)) {
7406 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
7407 }
7408 else {
7409 bindDescription = true;
7410
7411 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
7412 }
7413
7414 if (orderByComparator != null) {
7415 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7416 orderByComparator);
7417 }
7418 else
7419 if (pagination) {
7420 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
7421 }
7422
7423 String sql = query.toString();
7424
7425 Session session = null;
7426
7427 try {
7428 session = openSession();
7429
7430 Query q = session.createQuery(sql);
7431
7432 QueryPos qPos = QueryPos.getInstance(q);
7433
7434 qPos.add(groupId);
7435
7436 if (bindName) {
7437 qPos.add(name);
7438 }
7439
7440 if (bindDescription) {
7441 qPos.add(description);
7442 }
7443
7444 if (!pagination) {
7445 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
7446 start, end, false);
7447
7448 Collections.sort(list);
7449
7450 list = Collections.unmodifiableList(list);
7451 }
7452 else {
7453 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
7454 start, end);
7455 }
7456
7457 cacheResult(list);
7458
7459 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7460 }
7461 catch (Exception e) {
7462 FinderCacheUtil.removeResult(finderPath, finderArgs);
7463
7464 throw processException(e);
7465 }
7466 finally {
7467 closeSession(session);
7468 }
7469 }
7470
7471 return list;
7472 }
7473
7474
7484 @Override
7485 public DDMStructure findByG_N_D_First(long groupId, String name,
7486 String description, OrderByComparator<DDMStructure> orderByComparator)
7487 throws NoSuchStructureException {
7488 DDMStructure ddmStructure = fetchByG_N_D_First(groupId, name,
7489 description, orderByComparator);
7490
7491 if (ddmStructure != null) {
7492 return ddmStructure;
7493 }
7494
7495 StringBundler msg = new StringBundler(8);
7496
7497 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7498
7499 msg.append("groupId=");
7500 msg.append(groupId);
7501
7502 msg.append(", name=");
7503 msg.append(name);
7504
7505 msg.append(", description=");
7506 msg.append(description);
7507
7508 msg.append(StringPool.CLOSE_CURLY_BRACE);
7509
7510 throw new NoSuchStructureException(msg.toString());
7511 }
7512
7513
7522 @Override
7523 public DDMStructure fetchByG_N_D_First(long groupId, String name,
7524 String description, OrderByComparator<DDMStructure> orderByComparator) {
7525 List<DDMStructure> list = findByG_N_D(groupId, name, description, 0, 1,
7526 orderByComparator);
7527
7528 if (!list.isEmpty()) {
7529 return list.get(0);
7530 }
7531
7532 return null;
7533 }
7534
7535
7545 @Override
7546 public DDMStructure findByG_N_D_Last(long groupId, String name,
7547 String description, OrderByComparator<DDMStructure> orderByComparator)
7548 throws NoSuchStructureException {
7549 DDMStructure ddmStructure = fetchByG_N_D_Last(groupId, name,
7550 description, orderByComparator);
7551
7552 if (ddmStructure != null) {
7553 return ddmStructure;
7554 }
7555
7556 StringBundler msg = new StringBundler(8);
7557
7558 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7559
7560 msg.append("groupId=");
7561 msg.append(groupId);
7562
7563 msg.append(", name=");
7564 msg.append(name);
7565
7566 msg.append(", description=");
7567 msg.append(description);
7568
7569 msg.append(StringPool.CLOSE_CURLY_BRACE);
7570
7571 throw new NoSuchStructureException(msg.toString());
7572 }
7573
7574
7583 @Override
7584 public DDMStructure fetchByG_N_D_Last(long groupId, String name,
7585 String description, OrderByComparator<DDMStructure> orderByComparator) {
7586 int count = countByG_N_D(groupId, name, description);
7587
7588 if (count == 0) {
7589 return null;
7590 }
7591
7592 List<DDMStructure> list = findByG_N_D(groupId, name, description,
7593 count - 1, count, orderByComparator);
7594
7595 if (!list.isEmpty()) {
7596 return list.get(0);
7597 }
7598
7599 return null;
7600 }
7601
7602
7613 @Override
7614 public DDMStructure[] findByG_N_D_PrevAndNext(long structureId,
7615 long groupId, String name, String description,
7616 OrderByComparator<DDMStructure> orderByComparator)
7617 throws NoSuchStructureException {
7618 DDMStructure ddmStructure = findByPrimaryKey(structureId);
7619
7620 Session session = null;
7621
7622 try {
7623 session = openSession();
7624
7625 DDMStructure[] array = new DDMStructureImpl[3];
7626
7627 array[0] = getByG_N_D_PrevAndNext(session, ddmStructure, groupId,
7628 name, description, orderByComparator, true);
7629
7630 array[1] = ddmStructure;
7631
7632 array[2] = getByG_N_D_PrevAndNext(session, ddmStructure, groupId,
7633 name, description, orderByComparator, false);
7634
7635 return array;
7636 }
7637 catch (Exception e) {
7638 throw processException(e);
7639 }
7640 finally {
7641 closeSession(session);
7642 }
7643 }
7644
7645 protected DDMStructure getByG_N_D_PrevAndNext(Session session,
7646 DDMStructure ddmStructure, long groupId, String name,
7647 String description, OrderByComparator<DDMStructure> orderByComparator,
7648 boolean previous) {
7649 StringBundler query = null;
7650
7651 if (orderByComparator != null) {
7652 query = new StringBundler(6 +
7653 (orderByComparator.getOrderByFields().length * 6));
7654 }
7655 else {
7656 query = new StringBundler(3);
7657 }
7658
7659 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
7660
7661 query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
7662
7663 boolean bindName = false;
7664
7665 if (name == null) {
7666 query.append(_FINDER_COLUMN_G_N_D_NAME_1);
7667 }
7668 else if (name.equals(StringPool.BLANK)) {
7669 query.append(_FINDER_COLUMN_G_N_D_NAME_3);
7670 }
7671 else {
7672 bindName = true;
7673
7674 query.append(_FINDER_COLUMN_G_N_D_NAME_2);
7675 }
7676
7677 boolean bindDescription = false;
7678
7679 if (description == null) {
7680 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
7681 }
7682 else if (description.equals(StringPool.BLANK)) {
7683 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
7684 }
7685 else {
7686 bindDescription = true;
7687
7688 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
7689 }
7690
7691 if (orderByComparator != null) {
7692 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7693
7694 if (orderByConditionFields.length > 0) {
7695 query.append(WHERE_AND);
7696 }
7697
7698 for (int i = 0; i < orderByConditionFields.length; i++) {
7699 query.append(_ORDER_BY_ENTITY_ALIAS);
7700 query.append(orderByConditionFields[i]);
7701
7702 if ((i + 1) < orderByConditionFields.length) {
7703 if (orderByComparator.isAscending() ^ previous) {
7704 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7705 }
7706 else {
7707 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7708 }
7709 }
7710 else {
7711 if (orderByComparator.isAscending() ^ previous) {
7712 query.append(WHERE_GREATER_THAN);
7713 }
7714 else {
7715 query.append(WHERE_LESSER_THAN);
7716 }
7717 }
7718 }
7719
7720 query.append(ORDER_BY_CLAUSE);
7721
7722 String[] orderByFields = orderByComparator.getOrderByFields();
7723
7724 for (int i = 0; i < orderByFields.length; i++) {
7725 query.append(_ORDER_BY_ENTITY_ALIAS);
7726 query.append(orderByFields[i]);
7727
7728 if ((i + 1) < orderByFields.length) {
7729 if (orderByComparator.isAscending() ^ previous) {
7730 query.append(ORDER_BY_ASC_HAS_NEXT);
7731 }
7732 else {
7733 query.append(ORDER_BY_DESC_HAS_NEXT);
7734 }
7735 }
7736 else {
7737 if (orderByComparator.isAscending() ^ previous) {
7738 query.append(ORDER_BY_ASC);
7739 }
7740 else {
7741 query.append(ORDER_BY_DESC);
7742 }
7743 }
7744 }
7745 }
7746 else {
7747 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
7748 }
7749
7750 String sql = query.toString();
7751
7752 Query q = session.createQuery(sql);
7753
7754 q.setFirstResult(0);
7755 q.setMaxResults(2);
7756
7757 QueryPos qPos = QueryPos.getInstance(q);
7758
7759 qPos.add(groupId);
7760
7761 if (bindName) {
7762 qPos.add(name);
7763 }
7764
7765 if (bindDescription) {
7766 qPos.add(description);
7767 }
7768
7769 if (orderByComparator != null) {
7770 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
7771
7772 for (Object value : values) {
7773 qPos.add(value);
7774 }
7775 }
7776
7777 List<DDMStructure> list = q.list();
7778
7779 if (list.size() == 2) {
7780 return list.get(1);
7781 }
7782 else {
7783 return null;
7784 }
7785 }
7786
7787
7795 @Override
7796 public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
7797 String description) {
7798 return filterFindByG_N_D(groupId, name, description, QueryUtil.ALL_POS,
7799 QueryUtil.ALL_POS, null);
7800 }
7801
7802
7816 @Override
7817 public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
7818 String description, int start, int end) {
7819 return filterFindByG_N_D(groupId, name, description, start, end, null);
7820 }
7821
7822
7837 @Override
7838 public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
7839 String description, int start, int end,
7840 OrderByComparator<DDMStructure> orderByComparator) {
7841 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7842 return findByG_N_D(groupId, name, description, start, end,
7843 orderByComparator);
7844 }
7845
7846 StringBundler query = null;
7847
7848 if (orderByComparator != null) {
7849 query = new StringBundler(5 +
7850 (orderByComparator.getOrderByFields().length * 3));
7851 }
7852 else {
7853 query = new StringBundler(5);
7854 }
7855
7856 if (getDB().isSupportsInlineDistinct()) {
7857 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
7858 }
7859 else {
7860 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
7861 }
7862
7863 query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
7864
7865 boolean bindName = false;
7866
7867 if (name == null) {
7868 query.append(_FINDER_COLUMN_G_N_D_NAME_1);
7869 }
7870 else if (name.equals(StringPool.BLANK)) {
7871 query.append(_FINDER_COLUMN_G_N_D_NAME_3);
7872 }
7873 else {
7874 bindName = true;
7875
7876 query.append(_FINDER_COLUMN_G_N_D_NAME_2);
7877 }
7878
7879 boolean bindDescription = false;
7880
7881 if (description == null) {
7882 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
7883 }
7884 else if (description.equals(StringPool.BLANK)) {
7885 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
7886 }
7887 else {
7888 bindDescription = true;
7889
7890 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
7891 }
7892
7893 if (!getDB().isSupportsInlineDistinct()) {
7894 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
7895 }
7896
7897 if (orderByComparator != null) {
7898 if (getDB().isSupportsInlineDistinct()) {
7899 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7900 orderByComparator, true);
7901 }
7902 else {
7903 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7904 orderByComparator, true);
7905 }
7906 }
7907 else {
7908 if (getDB().isSupportsInlineDistinct()) {
7909 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
7910 }
7911 else {
7912 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
7913 }
7914 }
7915
7916 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7917 DDMStructure.class.getName(),
7918 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7919
7920 Session session = null;
7921
7922 try {
7923 session = openSession();
7924
7925 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7926
7927 if (getDB().isSupportsInlineDistinct()) {
7928 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
7929 }
7930 else {
7931 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
7932 }
7933
7934 QueryPos qPos = QueryPos.getInstance(q);
7935
7936 qPos.add(groupId);
7937
7938 if (bindName) {
7939 qPos.add(name);
7940 }
7941
7942 if (bindDescription) {
7943 qPos.add(description);
7944 }
7945
7946 return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
7947 end);
7948 }
7949 catch (Exception e) {
7950 throw processException(e);
7951 }
7952 finally {
7953 closeSession(session);
7954 }
7955 }
7956
7957
7968 @Override
7969 public DDMStructure[] filterFindByG_N_D_PrevAndNext(long structureId,
7970 long groupId, String name, String description,
7971 OrderByComparator<DDMStructure> orderByComparator)
7972 throws NoSuchStructureException {
7973 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7974 return findByG_N_D_PrevAndNext(structureId, groupId, name,
7975 description, orderByComparator);
7976 }
7977
7978 DDMStructure ddmStructure = findByPrimaryKey(structureId);
7979
7980 Session session = null;
7981
7982 try {
7983 session = openSession();
7984
7985 DDMStructure[] array = new DDMStructureImpl[3];
7986
7987 array[0] = filterGetByG_N_D_PrevAndNext(session, ddmStructure,
7988 groupId, name, description, orderByComparator, true);
7989
7990 array[1] = ddmStructure;
7991
7992 array[2] = filterGetByG_N_D_PrevAndNext(session, ddmStructure,
7993 groupId, name, description, orderByComparator, false);
7994
7995 return array;
7996 }
7997 catch (Exception e) {
7998 throw processException(e);
7999 }
8000 finally {
8001 closeSession(session);
8002 }
8003 }
8004
8005 protected DDMStructure filterGetByG_N_D_PrevAndNext(Session session,
8006 DDMStructure ddmStructure, long groupId, String name,
8007 String description, OrderByComparator<DDMStructure> orderByComparator,
8008 boolean previous) {
8009 StringBundler query = null;
8010
8011 if (orderByComparator != null) {
8012 query = new StringBundler(6 +
8013 (orderByComparator.getOrderByFields().length * 6));
8014 }
8015 else {
8016 query = new StringBundler(3);
8017 }
8018
8019 if (getDB().isSupportsInlineDistinct()) {
8020 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
8021 }
8022 else {
8023 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
8024 }
8025
8026 query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
8027
8028 boolean bindName = false;
8029
8030 if (name == null) {
8031 query.append(_FINDER_COLUMN_G_N_D_NAME_1);
8032 }
8033 else if (name.equals(StringPool.BLANK)) {
8034 query.append(_FINDER_COLUMN_G_N_D_NAME_3);
8035 }
8036 else {
8037 bindName = true;
8038
8039 query.append(_FINDER_COLUMN_G_N_D_NAME_2);
8040 }
8041
8042 boolean bindDescription = false;
8043
8044 if (description == null) {
8045 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
8046 }
8047 else if (description.equals(StringPool.BLANK)) {
8048 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
8049 }
8050 else {
8051 bindDescription = true;
8052
8053 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
8054 }
8055
8056 if (!getDB().isSupportsInlineDistinct()) {
8057 query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
8058 }
8059
8060 if (orderByComparator != null) {
8061 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8062
8063 if (orderByConditionFields.length > 0) {
8064 query.append(WHERE_AND);
8065 }
8066
8067 for (int i = 0; i < orderByConditionFields.length; i++) {
8068 if (getDB().isSupportsInlineDistinct()) {
8069 query.append(_ORDER_BY_ENTITY_ALIAS);
8070 }
8071 else {
8072 query.append(_ORDER_BY_ENTITY_TABLE);
8073 }
8074
8075 query.append(orderByConditionFields[i]);
8076
8077 if ((i + 1) < orderByConditionFields.length) {
8078 if (orderByComparator.isAscending() ^ previous) {
8079 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8080 }
8081 else {
8082 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8083 }
8084 }
8085 else {
8086 if (orderByComparator.isAscending() ^ previous) {
8087 query.append(WHERE_GREATER_THAN);
8088 }
8089 else {
8090 query.append(WHERE_LESSER_THAN);
8091 }
8092 }
8093 }
8094
8095 query.append(ORDER_BY_CLAUSE);
8096
8097 String[] orderByFields = orderByComparator.getOrderByFields();
8098
8099 for (int i = 0; i < orderByFields.length; i++) {
8100 if (getDB().isSupportsInlineDistinct()) {
8101 query.append(_ORDER_BY_ENTITY_ALIAS);
8102 }
8103 else {
8104 query.append(_ORDER_BY_ENTITY_TABLE);
8105 }
8106
8107 query.append(orderByFields[i]);
8108
8109 if ((i + 1) < orderByFields.length) {
8110 if (orderByComparator.isAscending() ^ previous) {
8111 query.append(ORDER_BY_ASC_HAS_NEXT);
8112 }
8113 else {
8114 query.append(ORDER_BY_DESC_HAS_NEXT);
8115 }
8116 }
8117 else {
8118 if (orderByComparator.isAscending() ^ previous) {
8119 query.append(ORDER_BY_ASC);
8120 }
8121 else {
8122 query.append(ORDER_BY_DESC);
8123 }
8124 }
8125 }
8126 }
8127 else {
8128 if (getDB().isSupportsInlineDistinct()) {
8129 query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
8130 }
8131 else {
8132 query.append(DDMStructureModelImpl.ORDER_BY_SQL);
8133 }
8134 }
8135
8136 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8137 DDMStructure.class.getName(),
8138 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8139
8140 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8141
8142 q.setFirstResult(0);
8143 q.setMaxResults(2);
8144
8145 if (getDB().isSupportsInlineDistinct()) {
8146 q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
8147 }
8148 else {
8149 q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
8150 }
8151
8152 QueryPos qPos = QueryPos.getInstance(q);
8153
8154 qPos.add(groupId);
8155
8156 if (bindName) {
8157 qPos.add(name);
8158 }
8159
8160 if (bindDescription) {
8161 qPos.add(description);
8162 }
8163
8164 if (orderByComparator != null) {
8165 Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
8166
8167 for (Object value : values) {
8168 qPos.add(value);
8169 }
8170 }
8171
8172 List<DDMStructure> list = q.list();
8173
8174 if (list.size() == 2) {
8175 return list.get(1);
8176 }
8177 else {
8178 return null;
8179 }
8180 }
8181
8182
8189 @Override
8190 public void removeByG_N_D(long groupId, String name, String description) {
8191 for (DDMStructure ddmStructure : findByG_N_D(groupId, name,
8192 description, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8193 remove(ddmStructure);
8194 }
8195 }
8196
8197
8205 @Override
8206 public int countByG_N_D(long groupId, String name, String description) {
8207 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_D;
8208
8209 Object[] finderArgs = new Object[] { groupId, name, description };
8210
8211 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8212 this);
8213
8214 if (count == null) {
8215 StringBundler query = new StringBundler(4);
8216
8217 query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
8218
8219 query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
8220
8221 boolean bindName = false;
8222
8223 if (name == null) {
8224 query.append(_FINDER_COLUMN_G_N_D_NAME_1);
8225 }
8226 else if (name.equals(StringPool.BLANK)) {
8227 query.append(_FINDER_COLUMN_G_N_D_NAME_3);
8228 }
8229 else {
8230 bindName = true;
8231
8232 query.append(_FINDER_COLUMN_G_N_D_NAME_2);
8233 }
8234
8235 boolean bindDescription = false;
8236
8237 if (description == null) {
8238 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
8239 }
8240 else if (description.equals(StringPool.BLANK)) {
8241 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
8242 }
8243 else {
8244 bindDescription = true;
8245
8246 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
8247 }
8248
8249 String sql = query.toString();
8250
8251 Session session = null;
8252
8253 try {
8254 session = openSession();
8255
8256 Query q = session.createQuery(sql);
8257
8258 QueryPos qPos = QueryPos.getInstance(q);
8259
8260 qPos.add(groupId);
8261
8262 if (bindName) {
8263 qPos.add(name);
8264 }
8265
8266 if (bindDescription) {
8267 qPos.add(description);
8268 }
8269
8270 count = (Long)q.uniqueResult();
8271
8272 FinderCacheUtil.putResult(finderPath, finderArgs, count);
8273 }
8274 catch (Exception e) {
8275 FinderCacheUtil.removeResult(finderPath, finderArgs);
8276
8277 throw processException(e);
8278 }
8279 finally {
8280 closeSession(session);
8281 }
8282 }
8283
8284 return count.intValue();
8285 }
8286
8287
8295 @Override
8296 public int filterCountByG_N_D(long groupId, String name, String description) {
8297 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8298 return countByG_N_D(groupId, name, description);
8299 }
8300
8301 StringBundler query = new StringBundler(4);
8302
8303 query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
8304
8305 query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
8306
8307 boolean bindName = false;
8308
8309 if (name == null) {
8310 query.append(_FINDER_COLUMN_G_N_D_NAME_1);
8311 }
8312 else if (name.equals(StringPool.BLANK)) {
8313 query.append(_FINDER_COLUMN_G_N_D_NAME_3);
8314 }
8315 else {
8316 bindName = true;
8317
8318 query.append(_FINDER_COLUMN_G_N_D_NAME_2);
8319 }
8320
8321 boolean bindDescription = false;
8322
8323 if (description == null) {
8324 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
8325 }
8326 else if (description.equals(StringPool.BLANK)) {
8327 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
8328 }
8329 else {
8330 bindDescription = true;
8331
8332 query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
8333 }
8334
8335 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8336 DDMStructure.class.getName(),
8337 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8338
8339 Session session = null;
8340
8341 try {
8342 session = openSession();
8343
8344 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8345
8346 q.addScalar(COUNT_COLUMN_NAME,
8347 com.liferay.portal.kernel.dao.orm.Type.LONG);
8348
8349 QueryPos qPos = QueryPos.getInstance(q);
8350
8351 qPos.add(groupId);
8352
8353 if (bindName) {
8354 qPos.add(name);
8355 }
8356
8357 if (bindDescription) {
8358 qPos.add(description);
8359 }
8360
8361 Long count = (Long)q.uniqueResult();
8362
8363 return count.intValue();
8364 }
8365 catch (Exception e) {
8366 throw processException(e);
8367 }
8368 finally {
8369 closeSession(session);
8370 }
8371 }
8372
8373 private static final String _FINDER_COLUMN_G_N_D_GROUPID_2 = "ddmStructure.groupId = ? AND ";
8374 private static final String _FINDER_COLUMN_G_N_D_NAME_1 = "ddmStructure.name IS NULL AND ";
8375 private static final String _FINDER_COLUMN_G_N_D_NAME_2 = "ddmStructure.name = ? AND ";
8376 private static final String _FINDER_COLUMN_G_N_D_NAME_3 = "(ddmStructure.name IS NULL OR ddmStructure.name = '') AND ";
8377 private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_1 = "ddmStructure.description IS NULL";
8378 private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_2 = "ddmStructure.description = ?";
8379 private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_3 = "(ddmStructure.description IS NULL OR ddmStructure.description = '')";
8380
8381 public DDMStructurePersistenceImpl() {
8382 setModelClass(DDMStructure.class);
8383 }
8384
8385
8390 @Override
8391 public void cacheResult(DDMStructure ddmStructure) {
8392 EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8393 DDMStructureImpl.class, ddmStructure.getPrimaryKey(), ddmStructure);
8394
8395 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
8396 new Object[] { ddmStructure.getUuid(), ddmStructure.getGroupId() },
8397 ddmStructure);
8398
8399 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
8400 new Object[] {
8401 ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
8402 ddmStructure.getStructureKey()
8403 }, ddmStructure);
8404
8405 ddmStructure.resetOriginalValues();
8406 }
8407
8408
8413 @Override
8414 public void cacheResult(List<DDMStructure> ddmStructures) {
8415 for (DDMStructure ddmStructure : ddmStructures) {
8416 if (EntityCacheUtil.getResult(
8417 DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8418 DDMStructureImpl.class, ddmStructure.getPrimaryKey()) == null) {
8419 cacheResult(ddmStructure);
8420 }
8421 else {
8422 ddmStructure.resetOriginalValues();
8423 }
8424 }
8425 }
8426
8427
8434 @Override
8435 public void clearCache() {
8436 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
8437 CacheRegistryUtil.clear(DDMStructureImpl.class.getName());
8438 }
8439
8440 EntityCacheUtil.clearCache(DDMStructureImpl.class);
8441
8442 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8443 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8444 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8445 }
8446
8447
8454 @Override
8455 public void clearCache(DDMStructure ddmStructure) {
8456 EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8457 DDMStructureImpl.class, ddmStructure.getPrimaryKey());
8458
8459 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8460 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8461
8462 clearUniqueFindersCache(ddmStructure);
8463 }
8464
8465 @Override
8466 public void clearCache(List<DDMStructure> ddmStructures) {
8467 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8468 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8469
8470 for (DDMStructure ddmStructure : ddmStructures) {
8471 EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8472 DDMStructureImpl.class, ddmStructure.getPrimaryKey());
8473
8474 clearUniqueFindersCache(ddmStructure);
8475 }
8476 }
8477
8478 protected void cacheUniqueFindersCache(DDMStructure ddmStructure) {
8479 if (ddmStructure.isNew()) {
8480 Object[] args = new Object[] {
8481 ddmStructure.getUuid(), ddmStructure.getGroupId()
8482 };
8483
8484 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
8485 Long.valueOf(1));
8486 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
8487 ddmStructure);
8488
8489 args = new Object[] {
8490 ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
8491 ddmStructure.getStructureKey()
8492 };
8493
8494 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S, args,
8495 Long.valueOf(1));
8496 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S, args,
8497 ddmStructure);
8498 }
8499 else {
8500 DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
8501
8502 if ((ddmStructureModelImpl.getColumnBitmask() &
8503 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
8504 Object[] args = new Object[] {
8505 ddmStructure.getUuid(), ddmStructure.getGroupId()
8506 };
8507
8508 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
8509 Long.valueOf(1));
8510 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
8511 ddmStructure);
8512 }
8513
8514 if ((ddmStructureModelImpl.getColumnBitmask() &
8515 FINDER_PATH_FETCH_BY_G_C_S.getColumnBitmask()) != 0) {
8516 Object[] args = new Object[] {
8517 ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
8518 ddmStructure.getStructureKey()
8519 };
8520
8521 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S, args,
8522 Long.valueOf(1));
8523 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S, args,
8524 ddmStructure);
8525 }
8526 }
8527 }
8528
8529 protected void clearUniqueFindersCache(DDMStructure ddmStructure) {
8530 DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
8531
8532 Object[] args = new Object[] {
8533 ddmStructure.getUuid(), ddmStructure.getGroupId()
8534 };
8535
8536 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
8537 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
8538
8539 if ((ddmStructureModelImpl.getColumnBitmask() &
8540 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
8541 args = new Object[] {
8542 ddmStructureModelImpl.getOriginalUuid(),
8543 ddmStructureModelImpl.getOriginalGroupId()
8544 };
8545
8546 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
8547 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
8548 }
8549
8550 args = new Object[] {
8551 ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
8552 ddmStructure.getStructureKey()
8553 };
8554
8555 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
8556 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S, args);
8557
8558 if ((ddmStructureModelImpl.getColumnBitmask() &
8559 FINDER_PATH_FETCH_BY_G_C_S.getColumnBitmask()) != 0) {
8560 args = new Object[] {
8561 ddmStructureModelImpl.getOriginalGroupId(),
8562 ddmStructureModelImpl.getOriginalClassNameId(),
8563 ddmStructureModelImpl.getOriginalStructureKey()
8564 };
8565
8566 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
8567 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S, args);
8568 }
8569 }
8570
8571
8577 @Override
8578 public DDMStructure create(long structureId) {
8579 DDMStructure ddmStructure = new DDMStructureImpl();
8580
8581 ddmStructure.setNew(true);
8582 ddmStructure.setPrimaryKey(structureId);
8583
8584 String uuid = PortalUUIDUtil.generate();
8585
8586 ddmStructure.setUuid(uuid);
8587
8588 return ddmStructure;
8589 }
8590
8591
8598 @Override
8599 public DDMStructure remove(long structureId)
8600 throws NoSuchStructureException {
8601 return remove((Serializable)structureId);
8602 }
8603
8604
8611 @Override
8612 public DDMStructure remove(Serializable primaryKey)
8613 throws NoSuchStructureException {
8614 Session session = null;
8615
8616 try {
8617 session = openSession();
8618
8619 DDMStructure ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
8620 primaryKey);
8621
8622 if (ddmStructure == null) {
8623 if (_log.isWarnEnabled()) {
8624 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8625 }
8626
8627 throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8628 primaryKey);
8629 }
8630
8631 return remove(ddmStructure);
8632 }
8633 catch (NoSuchStructureException nsee) {
8634 throw nsee;
8635 }
8636 catch (Exception e) {
8637 throw processException(e);
8638 }
8639 finally {
8640 closeSession(session);
8641 }
8642 }
8643
8644 @Override
8645 protected DDMStructure removeImpl(DDMStructure ddmStructure) {
8646 ddmStructure = toUnwrappedModel(ddmStructure);
8647
8648 ddmStructureToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(ddmStructure.getPrimaryKey());
8649
8650 ddmStructureToJournalFolderTableMapper.deleteLeftPrimaryKeyTableMappings(ddmStructure.getPrimaryKey());
8651
8652 Session session = null;
8653
8654 try {
8655 session = openSession();
8656
8657 if (!session.contains(ddmStructure)) {
8658 ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
8659 ddmStructure.getPrimaryKeyObj());
8660 }
8661
8662 if (ddmStructure != null) {
8663 session.delete(ddmStructure);
8664 }
8665 }
8666 catch (Exception e) {
8667 throw processException(e);
8668 }
8669 finally {
8670 closeSession(session);
8671 }
8672
8673 if (ddmStructure != null) {
8674 clearCache(ddmStructure);
8675 }
8676
8677 return ddmStructure;
8678 }
8679
8680 @Override
8681 public DDMStructure updateImpl(
8682 com.liferay.portlet.dynamicdatamapping.model.DDMStructure ddmStructure) {
8683 ddmStructure = toUnwrappedModel(ddmStructure);
8684
8685 boolean isNew = ddmStructure.isNew();
8686
8687 DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
8688
8689 if (Validator.isNull(ddmStructure.getUuid())) {
8690 String uuid = PortalUUIDUtil.generate();
8691
8692 ddmStructure.setUuid(uuid);
8693 }
8694
8695 Session session = null;
8696
8697 try {
8698 session = openSession();
8699
8700 if (ddmStructure.isNew()) {
8701 session.save(ddmStructure);
8702
8703 ddmStructure.setNew(false);
8704 }
8705 else {
8706 session.merge(ddmStructure);
8707 }
8708 }
8709 catch (Exception e) {
8710 throw processException(e);
8711 }
8712 finally {
8713 closeSession(session);
8714 }
8715
8716 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8717
8718 if (isNew || !DDMStructureModelImpl.COLUMN_BITMASK_ENABLED) {
8719 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8720 }
8721
8722 else {
8723 if ((ddmStructureModelImpl.getColumnBitmask() &
8724 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8725 Object[] args = new Object[] {
8726 ddmStructureModelImpl.getOriginalUuid()
8727 };
8728
8729 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8730 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8731 args);
8732
8733 args = new Object[] { ddmStructureModelImpl.getUuid() };
8734
8735 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8736 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8737 args);
8738 }
8739
8740 if ((ddmStructureModelImpl.getColumnBitmask() &
8741 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8742 Object[] args = new Object[] {
8743 ddmStructureModelImpl.getOriginalUuid(),
8744 ddmStructureModelImpl.getOriginalCompanyId()
8745 };
8746
8747 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8748 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8749 args);
8750
8751 args = new Object[] {
8752 ddmStructureModelImpl.getUuid(),
8753 ddmStructureModelImpl.getCompanyId()
8754 };
8755
8756 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8757 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8758 args);
8759 }
8760
8761 if ((ddmStructureModelImpl.getColumnBitmask() &
8762 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
8763 Object[] args = new Object[] {
8764 ddmStructureModelImpl.getOriginalGroupId()
8765 };
8766
8767 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8768 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8769 args);
8770
8771 args = new Object[] { ddmStructureModelImpl.getGroupId() };
8772
8773 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8774 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8775 args);
8776 }
8777
8778 if ((ddmStructureModelImpl.getColumnBitmask() &
8779 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID.getColumnBitmask()) != 0) {
8780 Object[] args = new Object[] {
8781 ddmStructureModelImpl.getOriginalParentStructureId()
8782 };
8783
8784 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTSTRUCTUREID,
8785 args);
8786 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID,
8787 args);
8788
8789 args = new Object[] { ddmStructureModelImpl.getParentStructureId() };
8790
8791 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTSTRUCTUREID,
8792 args);
8793 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID,
8794 args);
8795 }
8796
8797 if ((ddmStructureModelImpl.getColumnBitmask() &
8798 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
8799 Object[] args = new Object[] {
8800 ddmStructureModelImpl.getOriginalClassNameId()
8801 };
8802
8803 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
8804 args);
8805 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
8806 args);
8807
8808 args = new Object[] { ddmStructureModelImpl.getClassNameId() };
8809
8810 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
8811 args);
8812 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
8813 args);
8814 }
8815
8816 if ((ddmStructureModelImpl.getColumnBitmask() &
8817 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY.getColumnBitmask()) != 0) {
8818 Object[] args = new Object[] {
8819 ddmStructureModelImpl.getOriginalStructureKey()
8820 };
8821
8822 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREKEY,
8823 args);
8824 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY,
8825 args);
8826
8827 args = new Object[] { ddmStructureModelImpl.getStructureKey() };
8828
8829 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREKEY,
8830 args);
8831 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY,
8832 args);
8833 }
8834
8835 if ((ddmStructureModelImpl.getColumnBitmask() &
8836 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
8837 Object[] args = new Object[] {
8838 ddmStructureModelImpl.getOriginalGroupId(),
8839 ddmStructureModelImpl.getOriginalParentStructureId()
8840 };
8841
8842 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8843 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8844 args);
8845
8846 args = new Object[] {
8847 ddmStructureModelImpl.getGroupId(),
8848 ddmStructureModelImpl.getParentStructureId()
8849 };
8850
8851 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8852 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8853 args);
8854 }
8855
8856 if ((ddmStructureModelImpl.getColumnBitmask() &
8857 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
8858 Object[] args = new Object[] {
8859 ddmStructureModelImpl.getOriginalGroupId(),
8860 ddmStructureModelImpl.getOriginalClassNameId()
8861 };
8862
8863 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
8864 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
8865 args);
8866
8867 args = new Object[] {
8868 ddmStructureModelImpl.getGroupId(),
8869 ddmStructureModelImpl.getClassNameId()
8870 };
8871
8872 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
8873 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
8874 args);
8875 }
8876
8877 if ((ddmStructureModelImpl.getColumnBitmask() &
8878 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
8879 Object[] args = new Object[] {
8880 ddmStructureModelImpl.getOriginalCompanyId(),
8881 ddmStructureModelImpl.getOriginalClassNameId()
8882 };
8883
8884 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
8885 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
8886 args);
8887
8888 args = new Object[] {
8889 ddmStructureModelImpl.getCompanyId(),
8890 ddmStructureModelImpl.getClassNameId()
8891 };
8892
8893 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
8894 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
8895 args);
8896 }
8897
8898 if ((ddmStructureModelImpl.getColumnBitmask() &
8899 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D.getColumnBitmask()) != 0) {
8900 Object[] args = new Object[] {
8901 ddmStructureModelImpl.getOriginalGroupId(),
8902 ddmStructureModelImpl.getOriginalName(),
8903 ddmStructureModelImpl.getOriginalDescription()
8904 };
8905
8906 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_D, args);
8907 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D,
8908 args);
8909
8910 args = new Object[] {
8911 ddmStructureModelImpl.getGroupId(),
8912 ddmStructureModelImpl.getName(),
8913 ddmStructureModelImpl.getDescription()
8914 };
8915
8916 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_D, args);
8917 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D,
8918 args);
8919 }
8920 }
8921
8922 EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8923 DDMStructureImpl.class, ddmStructure.getPrimaryKey(), ddmStructure,
8924 false);
8925
8926 clearUniqueFindersCache(ddmStructure);
8927 cacheUniqueFindersCache(ddmStructure);
8928
8929 ddmStructure.resetOriginalValues();
8930
8931 return ddmStructure;
8932 }
8933
8934 protected DDMStructure toUnwrappedModel(DDMStructure ddmStructure) {
8935 if (ddmStructure instanceof DDMStructureImpl) {
8936 return ddmStructure;
8937 }
8938
8939 DDMStructureImpl ddmStructureImpl = new DDMStructureImpl();
8940
8941 ddmStructureImpl.setNew(ddmStructure.isNew());
8942 ddmStructureImpl.setPrimaryKey(ddmStructure.getPrimaryKey());
8943
8944 ddmStructureImpl.setUuid(ddmStructure.getUuid());
8945 ddmStructureImpl.setStructureId(ddmStructure.getStructureId());
8946 ddmStructureImpl.setGroupId(ddmStructure.getGroupId());
8947 ddmStructureImpl.setCompanyId(ddmStructure.getCompanyId());
8948 ddmStructureImpl.setUserId(ddmStructure.getUserId());
8949 ddmStructureImpl.setUserName(ddmStructure.getUserName());
8950 ddmStructureImpl.setCreateDate(ddmStructure.getCreateDate());
8951 ddmStructureImpl.setModifiedDate(ddmStructure.getModifiedDate());
8952 ddmStructureImpl.setParentStructureId(ddmStructure.getParentStructureId());
8953 ddmStructureImpl.setClassNameId(ddmStructure.getClassNameId());
8954 ddmStructureImpl.setStructureKey(ddmStructure.getStructureKey());
8955 ddmStructureImpl.setVersion(ddmStructure.getVersion());
8956 ddmStructureImpl.setName(ddmStructure.getName());
8957 ddmStructureImpl.setDescription(ddmStructure.getDescription());
8958 ddmStructureImpl.setDefinition(ddmStructure.getDefinition());
8959 ddmStructureImpl.setStorageType(ddmStructure.getStorageType());
8960 ddmStructureImpl.setType(ddmStructure.getType());
8961
8962 return ddmStructureImpl;
8963 }
8964
8965
8972 @Override
8973 public DDMStructure findByPrimaryKey(Serializable primaryKey)
8974 throws NoSuchStructureException {
8975 DDMStructure ddmStructure = fetchByPrimaryKey(primaryKey);
8976
8977 if (ddmStructure == null) {
8978 if (_log.isWarnEnabled()) {
8979 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8980 }
8981
8982 throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8983 primaryKey);
8984 }
8985
8986 return ddmStructure;
8987 }
8988
8989
8996 @Override
8997 public DDMStructure findByPrimaryKey(long structureId)
8998 throws NoSuchStructureException {
8999 return findByPrimaryKey((Serializable)structureId);
9000 }
9001
9002
9008 @Override
9009 public DDMStructure fetchByPrimaryKey(Serializable primaryKey) {
9010 DDMStructure ddmStructure = (DDMStructure)EntityCacheUtil.getResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9011 DDMStructureImpl.class, primaryKey);
9012
9013 if (ddmStructure == _nullDDMStructure) {
9014 return null;
9015 }
9016
9017 if (ddmStructure == null) {
9018 Session session = null;
9019
9020 try {
9021 session = openSession();
9022
9023 ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
9024 primaryKey);
9025
9026 if (ddmStructure != null) {
9027 cacheResult(ddmStructure);
9028 }
9029 else {
9030 EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9031 DDMStructureImpl.class, primaryKey, _nullDDMStructure);
9032 }
9033 }
9034 catch (Exception e) {
9035 EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9036 DDMStructureImpl.class, primaryKey);
9037
9038 throw processException(e);
9039 }
9040 finally {
9041 closeSession(session);
9042 }
9043 }
9044
9045 return ddmStructure;
9046 }
9047
9048
9054 @Override
9055 public DDMStructure fetchByPrimaryKey(long structureId) {
9056 return fetchByPrimaryKey((Serializable)structureId);
9057 }
9058
9059 @Override
9060 public Map<Serializable, DDMStructure> fetchByPrimaryKeys(
9061 Set<Serializable> primaryKeys) {
9062 if (primaryKeys.isEmpty()) {
9063 return Collections.emptyMap();
9064 }
9065
9066 Map<Serializable, DDMStructure> map = new HashMap<Serializable, DDMStructure>();
9067
9068 if (primaryKeys.size() == 1) {
9069 Iterator<Serializable> iterator = primaryKeys.iterator();
9070
9071 Serializable primaryKey = iterator.next();
9072
9073 DDMStructure ddmStructure = fetchByPrimaryKey(primaryKey);
9074
9075 if (ddmStructure != null) {
9076 map.put(primaryKey, ddmStructure);
9077 }
9078
9079 return map;
9080 }
9081
9082 Set<Serializable> uncachedPrimaryKeys = null;
9083
9084 for (Serializable primaryKey : primaryKeys) {
9085 DDMStructure ddmStructure = (DDMStructure)EntityCacheUtil.getResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9086 DDMStructureImpl.class, primaryKey);
9087
9088 if (ddmStructure == null) {
9089 if (uncachedPrimaryKeys == null) {
9090 uncachedPrimaryKeys = new HashSet<Serializable>();
9091 }
9092
9093 uncachedPrimaryKeys.add(primaryKey);
9094 }
9095 else {
9096 map.put(primaryKey, ddmStructure);
9097 }
9098 }
9099
9100 if (uncachedPrimaryKeys == null) {
9101 return map;
9102 }
9103
9104 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
9105 1);
9106
9107 query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE_PKS_IN);
9108
9109 for (Serializable primaryKey : uncachedPrimaryKeys) {
9110 query.append(String.valueOf(primaryKey));
9111
9112 query.append(StringPool.COMMA);
9113 }
9114
9115 query.setIndex(query.index() - 1);
9116
9117 query.append(StringPool.CLOSE_PARENTHESIS);
9118
9119 String sql = query.toString();
9120
9121 Session session = null;
9122
9123 try {
9124 session = openSession();
9125
9126 Query q = session.createQuery(sql);
9127
9128 for (DDMStructure ddmStructure : (List<DDMStructure>)q.list()) {
9129 map.put(ddmStructure.getPrimaryKeyObj(), ddmStructure);
9130
9131 cacheResult(ddmStructure);
9132
9133 uncachedPrimaryKeys.remove(ddmStructure.getPrimaryKeyObj());
9134 }
9135
9136 for (Serializable primaryKey : uncachedPrimaryKeys) {
9137 EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9138 DDMStructureImpl.class, primaryKey, _nullDDMStructure);
9139 }
9140 }
9141 catch (Exception e) {
9142 throw processException(e);
9143 }
9144 finally {
9145 closeSession(session);
9146 }
9147
9148 return map;
9149 }
9150
9151
9156 @Override
9157 public List<DDMStructure> findAll() {
9158 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9159 }
9160
9161
9172 @Override
9173 public List<DDMStructure> findAll(int start, int end) {
9174 return findAll(start, end, null);
9175 }
9176
9177
9189 @Override
9190 public List<DDMStructure> findAll(int start, int end,
9191 OrderByComparator<DDMStructure> orderByComparator) {
9192 boolean pagination = true;
9193 FinderPath finderPath = null;
9194 Object[] finderArgs = null;
9195
9196 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9197 (orderByComparator == null)) {
9198 pagination = false;
9199 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
9200 finderArgs = FINDER_ARGS_EMPTY;
9201 }
9202 else {
9203 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
9204 finderArgs = new Object[] { start, end, orderByComparator };
9205 }
9206
9207 List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
9208 finderArgs, this);
9209
9210 if (list == null) {
9211 StringBundler query = null;
9212 String sql = null;
9213
9214 if (orderByComparator != null) {
9215 query = new StringBundler(2 +
9216 (orderByComparator.getOrderByFields().length * 3));
9217
9218 query.append(_SQL_SELECT_DDMSTRUCTURE);
9219
9220 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9221 orderByComparator);
9222
9223 sql = query.toString();
9224 }
9225 else {
9226 sql = _SQL_SELECT_DDMSTRUCTURE;
9227
9228 if (pagination) {
9229 sql = sql.concat(DDMStructureModelImpl.ORDER_BY_JPQL);
9230 }
9231 }
9232
9233 Session session = null;
9234
9235 try {
9236 session = openSession();
9237
9238 Query q = session.createQuery(sql);
9239
9240 if (!pagination) {
9241 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
9242 start, end, false);
9243
9244 Collections.sort(list);
9245
9246 list = Collections.unmodifiableList(list);
9247 }
9248 else {
9249 list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
9250 start, end);
9251 }
9252
9253 cacheResult(list);
9254
9255 FinderCacheUtil.putResult(finderPath, finderArgs, list);
9256 }
9257 catch (Exception e) {
9258 FinderCacheUtil.removeResult(finderPath, finderArgs);
9259
9260 throw processException(e);
9261 }
9262 finally {
9263 closeSession(session);
9264 }
9265 }
9266
9267 return list;
9268 }
9269
9270
9274 @Override
9275 public void removeAll() {
9276 for (DDMStructure ddmStructure : findAll()) {
9277 remove(ddmStructure);
9278 }
9279 }
9280
9281
9286 @Override
9287 public int countAll() {
9288 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9289 FINDER_ARGS_EMPTY, this);
9290
9291 if (count == null) {
9292 Session session = null;
9293
9294 try {
9295 session = openSession();
9296
9297 Query q = session.createQuery(_SQL_COUNT_DDMSTRUCTURE);
9298
9299 count = (Long)q.uniqueResult();
9300
9301 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
9302 FINDER_ARGS_EMPTY, count);
9303 }
9304 catch (Exception e) {
9305 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
9306 FINDER_ARGS_EMPTY);
9307
9308 throw processException(e);
9309 }
9310 finally {
9311 closeSession(session);
9312 }
9313 }
9314
9315 return count.intValue();
9316 }
9317
9318
9324 @Override
9325 public long[] getDLFileEntryTypePrimaryKeys(long pk) {
9326 long[] pks = ddmStructureToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
9327
9328 return pks.clone();
9329 }
9330
9331
9337 @Override
9338 public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9339 long pk) {
9340 return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9341 }
9342
9343
9355 @Override
9356 public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9357 long pk, int start, int end) {
9358 return getDLFileEntryTypes(pk, start, end, null);
9359 }
9360
9361
9374 @Override
9375 public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9376 long pk, int start, int end,
9377 OrderByComparator<com.liferay.portlet.documentlibrary.model.DLFileEntryType> orderByComparator) {
9378 return ddmStructureToDLFileEntryTypeTableMapper.getRightBaseModels(pk,
9379 start, end, orderByComparator);
9380 }
9381
9382
9388 @Override
9389 public int getDLFileEntryTypesSize(long pk) {
9390 long[] pks = ddmStructureToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
9391
9392 return pks.length;
9393 }
9394
9395
9402 @Override
9403 public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK) {
9404 return ddmStructureToDLFileEntryTypeTableMapper.containsTableMapping(pk,
9405 dlFileEntryTypePK);
9406 }
9407
9408
9414 @Override
9415 public boolean containsDLFileEntryTypes(long pk) {
9416 if (getDLFileEntryTypesSize(pk) > 0) {
9417 return true;
9418 }
9419 else {
9420 return false;
9421 }
9422 }
9423
9424
9430 @Override
9431 public void addDLFileEntryType(long pk, long dlFileEntryTypePK) {
9432 ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9433 dlFileEntryTypePK);
9434 }
9435
9436
9442 @Override
9443 public void addDLFileEntryType(long pk,
9444 com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType) {
9445 ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9446 dlFileEntryType.getPrimaryKey());
9447 }
9448
9449
9455 @Override
9456 public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
9457 for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
9458 ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9459 dlFileEntryTypePK);
9460 }
9461 }
9462
9463
9469 @Override
9470 public void addDLFileEntryTypes(long pk,
9471 List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
9472 for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9473 ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9474 dlFileEntryType.getPrimaryKey());
9475 }
9476 }
9477
9478
9483 @Override
9484 public void clearDLFileEntryTypes(long pk) {
9485 ddmStructureToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9486 }
9487
9488
9494 @Override
9495 public void removeDLFileEntryType(long pk, long dlFileEntryTypePK) {
9496 ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9497 dlFileEntryTypePK);
9498 }
9499
9500
9506 @Override
9507 public void removeDLFileEntryType(long pk,
9508 com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType) {
9509 ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9510 dlFileEntryType.getPrimaryKey());
9511 }
9512
9513
9519 @Override
9520 public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
9521 for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
9522 ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9523 dlFileEntryTypePK);
9524 }
9525 }
9526
9527
9533 @Override
9534 public void removeDLFileEntryTypes(long pk,
9535 List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
9536 for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9537 ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9538 dlFileEntryType.getPrimaryKey());
9539 }
9540 }
9541
9542
9548 @Override
9549 public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
9550 Set<Long> newDLFileEntryTypePKsSet = SetUtil.fromArray(dlFileEntryTypePKs);
9551 Set<Long> oldDLFileEntryTypePKsSet = SetUtil.fromArray(ddmStructureToDLFileEntryTypeTableMapper.getRightPrimaryKeys(
9552 pk));
9553
9554 Set<Long> removeDLFileEntryTypePKsSet = new HashSet<Long>(oldDLFileEntryTypePKsSet);
9555
9556 removeDLFileEntryTypePKsSet.removeAll(newDLFileEntryTypePKsSet);
9557
9558 for (long removeDLFileEntryTypePK : removeDLFileEntryTypePKsSet) {
9559 ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9560 removeDLFileEntryTypePK);
9561 }
9562
9563 newDLFileEntryTypePKsSet.removeAll(oldDLFileEntryTypePKsSet);
9564
9565 for (long newDLFileEntryTypePK : newDLFileEntryTypePKsSet) {
9566 ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9567 newDLFileEntryTypePK);
9568 }
9569 }
9570
9571
9577 @Override
9578 public void setDLFileEntryTypes(long pk,
9579 List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
9580 try {
9581 long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
9582
9583 for (int i = 0; i < dlFileEntryTypes.size(); i++) {
9584 com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
9585 dlFileEntryTypes.get(i);
9586
9587 dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
9588 }
9589
9590 setDLFileEntryTypes(pk, dlFileEntryTypePKs);
9591 }
9592 catch (Exception e) {
9593 throw processException(e);
9594 }
9595 }
9596
9597
9603 @Override
9604 public long[] getJournalFolderPrimaryKeys(long pk) {
9605 long[] pks = ddmStructureToJournalFolderTableMapper.getRightPrimaryKeys(pk);
9606
9607 return pks.clone();
9608 }
9609
9610
9616 @Override
9617 public List<com.liferay.portlet.journal.model.JournalFolder> getJournalFolders(
9618 long pk) {
9619 return getJournalFolders(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9620 }
9621
9622
9634 @Override
9635 public List<com.liferay.portlet.journal.model.JournalFolder> getJournalFolders(
9636 long pk, int start, int end) {
9637 return getJournalFolders(pk, start, end, null);
9638 }
9639
9640
9653 @Override
9654 public List<com.liferay.portlet.journal.model.JournalFolder> getJournalFolders(
9655 long pk, int start, int end,
9656 OrderByComparator<com.liferay.portlet.journal.model.JournalFolder> orderByComparator) {
9657 return ddmStructureToJournalFolderTableMapper.getRightBaseModels(pk,
9658 start, end, orderByComparator);
9659 }
9660
9661
9667 @Override
9668 public int getJournalFoldersSize(long pk) {
9669 long[] pks = ddmStructureToJournalFolderTableMapper.getRightPrimaryKeys(pk);
9670
9671 return pks.length;
9672 }
9673
9674
9681 @Override
9682 public boolean containsJournalFolder(long pk, long journalFolderPK) {
9683 return ddmStructureToJournalFolderTableMapper.containsTableMapping(pk,
9684 journalFolderPK);
9685 }
9686
9687
9693 @Override
9694 public boolean containsJournalFolders(long pk) {
9695 if (getJournalFoldersSize(pk) > 0) {
9696 return true;
9697 }
9698 else {
9699 return false;
9700 }
9701 }
9702
9703
9709 @Override
9710 public void addJournalFolder(long pk, long journalFolderPK) {
9711 ddmStructureToJournalFolderTableMapper.addTableMapping(pk,
9712 journalFolderPK);
9713 }
9714
9715
9721 @Override
9722 public void addJournalFolder(long pk,
9723 com.liferay.portlet.journal.model.JournalFolder journalFolder) {
9724 ddmStructureToJournalFolderTableMapper.addTableMapping(pk,
9725 journalFolder.getPrimaryKey());
9726 }
9727
9728
9734 @Override
9735 public void addJournalFolders(long pk, long[] journalFolderPKs) {
9736 for (long journalFolderPK : journalFolderPKs) {
9737 ddmStructureToJournalFolderTableMapper.addTableMapping(pk,
9738 journalFolderPK);
9739 }
9740 }
9741
9742
9748 @Override
9749 public void addJournalFolders(long pk,
9750 List<com.liferay.portlet.journal.model.JournalFolder> journalFolders) {
9751 for (com.liferay.portlet.journal.model.JournalFolder journalFolder : journalFolders) {
9752 ddmStructureToJournalFolderTableMapper.addTableMapping(pk,
9753 journalFolder.getPrimaryKey());
9754 }
9755 }
9756
9757
9762 @Override
9763 public void clearJournalFolders(long pk) {
9764 ddmStructureToJournalFolderTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9765 }
9766
9767
9773 @Override
9774 public void removeJournalFolder(long pk, long journalFolderPK) {
9775 ddmStructureToJournalFolderTableMapper.deleteTableMapping(pk,
9776 journalFolderPK);
9777 }
9778
9779
9785 @Override
9786 public void removeJournalFolder(long pk,
9787 com.liferay.portlet.journal.model.JournalFolder journalFolder) {
9788 ddmStructureToJournalFolderTableMapper.deleteTableMapping(pk,
9789 journalFolder.getPrimaryKey());
9790 }
9791
9792
9798 @Override
9799 public void removeJournalFolders(long pk, long[] journalFolderPKs) {
9800 for (long journalFolderPK : journalFolderPKs) {
9801 ddmStructureToJournalFolderTableMapper.deleteTableMapping(pk,
9802 journalFolderPK);
9803 }
9804 }
9805
9806
9812 @Override
9813 public void removeJournalFolders(long pk,
9814 List<com.liferay.portlet.journal.model.JournalFolder> journalFolders) {
9815 for (com.liferay.portlet.journal.model.JournalFolder journalFolder : journalFolders) {
9816 ddmStructureToJournalFolderTableMapper.deleteTableMapping(pk,
9817 journalFolder.getPrimaryKey());
9818 }
9819 }
9820
9821
9827 @Override
9828 public void setJournalFolders(long pk, long[] journalFolderPKs) {
9829 Set<Long> newJournalFolderPKsSet = SetUtil.fromArray(journalFolderPKs);
9830 Set<Long> oldJournalFolderPKsSet = SetUtil.fromArray(ddmStructureToJournalFolderTableMapper.getRightPrimaryKeys(
9831 pk));
9832
9833 Set<Long> removeJournalFolderPKsSet = new HashSet<Long>(oldJournalFolderPKsSet);
9834
9835 removeJournalFolderPKsSet.removeAll(newJournalFolderPKsSet);
9836
9837 for (long removeJournalFolderPK : removeJournalFolderPKsSet) {
9838 ddmStructureToJournalFolderTableMapper.deleteTableMapping(pk,
9839 removeJournalFolderPK);
9840 }
9841
9842 newJournalFolderPKsSet.removeAll(oldJournalFolderPKsSet);
9843
9844 for (long newJournalFolderPK : newJournalFolderPKsSet) {
9845 ddmStructureToJournalFolderTableMapper.addTableMapping(pk,
9846 newJournalFolderPK);
9847 }
9848 }
9849
9850
9856 @Override
9857 public void setJournalFolders(long pk,
9858 List<com.liferay.portlet.journal.model.JournalFolder> journalFolders) {
9859 try {
9860 long[] journalFolderPKs = new long[journalFolders.size()];
9861
9862 for (int i = 0; i < journalFolders.size(); i++) {
9863 com.liferay.portlet.journal.model.JournalFolder journalFolder = journalFolders.get(i);
9864
9865 journalFolderPKs[i] = journalFolder.getPrimaryKey();
9866 }
9867
9868 setJournalFolders(pk, journalFolderPKs);
9869 }
9870 catch (Exception e) {
9871 throw processException(e);
9872 }
9873 }
9874
9875 @Override
9876 protected Set<String> getBadColumnNames() {
9877 return _badColumnNames;
9878 }
9879
9880
9883 public void afterPropertiesSet() {
9884 ddmStructureToDLFileEntryTypeTableMapper = TableMapperFactory.getTableMapper("DLFileEntryTypes_DDMStructures",
9885 "structureId", "fileEntryTypeId", this,
9886 dlFileEntryTypePersistence);
9887
9888 ddmStructureToJournalFolderTableMapper = TableMapperFactory.getTableMapper("JournalFolders_DDMStructures",
9889 "structureId", "folderId", this, journalFolderPersistence);
9890 }
9891
9892 public void destroy() {
9893 EntityCacheUtil.removeCache(DDMStructureImpl.class.getName());
9894 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9895 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9896 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9897
9898 TableMapperFactory.removeTableMapper("DLFileEntryTypes_DDMStructures");
9899 TableMapperFactory.removeTableMapper("JournalFolders_DDMStructures");
9900 }
9901
9902 @BeanReference(type = DLFileEntryTypePersistence.class)
9903 protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
9904 protected TableMapper<DDMStructure, com.liferay.portlet.documentlibrary.model.DLFileEntryType> ddmStructureToDLFileEntryTypeTableMapper;
9905 @BeanReference(type = JournalFolderPersistence.class)
9906 protected JournalFolderPersistence journalFolderPersistence;
9907 protected TableMapper<DDMStructure, com.liferay.portlet.journal.model.JournalFolder> ddmStructureToJournalFolderTableMapper;
9908 private static final String _SQL_SELECT_DDMSTRUCTURE = "SELECT ddmStructure FROM DDMStructure ddmStructure";
9909 private static final String _SQL_SELECT_DDMSTRUCTURE_WHERE_PKS_IN = "SELECT ddmStructure FROM DDMStructure ddmStructure WHERE structureId IN (";
9910 private static final String _SQL_SELECT_DDMSTRUCTURE_WHERE = "SELECT ddmStructure FROM DDMStructure ddmStructure WHERE ";
9911 private static final String _SQL_COUNT_DDMSTRUCTURE = "SELECT COUNT(ddmStructure) FROM DDMStructure ddmStructure";
9912 private static final String _SQL_COUNT_DDMSTRUCTURE_WHERE = "SELECT COUNT(ddmStructure) FROM DDMStructure ddmStructure WHERE ";
9913 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "ddmStructure.structureId";
9914 private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE = "SELECT DISTINCT {ddmStructure.*} FROM DDMStructure ddmStructure WHERE ";
9915 private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1 =
9916 "SELECT {DDMStructure.*} FROM (SELECT DISTINCT ddmStructure.structureId FROM DDMStructure ddmStructure WHERE ";
9917 private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2 =
9918 ") TEMP_TABLE INNER JOIN DDMStructure ON TEMP_TABLE.structureId = DDMStructure.structureId";
9919 private static final String _FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE = "SELECT COUNT(DISTINCT ddmStructure.structureId) AS COUNT_VALUE FROM DDMStructure ddmStructure WHERE ";
9920 private static final String _FILTER_ENTITY_ALIAS = "ddmStructure";
9921 private static final String _FILTER_ENTITY_TABLE = "DDMStructure";
9922 private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStructure.";
9923 private static final String _ORDER_BY_ENTITY_TABLE = "DDMStructure.";
9924 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStructure exists with the primary key ";
9925 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStructure exists with the key {";
9926 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9927 private static final Log _log = LogFactoryUtil.getLog(DDMStructurePersistenceImpl.class);
9928 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9929 "uuid", "type"
9930 });
9931 private static final DDMStructure _nullDDMStructure = new DDMStructureImpl() {
9932 @Override
9933 public Object clone() {
9934 return this;
9935 }
9936
9937 @Override
9938 public CacheModel<DDMStructure> toCacheModel() {
9939 return _nullDDMStructureCacheModel;
9940 }
9941 };
9942
9943 private static final CacheModel<DDMStructure> _nullDDMStructureCacheModel = new CacheModel<DDMStructure>() {
9944 @Override
9945 public DDMStructure toEntityModel() {
9946 return _nullDDMStructure;
9947 }
9948 };
9949 }