Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.0.GA</version>
<version>5.3.20.Final</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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> T unwrap(Class<T> unwrapType)
{
if (isUnwrappableAs(unwrapType))
{
return (T) this;
}
throw new IllegalArgumentException("Cannot unwrap to " + unwrapType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion db/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
>de.meningococcus.episcangis.db.HibernateConnectionProvider</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_second_level_cache">false</property>

<mapping resource="ClusterFeedback.hbm.xml"/>

Expand Down
2 changes: 1 addition & 1 deletion db/src/test/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
>de.meningococcus.episcangis.db.HibernateConnectionProvider</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_second_level_cache">false</property>

<mapping resource="ClusterFeedback.hbm.xml"/>

Expand Down
Loading