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" );
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() );

View File

@ -116,7 +116,7 @@ public final class BasicMetadataGenerator {
key
);
MetadataTools.addColumns( propMapping, value.getColumnIterator(), metadata );
MetadataTools.addColumns( propMapping, value.getColumnIterator() );
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.
manyToOneElement.addAttribute( "foreign-key", "none" );
MetadataTools.addColumns( manyToOneElement, value.getColumnIterator(), mainGenerator.getMetadata() );
MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() );
return true;
}

View File

@ -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<Element> 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 );

View File

@ -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();