forked from Archives/Athou_commafeed
portable way to unwrap the session (#266)
This commit is contained in:
@@ -6,7 +6,6 @@ import javax.persistence.PersistenceContext;
|
|||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.ejb.EntityManagerImpl;
|
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -72,8 +71,7 @@ public class MetricsBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getCacheStats() {
|
public String getCacheStats() {
|
||||||
EntityManagerImpl impl = (EntityManagerImpl) em.getDelegate();
|
Session session = em.unwrap(Session.class);
|
||||||
Session session = impl.getSession();
|
|
||||||
SessionFactory sessionFactory = session.getSessionFactory();
|
SessionFactory sessionFactory = session.getSessionFactory();
|
||||||
Statistics statistics = sessionFactory.getStatistics();
|
Statistics statistics = sessionFactory.getStatistics();
|
||||||
return statistics.toString();
|
return statistics.toString();
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import javax.persistence.criteria.Root;
|
|||||||
import javax.persistence.metamodel.Attribute;
|
import javax.persistence.metamodel.Attribute;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.ejb.EntityManagerImpl;
|
|
||||||
|
|
||||||
import com.commafeed.backend.model.AbstractModel;
|
import com.commafeed.backend.model.AbstractModel;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
@@ -39,8 +38,7 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
|||||||
|
|
||||||
public void saveOrUpdate(Collection<? extends AbstractModel> models) {
|
public void saveOrUpdate(Collection<? extends AbstractModel> models) {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
EntityManagerImpl impl = (EntityManagerImpl) em.getDelegate();
|
Session session = em.unwrap(Session.class);
|
||||||
Session session = impl.getSession();
|
|
||||||
for (AbstractModel model : models) {
|
for (AbstractModel model : models) {
|
||||||
session.saveOrUpdate(model);
|
session.saveOrUpdate(model);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user