Merge remote-tracking branch 'upstream/main' into wip/6.0

This commit is contained in:
Andrea Boriero 2021-08-30 14:07:19 +02:00
commit cdeb95a4d5
43 changed files with 1732 additions and 1355 deletions

View File

@ -23,3 +23,4 @@ hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFa
hibernate.service.allow_crawling=false
hibernate.session.events.log=true

View File

@ -60,7 +60,6 @@
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
<bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle>
<bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle>
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>
<bundle>mvn:org.hibernate.common/hibernate-commons-annotations/4.0.5.Final</bundle>

View File

@ -56,9 +56,6 @@
org.apache.karaf.shell.console,
org.apache.karaf.shell.commands,
javax.persistence;version="[1.0.0,2.1.0]",
<!-- Needed for proxying's Javassist enhancement during runtime -->
org.hibernate.proxy,
javassist.util.proxy,
*
</Import-Package>
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>

View File

@ -33,7 +33,6 @@
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
<bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle>
<bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle>
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>
<bundle>mvn:org.hibernate.common/hibernate-commons-annotations/4.0.5.Final</bundle>

View File

@ -68,9 +68,6 @@
org.apache.karaf.shell.commands,
org.h2,
javax.persistence;version="[1.0.0,2.1.0]",
<!-- Needed for proxying's Javassist enhancement during runtime -->
org.hibernate.proxy,
javassist.util.proxy,
*
</Import-Package>
</instructions>

View File

@ -41,7 +41,6 @@
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
<bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle>
<bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle>
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>
<bundle>mvn:org.hibernate.common/hibernate-commons-annotations/4.0.5.Final</bundle>

View File

@ -76,9 +76,6 @@
org.hibernate.cfg,
org.hibernate.service,
javax.persistence;version="[1.0.0,2.1.0]",
<!-- Needed for proxy enhancement during runtime -->
org.hibernate.proxy,
javassist.util.proxy,
*
</Import-Package>
</instructions>

View File

@ -434,7 +434,7 @@ Enable lazy loading feature in runtime bytecode enhancement. This way, even basi
Enable association management feature in runtime bytecode enhancement which automatically synchronizes a bidirectional association when only one side is changed.
`*hibernate.bytecode.provider*` (e.g. `bytebuddy` (default value))::
The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/bytecode/spi/BytecodeProvider.html[`BytecodeProvider`] built-in implementation flavor. Currently, only `bytebuddy` and `javassist` are valid values; `bytebuddy` is the default and recommended choice; `javassist` will be removed soon.
The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/bytecode/spi/BytecodeProvider.html[`BytecodeProvider`] built-in implementation flavor. Currently, only `bytebuddy` is a valid value, as older deprecated options have been removed.
`*hibernate.bytecode.use_reflection_optimizer*` (e.g. `true` or `false` (default value))::
Should we use reflection optimization? The reflection optimizer implements the https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/bytecode/spi/ReflectionOptimizer.html[`ReflectionOptimizer`] interface and improves entity instantiation and property getter/setter calls.

View File

