Skip to content

Commit dc6d255

Browse files
committed
HHH-8203 HHH-8204 Hibernate 4.x can't work with proxool 0.9.1
1 parent d0098f3 commit dc6d255

File tree

4 files changed

+95
-23
lines changed

4 files changed

+95
-23
lines changed

hibernate-proxool/src/main/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProvider.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.sql.Connection;
2727
import java.sql.DriverManager;
2828
import java.sql.SQLException;
29+
import java.util.Map;
2930
import java.util.Properties;
3031

3132
import org.jboss.logging.Logger;
@@ -41,13 +42,15 @@
4142
import org.hibernate.internal.util.config.ConfigurationHelper;
4243
import org.hibernate.service.UnknownUnwrapTypeException;
4344
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
45+
import org.hibernate.service.spi.Configurable;
46+
import org.hibernate.service.spi.Stoppable;
4447

4548
/**
4649
* A connection provider that uses a Proxool connection pool. Hibernate will use this by
4750
* default if the <tt>hibernate.proxool.*</tt> properties are set.
4851
* @see ConnectionProvider
4952
*/
50-
public class ProxoolConnectionProvider implements ConnectionProvider {
53+
public class ProxoolConnectionProvider implements ConnectionProvider, Configurable, Stoppable {
5154

5255
public static final ProxoolMessageLogger LOG = Logger.getMessageLogger(ProxoolMessageLogger.class, ProxoolConnectionProvider.class.getName());
5356

@@ -69,12 +72,13 @@ public class ProxoolConnectionProvider implements ConnectionProvider {
6972
* @return a JDBC connection
7073
* @throws SQLException
7174
*/
75+
@Override
7276
public Connection getConnection() throws SQLException {
7377
// get a connection from the pool (thru DriverManager, cfr. Proxool doc)
7478
Connection c = DriverManager.getConnection(proxoolAlias);
7579

7680
// set the Transaction Isolation if defined
77-
if (isolation!=null) c.setTransactionIsolation( isolation.intValue() );
81+
if (isolation!=null) c.setTransactionIsolation( isolation );
7882

7983
// toggle autoCommit to false if set
8084
if ( c.getAutoCommit()!=autocommit ) c.setAutoCommit(autocommit);
@@ -106,6 +110,7 @@ public <T> T unwrap(Class<T> unwrapType) {
106110
* @param conn a JDBC connection
107111
* @throws SQLException
108112
*/
113+
@Override
109114
public void closeConnection(Connection conn) throws SQLException {
110115
conn.close();
111116
}
@@ -114,15 +119,16 @@ public void closeConnection(Connection conn) throws SQLException {
114119
* Initialize the connection provider from given properties.
115120
* @param props <tt>SessionFactory</tt> properties
116121
*/
117-
public void configure(Properties props) throws HibernateException {
122+
@Override
123+
public void configure(Map props) {
118124

119125
// Get the configurator files (if available)
120-
String jaxpFile = props.getProperty(Environment.PROXOOL_XML);
121-
String propFile = props.getProperty(Environment.PROXOOL_PROPERTIES);
122-
String externalConfig = props.getProperty(Environment.PROXOOL_EXISTING_POOL);
126+
String jaxpFile = (String)props.get(Environment.PROXOOL_XML);
127+
String propFile = (String)props.get(Environment.PROXOOL_PROPERTIES);
128+
String externalConfig = (String)props.get(Environment.PROXOOL_EXISTING_POOL);
123129

124130
// Default the Proxool alias setting
125-
proxoolAlias = props.getProperty(Environment.PROXOOL_POOL_ALIAS);
131+
proxoolAlias = (String)props.get(Environment.PROXOOL_POOL_ALIAS);
126132

127133
// Configured outside of Hibernate (i.e. Servlet container, or Java Bean Container
128134
// already has Proxool pools running, and this provider is to just borrow one of these
@@ -235,8 +241,14 @@ public void close() throws HibernateException {
235241
/**
236242
* @see ConnectionProvider#supportsAggressiveRelease()
237243
*/
244+
@Override
238245
public boolean supportsAggressiveRelease() {
239246
return false;
240247
}
241248

249+
250+
@Override
251+
public void stop() {
252+
close();
253+
}
242254
}

hibernate-proxool/src/test/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProviderTest.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525

2626
import java.util.Arrays;
2727
import java.util.List;
28-
import java.util.Properties;
2928

3029
import org.junit.Test;
3130
import org.logicalcobwebs.proxool.ProxoolFacade;
3231

32+
import org.hibernate.boot.registry.StandardServiceRegistry;
33+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
3334
import org.hibernate.cfg.Environment;
35+
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
3436
import org.hibernate.testing.junit4.BaseUnitTestCase;
3537

3638
import static org.junit.Assert.assertEquals;
@@ -42,22 +44,25 @@
4244
* @author Sanne Grinovero
4345
*/
4446
public class ProxoolConnectionProviderTest extends BaseUnitTestCase {
47+
48+
49+
4550
@Test
4651
public void testPoolsClosed() {
4752
assertDefinedPools(); // zero-length-vararg used as parameter
48-
49-
ProxoolConnectionProvider providerOne = new ProxoolConnectionProvider();
50-
providerOne.configure( getPoolConfigurarion( "pool-one" ) );
53+
StandardServiceRegistry serviceRegistry = buildServiceRegistry( "pool-one" );
54+
ConnectionProvider providerOne = serviceRegistry.getService( ConnectionProvider.class );
5155
assertDefinedPools( "pool-one" );
52-
53-
ProxoolConnectionProvider providerTwo = new ProxoolConnectionProvider();
54-
providerTwo.configure( getPoolConfigurarion( "pool-two" ) );
56+
57+
58+
StandardServiceRegistry serviceRegistryTwo = buildServiceRegistry( "pool-two" );
59+
ConnectionProvider providerTwo = serviceRegistryTwo.getService( ConnectionProvider.class );
5560
assertDefinedPools( "pool-one", "pool-two" );
5661

57-
providerOne.close();
62+
StandardServiceRegistryBuilder.destroy( serviceRegistry );
5863
assertDefinedPools( "pool-two" );
59-
60-
providerTwo.close();
64+
65+
StandardServiceRegistryBuilder.destroy( serviceRegistryTwo );
6166
assertDefinedPools();
6267
}
6368

@@ -69,11 +74,14 @@ private void assertDefinedPools(String... expectedPoolNames) {
6974
}
7075
}
7176

72-
private Properties getPoolConfigurarion(String poolName) {
73-
Properties cfg = new Properties();
74-
cfg.setProperty( Environment.PROXOOL_POOL_ALIAS, poolName );
75-
cfg.setProperty( Environment.PROXOOL_PROPERTIES, poolName + ".properties" );
76-
return cfg;
77+
78+
private StandardServiceRegistry buildServiceRegistry(String poolName){
79+
80+
return new StandardServiceRegistryBuilder( )
81+
.applySetting( Environment.PROXOOL_POOL_ALIAS, poolName )
82+
.applySetting( Environment.PROXOOL_PROPERTIES, poolName + ".properties" )
83+
.applySetting( Environment.CONNECTION_PROVIDER, ProxoolConnectionProvider.class.getName() )
84+
.build();
85+
7786
}
78-
7987
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# Hibernate, Relational Persistence for Idiomatic Java
3+
#
4+
# Copyright (c) 2010, Red Hat Inc. or third-party contributors as
5+
# indicated by the @author tags or express copyright attribution
6+
# statements applied by the authors. All third-party contributions are
7+
# distributed under license by Red Hat Inc.
8+
#
9+
# This copyrighted material is made available to anyone wishing to use, modify,
10+
# copy, or redistribute it subject to the terms and conditions of the GNU
11+
# Lesser General Public License, as published by the Free Software Foundation.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
# for more details.
17+
#
18+
# You should have received a copy of the GNU Lesser General Public License
19+
# along with this distribution; if not, write to:
20+
# Free Software Foundation, Inc.
21+
# 51 Franklin Street, Fifth Floor
22+
# Boston, MA 02110-1301 USA
23+
#
24+
hibernate.dialect org.hibernate.dialect.H2Dialect
25+
hibernate.connection.driver_class org.h2.Driver
26+
hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
27+
hibernate.connection.username sa
28+
29+
hibernate.connection.pool_size 5
30+
hibernate.jdbc.batch_size 10
31+
hibernate.connection.provider_class org.hibernate.connection.ProxoolConnectionProvider
32+
hibernate.proxool.properties pool-one.properties
33+
34+
hibernate.show_sql false
35+
36+
hibernate.max_fetch_depth 5
37+
38+
hibernate.cache.region_prefix hibernate.test
39+
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
40+
41+
# NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
42+
hibernate.jdbc.batch_versioned_data true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
2+
log4j.appender.stdout.Target=System.out
3+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
4+
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
5+
6+
7+
log4j.rootLogger=info, stdout
8+
9+
log4j.logger.org.hibernate.tool.hbm2ddl=debug
10+
log4j.logger.org.hibernate.testing.cache=debug

0 commit comments

Comments
 (0)