mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-20 18:14:59 +00:00
HHH-18902 completely remove Vibur
it has not been updated in 5 years
This commit is contained in:
parent
90ff5e712a
commit
5efd37a4d8
@ -52,7 +52,6 @@ configurations {
|
||||
agroal
|
||||
c3p0
|
||||
hikaricp
|
||||
vibur
|
||||
|
||||
jcache
|
||||
|
||||
@ -71,7 +70,6 @@ configurations {
|
||||
extendsFrom agroal
|
||||
extendsFrom c3p0
|
||||
extendsFrom hikaricp
|
||||
extendsFrom vibur
|
||||
extendsFrom jcache
|
||||
extendsFrom jpamodelgen
|
||||
}
|
||||
@ -132,7 +130,6 @@ dependencies {
|
||||
reportAggregation project(':hibernate-jcache')
|
||||
reportAggregation project(':hibernate-micrometer')
|
||||
reportAggregation project(':hibernate-spatial')
|
||||
reportAggregation project(':hibernate-vibur')
|
||||
reportAggregation project(':hibernate-ant')
|
||||
reportAggregation project(':hibernate-maven-plugin')
|
||||
reportAggregation project(':hibernate-processor')
|
||||
@ -160,9 +157,6 @@ dependencies {
|
||||
hikaricp project( ':hibernate-hikaricp' )
|
||||
javadocSources project( path: ':hibernate-hikaricp', configuration: 'javadocSources' )
|
||||
|
||||
vibur project( ':hibernate-vibur' )
|
||||
javadocSources project( path: ':hibernate-vibur', configuration: 'javadocSources' )
|
||||
|
||||
jcache project( ':hibernate-jcache' )
|
||||
javadocSources project( path: ':hibernate-jcache', configuration: 'javadocSources' )
|
||||
|
||||
|
@ -52,7 +52,6 @@ transitive dependencies based on the features being used or not.
|
||||
|hibernate-agroal| Support for https://agroal.github.io/[Agroal] connection pooling
|
||||
|hibernate-c3p0| Support for https://www.mchange.com/projects/c3p0/[C3P0] connection pooling
|
||||
|hibernate-hikaricp| Support for https://github.com/brettwooldridge/HikariCP/[HikariCP] connection pooling
|
||||
|hibernate-vibur| Support for https://www.vibur.org/[Vibur DBCP] connection pooling
|
||||
|hibernate-ucp| Support for https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/intro.html[Universal Connection Pool] connection pooling
|
||||
|hibernate-jcache| Integration with https://jcp.org/en/jsr/detail?id=107$$[JCache], allowing any compliant implementation as a second-level cache provider
|
||||
|hibernate-graalvm| Experimental extension to make it easier to compile applications as a https://www.graalvm.org/[GraalVM] native image
|
||||
|
@ -17,10 +17,9 @@ Hibernate will internally determine which `ConnectionProvider` to use based on t
|
||||
2. else if `hibernate.connection.datasource` is set -> <<database-connectionprovider-datasource>>
|
||||
3. else if any setting prefixed by `hibernate.c3p0.` is set -> <<database-connectionprovider-c3p0>>
|
||||
4. else if any setting prefixed by `hibernate.hikari.` is set -> <<database-connectionprovider-hikari>>
|
||||
5. else if any setting prefixed by `hibernate.vibur.` is set -> <<database-connectionprovider-vibur>>
|
||||
6. else if any setting prefixed by `hibernate.agroal.` is set -> <<database-connectionprovider-agroal>>
|
||||
7. else if any setting prefixed by `hibernate.oracleucp.` is set -> <<database-connectionprovider-ucp>>
|
||||
8. else if `hibernate.connection.url` is set -> <<database-connectionprovider-drivermanager>>
|
||||
5. else if any setting prefixed by `hibernate.agroal.` is set -> <<database-connectionprovider-agroal>>
|
||||
6. else if any setting prefixed by `hibernate.oracleucp.` is set -> <<database-connectionprovider-ucp>>
|
||||
7. else if `hibernate.connection.url` is set -> <<database-connectionprovider-drivermanager>>
|
||||
9. else -> <<database-connectionprovider-provided>>
|
||||
|
||||
[[database-connectionprovider-datasource]]
|
||||
@ -92,26 +91,6 @@ Additionally, this `ConnectionProvider` will pick up the following Hibernate-spe
|
||||
Note that Hikari only supports JDBC standard isolation levels (apparently).
|
||||
`hibernate.connection.autocommit`:: Mapped to Hikari's `autoCommit` setting
|
||||
|
||||
[[database-connectionprovider-vibur]]
|
||||
=== Using Vibur DBCP
|
||||
|
||||
[IMPORTANT]
|
||||
====
|
||||
To use the Vibur DBCP integration, the application must include the `hibernate-vibur` module jar (as well as its dependencies) on the classpath.
|
||||
====
|
||||
|
||||
Hibernate also provides support for applications to use https://www.vibur.org/[Vibur DBCP] connection pool.
|
||||
|
||||
Set all of your Vibur settings in Hibernate prefixed by `hibernate.vibur.` and this `ConnectionProvider` will pick them up and pass them along to Vibur DBCP.
|
||||
Additionally, this `ConnectionProvider` will pick up the following Hibernate-specific properties and map them to the corresponding Vibur ones (any `hibernate.vibur.` prefixed ones have precedence):
|
||||
|
||||
`hibernate.connection.driver_class`:: Mapped to Vibur's `driverClassName` setting
|
||||
`hibernate.connection.url`:: Mapped to Vibur's `jdbcUrl` setting
|
||||
`hibernate.connection.username`:: Mapped to Vibur's `username` setting
|
||||
`hibernate.connection.password`:: Mapped to Vibur's `password` setting
|
||||
`hibernate.connection.isolation`:: Mapped to Vibur's `defaultTransactionIsolationValue` setting. See <<ConnectionProvider support for transaction isolation setting>>.
|
||||
`hibernate.connection.autocommit`:: Mapped to Vibur's `defaultAutoCommit` setting
|
||||
|
||||
[[database-connectionprovider-agroal]]
|
||||
=== Using Agroal
|
||||
|
||||
|
@ -70,11 +70,6 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator<Con
|
||||
*/
|
||||
public static final String HIKARI_STRATEGY = "hikari";
|
||||
|
||||
/**
|
||||
* The strategy for vibur connection pooling
|
||||
*/
|
||||
public static final String VIBUR_STRATEGY = "vibur";
|
||||
|
||||
/**
|
||||
* The strategy for oracle ucp connection pooling
|
||||
*/
|
||||
@ -159,9 +154,6 @@ else if ( hasConfiguration( configurationValues, C3P0_CONFIG_PREFIX ) ) {
|
||||
else if ( hasConfiguration( configurationValues, HIKARI_CONFIG_PREFIX ) ) {
|
||||
return instantiateProvider( strategySelector, HIKARI_STRATEGY );
|
||||
}
|
||||
else if ( hasConfiguration( configurationValues, "hibernate.vibur" ) ) {
|
||||
return instantiateProvider( strategySelector, VIBUR_STRATEGY );
|
||||
}
|
||||
else if (hasConfiguration( configurationValues, "hibernate.oracleucp" ) ) {
|
||||
return instantiateProvider( strategySelector, UCP_STRATEGY );
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ dependencies {
|
||||
api project( ":hibernate-agroal" )
|
||||
api project( ":hibernate-c3p0" )
|
||||
api project( ":hibernate-hikaricp" )
|
||||
api project( ":hibernate-vibur" )
|
||||
|
||||
api project( ":hibernate-jcache" )
|
||||
|
||||
@ -58,7 +57,6 @@ dependencies {
|
||||
runtime libs.agroalPool
|
||||
runtime libs.c3p0
|
||||
runtime libs.hikaricp
|
||||
runtime libs.vibur
|
||||
|
||||
runtime libs.jcache
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
description = 'Integration for Vibur Connection pooling as a Hibernate ORM ConnectionProvider'
|
||||
|
||||
apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' )
|
||||
|
||||
dependencies {
|
||||
implementation project( ':hibernate-core' )
|
||||
implementation libs.vibur
|
||||
|
||||
testImplementation project( ':hibernate-testing' )
|
||||
testImplementation "org.vibur:vibur-dbcp:${libs.versions.vibur.get()}:tests"
|
||||
testImplementation 'com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2'
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
* Copyright Red Hat Inc. and Hibernate Authors
|
||||
*/
|
||||
package org.hibernate.vibur.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
|
||||
import org.hibernate.boot.registry.selector.StrategyRegistration;
|
||||
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
|
||||
/**
|
||||
* Provides the {@link ViburDBCPConnectionProvider} to the
|
||||
* {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service.
|
||||
*
|
||||
* @author Simeon Malchev
|
||||
*/
|
||||
public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterable<StrategyRegistration> getStrategyRegistrations() {
|
||||
return Collections.singletonList(
|
||||
new SimpleStrategyRegistrationImpl<>(
|
||||
ConnectionProvider.class,
|
||||
ViburDBCPConnectionProvider.class,
|
||||
"vibur",
|
||||
"viburdbcp",
|
||||
ViburDBCPConnectionProvider.class.getSimpleName(),
|
||||
// for backward compatibility with pre-existing Vibur project Hibernate integration artifacts
|
||||
"org.vibur.dbcp.integration.ViburDBCPConnectionProvider",
|
||||
// for consistency's sake
|
||||
"org.hibernate.connection.ViburDBCPConnectionProvider"
|
||||
) );
|
||||
}
|
||||
}
|
@ -1,191 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
* Copyright Red Hat Inc. and Hibernate Authors
|
||||
*/
|
||||
package org.hibernate.vibur.internal;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||
import org.hibernate.internal.log.ConnectionInfoLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||
import org.hibernate.service.spi.Configurable;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
|
||||
import org.vibur.dbcp.ViburDBCPDataSource;
|
||||
|
||||
import static org.hibernate.cfg.AvailableSettings.AUTOCOMMIT;
|
||||
import static org.hibernate.cfg.AvailableSettings.DRIVER;
|
||||
import static org.hibernate.cfg.AvailableSettings.ISOLATION;
|
||||
import static org.hibernate.cfg.AvailableSettings.PASS;
|
||||
import static org.hibernate.cfg.AvailableSettings.URL;
|
||||
import static org.hibernate.cfg.AvailableSettings.USER;
|
||||
import static org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.allowJdbcMetadataAccess;
|
||||
|
||||
/**
|
||||
* <p>ViburDBCP connection provider for Hibernate integration.
|
||||
* <p>
|
||||
* To use this connection provider set:
|
||||
* <pre>
|
||||
* hibernate.connection.provider_class ViburDBCPConnectionProvider
|
||||
* </pre>
|
||||
* <p>
|
||||
* Supported Hibernate properties are:
|
||||
* <pre>
|
||||
* hibernate.connection.driver_class
|
||||
* hibernate.connection.url
|
||||
* hibernate.connection.username
|
||||
* hibernate.connection.password
|
||||
* hibernate.connection.isolation
|
||||
* hibernate.connection.autocommit
|
||||
* </pre>
|
||||
* <p>
|
||||
* All {@link org.vibur.dbcp.ViburConfig} properties are also supported via using the
|
||||
* {@code hibernate.vibur} prefix.
|
||||
*
|
||||
* @author Simeon Malchev
|
||||
* @see ConnectionProvider
|
||||
*/
|
||||
public class ViburDBCPConnectionProvider implements ConnectionProvider, Configurable, Stoppable {
|
||||
|
||||
private static final String VIBUR_CONFIG_PREFIX = "hibernate.vibur";
|
||||
private static final String VIBUR_PREFIX = VIBUR_CONFIG_PREFIX + ".";
|
||||
|
||||
private ViburDBCPDataSource dataSource = null;
|
||||
private boolean isMetadataAccessAllowed = true;
|
||||
|
||||
@Override
|
||||
public void configure(Map<String, Object> configurationValues) {
|
||||
isMetadataAccessAllowed = allowJdbcMetadataAccess( configurationValues );
|
||||
|
||||
ConnectionInfoLogger.INSTANCE.configureConnectionPool( "Vibur" );
|
||||
|
||||
dataSource = new ViburDBCPDataSource( transform( configurationValues ) );
|
||||
dataSource.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection(Connection connection) throws SQLException {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if ( dataSource != null ) {
|
||||
ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( VIBUR_CONFIG_PREFIX );
|
||||
dataSource.terminate();
|
||||
dataSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsAggressiveRelease() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
||||
return new DatabaseConnectionInfoImpl(
|
||||
dataSource.getJdbcUrl(),
|
||||
// Attempt to resolve the driver name from the dialect, in case it wasn't explicitly set and access to
|
||||
// the database metadata is allowed
|
||||
!StringHelper.isBlank( dataSource.getDriverClassName() ) ? dataSource.getDriverClassName() : extractDriverNameFromMetadata(),
|
||||
dialect.getVersion(),
|
||||
String.valueOf( dataSource.getDefaultAutoCommit() ),
|
||||
dataSource.getDefaultTransactionIsolation(),
|
||||
dataSource.getPoolInitialSize(),
|
||||
dataSource.getPoolMaxSize()
|
||||
);
|
||||
}
|
||||
|
||||
private String extractDriverNameFromMetadata() {
|
||||
if (isMetadataAccessAllowed) {
|
||||
try ( Connection conn = getConnection() ) {
|
||||
DatabaseMetaData dbmd = conn.getMetaData();
|
||||
return dbmd.getDriverName();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
||||
return ConnectionProvider.class.equals( unwrapType )
|
||||
|| ViburDBCPConnectionProvider.class.isAssignableFrom( unwrapType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T unwrap(Class<T> unwrapType) {
|
||||
if ( isUnwrappableAs( unwrapType ) ) {
|
||||
return (T) this;
|
||||
}
|
||||
else {
|
||||
throw new UnknownUnwrapTypeException( unwrapType );
|
||||
}
|
||||
}
|
||||
|
||||
private static Properties transform(Map<String, Object> configurationValues) {
|
||||
Properties result = new Properties();
|
||||
|
||||
String driverClassName = (String) configurationValues.get( DRIVER );
|
||||
if ( driverClassName != null ) {
|
||||
result.setProperty( "driverClassName", driverClassName );
|
||||
}
|
||||
|
||||
String jdbcUrl = (String) configurationValues.get( URL );
|
||||
if ( jdbcUrl != null ) {
|
||||
result.setProperty( "jdbcUrl", jdbcUrl );
|
||||
}
|
||||
|
||||
String username = (String) configurationValues.get( USER );
|
||||
if ( username != null ) {
|
||||
result.setProperty( "username", username );
|
||||
}
|
||||
String password = (String) configurationValues.get( PASS );
|
||||
if ( password != null ) {
|
||||
result.setProperty( "password", password );
|
||||
}
|
||||
|
||||
String defaultTransactionIsolationValue = (String) configurationValues.get( ISOLATION );
|
||||
if ( defaultTransactionIsolationValue != null ) {
|
||||
result.setProperty( "defaultTransactionIsolationValue", defaultTransactionIsolationValue );
|
||||
}
|
||||
String defaultAutoCommit = (String) configurationValues.get( AUTOCOMMIT );
|
||||
if ( defaultAutoCommit != null ) {
|
||||
result.setProperty( "defaultAutoCommit", defaultAutoCommit );
|
||||
}
|
||||
|
||||
for ( Map.Entry<String, Object> entry : configurationValues.entrySet() ) {
|
||||
String key = entry.getKey();
|
||||
if ( key.startsWith( VIBUR_PREFIX ) ) {
|
||||
key = key.substring( VIBUR_PREFIX.length() );
|
||||
result.setProperty( key, (String) entry.getValue() );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visible for testing purposes.
|
||||
*/
|
||||
public ViburDBCPDataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of ConnectionProvider using ViburDBCP.
|
||||
*/
|
||||
package org.hibernate.vibur.internal;
|
@ -1,13 +0,0 @@
|
||||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
org.hibernate.vibur.internal.StrategyRegistrationProviderImpl
|
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<blueprint default-activation="eager"
|
||||
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||
>
|
||||
|
||||
<bean id="strategyRegistrationProvider" class="org.hibernate.vibur.internal.StrategyRegistrationProviderImpl"/>
|
||||
<service ref="strategyRegistrationProvider" interface="org.hibernate.boot.registry.selector.StrategyRegistrationProvider"/>
|
||||
|
||||
</blueprint>
|
@ -1,174 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
* Copyright Red Hat Inc. and Hibernate Authors
|
||||
*/
|
||||
package org.hibernate.test.vibur;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.vibur.internal.ViburDBCPConnectionProvider;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.vibur.dbcp.ViburDBCPDataSource;
|
||||
import org.vibur.dbcp.stcache.StatementHolder;
|
||||
import org.vibur.dbcp.stcache.StatementMethod;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import static org.hibernate.cfg.AvailableSettings.*;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.vibur.dbcp.AbstractDataSourceTest.mockStatementCache;
|
||||
import static org.vibur.dbcp.stcache.StatementHolder.State.AVAILABLE;
|
||||
|
||||
/**
|
||||
* Hibernate unit/integration test for {@link ViburDBCPConnectionProvider}.
|
||||
*
|
||||
* @author Simeon Malchev
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ViburDBCPConnectionProviderTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private int poolMaxSize;
|
||||
private int statementCacheMaxSize;
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
Properties properties = configuration.getProperties();
|
||||
properties.put(CONNECTION_PROVIDER, ViburDBCPConnectionProvider.class);
|
||||
properties.put(SHOW_SQL, Boolean.TRUE);
|
||||
properties.put(FORMAT_SQL, Boolean.TRUE);
|
||||
|
||||
properties.put("hibernate.vibur.poolInitialSize", "1");
|
||||
properties.put("hibernate.vibur.poolMaxSize", Integer.toString(poolMaxSize));
|
||||
properties.put("hibernate.vibur.logQueryExecutionLongerThanMs", "100");
|
||||
properties.put("hibernate.vibur.statementCacheMaxSize", Integer.toString(statementCacheMaxSize));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { Actor.class };
|
||||
}
|
||||
|
||||
public void setUpPoolAndDatabase(int poolMaxSize, int statementCacheMaxSize) {
|
||||
this.poolMaxSize = poolMaxSize;
|
||||
this.statementCacheMaxSize = statementCacheMaxSize;
|
||||
buildSessionFactory();
|
||||
|
||||
doInHibernate(this::sessionFactory, session -> {
|
||||
addDbRecord(session, 1L, "CHRISTIAN", "GABLE");
|
||||
addDbRecord(session, 2L, "CHRISTIAN", "AKROYD");
|
||||
addDbRecord(session, 3L, "CHRISTIAN", "NEESON");
|
||||
addDbRecord(session, 4L, "CAMERON", "NEESON");
|
||||
addDbRecord(session, 5L, "RAY", "JOHANSSON");
|
||||
});
|
||||
}
|
||||
|
||||
private static void addDbRecord(Session session, Long id, String firstName, String lastName) {
|
||||
Actor actor = new Actor();
|
||||
actor.setId( id );
|
||||
actor.setFirstName(firstName);
|
||||
actor.setLastName(lastName);
|
||||
session.persist(actor);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
releaseSessionFactory();
|
||||
}
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<StatementMethod> key1, key2;
|
||||
@Captor
|
||||
private ArgumentCaptor<StatementHolder> val1;
|
||||
|
||||
@Test
|
||||
public void testSelectStatementNoStatementsCache() {
|
||||
setUpPoolAndDatabase(2, 0 /* disables the statements cache */ );
|
||||
|
||||
doInHibernate(this::sessionFactory, ViburDBCPConnectionProviderTest::executeAndVerifySelect);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectStatementWithStatementsCache() {
|
||||
setUpPoolAndDatabase(1, 10 /* statement cache is enabled */ );
|
||||
|
||||
ConnectionProvider cp = sessionFactory().getServiceRegistry().getService(ConnectionProvider.class);
|
||||
ViburDBCPDataSource ds = ((ViburDBCPConnectionProvider) cp).getDataSource();
|
||||
|
||||
ConcurrentMap<StatementMethod, StatementHolder> mockedStatementCache = mockStatementCache(ds);
|
||||
|
||||
doInHibernate(this::sessionFactory, ViburDBCPConnectionProviderTest::executeAndVerifySelect);
|
||||
|
||||
// We set above the poolMaxSize = 1, that's why the second session will get and use the same underlying connection.
|
||||
doInHibernate(this::sessionFactory, ViburDBCPConnectionProviderTest::executeAndVerifySelect);
|
||||
|
||||
InOrder inOrder = inOrder(mockedStatementCache);
|
||||
inOrder.verify(mockedStatementCache).get(key1.capture());
|
||||
inOrder.verify(mockedStatementCache).putIfAbsent(same(key1.getValue()), val1.capture());
|
||||
inOrder.verify(mockedStatementCache).get(key2.capture());
|
||||
|
||||
assertEquals(1, mockedStatementCache.size());
|
||||
assertTrue(mockedStatementCache.containsKey(key1.getValue()));
|
||||
assertEquals(key1.getValue(), key2.getValue());
|
||||
assertEquals(AVAILABLE, val1.getValue().state().get());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void executeAndVerifySelect(Session session) {
|
||||
List<Actor> list = session.createQuery("from Actor where firstName = ?1")
|
||||
.setParameter(1, "CHRISTIAN").list();
|
||||
|
||||
Set<String> expectedLastNames = new HashSet<>(Arrays.asList("GABLE", "AKROYD", "NEESON"));
|
||||
assertEquals(expectedLastNames.size(), list.size());
|
||||
for (Actor actor : list) {
|
||||
assertTrue(expectedLastNames.remove(actor.getLastName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name="Actor")
|
||||
public static class Actor {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
hibernate.dialect @db.dialect@
|
||||
hibernate.connection.driver_class @jdbc.driver@
|
||||
hibernate.connection.url @jdbc.url@
|
||||
hibernate.connection.username @jdbc.user@
|
||||
hibernate.connection.password @jdbc.pass@
|
||||
hibernate.connection.init_sql @connection.init_sql@
|
||||
|
||||
hibernate.jdbc.batch_size 10
|
||||
hibernate.connection.provider_class ViburDBCPConnectionProvider
|
@ -1,83 +0,0 @@
|
||||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
appender.stdout.type=Console
|
||||
appender.stdout.name=STDOUT
|
||||
appender.stdout.layout.type=PatternLayout
|
||||
appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||
appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n
|
||||
|
||||
appender.stdout-mdc.type=Console
|
||||
appender.stdout-mdc.name=stdout-mdc
|
||||
appender.stdout-mdc.layout.type=PatternLayout
|
||||
appender.stdout-mdc.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L (walk path -> %X{hibernateLoadPlanWalkPath}) - %m%n
|
||||
|
||||
appender.unclosedSessionFactoryFile.type=File
|
||||
appender.unclosedSessionFactoryFile.name=unclosedSessionFactoryFile
|
||||
appender.unclosedSessionFactoryFile.append=true
|
||||
appender.unclosedSessionFactoryFile.fileName=target/tmp/log/UnclosedSessionFactoryWarnings.log
|
||||
appender.unclosedSessionFactoryFile.layout.type=PatternLayout
|
||||
appender.unclosedSessionFactoryFile.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||
|
||||
rootLogger.level=info
|
||||
rootLogger.appenderRef.stdout.ref=STDOUT
|
||||
|
||||
logger.loader-plan.name=org.hibernate.loader.plan
|
||||
#logger.loader-plan.level=trace
|
||||
#logger.loader-plan.appenderRef.stdout-mdc.ref=stdout-mdc
|
||||
#logger.loader-plan.additivity=false
|
||||
logger.persister-walking.name=org.hibernate.persister.walking
|
||||
#logger.persister-walking.level=trace
|
||||
#logger.persister-walking.appenderRef.stdout-mdc.ref=stdout-mdc
|
||||
#logger.persister-walking.additivity=false
|
||||
|
||||
logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl
|
||||
logger.hbm2ddl.level=trace
|
||||
logger.testing-cache.name=org.hibernate.testing.cache
|
||||
logger.testing-cache.level=debug
|
||||
|
||||
# SQL Logging - HHH-6833
|
||||
logger.sql.name=org.hibernate.SQL
|
||||
logger.sql.level=debug
|
||||
|
||||
logger.type-basic-binder.name=org.hibernate.type.descriptor.jdbc.BasicBinder
|
||||
logger.type-basic-binder.level=trace
|
||||
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdbc.BasicExtractor
|
||||
logger.type-basic-extractor.level=trace
|
||||
|
||||
logger.hql-internal-ast.name=org.hibernate.hql.internal.ast
|
||||
logger.hql-internal-ast.level=debug
|
||||
|
||||
logger.sql-ordering-antlr.name=org.hibernate.sql.ordering.antlr
|
||||
logger.sql-ordering-antlr.level=debug
|
||||
|
||||
logger.load-plan-impl.name=org.hibernate.loader.plan2.build.internal.LoadPlanImpl
|
||||
logger.load-plan-impl.level=debug
|
||||
logger.load-plan-tree-printer.name=org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter
|
||||
logger.load-plan-tree-printer.level=debug
|
||||
logger.entity-load-query-details.name=org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails
|
||||
logger.entity-load-query-details.level=debug
|
||||
|
||||
logger.statistical-logging-session-event-listener.name=org.hibernate.engine.internal.StatisticalLoggingSessionEventListener
|
||||
logger.statistical-logging-session-event-listener.level=info
|
||||
|
||||
logger.model-binder.name=org.hibernate.boot.model.source.internal.hbm.ModelBinder
|
||||
logger.model-binder.level=debug
|
||||
logger.java-type-descriptor-registry.name=org.hibernate.type.descriptor.java.JavaTypeRegistry
|
||||
logger.java-type-descriptor-registry.level=debug
|
||||
|
||||
|
||||
logger.merged-entity-copies.name=org.hibernate.event.internal.EntityCopyAllowedLoggedObserver
|
||||
### When entity copy merge functionality is enabled using:
|
||||
### hibernate.event.merge.entity_copy_observer=log, the following will
|
||||
### provide information about merged entity copies.
|
||||
#logger.merged-entity-copies.level=debug
|
||||
|
||||
logger.test-class-metadata.name=org.hibernate.testing.junit4.TestClassMetadata
|
||||
logger.test-class-metadata.level=info
|
||||
logger.test-class-metadata.appenderRef.unclosedSessionFactoryFile.ref=unclosedSessionFactoryFile
|
||||
logger.scanning-coordinator.name=org.hibernate.boot.model.process.internal.ScanningCoordinator
|
||||
logger.scanning-coordinator.level=debug
|
@ -87,7 +87,6 @@ dependencyResolutionManagement {
|
||||
def agroalVersion = version "agroal", "2.5"
|
||||
def c3poVersion = version "c3p0", "0.10.1"
|
||||
def hikaricpVersion = version "hikaricp", "6.2.1"
|
||||
def viburVersion = version "vibur", "25.0"
|
||||
def ucpVersion = version "ucp", "23.6.0.24.10"
|
||||
|
||||
def jcacheVersion = version "jcache", "1.1.1"
|
||||
@ -120,7 +119,6 @@ dependencyResolutionManagement {
|
||||
library( "agroalPool", "io.agroal", "agroal-pool" ).versionRef( agroalVersion )
|
||||
library( "c3p0", "com.mchange", "c3p0" ).versionRef( c3poVersion )
|
||||
library( "hikaricp", "com.zaxxer", "HikariCP" ).versionRef( hikaricpVersion )
|
||||
library( "vibur", "org.vibur", "vibur-dbcp" ).versionRef( viburVersion )
|
||||
library( "ucp", "com.oracle.database.jdbc", "ucp11" ).versionRef( ucpVersion )
|
||||
|
||||
library( "ojdbc11", "com.oracle.database.jdbc", "ojdbc11" ).versionRef( ucpVersion )
|
||||
@ -322,7 +320,6 @@ include 'hibernate-vector'
|
||||
|
||||
include 'hibernate-c3p0'
|
||||
include 'hibernate-hikaricp'
|
||||
include 'hibernate-vibur'
|
||||
include 'hibernate-agroal'
|
||||
include 'hibernate-ucp'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user