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