Source Code Cross Referenced for JournalArticleFinderImpl.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portlet » journal » service » persistence » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portlet.journal.service.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003:         *
004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
005:         * of this software and associated documentation files (the "Software"), to deal
006:         * in the Software without restriction, including without limitation the rights
007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008:         * copies of the Software, and to permit persons to whom the Software is
009:         * furnished to do so, subject to the following conditions:
010:         *
011:         * The above copyright notice and this permission notice shall be included in
012:         * all copies or substantial portions of the Software.
013:         *
014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020:         * SOFTWARE.
021:         */package com.liferay.portlet.journal.service.persistence;
022:
023:        import com.liferay.portal.SystemException;
024:        import com.liferay.portal.kernel.util.OrderByComparator;
025:        import com.liferay.portal.kernel.util.StringPool;
026:        import com.liferay.portal.kernel.util.StringUtil;
027:        import com.liferay.portal.kernel.util.Validator;
028:        import com.liferay.portal.spring.hibernate.CustomSQLUtil;
029:        import com.liferay.portal.spring.hibernate.HibernateUtil;
030:        import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
031:        import com.liferay.util.cal.CalendarUtil;
032:        import com.liferay.util.dao.hibernate.QueryPos;
033:        import com.liferay.util.dao.hibernate.QueryUtil;
034:
035:        import java.sql.Timestamp;
036:
037:        import java.util.Date;
038:        import java.util.Iterator;
039:        import java.util.List;
040:
041:        import org.hibernate.Hibernate;
042:        import org.hibernate.SQLQuery;
043:        import org.hibernate.Session;
044:
045:        /**
046:         * <a href="JournalArticleFinderImpl.java.html"><b><i>View Source</i></b></a>
047:         *
048:         * @author Brian Wing Shun Chan
049:         *
050:         */
051:        public class JournalArticleFinderImpl implements  JournalArticleFinder {
052:
053:            public static String COUNT_BY_C_G_A_V_T_D_C_T_S_T_D_A_E_R = JournalArticleFinder.class
054:                    .getName()
055:                    + ".countByC_G_A_V_T_D_C_T_S_T_D_A_E_R";
056:
057:            public static String FIND_BY_EXPIRATION_DATE = JournalArticleFinder.class
058:                    .getName()
059:                    + ".findByExpirationDate";
060:
061:            public static String FIND_BY_REVIEW_DATE = JournalArticleFinder.class
062:                    .getName()
063:                    + ".findByReviewDate";
064:
065:            public static String FIND_BY_C_G_A_V_T_D_C_T_S_T_D_A_E_R = JournalArticleFinder.class
066:                    .getName()
067:                    + ".findByC_G_A_V_T_D_C_T_S_T_D_A_E_R";
068:
069:            public int countByKeywords(long companyId, long groupId,
070:                    String keywords, Double version, String type,
071:                    String structureId, String templateId, Date displayDateGT,
072:                    Date displayDateLT, Boolean approved, Boolean expired,
073:                    Date reviewDate) throws SystemException {
074:
075:                String[] articleIds = null;
076:                String[] titles = null;
077:                String[] descriptions = null;
078:                String[] contents = null;
079:                boolean andOperator = false;
080:
081:                if (Validator.isNotNull(keywords)) {
082:                    articleIds = CustomSQLUtil.keywords(keywords, false);
083:                    titles = CustomSQLUtil.keywords(keywords);
084:                    descriptions = CustomSQLUtil.keywords(keywords, false);
085:                    contents = CustomSQLUtil.keywords(keywords, false);
086:                } else {
087:                    andOperator = true;
088:                }
089:
090:                return countByC_G_A_V_T_D_C_T_S_T_D_A_E_R(companyId, groupId,
091:                        articleIds, version, titles, descriptions, contents,
092:                        type, new String[] { structureId },
093:                        new String[] { templateId }, displayDateGT,
094:                        displayDateLT, approved, expired, reviewDate,
095:                        andOperator);
096:            }
097:
098:            public int countByC_G_A_V_T_D_C_T_S_T_D_A_E_R(long companyId,
099:                    long groupId, String articleId, Double version,
100:                    String title, String description, String content,
101:                    String type, String structureId, String templateId,
102:                    Date displayDateGT, Date displayDateLT, Boolean approved,
103:                    Boolean expired, Date reviewDate, boolean andOperator)
104:                    throws SystemException {
105:
106:                return countByC_G_A_V_T_D_C_T_S_T_D_A_E_R(companyId, groupId,
107:                        articleId, version, title, description, content, type,
108:                        new String[] { structureId },
109:                        new String[] { templateId }, displayDateGT,
110:                        displayDateLT, approved, expired, reviewDate,
111:                        andOperator);
112:            }
113:
114:            public int countByC_G_A_V_T_D_C_T_S_T_D_A_E_R(long companyId,
115:                    long groupId, String articleId, Double version,
116:                    String title, String description, String content,
117:                    String type, String[] structureIds, String[] templateIds,
118:                    Date displayDateGT, Date displayDateLT, Boolean approved,
119:                    Boolean expired, Date reviewDate, boolean andOperator)
120:                    throws SystemException {
121:
122:                return countByC_G_A_V_T_D_C_T_S_T_D_A_E_R(companyId, groupId,
123:                        new String[] { articleId }, version,
124:                        new String[] { title }, new String[] { description },
125:                        new String[] { content }, type, structureIds,
126:                        templateIds, displayDateGT, displayDateLT, approved,
127:                        expired, reviewDate, andOperator);
128:            }
129:
130:            public int countByC_G_A_V_T_D_C_T_S_T_D_A_E_R(long companyId,
131:                    long groupId, String[] articleIds, Double version,
132:                    String[] titles, String[] descriptions, String[] contents,
133:                    String type, String[] structureIds, String[] templateIds,
134:                    Date displayDateGT, Date displayDateLT, Boolean approved,
135:                    Boolean expired, Date reviewDate, boolean andOperator)
136:                    throws SystemException {
137:
138:                articleIds = CustomSQLUtil.keywords(articleIds, false);
139:                titles = CustomSQLUtil.keywords(titles);
140:                descriptions = CustomSQLUtil.keywords(descriptions, false);
141:                contents = CustomSQLUtil.keywords(contents, false);
142:                structureIds = CustomSQLUtil.keywords(structureIds, false);
143:                templateIds = CustomSQLUtil.keywords(templateIds, false);
144:                Timestamp displayDateGT_TS = CalendarUtil
145:                        .getTimestamp(displayDateGT);
146:                Timestamp displayDateLT_TS = CalendarUtil
147:                        .getTimestamp(displayDateLT);
148:                Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);
149:
150:                Session session = null;
151:
152:                try {
153:                    session = HibernateUtil.openSession();
154:
155:                    String sql = CustomSQLUtil
156:                            .get(COUNT_BY_C_G_A_V_T_D_C_T_S_T_D_A_E_R);
157:
158:                    if (groupId <= 0) {
159:                        sql = StringUtil.replace(sql, "(groupId = ?) AND", "");
160:                    }
161:
162:                    sql = CustomSQLUtil.replaceKeywords(sql, "articleId",
163:                            StringPool.LIKE, false, articleIds);
164:
165:                    if (version == null) {
166:                        sql = StringUtil.replace(sql,
167:                                "(version = ?) [$AND_OR_CONNECTOR$]", "");
168:                    }
169:
170:                    sql = CustomSQLUtil.replaceKeywords(sql, "lower(title)",
171:                            StringPool.LIKE, false, titles);
172:                    sql = CustomSQLUtil.replaceKeywords(sql, "description",
173:                            StringPool.LIKE, false, descriptions);
174:                    sql = CustomSQLUtil.replaceKeywords(sql, "content",
175:                            StringPool.LIKE, false, contents);
176:                    sql = CustomSQLUtil.replaceKeywords(sql, "structureId",
177:                            StringPool.EQUAL, false, structureIds);
178:                    sql = CustomSQLUtil.replaceKeywords(sql, "templateId",
179:                            StringPool.EQUAL, false, templateIds);
180:
181:                    if (approved == null) {
182:                        sql = StringUtil.replace(sql, "(approved = ?) AND", "");
183:                    }
184:
185:                    if (expired == null) {
186:                        sql = StringUtil.replace(sql, "(expired = ?) AND", "");
187:                    }
188:
189:                    sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
190:
191:                    SQLQuery q = session.createSQLQuery(sql);
192:
193:                    q.addScalar(HibernateUtil.getCountColumnName(),
194:                            Hibernate.LONG);
195:
196:                    QueryPos qPos = QueryPos.getInstance(q);
197:
198:                    qPos.add(companyId);
199:
200:                    if (groupId > 0) {
201:                        qPos.add(groupId);
202:                    }
203:
204:                    qPos.add(articleIds, 2);
205:
206:                    if (version != null) {
207:                        qPos.add(version);
208:                    }
209:
210:                    qPos.add(titles, 2);
211:                    qPos.add(descriptions, 2);
212:                    qPos.add(contents, 2);
213:                    qPos.add(type);
214:                    qPos.add(type);
215:                    qPos.add(structureIds, 2);
216:                    qPos.add(templateIds, 2);
217:                    qPos.add(displayDateGT_TS);
218:                    qPos.add(displayDateGT_TS);
219:                    qPos.add(displayDateLT_TS);
220:                    qPos.add(displayDateLT_TS);
221:
222:                    if (approved != null) {
223:                        qPos.add(approved);
224:                    }
225:
226:                    if (expired != null) {
227:                        qPos.add(expired);
228:                    }
229:
230:                    qPos.add(reviewDate_TS);
231:                    qPos.add(reviewDate_TS);
232:
233:                    Iterator itr = q.list().iterator();
234:
235:                    if (itr.hasNext()) {
236:                        Long count = (Long) itr.next();
237:
238:                        if (count != null) {
239:                            return count.intValue();
240:                        }
241:                    }
242:
243:                    return 0;
244:                } catch (Exception e) {
245:                    throw new SystemException(e);
246:                } finally {
247:                    HibernateUtil.closeSession(session);
248:                }
249:            }
250:
251:            public List findByExpirationDate(Boolean expired,
252:                    Date expirationDateLT, Date expirationDateGT)
253:                    throws SystemException {
254:
255:                Timestamp expirationDateLT_TS = CalendarUtil
256:                        .getTimestamp(expirationDateLT);
257:                Timestamp expirationDateGT_TS = CalendarUtil
258:                        .getTimestamp(expirationDateGT);
259:
260:                Session session = null;
261:                try {
262:                    session = HibernateUtil.openSession();
263:
264:                    String sql = CustomSQLUtil.get(FIND_BY_EXPIRATION_DATE);
265:
266:                    if (expired == null) {
267:                        sql = StringUtil.replace(sql, "(expired = ?) AND", "");
268:                    }
269:
270:                    SQLQuery q = session.createSQLQuery(sql);
271:
272:                    q.addEntity("JournalArticle", JournalArticleImpl.class);
273:
274:                    QueryPos qPos = QueryPos.getInstance(q);
275:
276:                    if (expired != null) {
277:                        qPos.add(expired);
278:                    }
279:
280:                    qPos.add(expirationDateGT_TS);
281:                    qPos.add(expirationDateLT_TS);
282:
283:                    return q.list();
284:                } catch (Exception e) {
285:                    throw new SystemException(e);
286:                } finally {
287:                    HibernateUtil.closeSession(session);
288:                }
289:            }
290:
291:            public List findByKeywords(long companyId, long groupId,
292:                    String keywords, Double version, String type,
293:                    String structureId, String templateId, Date displayDateGT,
294:                    Date displayDateLT, Boolean approved, Boolean expired,
295:                    Date reviewDate, int begin, int end, OrderByComparator obc)
296:                    throws SystemException {
297:
298:                String[] articleIds = null;
299:                String[] titles = null;
300:                String[] descriptions = null;
301:                String[] contents = null;
302:                boolean andOperator = false;
303:
304:                if (Validator.isNotNull(keywords)) {
305:                    articleIds = CustomSQLUtil.keywords(keywords, false);
306:                    titles = CustomSQLUtil.keywords(keywords);
307:                    descriptions = CustomSQLUtil.keywords(keywords, false);
308:                    contents = CustomSQLUtil.keywords(keywords, false);
309:                } else {
310:                    andOperator = true;
311:                }
312:
313:                return findByC_G_A_V_T_D_C_T_S_T_D_A_E_R(companyId, groupId,
314:                        articleIds, version, titles, descriptions, contents,
315:                        type, new String[] { structureId },
316:                        new String[] { templateId }, displayDateGT,
317:                        displayDateLT, approved, expired, reviewDate,
318:                        andOperator, begin, end, obc);
319:            }
320:
321:            public List findByReviewDate(Date reviewDateLT, Date reviewDateGT)
322:                    throws SystemException {
323:
324:                Timestamp reviewDateLT_TS = CalendarUtil
325:                        .getTimestamp(reviewDateLT);
326:                Timestamp reviewDateGT_TS = CalendarUtil
327:                        .getTimestamp(reviewDateGT);
328:
329:                Session session = null;
330:                try {
331:                    session = HibernateUtil.openSession();
332:
333:                    String sql = CustomSQLUtil.get(FIND_BY_REVIEW_DATE);
334:
335:                    SQLQuery q = session.createSQLQuery(sql);
336:
337:                    q.addEntity("JournalArticle", JournalArticleImpl.class);
338:
339:                    QueryPos qPos = QueryPos.getInstance(q);
340:
341:                    qPos.add(reviewDateGT_TS);
342:                    qPos.add(reviewDateLT_TS);
343:
344:                    return q.list();
345:                } catch (Exception e) {
346:                    throw new SystemException(e);
347:                } finally {
348:                    HibernateUtil.closeSession(session);
349:                }
350:            }
351:
352:            public List findByC_G_A_V_T_D_C_T_S_T_D_A_E_R(long companyId,
353:                    long groupId, String articleId, Double version,
354:                    String title, String description, String content,
355:                    String type, String structureId, String templateId,
356:                    Date displayDateGT, Date displayDateLT, Boolean approved,
357:                    Boolean expired, Date reviewDate, boolean andOperator,
358:                    int begin, int end, OrderByComparator obc)
359:                    throws SystemException {
360:
361:                return findByC_G_A_V_T_D_C_T_S_T_D_A_E_R(companyId, groupId,
362:                        articleId, version, title, description, content, type,
363:                        new String[] { structureId },
364:                        new String[] { templateId }, displayDateGT,
365:                        displayDateLT, approved, expired, reviewDate,
366:                        andOperator, begin, end, obc);
367:            }
368:
369:            public List findByC_G_A_V_T_D_C_T_S_T_D_A_E_R(long companyId,
370:                    long groupId, String articleId, Double version,
371:                    String title, String description, String content,
372:                    String type, String[] structureIds, String[] templateIds,
373:                    Date displayDateGT, Date displayDateLT, Boolean approved,
374:                    Boolean expired, Date reviewDate, boolean andOperator,
375:                    int begin, int end, OrderByComparator obc)
376:                    throws SystemException {
377:
378:                return findByC_G_A_V_T_D_C_T_S_T_D_A_E_R(companyId, groupId,
379:                        new String[] { articleId }, version,
380:                        new String[] { title }, new String[] { description },
381:                        new String[] { content }, type, structureIds,
382:                        templateIds, displayDateGT, displayDateLT, approved,
383:                        expired, reviewDate, andOperator, begin, end, obc);
384:            }
385:
386:            public List findByC_G_A_V_T_D_C_T_S_T_D_A_E_R(long companyId,
387:                    long groupId, String[] articleIds, Double version,
388:                    String[] titles, String[] descriptions, String[] contents,
389:                    String type, String[] structureIds, String[] templateIds,
390:                    Date displayDateGT, Date displayDateLT, Boolean approved,
391:                    Boolean expired, Date reviewDate, boolean andOperator,
392:                    int begin, int end, OrderByComparator obc)
393:                    throws SystemException {
394:
395:                articleIds = CustomSQLUtil.keywords(articleIds, false);
396:                titles = CustomSQLUtil.keywords(titles);
397:                descriptions = CustomSQLUtil.keywords(descriptions, false);
398:                contents = CustomSQLUtil.keywords(contents, false);
399:                structureIds = CustomSQLUtil.keywords(structureIds, false);
400:                templateIds = CustomSQLUtil.keywords(templateIds, false);
401:                Timestamp displayDateGT_TS = CalendarUtil
402:                        .getTimestamp(displayDateGT);
403:                Timestamp displayDateLT_TS = CalendarUtil
404:                        .getTimestamp(displayDateLT);
405:                Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);
406:
407:                Session session = null;
408:
409:                try {
410:                    session = HibernateUtil.openSession();
411:
412:                    String sql = CustomSQLUtil
413:                            .get(FIND_BY_C_G_A_V_T_D_C_T_S_T_D_A_E_R);
414:
415:                    if (groupId <= 0) {
416:                        sql = StringUtil.replace(sql, "(groupId = ?) AND", "");
417:                    }
418:
419:                    sql = CustomSQLUtil.replaceKeywords(sql, "articleId",
420:                            StringPool.LIKE, false, articleIds);
421:
422:                    if (version == null) {
423:                        sql = StringUtil.replace(sql,
424:                                "(version = ?) [$AND_OR_CONNECTOR$]", "");
425:                    }
426:
427:                    sql = CustomSQLUtil.replaceKeywords(sql, "lower(title)",
428:                            StringPool.LIKE, false, titles);
429:                    sql = CustomSQLUtil.replaceKeywords(sql, "description",
430:                            StringPool.LIKE, false, descriptions);
431:                    sql = CustomSQLUtil.replaceKeywords(sql, "content",
432:                            StringPool.LIKE, false, contents);
433:                    sql = CustomSQLUtil.replaceKeywords(sql, "structureId",
434:                            StringPool.EQUAL, false, structureIds);
435:                    sql = CustomSQLUtil.replaceKeywords(sql, "templateId",
436:                            StringPool.EQUAL, false, templateIds);
437:
438:                    if (approved == null) {
439:                        sql = StringUtil.replace(sql, "(approved = ?) AND", "");
440:                    }
441:
442:                    if (expired == null) {
443:                        sql = StringUtil.replace(sql, "(expired = ?) AND", "");
444:                    }
445:
446:                    sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
447:                    sql = CustomSQLUtil.replaceOrderBy(sql, obc);
448:
449:                    SQLQuery q = session.createSQLQuery(sql);
450:
451:                    q.addEntity("JournalArticle", JournalArticleImpl.class);
452:
453:                    QueryPos qPos = QueryPos.getInstance(q);
454:
455:                    qPos.add(companyId);
456:
457:                    if (groupId > 0) {
458:                        qPos.add(groupId);
459:                    }
460:
461:                    qPos.add(articleIds, 2);
462:
463:                    if (version != null) {
464:                        qPos.add(version);
465:                    }
466:
467:                    qPos.add(titles, 2);
468:                    qPos.add(descriptions, 2);
469:                    qPos.add(contents, 2);
470:                    qPos.add(type);
471:                    qPos.add(type);
472:                    qPos.add(structureIds, 2);
473:                    qPos.add(templateIds, 2);
474:                    qPos.add(displayDateGT_TS);
475:                    qPos.add(displayDateGT_TS);
476:                    qPos.add(displayDateLT_TS);
477:                    qPos.add(displayDateLT_TS);
478:
479:                    if (approved != null) {
480:                        qPos.add(approved);
481:                    }
482:
483:                    if (expired != null) {
484:                        qPos.add(expired);
485:                    }
486:
487:                    qPos.add(reviewDate_TS);
488:                    qPos.add(reviewDate_TS);
489:
490:                    return QueryUtil.list(q, HibernateUtil.getDialect(), begin,
491:                            end);
492:                } catch (Exception e) {
493:                    throw new SystemException(e);
494:                } finally {
495:                    HibernateUtil.closeSession(session);
496:                }
497:            }
498:
499:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.