HHH-13886 Revert behavior changes introduced by HHH-10844

This commit is contained in:
Chris Cranford 2020-04-01 16:56:57 -04:00 committed by Chris Cranford
parent 2f32169249
commit e9f2c02140
5 changed files with 15 additions and 46 deletions

View File

@ -460,7 +460,7 @@ public final class AuditMetadataGenerator {
} }
final Element joinKey = joinElement.addElement( "key" ); 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 ); MetadataTools.addColumn( joinKey, verEntCfg.getRevisionFieldName(), null, null, null, null, null, null );
} }
} }
@ -509,7 +509,7 @@ public final class AuditMetadataGenerator {
if ( pc.getDiscriminator() != null ) { if ( pc.getDiscriminator() != null ) {
final Element discriminatorElement = classMapping.addElement( "discriminator" ); final Element discriminatorElement = classMapping.addElement( "discriminator" );
// Database column or SQL formula allowed to distinguish entity types // 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() ); discriminatorElement.addAttribute( "type", pc.getDiscriminator().getType().getName() );
} }
@ -633,7 +633,7 @@ public final class AuditMetadataGenerator {
// Adding the "key" element with all id columns... // Adding the "key" element with all id columns...
final Element keyMapping = mappingData.getFirst().addElement( "key" ); 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. // ... and the revision number column, read from the revision info relation mapping.
keyMapping.add( (Element) cloneAndSetupRevisionInfoRelationMapping().element( "column" ).clone() ); keyMapping.add( (Element) cloneAndSetupRevisionInfoRelationMapping().element( "column" ).clone() );

View File

@ -116,7 +116,7 @@ public final class BasicMetadataGenerator {
key key
); );
MetadataTools.addColumns( propMapping, value.getColumnIterator(), metadata ); MetadataTools.addColumns( propMapping, value.getColumnIterator() );
return propMapping; return propMapping;
} }

View File

@ -313,7 +313,7 @@ public final class IdMetadataGenerator {
// schema and the base table schema when a @ManyToOne is present in an identifier. // schema and the base table schema when a @ManyToOne is present in an identifier.
manyToOneElement.addAttribute( "foreign-key", "none" ); manyToOneElement.addAttribute( "foreign-key", "none" );
MetadataTools.addColumns( manyToOneElement, value.getColumnIterator(), mainGenerator.getMetadata() ); MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() );
return true; return true;
} }

View File

@ -9,10 +9,6 @@ package org.hibernate.envers.configuration.internal.metadata;
import java.util.Iterator; import java.util.Iterator;
import javax.persistence.JoinColumn; 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.envers.internal.tools.StringTools;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Formula; import org.hibernate.mapping.Formula;
@ -22,8 +18,6 @@ import org.dom4j.Attribute;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.Element; import org.dom4j.Element;
import org.jboss.logging.Logger;
/** /**
* @author Adam Warski (adam at warski dot org) * @author Adam Warski (adam at warski dot org)
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
@ -31,11 +25,6 @@ import org.jboss.logging.Logger;
*/ */
public final class MetadataTools { public final class MetadataTools {
private static final EnversMessageLogger LOG = Logger.getMessageLogger(
EnversMessageLogger.class,
MetadataTools.class.getName()
);
private MetadataTools() { private MetadataTools() {
} }
@ -297,17 +286,13 @@ public final class MetadataTools {
return joinMapping; return joinMapping;
} }
public static void addColumns(Element anyMapping, Iterator<?> selectables, Metadata metadata) { public static void addColumns(Element anyMapping, Iterator<?> selectables) {
addColumns( anyMapping, selectables, metadata, metadata.getDatabase().getDialect() );
}
public static void addColumns(Element anyMapping, Iterator<?> selectables, Mapping mapping, Dialect dialect) {
while ( selectables.hasNext() ) { while ( selectables.hasNext() ) {
final Selectable selectable = (Selectable) selectables.next(); final Selectable selectable = (Selectable) selectables.next();
if ( selectable.isFormula() ) { if ( selectable.isFormula() ) {
throw new FormulaNotSupportedException(); 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 anyMapping parent element
* @param column column descriptor * @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( addColumn(
anyMapping, anyMapping,
column.getName(), column.getName(),
column.getLength(), column.getLength(),
column.getScale(), column.getScale(),
column.getPrecision(), column.getPrecision(),
resolveSqlType( column, mapping, dialect ), column.getSqlType(),
column.getCustomRead(), column.getCustomRead(),
column.getCustomWrite(), column.getCustomWrite(),
column.isQuoted() 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"}) @SuppressWarnings({"unchecked"})
private static void changeNamesInColumnElement(Element element, ColumnNameIterator columnNameIterator) { private static void changeNamesInColumnElement(Element element, ColumnNameIterator columnNameIterator) {
final Iterator<Element> properties = element.elementIterator(); final Iterator<Element> properties = element.elementIterator();
@ -434,13 +401,12 @@ public final class MetadataTools {
* @param element Parent element. * @param element Parent element.
* @param columnIterator Iterator pointing at {@link org.hibernate.mapping.Column} and/or * @param columnIterator Iterator pointing at {@link org.hibernate.mapping.Column} and/or
* {@link org.hibernate.mapping.Formula} objects. * {@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() ) { while ( columnIterator.hasNext() ) {
final Object o = columnIterator.next(); final Object o = columnIterator.next();
if ( o instanceof Column ) { if ( o instanceof Column ) {
addColumn( element, (Column) o, metadata, metadata.getDatabase().getDialect() ); addColumn( element, (Column) o );
} }
else if ( o instanceof Formula ) { else if ( o instanceof Formula ) {
addFormula( element, (Formula) o ); addFormula( element, (Formula) o );

View File

@ -18,6 +18,7 @@ import org.hibernate.envers.Audited;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.Priority;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.junit.ComparisonFailure;
import org.junit.Test; import org.junit.Test;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.RequiresDialect;
@ -54,7 +55,9 @@ public class BasicTypeColumnDefinitionTest extends BaseEnversJPAFunctionalTestCa
return new Class<?>[] { BasicTypeContainer.class }; 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) @Priority(10)
public void testMetadataBindings() { public void testMetadataBindings() {
final Table auditTable = metadata().getEntityBinding( BasicTypeContainer.class.getName() + "_AUD" ).getTable(); final Table auditTable = metadata().getEntityBinding( BasicTypeContainer.class.getName() + "_AUD" ).getTable();