1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchLayoutException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.dao.DynamicQuery;
28 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
29 import com.liferay.portal.kernel.util.OrderByComparator;
30 import com.liferay.portal.kernel.util.StringMaker;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.model.Layout;
33 import com.liferay.portal.model.impl.LayoutImpl;
34 import com.liferay.portal.service.persistence.BasePersistence;
35 import com.liferay.portal.spring.hibernate.FinderCache;
36 import com.liferay.portal.spring.hibernate.HibernateUtil;
37
38 import com.liferay.util.dao.hibernate.QueryUtil;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43 import org.hibernate.Query;
44 import org.hibernate.Session;
45
46 import java.util.Collections;
47 import java.util.Iterator;
48 import java.util.List;
49
50
56 public class LayoutPersistenceImpl extends BasePersistence
57 implements LayoutPersistence {
58 public Layout create(long plid) {
59 Layout layout = new LayoutImpl();
60 layout.setNew(true);
61 layout.setPrimaryKey(plid);
62
63 return layout;
64 }
65
66 public Layout remove(long plid)
67 throws NoSuchLayoutException, SystemException {
68 Session session = null;
69
70 try {
71 session = openSession();
72
73 Layout layout = (Layout)session.get(LayoutImpl.class, new Long(plid));
74
75 if (layout == null) {
76 if (_log.isWarnEnabled()) {
77 _log.warn("No Layout exists with the primary key " + plid);
78 }
79
80 throw new NoSuchLayoutException(
81 "No Layout exists with the primary key " + plid);
82 }
83
84 return remove(layout);
85 }
86 catch (NoSuchLayoutException nsee) {
87 throw nsee;
88 }
89 catch (Exception e) {
90 throw HibernateUtil.processException(e);
91 }
92 finally {
93 closeSession(session);
94 }
95 }
96
97 public Layout remove(Layout layout) throws SystemException {
98 Session session = null;
99
100 try {
101 session = openSession();
102 session.delete(layout);
103 session.flush();
104
105 return layout;
106 }
107 catch (Exception e) {
108 throw HibernateUtil.processException(e);
109 }
110 finally {
111 closeSession(session);
112 FinderCache.clearCache(Layout.class.getName());
113 }
114 }
115
116 public Layout update(com.liferay.portal.model.Layout layout)
117 throws SystemException {
118 return update(layout, false);
119 }
120
121 public Layout update(com.liferay.portal.model.Layout layout, boolean merge)
122 throws SystemException {
123 Session session = null;
124
125 try {
126 session = openSession();
127
128 if (merge) {
129 session.merge(layout);
130 }
131 else {
132 if (layout.isNew()) {
133 session.save(layout);
134 }
135 }
136
137 session.flush();
138 layout.setNew(false);
139
140 return layout;
141 }
142 catch (Exception e) {
143 throw HibernateUtil.processException(e);
144 }
145 finally {
146 closeSession(session);
147 FinderCache.clearCache(Layout.class.getName());
148 }
149 }
150
151 public Layout findByPrimaryKey(long plid)
152 throws NoSuchLayoutException, SystemException {
153 Layout layout = fetchByPrimaryKey(plid);
154
155 if (layout == null) {
156 if (_log.isWarnEnabled()) {
157 _log.warn("No Layout exists with the primary key " + plid);
158 }
159
160 throw new NoSuchLayoutException(
161 "No Layout exists with the primary key " + plid);
162 }
163
164 return layout;
165 }
166
167 public Layout fetchByPrimaryKey(long plid) throws SystemException {
168 Session session = null;
169
170 try {
171 session = openSession();
172
173 return (Layout)session.get(LayoutImpl.class, new Long(plid));
174 }
175 catch (Exception e) {
176 throw HibernateUtil.processException(e);
177 }
178 finally {
179 closeSession(session);
180 }
181 }
182
183 public Layout findByDLF(long dlFolderId)
184 throws NoSuchLayoutException, SystemException {
185 Layout layout = fetchByDLF(dlFolderId);
186
187 if (layout == null) {
188 StringMaker msg = new StringMaker();
189 msg.append("No Layout exists with the key ");
190 msg.append(StringPool.OPEN_CURLY_BRACE);
191 msg.append("dlFolderId=");
192 msg.append(dlFolderId);
193 msg.append(StringPool.CLOSE_CURLY_BRACE);
194
195 if (_log.isWarnEnabled()) {
196 _log.warn(msg.toString());
197 }
198
199 throw new NoSuchLayoutException(msg.toString());
200 }
201
202 return layout;
203 }
204
205 public Layout fetchByDLF(long dlFolderId) throws SystemException {
206 String finderClassName = Layout.class.getName();
207 String finderMethodName = "fetchByDLF";
208 String[] finderParams = new String[] { Long.class.getName() };
209 Object[] finderArgs = new Object[] { new Long(dlFolderId) };
210 Object result = FinderCache.getResult(finderClassName,
211 finderMethodName, finderParams, finderArgs, getSessionFactory());
212
213 if (result == null) {
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 StringMaker query = new StringMaker();
220 query.append("FROM com.liferay.portal.model.Layout WHERE ");
221 query.append("dlFolderId = ?");
222 query.append(" ");
223 query.append("ORDER BY ");
224 query.append("parentLayoutId ASC").append(", ");
225 query.append("priority ASC");
226
227 Query q = session.createQuery(query.toString());
228 int queryPos = 0;
229 q.setLong(queryPos++, dlFolderId);
230
231 List list = q.list();
232 FinderCache.putResult(finderClassName, finderMethodName,
233 finderParams, finderArgs, list);
234
235 if (list.size() == 0) {
236 return null;
237 }
238 else {
239 return (Layout)list.get(0);
240 }
241 }
242 catch (Exception e) {
243 throw HibernateUtil.processException(e);
244 }
245 finally {
246 closeSession(session);
247 }
248 }
249 else {
250 List list = (List)result;
251
252 if (list.size() == 0) {
253 return null;
254 }
255 else {
256 return (Layout)list.get(0);
257 }
258 }
259 }
260
261 public List findByG_P(long groupId, boolean privateLayout)
262 throws SystemException {
263 String finderClassName = Layout.class.getName();
264 String finderMethodName = "findByG_P";
265 String[] finderParams = new String[] {
266 Long.class.getName(), Boolean.class.getName()
267 };
268 Object[] finderArgs = new Object[] {
269 new Long(groupId), Boolean.valueOf(privateLayout)
270 };
271 Object result = FinderCache.getResult(finderClassName,
272 finderMethodName, finderParams, finderArgs, getSessionFactory());
273
274 if (result == null) {
275 Session session = null;
276
277 try {
278 session = openSession();
279
280 StringMaker query = new StringMaker();
281 query.append("FROM com.liferay.portal.model.Layout WHERE ");
282 query.append("groupId = ?");
283 query.append(" AND ");
284 query.append("privateLayout = ?");
285 query.append(" ");
286 query.append("ORDER BY ");
287 query.append("parentLayoutId ASC").append(", ");
288 query.append("priority ASC");
289
290 Query q = session.createQuery(query.toString());
291 int queryPos = 0;
292 q.setLong(queryPos++, groupId);
293 q.setBoolean(queryPos++, privateLayout);
294
295 List list = q.list();
296 FinderCache.putResult(finderClassName, finderMethodName,
297 finderParams, finderArgs, list);
298
299 return list;
300 }
301 catch (Exception e) {
302 throw HibernateUtil.processException(e);
303 }
304 finally {
305 closeSession(session);
306 }
307 }
308 else {
309 return (List)result;
310 }
311 }
312
313 public List findByG_P(long groupId, boolean privateLayout, int begin,
314 int end) throws SystemException {
315 return findByG_P(groupId, privateLayout, begin, end, null);
316 }
317
318 public List findByG_P(long groupId, boolean privateLayout, int begin,
319 int end, OrderByComparator obc) throws SystemException {
320 String finderClassName = Layout.class.getName();
321 String finderMethodName = "findByG_P";
322 String[] finderParams = new String[] {
323 Long.class.getName(), Boolean.class.getName(),
324 "java.lang.Integer", "java.lang.Integer",
325 "com.liferay.portal.kernel.util.OrderByComparator"
326 };
327 Object[] finderArgs = new Object[] {
328 new Long(groupId), Boolean.valueOf(privateLayout),
329 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
330 };
331 Object result = FinderCache.getResult(finderClassName,
332 finderMethodName, finderParams, finderArgs, getSessionFactory());
333
334 if (result == null) {
335 Session session = null;
336
337 try {
338 session = openSession();
339
340 StringMaker query = new StringMaker();
341 query.append("FROM com.liferay.portal.model.Layout WHERE ");
342 query.append("groupId = ?");
343 query.append(" AND ");
344 query.append("privateLayout = ?");
345 query.append(" ");
346
347 if (obc != null) {
348 query.append("ORDER BY ");
349 query.append(obc.getOrderBy());
350 }
351 else {
352 query.append("ORDER BY ");
353 query.append("parentLayoutId ASC").append(", ");
354 query.append("priority ASC");
355 }
356
357 Query q = session.createQuery(query.toString());
358 int queryPos = 0;
359 q.setLong(queryPos++, groupId);
360 q.setBoolean(queryPos++, privateLayout);
361
362 List list = QueryUtil.list(q, getDialect(), begin, end);
363 FinderCache.putResult(finderClassName, finderMethodName,
364 finderParams, finderArgs, list);
365
366 return list;
367 }
368 catch (Exception e) {
369 throw HibernateUtil.processException(e);
370 }
371 finally {
372 closeSession(session);
373 }
374 }
375 else {
376 return (List)result;
377 }
378 }
379
380 public Layout findByG_P_First(long groupId, boolean privateLayout,
381 OrderByComparator obc) throws NoSuchLayoutException, SystemException {
382 List list = findByG_P(groupId, privateLayout, 0, 1, obc);
383
384 if (list.size() == 0) {
385 StringMaker msg = new StringMaker();
386 msg.append("No Layout exists with the key ");
387 msg.append(StringPool.OPEN_CURLY_BRACE);
388 msg.append("groupId=");
389 msg.append(groupId);
390 msg.append(", ");
391 msg.append("privateLayout=");
392 msg.append(privateLayout);
393 msg.append(StringPool.CLOSE_CURLY_BRACE);
394 throw new NoSuchLayoutException(msg.toString());
395 }
396 else {
397 return (Layout)list.get(0);
398 }
399 }
400
401 public Layout findByG_P_Last(long groupId, boolean privateLayout,
402 OrderByComparator obc) throws NoSuchLayoutException, SystemException {
403 int count = countByG_P(groupId, privateLayout);
404 List list = findByG_P(groupId, privateLayout, count - 1, count, obc);
405
406 if (list.size() == 0) {
407 StringMaker msg = new StringMaker();
408 msg.append("No Layout exists with the key ");
409 msg.append(StringPool.OPEN_CURLY_BRACE);
410 msg.append("groupId=");
411 msg.append(groupId);
412 msg.append(", ");
413 msg.append("privateLayout=");
414 msg.append(privateLayout);
415 msg.append(StringPool.CLOSE_CURLY_BRACE);
416 throw new NoSuchLayoutException(msg.toString());
417 }
418 else {
419 return (Layout)list.get(0);
420 }
421 }
422
423 public Layout[] findByG_P_PrevAndNext(long plid, long groupId,
424 boolean privateLayout, OrderByComparator obc)
425 throws NoSuchLayoutException, SystemException {
426 Layout layout = findByPrimaryKey(plid);
427 int count = countByG_P(groupId, privateLayout);
428 Session session = null;
429
430 try {
431 session = openSession();
432
433 StringMaker query = new StringMaker();
434 query.append("FROM com.liferay.portal.model.Layout WHERE ");
435 query.append("groupId = ?");
436 query.append(" AND ");
437 query.append("privateLayout = ?");
438 query.append(" ");
439
440 if (obc != null) {
441 query.append("ORDER BY ");
442 query.append(obc.getOrderBy());
443 }
444 else {
445 query.append("ORDER BY ");
446 query.append("parentLayoutId ASC").append(", ");
447 query.append("priority ASC");
448 }
449
450 Query q = session.createQuery(query.toString());
451 int queryPos = 0;
452 q.setLong(queryPos++, groupId);
453 q.setBoolean(queryPos++, privateLayout);
454
455 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, layout);
456 Layout[] array = new LayoutImpl[3];
457 array[0] = (Layout)objArray[0];
458 array[1] = (Layout)objArray[1];
459 array[2] = (Layout)objArray[2];
460
461 return array;
462 }
463 catch (Exception e) {
464 throw HibernateUtil.processException(e);
465 }
466 finally {
467 closeSession(session);
468 }
469 }
470
471 public Layout findByG_P_L(long groupId, boolean privateLayout, long layoutId)
472 throws NoSuchLayoutException, SystemException {
473 Layout layout = fetchByG_P_L(groupId, privateLayout, layoutId);
474
475 if (layout == null) {
476 StringMaker msg = new StringMaker();
477 msg.append("No Layout exists with the key ");
478 msg.append(StringPool.OPEN_CURLY_BRACE);
479 msg.append("groupId=");
480 msg.append(groupId);
481 msg.append(", ");
482 msg.append("privateLayout=");
483 msg.append(privateLayout);
484 msg.append(", ");
485 msg.append("layoutId=");
486 msg.append(layoutId);
487 msg.append(StringPool.CLOSE_CURLY_BRACE);
488
489 if (_log.isWarnEnabled()) {
490 _log.warn(msg.toString());
491 }
492
493 throw new NoSuchLayoutException(msg.toString());
494 }
495
496 return layout;
497 }
498
499 public Layout fetchByG_P_L(long groupId, boolean privateLayout,
500 long layoutId) throws SystemException {
501 String finderClassName = Layout.class.getName();
502 String finderMethodName = "fetchByG_P_L";
503 String[] finderParams = new String[] {
504 Long.class.getName(), Boolean.class.getName(),
505 Long.class.getName()
506 };
507 Object[] finderArgs = new Object[] {
508 new Long(groupId), Boolean.valueOf(privateLayout),
509 new Long(layoutId)
510 };
511 Object result = FinderCache.getResult(finderClassName,
512 finderMethodName, finderParams, finderArgs, getSessionFactory());
513
514 if (result == null) {
515 Session session = null;
516
517 try {
518 session = openSession();
519
520 StringMaker query = new StringMaker();
521 query.append("FROM com.liferay.portal.model.Layout WHERE ");
522 query.append("groupId = ?");
523 query.append(" AND ");
524 query.append("privateLayout = ?");
525 query.append(" AND ");
526 query.append("layoutId = ?");
527 query.append(" ");
528 query.append("ORDER BY ");
529 query.append("parentLayoutId ASC").append(", ");
530 query.append("priority ASC");
531
532 Query q = session.createQuery(query.toString());
533 int queryPos = 0;
534 q.setLong(queryPos++, groupId);
535 q.setBoolean(queryPos++, privateLayout);
536 q.setLong(queryPos++, layoutId);
537
538 List list = q.list();
539 FinderCache.putResult(finderClassName, finderMethodName,
540 finderParams, finderArgs, list);
541
542 if (list.size() == 0) {
543 return null;
544 }
545 else {
546 return (Layout)list.get(0);
547 }
548 }
549 catch (Exception e) {
550 throw HibernateUtil.processException(e);
551 }
552 finally {
553 closeSession(session);
554 }
555 }
556 else {
557 List list = (List)result;
558
559 if (list.size() == 0) {
560 return null;
561 }
562 else {
563 return (Layout)list.get(0);
564 }
565 }
566 }
567
568 public List findByG_P_P(long groupId, boolean privateLayout,
569 long parentLayoutId) throws SystemException {
570 String finderClassName = Layout.class.getName();
571 String finderMethodName = "findByG_P_P";
572 String[] finderParams = new String[] {
573 Long.class.getName(), Boolean.class.getName(),
574 Long.class.getName()
575 };
576 Object[] finderArgs = new Object[] {
577 new Long(groupId), Boolean.valueOf(privateLayout),
578 new Long(parentLayoutId)
579 };
580 Object result = FinderCache.getResult(finderClassName,
581 finderMethodName, finderParams, finderArgs, getSessionFactory());
582
583 if (result == null) {
584 Session session = null;
585
586 try {
587 session = openSession();
588
589 StringMaker query = new StringMaker();
590 query.append("FROM com.liferay.portal.model.Layout WHERE ");
591 query.append("groupId = ?");
592 query.append(" AND ");
593 query.append("privateLayout = ?");
594 query.append(" AND ");
595 query.append("parentLayoutId = ?");
596 query.append(" ");
597 query.append("ORDER BY ");
598 query.append("parentLayoutId ASC").append(", ");
599 query.append("priority ASC");
600
601 Query q = session.createQuery(query.toString());
602 int queryPos = 0;
603 q.setLong(queryPos++, groupId);
604 q.setBoolean(queryPos++, privateLayout);
605 q.setLong(queryPos++, parentLayoutId);
606
607 List list = q.list();
608 FinderCache.putResult(finderClassName, finderMethodName,
609 finderParams, finderArgs, list);
610
611 return list;
612 }
613 catch (Exception e) {
614 throw HibernateUtil.processException(e);
615 }
616 finally {
617 closeSession(session);
618 }
619 }
620 else {
621 return (List)result;
622 }
623 }
624
625 public List findByG_P_P(long groupId, boolean privateLayout,
626 long parentLayoutId, int begin, int end) throws SystemException {
627 return findByG_P_P(groupId, privateLayout, parentLayoutId, begin, end,
628 null);
629 }
630
631 public List findByG_P_P(long groupId, boolean privateLayout,
632 long parentLayoutId, int begin, int end, OrderByComparator obc)
633 throws SystemException {
634 String finderClassName = Layout.class.getName();
635 String finderMethodName = "findByG_P_P";
636 String[] finderParams = new String[] {
637 Long.class.getName(), Boolean.class.getName(),
638 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
639 "com.liferay.portal.kernel.util.OrderByComparator"
640 };
641 Object[] finderArgs = new Object[] {
642 new Long(groupId), Boolean.valueOf(privateLayout),
643 new Long(parentLayoutId), String.valueOf(begin),
644 String.valueOf(end), String.valueOf(obc)
645 };
646 Object result = FinderCache.getResult(finderClassName,
647 finderMethodName, finderParams, finderArgs, getSessionFactory());
648
649 if (result == null) {
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 StringMaker query = new StringMaker();
656 query.append("FROM com.liferay.portal.model.Layout WHERE ");
657 query.append("groupId = ?");
658 query.append(" AND ");
659 query.append("privateLayout = ?");
660 query.append(" AND ");
661 query.append("parentLayoutId = ?");
662 query.append(" ");
663
664 if (obc != null) {
665 query.append("ORDER BY ");
666 query.append(obc.getOrderBy());
667 }
668 else {
669 query.append("ORDER BY ");
670 query.append("parentLayoutId ASC").append(", ");
671 query.append("priority ASC");
672 }
673
674 Query q = session.createQuery(query.toString());
675 int queryPos = 0;
676 q.setLong(queryPos++, groupId);
677 q.setBoolean(queryPos++, privateLayout);
678 q.setLong(queryPos++, parentLayoutId);
679
680 List list = QueryUtil.list(q, getDialect(), begin, end);
681 FinderCache.putResult(finderClassName, finderMethodName,
682 finderParams, finderArgs, list);
683
684 return list;
685 }
686 catch (Exception e) {
687 throw HibernateUtil.processException(e);
688 }
689 finally {
690 closeSession(session);
691 }
692 }
693 else {
694 return (List)result;
695 }
696 }
697
698 public Layout findByG_P_P_First(long groupId, boolean privateLayout,
699 long parentLayoutId, OrderByComparator obc)
700 throws NoSuchLayoutException, SystemException {
701 List list = findByG_P_P(groupId, privateLayout, parentLayoutId, 0, 1,
702 obc);
703
704 if (list.size() == 0) {
705 StringMaker msg = new StringMaker();
706 msg.append("No Layout exists with the key ");
707 msg.append(StringPool.OPEN_CURLY_BRACE);
708 msg.append("groupId=");
709 msg.append(groupId);
710 msg.append(", ");
711 msg.append("privateLayout=");
712 msg.append(privateLayout);
713 msg.append(", ");
714 msg.append("parentLayoutId=");
715 msg.append(parentLayoutId);
716 msg.append(StringPool.CLOSE_CURLY_BRACE);
717 throw new NoSuchLayoutException(msg.toString());
718 }
719 else {
720 return (Layout)list.get(0);
721 }
722 }
723
724 public Layout findByG_P_P_Last(long groupId, boolean privateLayout,
725 long parentLayoutId, OrderByComparator obc)
726 throws NoSuchLayoutException, SystemException {
727 int count = countByG_P_P(groupId, privateLayout, parentLayoutId);
728 List list = findByG_P_P(groupId, privateLayout, parentLayoutId,
729 count - 1, count, obc);
730
731 if (list.size() == 0) {
732 StringMaker msg = new StringMaker();
733 msg.append("No Layout exists with the key ");
734 msg.append(StringPool.OPEN_CURLY_BRACE);
735 msg.append("groupId=");
736 msg.append(groupId);
737 msg.append(", ");
738 msg.append("privateLayout=");
739 msg.append(privateLayout);
740 msg.append(", ");
741 msg.append("parentLayoutId=");
742 msg.append(parentLayoutId);
743 msg.append(StringPool.CLOSE_CURLY_BRACE);
744 throw new NoSuchLayoutException(msg.toString());
745 }
746 else {
747 return (Layout)list.get(0);
748 }
749 }
750
751 public Layout[] findByG_P_P_PrevAndNext(long plid, long groupId,
752 boolean privateLayout, long parentLayoutId, OrderByComparator obc)
753 throws NoSuchLayoutException, SystemException {
754 Layout layout = findByPrimaryKey(plid);
755 int count = countByG_P_P(groupId, privateLayout, parentLayoutId);
756 Session session = null;
757
758 try {
759 session = openSession();
760
761 StringMaker query = new StringMaker();
762 query.append("FROM com.liferay.portal.model.Layout WHERE ");
763 query.append("groupId = ?");
764 query.append(" AND ");
765 query.append("privateLayout = ?");
766 query.append(" AND ");
767 query.append("parentLayoutId = ?");
768 query.append(" ");
769
770 if (obc != null) {
771 query.append("ORDER BY ");
772 query.append(obc.getOrderBy());
773 }
774 else {
775 query.append("ORDER BY ");
776 query.append("parentLayoutId ASC").append(", ");
777 query.append("priority ASC");
778 }
779
780 Query q = session.createQuery(query.toString());
781 int queryPos = 0;
782 q.setLong(queryPos++, groupId);
783 q.setBoolean(queryPos++, privateLayout);
784 q.setLong(queryPos++, parentLayoutId);
785
786 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, layout);
787 Layout[] array = new LayoutImpl[3];
788 array[0] = (Layout)objArray[0];
789 array[1] = (Layout)objArray[1];
790 array[2] = (Layout)objArray[2];
791
792 return array;
793 }
794 catch (Exception e) {
795 throw HibernateUtil.processException(e);
796 }
797 finally {
798 closeSession(session);
799 }
800 }
801
802 public Layout findByG_P_F(long groupId, boolean privateLayout,
803 String friendlyURL) throws NoSuchLayoutException, SystemException {
804 Layout layout = fetchByG_P_F(groupId, privateLayout, friendlyURL);
805
806 if (layout == null) {
807 StringMaker msg = new StringMaker();
808 msg.append("No Layout exists with the key ");
809 msg.append(StringPool.OPEN_CURLY_BRACE);
810 msg.append("groupId=");
811 msg.append(groupId);
812 msg.append(", ");
813 msg.append("privateLayout=");
814 msg.append(privateLayout);
815 msg.append(", ");
816 msg.append("friendlyURL=");
817 msg.append(friendlyURL);
818 msg.append(StringPool.CLOSE_CURLY_BRACE);
819
820 if (_log.isWarnEnabled()) {
821 _log.warn(msg.toString());
822 }
823
824 throw new NoSuchLayoutException(msg.toString());
825 }
826
827 return layout;
828 }
829
830 public Layout fetchByG_P_F(long groupId, boolean privateLayout,
831 String friendlyURL) throws SystemException {
832 String finderClassName = Layout.class.getName();
833 String finderMethodName = "fetchByG_P_F";
834 String[] finderParams = new String[] {
835 Long.class.getName(), Boolean.class.getName(),
836 String.class.getName()
837 };
838 Object[] finderArgs = new Object[] {
839 new Long(groupId), Boolean.valueOf(privateLayout), friendlyURL
840 };
841 Object result = FinderCache.getResult(finderClassName,
842 finderMethodName, finderParams, finderArgs, getSessionFactory());
843
844 if (result == null) {
845 Session session = null;
846
847 try {
848 session = openSession();
849
850 StringMaker query = new StringMaker();
851 query.append("FROM com.liferay.portal.model.Layout WHERE ");
852 query.append("groupId = ?");
853 query.append(" AND ");
854 query.append("privateLayout = ?");
855 query.append(" AND ");
856
857 if (friendlyURL == null) {
858 query.append("friendlyURL IS NULL");
859 }
860 else {
861 query.append("friendlyURL = ?");
862 }
863
864 query.append(" ");
865 query.append("ORDER BY ");
866 query.append("parentLayoutId ASC").append(", ");
867 query.append("priority ASC");
868
869 Query q = session.createQuery(query.toString());
870 int queryPos = 0;
871 q.setLong(queryPos++, groupId);
872 q.setBoolean(queryPos++, privateLayout);
873
874 if (friendlyURL != null) {
875 q.setString(queryPos++, friendlyURL);
876 }
877
878 List list = q.list();
879 FinderCache.putResult(finderClassName, finderMethodName,
880 finderParams, finderArgs, list);
881
882 if (list.size() == 0) {
883 return null;
884 }
885 else {
886 return (Layout)list.get(0);
887 }
888 }
889 catch (Exception e) {
890 throw HibernateUtil.processException(e);
891 }
892 finally {
893 closeSession(session);
894 }
895 }
896 else {
897 List list = (List)result;
898
899 if (list.size() == 0) {
900 return null;
901 }
902 else {
903 return (Layout)list.get(0);
904 }
905 }
906 }
907
908 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
909 throws SystemException {
910 Session session = null;
911
912 try {
913 session = openSession();
914
915 DynamicQuery query = queryInitializer.initialize(session);
916
917 return query.list();
918 }
919 catch (Exception e) {
920 throw HibernateUtil.processException(e);
921 }
922 finally {
923 closeSession(session);
924 }
925 }
926
927 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
928 int begin, int end) throws SystemException {
929 Session session = null;
930
931 try {
932 session = openSession();
933
934 DynamicQuery query = queryInitializer.initialize(session);
935 query.setLimit(begin, end);
936
937 return query.list();
938 }
939 catch (Exception e) {
940 throw HibernateUtil.processException(e);
941 }
942 finally {
943 closeSession(session);
944 }
945 }
946
947 public List findAll() throws SystemException {
948 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
949 }
950
951 public List findAll(int begin, int end) throws SystemException {
952 return findAll(begin, end, null);
953 }
954
955 public List findAll(int begin, int end, OrderByComparator obc)
956 throws SystemException {
957 String finderClassName = Layout.class.getName();
958 String finderMethodName = "findAll";
959 String[] finderParams = new String[] {
960 "java.lang.Integer", "java.lang.Integer",
961 "com.liferay.portal.kernel.util.OrderByComparator"
962 };
963 Object[] finderArgs = new Object[] {
964 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
965 };
966 Object result = FinderCache.getResult(finderClassName,
967 finderMethodName, finderParams, finderArgs, getSessionFactory());
968
969 if (result == null) {
970 Session session = null;
971
972 try {
973 session = openSession();
974
975 StringMaker query = new StringMaker();
976 query.append("FROM com.liferay.portal.model.Layout ");
977
978 if (obc != null) {
979 query.append("ORDER BY ");
980 query.append(obc.getOrderBy());
981 }
982 else {
983 query.append("ORDER BY ");
984 query.append("parentLayoutId ASC").append(", ");
985 query.append("priority ASC");
986 }
987
988 Query q = session.createQuery(query.toString());
989 List list = QueryUtil.list(q, getDialect(), begin, end);
990
991 if (obc == null) {
992 Collections.sort(list);
993 }
994
995 FinderCache.putResult(finderClassName, finderMethodName,
996 finderParams, finderArgs, list);
997
998 return list;
999 }
1000 catch (Exception e) {
1001 throw HibernateUtil.processException(e);
1002 }
1003 finally {
1004 closeSession(session);
1005 }
1006 }
1007 else {
1008 return (List)result;
1009 }
1010 }
1011
1012 public void removeByDLF(long dlFolderId)
1013 throws NoSuchLayoutException, SystemException {
1014 Layout layout = findByDLF(dlFolderId);
1015 remove(layout);
1016 }
1017
1018 public void removeByG_P(long groupId, boolean privateLayout)
1019 throws SystemException {
1020 Iterator itr = findByG_P(groupId, privateLayout).iterator();
1021
1022 while (itr.hasNext()) {
1023 Layout layout = (Layout)itr.next();
1024 remove(layout);
1025 }
1026 }
1027
1028 public void removeByG_P_L(long groupId, boolean privateLayout, long layoutId)
1029 throws NoSuchLayoutException, SystemException {
1030 Layout layout = findByG_P_L(groupId, privateLayout, layoutId);
1031 remove(layout);
1032 }
1033
1034 public void removeByG_P_P(long groupId, boolean privateLayout,
1035 long parentLayoutId) throws SystemException {
1036 Iterator itr = findByG_P_P(groupId, privateLayout, parentLayoutId)
1037 .iterator();
1038
1039 while (itr.hasNext()) {
1040 Layout layout = (Layout)itr.next();
1041 remove(layout);
1042 }
1043 }
1044
1045 public void removeByG_P_F(long groupId, boolean privateLayout,
1046 String friendlyURL) throws NoSuchLayoutException, SystemException {
1047 Layout layout = findByG_P_F(groupId, privateLayout, friendlyURL);
1048 remove(layout);
1049 }
1050
1051 public void removeAll() throws SystemException {
1052 Iterator itr = findAll().iterator();
1053
1054 while (itr.hasNext()) {
1055 remove((Layout)itr.next());
1056 }
1057 }
1058
1059 public int countByDLF(long dlFolderId) throws SystemException {
1060 String finderClassName = Layout.class.getName();
1061 String finderMethodName = "countByDLF";
1062 String[] finderParams = new String[] { Long.class.getName() };
1063 Object[] finderArgs = new Object[] { new Long(dlFolderId) };
1064 Object result = FinderCache.getResult(finderClassName,
1065 finderMethodName, finderParams, finderArgs, getSessionFactory());
1066
1067 if (result == null) {
1068 Session session = null;
1069
1070 try {
1071 session = openSession();
1072
1073 StringMaker query = new StringMaker();
1074 query.append("SELECT COUNT(*) ");
1075 query.append("FROM com.liferay.portal.model.Layout WHERE ");
1076 query.append("dlFolderId = ?");
1077 query.append(" ");
1078
1079 Query q = session.createQuery(query.toString());
1080 int queryPos = 0;
1081 q.setLong(queryPos++, dlFolderId);
1082
1083 Long count = null;
1084 Iterator itr = q.list().iterator();
1085
1086 if (itr.hasNext()) {
1087 count = (Long)itr.next();
1088 }
1089
1090 if (count == null) {
1091 count = new Long(0);
1092 }
1093
1094 FinderCache.putResult(finderClassName, finderMethodName,
1095 finderParams, finderArgs, count);
1096
1097 return count.intValue();
1098 }
1099 catch (Exception e) {
1100 throw HibernateUtil.processException(e);
1101 }
1102 finally {
1103 closeSession(session);
1104 }
1105 }
1106 else {
1107 return ((Long)result).intValue();
1108 }
1109 }
1110
1111 public int countByG_P(long groupId, boolean privateLayout)
1112 throws SystemException {
1113 String finderClassName = Layout.class.getName();
1114 String finderMethodName = "countByG_P";
1115 String[] finderParams = new String[] {
1116 Long.class.getName(), Boolean.class.getName()
1117 };
1118 Object[] finderArgs = new Object[] {
1119 new Long(groupId), Boolean.valueOf(privateLayout)
1120 };
1121 Object result = FinderCache.getResult(finderClassName,
1122 finderMethodName, finderParams, finderArgs, getSessionFactory());
1123
1124 if (result == null) {
1125 Session session = null;
1126
1127 try {
1128 session = openSession();
1129
1130 StringMaker query = new StringMaker();
1131 query.append("SELECT COUNT(*) ");
1132 query.append("FROM com.liferay.portal.model.Layout WHERE ");
1133 query.append("groupId = ?");
1134 query.append(" AND ");
1135 query.append("privateLayout = ?");
1136 query.append(" ");
1137
1138 Query q = session.createQuery(query.toString());
1139 int queryPos = 0;
1140 q.setLong(queryPos++, groupId);
1141 q.setBoolean(queryPos++, privateLayout);
1142
1143 Long count = null;
1144 Iterator itr = q.list().iterator();
1145
1146 if (itr.hasNext()) {
1147 count = (Long)itr.next();
1148 }
1149
1150 if (count == null) {
1151 count = new Long(0);
1152 }
1153
1154 FinderCache.putResult(finderClassName, finderMethodName,
1155 finderParams, finderArgs, count);
1156
1157 return count.intValue();
1158 }
1159 catch (Exception e) {
1160 throw HibernateUtil.processException(e);
1161 }
1162 finally {
1163 closeSession(session);
1164 }
1165 }
1166 else {
1167 return ((Long)result).intValue();
1168 }
1169 }
1170
1171 public int countByG_P_L(long groupId, boolean privateLayout, long layoutId)
1172 throws SystemException {
1173 String finderClassName = Layout.class.getName();
1174 String finderMethodName = "countByG_P_L";
1175 String[] finderParams = new String[] {
1176 Long.class.getName(), Boolean.class.getName(),
1177 Long.class.getName()
1178 };
1179 Object[] finderArgs = new Object[] {
1180 new Long(groupId), Boolean.valueOf(privateLayout),
1181 new Long(layoutId)
1182 };
1183 Object result = FinderCache.getResult(finderClassName,
1184 finderMethodName, finderParams, finderArgs, getSessionFactory());
1185
1186 if (result == null) {
1187 Session session = null;
1188
1189 try {
1190 session = openSession();
1191
1192 StringMaker query = new StringMaker();
1193 query.append("SELECT COUNT(*) ");
1194 query.append("FROM com.liferay.portal.model.Layout WHERE ");
1195 query.append("groupId = ?");
1196 query.append(" AND ");
1197 query.append("privateLayout = ?");
1198 query.append(" AND ");
1199 query.append("layoutId = ?");
1200 query.append(" ");
1201
1202 Query q = session.createQuery(query.toString());
1203 int queryPos = 0;
1204 q.setLong(queryPos++, groupId);
1205 q.setBoolean(queryPos++, privateLayout);
1206 q.setLong(queryPos++, layoutId);
1207
1208 Long count = null;
1209 Iterator itr = q.list().iterator();
1210
1211 if (itr.hasNext()) {
1212 count = (Long)itr.next();
1213 }
1214
1215 if (count == null) {
1216 count = new Long(0);
1217 }
1218
1219 FinderCache.putResult(finderClassName, finderMethodName,
1220 finderParams, finderArgs, count);
1221
1222 return count.intValue();
1223 }
1224 catch (Exception e) {
1225 throw HibernateUtil.processException(e);
1226 }
1227 finally {
1228 closeSession(session);
1229 }
1230 }
1231 else {
1232 return ((Long)result).intValue();
1233 }
1234 }
1235
1236 public int countByG_P_P(long groupId, boolean privateLayout,
1237 long parentLayoutId) throws SystemException {
1238 String finderClassName = Layout.class.getName();
1239 String finderMethodName = "countByG_P_P";
1240 String[] finderParams = new String[] {
1241 Long.class.getName(), Boolean.class.getName(),
1242 Long.class.getName()
1243 };
1244 Object[] finderArgs = new Object[] {
1245 new Long(groupId), Boolean.valueOf(privateLayout),
1246 new Long(parentLayoutId)
1247 };
1248 Object result = FinderCache.getResult(finderClassName,
1249 finderMethodName, finderParams, finderArgs, getSessionFactory());
1250
1251 if (result == null) {
1252 Session session = null;
1253
1254 try {
1255 session = openSession();
1256
1257 StringMaker query = new StringMaker();
1258 query.append("SELECT COUNT(*) ");
1259 query.append("FROM com.liferay.portal.model.Layout WHERE ");
1260 query.append("groupId = ?");
1261 query.append(" AND ");
1262 query.append("privateLayout = ?");
1263 query.append(" AND ");
1264 query.append("parentLayoutId = ?");
1265 query.append(" ");
1266
1267 Query q = session.createQuery(query.toString());
1268 int queryPos = 0;
1269 q.setLong(queryPos++, groupId);
1270 q.setBoolean(queryPos++, privateLayout);
1271 q.setLong(queryPos++, parentLayoutId);
1272
1273 Long count = null;
1274 Iterator itr = q.list().iterator();
1275
1276 if (itr.hasNext()) {
1277 count = (Long)itr.next();
1278 }
1279
1280 if (count == null) {
1281 count = new Long(0);
1282 }
1283
1284 FinderCache.putResult(finderClassName, finderMethodName,
1285 finderParams, finderArgs, count);
1286
1287 return count.intValue();
1288 }
1289 catch (Exception e) {
1290 throw HibernateUtil.processException(e);
1291 }
1292 finally {
1293 closeSession(session);
1294 }
1295 }
1296 else {
1297 return ((Long)result).intValue();
1298 }
1299 }
1300
1301 public int countByG_P_F(long groupId, boolean privateLayout,
1302 String friendlyURL) throws SystemException {
1303 String finderClassName = Layout.class.getName();
1304 String finderMethodName = "countByG_P_F";
1305 String[] finderParams = new String[] {
1306 Long.class.getName(), Boolean.class.getName(),
1307 String.class.getName()
1308 };
1309 Object[] finderArgs = new Object[] {
1310 new Long(groupId), Boolean.valueOf(privateLayout), friendlyURL
1311 };
1312 Object result = FinderCache.getResult(finderClassName,
1313 finderMethodName, finderParams, finderArgs, getSessionFactory());
1314
1315 if (result == null) {
1316 Session session = null;
1317
1318 try {
1319 session = openSession();
1320
1321 StringMaker query = new StringMaker();
1322 query.append("SELECT COUNT(*) ");
1323 query.append("FROM com.liferay.portal.model.Layout WHERE ");
1324 query.append("groupId = ?");
1325 query.append(" AND ");
1326 query.append("privateLayout = ?");
1327 query.append(" AND ");
1328
1329 if (friendlyURL == null) {
1330 query.append("friendlyURL IS NULL");
1331 }
1332 else {
1333 query.append("friendlyURL = ?");
1334 }
1335
1336 query.append(" ");
1337
1338 Query q = session.createQuery(query.toString());
1339 int queryPos = 0;
1340 q.setLong(queryPos++, groupId);
1341 q.setBoolean(queryPos++, privateLayout);
1342
1343 if (friendlyURL != null) {
1344 q.setString(queryPos++, friendlyURL);
1345 }
1346
1347 Long count = null;
1348 Iterator itr = q.list().iterator();
1349
1350 if (itr.hasNext()) {
1351 count = (Long)itr.next();
1352 }
1353
1354 if (count == null) {
1355 count = new Long(0);
1356 }
1357
1358 FinderCache.putResult(finderClassName, finderMethodName,
1359 finderParams, finderArgs, count);
1360
1361 return count.intValue();
1362 }
1363 catch (Exception e) {
1364 throw HibernateUtil.processException(e);
1365 }
1366 finally {
1367 closeSession(session);
1368 }
1369 }
1370 else {
1371 return ((Long)result).intValue();
1372 }
1373 }
1374
1375 public int countAll() throws SystemException {
1376 String finderClassName = Layout.class.getName();
1377 String finderMethodName = "countAll";
1378 String[] finderParams = new String[] { };
1379 Object[] finderArgs = new Object[] { };
1380 Object result = FinderCache.getResult(finderClassName,
1381 finderMethodName, finderParams, finderArgs, getSessionFactory());
1382
1383 if (result == null) {
1384 Session session = null;
1385
1386 try {
1387 session = openSession();
1388
1389 StringMaker query = new StringMaker();
1390 query.append("SELECT COUNT(*) ");
1391 query.append("FROM com.liferay.portal.model.Layout");
1392
1393 Query q = session.createQuery(query.toString());
1394 Long count = null;
1395 Iterator itr = q.list().iterator();
1396
1397 if (itr.hasNext()) {
1398 count = (Long)itr.next();
1399 }
1400
1401 if (count == null) {
1402 count = new Long(0);
1403 }
1404
1405 FinderCache.putResult(finderClassName, finderMethodName,
1406 finderParams, finderArgs, count);
1407
1408 return count.intValue();
1409 }
1410 catch (Exception e) {
1411 throw HibernateUtil.processException(e);
1412 }
1413 finally {
1414 closeSession(session);
1415 }
1416 }
1417 else {
1418 return ((Long)result).intValue();
1419 }
1420 }
1421
1422 protected void initDao() {
1423 }
1424
1425 private static Log _log = LogFactory.getLog(LayoutPersistenceImpl.class);
1426}