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