40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
package de.lusiardi.testprojekt.dao;
|
|
|
|
import de.lusiardi.testprojekt.entity.Counter;
|
|
import org.hibernate.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Repository;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
@Repository
|
|
public class CounterDao {
|
|
|
|
@Autowired
|
|
SessionFactory sessionFactory;
|
|
|
|
@Transactional(readOnly = true)
|
|
public Counter findByPage(String page) {
|
|
Query q = getCurrentSession().getNamedQuery("counter.findByPage");
|
|
q.setString("page", page);
|
|
return (Counter) q.uniqueResult();
|
|
}
|
|
|
|
@Transactional
|
|
public void save(final Counter entity) {
|
|
getCurrentSession().persist(entity);
|
|
}
|
|
|
|
@Transactional
|
|
public void update(final Counter entity) {
|
|
getCurrentSession().merge(entity);
|
|
}
|
|
|
|
@Transactional
|
|
public void delete(final Counter entity) {
|
|
getCurrentSession().delete(entity);
|
|
}
|
|
|
|
private Session getCurrentSession() throws HibernateException {
|
|
return sessionFactory.getCurrentSession();
|
|
}
|
|
} |