diff --git a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java index 0510847..bef44fe 100644 --- a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java +++ b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java @@ -2,35 +2,46 @@ package de.ctdo.bunti.dao; import java.util.List; -import de.ctdo.bunti.model.*; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; +import de.ctdo.bunti.model.BuntiDMXDevice; +import de.ctdo.bunti.model.BuntiDevice; +import org.springframework.stereotype.Repository; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; -public final class BuntiDevicesDAOImpl extends HibernateDaoSupport implements BuntiDevicesDAO { +@Repository +public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO { + private EntityManager em; + + @PersistenceContext + public void setEntityManager(EntityManager entityManager) { + this.em = entityManager; + } @Override public List getAllDMXDevices() { - return getHibernateTemplate().loadAll(BuntiDMXDevice.class); + //TODO: hier noch nur die DMX Geräte suchen! + return em.createQuery("SELECT d FROM BuntiDevice d").getResultList(); } @Override public List getAllDevices() { - return getHibernateTemplate().loadAll(BuntiDevice.class); + return em.createQuery("SELECT d FROM BuntiDevice d").getResultList(); } @Override public BuntiDevice getDeviceById(int deviceId) { - return getHibernateTemplate().get(BuntiDevice.class,deviceId); + return em.find(BuntiDevice.class, deviceId); } @Override public void addDevice(BuntiDevice device) { - getHibernateTemplate().save(device); + em.persist(device); } @Override public void removeDevice(int deviceId) { - getHibernateTemplate().delete(getDeviceById(deviceId)); + em.remove(getDeviceById(deviceId)); } } diff --git a/src/main/java/de/ctdo/bunti/dao/RoomsDAO.java b/src/main/java/de/ctdo/bunti/dao/RoomsDAO.java index ecb686d..e84754a 100644 --- a/src/main/java/de/ctdo/bunti/dao/RoomsDAO.java +++ b/src/main/java/de/ctdo/bunti/dao/RoomsDAO.java @@ -7,6 +7,6 @@ import java.util.List; public interface RoomsDAO { List getRooms(); Room getRoom(int id); - Room addRoom(Room room); + void addRoom(Room room); void removeRoom(int id); } diff --git a/src/main/java/de/ctdo/bunti/dao/RoomsDAOImpl.java b/src/main/java/de/ctdo/bunti/dao/RoomsDAOImpl.java index d82e74b..15415d0 100644 --- a/src/main/java/de/ctdo/bunti/dao/RoomsDAOImpl.java +++ b/src/main/java/de/ctdo/bunti/dao/RoomsDAOImpl.java @@ -1,29 +1,38 @@ package de.ctdo.bunti.dao; import de.ctdo.bunti.model.Room; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; +import org.springframework.stereotype.Repository; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; import java.util.List; -public final class RoomsDAOImpl extends HibernateDaoSupport implements RoomsDAO { +@Repository +public final class RoomsDAOImpl implements RoomsDAO { + private EntityManager em; + + @PersistenceContext + public void setEntityManager(EntityManager entityManager) { + this.em = entityManager; + } @Override public List getRooms() { - return getHibernateTemplate().loadAll(Room.class); + return em.createQuery("SELECT r FROM Room r").getResultList(); } @Override public Room getRoom(int id) { - return getHibernateTemplate().get(Room.class, id); + return em.find(Room.class, id); } @Override - public Room addRoom(Room room) { - getHibernateTemplate().save(room); - return room; + public void addRoom(Room room) { + em.persist(room); } @Override public void removeRoom(int id) { - getHibernateTemplate().delete(getRoom(id)); + em.remove(getRoom(id)); } } diff --git a/src/main/resources/META-INF/spring/hibernate-beans.xml b/src/main/resources/META-INF/spring/hibernate-beans.xml index ccc9010..b8f1cad 100755 --- a/src/main/resources/META-INF/spring/hibernate-beans.xml +++ b/src/main/resources/META-INF/spring/hibernate-beans.xml @@ -1,43 +1,47 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xmlns:tx="http://www.springframework.org/schema/tx" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/jdbc + http://www.springframework.org/schema/jdbc/spring-jdbc.xsd + http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx/spring-tx-3.1.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.1.xsd"> - - - - - org.hibernate.dialect.HSQLDialect - true - - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + + - + + + diff --git a/src/test/resources/de/ctdo/bunti/hibernate-test-context.xml b/src/test/resources/de/ctdo/bunti/hibernate-test-context.xml index 3def185..40fcd05 100644 --- a/src/test/resources/de/ctdo/bunti/hibernate-test-context.xml +++ b/src/test/resources/de/ctdo/bunti/hibernate-test-context.xml @@ -1,39 +1,45 @@ + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/jdbc + http://www.springframework.org/schema/jdbc/spring-jdbc.xsd + http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx/spring-tx-3.1.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.1.xsd"> - - - - - org.hibernate.dialect.HSQLDialect - true - - - + + + + + + + + + + - - - - - - - - - - - + + + + + + + \ No newline at end of file