Clover coverage report - JFox Service-Oriented Application Framework - 1.0-RC1 Coverage timestamp: 星期五 八月 19 2005 13:21:55 CST FRAMES NO FRAMES |
file stats: | LOC: | 749 |  | Methods: | 38
| NCLOC: | 548 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
HibernateServiceImpl.java | 37.5% | 11.7% | 23.7% | 14% |

1 |  |
     /**
2 |  |
      * @(#)HibernateServiceImpl.java
3 |  |
      *
4 |  |
      * JFoxSOAF, Service-Oriented Application Framework
5 |  |
      *
6 |  |
      * Copyright(c) JFoxSOAF Team
7 |  |
      *
8 |  |
      * Licensed under the GNU LGPL, Version 2.1 (the "License");
9 |  |
      * you may not use this file except in compliance with the License.
10 |  |
      * You may obtain a copy of the License at
11 |  |
      *
12 |  |
      * http://www.gnu.org/copyleft/lesser.html
13 |  |
      *
14 |  |
      * Unless required by applicable law or agreed to in writing, software
15 |  |
      * distributed under the License is distributed on an "AS IS" BASIS,
16 |  |
      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 |  |
      * See the License for the specific language governing permissions and
18 |  |
      * limitations under the License.
19 |  |
      *
20 |  |
      * For more information, please visit:
21 |  |
      * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
22 |  |
      * http://www.huihoo.org/jfox/jfoxsoaf
23 |  |
      */
24 |  |
25 |  |
     package org.huihoo.jfox.soaf.services.persistence;
26 |  |
27 |  |
     import java.io.Serializable;
28 |  |
     import java.util.Iterator;
29 |  |
     import java.util.List;
30 |  |
31 |  |
     import net.sf.hibernate.HibernateException;
32 |  |
     import net.sf.hibernate.LockMode;
33 |  |
     import net.sf.hibernate.Session;
34 |  |
     import net.sf.hibernate.SessionFactory;
35 |  |
     import net.sf.hibernate.Transaction;
36 |  |
     import net.sf.hibernate.cfg.Configuration;
37 |  |
     import net.sf.hibernate.type.Type;
38 |  |
39 |  |
     import org.apache.commons.logging.Log;
40 |  |
     import org.apache.commons.logging.LogFactory;
41 |  |
     import org.huihoo.jfox.soaf.exception.DAOException;
42 |  |
     import org.huihoo.jfox.soaf.util.resource.ResourceHelper;
43 |  |
     import org.picocontainer.Startable;
44 |  |
45 |  |
     /**
46 |  |
      * <p>
47 |  |
      * Hibernate persistence service implementation.
48 |  |
      * </p>
49 |  |
      *
50 |  |
      * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
51 |  |
      * @version $Revision: 1.10 $ $Date: 2005/05/22 06:50:29 $
52 |  |
      * @version Revision: 1.0
53 |  |
      */
