HHH-9639 support unwrapping HikariCPConnectionProvider as DataSource
This commit is contained in:
parent
260ff03ae5
commit
9aebcf64e7
|
@ -21,10 +21,8 @@
|
||||||
|
|
||||||
package org.hibernate.hikaricp.internal;
|
package org.hibernate.hikaricp.internal;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import java.sql.SQLException;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
|
@ -32,8 +30,10 @@ import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.Stoppable;
|
import org.hibernate.service.spi.Stoppable;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import javax.sql.DataSource;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HikariCP Connection provider for Hibernate.
|
* HikariCP Connection provider for Hibernate.
|
||||||
|
@ -106,18 +106,23 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public boolean isUnwrappableAs(Class unwrapType) {
|
public boolean isUnwrappableAs(Class unwrapType) {
|
||||||
return ConnectionProvider.class.equals( unwrapType )
|
return ConnectionProvider.class.equals( unwrapType )
|
||||||
|| HikariCPConnectionProvider.class.isAssignableFrom( unwrapType );
|
|| HikariCPConnectionProvider.class.isAssignableFrom( unwrapType )
|
||||||
|
|| DataSource.class.isAssignableFrom( unwrapType );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T unwrap(Class<T> unwrapType) {
|
public <T> T unwrap(Class<T> unwrapType) {
|
||||||
if ( isUnwrappableAs( unwrapType ) ) {
|
if ( ConnectionProvider.class.equals( unwrapType ) ||
|
||||||
return (T) this;
|
HikariCPConnectionProvider.class.isAssignableFrom( unwrapType ) ) {
|
||||||
}
|
return (T) this;
|
||||||
else {
|
}
|
||||||
throw new UnknownUnwrapTypeException( unwrapType );
|
else if ( DataSource.class.isAssignableFrom( unwrapType ) ) {
|
||||||
}
|
return (T) hds;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new UnknownUnwrapTypeException( unwrapType );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue