HHH-10398 Allow MOD column naming to be driven by a strategy

* Fixed javadoc comments
* Various code suggested code changes from review
This commit is contained in:
Chris Cranford 2019-09-30 14:00:22 -04:00 committed by Chris Cranford
parent f78877a607
commit b606759e61
4 changed files with 11 additions and 14 deletions

View File

@ -10,7 +10,6 @@ import org.hibernate.envers.boot.spi.ModifiedColumnNamingStrategy;
import org.hibernate.envers.configuration.internal.GlobalConfiguration; import org.hibernate.envers.configuration.internal.GlobalConfiguration;
import org.hibernate.envers.configuration.internal.metadata.MetadataTools; import org.hibernate.envers.configuration.internal.metadata.MetadataTools;
import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData; import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData;
import org.hibernate.envers.internal.tools.StringTools;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Value; import org.hibernate.mapping.Value;
@ -30,9 +29,9 @@ import org.dom4j.Element;
* </ul> * </ul>
* *
* @author Chris Cranford * @author Chris Cranford
* @since 5.4.6 * @since 5.4.7
*/ */
public class ImprovedModifiedColumnNamingStrategy implements ModifiedColumnNamingStrategy { public class ImprovedModifiedColumnNamingStrategy extends LegacyModifiedColumnNamingStrategy {
@Override @Override
public void addModifiedColumns( public void addModifiedColumns(
GlobalConfiguration globalCfg, GlobalConfiguration globalCfg,
@ -48,7 +47,7 @@ public class ImprovedModifiedColumnNamingStrategy implements ModifiedColumnNamin
Selectable selectable = value.getColumnIterator().next(); Selectable selectable = value.getColumnIterator().next();
if ( selectable instanceof Column ) { if ( selectable instanceof Column ) {
// This should not be applied for formulas // This should not be applied for formulas
String columnName = propertyAuditingData.getModifiedFlagName(); final String columnName;
if ( !propertyAuditingData.isModifiedFlagNameExplicitlySpecified() ) { if ( !propertyAuditingData.isModifiedFlagNameExplicitlySpecified() ) {
columnName = ( (Column) selectable ).getName() + globalCfg.getModifiedFlagSuffix(); columnName = ( (Column) selectable ).getName() + globalCfg.getModifiedFlagSuffix();
} }
@ -70,11 +69,6 @@ public class ImprovedModifiedColumnNamingStrategy implements ModifiedColumnNamin
} }
// Default legacy behavior // Default legacy behavior
MetadataTools.addModifiedFlagProperty( super.addModifiedColumns( globalCfg, value, parent, propertyAuditingData );
parent,
propertyAuditingData.getName(),
globalCfg.getModifiedFlagSuffix(),
propertyAuditingData.getModifiedFlagName()
);
} }
} }

View File

@ -24,7 +24,7 @@ import org.dom4j.Element;
* This is the default Envers modified column naming behavior. * This is the default Envers modified column naming behavior.
* *
* @author Chris Cranford * @author Chris Cranford
* @since 5.4.6 * @since 5.4.7
*/ */
public class LegacyModifiedColumnNamingStrategy implements ModifiedColumnNamingStrategy { public class LegacyModifiedColumnNamingStrategy implements ModifiedColumnNamingStrategy {
@Override @Override
@ -33,10 +33,13 @@ public class LegacyModifiedColumnNamingStrategy implements ModifiedColumnNamingS
Value value, Value value,
Element parent, Element parent,
PropertyAuditingData propertyAuditingData) { PropertyAuditingData propertyAuditingData) {
String columnName = propertyAuditingData.getModifiedFlagName(); final String columnName;
if ( propertyAuditingData.isModifiedFlagNameExplicitlySpecified() ) { if ( propertyAuditingData.isModifiedFlagNameExplicitlySpecified() ) {
columnName = propertyAuditingData.getExplicitModifiedFlagName(); columnName = propertyAuditingData.getExplicitModifiedFlagName();
} }
else {
columnName = propertyAuditingData.getModifiedFlagName();
}
MetadataTools.addModifiedFlagProperty( MetadataTools.addModifiedFlagProperty(
parent, parent,
propertyAuditingData.getName(), propertyAuditingData.getName(),

View File

@ -17,7 +17,7 @@ import org.dom4j.Element;
* Defines a naming strategy for applying modified columns to the audited entity metamodel. * Defines a naming strategy for applying modified columns to the audited entity metamodel.
* *
* @author Chris Cranford * @author Chris Cranford
* @since 5.4.6 * @since 5.4.7
*/ */
@Incubating @Incubating
public interface ModifiedColumnNamingStrategy { public interface ModifiedColumnNamingStrategy {

View File

@ -139,7 +139,7 @@ public interface EnversSettings {
* *
* Defaults to {@link org.hibernate.envers.boot.internal.LegacyModifiedColumnNamingStrategy}. * Defaults to {@link org.hibernate.envers.boot.internal.LegacyModifiedColumnNamingStrategy}.
* *
* @since 5.4.6 * @since 5.4.7
*/ */
String MODIFIED_COLUMN_NAMING_STRATEGY = "org.hibernate.envers.modified_column_naming_strategy"; String MODIFIED_COLUMN_NAMING_STRATEGY = "org.hibernate.envers.modified_column_naming_strategy";
} }