diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java b/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java index c5c77ff4eb..857ce15015 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java @@ -166,7 +166,7 @@ class TypeSafeActivator { for ( EntityBinding entityBinding : activationContext.getMetadata().getEntityBindings() ) { final String className = entityBinding.getEntity().getDescriptor().getName().toString(); - if ( className == null || className.length() == 0 ) { + if ( entityBinding.getEntity().getDescriptor() == null ) { continue; } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java index 52565d068b..d66b74d403 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java @@ -239,7 +239,7 @@ public abstract class PersistentClass implements Serializable, Filterable, MetaA } public void addProperty(Property p) { - properties.add(p); + properties.add( p ); declaredProperties.add(p); p.setPersistentClass(this); } @@ -879,7 +879,7 @@ public abstract class PersistentClass implements Serializable, Filterable, MetaA } public void addMappedsuperclassProperty(Property p) { - properties.add(p); + properties.add( p ); p.setPersistentClass(this); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java index 918ff8bf0c..d210ac986c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel; import java.util.Collection; import java.util.Map; +import java.util.UUID; import javax.persistence.NamedStoredProcedureQuery; @@ -61,6 +62,12 @@ public interface Metadata { */ SessionFactory buildSessionFactory(); + /** + * Gets the {@link UUID} for this metamodel. + * + * @return the UUID. + */ + UUID getUUID(); EntityBinding getEntityBinding(String entityName); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java index 6355dc3be0..0379329352 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import org.hibernate.AssertionFailure; import org.hibernate.DuplicateMappingException; @@ -36,6 +37,7 @@ import org.hibernate.EntityMode; import org.hibernate.MappingException; import org.hibernate.SessionFactory; import org.hibernate.annotations.common.util.StringHelper; +import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.CacheRegionDefinition; import org.hibernate.cache.spi.access.AccessType; @@ -117,6 +119,8 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; import org.jboss.logging.Logger; +import static org.hibernate.metamodel.spi.AdditionalJaxbRootProducer.AdditionalJaxbRootProducerContext; + /** * Represents the process of building a Metadata object. The main entry point is the * static {@link #build} @@ -126,7 +130,7 @@ import org.jboss.logging.Logger; public class MetadataBuildingProcess { private static final Logger log = Logger.getLogger( MetadataBuildingProcess.class ); - public static MetadataImpl build(MetadataSources sources, MetadataBuildingOptions options) { + public static MetadataImpl build(MetadataSources sources, final MetadataBuildingOptions options) { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // preliminary phases final IndexView jandexView = handleJandex( options, sources ); @@ -195,8 +199,19 @@ public class MetadataBuildingProcess { } final List bindResults = new ArrayList(); + final AdditionalJaxbRootProducerContext jaxbRootProducerContext = new AdditionalJaxbRootProducerContext() { + @Override + public IndexView getJandexIndex() { + return jandexView; + } + + @Override + public StandardServiceRegistry getServiceRegistry() { + return options.getServiceRegistry(); + } + }; for ( AdditionalJaxbRootProducer producer : classLoaderService.loadJavaServices( AdditionalJaxbRootProducer.class ) ) { - bindResults.addAll( producer.produceRoots( metadataCollector, jandexView ) ); + bindResults.addAll( producer.produceRoots( metadataCollector, jaxbRootProducerContext ) ); } final HbmMetadataSourceProcessorImpl processor = new HbmMetadataSourceProcessorImpl( rootBindingContext, bindResults ); final Binder binder = new Binder( rootBindingContext ); @@ -671,6 +686,7 @@ public class MetadataBuildingProcess { private final MetadataBuildingOptions options; private final TypeResolver typeResolver; + private final UUID uuid; private final Database database; private final ObjectNameNormalizer nameNormalizer; private final MutableIdentifierGeneratorFactory identifierGeneratorFactory; @@ -702,6 +718,7 @@ public class MetadataBuildingProcess { new HashMap(); public InFlightMetadataCollectorImpl(MetadataBuildingOptions options, TypeResolver typeResolver) { + this.uuid = UUID.randomUUID(); this.options = options; this.typeResolver = typeResolver; @@ -766,6 +783,10 @@ public class MetadataBuildingProcess { ); } + @Override + public UUID getUUID() { + return null; + } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1157,6 +1178,7 @@ public class MetadataBuildingProcess { options.getServiceRegistry(), database, typeResolver, + uuid, identifierGeneratorFactory, typeDefinitionMap, filterDefinitionMap, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java index f91dc3500b..c80a9a3bb0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java @@ -27,6 +27,7 @@ import java.io.Serializable; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import org.hibernate.AssertionFailure; import org.hibernate.MappingException; @@ -67,6 +68,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable { private final TypeResolver typeResolver; private final IdentifierGeneratorFactory identifierGeneratorFactory; + private final UUID uuid; + private final Map typeDefinitionMap = new HashMap(); private final Map filterDefinitionMap = new HashMap(); private final Map entityBindingMap = new HashMap(); @@ -85,6 +88,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { StandardServiceRegistry serviceRegistry, Database database, TypeResolver typeResolver, + UUID uuid, IdentifierGeneratorFactory identifierGeneratorFactory, Map typeDefinitionMap, Map filterDefinitionMap, @@ -102,6 +106,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { this.serviceRegistry = serviceRegistry; this.database = database; this.typeResolver = typeResolver; + this.uuid = uuid; this.identifierGeneratorFactory = identifierGeneratorFactory; if ( typeDefinitionMap != null ) { @@ -279,6 +284,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable { return getSessionFactoryBuilder().build(); } + @Override + public UUID getUUID() { + return null; + } + @Override public IdentifierGeneratorFactory getIdentifierGeneratorFactory() { return identifierGeneratorFactory; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java index b8bdd57558..f6a2e7f735 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java @@ -552,7 +552,9 @@ public class Binder { return null; } - final DotName descriptorTypeName = javaTypeDescriptorRepository.buildName( source.getTypeName() ); + final DotName descriptorTypeName = javaTypeDescriptorRepository.buildName( + typeHelper().determineJavaTypeName( source ) + ); final JavaTypeDescriptor javaTypeDescriptor = javaTypeDescriptorRepository.getType( descriptorTypeName ); if ( EntitySource.class.isInstance( source ) ) { @@ -1792,7 +1794,7 @@ public class Binder { if ( attribute != null ) { // validate its ok to use... if ( !Aggregate.class.isInstance( attribute.getSingularAttributeType() ) ) { - localBindingContext().makeMappingException( + throw localBindingContext().makeMappingException( "Found existing attribute on container for '" + attributeSource.getName() + "', but was expecting an Aggregate" ); @@ -1805,9 +1807,12 @@ public class Binder { compositeTypeDescriptor = attributeSource.getTypeDescriptor(); } else { + final EntityMode entityMode = + attributeBindingContainer.seekEntityBinding().getHierarchyDetails().getEntityMode(); compositeTypeDescriptor = typeHelper().determineJavaType( attributeSource, - attributeBindingContainer.getAttributeContainer() + attributeBindingContainer.getAttributeContainer(), + entityMode ); } composite = new Aggregate( compositeTypeDescriptor, null ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java index 365b87ddf4..9bfdbe441f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java @@ -33,6 +33,7 @@ import java.util.Map; import java.util.Properties; import org.hibernate.AssertionFailure; +import org.hibernate.EntityMode; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.internal.util.beans.BeanInfoHelper; @@ -45,6 +46,7 @@ import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.BasicPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.ComponentAttributeSource; import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.IdentifiableTypeSource; import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; @@ -808,6 +810,35 @@ class HibernateTypeHelper { return null; } + public String determineJavaTypeName(final IdentifiableTypeSource identifiableTypeSource) { + if ( identifiableTypeSource.getTypeName() == null ) { + if ( identifiableTypeSource.getHierarchy().getEntityMode() == EntityMode.MAP ) { + return Map.class.getName(); + + } + else { + return null; + } + } + else { + return identifiableTypeSource.getTypeName(); + } + } + + public JavaTypeDescriptor determineJavaType( + final ComponentAttributeSource attributeSource, + final AttributeContainer attributeContainer, + final EntityMode entityMode) { + if ( attributeSource.getTypeDescriptor() != null ) { + return attributeSource.getTypeDescriptor(); + } + else if ( entityMode == EntityMode.MAP ) { + return bindingContext().typeDescriptor( Map.class.getName() ); + } + else { + return determineJavaType( attributeSource, attributeContainer ); + } + } public JavaTypeDescriptor determineJavaType( final AttributeSource attributeSource, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/JandexHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/JandexHelper.java index f656c8cd08..5d0a981ea1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/JandexHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/JandexHelper.java @@ -689,6 +689,9 @@ public class JandexHelper { } returnValue = arr; } + else if ( type.isEnum() && String.class.isInstance( returnValue ) ) { + returnValue = Enum.valueOf( (Class) type, (String) returnValue ); + } return type.cast( nullIfUndefined( returnValue, type ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java index b18d76dcd8..1e8f137bea 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java @@ -202,4 +202,8 @@ class KeyManyToOneSourceImpl public boolean isCascadeDeleteEnabled() { return "cascade".equals( keyManyToOneElement.getOnDelete().value() ); } + + protected String getClassName() { + return keyManyToOneElement.getClazz(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AdditionalJaxbRootProducer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AdditionalJaxbRootProducer.java index 7a6c92814c..60162eb14c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AdditionalJaxbRootProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AdditionalJaxbRootProducer.java @@ -25,6 +25,8 @@ package org.hibernate.metamodel.spi; import java.util.List; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.service.ServiceRegistry; import org.hibernate.xml.spi.BindResult; import org.jboss.jandex.IndexView; @@ -41,9 +43,30 @@ public interface AdditionalJaxbRootProducer { * Produce and return the list of additional mappings to be processed. * * @param metadataCollector The metadata (for access to binding information). - * @param jandexIndex The Jandex annotation index + * @param context The context. * * @return List of additional mappings + * + * @see AdditionalJaxbRootProducerContext */ - public List produceRoots(InFlightMetadataCollector metadataCollector, IndexView jandexIndex); + public List produceRoots( + InFlightMetadataCollector metadataCollector, + AdditionalJaxbRootProducerContext context); + + public interface AdditionalJaxbRootProducerContext { + + /** + * Gets the Jandex annotation index. + * + * @return the Jandex annotation index + */ + public IndexView getJandexIndex(); + + /** + * Gets the service registry. + * + * @return The service registry. + */ + public StandardServiceRegistry getServiceRegistry(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java index 23349fcecc..11d0645d06 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; import org.hibernate.FetchMode; +import org.hibernate.metamodel.spi.relational.Value; /** * Basic contract describing the commonality between the various types of collection element mappings. @@ -52,6 +53,11 @@ public abstract class AbstractPluralAttributeElementBinding implements PluralAtt protected abstract RelationalValueBindingContainer getRelationalValueContainer(); + @Override + public List getValues() { + return getRelationalValueContainer().values(); + } + @Override public List getRelationalValueBindings() { return getRelationalValueContainer().relationalValueBindings(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeIndexBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeIndexBinding.java index 30d3acbfd3..57571f42ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeIndexBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeIndexBinding.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; import org.hibernate.AssertionFailure; +import org.hibernate.metamodel.spi.relational.Value; /** * @@ -44,6 +45,11 @@ public class BasicPluralAttributeIndexBinding extends AbstractPluralAttributeInd return relationalValueBindingContainer.relationalValueBindings(); } + @Override + public List getValues() { + return relationalValueBindingContainer.values(); + } + public void setRelationalValueBindings(List relationalValueBindings) { if ( relationalValueBindings == null || relationalValueBindings.isEmpty() ) { throw new AssertionFailure( "relationalValueBindings argument must be non-null and non-empty." ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeIndexBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeIndexBinding.java index ec87d55739..bf5451ada8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeIndexBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeIndexBinding.java @@ -30,6 +30,7 @@ import java.util.Map; import org.hibernate.metamodel.source.spi.MetaAttributeContext; import org.hibernate.metamodel.spi.domain.Aggregate; import org.hibernate.metamodel.spi.domain.SingularAttribute; +import org.hibernate.metamodel.spi.relational.Value; /** * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#AGGREGATE} elements @@ -90,4 +91,9 @@ public class CompositePluralAttributeIndexBinding extends AbstractPluralAttribut public List getRelationalValueBindings() { return compositeAttributeBindingContainer.getRelationalValueBindingContainer().relationalValueBindings(); } + + @Override + public List getValues() { + return compositeAttributeBindingContainer.getRelationalValueBindingContainer().values(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java index 60ff853e1b..20ba67e685 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java @@ -630,28 +630,33 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements public AttributeBinding[] getNonIdAttributeBindingClosure(){ // TODO: update size to account for joins if ( isRoot() ) { - return internalGetNonIdAttributeBindingClosure(); + return internalGetNonIdAttributeBindings(); } else { return ArrayHelper.join( superEntityBinding.getNonIdAttributeBindingClosure(), - internalGetNonIdAttributeBindingClosure() + internalGetNonIdAttributeBindings() ); } } - private AttributeBinding[] internalGetNonIdAttributeBindingClosure() { - List list = new ArrayList(); + public List getNonIdAttributeBindings() { + final List list = new ArrayList(); for ( final AttributeBinding ab : attributeBindings() ) { boolean isId = getHierarchyDetails().getEntityIdentifier().isIdentifierAttributeBinding( ab ); if ( !isId ) { list.add( ab ); } } - return list.toArray( new AttributeBinding[list.size()] ); + return list; } + private AttributeBinding[] internalGetNonIdAttributeBindings() { + final List list = getNonIdAttributeBindings(); + return list.toArray( new AttributeBinding[list.size()] ); + } + public List getDirectSubEntityBindings() { return subEntityBindings; } @@ -772,7 +777,7 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements results = ArrayHelper.join( results, - subEntityBinding.internalGetNonIdAttributeBindingClosure() + subEntityBinding.internalGetNonIdAttributeBindings() ); // TODO: if EntityBinding.attributeBindings() excludes joined attributes, then they need to be added here } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java index 42208ef53e..14b1efc332 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; import org.hibernate.FetchMode; +import org.hibernate.metamodel.spi.relational.Value; /** @@ -41,6 +42,8 @@ public interface PluralAttributeElementBinding { */ PluralAttributeBinding getPluralAttributeBinding(); + List getValues(); + /** * Retrieve the relational aspect of the element binding. Essentially describes the column(s) to which the * binding maps the elements diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java index 68683b8685..f462e536e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; import org.hibernate.metamodel.spi.domain.Type; +import org.hibernate.metamodel.spi.relational.Value; /** * @author Steve Ebersole @@ -43,6 +44,8 @@ public interface PluralAttributeIndexBinding { */ public List getRelationalValueBindings(); + List getValues(); + HibernateTypeDescriptor getHibernateTypeDescriptor(); Type getPluralAttributeIndexType(); diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index f684a090b9..3049b99762 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -225,6 +225,15 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } } + /** + * Gets the metadata. + * @return the metadata. + * @deprecated This should only be needed for testing and should ultimately be removed. + */ + public MetadataImplementor getMetadata() { + return metadata; + } + private SettingsImpl configure(StandardServiceRegistryBuilder ssrBuilder) { final SettingsImpl settings = new SettingsImpl(); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java index 09748c06b0..23893cab05 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java @@ -25,11 +25,11 @@ package org.hibernate.envers; import java.util.HashSet; import java.util.Set; +import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.FetchType; import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; import javax.persistence.MappedSuperclass; import org.hibernate.annotations.Fetch; @@ -45,7 +45,7 @@ import org.hibernate.annotations.FetchMode; @MappedSuperclass public class DefaultTrackingModifiedEntitiesRevisionEntity extends DefaultRevisionEntity { @ElementCollection(fetch = FetchType.EAGER) - @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) + @CollectionTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) @Column(name = "ENTITYNAME") @Fetch(FetchMode.JOIN) @ModifiedEntityNames diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AnnotationProxyBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AnnotationProxyBuilder.java new file mode 100644 index 0000000000..1aa312f452 --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AnnotationProxyBuilder.java @@ -0,0 +1,127 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.envers.configuration.internal; + +import java.lang.reflect.Array; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javassist.util.proxy.MethodHandler; +import javassist.util.proxy.ProxyFactory; +import javassist.util.proxy.ProxyObject; +import org.jboss.jandex.AnnotationInstance; + +import org.hibernate.HibernateException; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +public class AnnotationProxyBuilder { + private final Map proxyObjectMap = new HashMap(); + private final Map proxyFactoryMap = new HashMap(); + + public T getAnnotationProxy( + final AnnotationInstance annotationInstance, + final Class annotationClass, + final ClassLoaderService classLoaderService) { + T annotationProxy = (T) proxyObjectMap.get( annotationInstance ); + if ( annotationProxy == null ) { + annotationProxy = buildAnnotationProxy( annotationInstance, annotationClass, classLoaderService ); + proxyObjectMap.put( annotationInstance, annotationProxy ); + } + return annotationProxy; + } + + private T buildAnnotationProxy( + final AnnotationInstance annotationInstance, + final Class annotationClass, + final ClassLoaderService classLoaderService) { + try { + final Class annotation = annotationClass.getClassLoader().loadClass( annotationClass.getName() ); + final Class proxyClass = getProxyFactory( annotation ).createClass(); + final ProxyObject proxyObject = (ProxyObject) proxyClass.newInstance(); + proxyObject.setHandler( new MethodHandler() { + @Override + public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { + String executedMethodName = thisMethod.getName(); + if ( "toString".equals( executedMethodName ) ) { + return proxyClass.getName() + "@" + System.identityHashCode( self ); + } + final Class returnType = thisMethod.getReturnType(); + if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) { + final AnnotationInstance[] returnValues = JandexHelper.getValue( + annotationInstance, + executedMethodName, + AnnotationInstance[].class, + classLoaderService + ); + return buildAnnotationProxyArray( + returnValues, + returnType.getComponentType(), + classLoaderService + ); + } + return JandexHelper.getValue( + annotationInstance, + executedMethodName, + thisMethod.getReturnType(), + classLoaderService + ); + } + } ); + return (T) proxyObject; + } + catch ( Exception e ) { + throw new HibernateException( e ); + } + } + + @SuppressWarnings( {"unchecked"}) + private T[] buildAnnotationProxyArray( + final AnnotationInstance[] annotationInstances, + final Class annotationClass, + final ClassLoaderService classLoaderService) { + final T[] annotationProxyArray = (T[]) Array.newInstance( annotationClass, annotationInstances.length ); + for ( int i = 0 ; i < annotationInstances.length ; i++ ) { + annotationProxyArray[i] = buildAnnotationProxy( annotationInstances[i], annotationClass, classLoaderService ); + } + return annotationProxyArray; + } + + private ProxyFactory getProxyFactory(final Class annotation) { + ProxyFactory proxyFactory = proxyFactoryMap.get( annotation ); + if ( proxyFactory == null ) { + proxyFactory = new ProxyFactory(); + proxyFactoryMap.put( annotation, proxyFactory ); + } + proxyFactory.setInterfaces( new Class[] { annotation } ); + return proxyFactory; + } +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AuditEntitiesConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AuditEntitiesConfiguration.java index ae0a63010a..4db299091b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AuditEntitiesConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AuditEntitiesConfiguration.java @@ -25,11 +25,12 @@ package org.hibernate.envers.configuration.internal; import java.util.HashMap; import java.util.Map; -import java.util.Properties; +import org.hibernate.engine.config.spi.ConfigurationService; +import org.hibernate.engine.config.spi.StandardConverters; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.strategy.DefaultAuditStrategy; -import org.hibernate.internal.util.config.ConfigurationHelper; +import org.hibernate.service.ServiceRegistry; /** * Configuration of versions entities - names of fields, entities and tables created to store versioning information. @@ -62,36 +63,48 @@ public class AuditEntitiesConfiguration { private final String embeddableSetOrdinalPropertyName; - public AuditEntitiesConfiguration(Properties properties, String revisionInfoEntityName) { + public AuditEntitiesConfiguration(ServiceRegistry serviceRegistry, String revisionInfoEntityName) { this.revisionInfoEntityName = revisionInfoEntityName; - auditTablePrefix = ConfigurationHelper.getString( EnversSettings.AUDIT_TABLE_PREFIX, properties, "" ); - auditTableSuffix = ConfigurationHelper.getString( EnversSettings.AUDIT_TABLE_SUFFIX, properties, "_AUD" ); + final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class ); - auditStrategyName = ConfigurationHelper.getString( - EnversSettings.AUDIT_STRATEGY, properties, DefaultAuditStrategy.class.getName() + auditTablePrefix = configurationService.getSetting( + EnversSettings.AUDIT_TABLE_PREFIX, StandardConverters.STRING, "" + ); + auditTableSuffix = configurationService.getSetting( + EnversSettings.AUDIT_TABLE_SUFFIX, StandardConverters.STRING, "_AUD" + ); + + auditStrategyName = configurationService.getSetting( + EnversSettings.AUDIT_STRATEGY, StandardConverters.STRING, DefaultAuditStrategy.class.getName() ); originalIdPropName = "originalId"; - revisionFieldName = ConfigurationHelper.getString( EnversSettings.REVISION_FIELD_NAME, properties, "REV" ); + revisionFieldName = configurationService.getSetting( + EnversSettings.REVISION_FIELD_NAME, StandardConverters.STRING, "REV" + ); - revisionTypePropName = ConfigurationHelper.getString( - EnversSettings.REVISION_TYPE_FIELD_NAME, properties, "REVTYPE" + revisionTypePropName = configurationService.getSetting( + EnversSettings.REVISION_TYPE_FIELD_NAME, StandardConverters.STRING, "REVTYPE" ); revisionTypePropType = "byte"; - revisionEndFieldName = ConfigurationHelper.getString( - EnversSettings.AUDIT_STRATEGY_VALIDITY_END_REV_FIELD_NAME, properties, "REVEND" + revisionEndFieldName = configurationService.getSetting( + EnversSettings.AUDIT_STRATEGY_VALIDITY_END_REV_FIELD_NAME, StandardConverters.STRING, "REVEND" ); - revisionEndTimestampEnabled = ConfigurationHelper.getBoolean( - EnversSettings.AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP, properties, false + revisionEndTimestampEnabled = configurationService.getSetting( + EnversSettings.AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP, + StandardConverters.BOOLEAN, + false ); if ( revisionEndTimestampEnabled ) { - revisionEndTimestampFieldName = ConfigurationHelper.getString( - EnversSettings.AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME, properties, "REVEND_TSTMP" + revisionEndTimestampFieldName = configurationService.getSetting( + EnversSettings.AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME, + StandardConverters.STRING, + "REVEND_TSTMP" ); } else { @@ -103,8 +116,8 @@ public class AuditEntitiesConfiguration { revisionNumberPath = originalIdPropName + "." + revisionFieldName + ".id"; revisionPropBasePath = originalIdPropName + "." + revisionFieldName + "."; - embeddableSetOrdinalPropertyName = ConfigurationHelper.getString( - EnversSettings.EMBEDDABLE_SET_ORDINAL_FIELD_NAME, properties, "SETORDINAL" + embeddableSetOrdinalPropertyName = configurationService.getSetting( + EnversSettings.EMBEDDABLE_SET_ORDINAL_FIELD_NAME, StandardConverters.STRING, "SETORDINAL" ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/ClassesAuditingData.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/ClassesAuditingData.java index a3a868a74b..7ee9e0788e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/ClassesAuditingData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/ClassesAuditingData.java @@ -33,12 +33,12 @@ import org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditing import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData; import org.hibernate.envers.internal.EnversMessageLogger; import org.hibernate.envers.internal.tools.MappingTools; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.binding.EntityBinding; import org.jboss.logging.Logger; /** - * A helper class holding auditing meta-data for all persistent classes. + * A helper class holding auditing meta-data for all entity bindings. * * @author Adam Warski (adam at warski dot org) */ @@ -49,24 +49,25 @@ public class ClassesAuditingData { ); private final Map entityNameToAuditingData = new HashMap(); - private final Map persistentClassToAuditingData = new LinkedHashMap(); + private final Map entityBindingToAuditingData = + new LinkedHashMap(); /** * Stores information about auditing meta-data for the given class. * - * @param pc Persistent class. + * @param entityBinding The entity binding. * @param cad Auditing meta-data for the given class. */ - public void addClassAuditingData(PersistentClass pc, ClassAuditingData cad) { - entityNameToAuditingData.put( pc.getEntityName(), cad ); - persistentClassToAuditingData.put( pc, cad ); + public void addClassAuditingData(EntityBinding entityBinding, ClassAuditingData cad) { + entityNameToAuditingData.put( entityBinding.getEntityName(), cad ); + entityBindingToAuditingData.put( entityBinding, cad ); } /** * @return A collection of all auditing meta-data for persistent classes. */ - public Collection> getAllClassAuditedData() { - return persistentClassToAuditingData.entrySet(); + public Collection> getAllEntityBindingAuditedData() { + return entityBindingToAuditingData.entrySet(); } /** @@ -85,27 +86,27 @@ public class ClassesAuditingData { * */ public void updateCalculatedFields() { - for ( Map.Entry classAuditingDataEntry : persistentClassToAuditingData.entrySet() ) { - final PersistentClass pc = classAuditingDataEntry.getKey(); + for ( Map.Entry classAuditingDataEntry : entityBindingToAuditingData.entrySet() ) { + final EntityBinding entityBinding = classAuditingDataEntry.getKey(); final ClassAuditingData classAuditingData = classAuditingDataEntry.getValue(); for ( String propertyName : classAuditingData.getPropertyNames() ) { final PropertyAuditingData propertyAuditingData = classAuditingData.getPropertyAuditingData( propertyName ); // If a property had the @AuditMappedBy annotation, setting the referenced fields to be always insertable. if ( propertyAuditingData.getAuditMappedBy() != null ) { final String referencedEntityName = MappingTools.getReferencedEntityName( - pc.getProperty( propertyName ).getValue() + entityBinding.locateAttributeBinding( propertyName ) ); final ClassAuditingData referencedClassAuditingData = entityNameToAuditingData.get( referencedEntityName ); forcePropertyInsertable( referencedClassAuditingData, propertyAuditingData.getAuditMappedBy(), - pc.getEntityName(), referencedEntityName + entityBinding.getEntityName(), referencedEntityName ); forcePropertyInsertable( referencedClassAuditingData, propertyAuditingData.getPositionMappedBy(), - pc.getEntityName(), referencedEntityName + entityBinding.getEntityName(), referencedEntityName ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntitiesConfigurator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntitiesConfigurator.java index 2884f40a1b..6c0d29ab57 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntitiesConfigurator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntitiesConfigurator.java @@ -28,23 +28,22 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; import java.util.HashMap; -import java.util.Iterator; +import java.util.List; import java.util.Map; import org.hibernate.MappingException; -import org.hibernate.annotations.common.reflection.ReflectionManager; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.cfg.Configuration; import org.hibernate.envers.configuration.internal.metadata.AuditEntityNameRegister; import org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator; import org.hibernate.envers.configuration.internal.metadata.EntityXmlMappingData; import org.hibernate.envers.configuration.internal.metadata.reader.AnnotationsMetadataReader; import org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditingData; +import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.internal.EnversMessageLogger; import org.hibernate.envers.internal.entities.EntitiesConfigurations; import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.envers.internal.tools.graph.GraphTopologicalSort; import org.hibernate.envers.strategy.AuditStrategy; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.binding.EntityBinding; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -52,80 +51,84 @@ import org.dom4j.Element; import org.dom4j.io.DOMWriter; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; +import org.jboss.logging.Logger; /** * @author Adam Warski (adam at warski dot org) */ public class EntitiesConfigurator { + private static final EnversMessageLogger LOG = Logger.getMessageLogger( + EnversMessageLogger.class, + EntitiesConfigurator.class.getName() + ); + + public EntitiesConfigurations configure( - Configuration cfg, ReflectionManager reflectionManager, - GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, - AuditStrategy auditStrategy, ClassLoaderService classLoaderService, - Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) { + AuditConfiguration.AuditConfigurationContext context, + AuditStrategy auditStrategy, + Document revisionInfoXmlMapping, + Element revisionInfoRelationMapping) { // Creating a name register to capture all audit entity names created. final AuditEntityNameRegister auditEntityNameRegister = new AuditEntityNameRegister(); final DOMWriter writer = new DOMWriter(); - // Sorting the persistent class topologically - superclass always before subclass - final Iterator classes = GraphTopologicalSort.sort( new PersistentClassGraphDefiner( cfg ) ) - .iterator(); + // Sorting the entity bindings topologically - superclass always before subclass + final List entityBindings = + GraphTopologicalSort.sort( new EntityBindingGraphDefiner( context.getMetadata() ) ); final ClassesAuditingData classesAuditingData = new ClassesAuditingData(); - final Map xmlMappings = new HashMap(); + final Map xmlMappings = new HashMap(); // Reading metadata from annotations - while ( classes.hasNext() ) { - final PersistentClass pc = classes.next(); + final AnnotationsMetadataReader annotationsMetadataReader = new AnnotationsMetadataReader( context ); + for ( EntityBinding entityBinding : entityBindings ) { // Collecting information from annotations on the persistent class pc - final AnnotationsMetadataReader annotationsMetadataReader = - new AnnotationsMetadataReader( globalCfg, reflectionManager, pc ); - final ClassAuditingData auditData = annotationsMetadataReader.getAuditData(); + final ClassAuditingData auditData = annotationsMetadataReader.getAuditData( entityBinding ); - classesAuditingData.addClassAuditingData( pc, auditData ); + classesAuditingData.addClassAuditingData( entityBinding, auditData ); } // Now that all information is read we can update the calculated fields. classesAuditingData.updateCalculatedFields(); final AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator( - cfg, globalCfg, verEntCfg, auditStrategy, - classLoaderService, revisionInfoRelationMapping, auditEntityNameRegister + context, auditStrategy, revisionInfoRelationMapping, auditEntityNameRegister ); // First pass - for ( Map.Entry pcDatasEntry : classesAuditingData.getAllClassAuditedData() ) { - final PersistentClass pc = pcDatasEntry.getKey(); + for ( Map.Entry pcDatasEntry : classesAuditingData.getAllEntityBindingAuditedData() ) { + final EntityBinding entityBinding = pcDatasEntry.getKey(); final ClassAuditingData auditData = pcDatasEntry.getValue(); final EntityXmlMappingData xmlMappingData = new EntityXmlMappingData(); if ( auditData.isAudited() ) { if ( !StringTools.isEmpty( auditData.getAuditTable().value() ) ) { - verEntCfg.addCustomAuditTableName( pc.getEntityName(), auditData.getAuditTable().value() ); + context.getAuditEntitiesConfiguration().addCustomAuditTableName( entityBinding.getEntityName(), auditData.getAuditTable().value() ); } - auditMetaGen.generateFirstPass( pc, auditData, xmlMappingData, true ); + auditMetaGen.generateFirstPass( entityBinding, auditData, xmlMappingData, true ); } else { - auditMetaGen.generateFirstPass( pc, auditData, xmlMappingData, false ); + auditMetaGen.generateFirstPass( entityBinding, auditData, xmlMappingData, false ); } - xmlMappings.put( pc, xmlMappingData ); + xmlMappings.put( entityBinding, xmlMappingData ); } // Second pass - for ( Map.Entry pcDatasEntry : classesAuditingData.getAllClassAuditedData() ) { + for ( Map.Entry pcDatasEntry : classesAuditingData.getAllEntityBindingAuditedData() ) { final EntityXmlMappingData xmlMappingData = xmlMappings.get( pcDatasEntry.getKey() ); if ( pcDatasEntry.getValue().isAudited() ) { auditMetaGen.generateSecondPass( pcDatasEntry.getKey(), pcDatasEntry.getValue(), xmlMappingData ); try { - cfg.addDocument( writer.write( xmlMappingData.getMainXmlMapping() ) ); - //writeDocument(xmlMappingData.getMainXmlMapping()); + logDocument( xmlMappingData.getMainXmlMapping() ); + context.addDocument( writer.write( xmlMappingData.getMainXmlMapping() ) ); for ( Document additionalMapping : xmlMappingData.getAdditionalXmlMappings() ) { - cfg.addDocument( writer.write( additionalMapping ) ); - //writeDocument(additionalMapping); + logDocument( additionalMapping ); + context.addDocument( writer.write( additionalMapping ) ); } } catch (DocumentException e) { @@ -138,8 +141,8 @@ public class EntitiesConfigurator { if ( auditMetaGen.getEntitiesConfigurations().size() > 0 ) { try { if ( revisionInfoXmlMapping != null ) { - //writeDocument(revisionInfoXmlMapping); - cfg.addDocument( writer.write( revisionInfoXmlMapping ) ); + logDocument( revisionInfoXmlMapping ); + context.addDocument( writer.write( revisionInfoXmlMapping ) ); } } catch (DocumentException e) { @@ -153,8 +156,10 @@ public class EntitiesConfigurator { ); } - @SuppressWarnings({"UnusedDeclaration"}) - private void writeDocument(Document e) { + private void logDocument(Document e) { + if ( !LOG.isDebugEnabled() ) { + return; + } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Writer w = new PrintWriter( baos ); @@ -167,8 +172,8 @@ public class EntitiesConfigurator { e1.printStackTrace(); } - System.out.println( "-----------" ); - System.out.println( baos.toString() ); - System.out.println( "-----------" ); + LOG.debug( "-----------" ); + LOG.debug( baos.toString() ); + LOG.debug( "-----------" ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntityBindingGraphDefiner.java similarity index 63% rename from hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java rename to hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntityBindingGraphDefiner.java index c26a22474a..c838aba19f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntityBindingGraphDefiner.java @@ -27,10 +27,10 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.hibernate.cfg.Configuration; import org.hibernate.envers.internal.tools.Tools; import org.hibernate.envers.internal.tools.graph.GraphDefiner; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.Metadata; +import org.hibernate.metamodel.spi.binding.EntityBinding; /** * Defines a graph, where the vertexes are all persistent classes, and there is an edge from @@ -38,45 +38,45 @@ import org.hibernate.mapping.PersistentClass; * * @author Adam Warski (adam at warski dot org) */ -public class PersistentClassGraphDefiner implements GraphDefiner { - private Configuration cfg; +public class EntityBindingGraphDefiner implements GraphDefiner { + private Metadata metadata; - public PersistentClassGraphDefiner(Configuration cfg) { - this.cfg = cfg; + public EntityBindingGraphDefiner(Metadata metadata) { + this.metadata = metadata; } @Override - public String getRepresentation(PersistentClass pc) { + public String getRepresentation(EntityBinding pc) { return pc.getEntityName(); } @Override - public PersistentClass getValue(String entityName) { - return cfg.getClassMapping( entityName ); + public EntityBinding getValue(String entityName) { + return metadata.getEntityBinding( entityName ); } @SuppressWarnings({"unchecked"}) - private void addNeighbours(List neighbours, Iterator subclassIterator) { + private void addNeighbours(List neighbours, Iterator subclassIterator) { while ( subclassIterator.hasNext() ) { - final PersistentClass subclass = subclassIterator.next(); + final EntityBinding subclass = subclassIterator.next(); neighbours.add( subclass ); - addNeighbours( neighbours, (Iterator) subclass.getSubclassIterator() ); + addNeighbours( neighbours, subclass.getDirectSubEntityBindings().iterator() ); } } @Override @SuppressWarnings({"unchecked"}) - public List getNeighbours(PersistentClass pc) { - final List neighbours = new ArrayList(); + public List getNeighbours(EntityBinding entityBinding) { + final List neighbours = new ArrayList(); - addNeighbours( neighbours, (Iterator) pc.getSubclassIterator() ); + addNeighbours( neighbours, entityBinding.getDirectSubEntityBindings().iterator() ); return neighbours; } @Override @SuppressWarnings({"unchecked"}) - public List getValues() { - return Tools.iteratorToList( cfg.getClassMappings() ); + public List getValues() { + return Tools.iteratorToList( metadata.getEntityBindings().iterator() ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/GlobalConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/GlobalConfiguration.java index 61516f9b71..059b7ab712 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/GlobalConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/GlobalConfiguration.java @@ -23,17 +23,17 @@ */ package org.hibernate.envers.configuration.internal; -import java.util.Properties; import org.hibernate.MappingException; +import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; -import org.hibernate.cfg.Environment; import org.hibernate.dialect.HSQLDialect; +import org.hibernate.engine.config.spi.ConfigurationService; +import org.hibernate.engine.config.spi.StandardConverters; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.envers.RevisionListener; import org.hibernate.envers.configuration.EnversSettings; -import org.hibernate.envers.internal.tools.ReflectionTools; -import org.hibernate.internal.util.config.ConfigurationHelper; /** * @author Adam Warski (adam at warski dot org) @@ -89,46 +89,64 @@ public class GlobalConfiguration { */ private final String correlatedSubqueryOperator; - public GlobalConfiguration(Properties properties, ClassLoaderService classLoaderService) { - generateRevisionsForCollections = ConfigurationHelper.getBoolean( - EnversSettings.REVISION_ON_COLLECTION_CHANGE, properties, true + public GlobalConfiguration(StandardServiceRegistry serviceRegistry) { + + final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class ); + + generateRevisionsForCollections = configurationService.getSetting( + EnversSettings.REVISION_ON_COLLECTION_CHANGE, StandardConverters.BOOLEAN, true ); - doNotAuditOptimisticLockingField = ConfigurationHelper.getBoolean( - EnversSettings.DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD, properties, true + doNotAuditOptimisticLockingField = configurationService.getSetting( + EnversSettings.DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD, StandardConverters.BOOLEAN, true ); - storeDataAtDelete = ConfigurationHelper.getBoolean( EnversSettings.STORE_DATA_AT_DELETE, properties, false ); - - defaultSchemaName = properties.getProperty( EnversSettings.DEFAULT_SCHEMA, null ); - defaultCatalogName = properties.getProperty( EnversSettings.DEFAULT_CATALOG, null ); - - correlatedSubqueryOperator = HSQLDialect.class.getName() - .equals( properties.get( Environment.DIALECT ) ) ? "in" : "="; - - trackEntitiesChangedInRevision = ConfigurationHelper.getBoolean( - EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, properties, false - ); - - cascadeDeleteRevision = ConfigurationHelper.getBoolean( - "org.hibernate.envers.cascade_delete_revision", properties, false ); - - useRevisionEntityWithNativeId = ConfigurationHelper.getBoolean( - EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, properties, true + storeDataAtDelete = configurationService.getSetting( + EnversSettings.STORE_DATA_AT_DELETE, StandardConverters.BOOLEAN, false ); - hasGlobalSettingForWithModifiedFlag = properties.get( EnversSettings.GLOBAL_WITH_MODIFIED_FLAG ) != null; - globalWithModifiedFlag = ConfigurationHelper.getBoolean( - EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, properties, false + defaultSchemaName = configurationService.getSetting( + EnversSettings.DEFAULT_SCHEMA, StandardConverters.STRING ); - modifiedFlagSuffix = ConfigurationHelper.getString( - EnversSettings.MODIFIED_FLAG_SUFFIX, properties, "_MOD" + defaultCatalogName = configurationService.getSetting( + EnversSettings.DEFAULT_CATALOG, StandardConverters.STRING ); - final String revisionListenerClassName = properties.getProperty( EnversSettings.REVISION_LISTENER, null ); + // TODO: is this really needed??? Should be available in dialect... + final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class ); + correlatedSubqueryOperator = HSQLDialect.class.equals( jdbcEnvironment.getDialect().getClass() ) ? "in" : "="; + + trackEntitiesChangedInRevision = configurationService.getSetting( + EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, StandardConverters.BOOLEAN, false + ); + + // TODO: shouldn't there be an Envers setting for "org.hibernate.envers.cascade_delete_revision"? + cascadeDeleteRevision = configurationService.getSetting( + "org.hibernate.envers.cascade_delete_revision", StandardConverters.BOOLEAN, false + ); + + useRevisionEntityWithNativeId = configurationService.getSetting( + EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, StandardConverters.BOOLEAN, true + ); + + hasGlobalSettingForWithModifiedFlag = null != configurationService.getSetting( + EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, StandardConverters.BOOLEAN + ); + globalWithModifiedFlag = configurationService.getSetting( + EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, StandardConverters.BOOLEAN, false + ); + modifiedFlagSuffix = configurationService.getSetting( + EnversSettings.MODIFIED_FLAG_SUFFIX, StandardConverters.STRING, "_MOD" + ); + + final String revisionListenerClassName = configurationService.getSetting( + EnversSettings.REVISION_LISTENER, + StandardConverters.STRING + ); if ( revisionListenerClassName != null ) { try { - revisionListenerClass = ReflectionTools.loadClass( revisionListenerClassName, classLoaderService ); + revisionListenerClass = + serviceRegistry.getService( ClassLoaderService.class ).classForName( revisionListenerClassName ); } catch (ClassLoadingException e) { throw new MappingException( @@ -141,8 +159,8 @@ public class GlobalConfiguration { revisionListenerClass = null; } - allowIdentifierReuse = ConfigurationHelper.getBoolean( - EnversSettings.ALLOW_IDENTIFIER_REUSE, properties, false + allowIdentifierReuse = configurationService.getSetting( + EnversSettings.ALLOW_IDENTIFIER_REUSE, StandardConverters.BOOLEAN, false ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java index 57831e7f3d..771cc39b2c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java @@ -23,28 +23,20 @@ */ package org.hibernate.envers.configuration.internal; -import java.util.Date; -import java.util.Iterator; -import java.util.Set; -import javax.persistence.Column; +import java.sql.Date; +import java.util.Collection; import org.hibernate.MappingException; -import org.hibernate.annotations.common.reflection.ReflectionManager; -import org.hibernate.annotations.common.reflection.XClass; -import org.hibernate.annotations.common.reflection.XProperty; -import org.hibernate.cfg.Configuration; -import org.hibernate.envers.Audited; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.envers.DefaultRevisionEntity; import org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity; -import org.hibernate.envers.ModifiedEntityNames; import org.hibernate.envers.RevisionEntity; import org.hibernate.envers.RevisionListener; -import org.hibernate.envers.RevisionNumber; -import org.hibernate.envers.RevisionTimestamp; import org.hibernate.envers.configuration.internal.metadata.AuditTableData; import org.hibernate.envers.configuration.internal.metadata.MetadataTools; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; import org.hibernate.envers.enhanced.SequenceIdTrackingModifiedEntitiesRevisionEntity; +import org.hibernate.envers.event.spi.EnversDotNames; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.revisioninfo.DefaultRevisionInfoGenerator; import org.hibernate.envers.internal.revisioninfo.DefaultTrackingModifiedEntitiesRevisionInfoGenerator; @@ -53,14 +45,31 @@ import org.hibernate.envers.internal.revisioninfo.RevisionInfoGenerator; import org.hibernate.envers.internal.revisioninfo.RevisionInfoNumberReader; import org.hibernate.envers.internal.revisioninfo.RevisionInfoQueryCreator; import org.hibernate.envers.internal.tools.MutableBoolean; +import org.hibernate.envers.internal.tools.Tools; import org.hibernate.internal.util.xml.XMLHelper; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; +import org.hibernate.metamodel.spi.InFlightMetadataCollector; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; +import org.hibernate.metamodel.spi.binding.SetBinding; +import org.hibernate.type.IntegerType; import org.hibernate.type.LongType; import org.hibernate.type.Type; import org.dom4j.Document; import org.dom4j.Element; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationTarget; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.FieldInfo; +import org.jboss.jandex.IndexView; +import org.jboss.jandex.MethodInfo; + +import static org.hibernate.metamodel.spi.AdditionalJaxbRootProducer.AdditionalJaxbRootProducerContext; + /** * @author Adam Warski (adam at warski dot org) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) @@ -109,9 +118,9 @@ public class RevisionInfoConfiguration { classMapping, revisionInfoIdData.getName(), revisionPropType, - globalCfg.isUseRevisionEntityWithNativeId() + globalCfg.isUseRevisionEntityWithNativeId(), + "REV" ); - MetadataTools.addColumn( idProperty, "REV", null, null, null, null, null, null, false ); final Element timestampProperty = MetadataTools.addProperty( classMapping, @@ -178,8 +187,9 @@ public class RevisionInfoConfiguration { private Element generateRevisionInfoRelationMapping() { final Document document = XMLHelper.getDocumentFactory().createDocument(); final Element revRelMapping = document.addElement( "key-many-to-one" ); - revRelMapping.addAttribute( "type", revisionPropType ); - revRelMapping.addAttribute( "class", revisionInfoEntityName ); + // TODO: this does not belong here; does it belong somewhere else???? + //revRelMapping.addAttribute( "type", revisionPropType ); + revRelMapping.addAttribute( "entity-name", revisionInfoEntityName ); if ( revisionPropSqlType != null ) { // Putting a fake name to make Hibernate happy. It will be replaced later anyway. @@ -189,97 +199,161 @@ public class RevisionInfoConfiguration { return revRelMapping; } - private void searchForRevisionInfoCfgInProperties( - XClass clazz, - ReflectionManager reflectionManager, - MutableBoolean revisionNumberFound, - MutableBoolean revisionTimestampFound, - MutableBoolean modifiedEntityNamesFound, - String accessType) { - for ( XProperty property : clazz.getDeclaredProperties( accessType ) ) { - final RevisionNumber revisionNumber = property.getAnnotation( RevisionNumber.class ); - final RevisionTimestamp revisionTimestamp = property.getAnnotation( RevisionTimestamp.class ); - final ModifiedEntityNames modifiedEntityNames = property.getAnnotation( ModifiedEntityNames.class ); - - if ( revisionNumber != null ) { + private void searchForRevisionNumberCfg( + ClassInfo revisionInfoEntityClassInfo, + EntityBinding revisionInfoEntityBinding, + AdditionalJaxbRootProducerContext context, + MutableBoolean revisionNumberFound) { + for ( AnnotationInstance annotation : context.getJandexIndex().getAnnotations( EnversDotNames.REVISION_NUMBER ) ) { + final AnnotationTarget annotationTarget = annotation.target(); + if ( !( annotationTarget instanceof FieldInfo || annotationTarget instanceof MethodInfo ) ) { + throw new MappingException( "@RevisionNumber is applicable only to fields or properties." ); + } + if ( Tools.isFieldOrPropertyOfClass( + annotationTarget, + revisionInfoEntityClassInfo, + context.getJandexIndex() ) ) { if ( revisionNumberFound.isSet() ) { - throw new MappingException( "Only one property may be annotated with @RevisionNumber!" ); + throw new MappingException( "Only one property may be annotated with @RevisionNumber." ); } - final XClass revisionNumberClass = property.getType(); - if ( reflectionManager.equals( revisionNumberClass, Integer.class ) || - reflectionManager.equals( revisionNumberClass, Integer.TYPE ) ) { - revisionInfoIdData = new PropertyData( property.getName(), property.getName(), accessType, null ); - revisionNumberFound.set(); + final String revisionNumberProperty = JandexHelper.getPropertyName( annotationTarget ); + final AttributeBinding revisionNumberAttribute = revisionInfoEntityBinding.locateAttributeBinding( + revisionNumberProperty + ); + HibernateTypeDescriptor revisionNumberType = revisionNumberAttribute.getHibernateTypeDescriptor(); + // TODO: Check whether it is required to verify HibernateTypeDescriptor#getJavaTypeName()? + if ( revisionNumberType.getResolvedTypeMapping() instanceof IntegerType ) { + revisionPropType = "integer"; } - else if ( reflectionManager.equals( revisionNumberClass, Long.class ) || - reflectionManager.equals( revisionNumberClass, Long.TYPE ) ) { - revisionInfoIdData = new PropertyData( property.getName(), property.getName(), accessType, null ); - revisionNumberFound.set(); - - // The default is integer + else if ( revisionNumberType.getResolvedTypeMapping() instanceof LongType ) { + // The default is integer. revisionPropType = "long"; } else { throw new MappingException( - "The field annotated with @RevisionNumber must be of type " + - "int, Integer, long or Long" + "Field annotated with @RevisionNumber must be of type int, Integer, long or Long." ); } + revisionInfoIdData = new PropertyData( + revisionNumberProperty, + revisionNumberProperty, + revisionNumberAttribute.getPropertyAccessorName(), + null + ); + revisionNumberFound.set(); + + // Getting the @Column definition of the revision number property, to later use that info to // generate the same mapping for the relation from an audit table's revision number to the // revision entity revision number. - final Column revisionPropColumn = property.getAnnotation( Column.class ); - if ( revisionPropColumn != null ) { - revisionPropSqlType = revisionPropColumn.columnDefinition(); + final AnnotationInstance jpaColumnAnnotation = JandexHelper.getSingleAnnotation( + JandexHelper.getMemberAnnotations( + revisionInfoEntityClassInfo, + revisionNumberProperty, + context.getServiceRegistry() + ), + JPADotNames.COLUMN + ); + if ( jpaColumnAnnotation != null ) { + final ClassLoaderService classLoaderService = + context.getServiceRegistry().getService( ClassLoaderService.class ); + revisionPropSqlType = JandexHelper.getValue( + jpaColumnAnnotation, + "columnDefinition", + String.class, + classLoaderService + ); } } + } + } - if ( revisionTimestamp != null ) { + private void searchForRevisionTimestampCfg( + ClassInfo revisionInfoEntityClassInfo, + EntityBinding revisionInfoEntityBinding, + AdditionalJaxbRootProducerContext context, + MutableBoolean revisionTimestampFound) { + final IndexView jandexIndex = context.getJandexIndex(); + for ( AnnotationInstance annotation : jandexIndex.getAnnotations( EnversDotNames.REVISION_TIMESTAMP ) ) { + AnnotationTarget annotationTarget = annotation.target(); + if ( !( annotationTarget instanceof FieldInfo || annotationTarget instanceof MethodInfo ) ) { + throw new MappingException( "@RevisionTimestamp is applicable only to fields or properties." ); + } + if ( Tools.isFieldOrPropertyOfClass( annotationTarget, revisionInfoEntityClassInfo, jandexIndex ) ) { if ( revisionTimestampFound.isSet() ) { - throw new MappingException( "Only one property may be annotated with @RevisionTimestamp!" ); + throw new MappingException( "Only one property may be annotated with @RevisionTimestamp." ); } - final XClass revisionTimestampClass = property.getType(); - if ( reflectionManager.equals( revisionTimestampClass, Long.class ) || - reflectionManager.equals( revisionTimestampClass, Long.TYPE ) || - reflectionManager.equals( revisionTimestampClass, Date.class ) || - reflectionManager.equals( revisionTimestampClass, java.sql.Date.class ) ) { + final String revisionTimestampProperty = JandexHelper.getPropertyName( annotationTarget ); + final AttributeBinding revisionTimestampAttribute = revisionInfoEntityBinding.locateAttributeBinding( + revisionTimestampProperty + ); + HibernateTypeDescriptor revisionTimestampType = revisionTimestampAttribute.getHibernateTypeDescriptor(); + final String revisionTimestampClassName = revisionTimestampType.getJavaTypeDescriptor().getName().fullName(); + if ( Long.TYPE.getName().equals( revisionTimestampClassName ) || + java.util.Date.class.getName().equals( revisionTimestampClassName ) || + Date.class.getName().equals( revisionTimestampClassName) ) { revisionInfoTimestampData = new PropertyData( - property.getName(), - property.getName(), - accessType, + revisionTimestampProperty, + revisionTimestampProperty, + revisionTimestampAttribute.getPropertyAccessorName(), null ); revisionTimestampFound.set(); } else { throw new MappingException( - "The field annotated with @RevisionTimestamp must be of type " + - "long, Long, java.util.Date or java.sql.Date" + "Field annotated with @RevisionTimestamp must be of type long, Long, java.util.Date or java.sql.Date." ); } } + } + } - if ( modifiedEntityNames != null ) { + private void searchForModifiedEntityNamesCfg( + ClassInfo revisionInfoEntityClassInfo, + EntityBinding revisionInfoEntityBinding, + AdditionalJaxbRootProducerContext context, + MutableBoolean modifiedEntityNamesFound) { + final IndexView jandexIndex = context.getJandexIndex(); + for ( AnnotationInstance annotation : jandexIndex.getAnnotations( EnversDotNames.MODIFIED_ENTITY_NAMES ) ) { + AnnotationTarget annotationTarget = annotation.target(); + if ( !( annotationTarget instanceof FieldInfo || annotationTarget instanceof MethodInfo ) ) { + throw new MappingException( "@ModifiedEntityNames is applicable only to fields or properties." ); + } + if ( Tools.isFieldOrPropertyOfClass( annotationTarget, revisionInfoEntityClassInfo, jandexIndex ) ) { if ( modifiedEntityNamesFound.isSet() ) { - throw new MappingException( "Only one property may be annotated with @ModifiedEntityNames!" ); + throw new MappingException( "Only one property may be annotated with @ModifiedEntityNames." ); } - final XClass modifiedEntityNamesClass = property.getType(); - if ( reflectionManager.equals( modifiedEntityNamesClass, Set.class ) && - reflectionManager.equals( property.getElementClass(), String.class ) ) { - modifiedEntityNamesData = new PropertyData( - property.getName(), - property.getName(), - accessType, - null - ); - modifiedEntityNamesFound.set(); + + final String modifiedEntityNamesProperty = JandexHelper.getPropertyName( annotationTarget ); + final AttributeBinding modifiedEntityNamesAttribute = revisionInfoEntityBinding.locateAttributeBinding( + modifiedEntityNamesProperty + ); + + if ( modifiedEntityNamesAttribute instanceof SetBinding ) { + final SetBinding collectionBinding = (SetBinding) modifiedEntityNamesAttribute; + final String elementType = + collectionBinding + .getPluralAttributeElementBinding() + .getHibernateTypeDescriptor() + .getJavaTypeDescriptor().getName().fullName(); + if ( String.class.getName().equals( elementType ) ) { + modifiedEntityNamesData = new PropertyData( + modifiedEntityNamesProperty, + modifiedEntityNamesProperty, + modifiedEntityNamesAttribute.getPropertyAccessorName(), + null + ); + modifiedEntityNamesFound.set(); + } } - else { + + if ( !modifiedEntityNamesFound.isSet() ) { throw new MappingException( - "The field annotated with @ModifiedEntityNames must be of Set type." + "Field annotated with @ModifiedEntityNames must be of Set type." ); } } @@ -287,135 +361,136 @@ public class RevisionInfoConfiguration { } private void searchForRevisionInfoCfg( - XClass clazz, ReflectionManager reflectionManager, - MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound, + ClassInfo revisionInfoEntityClassInfo, + EntityBinding revisionInfoEntityBinding, + AdditionalJaxbRootProducerContext context, + MutableBoolean revisionNumberFound, + MutableBoolean revisionTimestampFound, MutableBoolean modifiedEntityNamesFound) { - final XClass superclazz = clazz.getSuperclass(); - if ( !"java.lang.Object".equals( superclazz.getName() ) ) { + searchForRevisionNumberCfg( revisionInfoEntityClassInfo, revisionInfoEntityBinding, context, revisionNumberFound ); + searchForRevisionTimestampCfg( + revisionInfoEntityClassInfo, + revisionInfoEntityBinding, + context, + revisionTimestampFound + ); + searchForModifiedEntityNamesCfg( + revisionInfoEntityClassInfo, + revisionInfoEntityBinding, + context, + modifiedEntityNamesFound + ); + } + + public RevisionInfoConfigurationResult configure( + InFlightMetadataCollector metadataCollector, + AdditionalJaxbRootProducerContext context) { + + final ClassLoaderService classLoaderService = context.getServiceRegistry().getService( ClassLoaderService.class ); + + boolean revisionEntityFound = false; + RevisionInfoGenerator revisionInfoGenerator = null; + Class revisionInfoEntityClass = null; + + // Locate @RevisionEntity provided by user and validate its mapping. + Collection revisionEntityAnnotations = context.getJandexIndex().getAnnotations( + EnversDotNames.REVISION_ENTITY + ); + if ( revisionEntityAnnotations.size() > 1 ) { + throw new MappingException( "Only one entity may be annotated with @RevisionEntity." ); + } + if ( revisionEntityAnnotations.size() == 1 ) { + final AnnotationInstance revisionEntityAnnotation = revisionEntityAnnotations.iterator().next(); + final ClassInfo revisionInfoEntityClassInfo = (ClassInfo) revisionEntityAnnotation.target(); + + // TODO: Get rid of revisionInfoEntityClass (don't want to load the class). + revisionInfoEntityClass = classLoaderService.classForName( revisionInfoEntityClassInfo.name().toString() ); + + // TODO: get entity name from @Entity + revisionInfoEntityName = revisionInfoEntityClass.getName(); + + final EntityBinding revisionInfoEntityBinding = metadataCollector.getEntityBinding( + revisionInfoEntityName + ); + + if ( revisionInfoEntityClassInfo.annotations().containsKey( EnversDotNames.AUDITED ) ) { + throw new MappingException( "An entity annotated with @RevisionEntity cannot be audited." ); + } + + MutableBoolean revisionNumberFound = new MutableBoolean(); + MutableBoolean revisionTimestampFound = new MutableBoolean(); + MutableBoolean modifiedEntityNamesFound = new MutableBoolean(); + searchForRevisionInfoCfg( - superclazz, - reflectionManager, + revisionInfoEntityClassInfo, + revisionInfoEntityBinding, + context, revisionNumberFound, revisionTimestampFound, modifiedEntityNamesFound ); - } - searchForRevisionInfoCfgInProperties( - clazz, reflectionManager, revisionNumberFound, revisionTimestampFound, - modifiedEntityNamesFound, "field" - ); - searchForRevisionInfoCfgInProperties( - clazz, reflectionManager, revisionNumberFound, revisionTimestampFound, - modifiedEntityNamesFound, "property" - ); - } - - public RevisionInfoConfigurationResult configure(Configuration cfg, ReflectionManager reflectionManager) { - boolean revisionEntityFound = false; - RevisionInfoGenerator revisionInfoGenerator = null; - Class revisionInfoClass = null; - - final Iterator classes = cfg.getClassMappings(); - while ( classes.hasNext() ) { - PersistentClass pc = classes.next(); - XClass clazz; - try { - clazz = reflectionManager.classForName( pc.getClassName(), this.getClass() ); - } - catch (ClassNotFoundException e) { - throw new MappingException( e ); - } - - final RevisionEntity revisionEntity = clazz.getAnnotation( RevisionEntity.class ); - if ( revisionEntity != null ) { - if ( revisionEntityFound ) { - throw new MappingException( "Only one entity may be annotated with @RevisionEntity!" ); - } - - // Checking if custom revision entity isn't audited - if ( clazz.getAnnotation( Audited.class ) != null ) { - throw new MappingException( "An entity annotated with @RevisionEntity cannot be audited!" ); - } - - revisionEntityFound = true; - - final MutableBoolean revisionNumberFound = new MutableBoolean(); - final MutableBoolean revisionTimestampFound = new MutableBoolean(); - final MutableBoolean modifiedEntityNamesFound = new MutableBoolean(); - - searchForRevisionInfoCfg( - clazz, - reflectionManager, - revisionNumberFound, - revisionTimestampFound, - modifiedEntityNamesFound + if ( !revisionNumberFound.isSet() ) { + throw new MappingException( + "An entity annotated with @RevisionEntity must have a field annotated with @RevisionNumber!" ); + } - if ( !revisionNumberFound.isSet() ) { - throw new MappingException( - "An entity annotated with @RevisionEntity must have a field annotated " + - "with @RevisionNumber!" - ); - } + if ( !revisionTimestampFound.isSet() ) { + throw new MappingException( + "An entity annotated with @RevisionEntity must have a field annotated with @RevisionTimestamp!" + ); + } - if ( !revisionTimestampFound.isSet() ) { - throw new MappingException( - "An entity annotated with @RevisionEntity must have a field annotated " + - "with @RevisionTimestamp!" - ); - } - - revisionInfoEntityName = pc.getEntityName(); - revisionInfoClass = pc.getMappedClass(); - final Class revisionListenerClass = getRevisionListenerClass( revisionEntity.value() ); - revisionInfoTimestampType = pc.getProperty( revisionInfoTimestampData.getName() ).getType(); - if ( globalCfg.isTrackEntitiesChangedInRevision() - || (globalCfg.isUseRevisionEntityWithNativeId() && DefaultTrackingModifiedEntitiesRevisionEntity.class - .isAssignableFrom( revisionInfoClass )) - || (!globalCfg.isUseRevisionEntityWithNativeId() && SequenceIdTrackingModifiedEntitiesRevisionEntity.class - .isAssignableFrom( revisionInfoClass )) - || modifiedEntityNamesFound.isSet() ) { - // If tracking modified entities parameter is enabled, custom revision info entity is a subtype - // of DefaultTrackingModifiedEntitiesRevisionEntity class, or @ModifiedEntityNames annotation is used. - revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator( - revisionInfoEntityName, - revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), - modifiedEntityNamesData - ); - globalCfg.setTrackEntitiesChangedInRevision( true ); - } - else { - revisionInfoGenerator = new DefaultRevisionInfoGenerator( - revisionInfoEntityName, revisionInfoClass, - revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate() - ); - } + Class revisionListenerClass = getRevisionListenerClass( + classLoaderService, + revisionEntityAnnotation + ); + revisionInfoTimestampType = + revisionInfoEntityBinding.locateAttributeBinding( revisionInfoTimestampData.getName() ) + .getHibernateTypeDescriptor() + .getResolvedTypeMapping(); + if ( globalCfg.isTrackEntitiesChangedInRevision() + || ( globalCfg.isUseRevisionEntityWithNativeId() && DefaultTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom( revisionInfoEntityClass ) ) + || ( !globalCfg.isUseRevisionEntityWithNativeId() && SequenceIdTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom( revisionInfoEntityClass ) ) + || modifiedEntityNamesFound.isSet() ) { + // If tracking modified entities parameter is enabled, custom revision info entity is a subtype + // of DefaultTrackingModifiedEntitiesRevisionEntity class, or @ModifiedEntityNames annotation is used. + revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator( + revisionInfoEntityBinding.getEntity().getName(), revisionInfoEntityClass, + revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData + ); + globalCfg.setTrackEntitiesChangedInRevision( true ); + } + else { + revisionInfoGenerator = new DefaultRevisionInfoGenerator( + revisionInfoEntityBinding.getEntity().getName(), revisionInfoEntityClass, + revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate() + ); } } // In case of a custom revision info generator, the mapping will be null. Document revisionInfoXmlMapping = null; - final Class revisionListenerClass = getRevisionListenerClass( RevisionListener.class ); - if ( revisionInfoGenerator == null ) { + final Class revisionListenerClass = getRevisionListenerClass( classLoaderService, null ); if ( globalCfg.isTrackEntitiesChangedInRevision() ) { - revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? - DefaultTrackingModifiedEntitiesRevisionEntity.class - : + revisionInfoEntityClass = globalCfg.isUseRevisionEntityWithNativeId() ? + DefaultTrackingModifiedEntitiesRevisionEntity.class : SequenceIdTrackingModifiedEntitiesRevisionEntity.class; - revisionInfoEntityName = revisionInfoClass.getName(); + revisionInfoEntityName = revisionInfoEntityClass.getName(); revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator( - revisionInfoEntityName, revisionInfoClass, + revisionInfoEntityName, revisionInfoEntityClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData ); } else { - revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? DefaultRevisionEntity.class - : SequenceIdRevisionEntity.class; + revisionInfoEntityClass = globalCfg.isUseRevisionEntityWithNativeId() ? + DefaultRevisionEntity.class : + SequenceIdRevisionEntity.class; revisionInfoGenerator = new DefaultRevisionInfoGenerator( - revisionInfoEntityName, revisionInfoClass, + revisionInfoEntityName, revisionInfoEntityClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate() ); } @@ -429,13 +504,13 @@ public class RevisionInfoConfiguration { revisionInfoTimestampData.getName(), isTimestampAsDate() ), generateRevisionInfoRelationMapping(), - new RevisionInfoNumberReader( revisionInfoClass, revisionInfoIdData ), + new RevisionInfoNumberReader( revisionInfoEntityClass, revisionInfoIdData ), globalCfg.isTrackEntitiesChangedInRevision() ? new ModifiedEntityNamesReader( - revisionInfoClass, + revisionInfoEntityClass, modifiedEntityNamesData ) : null, - revisionInfoEntityName, revisionInfoClass, revisionInfoTimestampData + revisionInfoEntityName, revisionInfoEntityClass, revisionInfoTimestampData ); } @@ -445,15 +520,21 @@ public class RevisionInfoConfiguration { } /** - * @param defaultListener Revision listener that shall be applied if {@code org.hibernate.envers.revision_listener} - * parameter has not been set. - * + * Method takes into consideration {@code org.hibernate.envers.revision_listener} parameter and custom + * {@link RevisionEntity} annotation. + * @param classLoaderService Class loading service. + * @param revisionEntityAnnotation User defined @RevisionEntity annotation, or {@code null} if none. * @return Revision listener. */ - private Class getRevisionListenerClass(Class defaultListener) { + private Class getRevisionListenerClass(ClassLoaderService classLoaderService, + AnnotationInstance revisionEntityAnnotation) { if ( globalCfg.getRevisionListenerClass() != null ) { return globalCfg.getRevisionListenerClass(); } - return defaultListener; + if ( revisionEntityAnnotation != null && revisionEntityAnnotation.value() != null ) { + // User provided revision listener implementation in @RevisionEntity mapping. + return classLoaderService.classForName( revisionEntityAnnotation.value().asString() ); + } + return RevisionListener.class; } } 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 adb256a6d0..a3a434c5f1 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 @@ -23,18 +23,17 @@ */ package org.hibernate.envers.configuration.internal.metadata; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.hibernate.MappingException; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.cfg.Configuration; import org.hibernate.envers.RelationTargetAuditMode; -import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; -import org.hibernate.envers.configuration.internal.GlobalConfiguration; import org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditingData; import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData; +import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.EnversMessageLogger; import org.hibernate.envers.internal.entities.EntityConfiguration; import org.hibernate.envers.internal.entities.IdMappingData; @@ -46,13 +45,16 @@ import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.envers.internal.tools.Triple; import org.hibernate.envers.strategy.AuditStrategy; import org.hibernate.envers.strategy.ValidityAuditStrategy; -import org.hibernate.mapping.Collection; -import org.hibernate.mapping.Join; -import org.hibernate.mapping.OneToOne; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.Table; -import org.hibernate.mapping.Value; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.binding.EntityDiscriminator; +import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; +import org.hibernate.metamodel.spi.binding.OneToOneAttributeBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.type.CollectionType; import org.hibernate.type.ComponentType; import org.hibernate.type.ManyToOneType; @@ -78,12 +80,8 @@ public final class AuditMetadataGenerator { EnversMessageLogger.class, AuditMetadataGenerator.class.getName() ); - - private final Configuration cfg; - private final GlobalConfiguration globalCfg; - private final AuditEntitiesConfiguration verEntCfg; + private final AuditConfiguration.AuditConfigurationContext context; private final AuditStrategy auditStrategy; - private final ClassLoaderService classLoaderService; private final Element revisionInfoRelationMapping; /* @@ -102,32 +100,31 @@ public final class AuditMetadataGenerator { private final AuditEntityNameRegister auditEntityNameRegister; + // TODO: add support for secondary tables. // Map entity name -> (join descriptor -> element describing the "versioned" join) - private final Map> entitiesJoins; + //private final Map> entitiesJoins; public AuditMetadataGenerator( - Configuration cfg, GlobalConfiguration globalCfg, - AuditEntitiesConfiguration verEntCfg, - AuditStrategy auditStrategy, ClassLoaderService classLoaderService, + AuditConfiguration.AuditConfigurationContext context, + AuditStrategy auditStrategy, Element revisionInfoRelationMapping, AuditEntityNameRegister auditEntityNameRegister) { - this.cfg = cfg; - this.globalCfg = globalCfg; - this.verEntCfg = verEntCfg; + this.context = context; this.auditStrategy = auditStrategy; - this.classLoaderService = classLoaderService; this.revisionInfoRelationMapping = revisionInfoRelationMapping; this.basicMetadataGenerator = new BasicMetadataGenerator(); - this.componentMetadataGenerator = new ComponentMetadataGenerator( this ); - this.idMetadataGenerator = new IdMetadataGenerator( this ); + this.componentMetadataGenerator = new ComponentMetadataGenerator( context, this ); + this.idMetadataGenerator = new IdMetadataGenerator( context, this ); this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator( this ); this.auditEntityNameRegister = auditEntityNameRegister; entitiesConfigurations = new HashMap(); notAuditedEntitiesConfigurations = new HashMap(); - entitiesJoins = new HashMap>(); + + // TODO: add support for secondary tables. + //entitiesJoins = new HashMap>(); } /** @@ -138,12 +135,12 @@ public final class AuditMetadataGenerator { */ private Element cloneAndSetupRevisionInfoRelationMapping() { final Element revMapping = (Element) revisionInfoRelationMapping.clone(); - revMapping.addAttribute( "name", verEntCfg.getRevisionFieldName() ); - if ( globalCfg.isCascadeDeleteRevision() ) { + revMapping.addAttribute( "name", context.getAuditEntitiesConfiguration().getRevisionFieldName() ); + if ( context.getGlobalConfiguration().isCascadeDeleteRevision() ) { revMapping.addAttribute( "on-delete", "cascade" ); } - MetadataTools.addOrModifyColumn( revMapping, verEntCfg.getRevisionFieldName() ); + MetadataTools.addOrModifyColumn( revMapping, context.getAuditEntitiesConfiguration().getRevisionFieldName() ); return revMapping; } @@ -152,13 +149,13 @@ public final class AuditMetadataGenerator { anyMapping.add( cloneAndSetupRevisionInfoRelationMapping() ); } - void addRevisionType(Element anyMapping, Element anyMappingEnd) { + void addRevisionType(Element anyMapping, Element anyMappingEnd, boolean key) { final Element revTypeProperty = MetadataTools.addProperty( anyMapping, - verEntCfg.getRevisionTypePropName(), - verEntCfg.getRevisionTypePropType(), + context.getAuditEntitiesConfiguration().getRevisionTypePropName(), + context.getAuditEntitiesConfiguration().getRevisionTypePropType(), true, - false + key ); revTypeProperty.addAttribute( "type", "org.hibernate.envers.internal.entities.RevisionTypeType" ); @@ -171,17 +168,17 @@ public final class AuditMetadataGenerator { if ( auditStrategy instanceof ValidityAuditStrategy ) { final Element endRevMapping = (Element) revisionInfoRelationMapping.clone(); endRevMapping.setName( "many-to-one" ); - endRevMapping.addAttribute( "name", verEntCfg.getRevisionEndFieldName() ); - MetadataTools.addOrModifyColumn( endRevMapping, verEntCfg.getRevisionEndFieldName() ); + endRevMapping.addAttribute( "name", context.getAuditEntitiesConfiguration().getRevisionEndFieldName() ); + MetadataTools.addOrModifyColumn( endRevMapping, context.getAuditEntitiesConfiguration().getRevisionEndFieldName() ); anyMapping.add( endRevMapping ); - if ( verEntCfg.isRevisionEndTimestampEnabled() ) { + if ( context.getAuditEntitiesConfiguration().isRevisionEndTimestampEnabled() ) { // add a column for the timestamp of the end revision final String revisionInfoTimestampSqlType = TimestampType.INSTANCE.getName(); final Element timestampProperty = MetadataTools.addProperty( anyMapping, - verEntCfg.getRevisionEndTimestampFieldName(), + context.getAuditEntitiesConfiguration().getRevisionEndTimestampFieldName(), revisionInfoTimestampSqlType, true, true, @@ -189,7 +186,7 @@ public final class AuditMetadataGenerator { ); MetadataTools.addColumn( timestampProperty, - verEntCfg.getRevisionEndTimestampFieldName(), + context.getAuditEntitiesConfiguration().getRevisionEndTimestampFieldName(), null, null, null, @@ -203,20 +200,33 @@ public final class AuditMetadataGenerator { private void addValueInFirstPass( Element parent, - Value value, + AttributeBinding attributeBinding, CompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, - boolean insertable, boolean processModifiedFlag) { - final Type type = value.getType(); + final Type type = attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); + + final List values; + final boolean isInsertable; + if ( attributeBinding.getAttribute().isSingular() ) { + final SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding; + values = singularAttributeBinding.getValues(); + isInsertable = singularAttributeBinding.isIncludedInInsert(); + } + else { + values = null; + isInsertable = false; + } + final boolean isBasic = basicMetadataGenerator.addBasic( parent, propertyAuditingData, - value, + attributeBinding.getHibernateTypeDescriptor(), + values, + isInsertable, currentMapper, - insertable, false ); @@ -225,8 +235,13 @@ public final class AuditMetadataGenerator { } else if ( type instanceof ComponentType ) { componentMetadataGenerator.addComponent( - parent, propertyAuditingData, value, currentMapper, - entityName, xmlMappingData, true + parent, + propertyAuditingData, + (CompositeAttributeBinding) attributeBinding, + currentMapper, + entityName, + xmlMappingData, + true ); } else { @@ -247,20 +262,19 @@ public final class AuditMetadataGenerator { private void addValueInSecondPass( Element parent, - Value value, + AttributeBinding attributeBinding, CompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, - boolean insertable, boolean processModifiedFlag) { - final Type type = value.getType(); + final Type type = attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); if ( type instanceof ComponentType ) { componentMetadataGenerator.addComponent( parent, propertyAuditingData, - value, + (CompositeAttributeBinding) attributeBinding, currentMapper, entityName, xmlMappingData, @@ -273,18 +287,17 @@ public final class AuditMetadataGenerator { toOneRelationMetadataGenerator.addToOne( parent, propertyAuditingData, - value, + (ManyToOneAttributeBinding) attributeBinding, currentMapper, - entityName, - insertable + entityName ); } else if ( type instanceof OneToOneType ) { - final OneToOne oneToOne = (OneToOne) value; - if ( oneToOne.getReferencedPropertyName() != null ) { + final OneToOneAttributeBinding oneToOneAttributeBinding = (OneToOneAttributeBinding) attributeBinding; + if ( oneToOneAttributeBinding.getReferencedAttributeBinding().getAttribute().getName() != null ) { toOneRelationMetadataGenerator.addOneToOneNotOwning( propertyAuditingData, - value, + oneToOneAttributeBinding, currentMapper, entityName ); @@ -293,17 +306,17 @@ public final class AuditMetadataGenerator { // @OneToOne relation marked with @PrimaryKeyJoinColumn toOneRelationMetadataGenerator.addOneToOnePrimaryKeyJoinColumn( propertyAuditingData, - value, + oneToOneAttributeBinding, currentMapper, - entityName, - insertable + entityName ); } } else if ( type instanceof CollectionType ) { final CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator( + context, this, - (Collection) value, + (PluralAttributeBinding) attributeBinding, currentMapper, entityName, xmlMappingData, @@ -325,50 +338,53 @@ public final class AuditMetadataGenerator { MetadataTools.addModifiedFlagProperty( parent, propertyAuditingData.getName(), - globalCfg.getModifiedFlagSuffix() + context.getGlobalConfiguration().getModifiedFlagSuffix() ); } } void addValue( - Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName, - EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, - boolean insertable, boolean firstPass, boolean processModifiedFlag) { + Element parent, + AttributeBinding attributeBinding, + CompositeMapperBuilder currentMapper, + String entityName, + EntityXmlMappingData xmlMappingData, + PropertyAuditingData propertyAuditingData, + boolean firstPass, + boolean processModifiedFlag) { if ( firstPass ) { addValueInFirstPass( - parent, value, currentMapper, entityName, - xmlMappingData, propertyAuditingData, insertable, processModifiedFlag + parent, attributeBinding, currentMapper, entityName, + xmlMappingData, propertyAuditingData, processModifiedFlag ); } else { addValueInSecondPass( - parent, value, currentMapper, entityName, - xmlMappingData, propertyAuditingData, insertable, processModifiedFlag + parent, attributeBinding, currentMapper, entityName, + xmlMappingData, propertyAuditingData, processModifiedFlag ); } } private void addProperties( Element parent, - Iterator properties, + AttributeBinding[] properties, CompositeMapperBuilder currentMapper, ClassAuditingData auditingData, String entityName, EntityXmlMappingData xmlMappingData, boolean firstPass) { - while ( properties.hasNext() ) { - final Property property = properties.next(); - final String propertyName = property.getName(); + for ( AttributeBinding property : properties ) { + final String propertyName = property.getAttribute().getName(); final PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData( propertyName ); if ( propertyAuditingData != null ) { addValue( parent, - property.getValue(), + property, currentMapper, entityName, xmlMappingData, propertyAuditingData, - property.isInsertable(), firstPass, true ); @@ -376,10 +392,10 @@ public final class AuditMetadataGenerator { } } - private boolean checkPropertiesAudited(Iterator properties, ClassAuditingData auditingData) { + private boolean checkPropertiesAudited(Iterator properties, ClassAuditingData auditingData) { while ( properties.hasNext() ) { - final Property property = properties.next(); - final String propertyName = property.getName(); + final AttributeBinding property = properties.next(); + final String propertyName = property.getAttribute().getName(); final PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData( propertyName ); if ( propertyAuditingData == null ) { return false; @@ -389,151 +405,193 @@ public final class AuditMetadataGenerator { return true; } - protected String getSchema(String schemaFromAnnotation, Table table) { + protected String getSchema(String schemaFromAnnotation, TableSpecification table) { // Get the schema from the annotation ... String schema = schemaFromAnnotation; // ... if empty, try using the default ... if ( StringTools.isEmpty( schema ) ) { - schema = globalCfg.getDefaultSchemaName(); + schema = context.getGlobalConfiguration().getDefaultSchemaName(); // ... if still empty, use the same as the normal table. - if ( StringTools.isEmpty( schema ) ) { - schema = table.getSchema(); + if ( StringTools.isEmpty( schema ) && table.getSchema().getName().getSchema() != null) { + schema = table.getSchema().getName().getSchema().getText(); } } return schema; } - protected String getCatalog(String catalogFromAnnotation, Table table) { + protected String getCatalog(String catalogFromAnnotation, TableSpecification table) { // Get the catalog from the annotation ... String catalog = catalogFromAnnotation; // ... if empty, try using the default ... if ( StringTools.isEmpty( catalog ) ) { - catalog = globalCfg.getDefaultCatalogName(); + catalog = context.getGlobalConfiguration().getDefaultCatalogName(); // ... if still empty, use the same as the normal table. - if ( StringTools.isEmpty( catalog ) ) { - catalog = table.getCatalog(); + if ( StringTools.isEmpty( catalog ) && table.getSchema().getName().getCatalog() != null ) { + catalog = table.getSchema().getName().getCatalog().getText(); } } return catalog; } - @SuppressWarnings({"unchecked"}) - private void createJoins(PersistentClass pc, Element parent, ClassAuditingData auditingData) { - final Iterator joins = pc.getJoinIterator(); - final Map joinElements = new HashMap(); - entitiesJoins.put( pc.getEntityName(), joinElements ); + // TODO: add support for secondary tables +// private void createJoins(EntityBinding entityBinding, Element parent, ClassAuditingData auditingData) { +// final Iterator joins = entityBinding.getSecondaryTables(); +// final Map joinElements = new HashMap(); +// entitiesJoins.put( entityBinding.getEntityName(), joinElements ); - while ( joins.hasNext() ) { - Join join = joins.next(); +// while ( joins.hasNext() ) { +// SecondaryTable join = joins.next(); // Checking if all of the join properties are audited - if ( !checkPropertiesAudited( join.getPropertyIterator(), auditingData ) ) { - continue; - } +// if ( !checkPropertiesAudited( join.getPropertyIterator(), auditingData ) ) { +// continue; +// } // Determining the table name. If there is no entry in the dictionary, just constructing the table name // as if it was an entity (by appending/prepending configured strings). - final String originalTableName = join.getTable().getName(); - String auditTableName = auditingData.getSecondaryTableDictionary().get( originalTableName ); - if ( auditTableName == null ) { - auditTableName = verEntCfg.getAuditEntityName( originalTableName ); - } +// final String originalTableName = join.getSecondaryTableReference().getLogicalName().getText(); +// String auditTableName = auditingData.getSecondaryTableDictionary().get( originalTableName ); +// if ( auditTableName == null ) { +// auditTableName = context.getAuditEntitiesConfiguration().getAuditEntityName( originalTableName ); +// } - final String schema = getSchema( auditingData.getAuditTable().schema(), join.getTable() ); - final String catalog = getCatalog( auditingData.getAuditTable().catalog(), join.getTable() ); +// final String schema = getSchema( auditingData.getAuditTable().schema(), join.getSecondaryTableReference() ); +// final String catalog = getCatalog( auditingData.getAuditTable().catalog(), join.getSecondaryTableReference() ); - final Element joinElement = MetadataTools.createJoin( parent, auditTableName, schema, catalog ); - joinElements.put( join, joinElement ); +// final Element joinElement = MetadataTools.createJoin( parent, auditTableName, schema, catalog ); +// joinElements.put( join, joinElement ); - final Element joinKey = joinElement.addElement( "key" ); - MetadataTools.addColumns( joinKey, join.getKey().getColumnIterator() ); - MetadataTools.addColumn( joinKey, verEntCfg.getRevisionFieldName(), null, null, null, null, null, null ); - } - } +// final Element joinKey = joinElement.addElement( "key" ); +// MetadataTools.addColumns( joinKey, join.getForeignKeyReference().getColumns() ); +// MetadataTools.addColumn( joinKey, context.getAuditEntitiesConfiguration().getRevisionFieldName(), null, null, null, null, null, null ); +// } +// } - @SuppressWarnings({"unchecked"}) - private void addJoins( - PersistentClass pc, - CompositeMapperBuilder currentMapper, - ClassAuditingData auditingData, - String entityName, - EntityXmlMappingData xmlMappingData, - boolean firstPass) { - final Iterator joins = pc.getJoinIterator(); +// @SuppressWarnings({"unchecked"}) +// private void createJoins(PersistentClass pc, Element parent, ClassAuditingData auditingData) { +// final Iterator joins = pc.getJoinIterator(); +// final Map joinElements = new HashMap(); +// entitiesJoins.put( pc.getEntityName(), joinElements ); +// +// while ( joins.hasNext() ) { +// Join join = joins.next(); - while ( joins.hasNext() ) { - final Join join = joins.next(); - final Element joinElement = entitiesJoins.get( entityName ).get( join ); + // Checking if all of the join properties are audited +// if ( !checkPropertiesAudited( join.getPropertyIterator(), auditingData ) ) { +// continue; +// } - if ( joinElement != null ) { - addProperties( - joinElement, - join.getPropertyIterator(), - currentMapper, - auditingData, - entityName, - xmlMappingData, - firstPass - ); - } - } - } + // Determining the table name. If there is no entry in the dictionary, just constructing the table name + // as if it was an entity (by appending/prepending configured strings). +// final String originalTableName = join.getTable().getName(); +// String auditTableName = auditingData.getSecondaryTableDictionary().get( originalTableName ); +// if ( auditTableName == null ) { +// auditTableName = verEntCfg.getAuditEntityName( originalTableName ); +// } + +// final String schema = getSchema( auditingData.getAuditTable().schema(), join.getTable() ); +// final String catalog = getCatalog( auditingData.getAuditTable().catalog(), join.getTable() ); + +// final Element joinElement = MetadataTools.createJoin( parent, auditTableName, schema, catalog ); +// joinElements.put( join, joinElement ); + +// final Element joinKey = joinElement.addElement( "key" ); +// MetadataTools.addColumns( joinKey, join.getKey().getColumnIterator() ); +// MetadataTools.addColumn( joinKey, verEntCfg.getRevisionFieldName(), null, null, null, null, null, null ); +// } +// } + +// @SuppressWarnings({"unchecked"}) +// private void addJoins( +// PersistentClass pc, +// CompositeMapperBuilder currentMapper, +// ClassAuditingData auditingData, +// String entityName, +// EntityXmlMappingData xmlMappingData, +// boolean firstPass) { +// final Iterator joins = pc.getJoinIterator(); + +// while ( joins.hasNext() ) { +// final Join join = joins.next(); +// final Element joinElement = entitiesJoins.get( entityName ).get( join ); + +// if ( joinElement != null ) { +// addProperties( +// joinElement, +// join.getPropertyIterator(), +// currentMapper, +// auditingData, +// entityName, +// xmlMappingData, +// firstPass +// ); +// } +// } +// } @SuppressWarnings({"unchecked"}) private Triple generateMappingData( - PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData, + EntityBinding entityBinding, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData, IdMappingData idMapper) { final Element classMapping = MetadataTools.createEntity( xmlMappingData.getMainXmlMapping(), auditTableData, - pc.getDiscriminatorValue(), - pc.isAbstract() + entityBinding.getDiscriminatorMatchValue(), + entityBinding.isAbstract() ); final ExtendedPropertyMapper propertyMapper = new MultiPropertyMapper(); - // Checking if there is a discriminator column - 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() ); - discriminatorElement.addAttribute( "type", pc.getDiscriminator().getType().getName() ); - } - // Adding the id mapping classMapping.add( (Element) idMapper.getXmlMapping().clone() ); + // Checking if there is a discriminator column + if ( entityBinding.getHierarchyDetails().getEntityDiscriminator() != null ) { + final EntityDiscriminator discriminator = entityBinding.getHierarchyDetails().getEntityDiscriminator(); + final Element discriminatorElement = classMapping.addElement( "discriminator" ); + // Database column or SQL formula allowed to distinguish entity types + MetadataTools.addColumnsOrFormulas( + discriminatorElement, + Collections.singletonList( discriminator.getRelationalValue() ) + ); + discriminatorElement.addAttribute( + "type", + discriminator.getExplicitHibernateTypeDescriptor().getExplicitTypeName() + ); + } + // Adding the "revision type" property - addRevisionType( classMapping, classMapping ); + addRevisionType( classMapping, classMapping, false ); return Triple.make( classMapping, propertyMapper, null ); } private Triple generateInheritanceMappingData( - PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData, + EntityBinding entityBinding, + EntityXmlMappingData xmlMappingData, + AuditTableData auditTableData, String inheritanceMappingType) { - final String extendsEntityName = verEntCfg.getAuditEntityName( pc.getSuperclass().getEntityName() ); + final String parentEntityName = entityBinding.getSuperEntityBinding().getEntityName(); + final String extendsEntityName = context.getAuditEntitiesConfiguration().getAuditEntityName( parentEntityName ); final Element classMapping = MetadataTools.createSubclassEntity( xmlMappingData.getMainXmlMapping(), inheritanceMappingType, auditTableData, extendsEntityName, - pc.getDiscriminatorValue(), - pc.isAbstract() + entityBinding.getDiscriminatorMatchValue(), + entityBinding.isAbstract() ); // The id and revision type is already mapped in the parent // Getting the property mapper of the parent - when mapping properties, they need to be included - final String parentEntityName = pc.getSuperclass().getEntityName(); - final EntityConfiguration parentConfiguration = entitiesConfigurations.get( parentEntityName ); if ( parentConfiguration == null ) { throw new MappingException( - "Entity '" + pc.getEntityName() + "' is audited, but its superclass: '" + + "Entity '" + entityBinding.getEntityName() + "' is audited, but its superclass: '" + parentEntityName + "' is not." ); } @@ -549,16 +607,16 @@ public final class AuditMetadataGenerator { @SuppressWarnings({"unchecked"}) public void generateFirstPass( - PersistentClass pc, + EntityBinding entityBinding, ClassAuditingData auditingData, EntityXmlMappingData xmlMappingData, boolean isAudited) { - final String schema = getSchema( auditingData.getAuditTable().schema(), pc.getTable() ); - final String catalog = getCatalog( auditingData.getAuditTable().catalog(), pc.getTable() ); + final String schema = getSchema( auditingData.getAuditTable().schema(), entityBinding.getPrimaryTable() ); + final String catalog = getCatalog( auditingData.getAuditTable().catalog(), entityBinding.getPrimaryTable() ); if ( !isAudited ) { - final String entityName = pc.getEntityName(); - final IdMappingData idMapper = idMetadataGenerator.addId( pc, false ); + final String entityName = entityBinding.getEntityName(); + final IdMappingData idMapper = idMetadataGenerator.addId( entityBinding, false ); if ( idMapper == null ) { // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception @@ -574,7 +632,7 @@ public final class AuditMetadataGenerator { final String parentEntityName = null; final EntityConfiguration entityCfg = new EntityConfiguration( entityName, - pc.getClassName(), + entityBinding.getEntity().getDescriptor().getName().fullName(), idMapper, propertyMapper, parentEntityName @@ -583,11 +641,14 @@ public final class AuditMetadataGenerator { return; } - final String entityName = pc.getEntityName(); + final String entityName = entityBinding.getEntityName(); LOG.debugf( "Generating first-pass auditing mapping for entity %s", entityName ); - final String auditEntityName = verEntCfg.getAuditEntityName( entityName ); - final String auditTableName = verEntCfg.getAuditTableName( entityName, pc.getTable().getName() ); + final String auditEntityName = context.getAuditEntitiesConfiguration().getAuditEntityName( entityName ); + final String auditTableName = context.getAuditEntitiesConfiguration().getAuditTableName( + entityName, + entityBinding.getPrimaryTableName() + ); // Registering the audit entity name, now that it is known auditEntityNameRegister.register( auditEntityName ); @@ -595,9 +656,9 @@ public final class AuditMetadataGenerator { final AuditTableData auditTableData = new AuditTableData( auditEntityName, auditTableName, schema, catalog ); // Generating a mapping for the id - final IdMappingData idMapper = idMetadataGenerator.addId( pc, true ); + final IdMappingData idMapper = idMetadataGenerator.addId( entityBinding, true ); - final InheritanceType inheritanceType = InheritanceType.get( pc ); + final InheritanceType inheritanceType = InheritanceType.get( entityBinding ); // These properties will be read from the mapping data final Element classMapping; @@ -609,26 +670,26 @@ public final class AuditMetadataGenerator { // Reading the mapping data depending on inheritance type (if any) switch ( inheritanceType ) { case NONE: - mappingData = generateMappingData( pc, xmlMappingData, auditTableData, idMapper ); + mappingData = generateMappingData( entityBinding, xmlMappingData, auditTableData, idMapper ); break; case SINGLE: - mappingData = generateInheritanceMappingData( pc, xmlMappingData, auditTableData, "subclass" ); + mappingData = generateInheritanceMappingData( entityBinding, xmlMappingData, auditTableData, "subclass" ); break; case JOINED: - mappingData = generateInheritanceMappingData( pc, xmlMappingData, auditTableData, "joined-subclass" ); + mappingData = generateInheritanceMappingData( entityBinding, xmlMappingData, auditTableData, "joined-subclass" ); // Adding the "key" element with all id columns... final Element keyMapping = mappingData.getFirst().addElement( "key" ); - MetadataTools.addColumns( keyMapping, pc.getTable().getPrimaryKey().columnIterator() ); + MetadataTools.addColumns( keyMapping, entityBinding.getPrimaryTable().getPrimaryKey().getColumns() ); // ... and the revision number column, read from the revision info relation mapping. keyMapping.add( (Element) cloneAndSetupRevisionInfoRelationMapping().element( "column" ).clone() ); break; case TABLE_PER_CLASS: - mappingData = generateInheritanceMappingData( pc, xmlMappingData, auditTableData, "union-subclass" ); + mappingData = generateInheritanceMappingData( entityBinding, xmlMappingData, auditTableData, "union-subclass" ); break; default: @@ -643,32 +704,38 @@ public final class AuditMetadataGenerator { // Mapping unjoined properties addProperties( - classMapping, pc.getUnjoinedPropertyIterator(), propertyMapper, - auditingData, pc.getEntityName(), xmlMappingData, + classMapping, + entityBinding.getNonIdAttributeBindingClosure(), // TODO: this needs to be corrected to only get non-joined attribute bindings. + //entityBinding.getUnjoinedPropertyIterator(), + propertyMapper, + auditingData, + entityBinding.getEntityName(), + xmlMappingData, true ); + // TODO: add support for joins // Creating and mapping joins (first pass) - createJoins( pc, classMapping, auditingData ); - addJoins( pc, propertyMapper, auditingData, pc.getEntityName(), xmlMappingData, true ); + //createJoins( entityBinding, classMapping, auditingData ); + //addJoins( entityBinding, propertyMapper, auditingData, entityBinding.getEntityName(), xmlMappingData, true ); // Storing the generated configuration final EntityConfiguration entityCfg = new EntityConfiguration( auditEntityName, - pc.getClassName(), + entityBinding.getEntity().getDescriptor().getName().fullName(), idMapper, propertyMapper, parentEntityName ); - entitiesConfigurations.put( pc.getEntityName(), entityCfg ); + entitiesConfigurations.put( entityBinding.getEntityName(), entityCfg ); } @SuppressWarnings({"unchecked"}) public void generateSecondPass( - PersistentClass pc, + EntityBinding entityBinding, ClassAuditingData auditingData, EntityXmlMappingData xmlMappingData) { - final String entityName = pc.getEntityName(); + final String entityName = entityBinding.getEntityName(); LOG.debugf( "Generating second-pass auditing mapping for entity %s", entityName ); final CompositeMapperBuilder propertyMapper = entitiesConfigurations.get( entityName ).getPropertyMapper(); @@ -678,7 +745,8 @@ public final class AuditMetadataGenerator { addProperties( parent, - pc.getUnjoinedPropertyIterator(), + entityBinding.getNonIdAttributeBindingClosure(), // TODO: this needs to be corrected to only get non-joined attribute bindings. + //entityBinding.getUnjoinedPropertyIterator(), propertyMapper, auditingData, entityName, @@ -686,8 +754,9 @@ public final class AuditMetadataGenerator { false ); + // TODO: add suuport for joins // Mapping joins (second pass) - addJoins( pc, propertyMapper, auditingData, entityName, xmlMappingData, false ); + //addJoins( entityBinding, propertyMapper, auditingData, entityName, xmlMappingData, false ); } public Map getEntitiesConfigurations() { @@ -700,26 +769,10 @@ public final class AuditMetadataGenerator { return basicMetadataGenerator; } - Configuration getCfg() { - return cfg; - } - - GlobalConfiguration getGlobalCfg() { - return globalCfg; - } - - AuditEntitiesConfiguration getVerEntCfg() { - return verEntCfg; - } - AuditStrategy getAuditStrategy() { return auditStrategy; } - ClassLoaderService getClassLoaderService() { - return classLoaderService; - } - AuditEntityNameRegister getAuditEntityNameRegister() { return auditEntityNameRegister; } 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 3fb8bf79c3..c20ee07ba6 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 @@ -23,16 +23,19 @@ */ package org.hibernate.envers.configuration.internal.metadata; -import java.util.Properties; +import java.util.List; +import java.util.Map; import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData; import org.hibernate.envers.internal.entities.mapper.SimpleMapperBuilder; -import org.hibernate.mapping.SimpleValue; -import org.hibernate.mapping.Value; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; +import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.type.BasicType; import org.hibernate.type.CustomType; import org.hibernate.type.EnumType; -import org.hibernate.type.SerializableToBlobType; import org.hibernate.type.Type; import org.hibernate.usertype.DynamicParameterizedType; @@ -46,18 +49,23 @@ import org.dom4j.Element; public final class BasicMetadataGenerator { @SuppressWarnings({"unchecked"}) boolean addBasic( - Element parent, PropertyAuditingData propertyAuditingData, - Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) { - final Type type = value.getType(); - - if ( type instanceof BasicType - || type instanceof SerializableToBlobType - || "org.hibernate.type.PrimitiveByteArrayBlobType".equals( type.getClass().getName() ) ) { + Element parent, + PropertyAuditingData propertyAuditingData, + HibernateTypeDescriptor hibernateTypeDescriptor, + List values, + boolean insertable, + SimpleMapperBuilder mapper, + boolean key) { + if ( hibernateTypeDescriptor.getResolvedTypeMapping() instanceof BasicType + || "org.hibernate.type.PrimitiveByteArrayBlobType".equals( + hibernateTypeDescriptor.getJavaTypeDescriptor() + .getName() + .fullName() + ) ) { if ( parent != null ) { - final boolean addNestedType = (value instanceof SimpleValue) - && ((SimpleValue) value).getTypeParameters() != null; + final boolean addNestedType = !hibernateTypeDescriptor.getTypeParameters().isEmpty(); - final String typeName = resolveType( value ); + final String typeName = resolveTypeName( hibernateTypeDescriptor ); final Element propMapping = MetadataTools.addProperty( parent, @@ -66,22 +74,22 @@ public final class BasicMetadataGenerator { propertyAuditingData.isForceInsertable() || insertable, key ); - MetadataTools.addColumns( propMapping, value.getColumnIterator() ); + MetadataTools.addValuesAsColumns( propMapping, values ); if ( addNestedType ) { - final Properties typeParameters = ((SimpleValue) value).getTypeParameters(); + final Map typeParameters = hibernateTypeDescriptor.getTypeParameters(); final Element typeMapping = propMapping.addElement( "type" ); typeMapping.addAttribute( "name", typeName ); if ( "org.hibernate.type.EnumType".equals( typeName ) ) { // Proper handling of enumeration type - mapEnumerationType( typeMapping, type, typeParameters ); + mapEnumerationType( typeMapping, hibernateTypeDescriptor.getResolvedTypeMapping(), typeParameters ); } else { // By default copying all Hibernate properties for ( Object object : typeParameters.keySet() ) { final String keyType = (String) object; - final String property = typeParameters.getProperty( keyType ); + final String property = typeParameters.get( keyType ); if ( property != null ) { typeMapping.addElement( "param" ).addAttribute( "name", keyType ).setText( property ); @@ -103,26 +111,23 @@ public final class BasicMetadataGenerator { return true; } - private String resolveType(Value value) { - final Type type = value.getType(); - String typeName = null; - if ( value instanceof SimpleValue ) { - typeName = ( (SimpleValue) value ).getTypeName(); - } + private String resolveTypeName(HibernateTypeDescriptor hibernateTypeDescriptor) { + final Type type = hibernateTypeDescriptor.getResolvedTypeMapping(); + String typeName = hibernateTypeDescriptor.getExplicitTypeName(); if ( typeName == null ) { typeName = type.getName(); } if ( typeName == null ) { - typeName = type.getClass().getName(); + typeName = hibernateTypeDescriptor.getJavaTypeDescriptor().getName().fullName(); } return typeName; } - private void mapEnumerationType(Element parent, Type type, Properties parameters) { - if ( parameters.getProperty( EnumType.ENUM ) != null ) { + private void mapEnumerationType(Element parent, Type type, Map parameters) { + if ( parameters.get( EnumType.ENUM ) != null ) { parent.addElement( "param" ) .addAttribute( "name", EnumType.ENUM ) - .setText( parameters.getProperty( EnumType.ENUM ) ); + .setText( parameters.get( EnumType.ENUM ) ); } else { parent.addElement( "param" ).addAttribute( "name", EnumType.ENUM ).setText( @@ -130,9 +135,9 @@ public final class BasicMetadataGenerator { .getName() ); } - if ( parameters.getProperty( EnumType.NAMED ) != null ) { + if ( parameters.get( EnumType.NAMED ) != null ) { parent.addElement( "param" ).addAttribute( "name", EnumType.NAMED ).setText( - parameters.getProperty( + parameters.get( EnumType.NAMED ) ); @@ -151,15 +156,15 @@ public final class BasicMetadataGenerator { boolean addManyToOne( Element parent, PropertyAuditingData propertyAuditingData, - Value value, + ManyToOneAttributeBinding attributeBinding, SimpleMapperBuilder mapper) { - final Type type = value.getType(); + final Type type = attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); // A null mapper occurs when adding to composite-id element final Element manyToOneElement = parent.addElement( mapper != null ? "many-to-one" : "key-many-to-one" ); manyToOneElement.addAttribute( "name", propertyAuditingData.getName() ); manyToOneElement.addAttribute( "class", type.getName() ); - MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() ); + MetadataTools.addValuesAsColumns( manyToOneElement, attributeBinding.getValues() ); // A null mapper means that we only want to add xml mappings if ( mapper != null ) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java index 0452eae109..4c924b6111 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java @@ -26,7 +26,6 @@ package org.hibernate.envers.configuration.internal.metadata; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -34,14 +33,15 @@ import java.util.TreeMap; import java.util.TreeSet; import javax.persistence.JoinColumn; +import org.hibernate.AssertionFailure; import org.hibernate.MappingException; -import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.envers.ModificationStore; import org.hibernate.envers.RelationTargetAuditMode; import org.hibernate.envers.configuration.internal.metadata.reader.AuditedPropertiesReader; import org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditedPropertiesReader; import org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData; import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData; +import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.EnversMessageLogger; import org.hibernate.envers.internal.entities.EntityConfiguration; import org.hibernate.envers.internal.entities.IdMappingData; @@ -78,17 +78,24 @@ import org.hibernate.envers.internal.tools.MappingTools; import org.hibernate.envers.internal.tools.ReflectionTools; import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.envers.internal.tools.Tools; -import org.hibernate.mapping.Collection; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.IndexedCollection; -import org.hibernate.mapping.ManyToOne; -import org.hibernate.mapping.OneToMany; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.Table; -import org.hibernate.mapping.Value; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.CompositePluralAttributeElementBinding; +import org.hibernate.metamodel.spi.binding.CompositePluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; +import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeAssociationElementBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.domain.PluralAttribute; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.type.BagType; import org.hibernate.type.ComponentType; +import org.hibernate.type.EntityType; import org.hibernate.type.ListType; import org.hibernate.type.ManyToOneType; import org.hibernate.type.MapType; @@ -113,9 +120,10 @@ public final class CollectionMetadataGenerator { CollectionMetadataGenerator.class.getName() ); + private final AuditConfiguration.AuditConfigurationContext context; private final AuditMetadataGenerator mainGenerator; private final String propertyName; - private final Collection propertyValue; + private final PluralAttributeBinding pluralAttributeBinding; private final CompositeMapperBuilder currentMapper; private final String referencingEntityName; private final EntityXmlMappingData xmlMappingData; @@ -129,7 +137,7 @@ public final class CollectionMetadataGenerator { /** * @param mainGenerator Main generator, giving access to configuration and the basic mapper. - * @param propertyValue Value of the collection, as mapped by Hibernate. + * @param pluralAttributeBinding Value of the collection, as mapped by Hibernate. * @param currentMapper Mapper, to which the appropriate {@link PropertyMapper} will be added. * @param referencingEntityName Name of the entity that owns this collection. * @param xmlMappingData In case this collection requires a middle table, additional mapping documents will @@ -139,12 +147,15 @@ public final class CollectionMetadataGenerator { * table and the value of the @MapKey annotation, if there was one. */ public CollectionMetadataGenerator( + AuditConfiguration.AuditConfigurationContext context, AuditMetadataGenerator mainGenerator, - Collection propertyValue, CompositeMapperBuilder currentMapper, + PluralAttributeBinding pluralAttributeBinding, + CompositeMapperBuilder currentMapper, String referencingEntityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData) { + this.context = context; this.mainGenerator = mainGenerator; - this.propertyValue = propertyValue; + this.pluralAttributeBinding = pluralAttributeBinding; this.currentMapper = currentMapper; this.referencingEntityName = referencingEntityName; this.xmlMappingData = xmlMappingData; @@ -157,17 +168,24 @@ public final class CollectionMetadataGenerator { throw new MappingException( "Unable to read auditing configuration for " + referencingEntityName + "!" ); } - referencedEntityName = MappingTools.getReferencedEntityName( propertyValue.getElement() ); + referencedEntityName = MappingTools.getReferencedEntityName( pluralAttributeBinding ); } void addCollection() { - final Type type = propertyValue.getType(); - final Value value = propertyValue.getElement(); + final Type type = pluralAttributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); + final PluralAttributeElementBinding.Nature elementNature = + pluralAttributeBinding.getPluralAttributeElementBinding().getNature(); final boolean oneToManyAttachedType = type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType; - final boolean inverseOneToMany = (value instanceof OneToMany) && (propertyValue.isInverse()); - final boolean owningManyToOneWithJoinTableBidirectional = (value instanceof ManyToOne) && (propertyAuditingData.getRelationMappedBy() != null); - final boolean fakeOneToManyBidirectional = (value instanceof OneToMany) && (propertyAuditingData.getAuditMappedBy() != null); + final boolean inverseOneToMany = + (elementNature == PluralAttributeElementBinding.Nature.ONE_TO_MANY) && + ( pluralAttributeBinding.getPluralAttributeKeyBinding().isInverse() ); + final boolean owningManyToOneWithJoinTableBidirectional = + (elementNature == PluralAttributeAssociationElementBinding.Nature.MANY_TO_MANY) && + (propertyAuditingData.getRelationMappedBy() != null); + final boolean fakeOneToManyBidirectional = + (elementNature == PluralAttributeElementBinding.Nature.ONE_TO_MANY) + && (propertyAuditingData.getAuditMappedBy() != null); if ( oneToManyAttachedType && (inverseOneToMany || fakeOneToManyBidirectional || owningManyToOneWithJoinTableBidirectional) ) { // A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...") @@ -181,7 +199,7 @@ public final class CollectionMetadataGenerator { private MiddleIdData createMiddleIdData(IdMappingData idMappingData, String prefix, String entityName) { return new MiddleIdData( - mainGenerator.getVerEntCfg(), idMappingData, prefix, entityName, + context.getAuditEntitiesConfiguration(), idMappingData, prefix, entityName, mainGenerator.getEntitiesConfigurations().containsKey( entityName ) ); } @@ -194,7 +212,9 @@ public final class CollectionMetadataGenerator { propertyName ); - final String mappedBy = getMappedBy( propertyValue ); + final String mappedBy = getMappedBy( + (PluralAttributeAssociationElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() + ); final IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData( referencingEntityName, @@ -230,8 +250,8 @@ public final class CollectionMetadataGenerator { // Generating the query generator - it should read directly from the related entity. final RelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator( - mainGenerator.getGlobalCfg(), - mainGenerator.getVerEntCfg(), + context.getGlobalConfiguration(), + context.getAuditEntitiesConfiguration(), mainGenerator.getAuditStrategy(), referencingIdData, referencedEntityName, @@ -241,7 +261,7 @@ public final class CollectionMetadataGenerator { // Creating common mapper data. final CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData( - mainGenerator.getVerEntCfg(), referencedEntityName, + context.getAuditEntitiesConfiguration(), referencedEntityName, propertyAuditingData.getPropertyData(), referencingIdData, queryGenerator ); @@ -327,19 +347,19 @@ public final class CollectionMetadataGenerator { } } - private String getMiddleTableName(Collection value, String entityName) { + private String getMiddleTableName(PluralAttributeBinding attributeBinding, String entityName) { // We check how Hibernate maps the collection. - if ( value.getElement() instanceof OneToMany && !value.isInverse() ) { + if ( attributeBinding.getPluralAttributeElementBinding().getNature() == + PluralAttributeElementBinding.Nature.ONE_TO_MANY && + !attributeBinding.getPluralAttributeKeyBinding().isInverse() ) { // This must be a @JoinColumn+@OneToMany mapping. Generating the table name, as Hibernate doesn't use a // middle table for mapping this relation. return StringTools.getLastComponent( entityName ) + "_" + StringTools.getLastComponent( - MappingTools.getReferencedEntityName( - value.getElement() - ) + MappingTools.getReferencedEntityName( attributeBinding ) ); } // Hibernate uses a middle table for mapping this relation, so we get it's name directly. - return value.getCollectionTable().getName(); + return attributeBinding.getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().getName(); } @SuppressWarnings({"unchecked"}) @@ -359,9 +379,9 @@ public final class CollectionMetadataGenerator { auditMiddleEntityName = propertyAuditingData.getJoinTable().name(); } else { - final String middleTableName = getMiddleTableName( propertyValue, referencingEntityName ); - auditMiddleTableName = mainGenerator.getVerEntCfg().getAuditTableName( null, middleTableName ); - auditMiddleEntityName = mainGenerator.getVerEntCfg().getAuditEntityName( middleTableName ); + final String middleTableName = getMiddleTableName( pluralAttributeBinding, referencingEntityName ); + auditMiddleTableName = context.getAuditEntitiesConfiguration().getAuditTableName( null, middleTableName ); + auditMiddleEntityName = context.getAuditEntitiesConfiguration().getAuditEntityName( middleTableName ); } LOG.debugf( "Using join table name: %s", auditMiddleTableName ); @@ -369,7 +389,7 @@ public final class CollectionMetadataGenerator { // Generating the XML mapping for the middle entity, only if the relation isn't inverse. // If the relation is inverse, will be later checked by comparing middleEntityXml with null. Element middleEntityXml; - if ( !propertyValue.isInverse() ) { + if ( !pluralAttributeBinding.getPluralAttributeKeyBinding().isInverse() ) { // Generating a unique middle entity name auditMiddleEntityName = mainGenerator.getAuditEntityNameRegister().createUnique( auditMiddleEntityName ); @@ -379,7 +399,7 @@ public final class CollectionMetadataGenerator { middleEntityXml = createMiddleEntityXml( auditMiddleTableName, auditMiddleEntityName, - propertyValue.getWhere() + pluralAttributeBinding.getWhere() ); } else { @@ -399,11 +419,11 @@ public final class CollectionMetadataGenerator { String referencingPrefixRelated; String referencedPrefix; - if ( propertyValue.isInverse() ) { + if ( pluralAttributeBinding.getPluralAttributeKeyBinding().isInverse() ) { // If the relation is inverse, then referencedEntityName is not null. mappedBy = getMappedBy( - propertyValue.getCollectionTable(), - mainGenerator.getCfg().getClassMapping( referencedEntityName ) + pluralAttributeBinding.getPluralAttributeKeyBinding().getCollectionTable(), + context.getEntityBinding( referencedEntityName ) ); referencingPrefixRelated = mappedBy + "_"; @@ -427,8 +447,8 @@ public final class CollectionMetadataGenerator { // references some entities (either from the element or index). At the end, this will be used to build // a query generator to read the raw data collection from the middle table. final QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder( - mainGenerator.getGlobalCfg(), - mainGenerator.getVerEntCfg(), + context.getGlobalConfiguration(), + context.getAuditEntitiesConfiguration(), mainGenerator.getAuditStrategy(), referencingIdData, auditMiddleEntityName, @@ -440,7 +460,9 @@ public final class CollectionMetadataGenerator { // Adding related-entity (in this case: the referencing's entity id) id mapping to the xml. addRelatedToXmlMapping( middleEntityXml, referencingPrefixRelated, - MetadataTools.getColumnNameIterator( propertyValue.getKey().getColumnIterator() ), + MetadataTools.getColumnNameIterator( + pluralAttributeBinding.getPluralAttributeKeyBinding().getValues().iterator() + ), referencingIdMapping ); } @@ -449,11 +471,11 @@ public final class CollectionMetadataGenerator { // Generating the element mapping. // ****** final MiddleComponentData elementComponentData = addValueToMiddleTable( - propertyValue.getElement(), middleEntityXml, queryGeneratorBuilder, referencedPrefix, - propertyAuditingData.getJoinTable().inverseJoinColumns() + propertyAuditingData.getJoinTable().inverseJoinColumns(), + false ); // ****** @@ -469,7 +491,7 @@ public final class CollectionMetadataGenerator { // Creating common data final CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData( - mainGenerator.getVerEntCfg(), + context.getAuditEntitiesConfiguration(), auditMiddleEntityName, propertyAuditingData.getPropertyData(), referencingIdData, @@ -486,17 +508,18 @@ public final class CollectionMetadataGenerator { } private MiddleComponentData addIndex(Element middleEntityXml, QueryGeneratorBuilder queryGeneratorBuilder) { - if ( propertyValue instanceof IndexedCollection ) { - final IndexedCollection indexedValue = (IndexedCollection) propertyValue; + if ( pluralAttributeBinding.getAttribute().getNature().isIndexable() ) { + final PluralAttributeIndexBinding indexBinding = + ( (IndexedPluralAttributeBinding) pluralAttributeBinding ).getPluralAttributeIndexBinding(); final String mapKey = propertyAuditingData.getMapKey(); if ( mapKey == null ) { // This entity doesn't specify a javax.persistence.MapKey. Mapping it to the middle entity. return addValueToMiddleTable( - indexedValue.getIndex(), middleEntityXml, queryGeneratorBuilder, "mapkey", - null + null, + true ); } else { @@ -507,7 +530,7 @@ public final class CollectionMetadataGenerator { // The key of the map is the id of the entity. return new MiddleComponentData( new MiddleMapKeyIdComponentMapper( - mainGenerator.getVerEntCfg(), + context.getAuditEntitiesConfiguration(), referencedIdMapping.getIdMapper() ), currentIndex @@ -531,29 +554,46 @@ public final class CollectionMetadataGenerator { } } + private PluralAttributeIndexBinding getPluralAttributeIndexBinding() { + if ( !pluralAttributeBinding.getAttribute().getNature().isIndexable() ) { + throw new AssertionFailure( "This method is only valid for an indexed plural attribute binding." ); + } + return ( (IndexedPluralAttributeBinding) pluralAttributeBinding ).getPluralAttributeIndexBinding(); + } + /** - * @param value Value, which should be mapped to the middle-table, either as a relation to another entity, - * or as a simple value. * @param xmlMapping If not null, xml mapping for this value is added to this element. * @param queryGeneratorBuilder In case value is a relation to another entity, information about it * should be added to the given. * @param prefix Prefix for proeprty names of related entities identifiers. * @param joinColumns Names of columns to use in the xml mapping, if this array isn't null and has any elements. + * @param isIndex true, if the value is for the collection index; false, if the value is for the collection element. * * @return Data for mapping this component. */ @SuppressWarnings({"unchecked"}) private MiddleComponentData addValueToMiddleTable( - Value value, Element xmlMapping, QueryGeneratorBuilder queryGeneratorBuilder, String prefix, - JoinColumn[] joinColumns) { - final Type type = value.getType(); - if ( type instanceof ManyToOneType ) { + JoinColumn[] joinColumns, + boolean isIndex) { + + final HibernateTypeDescriptor hibernateTypeDescriptor; + final List values; + if ( isIndex ) { + hibernateTypeDescriptor = getPluralAttributeIndexBinding().getHibernateTypeDescriptor(); + values = getPluralAttributeIndexBinding().getValues(); + } + else { + hibernateTypeDescriptor = pluralAttributeBinding.getPluralAttributeElementBinding().getHibernateTypeDescriptor(); + values = pluralAttributeBinding.getPluralAttributeElementBinding().getValues(); + + } ; + if ( hibernateTypeDescriptor.getResolvedTypeMapping() instanceof ManyToOneType ) { final String prefixRelated = prefix + "_"; - final String referencedEntityName = MappingTools.getReferencedEntityName( value ); + final String referencedEntityName = MappingTools.getReferencedEntityName( pluralAttributeBinding ); final IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData( referencingEntityName, @@ -569,7 +609,7 @@ public final class CollectionMetadataGenerator { xmlMapping, prefixRelated, joinColumns != null && joinColumns.length > 0 ? MetadataTools.getColumnNameIterator( joinColumns ) - : MetadataTools.getColumnNameIterator( value.getColumnIterator() ), + : MetadataTools.getColumnNameIterator( values.iterator() ), referencedIdMapping ); } @@ -588,12 +628,20 @@ public final class CollectionMetadataGenerator { queryGeneratorBuilder.getCurrentIndex() ); } - else if ( type instanceof ComponentType ) { + else if ( hibernateTypeDescriptor.getResolvedTypeMapping() instanceof ComponentType ) { + final CompositeAttributeBindingContainer compositeAttributeBindingContainer; + if ( isIndex ) { + compositeAttributeBindingContainer = + ( ( CompositePluralAttributeIndexBinding ) getPluralAttributeIndexBinding() ).getCompositeAttributeBindingContainer(); + } + else { + compositeAttributeBindingContainer = + ( (CompositePluralAttributeElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() ).getCompositeAttributeBindingContainer(); + } // Collection of embeddable elements. - final Component component = (Component) value; final Class componentClass = ReflectionTools.loadClass( - component.getComponentClassName(), - mainGenerator.getClassLoaderService() + hibernateTypeDescriptor.getJavaTypeDescriptor().getName().fullName(), + context.getClassLoaderService() ); final MiddleEmbeddableComponentMapper componentMapper = new MiddleEmbeddableComponentMapper( new MultiPropertyMapper(), @@ -602,12 +650,15 @@ public final class CollectionMetadataGenerator { final Element parentXmlMapping = xmlMapping.getParent(); final ComponentAuditingData auditData = new ComponentAuditingData(); - final ReflectionManager reflectionManager = mainGenerator.getCfg().getReflectionManager(); new ComponentAuditedPropertiesReader( - ModificationStore.FULL, - new AuditedPropertiesReader.ComponentPropertiesSource( reflectionManager, component ), - auditData, mainGenerator.getGlobalCfg(), reflectionManager, "" + context, + auditData, + new AuditedPropertiesReader.ComponentPropertiesSource( + context.getClassInfo( compositeAttributeBindingContainer.getAttributeContainer() ), + compositeAttributeBindingContainer + ), + "" ).read(); // Emulating first pass. @@ -615,12 +666,11 @@ public final class CollectionMetadataGenerator { final PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData( auditedPropertyName ); mainGenerator.addValue( parentXmlMapping, - component.getProperty( auditedPropertyName ).getValue(), + compositeAttributeBindingContainer.locateAttributeBinding( auditedPropertyName ), componentMapper, prefix, xmlMappingData, nestedAuditingData, true, - true, true ); } @@ -630,12 +680,11 @@ public final class CollectionMetadataGenerator { final PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData( auditedPropertyName ); mainGenerator.addValue( parentXmlMapping, - component.getProperty( auditedPropertyName ).getValue(), + compositeAttributeBindingContainer.locateAttributeBinding( auditedPropertyName ), componentMapper, referencingEntityName, xmlMappingData, nestedAuditingData, - true, false, true ); @@ -643,8 +692,8 @@ public final class CollectionMetadataGenerator { // Add an additional column holding a number to make each entry unique within the set. // Embeddable properties may contain null values, so cannot be stored within composite primary key. - if ( propertyValue.isSet() ) { - final String setOrdinalPropertyName = mainGenerator.getVerEntCfg() + if ( ( pluralAttributeBinding.getAttribute() ).getNature() == PluralAttribute.Nature.SET ) { + final String setOrdinalPropertyName = context.getAuditEntitiesConfiguration() .getEmbeddableSetOrdinalPropertyName(); final Element ordinalProperty = MetadataTools.addProperty( xmlMapping, setOrdinalPropertyName, "integer", true, true @@ -669,21 +718,24 @@ public final class CollectionMetadataGenerator { null, false ), - value, + hibernateTypeDescriptor, + values, + true, // TODO: is this correct for collection element? null, - true, true ); if ( mapped ) { // Simple values are always stored in the first item of the array returned by the query generator. return new MiddleComponentData( - new MiddleSimpleComponentMapper( mainGenerator.getVerEntCfg(), prefix ), + new MiddleSimpleComponentMapper( context.getAuditEntitiesConfiguration(), prefix ), 0 ); } else { - mainGenerator.throwUnsupportedTypeException( type, referencingEntityName, propertyName ); + mainGenerator.throwUnsupportedTypeException( + hibernateTypeDescriptor.getResolvedTypeMapping(), referencingEntityName, propertyName + ); // Impossible to get here. throw new AssertionError(); } @@ -694,7 +746,7 @@ public final class CollectionMetadataGenerator { CommonCollectionMapperData commonCollectionMapperData, MiddleComponentData elementComponentData, MiddleComponentData indexComponentData) { - final Type type = propertyValue.getType(); + final Type type = pluralAttributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); final boolean embeddableElementType = isEmbeddableElementType(); if ( type instanceof SortedSetType ) { currentMapper.addComposite( @@ -704,7 +756,7 @@ public final class CollectionMetadataGenerator { TreeSet.class, SortedSetProxy.class, elementComponentData, - propertyValue.getComparator(), + pluralAttributeBinding.getComparator(), embeddableElementType, embeddableElementType ) @@ -733,7 +785,7 @@ public final class CollectionMetadataGenerator { SortedMapProxy.class, elementComponentData, indexComponentData, - propertyValue.getComparator(), + pluralAttributeBinding.getComparator(), embeddableElementType ) ); @@ -785,7 +837,7 @@ public final class CollectionMetadataGenerator { private void storeMiddleEntityRelationInformation(String mappedBy) { // Only if this is a relation (when there is a referenced entity). if ( referencedEntityName != null ) { - if ( propertyValue.isInverse() ) { + if ( pluralAttributeBinding.getPluralAttributeKeyBinding().isInverse() ) { referencingEntityConfiguration.addToManyMiddleNotOwningRelation( propertyName, mappedBy, @@ -801,11 +853,11 @@ public final class CollectionMetadataGenerator { private Element createMiddleEntityXml(String auditMiddleTableName, String auditMiddleEntityName, String where) { final String schema = mainGenerator.getSchema( propertyAuditingData.getJoinTable().schema(), - propertyValue.getCollectionTable() + pluralAttributeBinding.getPluralAttributeKeyBinding().getCollectionTable() ); final String catalog = mainGenerator.getCatalog( propertyAuditingData.getJoinTable().catalog(), - propertyValue.getCollectionTable() + pluralAttributeBinding.getPluralAttributeKeyBinding().getCollectionTable() ); final Element middleEntityXml = MetadataTools.createEntity( @@ -819,7 +871,7 @@ public final class CollectionMetadataGenerator { middleEntityXml.addAttribute( "where", where ); } - middleEntityXmlId.addAttribute( "name", mainGenerator.getVerEntCfg().getOriginalIdPropName() ); + middleEntityXmlId.addAttribute( "name", context.getAuditEntitiesConfiguration().getOriginalIdPropName() ); // Adding the revision number as a foreign key to the revision info entity to the composite id of the // middle table. @@ -828,7 +880,8 @@ public final class CollectionMetadataGenerator { // Adding the revision type property to the entity xml. mainGenerator.addRevisionType( isEmbeddableElementType() ? middleEntityXmlId : middleEntityXml, - middleEntityXml + middleEntityXml, + isEmbeddableElementType() ); // All other properties should also be part of the primary key of the middle entity. @@ -839,20 +892,15 @@ public final class CollectionMetadataGenerator { * Checks if the collection element is of {@link ComponentType} type. */ private boolean isEmbeddableElementType() { - return propertyValue.getElement().getType() instanceof ComponentType; + return pluralAttributeBinding.getPluralAttributeElementBinding() + .getHibernateTypeDescriptor().getResolvedTypeMapping().isComponentType(); } - private String getMappedBy(Collection collectionValue) { - PersistentClass referencedClass = null; - if ( collectionValue.getElement() instanceof OneToMany ) { - final OneToMany oneToManyValue = (OneToMany) collectionValue.getElement(); - referencedClass = oneToManyValue.getAssociatedClass(); - } - else if ( collectionValue.getElement() instanceof ManyToOne ) { - // Case for bi-directional relation with @JoinTable on the owning @ManyToOne side. - final ManyToOne manyToOneValue = (ManyToOne) collectionValue.getElement(); - referencedClass = manyToOneValue.getMappings().getClass( manyToOneValue.getReferencedEntityName() ); - } + private String getMappedBy(PluralAttributeAssociationElementBinding elementBinding) { + EntityBinding referencedEntityBinding = null; + final EntityType entityType = + (EntityType) elementBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); + referencedEntityBinding = context.getEntityBinding( entityType.getAssociatedEntityName() ); // If there's an @AuditMappedBy specified, returning it directly. final String auditMappedBy = propertyAuditingData.getAuditMappedBy(); @@ -861,27 +909,30 @@ public final class CollectionMetadataGenerator { } // searching in referenced class - String mappedBy = this.searchMappedBy( referencedClass, collectionValue ); + String mappedBy = this.searchMappedBy( referencedEntityBinding ); if ( mappedBy == null ) { LOG.debugf( "Going to search the mapped by attribute for %s in superclasses of entity: %s", propertyName, - referencedClass.getClassName() + referencedEntityBinding.getEntityName() ); - PersistentClass tempClass = referencedClass; - while ( (mappedBy == null) && (tempClass.getSuperclass() != null) ) { - LOG.debugf( "Searching in superclass: %s", tempClass.getSuperclass().getClassName() ); - mappedBy = this.searchMappedBy( tempClass.getSuperclass(), collectionValue ); - tempClass = tempClass.getSuperclass(); + EntityBinding tempEntityBinding = referencedEntityBinding; + while ( (mappedBy == null) && (tempEntityBinding.getSuperEntityBinding() != null) ) { + LOG.debugf( + "Searching in superclass: %s", + tempEntityBinding.getSuperEntityBinding().getEntity().getDescriptor().getName() + ); + mappedBy = this.searchMappedBy( tempEntityBinding.getSuperEntityBinding() ); + tempEntityBinding = tempEntityBinding.getSuperEntityBinding(); } } if ( mappedBy == null ) { throw new MappingException( "Unable to read the mapped by attribute for " + propertyName + " in " - + referencedClass.getClassName() + "!" + + referencedEntityBinding.getEntity().getDescriptor().getName() + "!" ); } @@ -889,22 +940,30 @@ public final class CollectionMetadataGenerator { } @SuppressWarnings({"unchecked"}) - private String searchMappedBy(PersistentClass referencedClass, Collection collectionValue) { - final Iterator assocClassProps = referencedClass.getPropertyIterator(); - while ( assocClassProps.hasNext() ) { - final Property property = assocClassProps.next(); + private String searchMappedBy(EntityBinding referencedEntityBinding) { + for ( AttributeBinding attributeBinding : referencedEntityBinding.attributeBindings() ) { + if ( !attributeBinding.isAssociation() ) { + continue; + } + final List attributeValues; + if ( attributeBinding.getAttribute().isSingular() ) { + attributeValues = ( (SingularAttributeBinding) attributeBinding ).getValues(); + } + else { + attributeValues = ( (PluralAttributeBinding) attributeBinding ).getPluralAttributeElementBinding().getValues(); + } if ( Tools.iteratorsContentEqual( - property.getValue().getColumnIterator(), - collectionValue.getKey().getColumnIterator() + attributeValues.iterator(), + pluralAttributeBinding.getPluralAttributeKeyBinding().getValues().iterator() ) ) { - return property.getName(); + return attributeBinding.getAttribute().getName(); } } return null; } - private String getMappedBy(Table collectionTable, PersistentClass referencedClass) { + private String getMappedBy(TableSpecification collectionTable, EntityBinding referencedClass) { // If there's an @AuditMappedBy specified, returning it directly. final String auditMappedBy = propertyAuditingData.getAuditMappedBy(); if ( auditMappedBy != null ) { @@ -919,21 +978,24 @@ public final class CollectionMetadataGenerator { LOG.debugf( "Going to search the mapped by attribute for %s in superclasses of entity: %s", propertyName, - referencedClass.getClassName() + referencedClass.getEntity().getDescriptor().getName() ); - PersistentClass tempClass = referencedClass; - while ( (mappedBy == null) && (tempClass.getSuperclass() != null) ) { - LOG.debugf( "Searching in superclass: %s", tempClass.getSuperclass().getClassName() ); - mappedBy = this.searchMappedBy( tempClass.getSuperclass(), collectionTable ); - tempClass = tempClass.getSuperclass(); + EntityBinding tempClass = referencedClass; + while ( (mappedBy == null) && (tempClass.getSuperEntityBinding() != null) ) { + LOG.debugf( + "Searching in superclass: %s", + tempClass.getSuperEntityBinding().getEntity().getDescriptor().getName() + ); + mappedBy = this.searchMappedBy( tempClass.getSuperEntityBinding(), collectionTable ); + tempClass = tempClass.getSuperEntityBinding(); } } if ( mappedBy == null ) { throw new MappingException( "Unable to read the mapped by attribute for " + propertyName + " in " - + referencedClass.getClassName() + "!" + + referencedClass.getEntity().getDescriptor().getName() + "!" ); } @@ -941,15 +1003,14 @@ public final class CollectionMetadataGenerator { } @SuppressWarnings({"unchecked"}) - private String searchMappedBy(PersistentClass referencedClass, Table collectionTable) { - final Iterator properties = referencedClass.getPropertyIterator(); - while ( properties.hasNext() ) { - final Property property = properties.next(); - if ( property.getValue() instanceof Collection ) { + private String searchMappedBy(EntityBinding referencedClass, TableSpecification collectionTable) { + for ( AttributeBinding attributeBinding : referencedClass.attributeBindings() ) { + if ( !attributeBinding.getAttribute().isSingular() ) { // The equality is intentional. We want to find a collection property with the same collection table. //noinspection ObjectEquality - if ( ((Collection) property.getValue()).getCollectionTable() == collectionTable ) { - return property.getName(); + if ( ((PluralAttributeBinding) attributeBinding ).getPluralAttributeKeyBinding().getCollectionTable() == + collectionTable ) { + return attributeBinding.getAttribute().getName(); } } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ComponentMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ComponentMetadataGenerator.java index 5dad4f4a0d..b74cadfd52 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ComponentMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ComponentMetadataGenerator.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.configuration.internal.metadata; -import java.util.Iterator; import java.util.Map; +import org.hibernate.EntityMode; import org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData; import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData; +import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder; -import org.hibernate.envers.internal.tools.ReflectionTools; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.Value; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.dom4j.Element; @@ -43,29 +43,29 @@ import org.dom4j.Element; * @author Lukasz Zuchowski (author at zuchos dot com) */ public final class ComponentMetadataGenerator { - private final AuditMetadataGenerator mainGenerator; + private final AuditConfiguration.AuditConfigurationContext context; - ComponentMetadataGenerator(AuditMetadataGenerator auditMetadataGenerator) { + private final AuditMetadataGenerator mainGenerator; + + ComponentMetadataGenerator(AuditConfiguration.AuditConfigurationContext context, AuditMetadataGenerator auditMetadataGenerator) { + this.context = context; mainGenerator = auditMetadataGenerator; } @SuppressWarnings({"unchecked"}) public void addComponent( Element parent, PropertyAuditingData propertyAuditingData, - Value value, CompositeMapperBuilder mapper, String entityName, + CompositeAttributeBinding compositeAttributeBinding, CompositeMapperBuilder mapper, String entityName, EntityXmlMappingData xmlMappingData, boolean firstPass) { - final Component propComponent = (Component) value; final Class componentClass; - if (propComponent.isDynamic()) { - componentClass = ReflectionTools.loadClass( - Map.class.getCanonicalName(), - mainGenerator.getClassLoaderService()); - + final EntityMode entityMode = compositeAttributeBinding.seekEntityBinding().getHierarchyDetails().getEntityMode(); + if ( entityMode == EntityMode.MAP ) { + componentClass = context.getClassLoaderService().classForName( Map.class.getCanonicalName() ); } else { - componentClass = ReflectionTools.loadClass( - propComponent.getComponentClassName(), - mainGenerator.getClassLoaderService() + // TODO: get rid of classloading. + componentClass = context.getClassLoaderService().classForName( + compositeAttributeBinding.getHibernateTypeDescriptor().getJavaTypeDescriptor().getName().fullName() ); } final CompositeMapperBuilder componentMapper = mapper.addComponent( @@ -77,18 +77,16 @@ public final class ComponentMetadataGenerator { final ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData; // Adding all properties of the component - final Iterator properties = (Iterator) propComponent.getPropertyIterator(); - while (properties.hasNext()) { - final Property property = properties.next(); + for ( AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) { final PropertyAuditingData componentPropertyAuditingData = - componentAuditingData.getPropertyAuditingData(property.getName()); + componentAuditingData.getPropertyAuditingData( attributeBinding.getAttribute().getName() ); // Checking if that property is audited if (componentPropertyAuditingData != null) { mainGenerator.addValue( - parent, property.getValue(), componentMapper, entityName, xmlMappingData, - componentPropertyAuditingData, property.isInsertable(), firstPass, false + parent, attributeBinding, componentMapper, entityName, xmlMappingData, + componentPropertyAuditingData, firstPass, false ); } } 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 0135dbcc0b..034813c85c 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 @@ -23,12 +23,11 @@ */ package org.hibernate.envers.configuration.internal.metadata; -import java.util.Iterator; - import org.hibernate.MappingException; import org.hibernate.envers.ModificationStore; import org.hibernate.envers.RelationTargetAuditMode; import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData; +import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.entities.IdMappingData; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.entities.mapper.SimpleMapperBuilder; @@ -36,10 +35,14 @@ import org.hibernate.envers.internal.entities.mapper.id.EmbeddedIdMapper; import org.hibernate.envers.internal.entities.mapper.id.MultipleIdMapper; import org.hibernate.envers.internal.entities.mapper.id.SimpleIdMapperBuilder; import org.hibernate.envers.internal.entities.mapper.id.SingleIdMapper; -import org.hibernate.envers.internal.tools.ReflectionTools; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; +import org.hibernate.id.EntityIdentifierNature; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.binding.EntityIdentifier; +import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.binding.SingularNonAssociationAttributeBinding; import org.hibernate.type.ManyToOneType; import org.hibernate.type.Type; @@ -52,53 +55,57 @@ import org.dom4j.tree.DefaultElement; * @author Adam Warski (adam at warski dot org) */ public final class IdMetadataGenerator { + private final AuditConfiguration.AuditConfigurationContext context; private final AuditMetadataGenerator mainGenerator; - IdMetadataGenerator(AuditMetadataGenerator auditMetadataGenerator) { + IdMetadataGenerator(AuditConfiguration.AuditConfigurationContext context, AuditMetadataGenerator auditMetadataGenerator) { + this.context = context; mainGenerator = auditMetadataGenerator; } @SuppressWarnings({"unchecked"}) private boolean addIdProperties( Element parent, - Iterator properties, + CompositeAttributeBinding compositeAttributeBinding, SimpleMapperBuilder mapper, boolean key, boolean audited) { - while ( properties.hasNext() ) { - final Property property = properties.next(); - final Type propertyType = property.getType(); - if ( !"_identifierMapper".equals( property.getName() ) ) { - boolean added = false; - if ( propertyType instanceof ManyToOneType ) { - added = mainGenerator.getBasicMetadataGenerator().addManyToOne( - parent, - getIdPersistentPropertyAuditingData( property ), - property.getValue(), - mapper - ); + //if ( compositeAttributeBinding.getAttribute().isSynthetic() ) { + // return true; + //} + for ( AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) { + final Type propertyType = attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); + final boolean added; + if ( propertyType instanceof ManyToOneType ) { + added = mainGenerator.getBasicMetadataGenerator().addManyToOne( + parent, + getIdPersistentPropertyAuditingData( attributeBinding ), + (ManyToOneAttributeBinding) attributeBinding, + mapper + ); + } + else { + final SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding; + // Last but one parameter: ids are always insertable + added = mainGenerator.getBasicMetadataGenerator().addBasic( + parent, + getIdPersistentPropertyAuditingData( singularAttributeBinding ), + singularAttributeBinding.getHibernateTypeDescriptor(), + singularAttributeBinding.getValues(), + singularAttributeBinding.isIncludedInInsert(), + mapper, + key + ); + } + if ( !added ) { + // If the entity is audited, and a non-supported id component is used, throwing an exception. + // If the entity is not audited, then we simply don't support this entity, even in + // target relation mode not audited. + if ( audited ) { + throw new MappingException( "Type not supported: " + propertyType.getClass().getName() ); } else { - // Last but one parameter: ids are always insertable - added = mainGenerator.getBasicMetadataGenerator().addBasic( - parent, - getIdPersistentPropertyAuditingData( property ), - property.getValue(), - mapper, - true, - key - ); - } - if ( !added ) { - // If the entity is audited, and a non-supported id component is used, throwing an exception. - // If the entity is not audited, then we simply don't support this entity, even in - // target relation mode not audited. - if ( audited ) { - throw new MappingException( "Type not supported: " + propertyType.getClass().getName() ); - } - else { - return false; - } + return false; } } } @@ -107,31 +114,30 @@ public final class IdMetadataGenerator { } @SuppressWarnings({"unchecked"}) - IdMappingData addId(PersistentClass pc, boolean audited) { + IdMappingData addId(EntityBinding entityBinding, boolean audited) { // Xml mapping which will be used for relations final Element relIdMapping = new DefaultElement( "properties" ); // Xml mapping which will be used for the primary key of the versions table final Element origIdMapping = new DefaultElement( "composite-id" ); - final Property idProp = pc.getIdentifierProperty(); - final Component idMapper = pc.getIdentifierMapper(); + //final Property idProp = pc.getIdentifierProperty(); + //final Component idMapper = pc.getIdentifierMapper(); // Checking if the id mapping is supported - if ( idMapper == null && idProp == null ) { - return null; - } + //if ( idMapper == null && idProp == null ) { + // return null; + //} + final EntityIdentifier entityIdentifier = entityBinding.getHierarchyDetails().getEntityIdentifier(); SimpleIdMapperBuilder mapper; - if ( idMapper != null ) { + if ( entityIdentifier.getLookupClassBinding().definedIdClass() ) { // Multiple id - final Class componentClass = ReflectionTools.loadClass( - ( (Component) pc.getIdentifier() ).getComponentClassName(), - mainGenerator.getClassLoaderService() - ); + final Class componentClass = entityIdentifier.getLookupClassBinding().getIdClassType(); + mapper = new MultipleIdMapper( componentClass ); if ( !addIdProperties( relIdMapping, - (Iterator) idMapper.getPropertyIterator(), + (CompositeAttributeBinding) entityIdentifier.getAttributeBinding(), mapper, false, audited @@ -142,7 +148,7 @@ public final class IdMetadataGenerator { // null mapper - the mapping where already added the first time, now we only want to generate the xml if ( !addIdProperties( origIdMapping, - (Iterator) idMapper.getPropertyIterator(), + (CompositeAttributeBinding) entityIdentifier.getAttributeBinding(), null, true, audited @@ -150,17 +156,16 @@ public final class IdMetadataGenerator { return null; } } - else if ( idProp.isComposite() ) { - // Embedded id - final Component idComponent = (Component) idProp.getValue(); - final Class embeddableClass = ReflectionTools.loadClass( - idComponent.getComponentClassName(), - mainGenerator.getClassLoaderService() + else if ( entityIdentifier.getNature() == EntityIdentifierNature.AGGREGATED_COMPOSITE ) { + // Embeddable id + // TODO: get rid of classloading. + final Class embeddableClass = context.getClassLoaderService().classForName( + entityIdentifier.getAttributeBinding().getHibernateTypeDescriptor().getJavaTypeDescriptor().getName().fullName() ); - mapper = new EmbeddedIdMapper( getIdPropertyData( idProp ), embeddableClass ); + mapper = new EmbeddedIdMapper( getIdPropertyData( entityIdentifier.getAttributeBinding() ), embeddableClass ); if ( !addIdProperties( relIdMapping, - (Iterator) idComponent.getPropertyIterator(), + (CompositeAttributeBinding) entityIdentifier.getAttributeBinding(), mapper, false, audited @@ -171,7 +176,7 @@ public final class IdMetadataGenerator { // null mapper - the mapping where already added the first time, now we only want to generate the xml if ( !addIdProperties( origIdMapping, - (Iterator) idComponent.getPropertyIterator(), + (CompositeAttributeBinding) entityIdentifier.getAttributeBinding(), null, true, audited @@ -186,25 +191,27 @@ public final class IdMetadataGenerator { // Last but one parameter: ids are always insertable mainGenerator.getBasicMetadataGenerator().addBasic( relIdMapping, - getIdPersistentPropertyAuditingData( idProp ), - idProp.getValue(), + getIdPersistentPropertyAuditingData( entityIdentifier.getAttributeBinding() ), + entityIdentifier.getAttributeBinding().getHibernateTypeDescriptor(), + entityIdentifier.getAttributeBinding().getValues(), + entityIdentifier.getAttributeBinding().isIncludedInInsert(), mapper, - true, false ); // null mapper - the mapping where already added the first time, now we only want to generate the xml mainGenerator.getBasicMetadataGenerator().addBasic( origIdMapping, - getIdPersistentPropertyAuditingData( idProp ), - idProp.getValue(), + getIdPersistentPropertyAuditingData( entityIdentifier.getAttributeBinding() ), + entityIdentifier.getAttributeBinding().getHibernateTypeDescriptor(), + entityIdentifier.getAttributeBinding().getValues(), + entityIdentifier.getAttributeBinding().isIncludedInInsert(), null, - true, true ); } - origIdMapping.addAttribute( "name", mainGenerator.getVerEntCfg().getOriginalIdPropName() ); + origIdMapping.addAttribute( "name", context.getAuditEntitiesConfiguration().getOriginalIdPropName() ); // Adding a relation to the revision entity (effectively: the "revision number" property) mainGenerator.addRevisionInfoRelation( origIdMapping ); @@ -212,16 +219,18 @@ public final class IdMetadataGenerator { return new IdMappingData( mapper, origIdMapping, relIdMapping ); } - private PropertyData getIdPropertyData(Property property) { + private PropertyData getIdPropertyData(SingularNonAssociationAttributeBinding idAttributeBinding) { return new PropertyData( - property.getName(), property.getName(), property.getPropertyAccessorName(), + idAttributeBinding.getAttribute().getName(), + idAttributeBinding.getAttribute().getName(), + idAttributeBinding.getPropertyAccessorName(), ModificationStore.FULL ); } - private PropertyAuditingData getIdPersistentPropertyAuditingData(Property property) { + private PropertyAuditingData getIdPersistentPropertyAuditingData(AttributeBinding property) { return new PropertyAuditingData( - property.getName(), property.getPropertyAccessorName(), + property.getAttribute().getName(), property.getPropertyAccessorName(), ModificationStore.FULL, RelationTargetAuditMode.AUDITED, null, null, false ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/InheritanceType.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/InheritanceType.java index e912f525ff..5aaaab02e8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/InheritanceType.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/InheritanceType.java @@ -24,11 +24,7 @@ package org.hibernate.envers.configuration.internal.metadata; import org.hibernate.MappingException; -import org.hibernate.mapping.JoinedSubclass; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.SingleTableSubclass; -import org.hibernate.mapping.Subclass; -import org.hibernate.mapping.UnionSubclass; +import org.hibernate.metamodel.spi.binding.EntityBinding; /** * @author Adam Warski (adam at warski dot org) @@ -40,30 +36,30 @@ public enum InheritanceType { TABLE_PER_CLASS; /** - * @param pc The class for which to get the inheritance type. + * @param entityBinding The class for which to get the inheritance type. * * @return The inheritance type of this class. NONE, if this class does not inherit from * another persistent class. */ - public static InheritanceType get(PersistentClass pc) { - final PersistentClass superclass = pc.getSuperclass(); - if ( superclass == null ) { + public static InheritanceType get(EntityBinding entityBinding) { + final EntityBinding superEntityBinding = entityBinding.getSuperEntityBinding(); + if ( superEntityBinding == null ) { return InheritanceType.NONE; } // We assume that every subclass is of the same type. - final Subclass subclass = (Subclass) superclass.getSubclassIterator().next(); + final EntityBinding subEntityBinding = superEntityBinding.getDirectSubEntityBindings().get( 0 ); - if ( subclass instanceof SingleTableSubclass ) { + if ( subEntityBinding.getHierarchyDetails().getInheritanceType() == org.hibernate.metamodel.spi.binding.InheritanceType.SINGLE_TABLE ) { return InheritanceType.SINGLE; } - else if ( subclass instanceof JoinedSubclass ) { + else if ( subEntityBinding.getHierarchyDetails().getInheritanceType() == org.hibernate.metamodel.spi.binding.InheritanceType.JOINED ) { return InheritanceType.JOINED; } - else if ( subclass instanceof UnionSubclass ) { + else if ( subEntityBinding.getHierarchyDetails().getInheritanceType() == org.hibernate.metamodel.spi.binding.InheritanceType.TABLE_PER_CLASS ) { return InheritanceType.TABLE_PER_CLASS; } - throw new MappingException( "Unknown subclass class: " + subclass.getClass() ); + throw new MappingException( "Unknown subclass class: " + subEntityBinding.getClass() ); } } 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 4e74fe43e0..0e2d5453af 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 @@ -24,12 +24,14 @@ package org.hibernate.envers.configuration.internal.metadata; import java.util.Iterator; +import java.util.List; import javax.persistence.JoinColumn; +import org.hibernate.AssertionFailure; import org.hibernate.envers.internal.tools.StringTools; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Formula; -import org.hibernate.mapping.Selectable; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.DerivedValue; +import org.hibernate.metamodel.spi.relational.Value; import org.dom4j.Attribute; import org.dom4j.Document; @@ -46,9 +48,11 @@ public final class MetadataTools { public static Element addNativelyGeneratedId( Element parent, String name, String type, - boolean useRevisionEntityWithNativeId) { + boolean useRevisionEntityWithNativeId, + String idColumnName) { final Element idMapping = parent.addElement( "id" ); idMapping.addAttribute( "name", name ).addAttribute( "type", type ); + MetadataTools.addColumn( idMapping, idColumnName, null, null, null, null, null, null, false ); final Element generatorMapping = idMapping.addElement( "generator" ); if ( useRevisionEntityWithNativeId ) { @@ -87,9 +91,11 @@ public final class MetadataTools { } propMapping.addAttribute( "name", name ); - propMapping.addAttribute( "insert", Boolean.toString( insertable ) ); - propMapping.addAttribute( "update", Boolean.toString( updateable ) ); + if ( !key ) { + propMapping.addAttribute( "insert", Boolean.toString( insertable ) ); + propMapping.addAttribute( "update", Boolean.toString( updateable ) ); + } if ( type != null ) { propMapping.addAttribute( "type", type ); } @@ -151,7 +157,7 @@ public final class MetadataTools { public static Element addColumn( Element parent, String name, - Integer length, + Long length, Integer scale, Integer precision, String sqlType, @@ -163,7 +169,7 @@ public final class MetadataTools { public static Element addColumn( Element parent, String name, - Integer length, + Long length, Integer scale, Integer precision, String sqlType, @@ -215,16 +221,18 @@ public final class MetadataTools { classMapping.addAttribute( "discriminator-value", discriminatorValue ); } - if ( !StringTools.isEmpty( auditTableData.getAuditTableName() ) ) { - classMapping.addAttribute( "table", auditTableData.getAuditTableName() ); - } + if ( !"subclass".equals( type ) ) { + if ( !StringTools.isEmpty( auditTableData.getAuditTableName() ) ) { + classMapping.addAttribute( "table", auditTableData.getAuditTableName() ); + } - if ( !StringTools.isEmpty( auditTableData.getSchema() ) ) { - classMapping.addAttribute( "schema", auditTableData.getSchema() ); - } + if ( !StringTools.isEmpty( auditTableData.getSchema() ) ) { + classMapping.addAttribute( "schema", auditTableData.getSchema() ); + } - if ( !StringTools.isEmpty( auditTableData.getCatalog() ) ) { - classMapping.addAttribute( "catalog", auditTableData.getCatalog() ); + if ( !StringTools.isEmpty( auditTableData.getCatalog() ) ) { + classMapping.addAttribute( "catalog", auditTableData.getCatalog() ); + } } if ( isAbstract != null ) { @@ -282,13 +290,18 @@ public final class MetadataTools { return joinMapping; } - public static void addColumns(Element anyMapping, Iterator selectables) { - while ( selectables.hasNext() ) { - final Selectable selectable = (Selectable) selectables.next(); - if ( selectable.isFormula() ) { + public static void addColumns(Element anyMapping, List columns) { + for ( Column column : columns ) { + addColumn( anyMapping, column ); + } + } + + public static void addValuesAsColumns(Element anyMapping, List values) { + for ( Value value : values ) { + if ( Value.ValueType.DERIVED_VALUE.equals( value.getValueType() ) ) { throw new FormulaNotSupportedException(); } - addColumn( anyMapping, (Column) selectable ); + addColumn( anyMapping, (Column) value ); } } @@ -303,14 +316,14 @@ public final class MetadataTools { public static void addColumn(Element anyMapping, Column column) { addColumn( anyMapping, - column.getName(), - column.getLength(), - column.getScale(), - column.getPrecision(), + column.getColumnName().getText(), + column.getSize().getLength(), + column.getSize().getScale(), + column.getSize().getPrecision(), column.getSqlType(), - column.getCustomRead(), - column.getCustomWrite(), - column.isQuoted() + column.getReadFragment(), + column.getWriteFragment(), + column.getColumnName().isQuoted() ); } @@ -350,9 +363,11 @@ public final class MetadataTools { if ( changeToKey ) { property.setName( "key-" + property.getName() ); + // "insert" and "update" attributes are not allowed on key-many-to-one or key-property elements. + property.remove( property.attribute( "insert" ) ); + property.remove( property.attribute( "update" ) ); } - - if ( "property".equals( property.getName() ) ) { + else if ( "property".equals( property.getName() ) ) { final Attribute insert = property.attribute( "insert" ); insert.setText( Boolean.toString( insertable ) ); } @@ -366,25 +381,28 @@ public final class MetadataTools { * @param element Parent element. * @param formula Formula descriptor. */ - public static void addFormula(Element element, Formula formula) { - element.addElement( "formula" ).setText( formula.getText() ); + public static void addFormula(Element element, DerivedValue formula) { + element.addElement( "formula" ).setText( formula.getExpression() ); } /** * Adds all column or formula elements. * * @param element Parent element. - * @param columnIterator Iterator pointing at {@link org.hibernate.mapping.Column} and/or - * {@link org.hibernate.mapping.Formula} objects. + * @param values List of {@link Column} and/or {@link DerivedValue} objects. */ - public static void addColumnsOrFormulas(Element element, Iterator columnIterator) { - while ( columnIterator.hasNext() ) { - final Object o = columnIterator.next(); - if ( o instanceof Column ) { - addColumn( element, (Column) o ); + public static void addColumnsOrFormulas(Element element, List values) { + for ( Value value : values ) { + if ( value.getValueType() == Value.ValueType.COLUMN ) { + addColumn( element, (Column) value ); } - else if ( o instanceof Formula ) { - addFormula( element, (Formula) o ); + else if ( value.getValueType() == Value.ValueType.DERIVED_VALUE ) { + addFormula( element, (DerivedValue) value ); + } + else { + throw new AssertionFailure( + String.format( "unknown type of value: %s", value.getValueType() ) + ); } } } @@ -395,18 +413,18 @@ public final class MetadataTools { public static abstract class ColumnNameIterator implements Iterator { } - public static ColumnNameIterator getColumnNameIterator(final Iterator selectableIterator) { + public static ColumnNameIterator getColumnNameIterator(final Iterator selectableIterator) { return new ColumnNameIterator() { public boolean hasNext() { return selectableIterator.hasNext(); } public String next() { - final Selectable next = selectableIterator.next(); - if ( next.isFormula() ) { + final Value next = selectableIterator.next(); + if ( next.getValueType() == Value.ValueType.DERIVED_VALUE ) { throw new FormulaNotSupportedException(); } - return ((Column) next).getName(); + return ((Column) next).getColumnName().getText(); } public void remove() { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ToOneRelationMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ToOneRelationMetadataGenerator.java index 9411436a4c..7bcf44734f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ToOneRelationMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ToOneRelationMetadataGenerator.java @@ -37,6 +37,9 @@ import org.hibernate.envers.internal.tools.MappingTools; import org.hibernate.mapping.OneToOne; import org.hibernate.mapping.ToOne; import org.hibernate.mapping.Value; +import org.hibernate.metamodel.internal.source.annotations.attribute.SingularAssociationAttribute; +import org.hibernate.metamodel.spi.binding.OneToOneAttributeBinding; +import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding; import org.dom4j.Element; @@ -57,11 +60,10 @@ public final class ToOneRelationMetadataGenerator { void addToOne( Element parent, PropertyAuditingData propertyAuditingData, - Value value, + SingularAssociationAttributeBinding attributeBinding, CompositeMapperBuilder mapper, - String entityName, - boolean insertable) { - final String referencedEntityName = ((ToOne) value).getReferencedEntityName(); + String entityName) { + final String referencedEntityName = attributeBinding.getReferencedEntityName(); final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData( entityName, @@ -76,9 +78,10 @@ public final class ToOneRelationMetadataGenerator { final IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties( lastPropertyPrefix ); // Storing information about this relation + boolean insertable = attributeBinding.isIncludedInInsert(); mainGenerator.getEntitiesConfigurations().get( entityName ).addToOneRelation( propertyAuditingData.getName(), referencedEntityName, relMapper, - insertable, MappingTools.ignoreNotFound( value ) + insertable, MappingTools.ignoreNotFound( attributeBinding ) ); // If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship, @@ -104,7 +107,7 @@ public final class ToOneRelationMetadataGenerator { MetadataTools.prefixNamesInPropertyElement( properties, lastPropertyPrefix, - MetadataTools.getColumnNameIterator( value.getColumnIterator() ), + MetadataTools.getColumnNameIterator( attributeBinding.getValues().iterator() ), false, insertable ); @@ -127,11 +130,11 @@ public final class ToOneRelationMetadataGenerator { @SuppressWarnings({"unchecked"}) void addOneToOneNotOwning( PropertyAuditingData propertyAuditingData, - Value value, + OneToOneAttributeBinding attributeBinding, CompositeMapperBuilder mapper, String entityName) { - final OneToOne propertyValue = (OneToOne) value; - final String owningReferencePropertyName = propertyValue.getReferencedPropertyName(); + final String owningReferencePropertyName = + attributeBinding.getReferencedAttributeBinding().getAttribute().getName(); final EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get( entityName ); if ( configuration == null ) { @@ -145,7 +148,7 @@ public final class ToOneRelationMetadataGenerator { } final String lastPropertyPrefix = MappingTools.createToOneRelationPrefix( owningReferencePropertyName ); - final String referencedEntityName = propertyValue.getReferencedEntityName(); + final String referencedEntityName = attributeBinding.getReferencedEntityName(); // Generating the id mapper for the relation final IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties( lastPropertyPrefix ); @@ -153,7 +156,7 @@ public final class ToOneRelationMetadataGenerator { // Storing information about this relation mainGenerator.getEntitiesConfigurations().get( entityName ).addToOneNotOwningRelation( propertyAuditingData.getName(), owningReferencePropertyName, referencedEntityName, - ownedIdMapper, MappingTools.ignoreNotFound( value ) + ownedIdMapper, MappingTools.ignoreNotFound( attributeBinding ) ); // Adding mapper for the id @@ -167,11 +170,10 @@ public final class ToOneRelationMetadataGenerator { @SuppressWarnings({"unchecked"}) void addOneToOnePrimaryKeyJoinColumn( PropertyAuditingData propertyAuditingData, - Value value, + OneToOneAttributeBinding attributeBinding, CompositeMapperBuilder mapper, - String entityName, - boolean insertable) { - final String referencedEntityName = ((ToOne) value).getReferencedEntityName(); + String entityName) { + final String referencedEntityName = attributeBinding.getReferencedEntityName(); final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData( entityName, @@ -187,8 +189,8 @@ public final class ToOneRelationMetadataGenerator { // Storing information about this relation mainGenerator.getEntitiesConfigurations().get( entityName ).addToOneRelation( - propertyAuditingData.getName(), referencedEntityName, relMapper, insertable, - MappingTools.ignoreNotFound( value ) + propertyAuditingData.getName(), referencedEntityName, relMapper, attributeBinding.isIncludedInInsert(), + MappingTools.ignoreNotFound( attributeBinding ) ); // Adding mapper for the id diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AnnotationsMetadataReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AnnotationsMetadataReader.java index 88f21f9f44..402171a768 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AnnotationsMetadataReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AnnotationsMetadataReader.java @@ -24,19 +24,18 @@ package org.hibernate.envers.configuration.internal.metadata.reader; import java.lang.annotation.Annotation; -import java.util.Iterator; -import org.hibernate.MappingException; -import org.hibernate.annotations.common.reflection.ReflectionManager; -import org.hibernate.annotations.common.reflection.XClass; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; + import org.hibernate.envers.AuditTable; -import org.hibernate.envers.Audited; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.SecondaryAuditTable; -import org.hibernate.envers.SecondaryAuditTables; -import org.hibernate.envers.configuration.internal.GlobalConfiguration; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; +import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.event.spi.EnversDotNames; +import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EntityBinding; /** * A helper class to read versioning meta-data from annotations on a persistent class. @@ -45,101 +44,8 @@ import org.hibernate.mapping.Property; * @author Sebastian Komander */ public final class AnnotationsMetadataReader { - private final GlobalConfiguration globalCfg; - private final ReflectionManager reflectionManager; - private final PersistentClass pc; - /** - * This object is filled with information read from annotations and returned by the getVersioningData - * method. - */ - private final ClassAuditingData auditData; - - public AnnotationsMetadataReader( - GlobalConfiguration globalCfg, ReflectionManager reflectionManager, - PersistentClass pc) { - this.globalCfg = globalCfg; - this.reflectionManager = reflectionManager; - this.pc = pc; - - auditData = new ClassAuditingData(); - } - - private ModificationStore getDefaultAudited(XClass clazz) { - final Audited defaultAudited = clazz.getAnnotation( Audited.class ); - - if ( defaultAudited != null ) { - return defaultAudited.modStore(); - } - else { - return null; - } - } - - private void addAuditTable(XClass clazz) { - final AuditTable auditTable = clazz.getAnnotation( AuditTable.class ); - if ( auditTable != null ) { - auditData.setAuditTable( auditTable ); - } - else { - auditData.setAuditTable( getDefaultAuditTable() ); - } - } - - private void addAuditSecondaryTables(XClass clazz) { - // Getting information on secondary tables - final SecondaryAuditTable secondaryVersionsTable1 = clazz.getAnnotation( SecondaryAuditTable.class ); - if ( secondaryVersionsTable1 != null ) { - auditData.getSecondaryTableDictionary().put( - secondaryVersionsTable1.secondaryTableName(), - secondaryVersionsTable1.secondaryAuditTableName() - ); - } - - final SecondaryAuditTables secondaryAuditTables = clazz.getAnnotation( SecondaryAuditTables.class ); - if ( secondaryAuditTables != null ) { - for ( SecondaryAuditTable secondaryAuditTable2 : secondaryAuditTables.value() ) { - auditData.getSecondaryTableDictionary().put( - secondaryAuditTable2.secondaryTableName(), - secondaryAuditTable2.secondaryAuditTableName() - ); - } - } - } - - public ClassAuditingData getAuditData() { - if ( pc.getClassName() == null ) { - return auditData; - } - - try { - final XClass xclass = reflectionManager.classForName( pc.getClassName(), this.getClass() ); - - final ModificationStore defaultStore = getDefaultAudited( xclass ); - if ( defaultStore != null ) { - auditData.setDefaultAudited( true ); - } - - new AuditedPropertiesReader( - defaultStore, - new PersistentClassPropertiesSource( xclass ), - auditData, - globalCfg, - reflectionManager, - "" - ).read(); - - addAuditTable( xclass ); - addAuditSecondaryTables( xclass ); - } - catch (ClassNotFoundException e) { - throw new MappingException( e ); - } - - return auditData; - } - - private AuditTable defaultAuditTable = new AuditTable() { + private static final AuditTable DEFAULT_AUDIT_TABLE = new AuditTable() { public String value() { return ""; } @@ -157,28 +63,136 @@ public final class AnnotationsMetadataReader { } }; + private final AuditConfiguration.AuditConfigurationContext context; + + public AnnotationsMetadataReader(AuditConfiguration.AuditConfigurationContext context) { + this.context = context; + } + + private ModificationStore getDefaultAudited(ClassInfo classInfo) { + final AnnotationInstance audited = JandexHelper.getSingleAnnotation( + classInfo.annotations(), + EnversDotNames.AUDITED, + classInfo + ); + if ( audited != null ) { + return JandexHelper.getValue( audited, "modStore", ModificationStore.class, context.getClassLoaderService() ); + } + return null; + } + + private void addAuditTable(ClassInfo classInfo, ClassAuditingData auditData) { + final AnnotationInstance auditTable = JandexHelper.getSingleAnnotation( classInfo, EnversDotNames.AUDIT_TABLE ); + if ( auditTable != null ) { + auditData.setAuditTable( + context.getAnnotationProxy( + auditTable, + AuditTable.class + ) + ); + } + else { + auditData.setAuditTable( getDefaultAuditTable() ); + } + } + + private void addAuditSecondaryTables(ClassInfo classInfo, ClassAuditingData auditData) { + // Getting information on secondary tables + final AnnotationInstance secondaryAuditTable1 = JandexHelper.getSingleAnnotation( + classInfo, EnversDotNames.SECONDARY_AUDIT_TABLE + ); + if ( secondaryAuditTable1 != null ) { + auditData.getSecondaryTableDictionary().put( + JandexHelper.getValue( + secondaryAuditTable1, "secondaryTableName", String.class, context.getClassLoaderService() + ), + JandexHelper.getValue( + secondaryAuditTable1, "secondaryAuditTableName", String.class, context.getClassLoaderService() + ) + ); + } + + final AnnotationInstance secondaryAuditTables = JandexHelper.getSingleAnnotation( classInfo, EnversDotNames.SECONDARY_AUDIT_TABLES ); + if ( secondaryAuditTables != null ) { + final AnnotationInstance[] secondaryAuditTableValues = + JandexHelper.getValue( secondaryAuditTables, "value", AnnotationInstance[].class, context.getClassLoaderService() ); + for ( AnnotationInstance secondaryAuditTable : secondaryAuditTableValues ) { + auditData.getSecondaryTableDictionary().put( + JandexHelper.getValue( + secondaryAuditTable, "secondaryTableName", String.class, context.getClassLoaderService() + ), + JandexHelper.getValue( + secondaryAuditTable, "secondaryAuditTableName", String.class, context.getClassLoaderService() + ) + ); + } + } + } + + public ClassAuditingData getAuditData(EntityBinding entityBinding) { + /** + * This object is filled with information read from annotations and returned by the getVersioningData + * method. + */ + final ClassAuditingData auditData = new ClassAuditingData(); + + if ( entityBinding.getEntity().getDescriptor() == null ) { + // TODO: What is the case here? Test by throwing exception. + return auditData; + } + + final PersistentClassPropertiesSource persistentClassPropertiesSource = new PersistentClassPropertiesSource( + entityBinding, + context.getClassInfo( + entityBinding.getEntity().getDescriptor().getName().toString() + ) + ); + + ModificationStore defaultStore = getDefaultAudited( persistentClassPropertiesSource.getClassInfo() ); + auditData.setDefaultAudited( defaultStore != null ); + + new AuditedPropertiesReader( + context, + auditData, + persistentClassPropertiesSource, + "" + ).read(); + + addAuditTable( persistentClassPropertiesSource.getClassInfo(), auditData ); + addAuditSecondaryTables( persistentClassPropertiesSource.getClassInfo(), auditData ); + + return auditData; + } + private AuditTable getDefaultAuditTable() { - return defaultAuditTable; + return DEFAULT_AUDIT_TABLE; } private class PersistentClassPropertiesSource implements PersistentPropertiesSource { - private final XClass xclass; + private final EntityBinding entityBinding; + private final ClassInfo classInfo; - private PersistentClassPropertiesSource(XClass xclass) { - this.xclass = xclass; + private PersistentClassPropertiesSource(EntityBinding entityBinding, ClassInfo classInfo) { + this.entityBinding = entityBinding; + this.classInfo = classInfo; } @SuppressWarnings({"unchecked"}) - public Iterator getPropertyIterator() { - return pc.getPropertyIterator(); + public Iterable getNonIdAttributeBindings() { + return entityBinding.getNonIdAttributeBindings(); } - public Property getProperty(String propertyName) { - return pc.getProperty( propertyName ); + public AttributeBinding getAttributeBinding(String attributeName) { + return entityBinding.locateAttributeBinding( attributeName ); } - public XClass getXClass() { - return xclass; + @Override + public AttributeBindingContainer getAttributeBindingContainer() { + return entityBinding; + } + + public ClassInfo getClassInfo() { + return classInfo; } } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java index cfc9218e7c..32432e25e5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java @@ -25,37 +25,42 @@ package org.hibernate.envers.configuration.internal.metadata.reader; import java.lang.annotation.Annotation; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import javax.persistence.JoinColumn; -import javax.persistence.MapKey; -import javax.persistence.OneToMany; -import javax.persistence.Version; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; import org.hibernate.MappingException; -import org.hibernate.annotations.common.reflection.ReflectionManager; -import org.hibernate.annotations.common.reflection.XClass; -import org.hibernate.annotations.common.reflection.XProperty; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.AccessType; +import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.envers.AuditJoinTable; -import org.hibernate.envers.AuditMappedBy; import org.hibernate.envers.AuditOverride; import org.hibernate.envers.AuditOverrides; import org.hibernate.envers.Audited; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.NotAudited; import org.hibernate.envers.RelationTargetAuditMode; -import org.hibernate.envers.configuration.internal.GlobalConfiguration; import org.hibernate.envers.configuration.internal.metadata.MetadataTools; +import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.event.spi.EnversDotNames; import org.hibernate.envers.internal.tools.MappingTools; -import org.hibernate.envers.internal.tools.ReflectionTools; import org.hibernate.envers.internal.tools.StringTools; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.Value; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; +import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.domain.Attribute; +import org.hibernate.metamodel.spi.domain.Hierarchical; import static org.hibernate.envers.internal.tools.Tools.newHashMap; import static org.hibernate.envers.internal.tools.Tools.newHashSet; @@ -72,11 +77,11 @@ import static org.hibernate.envers.internal.tools.Tools.newHashSet; * @author Lukasz Zuchowski (author at zuchos dot com) */ public class AuditedPropertiesReader { - protected final ModificationStore defaultStore; - private final PersistentPropertiesSource persistentPropertiesSource; + private final AuditConfiguration.AuditConfigurationContext context; + // TODO: is AttributeBindingContainer actually needed or is Hierarchical sufficient? + private final PersistentPropertiesSource processedPersistentPropertiesSource; + private final ClassInfo processedClassInfo; private final AuditedPropertiesHolder auditedPropertiesHolder; - private final GlobalConfiguration globalCfg; - private final ReflectionManager reflectionManager; private final String propertyNamePrefix; private final Set propertyAccessedPersistentProperties; @@ -84,24 +89,23 @@ public class AuditedPropertiesReader { // Mapping class field to corresponding element. private final Map propertiesGroupMapping; - private final Set overriddenAuditedProperties; - private final Set overriddenNotAuditedProperties; + private final Set overriddenAuditedProperties; + private final Set overriddenNotAuditedProperties; - private final Set overriddenAuditedClasses; - private final Set overriddenNotAuditedClasses; + private final Set overriddenAuditedClasses; + private final Set overriddenNotAuditedClasses; public AuditedPropertiesReader( - ModificationStore defaultStore, - PersistentPropertiesSource persistentPropertiesSource, + AuditConfiguration.AuditConfigurationContext context, AuditedPropertiesHolder auditedPropertiesHolder, - GlobalConfiguration globalCfg, - ReflectionManager reflectionManager, + PersistentPropertiesSource processedPersistentPropertiesSource, String propertyNamePrefix) { - this.defaultStore = defaultStore; - this.persistentPropertiesSource = persistentPropertiesSource; + this.context = context; this.auditedPropertiesHolder = auditedPropertiesHolder; - this.globalCfg = globalCfg; - this.reflectionManager = reflectionManager; + this.processedPersistentPropertiesSource = processedPersistentPropertiesSource; + this.processedClassInfo = context.getClassInfo( + processedPersistentPropertiesSource.getAttributeBindingContainer().getAttributeContainer() + ); this.propertyNamePrefix = propertyNamePrefix; propertyAccessedPersistentProperties = newHashSet(); @@ -119,103 +123,122 @@ public class AuditedPropertiesReader { // First reading the access types for the persistent properties. readPersistentPropertiesAccess(); - if ( persistentPropertiesSource instanceof DynamicComponentSource ) { - addPropertiesFromDynamicComponent( (DynamicComponentSource) persistentPropertiesSource ); + if ( processedPersistentPropertiesSource instanceof DynamicComponentSource ) { + addPropertiesFromDynamicComponent( (DynamicComponentSource) processedPersistentPropertiesSource ); } else { // Retrieve classes and properties that are explicitly marked for auditing process by any superclass // of currently mapped entity or itself. - final XClass clazz = persistentPropertiesSource.getXClass(); - readAuditOverrides( clazz ); + readAuditOverrides( + processedClassInfo, + (Hierarchical) processedPersistentPropertiesSource.getAttributeBindingContainer().getAttributeContainer() + ); // Adding all properties from the given class. - addPropertiesFromClass( clazz ); + addPropertiesFromClass( processedPersistentPropertiesSource.getAttributeBindingContainer() ); } } + protected AuditConfiguration.AuditConfigurationContext getContext() { + return context; + } + /** * Recursively constructs sets of audited and not audited properties and classes which behavior has been overridden * using {@link AuditOverride} annotation. * - * @param clazz Class that is being processed. Currently mapped entity shall be passed during first invocation. + * @param classInfo Class that is being processed. Currently mapped entity shall be passed during first invocation. */ - private void readAuditOverrides(XClass clazz) { - /* TODO: Code to remove with @Audited.auditParents - start. */ - final Audited allClassAudited = clazz.getAnnotation( Audited.class ); - if ( allClassAudited != null && allClassAudited.auditParents().length > 0 ) { - for ( Class c : allClassAudited.auditParents() ) { - final XClass parentClass = reflectionManager.toXClass( c ); - checkSuperclass( clazz, parentClass ); - if ( !overriddenNotAuditedClasses.contains( parentClass ) ) { - // If the class has not been marked as not audited by the subclass. - overriddenAuditedClasses.add( parentClass ); - } - } - } - /* TODO: Code to remove with @Audited.auditParents - finish. */ - final List auditOverrides = computeAuditOverrides( clazz ); - for ( AuditOverride auditOverride : auditOverrides ) { - if ( auditOverride.forClass() != void.class ) { - final XClass overrideClass = reflectionManager.toXClass( auditOverride.forClass() ); - checkSuperclass( clazz, overrideClass ); - final String propertyName = auditOverride.name(); + private void readAuditOverrides(ClassInfo classInfo, Hierarchical hierarchical) { + final ClassLoaderService classLoaderService = context.getClassLoaderService() ; + // TODO: Remove auditParents. + final List auditOverrides = computeAuditOverrides( classInfo ); + for (AnnotationInstance auditOverride : auditOverrides) { + final String overrideClassName = JandexHelper.getValue( + auditOverride, "forClass", String.class, classLoaderService + ); + final boolean isAudited = JandexHelper.getValue( + auditOverride, "isAudited", boolean.class, classLoaderService + ); + if ( !void.class.getName().equals( overrideClassName )) { + final ClassInfo overrideClassInfo = context.getClassInfo( overrideClassName ); + checkSuperclass( classInfo, overrideClassInfo ); + final Hierarchical overrideHierarchical = getSuperHierarchical( hierarchical, overrideClassName ); + final String propertyName = JandexHelper.getValue( auditOverride, "name", String.class, classLoaderService ); if ( !StringTools.isEmpty( propertyName ) ) { // Override @Audited annotation on property level. - final XProperty property = getProperty( overrideClass, propertyName ); - if ( auditOverride.isAudited() ) { - if ( !overriddenNotAuditedProperties.contains( property ) ) { + final Attribute overrideAttribute = getAttribute( overrideHierarchical, propertyName ); + if ( isAudited ) { + if ( !overriddenNotAuditedProperties.contains( overrideAttribute ) ) { // If the property has not been marked as not audited by the subclass. - overriddenAuditedProperties.add( property ); + overriddenAuditedProperties.add( overrideAttribute ); } } else { - if ( !overriddenAuditedProperties.contains( property ) ) { + if ( !overriddenAuditedProperties.contains( overrideAttribute ) ) { // If the property has not been marked as audited by the subclass. - overriddenNotAuditedProperties.add( property ); + overriddenNotAuditedProperties.add( overrideAttribute ); } } - } - else { + } else { // Override @Audited annotation on class level. - if ( auditOverride.isAudited() ) { - if ( !overriddenNotAuditedClasses.contains( overrideClass ) ) { + if ( isAudited ) { + if (!overriddenNotAuditedClasses.contains( overrideHierarchical )) { // If the class has not been marked as not audited by the subclass. - overriddenAuditedClasses.add( overrideClass ); + overriddenAuditedClasses.add( overrideHierarchical ); } - } - else { - if ( !overriddenAuditedClasses.contains( overrideClass ) ) { + } else { + if (!overriddenAuditedClasses.contains( overrideHierarchical )) { // If the class has not been marked as audited by the subclass. - overriddenNotAuditedClasses.add( overrideClass ); + overriddenNotAuditedClasses.add( overrideHierarchical ); } } } } } - final XClass superclass = clazz.getSuperclass(); - if ( !clazz.isInterface() && !Object.class.getName().equals( superclass.getName() ) ) { - readAuditOverrides( superclass ); + // TODO: how to distinguish interface: !clazz.isInterface() && + // if (!clazz.isInterface() && !Object.class.getName().equals(superclass.getName())) { + if ( !Object.class.getName().equals( classInfo.superName().toString() ) ) { + readAuditOverrides( context.getClassInfo( classInfo.superName() ), hierarchical.getSuperType() ); } } + private Hierarchical getSuperHierarchical(Hierarchical hierarchical, String superclassName) { + Hierarchical superHierarchical = hierarchical.getSuperType(); + while ( superHierarchical != null ) { + if ( superclassName.equals( superHierarchical.getDescriptor().getName().toString() ) ) { + return superHierarchical; + } + superHierarchical = superHierarchical.getSuperType(); + } + throw new IllegalStateException( + String.format( "Hierarchical [%s] does not have a superclass with name [%s] ", + hierarchical.getRoleBaseName(), + superclassName + ) + ); + } + /** - * @param clazz Source class. + * @param classInfo Source {@link ClassInfo}. * * @return List of @AuditOverride annotations applied at class level. */ - private List computeAuditOverrides(XClass clazz) { - final AuditOverrides auditOverrides = clazz.getAnnotation( AuditOverrides.class ); - final AuditOverride auditOverride = clazz.getAnnotation( AuditOverride.class ); + private List computeAuditOverrides(ClassInfo classInfo) { + AnnotationInstance auditOverrides = JandexHelper.getSingleAnnotation( classInfo, EnversDotNames.AUDIT_OVERRIDES ); + AnnotationInstance auditOverride = JandexHelper.getSingleAnnotation( classInfo, EnversDotNames.AUDIT_OVERRIDE ); if ( auditOverrides == null && auditOverride != null ) { return Arrays.asList( auditOverride ); } else if ( auditOverrides != null && auditOverride == null ) { - return Arrays.asList( auditOverrides.value() ); + return Arrays.asList( + JandexHelper.getValue( auditOverrides, "value", AnnotationInstance[].class, context.getClassLoaderService() ) + ); } else if ( auditOverrides != null && auditOverride != null ) { throw new MappingException( "@AuditOverrides annotation should encapsulate all @AuditOverride declarations. " + - "Please revise Envers annotations applied to class " + clazz.getName() + "." + "Please revise Envers annotations applied to class " + classInfo.name() + "." ); } return Collections.emptyList(); @@ -223,15 +246,14 @@ public class AuditedPropertiesReader { /** * Checks whether one class is assignable from another. If not {@link MappingException} is thrown. - * * @param child Subclass. * @param parent Superclass. */ - private void checkSuperclass(XClass child, XClass parent) { - if ( !parent.isAssignableFrom( child ) ) { + private void checkSuperclass(ClassInfo child, ClassInfo parent) { + if ( !context.getJandexIndex().getAllKnownSubclasses( parent.name() ).contains( child ) ) { throw new MappingException( - "Class " + parent.getName() + " is not assignable from " + child.getName() + ". " + - "Please revise Envers annotations applied to " + child.getName() + " type." + "Class " + parent.name() + " is not assignable from " + child.name() + ". " + + "Please revise Envers annotations applied to " + child.name() + " type." ); } } @@ -239,85 +261,88 @@ public class AuditedPropertiesReader { /** * Checks whether class contains property with a given name. If not {@link MappingException} is thrown. * - * @param clazz Class. + * @param hierarchical The Hierarchical domain object.. * @param propertyName Property name. - * - * @return Property object. + * @return the attribute binding. */ - private XProperty getProperty(XClass clazz, String propertyName) { - final XProperty property = ReflectionTools.getProperty( clazz, propertyName ); - if ( property == null ) { + private Attribute getAttribute(Hierarchical hierarchical, String propertyName) { + final Attribute attribute = hierarchical.locateAttribute( propertyName ); + if ( attribute == null ) { throw new MappingException( - "Property '" + propertyName + "' not found in class " + clazz.getName() + ". " + - "Please revise Envers annotations applied to class " + persistentPropertiesSource.getXClass() + "." + "Property '" + propertyName + "' not found in class " + hierarchical.getDescriptor().getName().toString() + ". " + + "Please revise Envers annotations applied to class " + processedClassInfo.name() + "." ); } - return property; + return attribute; } private void readPersistentPropertiesAccess() { - final Iterator propertyIter = persistentPropertiesSource.getPropertyIterator(); - while ( propertyIter.hasNext() ) { - final Property property = propertyIter.next(); - addPersistentProperty( property ); - if ( "embedded".equals( property.getPropertyAccessorName() ) && property.getName() - .equals( property.getNodeName() ) ) { - // If property name equals node name and embedded accessor type is used, processing component - // has been defined with tag. See HHH-6636 JIRA issue. - createPropertiesGroupMapping( property ); - } + for ( AttributeBinding attributeBinding : processedPersistentPropertiesSource.getNonIdAttributeBindings() ) { + addPersistentAttribute( attributeBinding ); +// TODO: if ("embedded".equals(property.getPropertyAccessorName()) && property.getName().equals(property.getNodeName())) { +// // If property name equals node name and embedded accessor type is used, processing component +// // has been defined with tag. See HHH-6636 JIRA issue. +// createPropertiesGroupMapping(property); +// } } } - private void addPersistentProperty(Property property) { - if ( "field".equals( property.getPropertyAccessorName() ) ) { - fieldAccessedPersistentProperties.add( property.getName() ); + private void addPersistentAttribute(AttributeBinding attributeBinding) { + if ( "field".equals( attributeBinding.getPropertyAccessorName() ) ) { + fieldAccessedPersistentProperties.add( attributeBinding.getAttribute().getName() ); } else { - propertyAccessedPersistentProperties.add( property.getName() ); + propertyAccessedPersistentProperties.add( attributeBinding.getAttribute().getName() ); } } - @SuppressWarnings("unchecked") - private void createPropertiesGroupMapping(Property property) { - final Component component = (Component) property.getValue(); - final Iterator componentProperties = component.getPropertyIterator(); - while ( componentProperties.hasNext() ) { - final Property componentProperty = componentProperties.next(); - propertiesGroupMapping.put( componentProperty.getName(), component.getNodeName() ); - } - } + // TODO: add support for + //@SuppressWarnings("unchecked") + //private void createPropertiesGroupMapping(Property property) { + // final Component component = (Component) property.getValue(); + // final Iterator componentProperties = component.getPropertyIterator(); + // while ( componentProperties.hasNext() ) { + // final Property componentProperty = componentProperties.next(); + // propertiesGroupMapping.put( componentProperty.getName(), component.getNodeName() ); + // } + //} /** - * @param clazz Class which properties are currently being added. - * + * @param attributeBindingContainer Class which properties are currently being added. * @return {@link Audited} annotation of specified class. If processed type hasn't been explicitly marked, method * checks whether given class exists in {@link AuditedPropertiesReader#overriddenAuditedClasses} collection. * In case of success, {@link Audited} configuration of currently mapped entity is returned, otherwise * {@code null}. If processed type exists in {@link AuditedPropertiesReader#overriddenNotAuditedClasses} * collection, the result is also {@code null}. */ - private Audited computeAuditConfiguration(XClass clazz) { - Audited allClassAudited = clazz.getAnnotation( Audited.class ); + private Audited computeAuditConfiguration(AttributeBindingContainer attributeBindingContainer) { + final ClassInfo classInfo = context.getClassInfo( attributeBindingContainer.getAttributeContainer() ); + // TODO: Check this method if I have migrated everything correctly. + final AnnotationInstance allClassAudited = JandexHelper.getSingleAnnotation( + classInfo.annotations(), + EnversDotNames.AUDITED, + classInfo + ); // If processed class is not explicitly marked with @Audited annotation, check whether auditing is // forced by any of its child entities configuration (@AuditedOverride.forClass). - if ( allClassAudited == null && overriddenAuditedClasses.contains( clazz ) ) { + final Hierarchical hierarchical = (Hierarchical) attributeBindingContainer.getAttributeContainer(); + if ( allClassAudited == null && overriddenAuditedClasses.contains( hierarchical ) ) { // Declared audited parent copies @Audited.modStore and @Audited.targetAuditMode configuration from // currently mapped entity. - allClassAudited = persistentPropertiesSource.getXClass().getAnnotation( Audited.class ); - if ( allClassAudited == null ) { + if ( JandexHelper.getSingleAnnotation( processedClassInfo, EnversDotNames.AUDITED ) == null ) { // If parent class declares @Audited on the field/property level. - allClassAudited = DEFAULT_AUDITED; + return DEFAULT_AUDITED; } } - else if ( allClassAudited != null && overriddenNotAuditedClasses.contains( clazz ) ) { + else if ( allClassAudited != null && overriddenNotAuditedClasses.contains( hierarchical ) ) { return null; } - return allClassAudited; + + return allClassAudited == null ? null : context.getAnnotationProxy( allClassAudited, Audited.class ); } private void addPropertiesFromDynamicComponent(DynamicComponentSource dynamicComponentSource) { - Audited audited = computeAuditConfiguration( dynamicComponentSource.getXClass() ); + Audited audited = computeAuditConfiguration( dynamicComponentSource.getAttributeBindingContainer() ); if ( !fieldAccessedPersistentProperties.isEmpty() ) { throw new MappingException( "Audited dynamic component cannot have properties with access=\"field\" for properties: " + fieldAccessedPersistentProperties + ". \n Change properties access=\"property\", to make it work)" @@ -326,18 +351,17 @@ public class AuditedPropertiesReader { for ( String property : propertyAccessedPersistentProperties ) { String accessType = AccessType.PROPERTY.getType(); if ( !auditedPropertiesHolder.contains( property ) ) { - final Value propertyValue = persistentPropertiesSource.getProperty( property ).getValue(); - if ( propertyValue instanceof Component ) { + final AttributeBinding attributeBinding = processedPersistentPropertiesSource.getAttributeBinding( property ); + if ( CompositeAttributeBinding.class.isInstance( attributeBinding ) ) { this.addFromComponentProperty( - new DynamicProperty( dynamicComponentSource, property ), + (CompositeAttributeBinding) attributeBinding, accessType, - (Component) propertyValue, audited ); } else { this.addFromNotComponentProperty( - new DynamicProperty( dynamicComponentSource, property ), + attributeBinding, accessType, audited ); @@ -346,218 +370,218 @@ public class AuditedPropertiesReader { } } + private Collection getAttributeBindings( + AttributeBindingContainer attributeBindingContainer, + String propertyAccessorName) { + // TODO: why a LinkedList? + final List attributes = new LinkedList(); + for ( AttributeBinding attributeBinding : attributeBindingContainer.attributeBindings() ) { + if ( propertyAccessorName.equals( attributeBinding.getPropertyAccessorName() ) ) { + attributes.add( attributeBinding ); + } + } + return attributes; + } + /** * Recursively adds all audited properties of entity class and its superclasses. * - * @param clazz Currently processed class. + * @param attributeBindingContainer Currently processed attribute binding container.. */ - private void addPropertiesFromClass(XClass clazz) { - final Audited allClassAudited = computeAuditConfiguration( clazz ); + private void addPropertiesFromClass(AttributeBindingContainer attributeBindingContainer) { + final ClassInfo classInfo = context.getClassInfo( attributeBindingContainer.getAttributeContainer() ); + + final Audited allClassAudited = computeAuditConfiguration( attributeBindingContainer ); //look in the class - addFromProperties( - clazz.getDeclaredProperties( "field" ), - "field", - fieldAccessedPersistentProperties, - allClassAudited - ); - addFromProperties( - clazz.getDeclaredProperties( "property" ), - "property", - propertyAccessedPersistentProperties, - allClassAudited - ); + addFromProperties( getAttributeBindings( attributeBindingContainer, "field" ), "field", fieldAccessedPersistentProperties, allClassAudited ); + addFromProperties( getAttributeBindings( attributeBindingContainer, "property" ), "property", propertyAccessedPersistentProperties, allClassAudited ); if ( allClassAudited != null || !auditedPropertiesHolder.isEmpty() ) { - final XClass superclazz = clazz.getSuperclass(); - if ( !clazz.isInterface() && !"java.lang.Object".equals( superclazz.getName() ) ) { - addPropertiesFromClass( superclazz ); + if ( EntityBinding.class.isInstance( attributeBindingContainer ) ) { + final EntityBinding entityBinding = (EntityBinding) attributeBindingContainer; + if ( entityBinding.getSuperEntityBinding() != null ) { + addPropertiesFromClass( entityBinding.getSuperEntityBinding() ); + } } } } private void addFromProperties( - Iterable properties, + Iterable attributes, String accessType, Set persistentProperties, Audited allClassAudited) { - for ( XProperty property : properties ) { - // If this is not a persistent property, with the same access type as currently checked, - // it's not audited as well. - // If the property was already defined by the subclass, is ignored by superclasses - if ( persistentProperties.contains( property.getName() ) - && !auditedPropertiesHolder.contains( property.getName() ) ) { - final Value propertyValue = persistentPropertiesSource.getProperty( property.getName() ).getValue(); - if ( propertyValue instanceof Component ) { - this.addFromComponentProperty( property, accessType, (Component) propertyValue, allClassAudited ); + for ( AttributeBinding attributeBinding : attributes ) { + // If this is not a persistent property, with the same access type as currently checked, + // it's not audited as well. + // If the property was already defined by the subclass, is ignored by superclasses + final String attributeName = attributeBinding.getAttribute().getName(); + if ( persistentProperties.contains( attributeName ) && !auditedPropertiesHolder.contains( attributeName ) ) { + if ( attributeBinding instanceof CompositeAttributeBinding ) { + this.addFromComponentProperty( + (CompositeAttributeBinding) attributeBinding, accessType, allClassAudited + ); + } + else { + // TODO: is "this." needed? + this.addFromNotComponentProperty( attributeBinding, accessType, allClassAudited ); + } } - else { - this.addFromNotComponentProperty( property, accessType, allClassAudited ); - } - } - else if ( propertiesGroupMapping.containsKey( property.getName() ) ) { - // Retrieve embedded component name based on class field. - final String embeddedName = propertiesGroupMapping.get( property.getName() ); - if ( !auditedPropertiesHolder.contains( embeddedName ) ) { - // Manage properties mapped within tag. - final Value propertyValue = persistentPropertiesSource.getProperty( embeddedName ).getValue(); - this.addFromPropertiesGroup( - embeddedName, - property, - accessType, - (Component) propertyValue, - allClassAudited - ); - } - } +// TODO: else if ( propertiesGroupMapping.containsKey( attributeName ) ) { +// // Retrieve embedded component name based on class field. +// final String embeddedName = propertiesGroupMapping.get(attributeName); +// if (!auditedPropertiesHolder.contains(embeddedName)) { +// // Manage properties mapped within tag. +// Value propertyValue = persistentPropertiesSource.getProperty(embeddedName).getValue(); +// this.addFromPropertiesGroup( embeddedName, property, accessType, (Component) propertyValue, allClassAudited ); +// } +// } } } - private void addFromPropertiesGroup( - String embeddedName, - XProperty property, - String accessType, - Component propertyValue, - Audited allClassAudited) { - final ComponentAuditingData componentData = new ComponentAuditingData(); - final boolean isAudited = fillPropertyData( property, componentData, accessType, allClassAudited ); - if ( isAudited ) { - // EntityPersister.getPropertyNames() returns name of embedded component instead of class field. - componentData.setName( embeddedName ); - // Marking component properties as placed directly in class (not inside another component). - componentData.setBeanName( null ); - - final PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource( - reflectionManager, - propertyValue - ); - final AuditedPropertiesReader audPropReader = new AuditedPropertiesReader( - ModificationStore.FULL, componentPropertiesSource, componentData, globalCfg, reflectionManager, - propertyNamePrefix + MappingTools.createComponentPrefix( embeddedName ) - ); - audPropReader.read(); - - auditedPropertiesHolder.addPropertyAuditingData( embeddedName, componentData ); - } - } +// TODO: private void addFromPropertiesGroup( +// String embeddedName, +// XProperty property, +// String accessType, +// Component propertyValue, +// Audited allClassAudited) { +// final ComponentAuditingData componentData = new ComponentAuditingData(); +// final boolean isAudited = fillPropertyData( property, componentData, accessType, allClassAudited ); +// if ( isAudited ) { +// // EntityPersister.getPropertyNames() returns name of embedded component instead of class field. +// componentData.setName( embeddedName ); +// // Marking component properties as placed directly in class (not inside another component). +// componentData.setBeanName( null ); +// +// final PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource( +// reflectionManager, +// propertyValue +// ); +// final AuditedPropertiesReader audPropReader = new AuditedPropertiesReader( +// ModificationStore.FULL, componentPropertiesSource, componentData, globalCfg, reflectionManager, +// propertyNamePrefix + MappingTools.createComponentPrefix( embeddedName ) +// ); +// audPropReader.read(); +// +// auditedPropertiesHolder.addPropertyAuditingData( embeddedName, componentData ); +// } +// } private void addFromComponentProperty( - XProperty property, + CompositeAttributeBinding attributeBinding, String accessType, - Component propertyValue, Audited allClassAudited) { final ComponentAuditingData componentData = new ComponentAuditingData(); - final boolean isAudited = fillPropertyData( property, componentData, accessType, allClassAudited ); + final boolean isAudited = fillPropertyData( attributeBinding.getAttribute(), componentData, accessType, allClassAudited ); final PersistentPropertiesSource componentPropertiesSource; - if ( propertyValue.isDynamic() ) { - componentPropertiesSource = new DynamicComponentSource( reflectionManager, propertyValue, property ); - } - else { - componentPropertiesSource = new ComponentPropertiesSource( reflectionManager, propertyValue ); - } + // TODO: + //if ( attributeBinding.isDynamic() ) { + // componentPropertiesSource = new DynamicComponentSource( attributeBinding ); + //} + //else { + componentPropertiesSource = new ComponentPropertiesSource( + context.getClassInfo( attributeBinding.getAttributeContainer() ), + attributeBinding + ); + //} final ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader( - ModificationStore.FULL, - componentPropertiesSource, + context, componentData, - globalCfg, - reflectionManager, - propertyNamePrefix + MappingTools.createComponentPrefix( property.getName() ) + componentPropertiesSource, + propertyNamePrefix + MappingTools.createComponentPrefix( attributeBinding.getAttribute().getName() ) ); audPropReader.read(); if ( isAudited ) { // Now we know that the property is audited - auditedPropertiesHolder.addPropertyAuditingData( property.getName(), componentData ); + auditedPropertiesHolder.addPropertyAuditingData( attributeBinding.getAttribute().getName(), componentData ); } } - private void addFromNotComponentProperty(XProperty property, String accessType, Audited allClassAudited) { - final PropertyAuditingData propertyData = new PropertyAuditingData(); - final boolean isAudited = fillPropertyData( property, propertyData, accessType, allClassAudited ); + private void addFromNotComponentProperty(AttributeBinding attributeBinding, String accessType, Audited allClassAudited) { + PropertyAuditingData propertyData = new PropertyAuditingData(); + boolean isAudited = fillPropertyData( attributeBinding.getAttribute(), propertyData, accessType, allClassAudited ); if ( isAudited ) { // Now we know that the property is audited - auditedPropertiesHolder.addPropertyAuditingData( property.getName(), propertyData ); + auditedPropertiesHolder.addPropertyAuditingData( attributeBinding.getAttribute().getName(), propertyData ); } } - /** * Checks if a property is audited and if yes, fills all of its data. - * - * @param property Property to check. + * @param attribute Property to check. * @param propertyData Property data, on which to set this property's modification store. * @param accessType Access type for the property. - * * @return False if this property is not audited. */ private boolean fillPropertyData( - XProperty property, + Attribute attribute, PropertyAuditingData propertyData, String accessType, Audited allClassAudited) { - // check if a property is declared as not audited to exclude it // useful if a class is audited but some properties should be excluded - final NotAudited unVer = property.getAnnotation( NotAudited.class ); - if ( ( unVer != null - && !overriddenAuditedProperties.contains( property ) ) - || overriddenNotAuditedProperties.contains( property ) ) { + Map> attributeAnnotations = context.locateAttributeAnnotations( + attribute + ); + if ( ( attributeAnnotations.containsKey( EnversDotNames.NOT_AUDITED ) && !overriddenAuditedProperties.contains( attribute ) ) + || overriddenNotAuditedProperties.contains( attribute ) ) { return false; } else { // if the optimistic locking field has to be unversioned and the current property // is the optimistic locking field, don't audit it - if ( globalCfg.isDoNotAuditOptimisticLockingField() ) { - final Version jpaVer = property.getAnnotation( Version.class ); - if ( jpaVer != null ) { + if ( context.getGlobalConfiguration().isDoNotAuditOptimisticLockingField() ) { + if ( attributeAnnotations.containsKey( JPADotNames.VERSION ) ) { return false; } } } - - if ( !this.checkAudited( property, propertyData, allClassAudited ) ) { + // TODO: is "this." needed? + if ( !this.checkAudited( attribute, propertyData, allClassAudited ) ) { return false; } - final String propertyName = propertyNamePrefix + property.getName(); + String propertyName = propertyNamePrefix + attribute.getName(); propertyData.setName( propertyName ); propertyData.setModifiedFlagName( MetadataTools.getModifiedFlagPropertyName( propertyName, - globalCfg.getModifiedFlagSuffix() + context.getGlobalConfiguration().getModifiedFlagSuffix() ) ); - propertyData.setBeanName( property.getName() ); + propertyData.setBeanName( attribute.getName() ); propertyData.setAccessType( accessType ); - addPropertyJoinTables( property, propertyData ); - addPropertyAuditingOverrides( property, propertyData ); - if ( !processPropertyAuditingOverrides( property, propertyData ) ) { - // not audited due to AuditOverride annotation - return false; + addPropertyJoinTables( attributeAnnotations, propertyData ); + addPropertyAuditingOverrides( attributeAnnotations, propertyData ); + if ( !processPropertyAuditingOverrides( attribute, propertyData ) ) { + return false; // not audited due to AuditOverride annotation } - addPropertyMapKey( property, propertyData ); - setPropertyAuditMappedBy( property, propertyData ); - setPropertyRelationMappedBy( property, propertyData ); + addPropertyMapKey( attributeAnnotations, propertyData ); + setPropertyAuditMappedBy( attributeAnnotations, propertyData ); + setPropertyRelationMappedBy( attributeAnnotations, propertyData ); return true; } - - protected boolean checkAudited( - XProperty property, - PropertyAuditingData propertyData, Audited allClassAudited) { + protected boolean checkAudited(Attribute attribute, PropertyAuditingData propertyData, Audited allClassAudited) { + Map> attributeAnnotations = context.locateAttributeAnnotations( attribute ); // Checking if this property is explicitly audited or if all properties are. - Audited aud = ( property.isAnnotationPresent( Audited.class ) ) - ? property.getAnnotation( Audited.class ) + Audited aud = attributeAnnotations.containsKey( EnversDotNames.AUDITED ) + ? context.getAnnotationProxy( + attributeAnnotations.get( EnversDotNames.AUDITED ).get( 0 ), + Audited.class + ) : allClassAudited; - if ( aud == null - && overriddenAuditedProperties.contains( property ) - && !overriddenNotAuditedProperties.contains( property ) ) { + if ( aud == null && + overriddenAuditedProperties.contains( attribute ) && + !overriddenNotAuditedProperties.contains( attribute ) ) { // Assigning @Audited defaults. If anyone needs to customize those values in the future, // appropriate fields shall be added to @AuditOverride annotation. aud = DEFAULT_AUDITED; @@ -574,84 +598,117 @@ public class AuditedPropertiesReader { } protected boolean checkUsingModifiedFlag(Audited aud) { - return globalCfg.hasSettingForUsingModifiedFlag() ? - globalCfg.isGlobalWithModifiedFlag() : aud.withModifiedFlag(); + return context.getGlobalConfiguration().hasSettingForUsingModifiedFlag() ? + context.getGlobalConfiguration().isGlobalWithModifiedFlag() : aud.withModifiedFlag(); } - private void setPropertyRelationMappedBy(XProperty property, PropertyAuditingData propertyData) { - final OneToMany oneToMany = property.getAnnotation( OneToMany.class ); - if ( oneToMany != null && !"".equals( oneToMany.mappedBy() ) ) { - propertyData.setRelationMappedBy( oneToMany.mappedBy() ); - } - } - - private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) { - final AuditMappedBy auditMappedBy = property.getAnnotation( AuditMappedBy.class ); - if ( auditMappedBy != null ) { - propertyData.setAuditMappedBy( auditMappedBy.mappedBy() ); - if ( !"".equals( auditMappedBy.positionMappedBy() ) ) { - propertyData.setPositionMappedBy( auditMappedBy.positionMappedBy() ); + private void setPropertyRelationMappedBy(Map> attributeAnnotations, + PropertyAuditingData propertyData) { + final AnnotationInstance oneToMany = JandexHelper.getSingleAnnotation( + attributeAnnotations, + JPADotNames.ONE_TO_MANY + ); + if ( oneToMany != null ) { + final String mappedBy = JandexHelper.getValue( + oneToMany, "mappedBy", String.class, context.getClassLoaderService() + ); + if ( StringHelper.isNotEmpty( mappedBy ) ) { + propertyData.setRelationMappedBy( mappedBy ); } } } - private void addPropertyMapKey(XProperty property, PropertyAuditingData propertyData) { - final MapKey mapKey = property.getAnnotation( MapKey.class ); - if ( mapKey != null ) { - propertyData.setMapKey( mapKey.name() ); + private void setPropertyAuditMappedBy( + Map> attributeAnnotations, + PropertyAuditingData propertyData) { + final AnnotationInstance auditMappedBy = JandexHelper.getSingleAnnotation( + attributeAnnotations, + EnversDotNames.AUDIT_MAPPED_BY + ); + if ( auditMappedBy != null ) { + propertyData.setAuditMappedBy( + JandexHelper.getValue( auditMappedBy, "mappedBy", String.class, context.getClassLoaderService() ) + ); + final String positionMappedBy = JandexHelper.getValue( + auditMappedBy, "positionMappedBy", String.class, context.getClassLoaderService() + ); + if ( StringHelper.isNotEmpty( positionMappedBy ) ) { + propertyData.setPositionMappedBy( positionMappedBy ); + } } } - private void addPropertyJoinTables(XProperty property, PropertyAuditingData propertyData) { - // first set the join table based on the AuditJoinTable annotation - final AuditJoinTable joinTable = property.getAnnotation( AuditJoinTable.class ); - if ( joinTable != null ) { - propertyData.setJoinTable( joinTable ); + private void addPropertyMapKey( + Map> attributeAnnotations, + PropertyAuditingData propertyData) { + final AnnotationInstance mapKey = JandexHelper.getSingleAnnotation( attributeAnnotations, JPADotNames.MAP_KEY ); + if ( mapKey != null ) { + propertyData.setMapKey( + JandexHelper.getValue( + mapKey, + "name", + String.class, + context.getClassLoaderService() + ) + ); } - else { + } + + private void addPropertyJoinTables(Map> attributeAnnotations, + PropertyAuditingData propertyData) { + // first set the join table based on the AuditJoinTable annotation + final AnnotationInstance joinTable = JandexHelper.getSingleAnnotation( + attributeAnnotations, + EnversDotNames.AUDIT_JOIN_TABLE + ); + if ( joinTable != null ) { + propertyData.setJoinTable( context.getAnnotationProxy( joinTable, AuditJoinTable.class ) ); + } else { propertyData.setJoinTable( DEFAULT_AUDIT_JOIN_TABLE ); } } - /** - * Add the {@link AuditOverride} annotations. + /*** + * Add the {@link org.hibernate.envers.AuditOverride} annotations. * - * @param property the property being processed + * @param attributeAnnotations the property being processed * @param propertyData the Envers auditing data for this property */ - private void addPropertyAuditingOverrides(XProperty property, PropertyAuditingData propertyData) { - final AuditOverride annotationOverride = property.getAnnotation( AuditOverride.class ); + private void addPropertyAuditingOverrides( + Map> attributeAnnotations, + PropertyAuditingData propertyData) { + final AnnotationInstance annotationOverride = JandexHelper.getSingleAnnotation( attributeAnnotations, EnversDotNames.AUDIT_OVERRIDE ); if ( annotationOverride != null ) { - propertyData.addAuditingOverride( annotationOverride ); + propertyData.addAuditingOverride( context.getAnnotationProxy( annotationOverride, AuditOverride.class ) ); } - final AuditOverrides annotationOverrides = property.getAnnotation( AuditOverrides.class ); + final AnnotationInstance annotationOverrides = JandexHelper.getSingleAnnotation( attributeAnnotations, EnversDotNames.AUDIT_OVERRIDES ); if ( annotationOverrides != null ) { - propertyData.addAuditingOverrides( annotationOverrides ); + propertyData.addAuditingOverrides( context.getAnnotationProxy( annotationOverrides, AuditOverrides.class ) ); } } /** - * Process the {@link AuditOverride} annotations for this property. - * - * @param property the property for which the {@link AuditOverride} - * annotations are being processed - * @param propertyData the Envers auditing data for this property + * Process the {@link org.hibernate.envers.AuditOverride} annotations for this property. * + * @param attribute + * the property for which the {@link org.hibernate.envers.AuditOverride} + * annotations are being processed + * @param propertyData + * the Envers auditing data for this property * @return {@code false} if isAudited() of the override annotation was set to */ - private boolean processPropertyAuditingOverrides(XProperty property, PropertyAuditingData propertyData) { + private boolean processPropertyAuditingOverrides(Attribute attribute, PropertyAuditingData propertyData) { // if this property is part of a component, process all override annotations - if ( this.auditedPropertiesHolder instanceof ComponentAuditingData ) { - final List overrides = ( (ComponentAuditingData) this.auditedPropertiesHolder ).getAuditingOverrides(); - for ( AuditOverride override : overrides ) { - if ( property.getName().equals( override.name() ) ) { + if (this.auditedPropertiesHolder instanceof ComponentAuditingData) { + List overrides = ((ComponentAuditingData) this.auditedPropertiesHolder).getAuditingOverrides(); + for (AuditOverride override : overrides) { + if (attribute.getName().equals(override.name())) { // the override applies to this property - if ( !override.isAudited() ) { + if (!override.isAudited()) { return false; - } - else { - if ( override.auditJoinTable() != null ) { - propertyData.setJoinTable( override.auditJoinTable() ); + } else { + if (override.auditJoinTable() != null) { + propertyData.setJoinTable(override.auditJoinTable()); } } } @@ -716,50 +773,46 @@ public class AuditedPropertiesReader { }; public static class ComponentPropertiesSource implements PersistentPropertiesSource { - private final XClass xclass; - private final Component component; + private final ClassInfo classInfo; + private final AttributeBindingContainer attributeBindingContainer; - protected ComponentPropertiesSource(XClass xClazz, Component component) { - this.xclass = xClazz; - this.component = component; - } - - public ComponentPropertiesSource(ReflectionManager reflectionManager, Component component) { - try { - this.xclass = reflectionManager.classForName( component.getComponentClassName(), this.getClass() ); - } - catch ( ClassNotFoundException e ) { - throw new MappingException( e ); - } - - this.component = component; + public ComponentPropertiesSource( + ClassInfo classInfo, + AttributeBindingContainer attributeBindingContainer) { + this.classInfo = classInfo; + this.attributeBindingContainer = attributeBindingContainer; } @Override @SuppressWarnings({ "unchecked" }) - public Iterator getPropertyIterator() { - return component.getPropertyIterator(); + public Iterable getNonIdAttributeBindings() { + return attributeBindingContainer.attributeBindings(); } @Override - public Property getProperty(String propertyName) { - return component.getProperty( propertyName ); + public AttributeBinding getAttributeBinding(String attributeName) { + return attributeBindingContainer.locateAttributeBinding( attributeName ); } @Override - public XClass getXClass() { - return xclass; + public AttributeBindingContainer getAttributeBindingContainer() { + return attributeBindingContainer; + } + + @Override + public ClassInfo getClassInfo() { + return classInfo; } } public static class DynamicComponentSource extends ComponentPropertiesSource { - private XProperty baseProperty; - - public DynamicComponentSource(ReflectionManager reflectionManager, Component component, XProperty baseProperty) { - super( reflectionManager.toXClass( Map.class ), component ); - this.baseProperty = baseProperty; + public DynamicComponentSource( + AttributeBindingContainer attributeBindingContainer) { + //TODO: need a ClassInfo for Map. + //super( reflectionManager.toXClass( Map.class ), attributeBindingContainer ); + super( null, attributeBindingContainer ); + throw new NotYetImplementedException( "dynamic components are not supported yet." ); } } - } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ClassAuditingData.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ClassAuditingData.java index ed20a7f5bf..beace10747 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ClassAuditingData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ClassAuditingData.java @@ -25,6 +25,8 @@ package org.hibernate.envers.configuration.internal.metadata.reader; import java.util.Map; +import org.jboss.jandex.AnnotationInstance; + import org.hibernate.envers.AuditTable; import static org.hibernate.envers.internal.tools.Tools.newHashMap; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditedPropertiesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditedPropertiesReader.java index fa7d250237..969081a2be 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditedPropertiesReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditedPropertiesReader.java @@ -23,11 +23,17 @@ */ package org.hibernate.envers.configuration.internal.metadata.reader; -import org.hibernate.annotations.common.reflection.ReflectionManager; -import org.hibernate.annotations.common.reflection.XProperty; +import java.util.List; +import java.util.Map; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; + import org.hibernate.envers.Audited; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.configuration.internal.GlobalConfiguration; +import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.event.spi.EnversDotNames; +import org.hibernate.metamodel.spi.domain.Attribute; /** * Reads the audited properties for components. @@ -38,25 +44,29 @@ import org.hibernate.envers.configuration.internal.GlobalConfiguration; public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader { public ComponentAuditedPropertiesReader( - ModificationStore defaultStore, - PersistentPropertiesSource persistentPropertiesSource, + AuditConfiguration.AuditConfigurationContext context, AuditedPropertiesHolder auditedPropertiesHolder, - GlobalConfiguration globalCfg, ReflectionManager reflectionManager, + PersistentPropertiesSource persistentPropertiesSource, String propertyNamePrefix) { super( - defaultStore, persistentPropertiesSource, auditedPropertiesHolder, - globalCfg, reflectionManager, propertyNamePrefix + context, auditedPropertiesHolder, persistentPropertiesSource, propertyNamePrefix ); } @Override protected boolean checkAudited( - XProperty property, + Attribute attribute, PropertyAuditingData propertyData, Audited allClassAudited) { // Checking if this property is explicitly audited or if all properties are. - final Audited aud = property.getAnnotation( Audited.class ); - if ( aud != null ) { + final Map> attributeAnnotations = + getContext().locateAttributeAnnotations( attribute ); + // Checking if this property is explicitly audited or if all properties are. + if ( attributeAnnotations.containsKey( EnversDotNames.AUDITED ) ) { + final Audited aud = getContext().getAnnotationProxy( + attributeAnnotations.get( EnversDotNames.AUDITED ).get( 0 ), + Audited.class + ); propertyData.setStore( aud.modStore() ); propertyData.setRelationTargetAuditMode( aud.targetAuditMode() ); propertyData.setUsingModifiedFlag( checkUsingModifiedFlag( aud ) ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/DynamicProperty.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/DynamicProperty.java deleted file mode 100644 index 7b0b7ec303..0000000000 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/DynamicProperty.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.hibernate.envers.configuration.internal.metadata.reader; - -import java.lang.annotation.Annotation; -import java.util.Collection; - -import org.hibernate.annotations.common.reflection.XClass; -import org.hibernate.annotations.common.reflection.XProperty; - -/** - * This class prenteds to be property but in fact it represents entry in the map (for dynamic component) - * - * @author Lukasz Zuchowski (author at zuchos dot com) - */ -public class DynamicProperty implements XProperty { - - private AuditedPropertiesReader.DynamicComponentSource source; - private String propertyName; - - public DynamicProperty(AuditedPropertiesReader.DynamicComponentSource source, String propertyName) { - this.source = source; - this.propertyName = propertyName; - } - - @Override - public XClass getDeclaringClass() { - return source.getXClass(); - } - - @Override - public String getName() { - return propertyName; - } - - @Override - public boolean isCollection() { - return false; - } - - @Override - public boolean isArray() { - return false; - } - - @Override - public Class getCollectionClass() { - return null; - } - - @Override - public XClass getType() { - return source.getXClass(); - } - - @Override - public XClass getElementClass() { - return null; - } - - @Override - public XClass getClassOrElementClass() { - return null; - } - - @Override - public XClass getMapKey() { - return null; - } - - @Override - public int getModifiers() { - return 0; - } - - @Override - public void setAccessible(boolean accessible) { - } - - @Override - public Object invoke(Object target, Object... parameters) { - return null; - } - - @Override - public boolean isTypeResolved() { - return false; - } - - @Override - public T getAnnotation(Class annotationType) { - return null; - } - - @Override - public boolean isAnnotationPresent(Class annotationType) { - return false; - } - - @Override - public Annotation[] getAnnotations() { - return new Annotation[0]; - } -} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PersistentPropertiesSource.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PersistentPropertiesSource.java index b4832e5f91..2453fc4162 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PersistentPropertiesSource.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PersistentPropertiesSource.java @@ -24,9 +24,15 @@ package org.hibernate.envers.configuration.internal.metadata.reader; import java.util.Iterator; +import java.util.List; + +import org.jboss.jandex.ClassInfo; import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.mapping.Property; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; +import org.hibernate.metamodel.spi.domain.AttributeContainer; /** * A source of data on persistent properties of a class or component. @@ -34,9 +40,11 @@ import org.hibernate.mapping.Property; * @author Adam Warski (adam at warski dot org) */ public interface PersistentPropertiesSource { - Iterator getPropertyIterator(); + Iterable getNonIdAttributeBindings(); - Property getProperty(String propertyName); + AttributeBinding getAttributeBinding(String attributeName); - XClass getXClass(); + AttributeBindingContainer getAttributeBindingContainer(); + + ClassInfo getClassInfo(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java index 1c2024b401..1d7a94b697 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java @@ -24,18 +24,21 @@ package org.hibernate.envers.configuration.spi; import java.util.HashSet; +import java.util.List; import java.util.Map; -import java.util.Properties; +import java.util.UUID; import java.util.WeakHashMap; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; + import org.hibernate.MappingException; -import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.cfg.Configuration; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; import org.hibernate.envers.configuration.internal.EntitiesConfigurator; import org.hibernate.envers.configuration.internal.GlobalConfiguration; -import org.hibernate.envers.configuration.internal.RevisionInfoConfiguration; import org.hibernate.envers.configuration.internal.RevisionInfoConfigurationResult; import org.hibernate.envers.internal.entities.EntitiesConfigurations; import org.hibernate.envers.internal.entities.PropertyData; @@ -46,8 +49,13 @@ import org.hibernate.envers.internal.synchronization.AuditProcessManager; import org.hibernate.envers.internal.tools.ReflectionTools; import org.hibernate.envers.strategy.AuditStrategy; import org.hibernate.envers.strategy.ValidityAuditStrategy; -import org.hibernate.internal.util.ClassLoaderHelper; import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.metamodel.Metadata; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.domain.Attribute; +import org.hibernate.metamodel.spi.domain.AttributeContainer; import org.hibernate.property.Getter; /** @@ -101,45 +109,37 @@ public class AuditConfiguration { return classLoaderService; } - public AuditConfiguration(Configuration cfg) { - this( cfg, null ); - } + //public AuditConfiguration(Configuration cfg) { + // this( cfg, null ); + //} - public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderService) { - // TODO: Temporarily allow Envers to continuing using - // hibernate-commons-annotations' for reflection and class loading. - final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader( ClassLoaderHelper.getContextClassLoader() ); + public AuditConfiguration(AuditConfigurationContext context) { + this.globalCfg = context.getGlobalConfiguration(); + this.auditEntCfg = context.getAuditEntitiesConfiguration(); - final Properties properties = cfg.getProperties(); + this.auditProcessManager = new AuditProcessManager( context.getRevisionInfoConfigurationResult().getRevisionInfoGenerator() ); + this.revisionInfoQueryCreator = context.getRevisionInfoConfigurationResult().getRevisionInfoQueryCreator(); + this.revisionInfoNumberReader = context.getRevisionInfoConfigurationResult().getRevisionInfoNumberReader(); + this.modifiedEntityNamesReader = context.getRevisionInfoConfigurationResult().getModifiedEntityNamesReader(); - final ReflectionManager reflectionManager = cfg.getReflectionManager(); - this.globalCfg = new GlobalConfiguration( properties, classLoaderService ); - final RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration( globalCfg ); - final RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure( cfg, reflectionManager ); - this.auditEntCfg = new AuditEntitiesConfiguration( properties, revInfoCfgResult.getRevisionInfoEntityName() ); - this.auditProcessManager = new AuditProcessManager( revInfoCfgResult.getRevisionInfoGenerator() ); - this.revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator(); - this.revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader(); - this.modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader(); - this.classLoaderService = classLoaderService; this.auditStrategy = initializeAuditStrategy( - revInfoCfgResult.getRevisionInfoClass(), - revInfoCfgResult.getRevisionInfoTimestampData() + context.getRevisionInfoConfigurationResult().getRevisionInfoClass(), + context.getRevisionInfoConfigurationResult().getRevisionInfoTimestampData() ); this.entCfg = new EntitiesConfigurator().configure( - cfg, reflectionManager, globalCfg, auditEntCfg, auditStrategy, classLoaderService, - revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping() + context, + auditStrategy, + context.getRevisionInfoConfigurationResult().getRevisionInfoXmlMapping(), + context.getRevisionInfoConfigurationResult().getRevisionInfoRelationMapping() ); - Thread.currentThread().setContextClassLoader( tccl ); } private AuditStrategy initializeAuditStrategy(Class revisionInfoClass, PropertyData revisionInfoTimestampData) { AuditStrategy strategy; try { - Class auditStrategyClass = null; + Class auditStrategyClass; try { auditStrategyClass = this.getClass().getClassLoader().loadClass( auditEntCfg.getAuditStrategyName() ); } @@ -167,20 +167,19 @@ public class AuditConfiguration { return strategy; } - private static final Map CFGS = new WeakHashMap(); + private static final Map CFGS = new WeakHashMap(); - public synchronized static AuditConfiguration getFor(Configuration cfg) { - return getFor( cfg, null ); - } + //public synchronized static AuditConfiguration register(MetadataImplementor metadata) { + // return register( metadata, null ); + //} - public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoaderService classLoaderService) { - AuditConfiguration verCfg = CFGS.get( cfg ); + public synchronized static AuditConfiguration register( + AuditConfigurationContext context, Metadata metadata) { + AuditConfiguration verCfg = CFGS.get( metadata.getUUID() ); if ( verCfg == null ) { - verCfg = new AuditConfiguration( cfg, classLoaderService ); - CFGS.put( cfg, verCfg ); - - cfg.buildMappings(); + verCfg = new AuditConfiguration( context ); + CFGS.put( metadata.getUUID(), verCfg ); } return verCfg; @@ -188,7 +187,7 @@ public class AuditConfiguration { public void destroy() { synchronized (AuditConfiguration.class) { - for ( Map.Entry c : new HashSet>( + for ( Map.Entry c : new HashSet>( CFGS.entrySet() ) ) { if ( c.getValue() == this ) { // this is nasty cleanup fix, whole static CFGS should be reworked CFGS.remove( c.getKey() ); @@ -197,4 +196,41 @@ public class AuditConfiguration { } classLoaderService = null; } + + public interface AuditConfigurationContext { + //InFlightMetadataCollector metadataCollector, + //AdditionalJaxbRootProducer.AdditionalJaxbRootProducerContext context, + //GlobalConfiguration globalCfg, + //AuditEntitiesConfiguration verEntCfg, + //AuditStrategy auditStrategy, + + Metadata getMetadata(); + + EntityBinding getEntityBinding(String entityName); + + EntityBinding getEntityBinding(ClassInfo classInfo); + + IndexView getJandexIndex(); + + ClassInfo getClassInfo(String className); + + ClassInfo getClassInfo(DotName classDotName); + + ClassInfo getClassInfo(AttributeContainer attributeContainer); + + ClassLoaderService getClassLoaderService(); + + T getAnnotationProxy(AnnotationInstance annotationInstance, Class annotationClass); + + Map> locateAttributeAnnotations(Attribute attribute); + // return coreConfiguration.locateAttributeAnnotations; + + GlobalConfiguration getGlobalConfiguration(); + + AuditEntitiesConfiguration getAuditEntitiesConfiguration(); + + public RevisionInfoConfigurationResult getRevisionInfoConfigurationResult(); + + void addDocument(org.w3c.dom.Document document); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdTrackingModifiedEntitiesRevisionEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdTrackingModifiedEntitiesRevisionEntity.java index 169b74d17e..0cbe5c0911 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdTrackingModifiedEntitiesRevisionEntity.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdTrackingModifiedEntitiesRevisionEntity.java @@ -25,11 +25,11 @@ package org.hibernate.envers.enhanced; import java.util.HashSet; import java.util.Set; +import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.FetchType; import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; import javax.persistence.MappedSuperclass; import org.hibernate.annotations.Fetch; @@ -46,7 +46,7 @@ import org.hibernate.envers.ModifiedEntityNames; @MappedSuperclass public class SequenceIdTrackingModifiedEntitiesRevisionEntity extends SequenceIdRevisionEntity { @ElementCollection(fetch = FetchType.EAGER) - @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) + @CollectionTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) @Column(name = "ENTITYNAME") @Fetch(FetchMode.JOIN) @ModifiedEntityNames diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversDotNames.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversDotNames.java new file mode 100644 index 0000000000..6e412ef9ae --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversDotNames.java @@ -0,0 +1,36 @@ +package org.hibernate.envers.event.spi; + +import org.jboss.jandex.DotName; + +import org.hibernate.envers.AuditJoinTable; +import org.hibernate.envers.AuditMappedBy; +import org.hibernate.envers.AuditOverride; +import org.hibernate.envers.AuditOverrides; +import org.hibernate.envers.AuditTable; +import org.hibernate.envers.Audited; +import org.hibernate.envers.ModifiedEntityNames; +import org.hibernate.envers.NotAudited; +import org.hibernate.envers.RevisionEntity; +import org.hibernate.envers.RevisionNumber; +import org.hibernate.envers.RevisionTimestamp; +import org.hibernate.envers.SecondaryAuditTable; +import org.hibernate.envers.SecondaryAuditTables; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +public interface EnversDotNames { + DotName AUDITED = DotName.createSimple( Audited.class.getName() ); + DotName AUDIT_JOIN_TABLE = DotName.createSimple( AuditJoinTable.class.getName() ); + DotName AUDIT_MAPPED_BY = DotName.createSimple( AuditMappedBy.class.getName() ); + DotName AUDIT_OVERRIDE = DotName.createSimple( AuditOverride.class.getName() ); + DotName AUDIT_OVERRIDES = DotName.createSimple( AuditOverrides.class.getName() ); + DotName AUDIT_TABLE = DotName.createSimple( AuditTable.class.getName() ); + DotName MODIFIED_ENTITY_NAMES = DotName.createSimple( ModifiedEntityNames.class.getName() ); + DotName NOT_AUDITED = DotName.createSimple( NotAudited.class.getName() ); + DotName REVISION_ENTITY = DotName.createSimple( RevisionEntity.class.getName() ); + DotName REVISION_NUMBER = DotName.createSimple( RevisionNumber.class.getName() ); + DotName REVISION_TIMESTAMP = DotName.createSimple( RevisionTimestamp.class.getName() ); + DotName SECONDARY_AUDIT_TABLE = DotName.createSimple( SecondaryAuditTable.class.getName() ); + DotName SECONDARY_AUDIT_TABLES = DotName.createSimple( SecondaryAuditTables.class.getName() ); +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java index 8b74702c41..874c2f049c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java @@ -23,8 +23,10 @@ */ package org.hibernate.envers.event.spi; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.AssertionFailure; import org.hibernate.cfg.Configuration; +import org.hibernate.engine.config.spi.ConfigurationService; +import org.hibernate.engine.config.spi.StandardConverters; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.event.service.spi.EventListenerRegistry; @@ -73,11 +75,72 @@ public class EnversIntegrator implements Integrator { final EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE ); - enversConfiguration = AuditConfiguration.getFor( - configuration, - serviceRegistry.getService( - ClassLoaderService.class - ) + if ( enversConfiguration.getEntCfg().hasAuditedEntities() ) { + listenerRegistry.appendListeners( + EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl( + enversConfiguration + ) + ); + listenerRegistry.appendListeners( + EventType.POST_INSERT, new EnversPostInsertEventListenerImpl( + enversConfiguration + ) + ); + listenerRegistry.appendListeners( + EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl( + enversConfiguration + ) + ); + listenerRegistry.appendListeners( + EventType.POST_COLLECTION_RECREATE, + new EnversPostCollectionRecreateEventListenerImpl( enversConfiguration ) + ); + listenerRegistry.appendListeners( + EventType.PRE_COLLECTION_REMOVE, + new EnversPreCollectionRemoveEventListenerImpl( enversConfiguration ) + ); + listenerRegistry.appendListeners( + EventType.PRE_COLLECTION_UPDATE, + new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration ) + ); + throw new AssertionFailure( "No longer implemented." ); + } + } + + @Override + public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { + if ( enversConfiguration != null ) { + enversConfiguration.destroy(); + } + } + + /** + * {@inheritDoc} + * + * @see org.hibernate.integrator.spi.Integrator#integrate(org.hibernate.metamodel.spi.MetadataImplementor, org.hibernate.engine.spi.SessionFactoryImplementor, org.hibernate.service.spi.SessionFactoryServiceRegistry) + */ + @Override + public void integrate( + MetadataImplementor metadata, + SessionFactoryImplementor sessionFactory, + SessionFactoryServiceRegistry serviceRegistry) { + final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class ); + final boolean autoRegister = configurationService.getSetting( + AUTO_REGISTER, + StandardConverters.BOOLEAN, + true + ); + if ( !autoRegister ) { + LOG.debug( "Skipping Envers listener auto registration" ); + return; + } + + final EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); + listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE ); + + enversConfiguration = AuditConfiguration.register( + null, + metadata ); if ( enversConfiguration.getEntCfg().hasAuditedEntities() ) { @@ -110,24 +173,4 @@ public class EnversIntegrator implements Integrator { ); } } - - @Override - public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { - if ( enversConfiguration != null ) { - enversConfiguration.destroy(); - } - } - - /** - * {@inheritDoc} - * - * @see org.hibernate.integrator.spi.Integrator#integrate(org.hibernate.metamodel.source.MetadataImplementor, org.hibernate.engine.spi.SessionFactoryImplementor, org.hibernate.service.spi.SessionFactoryServiceRegistry) - */ - @Override - public void integrate( - MetadataImplementor metadata, - SessionFactoryImplementor sessionFactory, - SessionFactoryServiceRegistry serviceRegistry) { - // TODO: implement - } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversJaxbRootProducer.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversJaxbRootProducer.java new file mode 100644 index 0000000000..050ed61ea1 --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversJaxbRootProducer.java @@ -0,0 +1,200 @@ +package org.hibernate.envers.event.spi; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; +import org.jboss.logging.Logger; + +import org.hibernate.MappingException; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.envers.configuration.internal.AnnotationProxyBuilder; +import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; +import org.hibernate.envers.configuration.internal.GlobalConfiguration; +import org.hibernate.envers.configuration.internal.RevisionInfoConfiguration; +import org.hibernate.envers.configuration.internal.RevisionInfoConfigurationResult; +import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.metamodel.Metadata; +import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.AdditionalJaxbRootProducer; +import org.hibernate.metamodel.spi.InFlightMetadataCollector; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.domain.Attribute; +import org.hibernate.metamodel.spi.domain.AttributeContainer; +import org.hibernate.xml.internal.jaxb.MappingXmlBinder; +import org.hibernate.xml.spi.BindResult; +import org.hibernate.xml.spi.Origin; +import org.hibernate.xml.spi.SourceType; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +public class EnversJaxbRootProducer implements AdditionalJaxbRootProducer { + private static final CoreMessageLogger LOG = Logger.getMessageLogger( + CoreMessageLogger.class, + EnversJaxbRootProducer.class.getName() + ); + + @Override + public List produceRoots( + final InFlightMetadataCollector metadataCollector, + final AdditionalJaxbRootProducerContext additionalJaxbRootProducerContext) { + + final AuditConfigurationContextImpl context = new AuditConfigurationContextImpl( + metadataCollector, + additionalJaxbRootProducerContext + ); + + final AuditConfiguration configuration = AuditConfiguration.register( context, metadataCollector); + return Collections.unmodifiableList( context.getBindResults() ); + } + + + private class AuditConfigurationContextImpl implements AuditConfiguration.AuditConfigurationContext { + + private final InFlightMetadataCollector metadataCollector; + private final AdditionalJaxbRootProducerContext additionalJaxbRootProducerContext; + private final AnnotationProxyBuilder annotationProxyBuilder = new AnnotationProxyBuilder(); + private final MappingXmlBinder jaxbProcessor; + private final List bindResults = new ArrayList(); + private final Origin origin = new Origin( SourceType.DOM, Origin.UNKNOWN_FILE_PATH ); + private final GlobalConfiguration globalCfg; + private final AuditEntitiesConfiguration auditEntCfg; + private final RevisionInfoConfigurationResult revInfoCfgResult; + + AuditConfigurationContextImpl( + final InFlightMetadataCollector metadataCollector, + final AdditionalJaxbRootProducerContext additionalJaxbRootProducerContext) { + this.metadataCollector = metadataCollector; + this.additionalJaxbRootProducerContext = additionalJaxbRootProducerContext; + this.globalCfg = new GlobalConfiguration( additionalJaxbRootProducerContext.getServiceRegistry() ); + final RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration( globalCfg ); + this.revInfoCfgResult = revInfoCfg.configure( metadataCollector, additionalJaxbRootProducerContext ); + this.auditEntCfg = new AuditEntitiesConfiguration( additionalJaxbRootProducerContext.getServiceRegistry(), revInfoCfgResult.getRevisionInfoEntityName() ); + jaxbProcessor = new MappingXmlBinder( + additionalJaxbRootProducerContext.getServiceRegistry() + ); + } + + @Override + public Metadata getMetadata() { + return metadataCollector; + } + + @Override + public EntityBinding getEntityBinding(String entityName) { + return metadataCollector.getEntityBinding( entityName ); + } + + @Override + public EntityBinding getEntityBinding(final ClassInfo clazz) { + // TODO: Is there a better way? +// final AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation( clazz, JPADotNames.ENTITY ); +// String entityName = JandexHelper.getValue( jpaEntityAnnotation, "name", String.class ); +// if ( entityName == null ) { +// entityName = clazz.name().toString(); +// } + return getEntityBinding( clazz.name().toString() ); + } + + @Override + public IndexView getJandexIndex() { + return additionalJaxbRootProducerContext.getJandexIndex(); + } + + @Override + public ClassInfo getClassInfo(AttributeContainer attributeContainer) { + return getClassInfo( + attributeContainer.getDescriptor().getName().fullName() + ); + } + + @Override + public ClassInfo getClassInfo(String className) { + return getClassInfo( DotName.createSimple( className ) ); + } + + @Override + public ClassInfo getClassInfo(DotName classDotName) { + return getJandexIndex().getClassByName( classDotName ); + } + + @Override + public ClassLoaderService getClassLoaderService() { + return additionalJaxbRootProducerContext.getServiceRegistry().getService( ClassLoaderService.class ); + } + + @Override + public T getAnnotationProxy(AnnotationInstance annotationInstance, Class annotationClass) { + return annotationProxyBuilder.getAnnotationProxy( + annotationInstance, annotationClass, getClassLoaderService() + ); + } + + @Override + public Map> locateAttributeAnnotations(final Attribute attribute) { + final ClassInfo classInfo = getClassInfo( attribute.getAttributeContainer() ); + return JandexHelper.getMemberAnnotations( + classInfo, + attribute.getName(), + additionalJaxbRootProducerContext.getServiceRegistry() + ); + } + + @Override + public GlobalConfiguration getGlobalConfiguration() { + return globalCfg; + } + + @Override + public AuditEntitiesConfiguration getAuditEntitiesConfiguration() { + return auditEntCfg; + } + + @Override + public RevisionInfoConfigurationResult getRevisionInfoConfigurationResult() { + return revInfoCfgResult; + } + + @Override + public void addDocument(org.w3c.dom.Document document) { + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Source xmlSource = new DOMSource( document ); + Result outputTarget = new StreamResult( outputStream ); + try { + TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget); + } + catch ( TransformerConfigurationException ex ){ + throw new MappingException( ex ); + } + catch ( TransformerException ex ) { + throw new MappingException( ex ); + } + InputStream is = new ByteArrayInputStream(outputStream.toByteArray()); + bindResults.add( jaxbProcessor.bind( is, origin ) ); + + } + + private List getBindResults() { + return bindResults; + } + } +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MappingTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MappingTools.java index 52446e8da6..5cf8af3f17 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MappingTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MappingTools.java @@ -23,11 +23,14 @@ */ package org.hibernate.envers.internal.tools; -import org.hibernate.mapping.Collection; -import org.hibernate.mapping.ManyToOne; -import org.hibernate.mapping.OneToMany; -import org.hibernate.mapping.ToOne; -import org.hibernate.mapping.Value; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeAssociationElementBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; +import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.type.EntityType; /** * @author Adam Warski (adam at warski dot org) @@ -51,30 +54,43 @@ public abstract class MappingTools { return referencePropertyName + "_"; } - public static String getReferencedEntityName(Value value) { - if ( value instanceof ToOne ) { - return ((ToOne) value).getReferencedEntityName(); + public static String getReferencedEntityName(AttributeBinding attributeBinding) { + if ( attributeBinding.getAttribute().isSingular() ) { + final SingularAttributeBinding singularAttributeBinding = (SingularAssociationAttributeBinding) attributeBinding; + if ( singularAttributeBinding.isAssociation() ) { + return SingularAssociationAttributeBinding.class.cast( singularAttributeBinding ).getReferencedEntityName(); + } } - else if ( value instanceof OneToMany ) { - return ((OneToMany) value).getReferencedEntityName(); + else { + final PluralAttributeBinding pluralAttributeBinding = (PluralAttributeBinding) attributeBinding; + if ( pluralAttributeBinding.getPluralAttributeElementBinding().getNature().isAssociation() ) { + final PluralAttributeAssociationElementBinding associationPluralAttributeElementBinding = + (PluralAttributeAssociationElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding(); + final EntityType entityType = + (EntityType) associationPluralAttributeElementBinding + .getHibernateTypeDescriptor() + .getResolvedTypeMapping(); + return entityType.getAssociatedEntityName(); + } } - else if ( value instanceof Collection ) { - return getReferencedEntityName( ((Collection) value).getElement() ); - } - return null; } /** - * @param value Persistent property. + * @param attributeBinding Persistent property. * @return {@code false} if lack of associated entity shall raise an exception, {@code true} otherwise. */ - public static boolean ignoreNotFound(Value value) { - if ( value instanceof ManyToOne ) { - return ( (ManyToOne) value ).isIgnoreNotFound(); + public static boolean ignoreNotFound(AttributeBinding attributeBinding) { + if ( ManyToOneAttributeBinding.class.isInstance( attributeBinding )) { + return ! ( (ManyToOneAttributeBinding) attributeBinding ).isNotFoundAnException(); } - else if ( value instanceof OneToMany ) { - return ( (OneToMany) value ).isIgnoreNotFound(); + else if ( attributeBinding instanceof PluralAttributeBinding ) { + final PluralAttributeBinding pluralAttributeBinding = (PluralAttributeBinding) attributeBinding; + final PluralAttributeElementBinding elementBinding = pluralAttributeBinding.getPluralAttributeElementBinding(); + if ( elementBinding.getNature() == PluralAttributeElementBinding.Nature.ONE_TO_MANY ) { + // TODO: FIX THIS!!! + //return !( (OneToManyPluralAttributeElementBinding) elementBinding ).isNotFoundAnException(); + } } return false; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java index 64e0b4dcee..4c0e1567ab 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java @@ -126,7 +126,7 @@ public abstract class ReflectionTools { * * @param name Fully qualified class name. * @param classLoaderService Class loading service. Passing {@code null} reference - * in case of {@link AuditConfiguration#getFor(Configuration)} usage. + * in case of {@link AuditConfiguration#register(Configuration)} usage. * * @return The cass reference. * diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java index 0fafa83c1d..830d6d4b96 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java @@ -32,6 +32,13 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jboss.jandex.AnnotationTarget; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.FieldInfo; +import org.jboss.jandex.IndexView; +import org.jboss.jandex.MethodInfo; + +import org.hibernate.AssertionFailure; import org.hibernate.envers.tools.Pair; /** @@ -100,4 +107,21 @@ public abstract class Tools { return ret; } + + public static boolean isFieldOrPropertyOfClass(AnnotationTarget target, ClassInfo clazz, IndexView jandexIndex) { + final ClassInfo enclosingClass; + if ( target instanceof FieldInfo ) { + final FieldInfo field = (FieldInfo) target; + enclosingClass = field.declaringClass(); + } + else if ( target instanceof MethodInfo ) { + final MethodInfo method = (MethodInfo) target; + enclosingClass = method.declaringClass(); + } + else { + throw new AssertionFailure( "Unexpected annotation target " + target.toString() ); + } + return enclosingClass.equals( clazz ) || jandexIndex.getAllKnownSubclasses( clazz.name() ).contains( enclosingClass ); + } + } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java index 62d8d23269..d6664ae1ee 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java @@ -24,11 +24,27 @@ package org.hibernate.envers.tools.hbm2ddl; import java.sql.Connection; +import java.util.List; +import java.util.Map; import java.util.Properties; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; +import org.w3c.dom.Document; + import org.hibernate.HibernateException; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.Configuration; +import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; +import org.hibernate.envers.configuration.internal.GlobalConfiguration; +import org.hibernate.envers.configuration.internal.RevisionInfoConfigurationResult; import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.metamodel.Metadata; +import org.hibernate.metamodel.spi.MetadataImplementor; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.service.ServiceRegistry; import org.hibernate.tool.hbm2ddl.SchemaExport; @@ -38,33 +54,11 @@ import org.hibernate.tool.hbm2ddl.SchemaExport; public class EnversSchemaGenerator { private final SchemaExport export; - public EnversSchemaGenerator(ServiceRegistry serviceRegistry, Configuration configuration) { - configuration = configureAuditing( configuration ); - export = new SchemaExport( serviceRegistry, configuration ); - } - - public EnversSchemaGenerator(Configuration configuration) { - configuration = configureAuditing( configuration ); - export = new SchemaExport( configuration ); - } - - public EnversSchemaGenerator(Configuration configuration, Properties properties) throws HibernateException { - configuration = configureAuditing( configuration ); - export = new SchemaExport( configuration, properties ); - } - - public EnversSchemaGenerator(Configuration configuration, Connection connection) throws HibernateException { - configuration = configureAuditing( configuration ); - export = new SchemaExport( configuration, connection ); + public EnversSchemaGenerator(MetadataImplementor metadata) { + export = new SchemaExport( metadata ); } public SchemaExport export() { return export; } - - private Configuration configureAuditing(Configuration configuration) { - configuration.buildMappings(); - AuditConfiguration.getFor( configuration ); - return configuration; - } } diff --git a/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.metamodel.spi.AdditionalJaxbRootProducer b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.metamodel.spi.AdditionalJaxbRootProducer new file mode 100644 index 0000000000..f2d2298f01 --- /dev/null +++ b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.metamodel.spi.AdditionalJaxbRootProducer @@ -0,0 +1 @@ +org.hibernate.envers.event.spi.EnversJaxbRootProducer \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java index 0bb267cbc6..f2c31bc98b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java @@ -52,6 +52,7 @@ import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter; import org.junit.After; +import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.jta.TestingJtaPlatformImpl; @@ -85,8 +86,8 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest return serviceRegistry; } - protected Configuration getCfg() { - return entityManagerFactoryBuilder.getHibernateConfiguration(); + protected MetadataImplementor getMetadata() { + return entityManagerFactoryBuilder.getMetadata(); } @BeforeClassOnce diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity1.java index 462762552f..393bae9d1a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity1.java @@ -2,6 +2,7 @@ package org.hibernate.envers.test.entities.collection; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.ForeignKey; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -9,7 +10,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Version; -import org.hibernate.annotations.ForeignKey; import org.hibernate.envers.Audited; import org.hibernate.envers.NotAudited; @@ -29,8 +29,7 @@ public class MultipleCollectionRefEntity1 { private String text; @ManyToOne - @JoinColumn(name = "MCE_ID", nullable = false, insertable = false, updatable = false) - @ForeignKey(name = "FK_RE1_MCE") + @JoinColumn(name = "MCE_ID", nullable = false, insertable = false, updatable = false, foreignKey = @ForeignKey(name = "FK_RE1_MCE") ) @NotAudited private MultipleCollectionEntity multipleCollectionEntity; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity2.java index a9c7dc283e..0768146898 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity2.java @@ -2,6 +2,7 @@ package org.hibernate.envers.test.entities.collection; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.ForeignKey; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -9,7 +10,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Version; -import org.hibernate.annotations.ForeignKey; import org.hibernate.envers.Audited; import org.hibernate.envers.NotAudited; @@ -29,8 +29,7 @@ public class MultipleCollectionRefEntity2 { private String text; @ManyToOne - @JoinColumn(name = "MCE_ID", nullable = false, insertable = false, updatable = false) - @ForeignKey(name = "FK_RE2_MCE") + @JoinColumn(name = "MCE_ID", nullable = false, insertable = false, updatable = false, foreignKey = @ForeignKey(name = "FK_RE2_MCE") ) @NotAudited private MultipleCollectionEntity multipleCollectionEntity; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringListEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringListEntity.java index 7fb7669c26..c58d5562ef 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringListEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringListEntity.java @@ -27,10 +27,10 @@ import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.OrderColumn; import java.util.ArrayList; import java.util.List; -import org.hibernate.annotations.IndexColumn; import org.hibernate.envers.Audited; /** @@ -44,7 +44,7 @@ public class StringListEntity { @Audited @ElementCollection - @IndexColumn(name = "list_index") + @OrderColumn(name = "list_index") private List strings; public StringListEntity() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java index 753f04dfce..a358be250b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.entities.components; +import javax.persistence.Embeddable; import javax.persistence.Embedded; /** * @author Erik-Berndt Scheper */ +@Embeddable public class DefaultValueComponent1 { private String str1; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java index d84b532043..114c0b706f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java @@ -1,9 +1,12 @@ package org.hibernate.envers.test.entities.components; +import javax.persistence.Embeddable; + /** * @author Erik-Berndt Scheper */ +@Embeddable public class DefaultValueComponent2 { private String str1 = "defaultValue"; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java index f88dcf09fa..02f6fd16c4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java @@ -33,8 +33,7 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import org.hibernate.annotations.Sort; -import org.hibernate.annotations.SortType; +import org.hibernate.annotations.SortComparator; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.StrTestEntityComparator; @@ -54,12 +53,12 @@ public class SortedSetEntity { @Audited @ManyToMany - @Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) + @SortComparator(value = StrTestEntityComparator.class) private SortedSet sortedSet = new TreeSet( StrTestEntityComparator.INSTANCE ); @Audited @ElementCollection @MapKeyJoinColumn - @Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) + @SortComparator(value = StrTestEntityComparator.class) private SortedMap sortedMap = new TreeMap( StrTestEntityComparator.INSTANCE ); public SortedSetEntity() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java index 712838b824..d545ab216f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java @@ -5,12 +5,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; +import javax.persistence.OrderColumn; import javax.persistence.Table; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.hibernate.annotations.IndexColumn; import org.hibernate.envers.AuditMappedBy; import org.hibernate.envers.Audited; @@ -32,7 +32,7 @@ public class IndexedListJoinColumnBidirectionalRefIngEntity { @OneToMany @JoinColumn(name = "indexed_join_column") - @IndexColumn(name = "indexed_index") + @OrderColumn(name = "indexed_index") @AuditMappedBy(mappedBy = "owner", positionMappedBy = "position") private List references; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java index 2f37ff3986..ad5efbbb4c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java @@ -7,12 +7,12 @@ import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; +import javax.persistence.OrderColumn; import javax.persistence.Table; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.hibernate.annotations.IndexColumn; import org.hibernate.envers.AuditMappedBy; import org.hibernate.envers.Audited; @@ -35,7 +35,7 @@ public abstract class ParentIndexedListJoinColumnBidirectionalRefIngEntity { @OneToMany @JoinColumn(name = "indexed_join_column") - @IndexColumn(name = "indexed_index") + @OrderColumn(name = "indexed_index") @AuditMappedBy(mappedBy = "owner", positionMappedBy = "position") private List references; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/AnnotatedTrackingRevisionEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/AnnotatedTrackingRevisionEntity.java index 8101398461..da44572b4f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/AnnotatedTrackingRevisionEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/AnnotatedTrackingRevisionEntity.java @@ -1,12 +1,12 @@ package org.hibernate.envers.test.entities.reventity.trackmodifiedentities; +import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; import javax.persistence.Table; import java.util.Set; @@ -44,7 +44,7 @@ public class AnnotatedTrackingRevisionEntity { private long customTimestamp; @ElementCollection - @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) + @CollectionTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) @Column(name = "ENTITYNAME") @ModifiedEntityNames private Set entityNames; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java index df867fc111..ffff521a5a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java @@ -23,12 +23,13 @@ */ package org.hibernate.envers.test.integration.accesstype; +import javax.persistence.Access; +import javax.persistence.AccessType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Transient; -import org.hibernate.annotations.AccessType; import org.hibernate.envers.Audited; /** @@ -40,7 +41,7 @@ public class MixedAccessTypeEntity { @GeneratedValue private Integer id; - @AccessType("property") + @Access(value = AccessType.PROPERTY) private String data; @Transient diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ColumnScalePrecisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ColumnScalePrecisionTest.java index d176ee1e8d..9428316bf6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ColumnScalePrecisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ColumnScalePrecisionTest.java @@ -5,12 +5,12 @@ import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; import org.junit.Assert; import org.junit.Test; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.testing.TestForIssue; /** @@ -18,8 +18,8 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-7003") public class ColumnScalePrecisionTest extends BaseEnversJPAFunctionalTestCase { - private Table auditTable = null; - private Table originalTable = null; + private TableSpecification auditTable = null; + private TableSpecification originalTable = null; private Long id = null; @Override @@ -39,21 +39,29 @@ public class ColumnScalePrecisionTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().commit(); id = entity.getId(); - auditTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity_AUD" ) - .getTable(); - originalTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity" ) - .getTable(); + auditTable = getMetadata().getEntityBinding( + "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity_AUD" + ) + .getPrimaryTable(); + originalTable = getMetadata().getEntityBinding( + "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity" + ) + .getPrimaryTable(); } @Test public void testColumnScalePrecision() { - Column testColumn = new Column( "wholeNumber" ); - Column scalePrecisionAuditColumn = auditTable.getColumn( testColumn ); - Column scalePrecisionColumn = originalTable.getColumn( testColumn ); + String columnName = "wholeNumber"; + Column scalePrecisionAuditColumn = auditTable.locateColumn( columnName ); + Column scalePrecisionColumn = originalTable.locateColumn( columnName ); Assert.assertNotNull( scalePrecisionAuditColumn ); - Assert.assertEquals( scalePrecisionColumn.getPrecision(), scalePrecisionAuditColumn.getPrecision() ); - Assert.assertEquals( scalePrecisionColumn.getScale(), scalePrecisionAuditColumn.getScale() ); + Assert.assertNotNull( scalePrecisionAuditColumn.getSize() ); + Assert.assertEquals( + scalePrecisionColumn.getSize().getPrecision(), + scalePrecisionAuditColumn.getSize().getPrecision() + ); + Assert.assertEquals( scalePrecisionColumn.getSize().getScale(), scalePrecisionAuditColumn.getSize().getScale() ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NoneAudited.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NoneAudited.java index 2acf054521..f10ecf64c1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NoneAudited.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NoneAudited.java @@ -28,7 +28,7 @@ import java.util.Iterator; import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.binding.EntityBinding; import org.junit.Assert; import org.junit.Test; @@ -44,9 +44,12 @@ public class NoneAudited extends BaseEnversJPAFunctionalTestCase { @Test public void testRevisionInfoTableNotCreated() { - @SuppressWarnings({"unchecked"}) List pcs = iteratorToList( getCfg().getClassMappings() ); + @SuppressWarnings({"unchecked"}) List pcs = iteratorToList( + getMetadata().getEntityBindings() + .iterator() + ); Assert.assertEquals( 1, pcs.size() ); - Assert.assertTrue( pcs.get( 0 ).getClassName().contains( "BasicTestEntity3" ) ); + Assert.assertTrue( pcs.get( 0 ).getEntityName().contains( "BasicTestEntity3" ) ); } private List iteratorToList(Iterator it) { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList1.java index 2de3e23a73..e62b575f28 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList1.java @@ -53,7 +53,7 @@ public class EmbeddableList1 extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {EmbeddableListEntity1.class}; + return new Class[] {EmbeddableListEntity1.class, Component3.class, Component4.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList2.java index cd10bcfd0a..91bd75d022 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList2.java @@ -62,7 +62,7 @@ public class EmbeddableList2 extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {EmbeddableListEntity2.class, StrTestNoProxyEntity.class}; + return new Class[] {EmbeddableListEntity2.class, StrTestNoProxyEntity.class, ManyToOneEagerComponent.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableMap.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableMap.java index 2fa9be12dd..d1b187e348 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableMap.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableMap.java @@ -54,7 +54,7 @@ public class EmbeddableMap extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {EmbeddableMapEntity.class}; + return new Class[] {EmbeddableMapEntity.class, Component3.class, Component4.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableSet.java index 3bdb433431..fbb100587c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableSet.java @@ -55,7 +55,7 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {EmbeddableSetEntity.class}; + return new Class[] {EmbeddableSetEntity.class, Component3.class, Component4.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKey.java index c2ba8a0711..1c4e116f4e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKey.java @@ -32,12 +32,14 @@ import org.hibernate.envers.test.entities.components.Component1; import org.hibernate.envers.test.entities.components.Component2; import org.hibernate.envers.test.entities.components.ComponentTestEntity; import org.hibernate.envers.test.tools.TestTools; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Adam Warski (adam at warski dot org) */ +@FailureExpectedWithNewMetamodel( message = " Plural attribute index that is an attribute of the referenced entity is not supported yet." ) public class ComponentMapKey extends BaseEnversJPAFunctionalTestCase { private Integer cmke_id; @@ -46,7 +48,7 @@ public class ComponentMapKey extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {ComponentMapKeyEntity.class, ComponentTestEntity.class}; + return new Class[] {ComponentMapKeyEntity.class, ComponentTestEntity.class, Component1.class, Component2.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKey.java index de6288fb4c..11003823bc 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKey.java @@ -30,12 +30,14 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Adam Warski (adam at warski dot org) */ +@FailureExpectedWithNewMetamodel( message = " Plural attribute index that is an attribute of the referenced entity is not supported yet." ) public class IdMapKey extends BaseEnversJPAFunctionalTestCase { private Integer imke_id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java index 3e54435d33..55ac576753 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java @@ -45,7 +45,7 @@ public class Components extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {ComponentTestEntity.class}; + return new Class[] {ComponentTestEntity.class, Component1.class, Component2.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java index b35529ce71..d5aa37c540 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java @@ -57,7 +57,7 @@ public class DefaultValueComponents extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {DefaultValueComponentTestEntity.class}; + return new Class[] {DefaultValueComponentTestEntity.class, DefaultValueComponent1.class, DefaultValueComponent2.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java index db70b09c9c..4d7e11821c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java @@ -5,21 +5,22 @@ import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.components.UniquePropsEntity; import org.hibernate.envers.test.entities.components.UniquePropsNotAuditedEntity; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PersistentClass; import org.junit.Assert; import org.junit.Test; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-6636") +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class PropertiesGroupTest extends BaseEnversFunctionalTestCase { - private PersistentClass uniquePropsAudit = null; - private PersistentClass uniquePropsNotAuditedAudit = null; + private EntityBinding uniquePropsAudit = null; + private EntityBinding uniquePropsNotAuditedAudit = null; private UniquePropsEntity entityRev1 = null; private UniquePropsNotAuditedEntity entityNotAuditedRev2 = null; @@ -34,10 +35,10 @@ public class PropertiesGroupTest extends BaseEnversFunctionalTestCase { @Test @Priority(10) public void initData() { - uniquePropsAudit = configuration().getClassMapping( + uniquePropsAudit = metadata().getEntityBinding( "org.hibernate.envers.test.entities.components.UniquePropsEntity_AUD" ); - uniquePropsNotAuditedAudit = configuration().getClassMapping( + uniquePropsNotAuditedAudit = metadata().getEntityBinding( "org.hibernate.envers.test.entities.components.UniquePropsNotAuditedEntity_AUD" ); @@ -65,11 +66,11 @@ public class PropertiesGroupTest extends BaseEnversFunctionalTestCase { @Test public void testAuditTableColumns() { - Assert.assertNotNull( uniquePropsAudit.getTable().getColumn( new Column( "DATA1" ) ) ); - Assert.assertNotNull( uniquePropsAudit.getTable().getColumn( new Column( "DATA2" ) ) ); + Assert.assertNotNull( uniquePropsAudit.getPrimaryTable().locateColumn( "DATA1" ) ); + Assert.assertNotNull( uniquePropsAudit.getPrimaryTable().locateColumn( "DATA2" ) ); - Assert.assertNotNull( uniquePropsNotAuditedAudit.getTable().getColumn( new Column( "DATA1" ) ) ); - Assert.assertNull( uniquePropsNotAuditedAudit.getTable().getColumn( new Column( "DATA2" ) ) ); + Assert.assertNotNull( uniquePropsNotAuditedAudit.getPrimaryTable().locateColumn( "DATA1" ) ); + Assert.assertNull( uniquePropsNotAuditedAudit.getPrimaryTable().locateColumn( "DATA2" ) ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentTest.java index 91088c9422..af55a5cc70 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentTest.java @@ -18,6 +18,7 @@ import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.service.ServiceRegistry; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.testing.TestForIssue; @@ -26,6 +27,7 @@ import org.hibernate.testing.TestForIssue; * @author Lukasz Zuchowski (author at zuchos dot com) */ @TestForIssue(jiraKey = "HHH-8049") +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase { @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentsAdvancedCasesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentsAdvancedCasesTest.java index 87d568d033..4978254e63 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentsAdvancedCasesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentsAdvancedCasesTest.java @@ -17,6 +17,7 @@ import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** @@ -24,6 +25,7 @@ import org.hibernate.testing.TestForIssue; * More advanced tests for dynamic component. */ @TestForIssue(jiraKey = "HHH-8049") +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctionalTestCase { public static final String PROP_BOOLEAN = "propBoolean"; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicComponentTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicComponentTest.java index 274c6aa242..b58dc06954 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicComponentTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicComponentTest.java @@ -8,12 +8,14 @@ import org.junit.Test; import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-8049") +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class NotAuditedDynamicComponentTest extends BaseEnversFunctionalTestCase { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/SanityCheckTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/SanityCheckTest.java index 00aa5a9d82..aa8ce61e59 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/SanityCheckTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/SanityCheckTest.java @@ -12,7 +12,9 @@ import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class SanityCheckTest extends BaseEnversFunctionalTestCase { @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/ManyToOneInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/ManyToOneInComponent.java index fd7882acea..bf7f61e4af 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/ManyToOneInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/ManyToOneInComponent.java @@ -44,7 +44,7 @@ public class ManyToOneInComponent extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {ManyToOneComponentTestEntity.class, StrTestEntity.class}; + return new Class[] {ManyToOneComponentTestEntity.class, StrTestEntity.class, ManyToOneComponent.class}; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/NotAuditedManyToOneInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/NotAuditedManyToOneInComponent.java index 114cdd9c51..13871b4676 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/NotAuditedManyToOneInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/NotAuditedManyToOneInComponent.java @@ -42,7 +42,11 @@ public class NotAuditedManyToOneInComponent extends BaseEnversJPAFunctionalTestC @Override protected Class[] getAnnotatedClasses() { - return new Class[] {NotAuditedManyToOneComponentTestEntity.class, UnversionedStrTestEntity.class}; + return new Class[] { + NotAuditedManyToOneComponentTestEntity.class, + UnversionedStrTestEntity.class, + NotAuditedManyToOneComponent.class + }; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/OneToManyInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/OneToManyInComponent.java index d2076681e6..675b907b0a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/OneToManyInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/OneToManyInComponent.java @@ -44,7 +44,7 @@ public class OneToManyInComponent extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {OneToManyComponentTestEntity.class, StrTestEntity.class}; + return new Class[] {OneToManyComponentTestEntity.class, StrTestEntity.class, OneToManyComponent.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/UnspecifiedEnumTypeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/UnspecifiedEnumTypeTest.java index 97cc813613..534d604c77 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/UnspecifiedEnumTypeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/UnspecifiedEnumTypeTest.java @@ -14,6 +14,7 @@ import org.hibernate.envers.test.entities.customtype.UnspecifiedEnumTypeEntity; import org.junit.Assert; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; @@ -22,6 +23,7 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-7780") @RequiresDialect(value = H2Dialect.class) +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase { private Long id = null; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/ReadEntityWhitEntityNameTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/ReadEntityWhitEntityNameTest.java index 7dd5e33c4e..54ec10ac6c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/ReadEntityWhitEntityNameTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/ReadEntityWhitEntityNameTest.java @@ -8,12 +8,14 @@ import java.util.List; import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Hernán Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class ReadEntityWhitEntityNameTest extends AbstractOneSessionTest { private long id_pers1; @@ -36,6 +38,7 @@ public class ReadEntityWhitEntityNameTest extends AbstractOneSessionTest { @Test @Priority(10) + //@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public void initData() { initializeSession(); @@ -79,6 +82,7 @@ public class ReadEntityWhitEntityNameTest extends AbstractOneSessionTest { @Test + @FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public void testRetrieveRevisionsWithEntityName() { List pers1Revs = getAuditReader().getRevisions( Person.class, "Personaje", id_pers1 ); List pers2Revs = getAuditReader().getRevisions( Person.class, "Personaje", id_pers2 ); @@ -90,6 +94,7 @@ public class ReadEntityWhitEntityNameTest extends AbstractOneSessionTest { } @Test + @FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public void testRetrieveAuditedEntityWithEntityName() { person1_1 = getAuditReader().find( Person.class, "Personaje", id_pers1, 1 ); person1_2 = getAuditReader().find( Person.class, "Personaje", id_pers1, 2 ); @@ -102,6 +107,7 @@ public class ReadEntityWhitEntityNameTest extends AbstractOneSessionTest { } @Test + @FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public void testObtainEntityNameAuditedEntityWithEntityName() { person1_1 = getAuditReader().find( Person.class, "Personaje", id_pers1, 1 ); person1_2 = getAuditReader().find( Person.class, "Personaje", id_pers1, 2 ); @@ -121,6 +127,7 @@ public class ReadEntityWhitEntityNameTest extends AbstractOneSessionTest { } @Test + @FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public void testRetrieveAuditedEntityWithEntityNameWithNewSession() { // force a new session and AR diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java index d18900cfb4..ca530627ae 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java @@ -9,12 +9,14 @@ import java.util.List; import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Hernán Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class ReadEntityWithAuditedManyToManyTest extends AbstractOneSessionTest { private long id_car1; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java index f65fc0b464..4d10fa48a3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java @@ -9,12 +9,14 @@ import java.util.List; import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Hernán Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class ReadEntityWithAuditedCollectionTest extends AbstractOneSessionTest { private long id_car1; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java index bdc40336ab..c5417857cf 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java @@ -7,12 +7,14 @@ import java.net.URL; import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Hernán Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class ReadEntityAssociatedAuditedTest extends AbstractOneSessionTest { private long id_car1; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/SingleDomainObjectToMultipleTablesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/SingleDomainObjectToMultipleTablesTest.java index 2f7f8731a2..9004d2470f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/SingleDomainObjectToMultipleTablesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/SingleDomainObjectToMultipleTablesTest.java @@ -11,11 +11,13 @@ import org.hibernate.envers.test.Priority; import org.junit.Assert; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class SingleDomainObjectToMultipleTablesTest extends AbstractOneSessionTest { private long carId = 0; private long ownerId = 0; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java index 3fcb36bb83..63952ac912 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java @@ -7,12 +7,14 @@ import java.net.URL; import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Hernán Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class ReadEntityAssociatedNotAuditedTest extends AbstractOneSessionTest { private long id_car1; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java index 0f3d28d965..bfc6309f03 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java @@ -42,7 +42,7 @@ public class CompositeDateId extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {CompositeDateIdTestEntity.class}; + return new Class[] {CompositeDateIdTestEntity.class, DateEmbId.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java index fdedd4a2c0..42055b491f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java @@ -51,7 +51,13 @@ public class CompositeIds extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {EmbIdTestEntity.class, MulIdTestEntity.class, EmbIdWithCustomTypeTestEntity.class}; + return new Class[] { + EmbIdTestEntity.class, + MulIdTestEntity.class, + EmbIdWithCustomTypeTestEntity.class, + EmbId.class, + EmbIdWithCustomType.class + }; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/ManyToOneIdNotAudited.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/ManyToOneIdNotAudited.java index 9fb2e9b125..ef22d80f6c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/ManyToOneIdNotAudited.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/ManyToOneIdNotAudited.java @@ -22,7 +22,12 @@ public class ManyToOneIdNotAudited extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {ManyToOneIdNotAuditedTestEntity.class, UnversionedStrTestEntity.class, StrTestEntity.class}; + return new Class[] { + ManyToOneIdNotAuditedTestEntity.class, + UnversionedStrTestEntity.class, + StrTestEntity.class, + ManyToOneNotAuditedEmbId.class + }; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/RelationInsideEmbeddableTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/RelationInsideEmbeddableTest.java index cfc6c47c59..c56fb54e0c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/RelationInsideEmbeddableTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/RelationInsideEmbeddableTest.java @@ -9,12 +9,14 @@ import org.hibernate.envers.test.Priority; import org.junit.Assert; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-7690") +@FailureExpectedWithNewMetamodel( message = "Associations with non-envers entities not supported yet." ) public class RelationInsideEmbeddableTest extends BaseEnversJPAFunctionalTestCase { private Integer orderId = null; private ItemId itemId = null; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java index 2d96f5b568..b50a3aba03 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java @@ -30,7 +30,7 @@ import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.relational.Column; import org.junit.Assert; import org.junit.Test; @@ -101,11 +101,15 @@ public class ChildPrimaryKeyJoinAuditing extends BaseEnversJPAFunctionalTestCase public void testChildIdColumnName() { Assert.assertEquals( "other_id", - ((Column) getCfg() - .getClassMapping( + ( (Column) getMetadata() + .getEntityBinding( "org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin.ChildPrimaryKeyJoinEntity_AUD" ) - .getKey().getColumnIterator().next()).getName() + .getHierarchyDetails() + .getEntityIdentifier() + .getAttributeBinding() + .getValues() + .get( 0 ) ).getColumnName().getText() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java index 5b9354e76d..86ef3e96df 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java @@ -30,7 +30,8 @@ public class MixedInheritanceStrategiesEntityTest extends BaseEnversJPAFunctiona AbstractActivity.class, AbstractCheckActivity.class, CheckInActivity.class, - NormalActivity.class + NormalActivity.class, + ActivityId.class }; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/DiscriminatorFormulaTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/DiscriminatorFormulaTest.java index d471294988..99d998f825 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/DiscriminatorFormulaTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/DiscriminatorFormulaTest.java @@ -2,13 +2,14 @@ package org.hibernate.envers.test.integration.inheritance.single.discriminatorfo import javax.persistence.EntityManager; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Formula; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.binding.EntityDiscriminator; +import org.hibernate.metamodel.spi.relational.DerivedValue; +import org.hibernate.metamodel.spi.relational.Value; import org.junit.Assert; import org.junit.Test; @@ -17,7 +18,7 @@ import org.junit.Test; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class DiscriminatorFormulaTest extends BaseEnversJPAFunctionalTestCase { - private PersistentClass parentAudit = null; + private EntityBinding parentAudit = null; private ChildEntity childVer1 = null; private ChildEntity childVer2 = null; private ParentEntity parentVer1 = null; @@ -31,7 +32,7 @@ public class DiscriminatorFormulaTest extends BaseEnversJPAFunctionalTestCase { @Test @Priority(10) public void initData() { - parentAudit = getCfg().getClassMapping( + parentAudit = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.inheritance.single.discriminatorformula.ParentEntity_AUD" ); @@ -87,16 +88,10 @@ public class DiscriminatorFormulaTest extends BaseEnversJPAFunctionalTestCase { @Test public void testDiscriminatorFormulaInAuditTable() { - assert parentAudit.getDiscriminator().hasFormula(); - Iterator iterator = parentAudit.getDiscriminator().getColumnIterator(); - while ( iterator.hasNext() ) { - Object o = iterator.next(); - if ( o instanceof Formula ) { - Formula formula = (Formula) o; - Assert.assertEquals( ParentEntity.DISCRIMINATOR_QUERY, formula.getText() ); - return; - } - } + final EntityDiscriminator entityDiscriminator = parentAudit.getHierarchyDetails().getEntityDiscriminator(); + assert entityDiscriminator.getRelationalValue().getValueType() == Value.ValueType.DERIVED_VALUE; + DerivedValue derivedValue = (DerivedValue) entityDiscriminator.getRelationalValue(); + Assert.assertEquals( ParentEntity.DISCRIMINATOR_QUERY, derivedValue.getExpression() ); assert false; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/abstractparent/AuditedAbstractParentTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/abstractparent/AuditedAbstractParentTest.java index f6b95aedad..344cefa1e0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/abstractparent/AuditedAbstractParentTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/abstractparent/AuditedAbstractParentTest.java @@ -1,15 +1,16 @@ package org.hibernate.envers.test.integration.inheritance.tableperclass.abstractparent; import javax.persistence.EntityManager; -import java.util.Iterator; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Table; import org.junit.Assert; import org.junit.Test; +import org.hibernate.metamodel.spi.relational.Schema; +import org.hibernate.metamodel.spi.relational.Table; +import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.testing.TestForIssue; /** @@ -38,12 +39,12 @@ public class AuditedAbstractParentTest extends BaseEnversJPAFunctionalTestCase { @Test public void testAbstractTableExistence() { - Iterator tableIterator = getCfg().getTableMappings(); - while ( tableIterator.hasNext() ) { - Table table = tableIterator.next(); - if ( "AbstractEntity_AUD".equals( table.getName() ) ) { - Assert.assertFalse( table.isPhysicalTable() ); - return; + for ( Schema schema : getMetadata().getDatabase().getSchemas() ) { + for ( TableSpecification table : schema.getTables() ) { + if ( "AbstractEntity_AUD".equals( table.getLogicalName().getText() ) ) { + Assert.assertFalse( Table.class.isInstance( table ) ); + return; + } } } Assert.fail(); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java index f28e6032ad..c07ad1d858 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java @@ -39,7 +39,7 @@ public class InterfacesComponents extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {ComponentTestEntity.class}; + return new Class[] {ComponentTestEntity.class, Component1.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/joined/JoinedAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/joined/JoinedAllAuditedTest.java index 0242ecf0dd..9ca90dee20 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/joined/JoinedAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/joined/JoinedAllAuditedTest.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.allAudited.joined; import org.hibernate.envers.test.integration.interfaces.hbm.allAudited.AbstractAllAuditedTest; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class JoinedAllAuditedTest extends AbstractAllAuditedTest { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/subclass/SubclassAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/subclass/SubclassAllAuditedTest.java index 6cbb92252d..8fa57049b2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/subclass/SubclassAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/subclass/SubclassAllAuditedTest.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.allAudited.subclass; import org.hibernate.envers.test.integration.interfaces.hbm.allAudited.AbstractAllAuditedTest; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class SubclassAllAuditedTest extends AbstractAllAuditedTest { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/union/UnionAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/union/UnionAllAuditedTest.java index 033741a0d7..d8474336a8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/union/UnionAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/union/UnionAllAuditedTest.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.allAudited.union; import org.hibernate.envers.test.integration.interfaces.hbm.allAudited.AbstractAllAuditedTest; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class UnionAllAuditedTest extends AbstractAllAuditedTest { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/joined/JoinedPropertiesAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/joined/JoinedPropertiesAuditedTest.java index ee043e4e48..28a5baac51 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/joined/JoinedPropertiesAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/joined/JoinedPropertiesAuditedTest.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.joined; import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.AbstractPropertiesAuditedTest; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class JoinedPropertiesAuditedTest extends AbstractPropertiesAuditedTest { @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/subclass/SubclassPropertiesAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/subclass/SubclassPropertiesAuditedTest.java index 7caf878627..c3607594a0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/subclass/SubclassPropertiesAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/subclass/SubclassPropertiesAuditedTest.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.subclass; import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.AbstractPropertiesAuditedTest; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class SubclassPropertiesAuditedTest extends AbstractPropertiesAuditedTest { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/union/UnionPropertiesAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/union/UnionPropertiesAuditedTest.java index 1ec2f8b854..e0cfd87c00 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/union/UnionPropertiesAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/union/UnionPropertiesAuditedTest.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.union; import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.AbstractPropertiesAuditedTest; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class UnionPropertiesAuditedTest extends AbstractPropertiesAuditedTest { @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/joined/JoinedPropertiesAudited2Test.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/joined/JoinedPropertiesAudited2Test.java index 7f4acf5475..2a7d542909 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/joined/JoinedPropertiesAudited2Test.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/joined/JoinedPropertiesAudited2Test.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.joined; import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.AbstractPropertiesAudited2Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class JoinedPropertiesAudited2Test extends AbstractPropertiesAudited2Test { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/subclass/SubclassPropertiesAudited2Test.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/subclass/SubclassPropertiesAudited2Test.java index 1adce3c08e..feae6d2845 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/subclass/SubclassPropertiesAudited2Test.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/subclass/SubclassPropertiesAudited2Test.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.subclass; import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.AbstractPropertiesAudited2Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class SubclassPropertiesAudited2Test extends AbstractPropertiesAudited2Test { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/union/UnionPropertiesAudited2Test.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/union/UnionPropertiesAudited2Test.java index 01088eafb8..e44205848f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/union/UnionPropertiesAudited2Test.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/union/UnionPropertiesAudited2Test.java @@ -1,10 +1,12 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.union; import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.AbstractPropertiesAudited2Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class UnionPropertiesAudited2Test extends AbstractPropertiesAudited2Test { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/CustomComparatorEntityTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/CustomComparatorEntityTest.java index cc5bb26d36..de882a88b4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/CustomComparatorEntityTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/CustomComparatorEntityTest.java @@ -35,6 +35,7 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.StrTestEntityComparator; import org.hibernate.envers.test.entities.manytomany.SortedSetEntity; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -43,6 +44,7 @@ import static org.junit.Assert.assertEquals; /** * @author Michal Skowronek (mskowr at o2 pl) */ +@FailureExpectedWithNewMetamodel( message = "@MapKeyJoinColumn is not supported yet" ) public class CustomComparatorEntityTest extends BaseEnversJPAFunctionalTestCase { private Integer id1; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/ManyToManyInverseToSuperclassTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/ManyToManyInverseToSuperclassTest.java index 4a0f2a4f71..3266f53bf2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/ManyToManyInverseToSuperclassTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/ManyToManyInverseToSuperclassTest.java @@ -5,12 +5,14 @@ import java.util.ArrayList; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Hern�n Chanfreau */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class ManyToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTestCase { private long m1_id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMap.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMap.java index f527070643..6a620bfc84 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMap.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMap.java @@ -31,6 +31,7 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.IntTestPrivSeqEntity; import org.hibernate.envers.test.entities.StrTestPrivSeqEntity; import org.hibernate.envers.test.tools.TestTools; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Assert; import org.junit.Test; @@ -38,6 +39,8 @@ import org.junit.Test; /** * @author Adam Warski (adam at warski dot org) */ +@FailureExpectedWithNewMetamodel( message = "@MapKeyJoinColumn is not supported yet" ) + public class TernaryMap extends BaseEnversJPAFunctionalTestCase { private Integer str1_id; private Integer str2_id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapFlush.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapFlush.java index e072ec36b7..ace5289482 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapFlush.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapFlush.java @@ -32,6 +32,7 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.IntTestPrivSeqEntity; import org.hibernate.envers.test.entities.StrTestPrivSeqEntity; import org.hibernate.envers.test.tools.TestTools; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -40,6 +41,7 @@ import static org.junit.Assert.assertEquals; /** * @author Adam Warski (adam at warski dot org) */ +@FailureExpectedWithNewMetamodel( message = "@MapKeyJoinColumn is not supported yet" ) public class TernaryMapFlush extends BaseEnversJPAFunctionalTestCase { private Integer str1_id; private Integer str2_id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAuditedManyToManyTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAuditedManyToManyTest.java index 3df9dd68db..28dc476fbd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAuditedManyToManyTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAuditedManyToManyTest.java @@ -11,6 +11,7 @@ import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Car; import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Person; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -22,6 +23,7 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Hernán Chanfreau * @author Michal Skowronek (mskowr at o2 dot pl) */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class HasChangedAuditedManyToManyTest extends AbstractModifiedFlagsOneSessionTest { private long id_car1; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentCollection.java index 49db29119a..f701fef0ed 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentCollection.java @@ -30,7 +30,7 @@ public class HasChangedComponentCollection extends AbstractModifiedFlagsEntityTe @Override protected Class[] getAnnotatedClasses() { - return new Class[] {EmbeddableListEntity1.class}; + return new Class[] {EmbeddableListEntity1.class, Component3.class, Component4.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentMapKey.java index 54909f5ea0..bcb0a9a598 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentMapKey.java @@ -31,6 +31,7 @@ import org.hibernate.envers.test.entities.components.Component1; import org.hibernate.envers.test.entities.components.Component2; import org.hibernate.envers.test.entities.components.ComponentTestEntity; import org.hibernate.envers.test.integration.collection.mapkey.ComponentMapKeyEntity; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -42,6 +43,7 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Adam Warski (adam at warski dot org) * @author Michal Skowronek (mskowr at o2 dot pl) */ +@FailureExpectedWithNewMetamodel( message = "Plural attribute index that is an attribute of the referenced entity is not supported yet." ) public class HasChangedComponentMapKey extends AbstractModifiedFlagsEntityTest { private Integer cmke_id; @@ -50,7 +52,7 @@ public class HasChangedComponentMapKey extends AbstractModifiedFlagsEntityTest { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {ComponentMapKeyEntity.class, ComponentTestEntity.class}; + return new Class[] {ComponentMapKeyEntity.class, ComponentTestEntity.class, Component1.class, Component2.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponents.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponents.java index f39023c8cb..b44da52d07 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponents.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponents.java @@ -51,7 +51,7 @@ public class HasChangedComponents extends AbstractModifiedFlagsEntityTest { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {ComponentTestEntity.class}; + return new Class[] {ComponentTestEntity.class, Component1.class, Component2.class}; } @Test @@ -139,7 +139,7 @@ public class HasChangedComponents extends AbstractModifiedFlagsEntityTest { assertEquals( TestTools.makeSet( "comp1_MOD" ), TestTools.extractModProperties( - getCfg().getClassMapping( + getMetadata().getEntityBinding( "org.hibernate.envers.test.entities.components.ComponentTestEntity_AUD" ) ) diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedForDefaultNotUsing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedForDefaultNotUsing.java index ce28305313..4da889c648 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedForDefaultNotUsing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedForDefaultNotUsing.java @@ -58,7 +58,9 @@ public class HasChangedForDefaultNotUsing extends AbstractModifiedFlagsEntityTes return new Class[] { PartialModifiedFlagsEntity.class, WithModifiedFlagReferencingEntity.class, - StrTestEntity.class + StrTestEntity.class, + Component1.class, + Component2.class }; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedIdMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedIdMapKey.java index 1b8837dc7c..3ba1acf23f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedIdMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedIdMapKey.java @@ -29,6 +29,7 @@ import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.integration.collection.mapkey.IdMapKeyEntity; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -40,6 +41,7 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Adam Warski (adam at warski dot org) * @author Michal Skowronek (mskowr at o2 dot pl) */ +@FailureExpectedWithNewMetamodel( message = "Plural attribute index that is an attribute of the referenced entity is not supported yet." ) public class HasChangedIdMapKey extends AbstractModifiedFlagsEntityTest { private Integer imke_id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManyToOneInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManyToOneInComponent.java index 1a771185f9..3f491792a2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManyToOneInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManyToOneInComponent.java @@ -46,7 +46,7 @@ public class HasChangedManyToOneInComponent extends AbstractModifiedFlagsEntityT @Override protected Class[] getAnnotatedClasses() { - return new Class[] {ManyToOneComponentTestEntity.class, StrTestEntity.class}; + return new Class[] {ManyToOneComponentTestEntity.class, StrTestEntity.class, ManyToOneComponent.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedOneToManyInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedOneToManyInComponent.java index e6453884f2..77bf357418 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedOneToManyInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedOneToManyInComponent.java @@ -30,6 +30,7 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.components.relations.OneToManyComponent; import org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity; +import org.hibernate.envers.test.integration.naming.VersionsJoinTableRangeComponent; import org.junit.Test; @@ -46,7 +47,12 @@ public class HasChangedOneToManyInComponent extends AbstractModifiedFlagsEntityT @Override protected Class[] getAnnotatedClasses() { - return new Class[] {OneToManyComponentTestEntity.class, StrTestEntity.class}; + return new Class[] { + OneToManyComponentTestEntity.class, + StrTestEntity.class, + OneToManyComponent.class, + VersionsJoinTableRangeComponent.class + }; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/ModifiedFlagSuffix.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/ModifiedFlagSuffix.java index a88b79d180..938ba319a9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/ModifiedFlagSuffix.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/ModifiedFlagSuffix.java @@ -78,7 +78,7 @@ public class ModifiedFlagSuffix extends AbstractModifiedFlagsEntityTest { assertEquals( TestTools.makeSet( "str1_CHANGED", "long1_CHANGED" ), TestTools.extractModProperties( - getCfg().getClassMapping( + getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.basic.BasicTestEntity1_AUD" ), "_CHANGED" diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/PartialModifiedFlagsEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/PartialModifiedFlagsEntity.java index 76e22e31b6..2f22ba23a2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/PartialModifiedFlagsEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/PartialModifiedFlagsEntity.java @@ -75,25 +75,25 @@ public class PartialModifiedFlagsEntity { @Audited(withModifiedFlag = true) @ElementCollection - @JoinTable(name = "PartialModFlags_StrSet") + @CollectionTable(name = "PartialModFlags_StrSet") @AuditJoinTable(name = "PartialModFlags_StrSet_AUD") private Set stringSet = new HashSet(); @Audited(withModifiedFlag = true) @ManyToMany - @CollectionTable(name = "ENTITIESSET") + @JoinTable(name = "ENTITIESSET") private Set entitiesSet = new HashSet(); @Audited(withModifiedFlag = true) @ElementCollection @MapKeyColumn(nullable = false) - @JoinTable(name = "PartialModFlags_StrMap") + @CollectionTable(name = "PartialModFlags_StrMap") @AuditJoinTable(name = "PartialModFlags_StrMap_AUD") private Map stringMap = new HashMap(); @Audited(withModifiedFlag = true) @ManyToMany - @CollectionTable(name = "ENTITIESMAP") + @JoinTable(name = "ENTITIESMAP") @MapKeyColumn(nullable = false) private Map entitiesMap = new HashMap(); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/BasicNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/BasicNaming.java index 99711705d3..ac2c42d277 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/BasicNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/BasicNaming.java @@ -110,8 +110,8 @@ public class BasicNaming extends BaseEnversJPAFunctionalTestCase { @Test public void testTableName() { assert "naming_test_entity_1_versions".equals( - getCfg().getClassMapping( "org.hibernate.envers.test.integration.naming.NamingTestEntity1_AUD" ) - .getTable().getName() + getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.naming.NamingTestEntity1_AUD" ) + .getPrimaryTableName() ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java index 166635d22c..3a154242df 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java @@ -25,16 +25,16 @@ package org.hibernate.envers.test.integration.naming; import javax.persistence.EntityManager; import java.util.Arrays; -import java.util.Iterator; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.relational.Column; import org.junit.Test; import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; /** @@ -128,11 +128,17 @@ public class JoinNaming extends BaseEnversJPAFunctionalTestCase { @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnName() { - Iterator columns = - getCfg().getClassMapping( "org.hibernate.envers.test.integration.naming.JoinNamingRefIngEntity_AUD" ) - .getProperty( "reference_id" ).getColumnIterator(); - assertTrue( columns.hasNext() ); - assertEquals( "jnree_column_reference", columns.next().getName() ); - assertFalse( columns.hasNext() ); + final AttributeBinding attributeBinding = getMetadata().getEntityBinding( + "org.hibernate.envers.test.integration.naming.JoinNamingRefIngEntity_AUD" + ).locateAttributeBinding( "reference_id" ); + assertTrue( attributeBinding.getAttribute().isSingular() ); + final SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding; + assertTrue( !singularAttributeBinding.getValues().isEmpty() ); + + assertEquals( + "jnree_column_reference", + ( (Column) singularAttributeBinding.getValues().get( 0 ) ).getColumnName().getText() + ); + assertEquals( singularAttributeBinding.getValues().size(), 1 ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/OneToManyUnidirectionalNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/OneToManyUnidirectionalNaming.java index cb52a4abbf..9de6eee67e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/OneToManyUnidirectionalNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/OneToManyUnidirectionalNaming.java @@ -26,13 +26,14 @@ package org.hibernate.envers.test.integration.naming; import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import java.util.Iterator; +import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.Value; import org.junit.Test; @@ -104,26 +105,25 @@ public class OneToManyUnidirectionalNaming extends BaseEnversJPAFunctionalTestCa @Test public void testTableName() { assert MIDDLE_VERSIONS_ENTITY_NAME.equals( - getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getName() + getMetadata().getEntityBinding( MIDDLE_VERSIONS_ENTITY_NAME ).getPrimaryTableName() ); } @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnName() { - Iterator columns = - getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getColumnIterator(); boolean id1Found = false; boolean id2Found = false; - while ( columns.hasNext() ) { - Column column = columns.next(); - if ( "ID_1".equals( column.getName() ) ) { + final List values = getMetadata().getEntityBinding( MIDDLE_VERSIONS_ENTITY_NAME ).getPrimaryTable().values(); + for ( Value value : values ) { + Column column = (Column) value; + if ( "ID_1".equals( column.getColumnName().getText() ) ) { id1Found = true; } - if ( "ID_2".equals( column.getName() ) ) { + if ( "ID_2".equals( column.getColumnName().getText() ) ) { id2Found = true; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableNaming.java index 70d410d043..8d6bbdd80a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableNaming.java @@ -26,13 +26,14 @@ package org.hibernate.envers.test.integration.naming; import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import java.util.Iterator; +import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.Value; import org.junit.Test; @@ -109,26 +110,26 @@ public class VersionsJoinTableNaming extends BaseEnversJPAFunctionalTestCase { @Test public void testTableName() { assert MIDDLE_VERSIONS_ENTITY_NAME.equals( - getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getName() + getMetadata().getEntityBinding( MIDDLE_VERSIONS_ENTITY_NAME ).getPrimaryTableName() ); } @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnName() { - Iterator columns = - getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getColumnIterator(); + List values = + getMetadata().getEntityBinding( MIDDLE_VERSIONS_ENTITY_NAME ).getPrimaryTable().values(); boolean id1Found = false; boolean id2Found = false; - while ( columns.hasNext() ) { - Column column = columns.next(); - if ( "VJT_ID".equals( column.getName() ) ) { + for ( Value value : values ) { + Column column = (Column) value; + if ( "VJT_ID".equals( column.getColumnName().getText() ) ) { id1Found = true; } - if ( "STR_ID".equals( column.getName() ) ) { + if ( "STR_ID".equals( column.getColumnName().getText() ) ) { id2Found = true; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponent.java index a1d0641ab9..7f07fe3ead 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponent.java @@ -21,9 +21,8 @@ import org.hibernate.annotations.FetchMode; @Embeddable public final class VersionsJoinTableRangeComponent { - @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) @org.hibernate.annotations.Fetch(value = FetchMode.SUBSELECT) - @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) @JoinColumn(name = "VJTRCTE_ID", insertable = true, updatable = false, nullable = false) // Note: If this is processed without override annotation, then we should get a // org.hibernate.DuplicateMappingException: diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponentNamingTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponentNamingTest.java index 03303fa215..2c1b8278eb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponentNamingTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponentNamingTest.java @@ -31,8 +31,9 @@ import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.components.Component1; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.Value; import org.junit.Test; @@ -54,7 +55,9 @@ public class VersionsJoinTableRangeComponentNamingTest extends VersionsJoinTableRangeComponentTestEntity.class, VersionsJoinTableRangeTestEntitySuperClass.class, VersionsJoinTableRangeTestEntity.class, - VersionsJoinTableRangeTestAlternateEntity.class + VersionsJoinTableRangeTestAlternateEntity.class, + VersionsJoinTableRangeComponent.class, + Component1.class }; } @@ -198,31 +201,29 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testExpectedTableNameComponent1() { - PersistentClass auditClass = getCfg().getClassMapping( + EntityBinding auditClass = getMetadata().getEntityBinding( COMPONENT_1_AUDIT_JOIN_TABLE_NAME ); assert auditClass != null; assert COMPONENT_1_AUDIT_JOIN_TABLE_NAME.equals( - auditClass.getTable() - .getName() + auditClass.getPrimaryTableName() ); } @Test public void testExpectedTableNameComponent2() { - PersistentClass auditClass = getCfg().getClassMapping( + EntityBinding auditClass = getMetadata().getEntityBinding( COMPONENT_2_AUDIT_JOIN_TABLE_NAME ); assert auditClass != null; assert COMPONENT_2_AUDIT_JOIN_TABLE_NAME.equals( - auditClass.getTable() - .getName() + auditClass.getPrimaryTableName() ); } @Test public void testWrongTableNameComponent1() { - PersistentClass auditClass = getCfg().getClassMapping( + EntityBinding auditClass = getMetadata().getEntityBinding( UNMODIFIED_COMPONENT_1_AUDIT_JOIN_TABLE_NAME ); assert auditClass == null; @@ -230,7 +231,7 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testWrongTableNameComponent2() { - PersistentClass auditClass = getCfg().getClassMapping( + EntityBinding auditClass = getMetadata().getEntityBinding( UNMODIFIED_COMPONENT_2_AUDIT_JOIN_TABLE_NAME ); assert auditClass == null; @@ -238,24 +239,22 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testJoinColumnNamesComponent1() { - PersistentClass auditClass = getCfg().getClassMapping( + EntityBinding auditClass = getMetadata().getEntityBinding( COMPONENT_1_AUDIT_JOIN_TABLE_NAME ); assert auditClass != null; - @SuppressWarnings({"unchecked"}) - Iterator columns = auditClass.getTable().getColumnIterator(); - boolean id1Found = false; boolean id2Found = false; - while ( columns.hasNext() ) { - Column column = columns.next(); - if ( "VJTRCTE1_ID".equals( column.getName() ) ) { + List values = auditClass.getPrimaryTable().values(); + for ( Value value : values ) { + Column column = (Column) value; + if ( "VJTRCTE1_ID".equals( column.getColumnName().getText() ) ) { id1Found = true; } - if ( "VJTRTE_ID".equals( column.getName() ) ) { + if ( "VJTRTE_ID".equals( column.getColumnName().getText() ) ) { id2Found = true; } } @@ -265,24 +264,22 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testJoinColumnNamesComponent2() { - PersistentClass auditClass = getCfg().getClassMapping( + EntityBinding auditClass = getMetadata().getEntityBinding( COMPONENT_2_AUDIT_JOIN_TABLE_NAME ); assert auditClass != null; - @SuppressWarnings({"unchecked"}) - Iterator columns = auditClass.getTable().getColumnIterator(); - boolean id1Found = false; boolean id2Found = false; - while ( columns.hasNext() ) { - Column column = columns.next(); - if ( "VJTRCTE2_ID".equals( column.getName() ) ) { + List values = auditClass.getPrimaryTable().values(); + for ( Value value : values ) { + Column column = (Column) value; + if ( "VJTRCTE2_ID".equals( column.getColumnName().getText() ) ) { id1Found = true; } - if ( "VJTRTAE_ID".equals( column.getName() ) ) { + if ( "VJTRTAE_ID".equals( column.getColumnName().getText() ) ) { id2Found = true; } } @@ -297,25 +294,23 @@ public class VersionsJoinTableRangeComponentNamingTest extends */ @Test public void testOverrideNotAudited() { - PersistentClass auditClass = getCfg().getClassMapping( + EntityBinding auditClass = getMetadata().getEntityBinding( VersionsJoinTableRangeComponentTestEntity.class.getName() + "_AUD" ); assert auditClass != null; - @SuppressWarnings({"unchecked"}) - Iterator columns = auditClass.getTable().getColumnIterator(); - boolean auditColumn1Found = false; boolean auditColumn2Found = false; - while ( columns.hasNext() ) { - Column column = columns.next(); - if ( "STR1".equals( column.getName() ) ) { + List values = auditClass.getPrimaryTable().values(); + for ( Value value : values ) { + Column column = (Column) value; + if ( "STR1".equals( column.getColumnName().getText() ) ) { auditColumn1Found = true; } - if ( "STR2".equals( column.getName() ) ) { + if ( "STR2".equals( column.getColumnName().getText() ) ) { auditColumn2Found = true; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java index cbb4ac50c8..aaa4fec491 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java @@ -25,21 +25,24 @@ package org.hibernate.envers.test.integration.naming.ids; import javax.persistence.EntityManager; import java.util.Arrays; -import java.util.Iterator; +import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.Value; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; /** * @author Adam Warski (adam at warski dot org) */ +@FailureExpectedWithNewMetamodel( message = " No support yet for referenced join columns unless they correspond with columns bound for an attribute binding." ) public class JoinEmbIdNaming extends BaseEnversJPAFunctionalTestCase { private EmbIdNaming ed_id1; private EmbIdNaming ed_id2; @@ -141,22 +144,23 @@ public class JoinEmbIdNaming extends BaseEnversJPAFunctionalTestCase { @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnNames() { - Iterator columns = - getCfg().getClassMapping( + SingularAttributeBinding attributeBinding = (SingularAttributeBinding) + getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD" - ) - .getProperty( "reference_x" ).getColumnIterator(); - assertTrue( columns.hasNext() ); - assertEquals( "XX_reference", columns.next().getName() ); - assertFalse( columns.hasNext() ); + ).locateAttributeBinding( "reference_x" ); + List values = attributeBinding.getValues(); + assertTrue( !values.isEmpty() ); + assertEquals( "XX_reference", ( (Column) values.get( 0 ) ).getColumnName().getText() ); + assertEquals( 1, values.size() ); - columns = getCfg().getClassMapping( - "org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD" - ) - .getProperty( "reference_y" ).getColumnIterator(); + attributeBinding = (SingularAttributeBinding) + getMetadata().getEntityBinding( + "org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD" + ).locateAttributeBinding( "reference_y" ); + values = attributeBinding.getValues(); - assertTrue( columns.hasNext() ); - assertEquals( "YY_reference", columns.next().getName() ); - assertFalse( columns.hasNext() ); + assertTrue( !values.isEmpty() ); + assertEquals( "YY_reference", ( (Column) values.get( 0 ) ).getColumnName().getText() ); + assertEquals( 1, values.size() ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java index 9d3a050172..097560ef31 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java @@ -25,11 +25,14 @@ package org.hibernate.envers.test.integration.naming.ids; import javax.persistence.EntityManager; import java.util.Arrays; -import java.util.Iterator; +import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.Value; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -40,6 +43,8 @@ import static junit.framework.Assert.assertTrue; /** * @author Adam Warski (adam at warski dot org) */ +@FailureExpectedWithNewMetamodel( message = " No support yet for referenced join columns unless they correspond with columns bound for an attribute binding." ) + public class JoinMulIdNaming extends BaseEnversJPAFunctionalTestCase { private MulIdNaming ed_id1; private MulIdNaming ed_id2; @@ -141,21 +146,20 @@ public class JoinMulIdNaming extends BaseEnversJPAFunctionalTestCase { @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnNames() { - Iterator columns = - getCfg().getClassMapping( - "org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD" - ) - .getProperty( "reference_id1" ).getColumnIterator(); - assertTrue( columns.hasNext() ); - assertEquals( "ID1_reference", columns.next().getName() ); - assertFalse( columns.hasNext() ); - - columns = getCfg().getClassMapping( + SingularAttributeBinding attributeBinding = (SingularAttributeBinding) getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD" - ) - .getProperty( "reference_id2" ).getColumnIterator(); - assertTrue( columns.hasNext() ); - assertEquals( "ID2_reference", columns.next().getName() ); - assertFalse( columns.hasNext() ); + ).locateAttributeBinding( "reference_id1" ); + List values = attributeBinding.getValues(); + assertTrue( !values.isEmpty() ); + assertEquals( "ID1_reference", ( (Column) values.get( 0 ) ).getColumnName().getText() ); + assertEquals( 1, values.size() ); + + attributeBinding = (SingularAttributeBinding) getMetadata().getEntityBinding( + "org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD" + ).locateAttributeBinding( "reference_id2" ); + values = attributeBinding.getValues(); + assertTrue( !values.isEmpty() ); + assertEquals( "ID2_reference", ( (Column) values.get( 0 ) ).getColumnName().getText() ); + assertEquals( 1, values.size() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java index 8ba87cdf0c..2b9c7ee4d6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java @@ -2,12 +2,11 @@ package org.hibernate.envers.test.integration.naming.quotation; import javax.persistence.EntityManager; import java.util.Arrays; -import java.util.Iterator; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.TableSpecification; import org.junit.Test; @@ -80,28 +79,17 @@ public class QuotedFieldsTest extends BaseEnversJPAFunctionalTestCase { @Test public void testEscapeEntityField() { - Table table = getCfg().getClassMapping( + TableSpecification table = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.naming.quotation.QuotedFieldsEntity_AUD" - ).getTable(); - Column column1 = getColumnByName( table, "id" ); - Column column2 = getColumnByName( table, "data1" ); - Column column3 = getColumnByName( table, "data2" ); + ).getPrimaryTable(); + Column column1 = table.locateColumn( "id" ); + Column column2 = table.locateColumn( "data1" ); + Column column3 = table.locateColumn( "data2" ); assert column1 != null; assert column2 != null; assert column3 != null; - assert column1.isQuoted(); - assert column2.isQuoted(); - assert column3.isQuoted(); - } - - private Column getColumnByName(Table table, String columnName) { - Iterator columnIterator = table.getColumnIterator(); - while ( columnIterator.hasNext() ) { - Column column = columnIterator.next(); - if ( columnName.equals( column.getName() ) ) { - return column; - } - } - return null; + assert column1.getColumnName().isQuoted(); + assert column2.getColumnName().isQuoted(); + assert column3.getColumnName().isQuoted(); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithEmbId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithEmbId.java index af713707f4..06f283605e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithEmbId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithEmbId.java @@ -49,7 +49,7 @@ public class BasicSetWithEmbId extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class}; + return new Class[] {SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class, EmbId.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BidirectionalMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BidirectionalMapKey.java index 494c4cc0ed..47ad32ec49 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BidirectionalMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BidirectionalMapKey.java @@ -29,12 +29,14 @@ import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Adam Warski (adam at warski dot org) */ +@FailureExpectedWithNewMetamodel( message = "Plural attribute index that is an attribute of the referenced entity is not supported yet" ) public class BidirectionalMapKey extends BaseEnversJPAFunctionalTestCase { private Integer ed_id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithEmbId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithEmbId.java index 2b3e9bad8a..852a75741c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithEmbId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithEmbId.java @@ -47,7 +47,7 @@ public class BasicDetachedSetWithEmbId extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {EmbIdTestEntity.class, SetRefCollEntityEmbId.class}; + return new Class[] {EmbIdTestEntity.class, SetRefCollEntityEmbId.class, EmbId.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/OneToManyInverseToSuperclassTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/OneToManyInverseToSuperclassTest.java index 68daa68379..68d8673b40 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/OneToManyInverseToSuperclassTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/OneToManyInverseToSuperclassTest.java @@ -5,13 +5,14 @@ import java.util.ArrayList; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Hern�n Chanfreau */ - +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTestCase { private long m1_id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerHbmTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerHbmTest.java index 1b5d29d381..7f9b8c12a4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerHbmTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerHbmTest.java @@ -32,6 +32,7 @@ import org.hibernate.envers.test.entities.onetoone.BidirectionalEagerHbmRefIngPK import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertNotNull; @@ -40,6 +41,7 @@ import static org.junit.Assert.assertNotNull; * @author Erik-Berndt Scheper, Amar Singh */ @TestForIssue(jiraKey = "HHH-3854") +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class BidirectionalEagerHbmTest extends BaseEnversJPAFunctionalTestCase { private Long refIngId1 = null; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/EmbIdBidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/EmbIdBidirectional.java index b713c87056..abd622e7ed 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/EmbIdBidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/EmbIdBidirectional.java @@ -43,7 +43,7 @@ public class EmbIdBidirectional extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {BiEmbIdRefEdEntity.class, BiEmbIdRefIngEntity.class}; + return new Class[] {BiEmbIdRefEdEntity.class, BiEmbIdRefIngEntity.class, EmbId.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalMulIdWithNulls.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalMulIdWithNulls.java index 8d6bb63ca8..d1b14b45e2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalMulIdWithNulls.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalMulIdWithNulls.java @@ -21,7 +21,7 @@ public class UnidirectionalMulIdWithNulls extends BaseEnversJPAFunctionalTestCas @Override protected Class[] getAnnotatedClasses() { - return new Class[] {EmbIdTestEntity.class, UniRefIngMulIdEntity.class}; + return new Class[] {EmbIdTestEntity.class, UniRefIngMulIdEntity.class, EmbId.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingField.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingField.java index 655d1f2dc0..3f2c59f5e5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingField.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingField.java @@ -31,8 +31,7 @@ import java.util.Map; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; +import org.hibernate.metamodel.spi.binding.EntityBinding; import org.junit.Test; @@ -92,11 +91,7 @@ public class UnversionedOptimisticLockingField extends BaseEnversJPAFunctionalTe @Test public void testMapping() { - PersistentClass pc = getCfg().getClassMapping( UnversionedOptimisticLockingFieldEntity.class.getName() + "_AUD" ); - Iterator pi = pc.getPropertyIterator(); - while ( pi.hasNext() ) { - Property p = (Property) pi.next(); - assert !"optLocking".equals( p.getName() ); - } + EntityBinding entityBinding = getMetadata().getEntityBinding( UnversionedOptimisticLockingFieldEntity.class.getName() + "_AUD" ); + assert entityBinding.locateAttributeBinding( "optLocking" ) == null; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java index a8b43fe9e5..97cedf0b40 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java @@ -38,11 +38,13 @@ import org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAudi import org.hibernate.envers.test.entities.onetomany.OneToManyNotAuditedNullEntity; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Eugene Goroschenya */ +@FailureExpectedWithNewMetamodel( message = "@NotFound(action = NotFoundAction.IGNORE) not supported yet." ) public class ProxyIdentifier extends BaseEnversJPAFunctionalTestCase { private TargetNotAuditedEntity tnae1 = null; private ManyToOneNotAuditedNullEntity mtonane1 = null; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/RemovedObjectQueryTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/RemovedObjectQueryTest.java index 3f862afae9..c4ad36919e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/RemovedObjectQueryTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/RemovedObjectQueryTest.java @@ -33,12 +33,14 @@ import org.hibernate.envers.test.tools.TestTools; import org.junit.Assert; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-5845") +@FailureExpectedWithNewMetamodel( message = "@MapKeyJoinColumn is not supported yet" ) public class RemovedObjectQueryTest extends BaseEnversJPAFunctionalTestCase { private Integer stringSetId = null; private Integer ternaryMapId = null; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/NullPropertyQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/NullPropertyQuery.java index 1e146e7b47..d0a3de6b52 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/NullPropertyQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/NullPropertyQuery.java @@ -31,7 +31,8 @@ public class NullPropertyQuery extends BaseEnversJPAFunctionalTestCase { SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class, CollectionRefEdEntity.class, - CollectionRefIngEntity.class + CollectionRefIngEntity.class, + EmbId.class }; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java index f2dd4ff812..030d65a1ea 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java @@ -59,7 +59,7 @@ public class SimpleQuery extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrIntTestEntity.class, MulIdTestEntity.class, EmbIdTestEntity.class }; + return new Class[] { StrIntTestEntity.class, MulIdTestEntity.class, EmbIdTestEntity.class, EmbId.class }; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java index 2e53bf689f..0a2f317109 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java @@ -51,7 +51,7 @@ public class EmbIdOneToManyQuery extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class}; + return new Class[] {SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class, EmbId.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/DifferentDBSchemaTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/DifferentDBSchemaTest.java index 96b90a80d1..d5c2882d64 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/DifferentDBSchemaTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/DifferentDBSchemaTest.java @@ -10,10 +10,10 @@ import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; -import org.hibernate.mapping.Table; import org.junit.Test; +import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.testing.RequiresDialect; /** @@ -65,9 +65,9 @@ public class DifferentDBSchemaTest extends BaseEnversJPAFunctionalTestCase { @Test public void testRevinfoSchemaName() { - Table revisionTable = getCfg().getClassMapping( "org.hibernate.envers.enhanced.SequenceIdRevisionEntity" ) - .getTable(); - assert SCHEMA_NAME.equals( revisionTable.getSchema() ); + TableSpecification revisionTable = getMetadata().getEntityBinding( "org.hibernate.envers.enhanced.SequenceIdRevisionEntity" ) + .getPrimaryTable(); + assert SCHEMA_NAME.equals( revisionTable.getSchema().getName().getSchema().getText() ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java index c73030cd11..3970f481a8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java @@ -29,7 +29,7 @@ import java.util.Iterator; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.integration.inheritance.joined.ChildEntity; import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.relational.Value; import org.junit.Test; @@ -50,13 +50,12 @@ public class LongRevEntityInheritanceChildAuditing extends BaseEnversJPAFunction @Test public void testChildRevColumnType() { // We need the second column - Iterator childEntityKeyColumnsIterator = getCfg() - .getClassMapping( "org.hibernate.envers.test.integration.inheritance.joined.ChildEntity_AUD" ) - .getKey() - .getColumnIterator(); + Iterator childEntityKeyColumnsIterator = getMetadata() + .getEntityBinding( "org.hibernate.envers.test.integration.inheritance.joined.ChildEntity_AUD" ) + .getHierarchyDetails().getEntityIdentifier().getAttributeBinding().getValues().iterator(); childEntityKeyColumnsIterator.next(); - Column second = (Column) childEntityKeyColumnsIterator.next(); + Value second = (Value) childEntityKeyColumnsIterator.next(); - assertEquals( second.getSqlType(), "int" ); + assertEquals( second.getJdbcDataType().getTypeName(), "int" ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java index 4f73a6699f..0833c8e96f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java @@ -1,7 +1,6 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; import javax.persistence.EntityManager; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -14,8 +13,8 @@ import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; import org.hibernate.envers.tools.Pair; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; +import org.hibernate.metamodel.spi.relational.Schema; +import org.hibernate.metamodel.spi.relational.TableSpecification; import org.junit.Test; @@ -73,14 +72,14 @@ public class DefaultTrackingEntitiesTest extends BaseEnversJPAFunctionalTestCase @Test public void testRevEntityTableCreation() { - Iterator
tableIterator = getCfg().getTableMappings(); - while ( tableIterator.hasNext() ) { - Table table = tableIterator.next(); - if ( "REVCHANGES".equals( table.getName() ) ) { - assert table.getColumnSpan() == 2; - assert table.getColumn( new Column( "REV" ) ) != null; - assert table.getColumn( new Column( "ENTITYNAME" ) ) != null; - return; + for ( Schema schema : getMetadata().getDatabase().getSchemas() ) { + for ( TableSpecification table : schema.getTables() ) { + if ( "REVCHANGES".equals( table.getLogicalName().getText() ) ) { + assert table.values().size() == 2; + assert table.locateColumn( "REV" ) != null; + assert table.locateColumn( "ENTITYNAME" ) != null; + return; + } } } assert false; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java index 703fe1b19f..fd38e08386 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java @@ -11,12 +11,14 @@ import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Car; import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Person; import org.hibernate.envers.test.tools.TestTools; import org.hibernate.envers.tools.Pair; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ +@FailureExpectedWithNewMetamodel( message = "hbm.xml source not supported because it is not indexed." ) public class EntityNamesTest extends BaseEnversFunctionalTestCase { @Override protected String[] getMappings() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/BasicSecondary.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/BasicSecondary.java index f09bf20823..f9440e4b7c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/BasicSecondary.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/BasicSecondary.java @@ -29,7 +29,8 @@ import java.util.Iterator; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Join; +import org.hibernate.metamodel.spi.binding.SecondaryTable; +import org.hibernate.metamodel.spi.relational.Identifier; import org.junit.Test; @@ -89,12 +90,11 @@ public class BasicSecondary extends BaseEnversJPAFunctionalTestCase { @Test public void testTableNames() { assert "secondary_AUD".equals( - ((Iterator) - getCfg().getClassMapping( + getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.SecondaryTestEntity_AUD" ) - .getJoinIterator()) - .next().getTable().getName() + .getSecondaryTables().values().iterator().next() + .getSecondaryTableReference().getLogicalName().getText() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/NamingSecondary.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/NamingSecondary.java index 34122b1a8f..43c5b55937 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/NamingSecondary.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/NamingSecondary.java @@ -25,11 +25,9 @@ package org.hibernate.envers.test.integration.secondary; import javax.persistence.EntityManager; import java.util.Arrays; -import java.util.Iterator; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Join; import org.junit.Test; @@ -89,12 +87,10 @@ public class NamingSecondary extends BaseEnversJPAFunctionalTestCase { @Test public void testTableNames() { assert "sec_versions".equals( - ((Iterator) - getCfg().getClassMapping( + getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.SecondaryNamingTestEntity_AUD" ) - .getJoinIterator()) - .next().getTable().getName() + .getSecondaryTables().keySet().iterator().next().getText() ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/EmbIdSecondary.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/EmbIdSecondary.java index add9e2dba7..91da2adbfb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/EmbIdSecondary.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/EmbIdSecondary.java @@ -25,12 +25,10 @@ package org.hibernate.envers.test.integration.secondary.ids; import javax.persistence.EntityManager; import java.util.Arrays; -import java.util.Iterator; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.ids.EmbId; -import org.hibernate.mapping.Join; import org.junit.Test; @@ -88,12 +86,10 @@ public class EmbIdSecondary extends BaseEnversJPAFunctionalTestCase { @Test public void testTableNames() { assert "sec_embid_versions".equals( - ((Iterator) - getCfg().getClassMapping( + getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.ids.SecondaryEmbIdTestEntity_AUD" ) - .getJoinIterator()) - .next().getTable().getName() + .getSecondaryTables().keySet().iterator().next().getText() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/MulIdSecondary.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/MulIdSecondary.java index 897eb03149..2ac4775680 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/MulIdSecondary.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/MulIdSecondary.java @@ -88,12 +88,10 @@ public class MulIdSecondary extends BaseEnversJPAFunctionalTestCase { @Test public void testTableNames() { assert "sec_mulid_versions".equals( - ((Iterator) - getCfg().getClassMapping( + getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.ids.SecondaryMulIdTestEntity_AUD" ) - .getJoinIterator()) - .next().getTable().getName() + .getSecondaryTables().keySet().iterator().next().getText() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java index 2d9a2cb159..fc00544f29 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java @@ -4,23 +4,24 @@ import javax.persistence.EntityManager; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; import org.junit.Assert; import org.junit.Test; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-4439") +@FailureExpectedWithNewMetamodel( message = "Audit overrides on MappedSuperclasses not supported yet." ) public class AuditClassOverrideTest extends BaseEnversJPAFunctionalTestCase { private Integer classAuditedEntityId = null; private Integer classNotAuditedEntityId = null; - private Table classAuditedTable = null; - private Table classNotAuditedTable = null; + private TableSpecification classAuditedTable = null; + private TableSpecification classNotAuditedTable = null; @Override protected Class[] getAnnotatedClasses() { @@ -50,26 +51,26 @@ public class AuditClassOverrideTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().commit(); classNotAuditedEntityId = classOverrideNotAuditedEntity.getId(); - classAuditedTable = getCfg().getClassMapping( + classAuditedTable = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideAuditedEntity_AUD" - ).getTable(); - classNotAuditedTable = getCfg().getClassMapping( + ).getPrimaryTable(); + classNotAuditedTable = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideNotAuditedEntity_AUD" - ).getTable(); + ).getPrimaryTable(); } @Test public void testAuditedProperty() { - Assert.assertNotNull( classAuditedTable.getColumn( new Column( "number1" ) ) ); - Assert.assertNotNull( classAuditedTable.getColumn( new Column( "str1" ) ) ); - Assert.assertNotNull( classAuditedTable.getColumn( new Column( "str2" ) ) ); - Assert.assertNotNull( classNotAuditedTable.getColumn( new Column( "str2" ) ) ); + Assert.assertNotNull( classAuditedTable.locateColumn( "number1" ) ); + Assert.assertNotNull( classAuditedTable.locateColumn( "str1" ) ); + Assert.assertNotNull( classAuditedTable.locateColumn( "str2" ) ); + Assert.assertNotNull( classNotAuditedTable.locateColumn( "str2" ) ); } @Test public void testNotAuditedProperty() { - Assert.assertNull( classNotAuditedTable.getColumn( new Column( "number1" ) ) ); - Assert.assertNull( classNotAuditedTable.getColumn( new Column( "str1" ) ) ); + Assert.assertNull( classNotAuditedTable.locateColumn( "number1" ) ); + Assert.assertNull( classNotAuditedTable.locateColumn( "str1" ) ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java index 4ee096fb92..8b569fe056 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java @@ -4,25 +4,26 @@ import javax.persistence.EntityManager; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; import org.junit.Assert; import org.junit.Test; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-4439") +@FailureExpectedWithNewMetamodel( message = "Audit overrides on MappedSuperclasses not supported yet.") public class AuditPropertyOverrideTest extends BaseEnversJPAFunctionalTestCase { private Integer propertyEntityId = null; private Integer transitiveEntityId = null; private Integer auditedEntityId = null; - private Table propertyTable = null; - private Table transitiveTable = null; - private Table auditedTable = null; + private TableSpecification propertyTable = null; + private TableSpecification transitiveTable = null; + private TableSpecification auditedTable = null; @Override protected Class[] getAnnotatedClasses() { @@ -55,33 +56,33 @@ public class AuditPropertyOverrideTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().commit(); auditedEntityId = auditedEntity.getId(); - propertyTable = getCfg().getClassMapping( + propertyTable = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.PropertyOverrideEntity_AUD" - ).getTable(); - transitiveTable = getCfg().getClassMapping( + ).getPrimaryTable(); + transitiveTable = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.TransitiveOverrideEntity_AUD" - ).getTable(); - auditedTable = getCfg().getClassMapping( + ).getPrimaryTable(); + auditedTable = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.AuditedSpecialEntity_AUD" - ).getTable(); + ).getPrimaryTable(); } @Test public void testNotAuditedProperty() { - Assert.assertNull( propertyTable.getColumn( new Column( "str1" ) ) ); + Assert.assertNull( propertyTable.locateColumn( "str1" ) ); } @Test public void testAuditedProperty() { - Assert.assertNotNull( propertyTable.getColumn( new Column( "number1" ) ) ); - Assert.assertNotNull( transitiveTable.getColumn( new Column( "number2" ) ) ); - Assert.assertNotNull( auditedTable.getColumn( new Column( "str1" ) ) ); + Assert.assertNotNull( propertyTable.locateColumn( "number1" ) ); + Assert.assertNotNull( transitiveTable.locateColumn( "number2" ) ); + Assert.assertNotNull( auditedTable.locateColumn( "str1" ) ); } @Test public void testTransitiveAuditedProperty() { - Assert.assertNotNull( transitiveTable.getColumn( new Column( "number1" ) ) ); - Assert.assertNotNull( transitiveTable.getColumn( new Column( "str1" ) ) ); + Assert.assertNotNull( transitiveTable.locateColumn( "number1" ) ); + Assert.assertNotNull( transitiveTable.locateColumn( "str1" ) ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideEntity.java index e3f6e20d8e..d60b0cd12b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideEntity.java @@ -5,6 +5,7 @@ import javax.persistence.Entity; import org.hibernate.envers.AuditOverride; import org.hibernate.envers.AuditOverrides; import org.hibernate.envers.Audited; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideTest.java index 169d0afb68..71831931da 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideTest.java @@ -4,21 +4,22 @@ import javax.persistence.EntityManager; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; import org.junit.Assert; import org.junit.Test; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-4439") +@FailureExpectedWithNewMetamodel( message = "Audit overrides on MappedSuperclasses not supported yet.") public class MixedOverrideTest extends BaseEnversJPAFunctionalTestCase { private Integer mixedEntityId = null; - private Table mixedTable = null; + private TableSpecification mixedTable = null; @Override protected Class[] getAnnotatedClasses() { @@ -37,20 +38,20 @@ public class MixedOverrideTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().commit(); mixedEntityId = mixedEntity.getId(); - mixedTable = getCfg().getClassMapping( + mixedTable = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.MixedOverrideEntity_AUD" - ).getTable(); + ).getPrimaryTable(); } @Test public void testAuditedProperty() { - Assert.assertNotNull( mixedTable.getColumn( new Column( "number1" ) ) ); - Assert.assertNotNull( mixedTable.getColumn( new Column( "str2" ) ) ); + Assert.assertNotNull( mixedTable.locateColumn( "number1" ) ); + Assert.assertNotNull( mixedTable.locateColumn( "str2" ) ); } @Test public void testNotAuditedProperty() { - Assert.assertNull( mixedTable.getColumn( new Column( "str1" ) ) ); + Assert.assertNull( mixedTable.locateColumn( "str1" ) ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MultipleAuditParentsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MultipleAuditParentsTest.java index 760190bd94..87919d14b0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MultipleAuditParentsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MultipleAuditParentsTest.java @@ -9,8 +9,8 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.tools.TestTools; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Assert; import org.junit.Test; @@ -21,6 +21,7 @@ import org.junit.Test; * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ +@FailureExpectedWithNewMetamodel( message = "Audit overrides on MappedSuperclasses not supported yet.") public class MultipleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { private long childMultipleId = 1L; private Integer siteMultipleId = null; @@ -62,17 +63,17 @@ public class MultipleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { Set expectedColumns = TestTools.makeSet( "child", "parent", "relation_id", "grandparent", "id" ); Set unexpectedColumns = TestTools.makeSet( "notAudited" ); - Table table = getCfg().getClassMapping( + TableSpecification table = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ChildMultipleParentsEntity_AUD" - ).getTable(); + ).getPrimaryTable(); for ( String columnName : expectedColumns ) { // Check whether expected column exists. - Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); + Assert.assertNotNull( table.locateColumn( columnName ) ); } for ( String columnName : unexpectedColumns ) { // Check whether unexpected column does not exist. - Assert.assertNull( table.getColumn( new Column( columnName ) ) ); + Assert.assertNull( table.locateColumn( columnName ) ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/SingleAuditParentsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/SingleAuditParentsTest.java index 57e7c38ba6..007fdb4caa 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/SingleAuditParentsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/SingleAuditParentsTest.java @@ -9,8 +9,8 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.tools.TestTools; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Assert; import org.junit.Test; @@ -21,6 +21,7 @@ import org.junit.Test; * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ +@FailureExpectedWithNewMetamodel( message = "Audit overrides on MappedSuperclasses not supported yet.") public class SingleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { private long childSingleId = 1L; private Integer siteSingleId = null; @@ -63,17 +64,17 @@ public class SingleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { Set expectedColumns = TestTools.makeSet( "child", "grandparent", "id" ); Set unexpectedColumns = TestTools.makeSet( "parent", "relation_id", "notAudited" ); - Table table = getCfg().getClassMapping( + TableSpecification table = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ChildSingleParentEntity_AUD" - ).getTable(); + ).getPrimaryTable(); for ( String columnName : expectedColumns ) { // Check whether expected column exists. - Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); + Assert.assertNotNull( table.locateColumn( columnName ) ); } for ( String columnName : unexpectedColumns ) { // Check whether unexpected column does not exist. - Assert.assertNull( table.getColumn( new Column( columnName ) ) ); + Assert.assertNull( table.locateColumn( columnName ) ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TotalAuditParentsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TotalAuditParentsTest.java index 5c58a455bc..c3b6138029 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TotalAuditParentsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TotalAuditParentsTest.java @@ -8,8 +8,8 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.tools.TestTools; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Assert; import org.junit.Test; @@ -21,6 +21,7 @@ import org.junit.Test; * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ +@FailureExpectedWithNewMetamodel( message = "Audit overrides on MappedSuperclasses not supported yet.") public class TotalAuditParentsTest extends BaseEnversJPAFunctionalTestCase { private long babyCompleteId = 1L; private Integer siteCompleteId = null; @@ -71,17 +72,17 @@ public class TotalAuditParentsTest extends BaseEnversJPAFunctionalTestCase { ); Set unexpectedColumns = TestTools.makeSet( "notAudited" ); - Table table = getCfg().getClassMapping( + TableSpecification table = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.BabyCompleteEntity_AUD" - ).getTable(); + ).getPrimaryTable(); for ( String columnName : expectedColumns ) { // Check whether expected column exists. - Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); + Assert.assertNotNull( table.locateColumn( columnName ) ); } for ( String columnName : unexpectedColumns ) { // Check whether unexpected column does not exist. - Assert.assertNull( table.getColumn( new Column( columnName ) ) ); + Assert.assertNull( table.locateColumn(columnName ) ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveAuditParentsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveAuditParentsTest.java index c6add0fe2d..a0f77a5c68 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveAuditParentsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveAuditParentsTest.java @@ -7,8 +7,8 @@ import org.hibernate.envers.Audited; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Assert; import org.junit.Test; @@ -19,6 +19,7 @@ import org.junit.Test; * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ +@FailureExpectedWithNewMetamodel( message = "Audit overrides on MappedSuperclasses not supported yet.") public class TransitiveAuditParentsTest extends BaseEnversJPAFunctionalTestCase { private long childImpTransId = 1L; private long childExpTransId = 2L; @@ -67,18 +68,18 @@ public class TransitiveAuditParentsTest extends BaseEnversJPAFunctionalTestCase @Test public void testCreatedAuditTables() { - Table explicitTransChildTable = getCfg().getClassMapping( + TableSpecification explicitTransChildTable = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ExplicitTransitiveChildEntity_AUD" - ).getTable(); + ).getPrimaryTable(); checkTableColumns( TestTools.makeSet( "child", "parent", "grandparent", "id" ), TestTools.makeSet( "notAudited" ), explicitTransChildTable ); - Table implicitTransChildTable = getCfg().getClassMapping( + TableSpecification implicitTransChildTable = getMetadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ImplicitTransitiveChildEntity_AUD" - ).getTable(); + ).getPrimaryTable(); checkTableColumns( TestTools.makeSet( "child", "parent", "grandparent", "id" ), TestTools.makeSet( "notAudited" ), @@ -86,14 +87,14 @@ public class TransitiveAuditParentsTest extends BaseEnversJPAFunctionalTestCase ); } - private void checkTableColumns(Set expectedColumns, Set unexpectedColumns, Table table) { + private void checkTableColumns(Set expectedColumns, Set unexpectedColumns, TableSpecification table) { for ( String columnName : expectedColumns ) { // Check whether expected column exists. - Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); + Assert.assertNotNull( table.locateColumn( columnName ) ); } for ( String columnName : unexpectedColumns ) { // Check whether unexpected column does not exist. - Assert.assertNull( table.getColumn( new Column( columnName ) ) ); + Assert.assertNull( table.locateColumn( columnName ) ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/SchemaExportTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/SchemaExportTest.java index 6608fcdf72..aefb6ba0da 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/SchemaExportTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/SchemaExportTest.java @@ -36,7 +36,7 @@ public class SchemaExportTest extends BaseEnversFunctionalTestCase { @FailureExpectedWithNewMetamodel public void testSchemaCreation() { // Generate complete schema. - new EnversSchemaGenerator( configuration() ).export().create( true, true ); + new EnversSchemaGenerator( metadata() ).export().create( true, true ); // Populate database with test data. Session session = getSession(); @@ -59,6 +59,6 @@ public class SchemaExportTest extends BaseEnversFunctionalTestCase { @Test @Priority(8) public void testSchemaDrop() { - new EnversSchemaGenerator( configuration() ).export().drop( true, true ); + new EnversSchemaGenerator( metadata() ).export().drop( true, true ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/tools/TestTools.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/tools/TestTools.java index 429df8c5f7..3e74f10baa 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/tools/TestTools.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/tools/TestTools.java @@ -36,6 +36,8 @@ import java.util.Set; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; +import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.EntityBinding; /** * @author Adam Warski (adam at warski dot org) @@ -84,16 +86,14 @@ public class TestTools { return result; } - public static Set extractModProperties(PersistentClass persistentClass) { - return extractModProperties( persistentClass, "_MOD" ); + public static Set extractModProperties(EntityBinding entityBinding) { + return extractModProperties( entityBinding, "_MOD" ); } - public static Set extractModProperties(PersistentClass persistentClass, String suffix) { + public static Set extractModProperties(EntityBinding entityBinding, String suffix) { final Set result = new HashSet(); - final Iterator iterator = persistentClass.getPropertyIterator(); - while ( iterator.hasNext() ) { - final Property property = (Property) iterator.next(); - final String propertyName = property.getName(); + for ( AttributeBinding property : entityBinding.attributeBindings() ) { + final String propertyName = property.getAttribute().getName(); if ( propertyName.endsWith( suffix ) ) { result.add( propertyName ); } diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/sortedcollection/Printer.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/sortedcollection/Printer.java index dd0218f2d7..90b04c4ce0 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/sortedcollection/Printer.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/sortedcollection/Printer.java @@ -30,7 +30,6 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; -import org.hibernate.annotations.Sort; /** * @author Hardy Ferentschik