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