From e9f2c02140893c0b8e07e89adf9019831ef4f3e7 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Wed, 1 Apr 2020 16:56:57 -0400 Subject: [PATCH] HHH-13886 Revert behavior changes introduced by HHH-10844 --- .../metadata/AuditMetadataGenerator.java | 6 +-- .../metadata/BasicMetadataGenerator.java | 2 +- .../metadata/IdMetadataGenerator.java | 2 +- .../internal/metadata/MetadataTools.java | 46 +++---------------- .../basic/BasicTypeColumnDefinitionTest.java | 5 +- 5 files changed, 15 insertions(+), 46 deletions(-) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditMetadataGenerator.java index 89d69df8ad..2a4afc32c6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditMetadataGenerator.java @@ -460,7 +460,7 @@ public final class AuditMetadataGenerator { } final Element joinKey = joinElement.addElement( "key" ); - MetadataTools.addColumns( joinKey, join.getKey().getColumnIterator(), metadata ); + MetadataTools.addColumns( joinKey, join.getKey().getColumnIterator() ); MetadataTools.addColumn( joinKey, verEntCfg.getRevisionFieldName(), null, null, null, null, null, null ); } } @@ -509,7 +509,7 @@ public final class AuditMetadataGenerator { if ( pc.getDiscriminator() != null ) { final Element discriminatorElement = classMapping.addElement( "discriminator" ); // Database column or SQL formula allowed to distinguish entity types - MetadataTools.addColumnsOrFormulas( discriminatorElement, pc.getDiscriminator().getColumnIterator(), metadata ); + MetadataTools.addColumnsOrFormulas( discriminatorElement, pc.getDiscriminator().getColumnIterator() ); discriminatorElement.addAttribute( "type", pc.getDiscriminator().getType().getName() ); } @@ -633,7 +633,7 @@ public final class AuditMetadataGenerator { // Adding the "key" element with all id columns... final Element keyMapping = mappingData.getFirst().addElement( "key" ); - MetadataTools.addColumns( keyMapping, pc.getTable().getPrimaryKey().columnIterator(), metadata ); + MetadataTools.addColumns( keyMapping, pc.getTable().getPrimaryKey().columnIterator() ); // ... and the revision number column, read from the revision info relation mapping. keyMapping.add( (Element) cloneAndSetupRevisionInfoRelationMapping().element( "column" ).clone() ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java index 7bd79f533c..006225d41f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java @@ -116,7 +116,7 @@ public final class BasicMetadataGenerator { key ); - MetadataTools.addColumns( propMapping, value.getColumnIterator(), metadata ); + MetadataTools.addColumns( propMapping, value.getColumnIterator() ); return propMapping; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/IdMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/IdMetadataGenerator.java index fdcb7aec5b..0047dd6a69 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/IdMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/IdMetadataGenerator.java @@ -313,7 +313,7 @@ public final class IdMetadataGenerator { // schema and the base table schema when a @ManyToOne is present in an identifier. manyToOneElement.addAttribute( "foreign-key", "none" ); - MetadataTools.addColumns( manyToOneElement, value.getColumnIterator(), mainGenerator.getMetadata() ); + MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() ); return true; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java index 4999800909..b29750f9cb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java @@ -9,10 +9,6 @@ package org.hibernate.envers.configuration.internal.metadata; import java.util.Iterator; import javax.persistence.JoinColumn; -import org.hibernate.boot.Metadata; -import org.hibernate.dialect.Dialect; -import org.hibernate.engine.spi.Mapping; -import org.hibernate.envers.internal.EnversMessageLogger; import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.mapping.Column; import org.hibernate.mapping.Formula; @@ -22,8 +18,6 @@ import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.Element; -import org.jboss.logging.Logger; - /** * @author Adam Warski (adam at warski dot org) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) @@ -31,11 +25,6 @@ import org.jboss.logging.Logger; */ public final class MetadataTools { - private static final EnversMessageLogger LOG = Logger.getMessageLogger( - EnversMessageLogger.class, - MetadataTools.class.getName() - ); - private MetadataTools() { } @@ -297,17 +286,13 @@ public final class MetadataTools { return joinMapping; } - public static void addColumns(Element anyMapping, Iterator selectables, Metadata metadata) { - addColumns( anyMapping, selectables, metadata, metadata.getDatabase().getDialect() ); - } - - public static void addColumns(Element anyMapping, Iterator selectables, Mapping mapping, Dialect dialect) { + public static void addColumns(Element anyMapping, Iterator selectables) { while ( selectables.hasNext() ) { final Selectable selectable = (Selectable) selectables.next(); if ( selectable.isFormula() ) { throw new FormulaNotSupportedException(); } - addColumn( anyMapping, (Column) selectable, mapping, dialect ); + addColumn( anyMapping, (Column) selectable ); } } @@ -326,39 +311,21 @@ public final class MetadataTools { * * @param anyMapping parent element * @param column column descriptor - * @param mapping the metadata mapping - * @param dialect the dialect */ - public static void addColumn(Element anyMapping, Column column, Mapping mapping, Dialect dialect) { + public static void addColumn(Element anyMapping, Column column) { addColumn( anyMapping, column.getName(), column.getLength(), column.getScale(), column.getPrecision(), - resolveSqlType( column, mapping, dialect ), + column.getSqlType(), column.getCustomRead(), column.getCustomWrite(), column.isQuoted() ); } - private static String resolveSqlType(Column column, Mapping mapping, Dialect dialect) { - String columnDefinition = column.getSqlType(); - if ( !StringTools.isEmpty( columnDefinition ) ) { - final int sqlTypeCode = column.getSqlTypeCode( mapping ); - final String sqlType = dialect.getTypeName( sqlTypeCode, column.getLength(), column.getPrecision(), column.getScale() ); - LOG.infof( - "Column [%s] uses a column-definition of [%s], resolved sql-type as [%s].", - column.getName(), - columnDefinition, - sqlType - ); - columnDefinition = sqlType; - } - return columnDefinition; - } - @SuppressWarnings({"unchecked"}) private static void changeNamesInColumnElement(Element element, ColumnNameIterator columnNameIterator) { final Iterator properties = element.elementIterator(); @@ -434,13 +401,12 @@ public final class MetadataTools { * @param element Parent element. * @param columnIterator Iterator pointing at {@link org.hibernate.mapping.Column} and/or * {@link org.hibernate.mapping.Formula} objects. - * @param metadata The boot-time entity model metadata */ - public static void addColumnsOrFormulas(Element element, Iterator columnIterator, Metadata metadata) { + public static void addColumnsOrFormulas(Element element, Iterator columnIterator) { while ( columnIterator.hasNext() ) { final Object o = columnIterator.next(); if ( o instanceof Column ) { - addColumn( element, (Column) o, metadata, metadata.getDatabase().getDialect() ); + addColumn( element, (Column) o ); } else if ( o instanceof Formula ) { addFormula( element, (Formula) o ); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTypeColumnDefinitionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTypeColumnDefinitionTest.java index 25e78f3e6c..07d87ee47e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTypeColumnDefinitionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTypeColumnDefinitionTest.java @@ -18,6 +18,7 @@ import org.hibernate.envers.Audited; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Table; +import org.junit.ComparisonFailure; import org.junit.Test; import org.hibernate.testing.RequiresDialect; @@ -54,7 +55,9 @@ public class BasicTypeColumnDefinitionTest extends BaseEnversJPAFunctionalTestCa return new Class[] { BasicTypeContainer.class }; } - @Test + // By reverting changes for HHH-10844 to restore columnDefinition original behavior, this implies this test will + // now fail because the expected sql-type will once again be identical to the base table mapping. + @Test(expected = ComparisonFailure.class) @Priority(10) public void testMetadataBindings() { final Table auditTable = metadata().getEntityBinding( BasicTypeContainer.class.getName() + "_AUD" ).getTable();