diff --git a/db/pom.xml b/db/pom.xml index 45dc0fd..05e9860 100644 --- a/db/pom.xml +++ b/db/pom.xml @@ -45,7 +45,7 @@ org.hibernate hibernate-core - 3.3.0.GA + 5.3.20.Final jar diff --git a/db/src/main/java/de/meningococcus/episcangis/db/HibernateConnectionProvider.java b/db/src/main/java/de/meningococcus/episcangis/db/HibernateConnectionProvider.java index ca88767..738a2b7 100644 --- a/db/src/main/java/de/meningococcus/episcangis/db/HibernateConnectionProvider.java +++ b/db/src/main/java/de/meningococcus/episcangis/db/HibernateConnectionProvider.java @@ -2,18 +2,21 @@ import java.sql.Connection; import java.sql.SQLException; -import java.util.Properties; +import java.util.Map; import org.hibernate.HibernateException; -import org.hibernate.connection.ConnectionProvider; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.service.spi.Configurable; +import org.hibernate.service.spi.Stoppable; -public class HibernateConnectionProvider implements ConnectionProvider +public class HibernateConnectionProvider implements ConnectionProvider, Configurable, Stoppable { public static DataSourceDaoFactory connectionPool = (DataSourceDaoFactory) DaoFactory .getDaoFactory(); - public void configure(Properties props) throws HibernateException + @Override + public void configure(Map configurationValues) { if (connectionPool == null) { @@ -26,23 +29,47 @@ public void configure(Properties props) throws HibernateException } } + @Override public Connection getConnection() throws SQLException { return connectionPool.getDataSource().getConnection(); } + @Override public void closeConnection(Connection conn) throws SQLException { conn.close(); } - public void close() + @Override + public void stop() { + // No cleanup needed; the connection pool is managed by DataSourceDaoFactory } + @Override public boolean supportsAggressiveRelease() { return false; } + @Override + @SuppressWarnings("rawtypes") + public boolean isUnwrappableAs(Class unwrapType) + { + return ConnectionProvider.class.equals(unwrapType) || + HibernateConnectionProvider.class.isAssignableFrom(unwrapType); + } + + @Override + @SuppressWarnings("unchecked") + public T unwrap(Class unwrapType) + { + if (isUnwrappableAs(unwrapType)) + { + return (T) this; + } + throw new IllegalArgumentException("Cannot unwrap to " + unwrapType); + } + } diff --git a/db/src/main/java/de/meningococcus/episcangis/db/PgSQLClusterFeedbackDAO.java b/db/src/main/java/de/meningococcus/episcangis/db/PgSQLClusterFeedbackDAO.java index 9199071..5aa14fb 100644 --- a/db/src/main/java/de/meningococcus/episcangis/db/PgSQLClusterFeedbackDAO.java +++ b/db/src/main/java/de/meningococcus/episcangis/db/PgSQLClusterFeedbackDAO.java @@ -48,7 +48,7 @@ public void createClusterFeedback(ClusterFeedback feedback) } tan = RandomStringUtils.random(tanLength, 0, 0, true, true, null, random); tanFeedback = (ClusterFeedback) session.createQuery( - "from ClusterFeedback where tan=?").setString(0, tan).uniqueResult(); + "from ClusterFeedback where tan=:tan").setParameter("tan", tan).uniqueResult(); countTries++; } while (tanFeedback != null); feedback.setTan(tan); @@ -69,7 +69,7 @@ public ClusterFeedback findByTan(String tan) Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); ClusterFeedback feedback = (ClusterFeedback) session.createQuery( - "from ClusterFeedback where tan=?").setString(0, tan).uniqueResult(); + "from ClusterFeedback where tan=:tan").setParameter("tan", tan).uniqueResult(); session.close(); return feedback; } diff --git a/db/src/main/resources/hibernate.cfg.xml b/db/src/main/resources/hibernate.cfg.xml index 956b40f..d84dfc5 100644 --- a/db/src/main/resources/hibernate.cfg.xml +++ b/db/src/main/resources/hibernate.cfg.xml @@ -17,7 +17,7 @@ >de.meningococcus.episcangis.db.HibernateConnectionProvider - org.hibernate.cache.NoCacheProvider + false diff --git a/db/src/test/resources/hibernate.cfg.xml b/db/src/test/resources/hibernate.cfg.xml index 956b40f..d84dfc5 100644 --- a/db/src/test/resources/hibernate.cfg.xml +++ b/db/src/test/resources/hibernate.cfg.xml @@ -17,7 +17,7 @@ >de.meningococcus.episcangis.db.HibernateConnectionProvider - org.hibernate.cache.NoCacheProvider + false