Files
Athou_commafeed/src/main/java/com/commafeed/backend/dao/GenericDAO.java

60 lines
1.1 KiB
Java
Raw Normal View History

2013-03-20 20:33:42 +01:00
package com.commafeed.backend.dao;
import io.dropwizard.hibernate.AbstractDAO;
2013-03-20 20:33:42 +01:00
import java.util.Collection;
2013-03-20 20:33:42 +01:00
import org.hibernate.SessionFactory;
2013-06-06 10:57:58 +02:00
2013-03-23 19:46:09 +01:00
import com.commafeed.backend.model.AbstractModel;
import com.mysema.query.jpa.hibernate.HibernateQuery;
2013-03-20 20:33:42 +01:00
public abstract class GenericDAO<T extends AbstractModel> extends AbstractDAO<T> {
2013-03-20 20:33:42 +01:00
2014-08-14 11:40:30 +02:00
protected GenericDAO(SessionFactory sessionFactory) {
super(sessionFactory);
2013-03-20 20:33:42 +01:00
}
protected HibernateQuery newQuery() {
return new HibernateQuery(currentSession());
}
public void saveOrUpdate(T model) {
persist(model);
2013-03-23 19:46:09 +01:00
}
public void saveOrUpdate(Collection<T> models) {
for (T model : models) {
persist(model);
2013-03-30 11:57:11 +01:00
}
2013-03-20 20:33:42 +01:00
}
public void merge(T model) {
currentSession().merge(model);
2013-03-30 11:37:57 +01:00
}
public void merge(Collection<T> models) {
for (T model : models) {
merge(model);
2013-03-30 11:57:11 +01:00
}
2013-03-20 20:33:42 +01:00
}
2013-03-30 11:37:57 +01:00
public T findById(Long id) {
return get(id);
2013-03-20 20:33:42 +01:00
}
public void delete(T object) {
if (object != null) {
currentSession().delete(object);
}
2013-03-20 20:33:42 +01:00
}
public int delete(Collection<T> objects) {
for (T object : objects) {
delete(object);
2013-04-11 20:49:08 +02:00
}
return objects.size();
}
2013-03-20 20:33:42 +01:00
}