From 2e49586adc2fdd4f5da6b206de076069b6d71723 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 16 Nov 2016 13:46:24 -0600 Subject: [PATCH] HHH-11152 - Byte Buddy BytecodeProvider --- hibernate-core/hibernate-core.gradle | 3 ++- .../java/org/hibernate/cfg/Environment.java | 24 +++++++++++++------ .../hibernate/internal/CoreMessageLogger.java | 4 ++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 0b8cb72be8..aa3a8e1605 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -23,7 +23,8 @@ configurations { dependencies { compile( libraries.jpa ) compile( libraries.javassist ) - compile( libraries.byteBuddy ) + // provided until 6.0 when we make it the default and drop Javassist support + provided( libraries.byteBuddy ) compile( libraries.antlr ) compile( libraries.jta ) compile( libraries.jandex ) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java b/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java index f8c8a0550f..6c37f6ee4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java @@ -151,7 +151,7 @@ import org.jboss.logging.Logger; * @author Gavin King */ public final class Environment implements AvailableSettings { - private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, Environment.class.getName()); + private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, Environment.class.getName()); private static final BytecodeProvider BYTECODE_PROVIDER_INSTANCE; private static final boolean ENABLE_BINARY_STREAMS; @@ -313,21 +313,31 @@ public final class Environment implements AvailableSettings { return ConnectionProviderInitiator.toIsolationNiceName( isolation ); } + + public static final String BYTECODE_PROVIDER_NAME_JAVASSIST = "javassist"; + public static final String BYTECODE_PROVIDER_NAME_BYTEBUDDY = "bytebuddy"; + public static final String BYTECODE_PROVIDER_NAME_DEFAULT = BYTECODE_PROVIDER_NAME_JAVASSIST; + public static BytecodeProvider buildBytecodeProvider(Properties properties) { - String provider = ConfigurationHelper.getString( BYTECODE_PROVIDER, properties, "bytebuddy" ); - LOG.bytecodeProvider( provider ); + String provider = ConfigurationHelper.getString( BYTECODE_PROVIDER, properties, BYTECODE_PROVIDER_NAME_DEFAULT ); return buildBytecodeProvider( provider ); } private static BytecodeProvider buildBytecodeProvider(String providerName) { - if ( "bytebuddy".equals( providerName ) ) { + if ( BYTECODE_PROVIDER_NAME_BYTEBUDDY.equals( providerName ) ) { return new org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl(); } - if ( "javassist".equals( providerName ) ) { + + if ( BYTECODE_PROVIDER_NAME_JAVASSIST.equals( providerName ) ) { return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl(); } - LOG.unknownBytecodeProvider( providerName ); - return new org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl(); + LOG.bytecodeProvider( providerName ); + + // todo : allow a custom class name - just check if the config is a FQN + // currently we assume it is only ever the Strings "javassist" or "bytebuddy"... + + LOG.unknownBytecodeProvider( providerName, BYTECODE_PROVIDER_NAME_DEFAULT ); + return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index edcc7b6658..3070d01004 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -1327,8 +1327,8 @@ public interface CoreMessageLogger extends BasicLogger { void unexpectedRowCounts(); @LogMessage(level = WARN) - @Message(value = "unrecognized bytecode provider [%s], using 'bytebuddy' by default", id = 382) - void unknownBytecodeProvider(String providerName); + @Message(value = "unrecognized bytecode provider [%s], using [%s] by default", id = 382) + void unknownBytecodeProvider(String providerName, String defaultProvider); @LogMessage(level = WARN) @Message(value = "Unknown Ingres major version [%s]; using Ingres 9.2 dialect", id = 383)