Enable adding non-String setting values to the @Jpa integrationSettings

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2021-02-02 18:34:40 +01:00 committed by Jan Schatteman
parent dc884e077b
commit b15e7506cc
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,15 @@
/*
* 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>.
*/
package org.hibernate.testing.orm.jpa;
/**
* @author Jan Schatteman
*/
public abstract class NonStringValueSettingProvider {
public abstract String getKey();
public abstract Object getValue();
}

View File

@ -39,6 +39,7 @@ import org.hibernate.testing.jdbc.SharedDriverManagerConnectionProviderImpl;
import org.hibernate.testing.orm.domain.DomainModelDescriptor;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.jpa.PersistenceUnitInfoImpl;
import org.hibernate.testing.orm.jpa.NonStringValueSettingProvider;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
@ -156,6 +157,19 @@ public class EntityManagerFactoryExtension
integrationSettings.put( setting.name(), setting.value() );
}
if ( emfAnn.nonStringValueSettingProvider().length > 0 ) {
for ( int i = 0; i < emfAnn.nonStringValueSettingProvider().length; i++ ) {
final Class<? extends NonStringValueSettingProvider> _class = emfAnn.nonStringValueSettingProvider()[ i ];
try {
NonStringValueSettingProvider valueProvider = _class.newInstance();
integrationSettings.put( valueProvider.getKey(), valueProvider.getValue() );
}
catch (Exception e) {
log.error( "Error obtaining special value for " + _class.getName(), e );
}
}
}
final EntityManagerFactoryScopeImpl scope = new EntityManagerFactoryScopeImpl( pui, integrationSettings );
locateExtensionStore( testInstance, context ).put( EMF_KEY, scope );

View File

@ -18,6 +18,7 @@ import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.testing.orm.domain.DomainModelDescriptor;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.jpa.NonStringValueSettingProvider;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
@ -43,6 +44,8 @@ public @interface Jpa {
*/
Setting[] integrationSettings() default {};
Class<? extends NonStringValueSettingProvider>[] nonStringValueSettingProvider() default {};
String persistenceUnitName() default "test-pu";
// todo : multiple persistence units?