KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > persistence > hibernate > core > ContentLocaleDAOHibernate


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.persistence.hibernate.core;
17
18 import com.blandware.atleap.common.util.PartialCollection;
19 import com.blandware.atleap.common.util.QueryInfo;
20 import com.blandware.atleap.model.core.ContentLocale;
21 import com.blandware.atleap.persistence.core.ContentLocaleDAO;
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25
26 /**
27  * <p>Hibernate implementation of ContentLocaleDAO</p>
28  * <p><a HREF="ContentLocaleDAOHibernate.java.htm"><i>View Source</i></a></p>
29  *
30  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
31  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
32  * @version $Revision: 1.27 $ $Date: 2005/08/06 17:13:04 $
33  */

34 public class ContentLocaleDAOHibernate extends BaseDAOHibernate implements ContentLocaleDAO {
35
36     /**
37      * Creates new instance of ContentLocaleDAOHibernate
38      */

39     public ContentLocaleDAOHibernate() {
40     }
41
42     /**
43      * @see com.blandware.atleap.persistence.core.ContentLocaleDAO#createContentLocale(com.blandware.atleap.model.core.ContentLocale)
44      */

45     public void createContentLocale(ContentLocale contentLocale) {
46         getHibernateTemplate().save(contentLocale);
47     }
48
49     /**
50      * @see com.blandware.atleap.persistence.core.ContentLocaleDAO#retrieveContentLocale(java.lang.String)
51      */

52     public ContentLocale retrieveContentLocale(String JavaDoc localeIdentifier) {
53         return (ContentLocale) getHibernateTemplate().get(ContentLocale.class, localeIdentifier);
54     }
55
56     /**
57      * @see com.blandware.atleap.persistence.core.ContentLocaleDAO#updateContentLocale(com.blandware.atleap.model.core.ContentLocale)
58      */

59     public void updateContentLocale(ContentLocale contentLocale) {
60         getHibernateTemplate().update(contentLocale);
61     }
62
63     /**
64      * @see com.blandware.atleap.persistence.core.ContentLocaleDAO#deleteContentLocale(com.blandware.atleap.model.core.ContentLocale)
65      */

66     public void deleteContentLocale(ContentLocale contentLocale) {
67         getHibernateTemplate().delete(contentLocale);
68     }
69
70     /**
71      * @see com.blandware.atleap.persistence.core.ContentLocaleDAO#listContentLocales(com.blandware.atleap.common.util.QueryInfo)
72      */

73     public PartialCollection listContentLocales(QueryInfo queryInfo) {
74         String JavaDoc whereClause = new String JavaDoc();
75         String JavaDoc orderByClause = new String JavaDoc();
76         if ( queryInfo != null ) {
77             whereClause = queryInfo.getWhereClause();
78             orderByClause = queryInfo.getOrderByClause();
79             if ( whereClause != null && whereClause.length() != 0 ) {
80                 whereClause = " where " + whereClause;
81             } else {
82                 whereClause = new String JavaDoc();
83             }
84             if ( orderByClause != null && orderByClause.length() != 0 ) {
85                 orderByClause = " order by " + orderByClause;
86             } else {
87                 orderByClause = " order by l.identifier";
88             }
89         }
90
91         List JavaDoc list = null;
92         Integer JavaDoc total = null;
93         String JavaDoc hqlPart = "from ContentLocale l" + whereClause;
94         if ( queryInfo != null && (queryInfo.getLimit() != null || queryInfo.getOffset() != null) ) {
95             String JavaDoc hqlForTotal = "select count(l.identifier) " + hqlPart;
96             total = (Integer JavaDoc) findUniqueResult(hqlForTotal);
97             if ( total == null ) {
98                 total = new Integer JavaDoc(0);
99             }
100         }
101         // If we don't have any info about the total number of results yet or
102
// we know that there's something that will be found, then fetch data
103
if ( total == null || total.intValue() > 0 ) {
104             String JavaDoc hql = "select l " + hqlPart + orderByClause;
105             list = executeFind(hql, queryInfo);
106             if ( total == null ) {
107                 total = new Integer JavaDoc(list.size());
108             }
109         } else {
110             list = new ArrayList JavaDoc();
111         }
112         return new PartialCollection(list, total);
113     }
114
115     /**
116      * @see com.blandware.atleap.persistence.core.ContentLocaleDAO#findDefaultContentLocale()
117      */

118     public ContentLocale findDefaultContentLocale() {
119         return (ContentLocale) findUniqueResult("from ContentLocale l where l.defaultInstance = 'T'", true, "query.findDefaultContentLocale");
120     }
121
122 }
123
Popular Tags