54 |  |
55 |  |
     public class HibernateServiceImpl implements HibernateService, Startable {
56 |  |
57 |  |
         private static String HIBERNATE_CONFIG = "hibernate.cfg.xml";
58 |  |
59 |  |
         private final Log logger = LogFactory.getLog(getClass());
60 |  |
61 |  |
         private Session session = null;
62 |  |
63 |  |
         private Configuration config;
64 |  |
65 |  |
         private Transaction transaction = null;
66 |  |
67 |  |
         private SessionFactory sessionFactory = null;
68 |  |
69 |  |
         /**
70 |  |
          * Default constructor.
71 |  |
          */
72 | 4 |
         public HibernateServiceImpl() throws HibernateException {
73 |  |
         }
74 |  |
75 |  |
         /**
76 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#openSession()
77 |  |
          */
78 | 5 |
         public Session openSession() throws HibernateException {
79 | 5 |
             if (session == null) {
80 | 5 |
                 session = getSessionFactory().openSession();
81 | 5 |
                 transaction = session.beginTransaction();
82 |  |
             }
83 | 0 |
             return session;
84 |  |
         }
85 |  |
86 |  |
         /**
87 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#getConfiguration()
88 |  |
          */
89 | 0 |
         public Configuration getConfiguration() throws HibernateException {
90 | 0 |
             return config;
91 |  |
         }
92 |  |
93 |  |
         /**
94 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#getSessionFactory()
95 |  |
          */
96 | 5 |
         public synchronized SessionFactory getSessionFactory()
97 |  |
                 throws HibernateException {
98 | 5 |
             if (sessionFactory == null) {
99 | 1 |
                 try {
100 | 1 |
                     sessionFactory = config.buildSessionFactory();
101 |  |
                 } catch (Throwable t) {
102 | 0 |
                     if (logger.isInfoEnabled()) {
103 | 0 |
                         logger.info("Could not configure hibernate ");
104 |  |
                     }
105 | 0 |
                     t.printStackTrace();
106 |  |
                 }
107 |  |
             }
108 | 5 |
             return sessionFactory;
109 |  |
         }
110 |  |
111 |  |
         /**
112 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#closeSession()
113 |  |
          */
114 | 5 |
         public void closeSession() throws HibernateException {
115 | 5 |
             if (session != null) {
116 | 5 |
                 if (transaction != null && !transaction.wasCommitted()
117 |  |
                         && !transaction.wasRolledBack()) {
118 | 0 |
                     transaction.commit();
119 | 0 |
                     transaction = null;
120 |  |
                 }
121 | 5 |
                 session.close();
122 | 5 |
                 session = null;
123 |  |
             }
124 |  |
         }
125 |  |
126 |  |
         /**
127 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#commit()
128 |  |
          */
129 | 0 |
         public void commit() throws HibernateException {
130 | 0 |
             if (session != null && transaction != null
131 |  |
                     && !transaction.wasCommitted() && !transaction.wasRolledBack()) {
132 | 0 |
                 transaction.commit();
133 | 0 |
                 transaction = session.beginTransaction();
134 |  |
             }
135 |  |
         }
136 |  |
137 |  |
         /**
138 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#reset()
139 |  |
          */
140 | 0 |
         public void reset() {
141 | 0 |
             try {
142 | 0 |
                 rollback();
143 | 0 |
                 if (session != null) {
144 | 0 |
                     session.clear();
145 | 0 |
                     session.close();
146 |  |
                 }
147 |  |
             } catch (HibernateException ex) {
148 |  |
                 // we do nothing here, because this shall be called if something
149 |  |
                 // went wrong.
150 |  |
             } finally {
151 | 0 |
                 session = null;
152 | 0 |
                 transaction = null;
153 |  |
             }
154 |  |
155 |  |
         }
156 |  |
157 |  |
         /**
158 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#rollback()
159 |  |
          */
160 | 5 |
         public void rollback() throws HibernateException {
161 | 5 |
             if (session != null && transaction != null
162 |  |
                     && !transaction.wasCommitted() && !transaction.wasRolledBack()) {
163 | 0 |
                 transaction.rollback();
164 | 0 |
                 transaction = session.beginTransaction();
165 |  |
             }
166 |  |
         }
167 |  |
168 |  |
         /**
169 |  |
          * @see org.picocontainer.Startable#start()
170 |  |
          */
171 | 4 |
         public void start() {
172 | 4 |
             config = new Configuration();
173 | 4 |
             try {
174 | 4 |
                 config.configure(ResourceHelper.getResourceURL(HIBERNATE_CONFIG));
175 |  |
             } catch (Exception e) {
176 | 0 |
                 logger.error("Failed to start hibernate service " + e.getMessage());
177 |  |
             }
178 | 4 |
             logger.info("Start hibernate service successful.");
179 |  |
         }
180 |  |
181 |  |
         /**
182 |  |
          * @see org.picocontainer.Startable#stop()
183 |  |
          */
184 | 0 |
         public void stop() {
185 |  |
         }
186 |  |
187 |  |
         /**
188 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#contains(Object)
189 |  |
          */
190 | 0 |
         public boolean contains(Object object) throws HibernateException,
191 |  |
                 DAOException {
192 | 0 |
             boolean isContains = false;
193 | 0 |
             Session session;
194 | 0 |
             try {
195 | 0 |
                 session = openSession();
196 | 0 |
                 session.contains(object);
197 | 0 |
                 commit();
198 |  |
             } catch (Exception e) {
199 | 0 |
                 rollback();
200 | 0 |
                 throw new DAOException(e);
201 |  |
             } finally {
202 | 0 |
                 session = null;
203 | 0 |
                 closeSession();
204 |  |
             }
205 | 0 |
             return isContains;
206 |  |
         }
207 |  |
208 |  |
         /**
209 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#delete(Object)
210 |  |
          */
211 | 1 |
         public void delete(Object object) throws HibernateException, DAOException {
212 | 1 |
             Session session;
213 | 1 |
             try {
214 | 1 |
                 session = openSession();
215 | 0 |
                 session.delete(object);
216 | 0 |
                 commit();
217 |  |
             } catch (Exception e) {
218 | 1 |
                 rollback();
219 | 1 |
                 throw new DAOException(e);
220 |  |
             } finally {
221 | 1 |
                 session = null;
222 | 1 |
                 closeSession();
223 |  |
             }
224 |  |
         }
225 |  |
226 |  |
         /**
227 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#delete(Object, LockMode)
228 |  |
          */
229 | 0 |
         public void delete(Object object, LockMode lockMode)
230 |  |
                 throws HibernateException, DAOException {
231 | 0 |
             Session session;
232 | 0 |
             try {
233 | 0 |
                 session = openSession();
234 | 0 |
                 session.lock(object, lockMode);
235 | 0 |
                 session.delete(object);
236 | 0 |
                 commit();
237 |  |
             } catch (Exception e) {
238 | 0 |
                 rollback();
239 | 0 |
                 throw new HibernateException(e);
240 |  |
             } finally {
241 | 0 |
                 session = null;
242 | 0 |
                 closeSession();
243 |  |
             }
244 |  |
         }
245 |  |
246 |  |
         /**
247 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#delete(String)
248 |  |
          */
249 | 0 |
         public int delete(String query) throws HibernateException, DAOException {
250 | 0 |
             int instancesCount = 0;
251 | 0 |
             Session session;
252 | 0 |
             try {
253 | 0 |
                 session = openSession();
254 | 0 |
                 instancesCount = session.delete(query);
255 | 0 |
                 commit();
256 |  |
             } catch (Exception e) {
257 | 0 |
                 rollback();
258 | 0 |
                 throw new DAOException(e);
259 |  |
             } finally {
260 | 0 |
                 session = null;
261 | 0 |
                 closeSession();
262 |  |
             }
263 | 0 |
             return instancesCount;
264 |  |
         }
265 |  |
266 |  |
         /**
267 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#delete(String, Object, Type)
268 |  |
          */
269 | 0 |
         public int delete(String query, Object value, Type type)
270 |  |
                 throws HibernateException, DAOException {
271 | 0 |
             int instancesCount = 0;
272 | 0 |
             Session session;
273 | 0 |
             try {
274 | 0 |
                 session = openSession();
275 | 0 |
                 instancesCount = session.delete(query, value, type);
276 | 0 |
                 commit();
277 |  |
             } catch (Exception e) {
278 | 0 |
                 rollback();
279 | 0 |
                 throw new DAOException(e);
280 |  |
             } finally {
281 | 0 |
                 session = null;
282 | 0 |
                 closeSession();
283 |  |
             }
284 | 0 |
             return instancesCount;
285 |  |
         }
286 |  |
287 |  |
         /**
288 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#delete(String, Object[], Type[])
289 |  |
          */
290 | 0 |
         public int delete(String query, Object[] values, Type[] types)
291 |  |
                 throws HibernateException, DAOException {
292 | 0 |
             int instancesCount = 0;
293 | 0 |
             Session session;
294 | 0 |
             try {
295 | 0 |
                 session = openSession();
296 | 0 |
                 instancesCount = session.delete(query, values, types);
297 | 0 |
                 commit();
298 |  |
             } catch (Exception e) {
299 | 0 |
                 rollback();
300 | 0 |
                 throw new DAOException(e);
301 |  |
             } finally {
302 | 0 |
                 session = null;
303 | 0 |
                 closeSession();
304 |  |
             }
305 | 0 |
             return instancesCount;
306 |  |
         }
307 |  |
308 |  |
         /**
309 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#evict(Object)
310 |  |
          */
311 | 0 |
         public void evict(Object object) throws HibernateException, DAOException {
312 | 0 |
             Session session;
313 | 0 |
             try {
314 | 0 |
                 session = openSession();
315 | 0 |
                 session.evict(object);
316 | 0 |
                 commit();
317 |  |
             } catch (Exception e) {
318 | 0 |
                 rollback();
319 | 0 |
                 throw new DAOException(e);
320 |  |
             } finally {
321 | 0 |
                 session = null;
322 | 0 |
                 closeSession();
323 |  |
             }
324 |  |
         }
325 |  |
326 |  |
         /**
327 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#find(String)
328 |  |
          */
329 | 0 |
         public List find(String query) throws HibernateException, DAOException {
330 | 0 |
             List list;
331 | 0 |
             Session session;
332 | 0 |
             try {
333 | 0 |
                 session = openSession();
334 | 0 |
                 list = session.find(query);
335 | 0 |
                 commit();
336 |  |
             } catch (Exception e) {
337 | 0 |
                 rollback();
338 | 0 |
                 throw new DAOException(e);
339 |  |
             } finally {
340 | 0 |
                 session = null;
341 | 0 |
                 closeSession();
342 |  |
             }
343 | 0 |
             return list;
344 |  |
         }
345 |  |
346 |  |
         /**
347 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#find(String, Object, Type)
348 |  |
          */
349 | 0 |
         public List find(String query, Object value, Type type)
350 |  |
                 throws HibernateException, DAOException {
351 | 0 |
             List list;
352 | 0 |
             Session session;
353 | 0 |
             try {
354 | 0 |
                 session = openSession();
355 | 0 |
                 list = session.find(query, value, type);
356 | 0 |
                 commit();
357 |  |
             } catch (Exception e) {
358 | 0 |
                 rollback();
359 | 0 |
                 throw new DAOException(e);
360 |  |
             } finally {
361 | 0 |
                 session = null;
362 | 0 |
                 closeSession();
363 |  |
             }
364 | 0 |
             return list;
365 |  |
         }
366 |  |
367 |  |
         /**
368 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#find(String, Object[], Type[])
369 |  |
          */
370 | 0 |
         public List find(String query, Object[] values, Type[] types)
371 |  |
                 throws HibernateException, DAOException {
372 | 0 |
             List list;
373 | 0 |
             Session session;
374 | 0 |
             try {
375 | 0 |
                 session = openSession();
376 | 0 |
                 list = session.find(query, values, types);
377 | 0 |
                 commit();
378 |  |
             } catch (Exception e) {
379 | 0 |
                 rollback();
380 | 0 |
                 throw new DAOException(e);
381 |  |
             } finally {
382 | 0 |
                 session = null;
383 | 0 |
                 closeSession();
384 |  |
             }
385 | 0 |
             return list;
386 |  |
         }
387 |  |
388 |  |
         /**
389 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#get(Class, Serializable)
390 |  |
          */
391 | 3 |
         public Object get(Class clazz, final Serializable id) throws HibernateException,
392 |  |
                 DAOException {
393 | 3 |
             Object object;
394 | 3 |
             Session session;
395 | 3 |
             try {
396 | 3 |
                 session = openSession();
397 | 0 |
                 object = session.get(clazz, id);
398 | 0 |
                 commit();
399 |  |
             } catch (Exception e) {
400 | 3 |
                 rollback();
401 | 3 |
                 throw new DAOException(e);
402 |  |
             } finally {
403 | 3 |
                 session = null;
404 | 3 |
                 closeSession();
405 |  |
             }
406 | 0 |
             return object;
407 |  |
         }
408 |  |
409 |  |
         /**
410 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#get(Class, Serializable, LockMode)
411 |  |
          */
412 | 0 |
         public Object get(Class clazz, final Serializable id, LockMode lockMode)
413 |  |
                 throws HibernateException, DAOException {
414 | 0 |
             Object object;
415 | 0 |
             Session session;
416 | 0 |
             try {
417 | 0 |
                 session = openSession();
418 | 0 |
                 object = session.get(clazz, id, lockMode);
419 | 0 |
                 commit();
420 |  |
             } catch (Exception e) {
421 | 0 |
                 rollback();
422 | 0 |
                 throw new DAOException(e);
423 |  |
             } finally {
424 | 0 |
                 session = null;
425 | 0 |
                 closeSession();
426 |  |
             }
427 | 0 |
             return object;
428 |  |
         }
429 |  |
430 |  |
         /**
431 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#iterate(String)
432 |  |
          */
433 | 0 |
         public Iterator iterate(String query) throws HibernateException,
434 |  |
                 DAOException {
435 | 0 |
             Iterator iter;
436 | 0 |
             Session session;
437 | 0 |
             try {
438 | 0 |
                 session = openSession();
439 | 0 |
                 iter = session.iterate(query);
440 | 0 |
                 commit();
441 |  |
             } catch (Exception e) {
442 | 0 |
                 rollback();
443 | 0 |
                 throw new DAOException(e);
444 |  |
             } finally {
445 | 0 |
                 session = null;
446 | 0 |
                 closeSession();
447 |  |
             }
448 | 0 |
             return iter;
449 |  |
         }
450 |  |
451 |  |
         /**
452 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#iterate(String, Object, Type)
453 |  |
          */
454 | 0 |
         public Iterator iterate(String query, Object value, Type type)
455 |  |
                 throws HibernateException, DAOException {
456 | 0 |
             Iterator iter;
457 | 0 |
             Session session;
458 | 0 |
             try {
459 | 0 |
                 session = openSession();
460 | 0 |
                 iter = session.iterate(query, value, type);
461 | 0 |
                 commit();
462 |  |
             } catch (Exception e) {
463 | 0 |
                 rollback();
464 | 0 |
                 throw new DAOException(e);
465 |  |
             } finally {
466 | 0 |
                 session = null;
467 | 0 |
                 closeSession();
468 |  |
             }
469 | 0 |
             return iter;
470 |  |
         }
471 |  |
472 |  |
         /**
473 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#iterate(String, Object[], Type[])
474 |  |
          */
475 | 0 |
         public Iterator iterate(String query, Object[] values, Type[] types)
476 |  |
                 throws HibernateException, DAOException {
477 | 0 |
             Iterator iter;
478 | 0 |
             Session session;
479 | 0 |
             try {
480 | 0 |
                 session = openSession();
481 | 0 |
                 iter = session.iterate(query, values, types);
482 | 0 |
                 commit();
483 |  |
             } catch (Exception e) {
484 | 0 |
                 rollback();
485 | 0 |
                 throw new DAOException(e);
486 |  |
             } finally {
487 | 0 |
                 session = null;
488 | 0 |
                 closeSession();
489 |  |
             }
490 | 0 |
             return iter;
491 |  |
         }
492 |  |
493 |  |
         /**
494 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#load(Class, Serializable)
495 |  |
          */
496 | 0 |
         public Object load(Class clazz, final Serializable id) throws HibernateException,
497 |  |
                 DAOException {
498 | 0 |
             Object object;
499 | 0 |
             Session session;
500 | 0 |
             try {
501 | 0 |
                 session = openSession();
502 | 0 |
                 object = session.load(clazz, id);
503 | 0 |
                 commit();
504 |  |
             } catch (Exception e) {
505 | 0 |
                 rollback();
506 | 0 |
                 throw new DAOException(e);
507 |  |
             } finally {
508 | 0 |
                 session = null;
509 | 0 |
                 closeSession();
510 |  |
             }
511 | 0 |
             return object;
512 |  |
         }
513 |  |
514 |  |
         /**
515 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#load(Class, Serializable, LockMode)
516 |  |
          */
517 | 0 |
         public Object load(Class clazz, final Serializable id, LockMode lockMode)
518 |  |
                 throws HibernateException, DAOException {
519 | 0 |
             Object object;
520 | 0 |
             Session session;
521 | 0 |
             try {
522 | 0 |
                 session = openSession();
523 | 0 |
                 object = session.load(clazz, id, lockMode);
524 | 0 |
                 commit();
525 |  |
             } catch (Exception e) {
526 | 0 |
                 rollback();
527 | 0 |
                 throw new DAOException(e);
528 |  |
             } finally {
529 | 0 |
                 session = null;
530 | 0 |
                 closeSession();
531 |  |
             }
532 | 0 |
             return object;
533 |  |
         }
534 |  |
535 |  |
         /**
536 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#load(Object, Serializable)
537 |  |
          */
538 | 0 |
         public void load(Object object, final Serializable id) throws HibernateException,
539 |  |
                 DAOException {
540 | 0 |
             Session session;
541 | 0 |
             try {
542 | 0 |
                 session = openSession();
543 | 0 |
                 session.load(object, id);
544 | 0 |
                 commit();
545 |  |
             } catch (Exception e) {
546 | 0 |
                 rollback();
547 | 0 |
                 throw new DAOException(e);
548 |  |
             } finally {
549 | 0 |
                 session = null;
550 | 0 |
                 closeSession();
551 |  |
             }
552 |  |
         }
553 |  |
554 |  |
         /**
555 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#load(Class, Serializable, LockMode)
556 |  |
          */
557 | 0 |
         public void lock(Object object, LockMode lockMode)
558 |  |
                 throws HibernateException, DAOException {
559 | 0 |
             Session session;
560 | 0 |
             try {
561 | 0 |
                 session = openSession();
562 | 0 |
                 session.lock(object, lockMode);
563 | 0 |
                 commit();
564 |  |
             } catch (Exception e) {
565 | 0 |
                 rollback();
566 | 0 |
                 throw new DAOException(e);
567 |  |
             } finally {
568 | 0 |
                 session = null;
569 | 0 |
                 closeSession();
570 |  |
             }
571 |  |
         }
572 |  |
573 |  |
         /**
574 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#update(Object)
575 |  |
          */
576 | 0 |
         public void update(Object object) throws HibernateException, DAOException {
577 | 0 |
             Session session;
578 | 0 |
             try {
579 | 0 |
                 session = openSession();
580 | 0 |
                 session.update(object);
581 | 0 |
                 commit();
582 |  |
             } catch (Exception e) {
583 | 0 |
                 rollback();
584 | 0 |
                 throw new DAOException(e);
585 |  |
             } finally {
586 | 0 |
                 session = null;
587 | 0 |
                 closeSession();
588 |  |
             }
589 |  |
         }
590 |  |
591 |  |
         /**
592 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#update(Object, Serializable)
593 |  |
          */
594 | 0 |
         public void update(Object object, final Serializable id)
595 |  |
                 throws HibernateException, DAOException {
596 | 0 |
             Session session;
597 | 0 |
             try {
598 | 0 |
                 session = openSession();
599 | 0 |
                 session.update(object, id);
600 | 0 |
                 commit();
601 |  |
             } catch (Exception e) {
602 | 0 |
                 rollback();
603 | 0 |
                 throw new DAOException(e);
604 |  |
             } finally {
605 | 0 |
                 session = null;
606 | 0 |
                 closeSession();
607 |  |
             }
608 |  |
         }
609 |  |
610 |  |
         /**
611 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#saveOrUpdate(Object)
612 |  |
          */
613 | 0 |
         public Object saveOrUpdateCopy(Object object) throws HibernateException,
614 |  |
                 DAOException {
615 | 0 |
             Session session;
616 | 0 |
             Object obj;
617 | 0 |
             try {
618 | 0 |
                 session = openSession();
619 | 0 |
                 obj = session.saveOrUpdateCopy(object);
620 | 0 |
                 commit();
621 |  |
             } catch (Exception e) {
622 | 0 |
                 rollback();
623 | 0 |
                 throw new DAOException(e);
624 |  |
             } finally {
625 | 0 |
                 session = null;
626 | 0 |
                 closeSession();
627 |  |
             }
628 | 0 |
             return obj;
629 |  |
         }
630 |  |
631 |  |
         /**
632 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#saveOrUpdateCopy(Object, Serializable)
633 |  |
          */
634 | 0 |
         public Object saveOrUpdateCopy(Object object, final Serializable id)
635 |  |
                 throws HibernateException, DAOException {
636 | 0 |
             Session session;
637 | 0 |
             Object obj;
638 | 0 |
             try {
639 | 0 |
                 session = openSession();
640 | 0 |
                 obj = session.saveOrUpdateCopy(object, id);
641 | 0 |
                 commit();
642 |  |
             } catch (Exception e) {
643 | 0 |
                 rollback();
644 | 0 |
                 throw new DAOException(e);
645 |  |
             } finally {
646 | 0 |
                 session = null;
647 | 0 |
                 closeSession();
648 |  |
             }
649 | 0 |
             return obj;
650 |  |
         }
651 |  |
652 |  |
         /**
653 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#refresh(Object)
654 |  |
          */
655 | 0 |
         public void refresh(Object object) throws HibernateException, DAOException {
656 | 0 |
             Session session;
657 | 0 |
             try {
658 | 0 |
                 session = openSession();
659 | 0 |
                 session.refresh(object);
660 | 0 |
                 commit();
661 |  |
             } catch (Exception e) {
662 | 0 |
                 rollback();
663 | 0 |
                 throw new DAOException(e);
664 |  |
             } finally {
665 | 0 |
                 session = null;
666 | 0 |
                 closeSession();
667 |  |
             }
668 |  |
         }
669 |  |
670 |  |
         /**
671 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#refresh(Object, LockMode)
672 |  |
          */
673 | 0 |
         public void refresh(Object object, LockMode lockMode)
674 |  |
                 throws HibernateException, DAOException {
675 | 0 |
             Session session;
676 | 0 |
             try {
677 | 0 |
                 session = openSession();
678 | 0 |
                 session.refresh(object, lockMode);
679 | 0 |
                 commit();
680 |  |
             } catch (Exception e) {
681 | 0 |
                 rollback();
682 | 0 |
                 throw new DAOException(e);
683 |  |
             } finally {
684 | 0 |
                 session = null;
685 | 0 |
                 closeSession();
686 |  |
             }
687 |  |
         }
688 |  |
689 |  |
         /**
690 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#save(Object)
691 |  |
          */
692 | 0 |
         public Serializable save(Object object) throws HibernateException,
693 |  |
                 DAOException {
694 | 0 |
             Serializable seriaObj;
695 | 0 |
             Session session;
696 | 0 |
             try {
697 | 0 |
                 session = openSession();
698 | 0 |
                 seriaObj = session.save(object);
699 | 0 |
                 commit();
700 |  |
             } catch (Exception e) {
701 | 0 |
                 rollback();
702 | 0 |
                 throw new DAOException(e);
703 |  |
             } finally {
704 | 0 |
                 session = null;
705 | 0 |
                 closeSession();
706 |  |
             }
707 | 0 |
             return seriaObj;
708 |  |
         }
709 |  |
710 |  |
         /**
711 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#save(Object, Serializable)
712 |  |
          */
713 | 0 |
         public void save(Object object, final Serializable id) throws HibernateException,
714 |  |
                 DAOException {
715 | 0 |
             Session session;
716 | 0 |
             try {
717 | 0 |
                 session = openSession();
718 | 0 |
                 session.save(object, id);
719 | 0 |
                 commit();
720 |  |
             } catch (Exception e) {
721 | 0 |
                 rollback();
722 | 0 |
                 throw new DAOException(e);
723 |  |
             } finally {
724 | 0 |
                 System.out.println("save close session");
725 | 0 |
                 session = null;
726 | 0 |
                 closeSession();
727 |  |
             }
728 |  |
         }
729 |  |
730 |  |
         /**
731 |  |
          * @see org.huihoo.jfox.soaf.services.persistence.HibernateService#saveOrUpdate(Object)
732 |  |
          */
733 | 1 |
         public void saveOrUpdate(Object object) throws HibernateException,
734 |  |
                 DAOException {
735 | 1 |
             Session session;
736 | 1 |
             try {
737 | 1 |
                 session = openSession();
738 | 0 |
                 session.saveOrUpdate(object);
739 | 0 |
                 commit();
740 |  |
             } catch (Exception e) {
741 | 1 |
                 rollback();
742 | 1 |
                 throw new DAOException(e);
743 |  |
             } finally {
744 | 1 |
                 session = null;
745 | 1 |
                 closeSession();
746 |  |
             }
747 |  |
         }
748 |  |
749 |  |
     }