@ -455,10 +455,9 @@ Hibernate will trigger a Persistence Context flush if there are pending `Account
==== Define a custom entity proxy
By default, when it needs to use a proxy instead of the actual POJO, Hibernate is going to use a Bytecode manipulation library like
https://jboss-javassist.github.io/javassist/[Javassist] or
https://bytebuddy.net/[Byte Buddy].
However, if the entity class is final, Javassist will not create a proxy and you will get a POJO even when you only need a proxy reference.
However, if the entity class is final, a proxy will not be created; you will get a POJO even when you only need a proxy reference.
In this case, you could proxy an interface that this particular entity implements, as illustrated by the following example.
[[entity-proxy-interface-mapping]]

View File

@ -93,7 +93,6 @@ That `DataSource` is then used by your `persistence.xml` persistence-unit. The f
Your bundle's manifest will need to import, at a minimum:
* `javax.persistence`
* `org.hibernate.proxy` and `javassist.util.proxy`, due to Hibernate's ability to return proxies for lazy initialization (Javassist enhancement occurs on the entity's `ClassLoader` during runtime).
=== Obtaining an EntityManger
@ -123,7 +122,6 @@ Similar to any other JPA setup, your bundle must include a `persistence.xml` fil
Your bundle's manifest will need to import, at a minimum:
* `javax.persistence`
* `org.hibernate.proxy` and `javassist.util.proxy`, due to Hibernate's ability to return proxies for lazy initialization (Javassist enhancement occurs on the entity's `ClassLoader` during runtime)
* JDBC driver package (example: `org.h2`)
* `org.osgi.framework`, necessary to discover the `EntityManagerFactory` (described below)
@ -157,7 +155,6 @@ Native Hibernate use is also supported. The client bundle is responsible for man
Your bundle's manifest will need to import, at a minimum:
* `javax.persistence`
* `org.hibernate.proxy` and `javassist.util.proxy`, due to Hibernate's ability to return proxies for lazy initialization (Javassist enhancement occurs on the entity's `ClassLoader` during runtime)
* JDBC driver package (example: `org.h2`)
* `org.osgi.framework`, necessary to discover the `SessionFactory` (described below)
* `org.hibernate.*` packages, as necessary (ex: cfg, criterion, service, etc.)

View File

@ -77,7 +77,6 @@ dependencies {
testImplementation libraries.byteman_bmunit
testRuntimeOnly libraries.log4j2
testRuntimeOnly libraries.javassist
testRuntimeOnly libraries.byteBuddy
//Databases

View File

@ -27,7 +27,6 @@ ext {
weldVersion = '3.1.5.Final'
jakartaWeldVersion = '4.0.1.SP1'
javassistVersion = '3.27.0-GA'
byteBuddyVersion = '1.11.12'
agroalVersion = '1.9'
@ -70,9 +69,6 @@ ext {
// Dom4J
dom4j: 'org.dom4j:dom4j:2.1.3@jar',
// Javassist
javassist: "org.javassist:javassist:${javassistVersion}",
// Byte Buddy
byteBuddy: "net.bytebuddy:byte-buddy:${byteBuddyVersion}",

View File

@ -59,7 +59,6 @@ dependencies {
testRuntimeOnly "org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Final"
testRuntimeOnly libraries.jakarta_el
testRuntimeOnly 'jaxen:jaxen:1.1'
testRuntimeOnly libraries.javassist
testRuntimeOnly libraries.byteBuddy
testRuntimeOnly libraries.jakarta_weld
testRuntimeOnly libraries.atomikos

View File

@ -21,10 +21,6 @@ configurations {
tests {
description = 'Configuration for the produced test jar'
}
javassist {
description "Dependencies for compiling and running the Javassist tests in the `javassist` source-set"
}
}
@ -45,7 +41,6 @@ dependencies {
compileOnly libraries.validation
compileOnly libraries.ant
compileOnly libraries.cdi
compileOnly libraries.javassist
testImplementation project(':hibernate-testing')
testImplementation libraries.shrinkwrap_api
@ -71,7 +66,6 @@ dependencies {
testRuntimeOnly "org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Final"
testRuntimeOnly libraries.expression_language
testRuntimeOnly 'jaxen:jaxen:1.1'
// testRuntimeOnly libraries.javassist
testRuntimeOnly libraries.byteBuddy
testRuntimeOnly libraries.weld
testRuntimeOnly libraries.atomikos
@ -163,14 +157,6 @@ sourceSets {
srcDir 'src/test/bundles'
}
}
testJavassist {
// define the testJavassist source-set
java {
compileClasspath += main.output + test.output + configurations.javassist
runtimeClasspath += main.output + test.output + configurations.javassist
}
}
}
xjc {

View File

@ -14,7 +14,7 @@ import org.hibernate.service.Service;
* An interface for factories of {@link ProxyFactory proxy factory} instances.
* <p/>
* Currently used to abstract from the tuplizer whether we are using Byte Buddy or
* not for lazy proxy generation.
* possibly another implementation (in the future?) for lazy proxy generation.
*
* @author Steve Ebersole
*/

View File

@ -1497,9 +1497,8 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
*/
String CHECK_NULLABILITY = "hibernate.check_nullability";
/**
* Pick which bytecode enhancing library to use. Currently only supports bytebuddy.
* Pick which bytecode enhancing library to use. Currently supports only bytebuddy, bytebuddy being the default since version 5.3.
*/
String BYTECODE_PROVIDER = "hibernate.bytecode.provider";

View File

@ -14,6 +14,10 @@ import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.NullOrdering;
import org.hibernate.query.TemporalUnit;
@ -25,6 +29,8 @@ import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.type.StandardBasicTypes;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Iterator;
import java.util.Map;
@ -515,4 +521,23 @@ public class CockroachDialect extends Dialect {
public RowLockStrategy getWriteRowLockStrategy() {
return getVersion() >= 2010 ? RowLockStrategy.TABLE : RowLockStrategy.NONE;
}
@Override
public NameQualifierSupport getNameQualifierSupport() {
// This method is overridden so the correct value will be returned when
// DatabaseMetaData is not available.
return NameQualifierSupport.SCHEMA;
}
@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
throws SQLException {
if ( dbMetaData == null ) {
builder.setUnquotedCaseStrategy( IdentifierCaseStrategy.LOWER );
builder.setQuotedCaseStrategy( IdentifierCaseStrategy.MIXED );
}
return super.buildIdentifierHelper( builder, dbMetaData );
}
}

View File

@ -11,6 +11,7 @@ import org.hibernate.dialect.function.FieldFunction;
import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
import org.hibernate.query.NullOrdering;
import org.hibernate.query.NullPrecedence;
import org.hibernate.PessimisticLockException;
@ -837,6 +838,11 @@ public class MySQLDialect extends Dialect {
};
}
@Override
public NameQualifierSupport getNameQualifierSupport() {
return NameQualifierSupport.CATALOG;
}
@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
throws SQLException {

View File

@ -33,6 +33,7 @@ import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
@ -350,6 +351,18 @@ public class PostgreSQLDialect extends Dialect {
}
}
@Override
public NameQualifierSupport getNameQualifierSupport() {
// This method is overridden so the correct value will be returned when
// DatabaseMetaData is not available.
return NameQualifierSupport.SCHEMA;
}
@Override
public String getCurrentSchemaCommand() {
return "select current_schema()";
}
@Override
public boolean supportsIfExistsBeforeTableName() {
return getVersion() >= 820;

View File

@ -1822,9 +1822,7 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Detaching an uninitialized collection with enabled filters from a session: %s", id = 506)
void enabledFiltersWhenDetachFromSession(String collectionInfoString);
@LogMessage(level = WARN)
@Message(value = "The Javassist based BytecodeProvider is deprecated. Please switch to using the ByteBuddy based BytecodeProvider, " +
"which is the default since Hibernate ORM 5.3. The Javassist one will be removed soon.", id = 507)
void warnUsingJavassistBytecodeProviderIsDeprecated();
@Message(value = "The Javassist based BytecodeProvider has been removed: remove the `hibernate.bytecode.provider` configuration property to switch to the default provider", id = 508)
HibernateException usingRemovedJavassistBytecodeProvider();
}

View File

@ -23,7 +23,7 @@ import org.hibernate.tool.schema.extract.spi.InformationExtractor;
import org.hibernate.tool.schema.extract.spi.NameSpaceTablesInformation;
import org.hibernate.tool.schema.extract.spi.SequenceInformation;
import org.hibernate.tool.schema.extract.spi.TableInformation;
import org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
/**
* @author Steve Ebersole
@ -31,7 +31,7 @@ import org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl;
public class DatabaseInformationImpl
implements DatabaseInformation, ExtractionContext.DatabaseObjectAccess {
private final JdbcEnvironment jdbcEnvironment;
private final ImprovedExtractionContextImpl extractionContext;
private final ExtractionContext extractionContext;
private final InformationExtractor extractor;
private final Map<QualifiedSequenceName, SequenceInformation> sequenceInformationMap = new HashMap<>();
@ -40,10 +40,10 @@ public class DatabaseInformationImpl
ServiceRegistry serviceRegistry,
JdbcEnvironment jdbcEnvironment,
DdlTransactionIsolator ddlTransactionIsolator,
Namespace.Name defaultNamespace) throws SQLException {
Namespace.Name defaultNamespace,
SchemaManagementTool tool) throws SQLException {
this.jdbcEnvironment = jdbcEnvironment;
this.extractionContext = new ImprovedExtractionContextImpl(
this.extractionContext = tool.getExtractionTool().createExtractionContext(
serviceRegistry,
jdbcEnvironment,
ddlTransactionIsolator,
@ -52,8 +52,7 @@ public class DatabaseInformationImpl
this
);
// todo : make this pluggable
this.extractor = new InformationExtractorJdbcDatabaseMetaDataImpl( extractionContext );
this.extractor = tool.getExtractionTool().createInformationExtractor( extractionContext );
// because we do not have defined a way to locate sequence info by name
initializeSequences();

View File

@ -36,25 +36,20 @@ public class SequenceInformationExtractorLegacyImpl implements SequenceInformati
return SequenceInformationExtractorNoOpImpl.INSTANCE.extractMetadata( extractionContext );
}
final IdentifierHelper identifierHelper = extractionContext.getJdbcEnvironment().getIdentifierHelper();
final Statement statement = extractionContext.getJdbcConnection().createStatement();
try {
final ResultSet resultSet = statement.executeQuery( lookupSql );
try {
return extractionContext.getQueryResults(
lookupSql,
null,
(ExtractionContext.ResultSetProcessor<Iterable<SequenceInformation>>) resultSet -> {
final IdentifierHelper identifierHelper = extractionContext.getJdbcEnvironment()
.getIdentifierHelper();
final List<SequenceInformation> sequenceInformationList = new ArrayList<>();
while ( resultSet.next() ) {
sequenceInformationList.add(
new SequenceInformationImpl(
new QualifiedSequenceName(
identifierHelper.toIdentifier(
resultSetCatalogName( resultSet )
),
identifierHelper.toIdentifier(
resultSetSchemaName( resultSet )
),
identifierHelper.toIdentifier(
resultSetSequenceName( resultSet )
)
identifierHelper.toIdentifier( resultSetCatalogName( resultSet ) ),
identifierHelper.toIdentifier( resultSetSchemaName( resultSet ) ),
identifierHelper.toIdentifier( resultSetSequenceName( resultSet ) )
),
resultSetStartValueSize( resultSet ),
resultSetMinValue( resultSet ),
@ -65,21 +60,7 @@ public class SequenceInformationExtractorLegacyImpl implements SequenceInformati
}
return sequenceInformationList;
}
finally {
try {
resultSet.close();
}
catch (SQLException ignore) {
}
}
}
finally {
try {
statement.close();
}
catch (SQLException ignore) {
}
}
);
}
protected String sequenceNameColumn() {

View File

@ -8,8 +8,8 @@ package org.hibernate.tool.schema.extract.internal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.hibernate.boot.model.relational.QualifiedSequenceName;
@ -42,60 +42,49 @@ public class SequenceInformationExtractorMariaDBDatabaseImpl extends SequenceInf
return SequenceInformationExtractorNoOpImpl.INSTANCE.extractMetadata(extractionContext);
}
final IdentifierHelper identifierHelper = extractionContext.getJdbcEnvironment().getIdentifierHelper();
final List<SequenceInformation> sequenceInformationList = new ArrayList<>();
final List<String> sequenceNames = new ArrayList<>();
try (
final Statement statement = extractionContext.getJdbcConnection().createStatement();
final ResultSet resultSet = statement.executeQuery( lookupSql )
) {
final List<String> sequenceNames = extractionContext.getQueryResults( lookupSql, null, resultSet -> {
final List<String> sequences = new ArrayList<>();
while ( resultSet.next() ) {
sequenceNames.add( resultSetSequenceName( resultSet ) );
}
sequences.add( resultSetSequenceName( resultSet ) );
}
return sequences;
});
if ( !sequenceNames.isEmpty() ) {
StringBuilder sequenceInfoQueryBuilder = new StringBuilder();
for ( String sequenceName : sequenceNames ) {
if ( sequenceInfoQueryBuilder.length() > 0 ) {
sequenceInfoQueryBuilder.append( UNION_ALL );
}
sequenceInfoQueryBuilder.append( String.format( SQL_SEQUENCE_QUERY, sequenceName ) );
}
int index = 0;
try (
final Statement statement = extractionContext.getJdbcConnection().createStatement();
final ResultSet resultSet = statement.executeQuery( sequenceInfoQueryBuilder.toString() )
) {
return extractionContext.getQueryResults(
sequenceInfoQueryBuilder.toString(),
null,
(ExtractionContext.ResultSetProcessor<Iterable<SequenceInformation>>) resultSet -> {
final List<SequenceInformation> sequenceInformationList = new ArrayList<>();
final IdentifierHelper identifierHelper = extractionContext.getJdbcEnvironment()
.getIdentifierHelper();
while ( resultSet.next() ) {
SequenceInformation sequenceInformation = new SequenceInformationImpl(
new QualifiedSequenceName(
null,
null,
identifierHelper.toIdentifier(
resultSetSequenceName(resultSet)
)
identifierHelper.toIdentifier( resultSetSequenceName(resultSet) )
),
resultSetStartValueSize(resultSet),
resultSetMinValue(resultSet),
resultSetMaxValue(resultSet),
resultSetIncrementValue(resultSet)
);
sequenceInformationList.add(sequenceInformation);
}
}
}
return sequenceInformationList;
});
}
return Collections.emptyList();
}
protected String resultSetSequenceName(ResultSet resultSet) throws SQLException {

View File

@ -8,6 +8,9 @@ package org.hibernate.tool.schema.extract.spi;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.Incubating;
import org.hibernate.boot.model.naming.Identifier;
@ -21,6 +24,7 @@ import org.hibernate.service.ServiceRegistry;
* well as to delegates needed in performing extraction.
*
* @author Steve Ebersole
* @author Gail Badner
*/
@Incubating
public interface ExtractionContext {
@ -29,9 +33,31 @@ public interface ExtractionContext {
Connection getJdbcConnection();
DatabaseMetaData getJdbcDatabaseMetaData();
@Incubating
default <T> T getQueryResults(
String queryString,
Object[] positionalParameters,
ResultSetProcessor<T> resultSetProcessor) throws SQLException {
try (PreparedStatement statement = getJdbcConnection().prepareStatement( queryString )) {
if ( positionalParameters != null ) {
for ( int i = 0 ; i < positionalParameters.length ; i++ ) {
statement.setObject( i + 1, positionalParameters[i] );
}
}
try (ResultSet resultSet = statement.executeQuery()) {
return resultSetProcessor.process( resultSet );
}
}
}
Identifier getDefaultCatalog();
Identifier getDefaultSchema();
@Incubating
interface ResultSetProcessor<T> {
T process(ResultSet resultSet) throws SQLException;
}
/**
* In conjunction with {@link #getDatabaseObjectAccess()} provides access to
* information about known database objects to the extractor.

View File

@ -102,7 +102,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
final DatabaseInformation databaseInformation = Helper.buildDatabaseInformation(
tool.getServiceRegistry(),
ddlTransactionIsolator,
metadata.getDatabase().getDefaultNamespace().getName()
metadata.getDatabase().getDefaultNamespace().getName(),
tool
);
final GenerationTarget[] targets = tool.buildGenerationTargets(

View File

@ -61,11 +61,11 @@ public abstract class AbstractSchemaValidator implements SchemaValidator {
final JdbcContext jdbcContext = tool.resolveJdbcContext( options.getConfigurationValues() );
final DdlTransactionIsolator isolator = tool.getDdlTransactionIsolator( jdbcContext );
final DatabaseInformation databaseInformation = Helper.buildDatabaseInformation(
tool.getServiceRegistry(),
isolator,
metadata.getDatabase().getDefaultNamespace().getName()
metadata.getDatabase().getDefaultNamespace().getName(),
tool
);
try {

View File

@ -33,6 +33,7 @@ import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromUrl;
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToFile;
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToUrl;
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToWriter;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
import org.hibernate.tool.schema.spi.ScriptSourceInput;
import org.hibernate.tool.schema.spi.ScriptTargetOutput;
@ -176,14 +177,16 @@ public class Helper {
public static DatabaseInformation buildDatabaseInformation(
ServiceRegistry serviceRegistry,
DdlTransactionIsolator ddlTransactionIsolator,
Namespace.Name defaultNamespace) {
Namespace.Name defaultNamespace,
SchemaManagementTool tool) {
final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
try {
return new DatabaseInformationImpl(
serviceRegistry,
jdbcEnvironment,
ddlTransactionIsolator,
defaultNamespace
defaultNamespace,
tool
);
}
catch (SQLException e) {

View File

@ -9,12 +9,14 @@ package org.hibernate.tool.schema.internal;
import java.sql.Connection;
import java.util.Map;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
@ -27,12 +29,17 @@ import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tool.schema.JdbcMetadaAccessStrategy;
import org.hibernate.tool.schema.TargetType;
import org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl;
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
import org.hibernate.tool.schema.extract.spi.InformationExtractor;
import org.hibernate.tool.schema.internal.exec.GenerationTarget;
import org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase;
import org.hibernate.tool.schema.internal.exec.GenerationTargetToScript;
import org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout;
import org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl;
import org.hibernate.tool.schema.internal.exec.JdbcConnectionAccessProvidedConnectionImpl;
import org.hibernate.tool.schema.internal.exec.JdbcContext;
import org.hibernate.tool.schema.spi.ExtractionTool;
import org.hibernate.tool.schema.spi.SchemaCreator;
import org.hibernate.tool.schema.spi.SchemaDropper;
import org.hibernate.tool.schema.spi.SchemaFilterProvider;
@ -114,6 +121,11 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
this.customTarget = generationTarget;
}
@Override
public ExtractionTool getExtractionTool() {
return HibernateExtractionTool.INSTANCE;
}
GenerationTarget getCustomDatabaseGenerationTarget() {
return customTarget;
}
@ -176,7 +188,10 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
}
if ( targetDescriptor.getTargetTypes().contains( TargetType.DATABASE ) ) {
targets[index] = new GenerationTargetToDatabase( ddlTransactionIsolator, false );
targets[index] = customTarget == null
? new GenerationTargetToDatabase( ddlTransactionIsolator, false )
: customTarget;
index++;
}
return targets;
@ -361,4 +376,34 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
}
}
private static class HibernateExtractionTool implements ExtractionTool {
private static final HibernateExtractionTool INSTANCE = new HibernateExtractionTool();
private HibernateExtractionTool() {
}
@Override
public ExtractionContext createExtractionContext(
ServiceRegistry serviceRegistry,
JdbcEnvironment jdbcEnvironment,
DdlTransactionIsolator ddlTransactionIsolator,
Identifier defaultCatalog,
Identifier defaultSchema,
ExtractionContext.DatabaseObjectAccess databaseObjectAccess) {
return new ImprovedExtractionContextImpl(
serviceRegistry,
jdbcEnvironment,
ddlTransactionIsolator,
defaultCatalog,
defaultSchema,
databaseObjectAccess
);
}
@Override
public InformationExtractor createInformationExtractor(ExtractionContext extractionContext) {
return new InformationExtractorJdbcDatabaseMetaDataImpl( extractionContext );
}
}
}

View File

@ -0,0 +1,35 @@
/*
* 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.tool.schema.spi;
import org.hibernate.Incubating;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
import org.hibernate.tool.schema.extract.spi.InformationExtractor;
/**
* Encapsulates the functionality for extracting database metadata used by
* {@link SchemaManagementTool}.
*
* @author Gail Badner
*/
@Incubating
public interface ExtractionTool {
ExtractionContext createExtractionContext(
ServiceRegistry serviceRegistry,
JdbcEnvironment jdbcEnvironment,
DdlTransactionIsolator ddlTransactionIsolator,
Identifier defaultCatalog,
Identifier defaultSchema,
ExtractionContext.DatabaseObjectAccess databaseObjectAccess);
InformationExtractor createInformationExtractor(ExtractionContext extractionContext);
}

View File

@ -32,4 +32,6 @@ public interface SchemaManagementTool extends Service {
* @param generationTarget the custom instance to use.
*/
void setCustomDatabaseGenerationTarget(GenerationTarget generationTarget);
ExtractionTool getExtractionTool();
}

View File

@ -19,7 +19,7 @@ import org.junit.Assert;
import org.junit.Test;
/**
* Tests if bytebuddy instrumentation is done with the proper classloader for entities with proxy class. The classloader
* Tests if instrumentation is done with the proper classloader for entities with proxy class. The classloader
* of {@link HibernateProxy} will not see {@link IPerson}, since it is only accessible from this package. But: the
* classloader of {@link IPerson} will see {@link HibernateProxy}, so instrumentation will only work if this classloader
* is chosen for creating the instrumented proxy class. We need to check the class of a loaded object though, since

View File

@ -17,6 +17,7 @@ import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl;
@ -24,7 +25,9 @@ import org.hibernate.tool.schema.extract.internal.ExtractionContextImpl;
import org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl;
import org.hibernate.tool.schema.extract.spi.DatabaseInformation;
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
import org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl;
import org.hibernate.tool.schema.internal.exec.JdbcContext;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
import org.junit.After;
import org.junit.Test;
@ -122,8 +125,10 @@ public class TestExtraPhysicalTableTypes {
ssr,
database.getJdbcEnvironment(),
ddlTransactionIsolator,
database.getDefaultNamespace().getName()
database.getDefaultNamespace().getName(),
database.getServiceRegistry().getService( SchemaManagementTool.class )
);
ExtractionContextImpl extractionContext = new ExtractionContextImpl(
ssr,
database.getJdbcEnvironment(),

View File

@ -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>.
*/
package org.hibernate.test.bytecode.javassist;
import java.text.ParseException;
import java.util.Date;
/**
* @author Steve Ebersole
*/
public class Bean {
private String someString;
private Long someLong;
private Integer someInteger;
private Date someDate;
private long somelong;
private int someint;
private Object someObject;
public String getSomeString() {
return someString;
}
public void setSomeString(String someString) {
this.someString = someString;
}
public Long getSomeLong() {
return someLong;
}
public void setSomeLong(Long someLong) {
this.someLong = someLong;
}
public Integer getSomeInteger() {
return someInteger;
}
public void setSomeInteger(Integer someInteger) {
this.someInteger = someInteger;
}
public Date getSomeDate() {
return someDate;
}
public void setSomeDate(Date someDate) {
this.someDate = someDate;
}
public long getSomelong() {
return somelong;
}
public void setSomelong(long somelong) {
this.somelong = somelong;
}
public int getSomeint() {
return someint;
}
public void setSomeint(int someint) {
this.someint = someint;
}
public Object getSomeObject() {
return someObject;
}
public void setSomeObject(Object someObject) {
this.someObject = someObject;
}
public void throwException() throws ParseException {
throw new ParseException( "you asked for it...", 0 );
}
}

View File

@ -1,92 +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>.
*/
package org.hibernate.test.bytecode.javassist;
import java.util.Date;
import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.Setter;
/**
* @author Steve Ebersole
*/
public class BeanReflectionHelper {
public static final Object[] TEST_VALUES = new Object[] {
"hello", new Long(1), new Integer(1), new Date(), new Long(1), new Integer(1), new Object()
};
private static final String[] getterNames = new String[7];
private static final String[] setterNames = new String[7];
private static final Class[] types = new Class[7];
static {
final PropertyAccessStrategyBasicImpl propertyAccessStrategy = new PropertyAccessStrategyBasicImpl();
PropertyAccess propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someString" );
Getter getter = propertyAccess.getGetter();
Setter setter = propertyAccess.getSetter();
getterNames[0] = getter.getMethodName();
types[0] = getter.getReturnType();
setterNames[0] = setter.getMethodName();
propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someLong" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[1] = getter.getMethodName();
types[1] = getter.getReturnType();
setterNames[1] = setter.getMethodName();
propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someInteger" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[2] = getter.getMethodName();
types[2] = getter.getReturnType();
setterNames[2] = setter.getMethodName();
propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someDate" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[3] = getter.getMethodName();
types[3] = getter.getReturnType();
setterNames[3] = setter.getMethodName();
propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "somelong" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[4] = getter.getMethodName();
types[4] = getter.getReturnType();
setterNames[4] = setter.getMethodName();
propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someint" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[5] = getter.getMethodName();
types[5] = getter.getReturnType();
setterNames[5] = setter.getMethodName();
propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someObject" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[6] = getter.getMethodName();
types[6] = getter.getReturnType();
setterNames[6] = setter.getMethodName();
}
public static String[] getGetterNames() {
return getterNames;
}
public static String[] getSetterNames() {
return setterNames;
}
public static Class[] getTypes() {
return types;
}
}

View File

@ -1,30 +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>.
*/
package org.hibernate.test.bytecode.javassist;
import org.hibernate.bytecode.internal.javassist.BulkAccessor;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
/**
* @author Steve Ebersole
*/
// Extracted from org.hibernate.test.bytecode.ReflectionOptimizerTest.
// I (Yoann) don't know what this tests does, but it's definitely specific to javassist.
public class BulkAccessorTest extends BaseUnitTestCase {
@Test
public void testBulkAccessorDirectly() {
BulkAccessor bulkAccessor = BulkAccessor.create(
Bean.class,
BeanReflectionHelper.getGetterNames(),
BeanReflectionHelper.getSetterNames(),
BeanReflectionHelper.getTypes()
);
}
}

View File

@ -13,8 +13,6 @@ apply plugin: 'org.hibernate.matrix-test'
dependencies {
api project( ':hibernate-core' )
implementation libraries.commons_annotations
// TODO HHH-13703: get rid of this dependency
implementation libraries.dom4j

View File

@ -77,7 +77,7 @@ public abstract class EntityTools {
return null;
}
else if ( HibernateProxy.class.isAssignableFrom( clazz ) ) {
// Get the source class of Bytebuddy proxy instance.
// Get the source class of the proxy instance.
return (Class<T>) clazz.getSuperclass();
}
return clazz;

View File

@ -22,11 +22,4 @@ sourceSets {
setSrcDirs( ['src/test/java','src/test/resources'] )
}
}
testJavassist {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
}

View File

@ -50,7 +50,6 @@ task processPluginXml(type: Copy) {
+ generateMavenDependency(libraries.antlr)\
+ generateMavenDependency(libraries.jta)\
+ generateMavenDependency(libraries.commons_annotations)\
+ generateMavenDependency(libraries.javassist)\
+ generateMavenDependency(libraries.byteBuddy)\
+ generateMavenDependency(libraries.logging)\
+ generateMavenDependency("org.hibernate:hibernate-core:" + project.version)])

View File

@ -34,7 +34,6 @@ dependencies {
implementation project( ':hibernate-core' )
implementation libraries.jpa
implementation libraries.javassist
implementation libraries.byteBuddy
implementation gradleApi()
implementation localGroovy()