|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| HibernatePersistenceManager.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* HibernatePersistenceManager.java
|
|
| 3 |
* Copyright 2002-2004 Bill2, Inc.
|
|
| 4 |
*
|
|
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 6 |
* you may not use this file except in compliance with the License.
|
|
| 7 |
* You may obtain a copy of the License at
|
|
| 8 |
*
|
|
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 10 |
*
|
|
| 11 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 14 |
* See the License for the specific language governing permissions and
|
|
| 15 |
* limitations under the License.
|
|
| 16 |
*/
|
|
| 17 |
package org.dentaku.services.persistence.hibernate;
|
|
| 18 |
|
|
| 19 |
import net.sf.hibernate.HibernateException;
|
|
| 20 |
import net.sf.hibernate.type.Type;
|
|
| 21 |
import org.dentaku.services.persistence.ModelEntity;
|
|
| 22 |
import org.dentaku.services.persistence.PersistenceException;
|
|
| 23 |
|
|
| 24 |
import java.io.Serializable;
|
|
| 25 |
import java.util.List;
|
|
| 26 |
import java.util.Collection;
|
|
| 27 |
|
|
| 28 |
public class HibernatePersistenceManager extends AbstractPersistenceManager { |
|
| 29 | 0 |
public HibernatePersistenceManager() {
|
| 30 |
|
|
| 31 |
} |
|
| 32 |
|
|
| 33 | 0 |
public void saveOrUpdate(ModelEntity object) throws PersistenceException { |
| 34 | 0 |
try {
|
| 35 | 0 |
if (object.getId() != null) { |
| 36 | 0 |
sessionProvider.getSession().saveOrUpdate(object); |
| 37 |
} else {
|
|
| 38 | 0 |
Long pk = (Long) sessionProvider.getSession().save(object); |
| 39 | 0 |
object.setId(pk); |
| 40 |
} |
|
| 41 |
} catch (HibernateException e) {
|
|
| 42 | 0 |
throw new PersistenceException(e); |
| 43 |
} |
|
| 44 |
} |
|
| 45 |
|
|
| 46 | 0 |
public void delete(ModelEntity object) throws PersistenceException { |
| 47 | 0 |
try {
|
| 48 | 0 |
sessionProvider.getSession().delete(object); |
| 49 |
} catch (HibernateException e) {
|
|
| 50 | 0 |
throw new PersistenceException(e); |
| 51 |
} |
|
| 52 |
} |
|
| 53 |
|
|
| 54 | 0 |
public Object load(Class theClass, Serializable id) throws PersistenceException { |
| 55 | 0 |
try {
|
| 56 | 0 |
return sessionProvider.getSession().load(theClass, id);
|
| 57 |
} catch (HibernateException e) {
|
|
| 58 | 0 |
throw new PersistenceException(e); |
| 59 |
} |
|
| 60 |
} |
|
| 61 |
|
|
| 62 | 0 |
public List find(String query, Object value, Type type) throws PersistenceException { |
| 63 | 0 |
try {
|
| 64 | 0 |
return sessionProvider.getSession().find(query, value, type);
|
| 65 |
} catch (HibernateException e) {
|
|
| 66 | 0 |
throw new PersistenceException(e); |
| 67 |
} |
|
| 68 |
} |
|
| 69 |
|
|
| 70 | 0 |
public List find(String query, Object[] values, Type[] types) throws PersistenceException { |
| 71 | 0 |
try {
|
| 72 | 0 |
return sessionProvider.getSession().find(query, values, types);
|
| 73 |
} catch (HibernateException e) {
|
|
| 74 | 0 |
throw new PersistenceException(e); |
| 75 |
} |
|
| 76 |
} |
|
| 77 |
|
|
| 78 | 0 |
public Collection filter(Collection c, String filter) throws PersistenceException { |
| 79 | 0 |
try {
|
| 80 | 0 |
return sessionProvider.getSession().filter(c, filter);
|
| 81 |
} catch (HibernateException e) {
|
|
| 82 | 0 |
throw new PersistenceException(e); |
| 83 |
} |
|
| 84 |
} |
|
| 85 |
|
|
| 86 | 0 |
public void refresh(Object o) throws PersistenceException { |
| 87 | 0 |
try {
|
| 88 | 0 |
sessionProvider.getSession().refresh(o); |
| 89 |
} catch (HibernateException e) {
|
|
| 90 | 0 |
throw new PersistenceException(e); |
| 91 |
} |
|
| 92 |
} |
|
| 93 |
} |
|
| 94 |
|
|
||||||||||