From 63a0f03c5ae773f96c92c02fba9d13133d02485b Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 18 Mar 2015 20:21:33 -0500 Subject: [PATCH] HHH-9654 - Adjust envers for 5.0 APIs + JAXB --- .../main/docbook/devguide/en-US/Envers.xml | 2 +- .../osgi/extras/extension_point_blueprint.xml | 4 +- hibernate-core/hibernate-core.gradle | 2 + .../InFlightMetadataCollectorImpl.java | 10 +- .../boot/internal/MetadataBuilderImpl.java | 11 +- .../internal/MetadataBuildingProcess.java | 114 +++---- .../boot/jaxb/internal/MappingBinder.java | 37 +-- .../jaxb/internal/stax/HbmEventReader.java | 3 + .../internal/stax/JpaOrmXmlEventReader.java | 7 +- .../hbm/EntityHierarchySourceImpl.java | 2 +- .../source/internal/hbm/ModelBinder.java | 25 +- .../internal/ClassLoaderServiceImpl.java | 15 +- .../classloading/spi/ClassLoaderService.java | 27 ++ .../spi/AdditionalJaxbMappingProducer.java | 46 +++ .../boot/spi/MetadataBuilderContributor.java | 35 ++ .../boot/spi/MetadataContributor.java | 44 +++ .../boot/spi/MetadataSourcesContributor.java | 7 +- .../java/org/hibernate/cfg/Configuration.java | 3 + .../hibernate/envers/AuditReaderFactory.java | 27 +- .../AdditionalJaxbMappingProducerImpl.java | 144 +++++++++ .../internal}/EnversIntegrator.java | 84 ++--- .../envers/boot/internal/EnversService.java | 97 ++++++ .../internal/EnversServiceContributor.java | 40 +++ .../boot/internal/EnversServiceImpl.java | 304 ++++++++++++++++++ .../boot/internal/EnversServiceInitiator.java | 51 +++ .../internal}/TypeContributorImpl.java | 8 +- .../internal/AuditEntitiesConfiguration.java | 2 +- .../internal/EntitiesConfigurator.java | 68 ++-- .../internal/GlobalConfiguration.java | 50 ++- .../internal/MappingCollector.java | 38 +++ .../internal/PersistentClassGraphDefiner.java | 12 +- .../internal/RevisionInfoConfiguration.java | 17 +- .../metadata/AuditMetadataGenerator.java | 47 ++- .../metadata/BasicMetadataGenerator.java | 1 + .../metadata/CollectionMetadataGenerator.java | 9 +- .../metadata/ComponentMetadataGenerator.java | 3 +- .../internal/metadata/MetadataTools.java | 4 +- .../reader/AuditedPropertiesReader.java | 4 +- .../configuration/spi/AuditConfiguration.java | 151 ++++----- .../BaseEnversCollectionEventListener.java | 40 +-- .../event/spi/BaseEnversEventListener.java | 29 +- .../envers/event/spi/EnversListener.java | 8 - ...stCollectionRecreateEventListenerImpl.java | 6 +- .../EnversPostDeleteEventListenerImpl.java | 14 +- .../EnversPostInsertEventListenerImpl.java | 14 +- .../EnversPostUpdateEventListenerImpl.java | 14 +- ...sPreCollectionRemoveEventListenerImpl.java | 6 +- ...sPreCollectionUpdateEventListenerImpl.java | 6 +- .../envers/internal/EnversMessageLogger.java | 1 - .../internal/entities/EntityInstantiator.java | 50 +-- .../mapper/ComponentPropertyMapper.java | 8 +- .../mapper/MultiDynamicComponentMapper.java | 21 +- .../entities/mapper/MultiPropertyMapper.java | 12 +- .../entities/mapper/PropertyMapper.java | 12 +- .../entities/mapper/SinglePropertyMapper.java | 10 +- .../mapper/SubclassPropertyMapper.java | 8 +- .../relation/AbstractCollectionMapper.java | 26 +- .../relation/AbstractOneToOneMapper.java | 12 +- .../mapper/relation/AbstractToOneMapper.java | 32 +- .../relation/BasicCollectionMapper.java | 26 +- .../mapper/relation/ListCollectionMapper.java | 19 +- .../mapper/relation/MapCollectionMapper.java | 20 +- .../relation/SortedMapCollectionMapper.java | 21 +- .../relation/SortedSetCollectionMapper.java | 20 +- .../mapper/relation/ToOneEntityLoader.java | 16 +- .../mapper/relation/ToOneIdMapper.java | 66 ++-- .../MiddleEmbeddableComponentMapper.java | 14 +- .../lazy/ToOneDelegateSessionImplementor.java | 15 +- .../AbstractCollectionInitializor.java | 6 +- .../ArrayCollectionInitializor.java | 6 +- .../BasicCollectionInitializor.java | 6 +- .../ListCollectionInitializor.java | 10 +- .../initializor/MapCollectionInitializor.java | 6 +- .../SortedMapCollectionInitializor.java | 6 +- .../SortedSetCollectionInitializor.java | 15 +- .../internal/reader/AuditReaderImpl.java | 33 +- .../CrossTypeRevisionChangesReaderImpl.java | 12 +- .../work/AbstractAuditWorkUnit.java | 26 +- .../synchronization/work/AddWorkUnit.java | 28 +- .../work/CollectionChangeWorkUnit.java | 36 ++- .../synchronization/work/DelWorkUnit.java | 20 +- .../FakeBidirectionalRelationWorkUnit.java | 20 +- .../synchronization/work/ModWorkUnit.java | 33 +- .../PersistentCollectionChangeWorkUnit.java | 41 ++- .../envers/internal/tools/Tools.java | 12 + .../envers/query/AuditQueryCreator.java | 20 +- .../criteria/AggregatedAuditExpression.java | 21 +- .../query/criteria/AuditConjunction.java | 13 +- .../envers/query/criteria/AuditCriterion.java | 9 +- .../query/criteria/AuditDisjunction.java | 11 +- .../envers/query/criteria/AuditProperty.java | 6 +- .../internal/BetweenAuditExpression.java | 13 +- .../criteria/internal/CriteriaTools.java | 37 ++- .../internal/IdentifierEqAuditExpression.java | 15 +- .../internal/IlikeAuditExpression.java | 12 +- .../criteria/internal/InAuditExpression.java | 13 +- .../internal/LogicalAuditExpression.java | 13 +- .../criteria/internal/NotAuditExpression.java | 11 +- .../internal/NotNullAuditExpression.java | 13 +- .../internal/NullAuditExpression.java | 13 +- .../internal/PropertyAuditExpression.java | 14 +- .../internal/RelatedAuditExpression.java | 13 +- .../internal/RevisionTypeAuditExpression.java | 11 +- .../internal/SimpleAuditExpression.java | 13 +- .../internal/impl/AbstractAuditQuery.java | 31 +- .../impl/EntitiesAtRevisionQuery.java | 31 +- .../impl/EntitiesModifiedAtRevisionQuery.java | 23 +- .../internal/impl/RevisionsOfEntityQuery.java | 31 +- .../internal/property/EntityPropertyName.java | 4 +- .../property/ModifiedFlagPropertyName.java | 8 +- .../property/OriginalIdPropertyName.java | 6 +- .../internal/property/PropertyNameGetter.java | 6 +- .../property/RevisionNumberPropertyName.java | 6 +- .../RevisionPropertyPropertyName.java | 6 +- .../property/RevisionTypePropertyName.java | 6 +- .../envers/query/order/AuditOrder.java | 6 +- .../order/internal/PropertyAuditOrder.java | 6 +- .../query/projection/AuditProjection.java | 6 +- .../internal/PropertyAuditProjection.java | 6 +- .../envers/strategy/AuditStrategy.java | 36 ++- .../envers/strategy/DefaultAuditStrategy.java | 20 +- .../strategy/ValidityAuditStrategy.java | 79 +++-- .../tools/hbm2ddl/EnversSchemaGenerator.java | 74 ----- .../org.hibernate.boot.model.TypeContributor | 2 +- ...ate.boot.spi.AdditionalJaxbMappingProducer | 1 + .../org.hibernate.integrator.spi.Integrator | 2 +- ...g.hibernate.service.spi.ServiceContributor | 1 + .../OSGI-INF/blueprint/blueprint.xml | 4 +- .../test/BaseEnversFunctionalTestCase.java | 16 +- .../test/BaseEnversJPAFunctionalTestCase.java | 8 +- .../basic/ColumnScalePrecisionTest.java | 4 +- .../test/integration/basic/NoneAudited.java | 15 +- .../basic/OutsideTransactionTest.java | 11 +- .../AbstractCollectionChangeTest.java | 8 +- .../components/PropertiesGroupTest.java | 11 +- .../customtype/UnspecifiedEnumTypeTest.java | 10 +- .../ChildPrimaryKeyJoinAuditing.java | 8 +- .../DiscriminatorFormulaTest.java | 2 +- .../AuditedAbstractParentTest.java | 4 +- .../modifiedflags/HasChangedComponents.java | 2 +- .../modifiedflags/ModifiedFlagSuffix.java | 2 +- .../test/integration/naming/BasicNaming.java | 3 +- .../test/integration/naming/JoinNaming.java | 6 +- .../naming/OneToManyUnidirectionalNaming.java | 4 +- .../naming/VersionsJoinTableNaming.java | 4 +- ...ionsJoinTableRangeComponentNamingTest.java | 14 +- .../naming/ids/JoinEmbIdNaming.java | 14 +- .../naming/ids/JoinMulIdNaming.java | 15 +- .../naming/quotation/QuotedFieldsTest.java | 2 +- .../UnversionedOptimisticLockingField.java | 2 +- .../reventity/DifferentDBSchemaTest.java | 2 +- ...LongRevEntityInheritanceChildAuditing.java | 4 +- .../DefaultTrackingEntitiesTest.java | 4 +- .../EntityNamesTest.java | 8 +- .../integration/secondary/BasicSecondary.java | 2 +- .../secondary/NamingSecondary.java | 2 +- .../secondary/ids/EmbIdSecondary.java | 6 +- .../secondary/ids/MulIdSecondary.java | 2 +- .../auditoverride/AuditClassOverrideTest.java | 4 +- .../AuditPropertyOverrideTest.java | 6 +- .../auditoverride/MixedOverrideTest.java | 2 +- .../MultipleAuditParentsTest.java | 2 +- .../auditparents/SingleAuditParentsTest.java | 2 +- .../auditparents/TotalAuditParentsTest.java | 2 +- .../TransitiveAuditParentsTest.java | 4 +- .../integration/tools/SchemaExportTest.java | 15 - .../AbstractEntityManagerTest.java | 2 +- .../src/test/resources/log4j.properties | 4 +- .../BaseNonConfigCoreFunctionalTestCase.java | 4 + working-5.0-migration-guide.md | 3 + 170 files changed, 2147 insertions(+), 1187 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalJaxbMappingProducer.java create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuilderContributor.java create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataContributor.java create mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java rename hibernate-envers/src/main/java/org/hibernate/envers/{event/spi => boot/internal}/EnversIntegrator.java (53%) create mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversService.java create mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceContributor.java create mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceImpl.java create mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceInitiator.java rename hibernate-envers/src/main/java/org/hibernate/envers/{internal/entities => boot/internal}/TypeContributorImpl.java (86%) create mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/MappingCollector.java delete mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java create mode 100644 hibernate-envers/src/main/resources/META-INF/services/org.hibernate.boot.spi.AdditionalJaxbMappingProducer create mode 100644 hibernate-envers/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor diff --git a/documentation/src/main/docbook/devguide/en-US/Envers.xml b/documentation/src/main/docbook/devguide/en-US/Envers.xml index f3acd55206..49d247d35e 100644 --- a/documentation/src/main/docbook/devguide/en-US/Envers.xml +++ b/documentation/src/main/docbook/devguide/en-US/Envers.xml @@ -1113,7 +1113,7 @@ query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]> Create your own implementation of org.hibernate.integrator.spi.Integrator, - similar to org.hibernate.envers.event.spi.EnversIntegrator. Use your event + similar to org.hibernate.envers.boot.internal.EnversIntegrator. Use your event listener classes instead of the default ones. diff --git a/documentation/src/main/docbook/devguide/en-US/chapters/osgi/extras/extension_point_blueprint.xml b/documentation/src/main/docbook/devguide/en-US/chapters/osgi/extras/extension_point_blueprint.xml index a263100e5b..d9c56fc5d9 100644 --- a/documentation/src/main/docbook/devguide/en-US/chapters/osgi/extras/extension_point_blueprint.xml +++ b/documentation/src/main/docbook/devguide/en-US/chapters/osgi/extras/extension_point_blueprint.xml @@ -1,11 +1,11 @@ - + + class="org.hibernate.envers.boot.internal.TypeContributorImpl" /> \ No newline at end of file diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 08d254f49f..e485f20a70 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -16,6 +16,8 @@ dependencies { compile( libraries.antlr ) compile( libraries.jandex ) + compile( "org.codehaus.woodstox:woodstox-core-asl:4.3.0") + antlr( libraries.antlr ) provided( libraries.ant ) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java index cb18e8902a..efd3483b82 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java @@ -1660,7 +1660,11 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector private boolean inSecondPass = false; - private void processSecondPasses(MetadataBuildingContext buildingContext) { + + /** + * Ugh! But we need this done before we ask Envers to produce its entities. + */ + public void processSecondPasses(MetadataBuildingContext buildingContext) { inSecondPass = true; try { @@ -1969,6 +1973,8 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector buildUniqueKeyFromColumnNames( table, holder.getName(), holder.getColumns(), buildingContext ); } } + + uniqueConstraintHoldersByTable.clear(); } private void buildUniqueKeyFromColumnNames( @@ -2154,6 +2160,8 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector for ( NaturalIdUniqueKeyBinder naturalIdUniqueKeyBinder : naturalIdUniqueKeyBinderMap.values() ) { naturalIdUniqueKeyBinder.process(); } + + naturalIdUniqueKeyBinderMap.clear(); } private void processCachingOverrides() { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java index 9afbac5ffe..fdee0b3958 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java @@ -56,6 +56,7 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.spi.MappingDefaults; +import org.hibernate.boot.spi.MetadataBuilderContributor; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataSourcesContributor; import org.hibernate.cache.spi.RegionFactory; @@ -123,17 +124,21 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serviceRegistry) { this.sources = sources; + this.options = new MetadataBuildingOptionsImpl( serviceRegistry ); for ( MetadataSourcesContributor contributor : sources.getServiceRegistry() .getService( ClassLoaderService.class ) .loadJavaServices( MetadataSourcesContributor.class ) ) { - contributor.contribute( sources, null ); + contributor.contribute( sources ); } - this.options = new MetadataBuildingOptionsImpl( serviceRegistry ); - applyCfgXmlValues( serviceRegistry.getService( CfgXmlAccessService.class ) ); + + final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); + for ( MetadataBuilderContributor contributor : classLoaderService.loadJavaServices( MetadataBuilderContributor.class ) ) { + contributor.contribute( this ); + } } private void applyCfgXmlValues(CfgXmlAccessService service) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingProcess.java index 65f31df79f..2d904393f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingProcess.java @@ -24,7 +24,9 @@ package org.hibernate.boot.internal; import java.lang.reflect.Constructor; +import java.util.Collection; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import javax.persistence.Converter; @@ -40,15 +42,22 @@ import org.hibernate.boot.archive.scan.spi.ScanResult; import org.hibernate.boot.archive.scan.spi.Scanner; import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; import org.hibernate.boot.internal.DeploymentResourcesInterpreter.DeploymentResources; +import org.hibernate.boot.jaxb.internal.MappingBinder; import org.hibernate.boot.model.TypeContributions; import org.hibernate.boot.model.TypeContributor; import org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl; +import org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder; +import org.hibernate.boot.model.source.internal.hbm.EntityHierarchySourceImpl; import org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl; +import org.hibernate.boot.model.source.internal.hbm.MappingDocument; +import org.hibernate.boot.model.source.internal.hbm.ModelBinder; import org.hibernate.boot.model.source.spi.MetadataSourceProcessor; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; +import org.hibernate.boot.spi.AdditionalJaxbMappingProducer; import org.hibernate.boot.spi.ClassLoaderAccess; import org.hibernate.boot.spi.MetadataBuildingOptions; +import org.hibernate.boot.spi.MetadataContributor; import org.hibernate.cfg.MetadataSourceType; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.spi.JdbcServices; @@ -281,27 +290,37 @@ public class MetadataBuildingProcess { processor.finishUp(); -// for ( MetadataContributor contributor : classLoaderService.loadJavaServices( MetadataContributor.class ) ) { -// contributor.contribute( metadataCollector, jandexView ); -// } + for ( MetadataContributor contributor : classLoaderService.loadJavaServices( MetadataContributor.class ) ) { + log.tracef( "Calling MetadataContributor : %s", contributor ); + contributor.contribute( metadataCollector, jandexView ); + } -// 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, jaxbRootProducerContext ) ); -// } + metadataCollector.processSecondPasses( rootMetadataBuildingContext ); -// secondPass( rootMetadataBuildingContext ); + LinkedHashSet producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class ); + if ( producers != null && !producers.isEmpty() ) { + final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder(); +// final MappingBinder mappingBinder = new MappingBinder( true ); + // We need to disable validation here. It seems Envers is not producing valid (according to schema) XML + final MappingBinder mappingBinder = new MappingBinder( false ); + for ( AdditionalJaxbMappingProducer producer : producers ) { + log.tracef( "Calling AdditionalJaxbMappingProducer : %s", producer ); + Collection additionalMappings = producer.produceAdditionalMappings( + metadataCollector, + jandexView, + mappingBinder, + rootMetadataBuildingContext + ); + for ( MappingDocument mappingDocument : additionalMappings ) { + hierarchyBuilder.indexMappingDocument( mappingDocument ); + } + } + + ModelBinder binder = ModelBinder.prepare( rootMetadataBuildingContext ); + for ( EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies() ) { + binder.bindEntityHierarchy( entityHierarchySource ); + } + } return metadataCollector.buildMetadataInstance( rootMetadataBuildingContext ); } @@ -503,62 +522,5 @@ public class MetadataBuildingProcess { return basicTypeRegistry; } -// -// private static void secondPass(MetadataBuildingContextRootImpl bindingContext) { -// // This must be done outside of Table, rather than statically, to ensure -// // deterministic alias names. See HHH-2448. -// int uniqueInteger = 0; -// for ( Schema schema : bindingContext.getMetadataCollector().getDatabase().getSchemas() ) { -// for ( Table table : schema.getTables() ) { -// table.setTableNumber( uniqueInteger++ ); -// } -// } -// -// -// if ( bindingContext.getBuildingOptions().getCacheRegionDefinitions() == null -// || bindingContext.getBuildingOptions().getCacheRegionDefinitions().isEmpty() ) { -// return; -// } -// -// for ( CacheRegionDefinition override : bindingContext.getBuildingOptions().getCacheRegionDefinitions() ) { -// final String role = override.getRole(); -// -// // NOTE : entity region overrides are already handled when building the -// if ( override.getRegionType() == CacheRegionDefinition.CacheRegionType.ENTITY ) { -//// final EntityBinding entityBinding = bindingContext.getMetadataCollector().getEntityBinding( role ); -//// if ( entityBinding != null ) { -//// entityBinding.getHierarchyDetails().getCaching().setRegion( override.getRegion() ); -//// entityBinding.getHierarchyDetails().getCaching().setAccessType( AccessType.fromExternalName( override.getUsage() ) ); -//// entityBinding.getHierarchyDetails().getCaching().setCacheLazyProperties( override.isCacheLazy() ); -//// } -//// else { -//// //logging? -//// throw new MappingException( "Can't find entitybinding for role " + role +" to apply cache configuration" ); -//// } -// -// } -// else if ( override.getRegionType() == CacheRegionDefinition.CacheRegionType.COLLECTION ) { -// String collectionRole = role; -// if ( !role.contains( "#" ) ) { -// final int pivotPosition = role.lastIndexOf( '.' ); -// if ( pivotPosition > 0 ) { -// collectionRole = role.substring( 0, pivotPosition ) + '#' + role.substring( pivotPosition + 1 ); -// } -// } -// final PluralAttributeBinding pluralAttributeBinding = bindingContext.getMetadataCollector().getCollection( -// collectionRole -// ); -// if ( pluralAttributeBinding != null ) { -// pluralAttributeBinding.getCaching().overlay( override ); -// } -// else { -// //logging? -// throw new MappingException( "Can't find entitybinding for role " + role +" to apply cache configuration" ); -// } -// } -// } -// -// } - } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java index 36e96a02f5..1fe6311f49 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java @@ -23,6 +23,7 @@ */ package org.hibernate.boot.jaxb.internal; +import javax.xml.stream.XMLEventFactory; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.StartElement; @@ -49,6 +50,8 @@ import org.dom4j.io.STAXEventReader; public class MappingBinder extends AbstractBinder { private static final Logger log = Logger.getLogger( MappingBinder.class ); + private final XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance(); + public MappingBinder() { super(); } @@ -66,7 +69,7 @@ public class MappingBinder extends AbstractBinder { if ( "hibernate-mapping".equals( rootElementLocalName ) ) { log.debugf( "Performing JAXB binding of hbm.xml document : %s", origin.toString() ); - XMLEventReader hbmReader = new HbmEventReader( staxEventReader ); + XMLEventReader hbmReader = new HbmEventReader( staxEventReader, xmlEventFactory ); JaxbHbmHibernateMapping hbmBindings = jaxb( hbmReader, LocalSchema.HBM.getSchema(), JaxbHbmHibernateMapping.class, origin ); return new Binding( hbmBindings, origin ); } @@ -75,7 +78,7 @@ public class MappingBinder extends AbstractBinder { // return jaxb( reader, LocalSchema.MAPPING.getSchema(), JaxbEntityMappings.class, origin ); try { - final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader ); + final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader, xmlEventFactory ); return new Binding( toDom4jDocument( reader, origin), origin ); } catch (JpaOrmXmlEventReader.BadVersionException e) { @@ -111,34 +114,4 @@ public class MappingBinder extends AbstractBinder { ); } } - - /** - * Models an {@code orm.xml} file, which is processed in a delayed manner. - */ - public static class DelayedOrmXmlData { - private final XMLEventReader staxEventReader; - private final StartElement rootElementStartEvent; - private final Origin origin; - - public DelayedOrmXmlData( - XMLEventReader staxEventReader, - StartElement rootElementStartEvent, - Origin origin) { - this.staxEventReader = staxEventReader; - this.rootElementStartEvent = rootElementStartEvent; - this.origin = origin; - } - - public XMLEventReader getStaxEventReader() { - return staxEventReader; - } - - public StartElement getRootElementStartEvent() { - return rootElementStartEvent; - } - - public Origin getOrigin() { - return origin; - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/HbmEventReader.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/HbmEventReader.java index 14fa0fcfb5..8f97935e0b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/HbmEventReader.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/HbmEventReader.java @@ -97,6 +97,9 @@ public class HbmEventReader extends EventReaderDelegate { targetNamespaces.add( namespace ); } + // Transfer the location info from the incoming event to the event factory + // so that the event we ask it to generate for us has the same location info + xmlEventFactory.setLocation( startElement.getLocation() ); return xmlEventFactory.createStartElement( new QName( LocalSchema.HBM.getNamespaceUri(), startElement.getName().getLocalPart() ), startElement.getAttributes(), diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/JpaOrmXmlEventReader.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/JpaOrmXmlEventReader.java index c89ab842d2..ec77694917 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/JpaOrmXmlEventReader.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/JpaOrmXmlEventReader.java @@ -101,7 +101,9 @@ public class JpaOrmXmlEventReader extends EventReaderDelegate { List newElementAttributeList = mapAttributes( startElement ); List newNamespaceList = mapNamespaces( startElement ); - // create the new element + // Transfer the location info from the incoming event to the event factory + // so that the event we ask it to generate for us has the same location info + xmlEventFactory.setLocation( startElement.getLocation() ); return xmlEventFactory.createStartElement( new QName( LocalSchema.ORM.getNamespaceUri(), startElement.getName().getLocalPart() ), newElementAttributeList.iterator(), @@ -194,6 +196,9 @@ public class JpaOrmXmlEventReader extends EventReaderDelegate { private XMLEvent wrap(EndElement endElement) { final List targetNamespaces = mapNamespaces( existingXmlNamespacesIterator( endElement ) ); + // Transfer the location info from the incoming event to the event factory + // so that the event we ask it to generate for us has the same location info + xmlEventFactory.setLocation( endElement.getLocation() ); return xmlEventFactory.createEndElement( new QName( LocalSchema.ORM.getNamespaceUri(), endElement.getName().getLocalPart() ), targetNamespaces.iterator() diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/EntityHierarchySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/EntityHierarchySourceImpl.java index f4c5e492c1..ba21935ffe 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/EntityHierarchySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/EntityHierarchySourceImpl.java @@ -211,7 +211,7 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { } else { if ( jaxbDiscriminatorMapping.getFormula() != null ) { - columnOrFormulas = Collections.singletonList( jaxbDiscriminatorMapping.getColumn() ); + columnOrFormulas = Collections.singletonList( jaxbDiscriminatorMapping.getFormula() ); } else { columnOrFormulas = Collections.emptyList(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index 30eee0229a..74064f7a8d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -953,7 +953,9 @@ public class ModelBinder { private void finishBindingCompositeIdentifier( MappingDocument sourceDocument, RootClass rootEntityDescriptor, - CompositeIdentifierSource identifierSource, Component cid, String propertyName) { + CompositeIdentifierSource identifierSource, + Component cid, + String propertyName) { if ( propertyName == null ) { rootEntityDescriptor.setEmbeddedIdentifier( cid.isEmbedded() ); if ( cid.isEmbedded() ) { @@ -1889,6 +1891,10 @@ public class ModelBinder { attribute ); + final String xmlNodeName = determineXmlNodeName( embeddedSource, componentBinding.getOwner().getNodeName() ); + componentBinding.setNodeName( xmlNodeName ); + attribute.setNodeName( xmlNodeName ); + return attribute; } @@ -2439,7 +2445,7 @@ public class ModelBinder { AttributeSource propertySource, Property property) { property.setName( propertySource.getName() ); - property.setNodeName( propertySource.getXmlNodeName() ); + property.setNodeName( determineXmlNodeName( propertySource, null ) ); property.setPropertyAccessorName( StringHelper.isNotEmpty( propertySource.getPropertyAccessorName() ) @@ -2539,6 +2545,21 @@ public class ModelBinder { } } + private String determineXmlNodeName(AttributeSource propertySource, String fallbackXmlNodeName) { + String nodeName = propertySource.getXmlNodeName(); + if ( StringHelper.isNotEmpty( nodeName ) ) { + DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport(); + } + else { + nodeName = propertySource.getName(); + } + if ( nodeName == null ) { + nodeName = fallbackXmlNodeName; + } + + return nodeName; + } + private void bindComponent( MappingDocument sourceDocument, EmbeddableSource embeddableSource, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java index 9fb95e3b6b..57689f73d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java @@ -359,20 +359,6 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { // completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - /** - * Hack around continued (temporary) need to sometimes set the TCCL for code we call that expects it. - * - * @param The result type - */ - public static interface Work { - /** - * The work to be performed with the TCCL set - * - * @return The result of the work - */ - public T perform(); - } - /** * Perform some discrete work with with the TCCL set to our aggregated ClassLoader * @@ -381,6 +367,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { * * @return The work result. */ + @Override public T withTccl(Work work) { final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java index 87a8a2dd9c..4d679c5656 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java @@ -88,4 +88,31 @@ public interface ClassLoaderService extends Service, Stoppable { * @return The ordered set of discovered services. */ public LinkedHashSet loadJavaServices(Class serviceContract); + + + /** + * Hack around continued (temporary) need to sometimes set the TCCL for code we call that expects it. + * + * @param The result type + */ + @Deprecated + public static interface Work { + /** + * The work to be performed with the TCCL set + * + * @return The result of the work + */ + public T perform(); + } + + /** + * Perform some discrete work with with the TCCL set to our aggregated ClassLoader + * + * @param work The discrete work to be done + * @param The type of the work result + * + * @return The work result. + */ + @Deprecated + public T withTccl(Work work); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalJaxbMappingProducer.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalJaxbMappingProducer.java new file mode 100644 index 0000000000..c6661ae5e2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalJaxbMappingProducer.java @@ -0,0 +1,46 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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.boot.spi; + +import java.util.Collection; + +import org.hibernate.boot.jaxb.internal.MappingBinder; +import org.hibernate.boot.model.source.internal.hbm.MappingDocument; + +import org.jboss.jandex.IndexView; + +/** + * @author Steve Ebersole + * + * @deprecated Intended for Envers integration until we can migrate Envers away from XML generation + * for building its model. + */ +@Deprecated +public interface AdditionalJaxbMappingProducer { + Collection produceAdditionalMappings( + MetadataImplementor metadata, + IndexView jandexIndex, + MappingBinder mappingBinder, + MetadataBuildingContext buildingContext); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuilderContributor.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuilderContributor.java new file mode 100644 index 0000000000..1dcfa966a8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuilderContributor.java @@ -0,0 +1,35 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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.boot.spi; + +import org.hibernate.boot.MetadataBuilder; + +/** + * Contract for contributing to the initialization of MetadataBuilder + * + * @author Steve Ebersole + */ +public interface MetadataBuilderContributor { + public void contribute(MetadataBuilder metadataBuilder); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataContributor.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataContributor.java new file mode 100644 index 0000000000..ecc395ef3b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataContributor.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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.boot.spi; + +import org.jboss.jandex.IndexView; + +/** + * Contract for contributing to Metadata (InFlightMetadataCollector). + * + * This hook occurs just after all processing of all {@link org.hibernate.boot.MetadataSources}, + * and just before {@link AdditionalJaxbRootProducer}. + * + * @author Steve Ebersole + */ +public interface MetadataContributor { + /** + * Perform the contributions. + * + * @param metadataCollector The metadata collector, representing the in-flight metadata being built + * @param jandexIndex The Jandex index + */ + public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataSourcesContributor.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataSourcesContributor.java index b0655b5d70..5002646295 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataSourcesContributor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataSourcesContributor.java @@ -25,8 +25,6 @@ package org.hibernate.boot.spi; import org.hibernate.boot.MetadataSources; -import org.jboss.jandex.IndexView; - /** * A bootstrap process hook for contributing sources to MetadataSources. * @@ -36,8 +34,7 @@ public interface MetadataSourcesContributor { /** * Perform the process of contributing to MetadataSources. * - * @param metadataSources - * @param jandexIndex The Jandex index + * @param metadataSources The MetadataSources, to which to contribute. */ - public void contribute(MetadataSources metadataSources, IndexView jandexIndex); + public void contribute(MetadataSources metadataSources); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index e9ebb1621b..0e7f48d3bc 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -272,6 +272,7 @@ public class Configuration { standardServiceRegistryBuilder.configure( resource ); // todo : still need to have StandardServiceRegistryBuilder handle the "other cfg.xml" elements. // currently it just reads the config properties + properties.putAll( standardServiceRegistryBuilder.getSettings() ); return this; } @@ -316,6 +317,7 @@ public class Configuration { */ public Configuration configure(URL url) throws HibernateException { standardServiceRegistryBuilder.configure( url ); + properties.putAll( standardServiceRegistryBuilder.getSettings() ); return this; } @@ -331,6 +333,7 @@ public class Configuration { */ public Configuration configure(File configFile) throws HibernateException { standardServiceRegistryBuilder.configure( configFile ); + properties.putAll( standardServiceRegistryBuilder.getSettings() ); return this; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java index c19facf355..3e483410d2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java @@ -27,12 +27,10 @@ import javax.persistence.EntityManager; import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.event.spi.EnversListener; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.reader.AuditReaderImpl; -import org.hibernate.event.service.spi.EventListenerRegistry; -import org.hibernate.event.spi.EventType; -import org.hibernate.event.spi.PostInsertEventListener; +import org.hibernate.service.ServiceRegistry; /** * @author Adam Warski (adam at warski dot org) @@ -60,25 +58,10 @@ public class AuditReaderFactory { sessionImpl = (SessionImplementor) session; } - // todo : I wonder if there is a better means to do this via "named lookup" based on the session factory name/uuid - final EventListenerRegistry listenerRegistry = sessionImpl - .getFactory() - .getServiceRegistry() - .getService( EventListenerRegistry.class ); + final ServiceRegistry serviceRegistry = sessionImpl.getFactory().getServiceRegistry(); + final EnversService enversService = serviceRegistry.getService( EnversService.class ); - for ( PostInsertEventListener listener : listenerRegistry.getEventListenerGroup( EventType.POST_INSERT ) - .listeners() ) { - if ( listener instanceof EnversListener ) { - // todo : slightly different from original code in that I am not checking the other listener groups... - return new AuditReaderImpl( - ((EnversListener) listener).getAuditConfiguration(), - session, - sessionImpl - ); - } - } - - throw new AuditException( "Envers listeners were not properly registered" ); + return new AuditReaderImpl( enversService, session, sessionImpl ); } /** diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java new file mode 100644 index 0000000000..10eaffdb4e --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java @@ -0,0 +1,144 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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.boot.internal; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import javax.xml.transform.dom.DOMSource; + +import org.hibernate.HibernateException; +import org.hibernate.boot.archive.internal.ByteArrayInputStreamAccess; +import org.hibernate.boot.jaxb.Origin; +import org.hibernate.boot.jaxb.SourceType; +import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; +import org.hibernate.boot.jaxb.internal.MappingBinder; +import org.hibernate.boot.jaxb.spi.Binding; +import org.hibernate.boot.model.source.internal.hbm.MappingDocument; +import org.hibernate.boot.spi.AdditionalJaxbMappingProducer; +import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.envers.configuration.internal.MappingCollector; +import org.hibernate.service.ServiceRegistry; + +import org.jboss.jandex.IndexView; +import org.jboss.logging.Logger; + +import org.dom4j.DocumentException; +import org.dom4j.io.DOMWriter; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.XMLWriter; +import org.dom4j.Document; + +/** + * @author Steve Ebersole + */ +public class AdditionalJaxbMappingProducerImpl implements AdditionalJaxbMappingProducer { + private static final Logger log = Logger.getLogger( AdditionalJaxbMappingProducerImpl.class ); + + @Override + public Collection produceAdditionalMappings( + final MetadataImplementor metadata, + IndexView jandexIndex, + final MappingBinder mappingBinder, + final MetadataBuildingContext buildingContext) { + final ServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry(); + final EnversService enversService = serviceRegistry.getService( EnversService.class ); + + if ( !enversService.isEnabled() ) { + // short-circuit if envers integration has been disabled. + return Collections.emptyList(); + } + + final ArrayList additionalMappingDocuments = new ArrayList(); + + // atm we do not have distinct origin info for envers + final Origin origin = new Origin( SourceType.OTHER, "envers" ); +// final DOMWriter writer = new DOMWriter(); + + final MappingCollector mappingCollector = new MappingCollector() { + @Override + public void addDocument(Document document) throws DocumentException { + dump( document ); + + // while the commented-out code here is more efficient (well, understanding that + // this whole process is un-efficient) it leads to un-decipherable messages when + // we get mapping mapping errors from envers output. +// final DOMSource domSource = new DOMSource( writer.write( document ) ); +// domSource.setSystemId( "envers" ); +// final Binding jaxbBinding = mappingBinder.bind( domSource, origin ); + + // this form at least allows us to get better error messages + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final Writer w = new PrintWriter( baos ); + try { + final XMLWriter xw = new XMLWriter( w, new OutputFormat( " ", true ) ); + xw.write( document ); + w.flush(); + } + catch (IOException e) { + throw new HibernateException( "Unable to bind Envers-generated XML", e ); + } + + ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() ); + BufferedInputStream bis = new BufferedInputStream( bais ); + final Binding jaxbBinding = mappingBinder.bind( bis, origin ); + + final JaxbHbmHibernateMapping jaxbRoot = (JaxbHbmHibernateMapping) jaxbBinding.getRoot(); + additionalMappingDocuments.add( new MappingDocument( jaxbRoot, origin, buildingContext ) ); + } + }; + + enversService.initialize( metadata, mappingCollector ); + + return additionalMappingDocuments; + } + + private static void dump(Document document) { + if ( !log.isTraceEnabled() ) { + return; + } + + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final Writer w = new PrintWriter( baos ); + + try { + final XMLWriter xw = new XMLWriter( w, new OutputFormat( " ", true ) ); + xw.write( document ); + w.flush(); + } + catch (IOException e1) { + e1.printStackTrace(); + } + + log.tracef( "Envers-generate entity mapping -----------------------------\n%s", baos.toString() ); + log.trace( "------------------------------------------------------------" ); + } +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversIntegrator.java similarity index 53% rename from hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java rename to hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversIntegrator.java index 30b7d619ed..6f7ddd8ac9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversIntegrator.java @@ -21,99 +21,79 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.envers.event.spi; +package org.hibernate.envers.boot.internal; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.cfg.Configuration; +import org.hibernate.HibernateException; +import org.hibernate.boot.Metadata; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.event.spi.EnversListenerDuplicationStrategy; +import org.hibernate.envers.event.spi.EnversPostCollectionRecreateEventListenerImpl; +import org.hibernate.envers.event.spi.EnversPostDeleteEventListenerImpl; +import org.hibernate.envers.event.spi.EnversPostInsertEventListenerImpl; +import org.hibernate.envers.event.spi.EnversPostUpdateEventListenerImpl; +import org.hibernate.envers.event.spi.EnversPreCollectionRemoveEventListenerImpl; +import org.hibernate.envers.event.spi.EnversPreCollectionUpdateEventListenerImpl; import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.EventType; import org.hibernate.integrator.spi.Integrator; -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.spi.SessionFactoryServiceRegistry; -import org.jboss.logging.Logger; - /** - * Provides integration for Envers into Hibernate, which mainly means registering the proper event listeners. + * Hooks up Envers event listeners. * * @author Steve Ebersole */ public class EnversIntegrator implements Integrator { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( - CoreMessageLogger.class, - EnversIntegrator.class.getName() - ); + public static final String AUTO_REGISTER = EnversService.LEGACY_AUTO_REGISTER; - /** - * The name of a configuration setting that can be used to control whether auto registration of envers listeners - * should happen or not. Default is true - */ - public static final String AUTO_REGISTER = "hibernate.listeners.envers.autoRegister"; - private AuditConfiguration enversConfiguration; - - @Override public void integrate( - Configuration configuration, + Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { - final boolean autoRegister = ConfigurationHelper.getBoolean( - AUTO_REGISTER, - configuration.getProperties(), - true - ); - if ( !autoRegister ) { - LOG.debug( "Skipping Envers listener auto registration" ); + final EnversService enversService = serviceRegistry.getService( EnversService.class ); + if ( !enversService.isEnabled() ) { return; } + if ( !enversService.isInitialized() ) { + throw new HibernateException( + "Expecting EnversService to have been initialized prior to call to EnversIntegrator#integrate" + ); + } + final EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE ); - enversConfiguration = AuditConfiguration.getFor( - configuration, - serviceRegistry.getService( - ClassLoaderService.class - ) - ); - - if ( enversConfiguration.getEntCfg().hasAuditedEntities() ) { + if ( enversService.getEntitiesConfigurations().hasAuditedEntities() ) { listenerRegistry.appendListeners( - EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl( - enversConfiguration - ) + EventType.POST_DELETE, + new EnversPostDeleteEventListenerImpl( enversService ) ); listenerRegistry.appendListeners( - EventType.POST_INSERT, new EnversPostInsertEventListenerImpl( - enversConfiguration - ) + EventType.POST_INSERT, + new EnversPostInsertEventListenerImpl( enversService ) ); listenerRegistry.appendListeners( - EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl( - enversConfiguration - ) + EventType.POST_UPDATE, + new EnversPostUpdateEventListenerImpl( enversService ) ); listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, - new EnversPostCollectionRecreateEventListenerImpl( enversConfiguration ) + new EnversPostCollectionRecreateEventListenerImpl( enversService ) ); listenerRegistry.appendListeners( EventType.PRE_COLLECTION_REMOVE, - new EnversPreCollectionRemoveEventListenerImpl( enversConfiguration ) + new EnversPreCollectionRemoveEventListenerImpl( enversService ) ); listenerRegistry.appendListeners( EventType.PRE_COLLECTION_UPDATE, - new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration ) + new EnversPreCollectionUpdateEventListenerImpl( enversService ) ); } } @Override public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { - if ( enversConfiguration != null ) { - enversConfiguration.destroy(); - } + // nothing to do } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversService.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversService.java new file mode 100644 index 0000000000..9f1be77c97 --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversService.java @@ -0,0 +1,97 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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.boot.internal; + +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; +import org.hibernate.envers.configuration.internal.GlobalConfiguration; +import org.hibernate.envers.configuration.internal.MappingCollector; +import org.hibernate.envers.internal.entities.EntitiesConfigurations; +import org.hibernate.envers.internal.revisioninfo.ModifiedEntityNamesReader; +import org.hibernate.envers.internal.revisioninfo.RevisionInfoNumberReader; +import org.hibernate.envers.internal.revisioninfo.RevisionInfoQueryCreator; +import org.hibernate.envers.internal.synchronization.AuditProcessManager; +import org.hibernate.envers.strategy.AuditStrategy; +import org.hibernate.service.Service; + +/** + * Provides central access to Envers' configuration. + * + * In many ways, this replaces the legacy static map Envers used originally as + * a means to share the old AuditConfiguration. + * + * @author Steve Ebersole + */ +public interface EnversService extends Service { + /** + * The name of the configuration setting used to control whether the Envers integration + * is enabled. Default is true + */ + public static final String INTEGRATION_ENABLED = "hibernate.integration.envers.enabled"; + + /** + * The name of the legacy configuration setting used to control whether auto registration + * of envers listeners should happen or not. Default is true + */ + public static final String LEGACY_AUTO_REGISTER = "hibernate.listeners.envers.autoRegister"; + + /** + * Is the Envers integration enabled? This is generally used as a + * protection for other Envers services (in the ServiceLoader sense) + * determine whether they should do their work. + * + * @return {@code true} If the integration is enabled; {@code false} otherwise. + */ + boolean isEnabled(); + + /** + * Assuming {@link #isEnabled()} is {@code true}, has {@link #initialize} + * been called yet? + * + * @return {@code true} indicates {@link #initialize} has been called; {@code false} + * indicates that {@link #initialize} has not (yet) been called. + */ + boolean isInitialized(); + + void initialize(MetadataImplementor metadata, MappingCollector mappingCollector); + + GlobalConfiguration getGlobalConfiguration(); + + AuditEntitiesConfiguration getAuditEntitiesConfiguration(); + + AuditProcessManager getAuditProcessManager(); + + AuditStrategy getAuditStrategy(); + + EntitiesConfigurations getEntitiesConfigurations(); + + RevisionInfoQueryCreator getRevisionInfoQueryCreator(); + + RevisionInfoNumberReader getRevisionInfoNumberReader(); + + ModifiedEntityNamesReader getModifiedEntityNamesReader(); + + ClassLoaderService getClassLoaderService(); +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceContributor.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceContributor.java new file mode 100644 index 0000000000..0359668e4a --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceContributor.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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.boot.internal; + +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.spi.ServiceContributor; + +/** + * ServiceContributor implementation pushing the EnversService into + * the registry + * + * @author Steve Ebersole + */ +public class EnversServiceContributor implements ServiceContributor { + @Override + public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) { + serviceRegistryBuilder.addInitiator( EnversServiceInitiator.INSTANCE ); + } +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceImpl.java new file mode 100644 index 0000000000..27f46ce0ae --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceImpl.java @@ -0,0 +1,304 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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.boot.internal; + +import java.util.Map; +import java.util.Properties; + +import org.hibernate.MappingException; +import org.hibernate.annotations.common.reflection.ReflectionManager; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.engine.config.spi.ConfigurationService; +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.MappingCollector; +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; +import org.hibernate.envers.internal.revisioninfo.ModifiedEntityNamesReader; +import org.hibernate.envers.internal.revisioninfo.RevisionInfoNumberReader; +import org.hibernate.envers.internal.revisioninfo.RevisionInfoQueryCreator; +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.ReflectHelper; +import org.hibernate.internal.util.config.ConfigurationHelper; +import org.hibernate.property.Getter; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.service.spi.Configurable; +import org.hibernate.service.spi.Stoppable; + +import org.jboss.logging.Logger; + +/** + * Provides central access to Envers' configuration. + * + * In many ways, this replaces the legacy static map Envers used originally as + * a means to share the old AuditConfiguration. + * + * @author Steve Ebersole + */ +public class EnversServiceImpl implements EnversService, Configurable, Stoppable { + private static final Logger log = Logger.getLogger( EnversServiceImpl.class ); + + private boolean integrationEnabled; + private boolean initialized; + + private ServiceRegistry serviceRegistry; + private ClassLoaderService classLoaderService; + + // todo : not at all a fan of all these... + // 1) GlobalConfiguration, AuditEntitiesConfiguration and AuditStrategy are + // all "configuration" objects. They seem unnecessarily split apart from + // each other. Why 3? Why not just one? + // 2) AuditProcessManager is a glorified Map of AuditProcess instances (BeforeTransactionCompletionProcess) + // keyed by Transaction (Session) + // 3) Make sure that the info kept here is all really needed at run time, and not just at + // "mapping time" + private GlobalConfiguration globalConfiguration; + private AuditEntitiesConfiguration auditEntitiesConfiguration; + private AuditProcessManager auditProcessManager; + private AuditStrategy auditStrategy; + private EntitiesConfigurations entitiesConfigurations; + private RevisionInfoQueryCreator revisionInfoQueryCreator; + private RevisionInfoNumberReader revisionInfoNumberReader; + private ModifiedEntityNamesReader modifiedEntityNamesReader; + + @Override + public void configure(Map configurationValues) { + final boolean legacySetting = ConfigurationHelper.getBoolean( LEGACY_AUTO_REGISTER, configurationValues, true ); + this.integrationEnabled = ConfigurationHelper.getBoolean( INTEGRATION_ENABLED, configurationValues, legacySetting ); + + log.infof( "Envers integration enabled? : %s", integrationEnabled ); + } + + @Override + public boolean isEnabled() { + return integrationEnabled; + } + + @Override + public boolean isInitialized() { + return initialized; + } + + @Override + public void initialize(final MetadataImplementor metadata, final MappingCollector mappingCollector) { + if ( initialized ) { + throw new UnsupportedOperationException( "EnversService#initialize should be called only once" ); + } + + initialized = true; + + + this.serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry(); + + this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); + + // NOTE : we use the TCCL here for hibernate-commons-annotations + classLoaderService.withTccl( + new ClassLoaderService.Work() { + @Override + public Void perform() { + doInitialize( metadata, mappingCollector, serviceRegistry, classLoaderService ); + return null; + } + } + ); + } + + private void doInitialize( + final MetadataImplementor metadata, + final MappingCollector mappingCollector, + ServiceRegistry serviceRegistry, + ClassLoaderService classLoaderService) { + final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class ); + final Properties properties = new Properties(); + properties.putAll( cfgService.getSettings() ); + + this.globalConfiguration = new GlobalConfiguration( properties, classLoaderService ); + + final ReflectionManager reflectionManager = metadata.getMetadataBuildingOptions() + .getReflectionManager(); + final RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration( globalConfiguration ); + final RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure( + metadata, + reflectionManager + ); + + EnversServiceImpl.this.auditEntitiesConfiguration = new AuditEntitiesConfiguration( + properties, + revInfoCfgResult.getRevisionInfoEntityName() + ); + EnversServiceImpl.this.auditProcessManager = new AuditProcessManager( revInfoCfgResult.getRevisionInfoGenerator() ); + EnversServiceImpl.this.revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator(); + EnversServiceImpl.this.revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader(); + EnversServiceImpl.this.modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader(); + EnversServiceImpl.this.auditStrategy = initializeAuditStrategy( + auditEntitiesConfiguration.getAuditStrategyName(), + revInfoCfgResult.getRevisionInfoClass(), + revInfoCfgResult.getRevisionInfoTimestampData(), + classLoaderService + ); + EnversServiceImpl.this.entitiesConfigurations = new EntitiesConfigurator().configure( + metadata, + serviceRegistry, + reflectionManager, + mappingCollector, + globalConfiguration, + auditEntitiesConfiguration, + auditStrategy, + revInfoCfgResult.getRevisionInfoXmlMapping(), + revInfoCfgResult.getRevisionInfoRelationMapping() + ); + } + + private static AuditStrategy initializeAuditStrategy( + String auditStrategyName, + Class revisionInfoClass, + PropertyData revisionInfoTimestampData, + ClassLoaderService classLoaderService) { + AuditStrategy strategy; + + try { + Class auditStrategyClass = loadClass( auditStrategyName, classLoaderService ); + strategy = (AuditStrategy) ReflectHelper.getDefaultConstructor( auditStrategyClass ).newInstance(); + } + catch (Exception e) { + throw new MappingException( + String.format( "Unable to create AuditStrategy [%s] instance.", auditStrategyName ), + e + ); + } + + if ( strategy instanceof ValidityAuditStrategy ) { + // further initialization required + final Getter revisionTimestampGetter = ReflectionTools.getGetter( + revisionInfoClass, + revisionInfoTimestampData + ); + ( (ValidityAuditStrategy) strategy ).setRevisionTimestampGetter( revisionTimestampGetter ); + } + + return strategy; + } + + /** + * Load a class by name, preferring our ClassLoader and then the ClassLoaderService. + * + * @param auditStrategyName The name of the class to load + * @param classLoaderService The ClassLoaderService + * + * @return The loaded class. + */ + private static Class loadClass(String auditStrategyName, ClassLoaderService classLoaderService) { + try { + return EnversServiceImpl.class.getClassLoader().loadClass( auditStrategyName ); + } + catch (Exception e) { + return ReflectionTools.loadClass( auditStrategyName, classLoaderService ); + } + } + + @Override + public GlobalConfiguration getGlobalConfiguration() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return globalConfiguration; + } + + @Override + public AuditEntitiesConfiguration getAuditEntitiesConfiguration() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return auditEntitiesConfiguration; + } + + @Override + public AuditProcessManager getAuditProcessManager() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return auditProcessManager; + } + + @Override + public AuditStrategy getAuditStrategy() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return auditStrategy; + } + + @Override + public EntitiesConfigurations getEntitiesConfigurations() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return entitiesConfigurations; + } + + @Override + public RevisionInfoQueryCreator getRevisionInfoQueryCreator() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return revisionInfoQueryCreator; + } + + @Override + public RevisionInfoNumberReader getRevisionInfoNumberReader() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return revisionInfoNumberReader; + } + + @Override + public ModifiedEntityNamesReader getModifiedEntityNamesReader() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return modifiedEntityNamesReader; + } + + @Override + public ClassLoaderService getClassLoaderService() { + if ( !initialized ) { + throw new IllegalStateException( "Service is not yet initialized" ); + } + return classLoaderService; + } + + @Override + public void stop() { + // anything to release? + } +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceInitiator.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceInitiator.java new file mode 100644 index 0000000000..ccd67ccda1 --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceInitiator.java @@ -0,0 +1,51 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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.boot.internal; + +import java.util.Map; + +import org.hibernate.boot.registry.StandardServiceInitiator; +import org.hibernate.service.spi.ServiceRegistryImplementor; + +/** + * @author Steve Ebersole + */ +public class EnversServiceInitiator implements StandardServiceInitiator { + /** + * Singleton access + */ + public static final EnversServiceInitiator INSTANCE = new EnversServiceInitiator(); + + @Override + public EnversService initiateService( + Map configurationValues, + ServiceRegistryImplementor registry) { + return new EnversServiceImpl(); + } + + @Override + public Class getServiceInitiated() { + return EnversService.class; + } +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/TypeContributorImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/TypeContributorImpl.java similarity index 86% rename from hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/TypeContributorImpl.java rename to hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/TypeContributorImpl.java index c60751a7d1..786f1121aa 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/TypeContributorImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/TypeContributorImpl.java @@ -21,10 +21,11 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.envers.internal.entities; +package org.hibernate.envers.boot.internal; import org.hibernate.boot.model.TypeContributions; import org.hibernate.boot.model.TypeContributor; +import org.hibernate.envers.internal.entities.RevisionTypeType; import org.hibernate.service.ServiceRegistry; /** @@ -35,6 +36,11 @@ import org.hibernate.service.ServiceRegistry; public class TypeContributorImpl implements TypeContributor { @Override public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { + final EnversService enversService = serviceRegistry.getService( EnversService.class ); + if ( !enversService.isEnabled() ) { + return; + } + typeContributions.contributeType( new RevisionTypeType(), new String[] { RevisionTypeType.class.getName() } 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..fe4338b9ef 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 @@ -37,7 +37,7 @@ import org.hibernate.internal.util.config.ConfigurationHelper; * @author Adam Warski (adam at warski dot org) * @author Stephanie Pau at Markit Group Plc */ -public class AuditEntitiesConfiguration { +public class AuditEntitiesConfiguration { private final String auditTablePrefix; private final String auditTableSuffix; 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..7f56c19a4d 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 @@ -23,18 +23,13 @@ */ package org.hibernate.envers.configuration.internal; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.Writer; import java.util.HashMap; import java.util.Iterator; 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.boot.spi.MetadataImplementor; import org.hibernate.envers.configuration.internal.metadata.AuditEntityNameRegister; import org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator; import org.hibernate.envers.configuration.internal.metadata.EntityXmlMappingData; @@ -45,29 +40,31 @@ 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.service.ServiceRegistry; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; -import org.dom4j.io.DOMWriter; -import org.dom4j.io.OutputFormat; -import org.dom4j.io.XMLWriter; /** * @author Adam Warski (adam at warski dot org) */ public class EntitiesConfigurator { public EntitiesConfigurations configure( - Configuration cfg, ReflectionManager reflectionManager, - GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, - AuditStrategy auditStrategy, ClassLoaderService classLoaderService, - Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) { + MetadataImplementor metadata, + ServiceRegistry serviceRegistry, + ReflectionManager reflectionManager, + MappingCollector mappingCollector, + GlobalConfiguration globalConfiguration, + AuditEntitiesConfiguration auditEntitiesConfiguration, + 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 ) ) + final Iterator classes = GraphTopologicalSort.sort( new PersistentClassGraphDefiner( metadata ) ) .iterator(); final ClassesAuditingData classesAuditingData = new ClassesAuditingData(); @@ -79,7 +76,7 @@ public class EntitiesConfigurator { // Collecting information from annotations on the persistent class pc final AnnotationsMetadataReader annotationsMetadataReader = - new AnnotationsMetadataReader( globalCfg, reflectionManager, pc ); + new AnnotationsMetadataReader( globalConfiguration, reflectionManager, pc ); final ClassAuditingData auditData = annotationsMetadataReader.getAuditData(); classesAuditingData.addClassAuditingData( pc, auditData ); @@ -89,8 +86,13 @@ public class EntitiesConfigurator { classesAuditingData.updateCalculatedFields(); final AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator( - cfg, globalCfg, verEntCfg, auditStrategy, - classLoaderService, revisionInfoRelationMapping, auditEntityNameRegister + metadata, + serviceRegistry, + globalConfiguration, + auditEntitiesConfiguration, + auditStrategy, + revisionInfoRelationMapping, + auditEntityNameRegister ); // First pass @@ -101,7 +103,7 @@ public class EntitiesConfigurator { final EntityXmlMappingData xmlMappingData = new EntityXmlMappingData(); if ( auditData.isAudited() ) { if ( !StringTools.isEmpty( auditData.getAuditTable().value() ) ) { - verEntCfg.addCustomAuditTableName( pc.getEntityName(), auditData.getAuditTable().value() ); + auditEntitiesConfiguration.addCustomAuditTableName( pc.getEntityName(), auditData.getAuditTable().value() ); } auditMetaGen.generateFirstPass( pc, auditData, xmlMappingData, true ); @@ -120,12 +122,10 @@ public class EntitiesConfigurator { if ( pcDatasEntry.getValue().isAudited() ) { auditMetaGen.generateSecondPass( pcDatasEntry.getKey(), pcDatasEntry.getValue(), xmlMappingData ); try { - cfg.addDocument( writer.write( xmlMappingData.getMainXmlMapping() ) ); - //writeDocument(xmlMappingData.getMainXmlMapping()); + mappingCollector.addDocument( xmlMappingData.getMainXmlMapping() ); for ( Document additionalMapping : xmlMappingData.getAdditionalXmlMappings() ) { - cfg.addDocument( writer.write( additionalMapping ) ); - //writeDocument(additionalMapping); + mappingCollector.addDocument( additionalMapping ); } } catch (DocumentException e) { @@ -138,8 +138,7 @@ public class EntitiesConfigurator { if ( auditMetaGen.getEntitiesConfigurations().size() > 0 ) { try { if ( revisionInfoXmlMapping != null ) { - //writeDocument(revisionInfoXmlMapping); - cfg.addDocument( writer.write( revisionInfoXmlMapping ) ); + mappingCollector.addDocument( revisionInfoXmlMapping ); } } catch (DocumentException e) { @@ -152,23 +151,4 @@ public class EntitiesConfigurator { auditMetaGen.getNotAuditedEntitiesConfigurations() ); } - - @SuppressWarnings({"UnusedDeclaration"}) - private void writeDocument(Document e) { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final Writer w = new PrintWriter( baos ); - - try { - final XMLWriter xw = new XMLWriter( w, new OutputFormat( " ", true ) ); - xw.write( e ); - w.flush(); - } - catch (IOException e1) { - e1.printStackTrace(); - } - - System.out.println( "-----------" ); - System.out.println( baos.toString() ); - System.out.println( "-----------" ); - } } 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..5a00a8c018 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,7 +23,7 @@ */ package org.hibernate.envers.configuration.internal; -import java.util.Properties; +import java.util.Map; import org.hibernate.MappingException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; @@ -89,43 +89,63 @@ public class GlobalConfiguration { */ private final String correlatedSubqueryOperator; - public GlobalConfiguration(Properties properties, ClassLoaderService classLoaderService) { + public GlobalConfiguration(Map properties, ClassLoaderService classLoaderService) { generateRevisionsForCollections = ConfigurationHelper.getBoolean( - EnversSettings.REVISION_ON_COLLECTION_CHANGE, properties, true + EnversSettings.REVISION_ON_COLLECTION_CHANGE, + properties, + true ); doNotAuditOptimisticLockingField = ConfigurationHelper.getBoolean( - EnversSettings.DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD, properties, true + EnversSettings.DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD, + properties, + true ); - storeDataAtDelete = ConfigurationHelper.getBoolean( EnversSettings.STORE_DATA_AT_DELETE, properties, false ); + storeDataAtDelete = ConfigurationHelper.getBoolean( + EnversSettings.STORE_DATA_AT_DELETE, + properties, + false + ); - defaultSchemaName = properties.getProperty( EnversSettings.DEFAULT_SCHEMA, null ); - defaultCatalogName = properties.getProperty( EnversSettings.DEFAULT_CATALOG, null ); + defaultSchemaName = (String) properties.get( EnversSettings.DEFAULT_SCHEMA ); + defaultCatalogName = (String) properties.get( EnversSettings.DEFAULT_CATALOG ); - correlatedSubqueryOperator = HSQLDialect.class.getName() - .equals( properties.get( Environment.DIALECT ) ) ? "in" : "="; + correlatedSubqueryOperator = HSQLDialect.class.getName().equals( properties.get( Environment.DIALECT ) ) + ? "in" + : "="; trackEntitiesChangedInRevision = ConfigurationHelper.getBoolean( - EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, properties, false + EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, + properties, + false ); cascadeDeleteRevision = ConfigurationHelper.getBoolean( - "org.hibernate.envers.cascade_delete_revision", properties, false ); + "org.hibernate.envers.cascade_delete_revision", + properties, + false + ); useRevisionEntityWithNativeId = ConfigurationHelper.getBoolean( - EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, properties, true + EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, + properties, + true ); hasGlobalSettingForWithModifiedFlag = properties.get( EnversSettings.GLOBAL_WITH_MODIFIED_FLAG ) != null; globalWithModifiedFlag = ConfigurationHelper.getBoolean( - EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, properties, false + EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, + properties, + false ); modifiedFlagSuffix = ConfigurationHelper.getString( - EnversSettings.MODIFIED_FLAG_SUFFIX, properties, "_MOD" + EnversSettings.MODIFIED_FLAG_SUFFIX, + properties, + "_MOD" ); - final String revisionListenerClassName = properties.getProperty( EnversSettings.REVISION_LISTENER, null ); + final String revisionListenerClassName = (String) properties.get( EnversSettings.REVISION_LISTENER ); if ( revisionListenerClassName != null ) { try { revisionListenerClass = ReflectionTools.loadClass( revisionListenerClassName, classLoaderService ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/MappingCollector.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/MappingCollector.java new file mode 100644 index 0000000000..466ce9f7f5 --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/MappingCollector.java @@ -0,0 +1,38 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2015, 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 org.dom4j.Document; +import org.dom4j.DocumentException; + +/** + * Used in building the AuditConfiguration to allow callbacks for generated audit entities. + * + * The idea here is to allow a Envers to "callback" with any + * + * @author Steve Ebersole + */ +public interface MappingCollector { + void addDocument(Document document) throws DocumentException; +} 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/PersistentClassGraphDefiner.java index c26a22474a..10621d187d 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/PersistentClassGraphDefiner.java @@ -27,7 +27,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.hibernate.cfg.Configuration; +import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.envers.internal.tools.Tools; import org.hibernate.envers.internal.tools.graph.GraphDefiner; import org.hibernate.mapping.PersistentClass; @@ -39,10 +39,10 @@ import org.hibernate.mapping.PersistentClass; * @author Adam Warski (adam at warski dot org) */ public class PersistentClassGraphDefiner implements GraphDefiner { - private Configuration cfg; + private final MetadataImplementor metadata; - public PersistentClassGraphDefiner(Configuration cfg) { - this.cfg = cfg; + public PersistentClassGraphDefiner(MetadataImplementor metadata) { + this.metadata = metadata; } @Override @@ -52,7 +52,7 @@ public class PersistentClassGraphDefiner implements GraphDefiner getValues() { - return Tools.iteratorToList( cfg.getClassMappings() ); + return Tools.collectionToList( metadata.getEntityBindings() ); } } 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..933db43187 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 @@ -24,7 +24,6 @@ package org.hibernate.envers.configuration.internal; import java.util.Date; -import java.util.Iterator; import java.util.Set; import javax.persistence.Column; @@ -32,7 +31,7 @@ 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.boot.spi.MetadataImplementor; import org.hibernate.envers.Audited; import org.hibernate.envers.DefaultRevisionEntity; import org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity; @@ -311,17 +310,15 @@ public class RevisionInfoConfiguration { ); } - public RevisionInfoConfigurationResult configure(Configuration cfg, ReflectionManager reflectionManager) { + public RevisionInfoConfigurationResult configure(MetadataImplementor metadata, ReflectionManager reflectionManager) { boolean revisionEntityFound = false; RevisionInfoGenerator revisionInfoGenerator = null; Class revisionInfoClass = null; - final Iterator classes = cfg.getClassMappings(); - while ( classes.hasNext() ) { - PersistentClass pc = classes.next(); + for ( PersistentClass persistentClass : metadata.getEntityBindings() ) { XClass clazz; try { - clazz = reflectionManager.classForName( pc.getClassName(), this.getClass() ); + clazz = reflectionManager.classForName( persistentClass.getClassName(), this.getClass() ); } catch (ClassNotFoundException e) { throw new MappingException( e ); @@ -366,10 +363,10 @@ public class RevisionInfoConfiguration { ); } - revisionInfoEntityName = pc.getEntityName(); - revisionInfoClass = pc.getMappedClass(); + revisionInfoEntityName = persistentClass.getEntityName(); + revisionInfoClass = persistentClass.getMappedClass(); final Class revisionListenerClass = getRevisionListenerClass( revisionEntity.value() ); - revisionInfoTimestampType = pc.getProperty( revisionInfoTimestampData.getName() ).getType(); + revisionInfoTimestampType = persistentClass.getProperty( revisionInfoTimestampData.getName() ).getType(); if ( globalCfg.isTrackEntitiesChangedInRevision() || (globalCfg.isUseRevisionEntityWithNativeId() && DefaultTrackingModifiedEntitiesRevisionEntity.class .isAssignableFrom( revisionInfoClass )) 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 f24f214390..1e561a0c7a 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 @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.MappingException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.cfg.Configuration; +import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.envers.RelationTargetAuditMode; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; import org.hibernate.envers.configuration.internal.GlobalConfiguration; @@ -53,6 +53,7 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Table; import org.hibernate.mapping.Value; +import org.hibernate.service.ServiceRegistry; import org.hibernate.type.CollectionType; import org.hibernate.type.ComponentType; import org.hibernate.type.ManyToOneType; @@ -79,13 +80,15 @@ public final class AuditMetadataGenerator { AuditMetadataGenerator.class.getName() ); - private final Configuration cfg; + private final MetadataImplementor metadata; + private final ServiceRegistry serviceRegistry; private final GlobalConfiguration globalCfg; private final AuditEntitiesConfiguration verEntCfg; private final AuditStrategy auditStrategy; - private final ClassLoaderService classLoaderService; private final Element revisionInfoRelationMapping; + private final ClassLoaderService classLoaderService; + /* * Generators for different kinds of property values/types. */ @@ -106,16 +109,18 @@ public final class AuditMetadataGenerator { private final Map> entitiesJoins; public AuditMetadataGenerator( - Configuration cfg, GlobalConfiguration globalCfg, + MetadataImplementor metadata, + ServiceRegistry serviceRegistry, + GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, - AuditStrategy auditStrategy, ClassLoaderService classLoaderService, + AuditStrategy auditStrategy, Element revisionInfoRelationMapping, AuditEntityNameRegister auditEntityNameRegister) { - this.cfg = cfg; + this.metadata = metadata; + this.serviceRegistry = serviceRegistry; this.globalCfg = globalCfg; this.verEntCfg = verEntCfg; this.auditStrategy = auditStrategy; - this.classLoaderService = classLoaderService; this.revisionInfoRelationMapping = revisionInfoRelationMapping; this.basicMetadataGenerator = new BasicMetadataGenerator(); @@ -128,6 +133,20 @@ public final class AuditMetadataGenerator { entitiesConfigurations = new HashMap(); notAuditedEntitiesConfigurations = new HashMap(); entitiesJoins = new HashMap>(); + + classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); + } + + public MetadataImplementor getMetadata() { + return metadata; + } + + public ServiceRegistry getServiceRegistry() { + return serviceRegistry; + } + + public ClassLoaderService getClassLoaderService() { + return classLoaderService; } /** @@ -153,12 +172,16 @@ public final class AuditMetadataGenerator { } void addRevisionType(Element anyMapping, Element anyMappingEnd) { + addRevisionType( anyMapping, anyMappingEnd, false ); + } + + void addRevisionType(Element anyMapping, Element anyMappingEnd, boolean isKey) { final Element revTypeProperty = MetadataTools.addProperty( anyMapping, verEntCfg.getRevisionTypePropName(), verEntCfg.getRevisionTypePropType(), true, - false + isKey ); revTypeProperty.addAttribute( "type", "org.hibernate.envers.internal.entities.RevisionTypeType" ); @@ -701,10 +724,6 @@ public final class AuditMetadataGenerator { return basicMetadataGenerator; } - Configuration getCfg() { - return cfg; - } - GlobalConfiguration getGlobalCfg() { return globalCfg; } @@ -717,10 +736,6 @@ public final class AuditMetadataGenerator { 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 3e6f69e776..8ccf74da73 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 @@ -44,6 +44,7 @@ import org.dom4j.Element; * @author Adam Warski (adam at warski dot org) */ public final class BasicMetadataGenerator { + @SuppressWarnings({"unchecked"}) boolean addBasic( Element parent, PropertyAuditingData propertyAuditingData, 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 a333b1ae0a..1fdf9d4caf 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 @@ -403,7 +403,7 @@ public final class CollectionMetadataGenerator { // If the relation is inverse, then referencedEntityName is not null. mappedBy = getMappedBy( propertyValue.getCollectionTable(), - mainGenerator.getCfg().getClassMapping( referencedEntityName ) + mainGenerator.getMetadata().getEntityBinding( referencedEntityName ) ); referencingPrefixRelated = mappedBy + "_"; @@ -602,7 +602,7 @@ public final class CollectionMetadataGenerator { final Element parentXmlMapping = xmlMapping.getParent(); final ComponentAuditingData auditData = new ComponentAuditingData(); - final ReflectionManager reflectionManager = mainGenerator.getCfg().getReflectionManager(); + final ReflectionManager reflectionManager = mainGenerator.getMetadata().getMetadataBuildingOptions().getReflectionManager(); new ComponentAuditedPropertiesReader( ModificationStore.FULL, @@ -828,7 +828,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. @@ -851,7 +852,7 @@ public final class CollectionMetadataGenerator { 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.getMetadata().getClass( manyToOneValue.getReferencedEntityName() ); + referencedClass = manyToOneValue.getMetadata().getEntityBinding( manyToOneValue.getReferencedEntityName() ); } // If there's an @AuditMappedBy specified, returning it directly. 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..5e2f7fd063 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 @@ -60,7 +60,8 @@ public final class ComponentMetadataGenerator { if (propComponent.isDynamic()) { componentClass = ReflectionTools.loadClass( Map.class.getCanonicalName(), - mainGenerator.getClassLoaderService()); + mainGenerator.getClassLoaderService() + ); } else { componentClass = ReflectionTools.loadClass( 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 87f4972648..887e156515 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 @@ -84,11 +84,11 @@ public final class MetadataTools { } else { propMapping = parent.addElement( "property" ); + propMapping.addAttribute( "insert", Boolean.toString( insertable ) ); + propMapping.addAttribute( "update", Boolean.toString( updateable ) ); } propMapping.addAttribute( "name", name ); - propMapping.addAttribute( "insert", Boolean.toString( insertable ) ); - propMapping.addAttribute( "update", Boolean.toString( updateable ) ); if ( type != null ) { propMapping.addAttribute( "type", type ); 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 5b4c7f59ea..ba7fd9802c 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 @@ -260,8 +260,8 @@ public class AuditedPropertiesReader { while ( propertyIter.hasNext() ) { final Property property = propertyIter.next(); addPersistentProperty( property ); - if ( "embedded".equals( property.getPropertyAccessorName() ) && property.getName() - .equals( property.getNodeName() ) ) { + 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 ); 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..b6ccaed6b0 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 @@ -23,18 +23,17 @@ */ package org.hibernate.envers.configuration.spi; -import java.util.HashSet; -import java.util.Map; import java.util.Properties; -import java.util.WeakHashMap; 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.boot.spi.MetadataImplementor; +import org.hibernate.engine.config.spi.ConfigurationService; 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.MappingCollector; import org.hibernate.envers.configuration.internal.RevisionInfoConfiguration; import org.hibernate.envers.configuration.internal.RevisionInfoConfigurationResult; import org.hibernate.envers.internal.entities.EntitiesConfigurations; @@ -46,15 +45,18 @@ 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.property.Getter; +import org.hibernate.service.ServiceRegistry; /** * @author Adam Warski (adam at warski dot org) * @author Stephanie Pau at Markit Group Plc + * @author Steve Ebersole */ public class AuditConfiguration { + private final ServiceRegistry serviceRegistry; + private final GlobalConfiguration globalCfg; private final AuditEntitiesConfiguration auditEntCfg; private final AuditProcessManager auditProcessManager; @@ -63,7 +65,47 @@ public class AuditConfiguration { private final RevisionInfoQueryCreator revisionInfoQueryCreator; private final RevisionInfoNumberReader revisionInfoNumberReader; private final ModifiedEntityNamesReader modifiedEntityNamesReader; - private ClassLoaderService classLoaderService; + + public AuditConfiguration(MetadataImplementor metadata, MappingCollector mappingCollector) { + this.serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry(); + + final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class ); + final Properties properties = new Properties(); + properties.putAll( cfgService.getSettings() ); + + final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); + + this.globalCfg = new GlobalConfiguration( properties, classLoaderService ); + + final ReflectionManager reflectionManager = metadata.getMetadataBuildingOptions().getReflectionManager(); + final RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration( globalCfg ); + final RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure( metadata, 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.auditStrategy = initializeAuditStrategy( + auditEntCfg.getAuditStrategyName(), + revInfoCfgResult.getRevisionInfoClass(), + revInfoCfgResult.getRevisionInfoTimestampData(), + classLoaderService + ); + this.entCfg = new EntitiesConfigurator().configure( + metadata, + serviceRegistry, + reflectionManager, + mappingCollector, + globalCfg, + auditEntCfg, + auditStrategy, + revInfoCfgResult.getRevisionInfoXmlMapping(), + revInfoCfgResult.getRevisionInfoRelationMapping() + ); + + } + public AuditEntitiesConfiguration getAuditEntCfg() { return auditEntCfg; @@ -97,63 +139,20 @@ public class AuditConfiguration { return auditStrategy; } - public ClassLoaderService getClassLoaderService() { - return classLoaderService; - } - - 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() ); - - final Properties properties = cfg.getProperties(); - - 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() - ); - this.entCfg = new EntitiesConfigurator().configure( - cfg, reflectionManager, globalCfg, auditEntCfg, auditStrategy, classLoaderService, - revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping() - ); - - Thread.currentThread().setContextClassLoader( tccl ); - } - - private AuditStrategy initializeAuditStrategy(Class revisionInfoClass, PropertyData revisionInfoTimestampData) { + private static AuditStrategy initializeAuditStrategy( + String auditStrategyName, + Class revisionInfoClass, + PropertyData revisionInfoTimestampData, + ClassLoaderService classLoaderService) { AuditStrategy strategy; try { - Class auditStrategyClass = null; - try { - auditStrategyClass = this.getClass().getClassLoader().loadClass( auditEntCfg.getAuditStrategyName() ); - } - catch (Exception e) { - auditStrategyClass = ReflectionTools.loadClass( - auditEntCfg.getAuditStrategyName(), - classLoaderService - ); - } + Class auditStrategyClass = loadClass( auditStrategyName, classLoaderService ); strategy = (AuditStrategy) ReflectHelper.getDefaultConstructor( auditStrategyClass ).newInstance(); } catch (Exception e) { throw new MappingException( - String.format( "Unable to create AuditStrategy[%s] instance.", auditEntCfg.getAuditStrategyName() ), + String.format( "Unable to create AuditStrategy [%s] instance.", auditStrategyName ), e ); } @@ -167,34 +166,24 @@ public class AuditConfiguration { return strategy; } - private static final Map CFGS = new WeakHashMap(); - - public synchronized static AuditConfiguration getFor(Configuration cfg) { - return getFor( cfg, null ); - } - - public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoaderService classLoaderService) { - AuditConfiguration verCfg = CFGS.get( cfg ); - - if ( verCfg == null ) { - verCfg = new AuditConfiguration( cfg, classLoaderService ); - CFGS.put( cfg, verCfg ); - - cfg.buildMappings(); + /** + * Load a class by name, preferring our ClassLoader and then the ClassLoaderService. + * + * @param auditStrategyName The name of the class to load + * @param classLoaderService The ClassLoaderService + * + * @return The loaded class. + */ + private static Class loadClass(String auditStrategyName, ClassLoaderService classLoaderService) { + try { + return AuditConfiguration.class.getClassLoader().loadClass( auditStrategyName ); + } + catch (Exception e) { + return ReflectionTools.loadClass( auditStrategyName, classLoaderService ); } - - return verCfg; } public void destroy() { - synchronized (AuditConfiguration.class) { - 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() ); - } - } - } - classLoaderService = null; + // Anything we need to release in here? } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java index ab7a00547a..28925c144c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java @@ -30,7 +30,7 @@ import java.util.Set; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.CollectionEntry; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.EntityConfiguration; import org.hibernate.envers.internal.entities.RelationDescription; import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData; @@ -53,8 +53,8 @@ import org.hibernate.persister.collection.AbstractCollectionPersister; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventListener { - protected BaseEnversCollectionEventListener(AuditConfiguration enversConfiguration) { - super( enversConfiguration ); + protected BaseEnversCollectionEventListener(EnversService enversService) { + super( enversService ); } protected final CollectionEntry getCollectionEntry(AbstractCollectionEvent event) { @@ -69,7 +69,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL if ( shouldGenerateRevision( event ) ) { checkIfTransactionInProgress( event.getSession() ); - final AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() ); + final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get( event.getSession() ); final String entityName = event.getAffectedOwnerEntityName(); final String ownerEntityName = ((AbstractCollectionPersister) collectionEntry.getLoadedPersister()).getOwnerEntityName(); @@ -93,7 +93,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL final PersistentCollectionChangeWorkUnit workUnit = new PersistentCollectionChangeWorkUnit( event.getSession(), entityName, - getAuditConfiguration(), + getEnversService(), newColl, collectionEntry, oldColl, @@ -109,7 +109,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL event.getSession(), event.getAffectedOwnerEntityName(), referencingPropertyName, - getAuditConfiguration(), + getEnversService(), event.getAffectedOwnerIdOrNull(), event.getAffectedOwnerOrNull() ) @@ -142,8 +142,8 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL */ protected boolean shouldGenerateRevision(AbstractCollectionEvent event) { final String entityName = event.getAffectedOwnerEntityName(); - return getAuditConfiguration().getGlobalCfg().isGenerateRevisionsForCollections() - && getAuditConfiguration().getEntCfg().isVersioned( entityName ); + return getEnversService().getGlobalConfiguration().isGenerateRevisionsForCollections() + && getEnversService().getEntitiesConfigurations().isVersioned( entityName ); } /** @@ -157,7 +157,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL * be found. */ private RelationDescription searchForRelationDescription(String entityName, String referencingPropertyName) { - final EntityConfiguration configuration = getAuditConfiguration().getEntCfg().get( entityName ); + final EntityConfiguration configuration = getEnversService().getEntitiesConfigurations().get( entityName ); final RelationDescription rd = configuration.getRelationDescription( referencingPropertyName ); if ( rd == null && configuration.getParentEntityName() != null ) { return searchForRelationDescription( configuration.getParentEntityName(), referencingPropertyName ); @@ -175,8 +175,8 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL AbstractCollectionEvent event, RelationDescription rd) { // First computing the relation changes - final List collectionChanges = getAuditConfiguration() - .getEntCfg() + final List collectionChanges = getEnversService() + .getEntitiesConfigurations() .get( collectionEntityName ) .getPropertyMapper() .mapCollectionChanges( @@ -190,14 +190,14 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL // Getting the id mapper for the related entity, as the work units generated will correspond to the related // entities. final String relatedEntityName = rd.getToEntityName(); - final IdMapper relatedIdMapper = getAuditConfiguration().getEntCfg().get( relatedEntityName ).getIdMapper(); + final IdMapper relatedIdMapper = getEnversService().getEntitiesConfigurations().get( relatedEntityName ).getIdMapper(); // For each collection change, generating the bidirectional work unit. for ( PersistentCollectionChangeData changeData : collectionChanges ) { final Object relatedObj = changeData.getChangedElement(); final Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity( relatedObj ); final RevisionType revType = (RevisionType) changeData.getData().get( - getAuditConfiguration().getAuditEntCfg().getRevisionTypePropName() + getEnversService().getAuditEntitiesConfiguration().getRevisionTypePropName() ); // This can be different from relatedEntityName, in case of inheritance (the real entity may be a subclass @@ -209,7 +209,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL event.getSession(), realRelatedEntityName, rd.getMappedByPropertyName(), - getAuditConfiguration(), + getEnversService(), relatedId, relatedObj ); @@ -218,7 +218,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL new FakeBidirectionalRelationWorkUnit( event.getSession(), realRelatedEntityName, - getAuditConfiguration(), + getEnversService(), relatedId, referencingPropertyName, event.getAffectedOwnerOrNull(), @@ -236,7 +236,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL event.getSession(), collectionEntityName, referencingPropertyName, - getAuditConfiguration(), + getEnversService(), event.getAffectedOwnerIdOrNull(), event.getAffectedOwnerOrNull() ) @@ -249,7 +249,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL PersistentCollectionChangeWorkUnit workUnit, RelationDescription rd) { // Checking if this is enabled in configuration ... - if ( !getAuditConfiguration().getGlobalCfg().isGenerateRevisionsForCollections() ) { + if ( !getEnversService().getGlobalConfiguration().isGenerateRevisionsForCollections() ) { return; } @@ -258,9 +258,9 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL // relDesc can be null if this is a collection of simple values (not a relation). if ( rd != null && rd.isBidirectional() ) { final String relatedEntityName = rd.getToEntityName(); - final IdMapper relatedIdMapper = getAuditConfiguration().getEntCfg().get( relatedEntityName ).getIdMapper(); + final IdMapper relatedIdMapper = getEnversService().getEntitiesConfigurations().get( relatedEntityName ).getIdMapper(); - final Set toPropertyNames = getAuditConfiguration().getEntCfg().getToPropertyNames( + final Set toPropertyNames = getEnversService().getEntitiesConfigurations().getToPropertyNames( event.getAffectedOwnerEntityName(), rd.getFromPropertyName(), relatedEntityName @@ -276,7 +276,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL event.getSession(), event.getSession().bestGuessEntityName( relatedObj ), toPropertyName, - getAuditConfiguration(), + getEnversService(), relatedId, relatedObj ) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversEventListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversEventListener.java index f65fcef4a9..890ed80503 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversEventListener.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversEventListener.java @@ -27,7 +27,7 @@ import java.io.Serializable; import java.util.Set; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.RelationDescription; import org.hibernate.envers.internal.entities.RelationType; @@ -47,15 +47,14 @@ import org.hibernate.proxy.HibernateProxy; * @author Michal Skowronek (mskowr at o2 dot pl) */ public abstract class BaseEnversEventListener implements EnversListener { - private AuditConfiguration enversConfiguration; + private final EnversService enversService; - protected BaseEnversEventListener(AuditConfiguration enversConfiguration) { - this.enversConfiguration = enversConfiguration; + protected BaseEnversEventListener(EnversService enversService) { + this.enversService = enversService; } - @Override - public AuditConfiguration getAuditConfiguration() { - return enversConfiguration; + protected EnversService getEnversService() { + return enversService; } protected final void generateBidirectionalCollectionChangeWorkUnits( @@ -66,7 +65,7 @@ public abstract class BaseEnversEventListener implements EnversListener { Object[] oldState, SessionImplementor session) { // Checking if this is enabled in configuration ... - if ( !enversConfiguration.getGlobalCfg().isGenerateRevisionsForCollections() ) { + if ( !enversService.getGlobalConfiguration().isGenerateRevisionsForCollections() ) { return; } @@ -77,7 +76,7 @@ public abstract class BaseEnversEventListener implements EnversListener { for ( int i = 0; i < propertyNames.length; i++ ) { final String propertyName = propertyNames[i]; - final RelationDescription relDesc = enversConfiguration.getEntCfg().getRelationDescription( + final RelationDescription relDesc = enversService.getEntitiesConfigurations().getRelationDescription( entityName, propertyName ); @@ -120,11 +119,11 @@ public abstract class BaseEnversEventListener implements EnversListener { else { toEntityName = session.guessEntityName( value ); - final IdMapper idMapper = enversConfiguration.getEntCfg().get( toEntityName ).getIdMapper(); + final IdMapper idMapper = enversService.getEntitiesConfigurations().get( toEntityName ).getIdMapper(); id = (Serializable) idMapper.mapToIdFromEntity( value ); } - final Set toPropertyNames = enversConfiguration.getEntCfg().getToPropertyNames( + final Set toPropertyNames = enversService.getEntitiesConfigurations().getToPropertyNames( fromEntityName, relDesc.getFromPropertyName(), toEntityName @@ -133,8 +132,12 @@ public abstract class BaseEnversEventListener implements EnversListener { auditProcess.addWorkUnit( new CollectionChangeWorkUnit( - session, toEntityName, - toPropertyName, enversConfiguration, id, value + session, + toEntityName, + toPropertyName, + enversService, + id, + value ) ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListener.java index cd8f36ef90..95ec768f38 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListener.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListener.java @@ -23,18 +23,10 @@ */ package org.hibernate.envers.event.spi; -import org.hibernate.envers.configuration.spi.AuditConfiguration; - /** * Marker interface for Envers listeners for duplication handling. * * @author Steve Ebersole */ public interface EnversListener { - /** - * Get the Envers AuditConfiguration - * - * @return The Envers AuditConfiguration - */ - public AuditConfiguration getAuditConfiguration(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostCollectionRecreateEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostCollectionRecreateEventListenerImpl.java index 0a88a50a05..8ec95867c8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostCollectionRecreateEventListenerImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostCollectionRecreateEventListenerImpl.java @@ -24,7 +24,7 @@ package org.hibernate.envers.event.spi; import org.hibernate.engine.spi.CollectionEntry; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.event.spi.PostCollectionRecreateEvent; import org.hibernate.event.spi.PostCollectionRecreateEventListener; @@ -39,8 +39,8 @@ public class EnversPostCollectionRecreateEventListenerImpl extends BaseEnversCollectionEventListener implements PostCollectionRecreateEventListener { - protected EnversPostCollectionRecreateEventListenerImpl(AuditConfiguration enversConfiguration) { - super( enversConfiguration ); + public EnversPostCollectionRecreateEventListenerImpl(EnversService enversService) { + super( enversService ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostDeleteEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostDeleteEventListenerImpl.java index 79cacd10e3..ec18f5c6ff 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostDeleteEventListenerImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostDeleteEventListenerImpl.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.event.spi; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.synchronization.AuditProcess; import org.hibernate.envers.internal.synchronization.work.AuditWorkUnit; import org.hibernate.envers.internal.synchronization.work.DelWorkUnit; @@ -39,23 +39,23 @@ import org.hibernate.persister.entity.EntityPersister; * @author Steve Ebersole */ public class EnversPostDeleteEventListenerImpl extends BaseEnversEventListener implements PostDeleteEventListener { - protected EnversPostDeleteEventListenerImpl(AuditConfiguration enversConfiguration) { - super( enversConfiguration ); + public EnversPostDeleteEventListenerImpl(EnversService enversService) { + super( enversService ); } @Override public void onPostDelete(PostDeleteEvent event) { final String entityName = event.getPersister().getEntityName(); - if ( getAuditConfiguration().getEntCfg().isVersioned( entityName ) ) { + if ( getEnversService().getEntitiesConfigurations().isVersioned( entityName ) ) { checkIfTransactionInProgress( event.getSession() ); - final AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() ); + final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get( event.getSession() ); final AuditWorkUnit workUnit = new DelWorkUnit( event.getSession(), event.getPersister().getEntityName(), - getAuditConfiguration(), + getEnversService(), event.getId(), event.getPersister(), event.getDeletedState() @@ -77,6 +77,6 @@ public class EnversPostDeleteEventListenerImpl extends BaseEnversEventListener i @Override public boolean requiresPostCommitHanding(EntityPersister persister) { - return getAuditConfiguration().getEntCfg().isVersioned( persister.getEntityName() ); + return getEnversService().getEntitiesConfigurations().isVersioned( persister.getEntityName() ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostInsertEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostInsertEventListenerImpl.java index db3c1d1853..b7f8b18b93 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostInsertEventListenerImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostInsertEventListenerImpl.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.event.spi; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.synchronization.AuditProcess; import org.hibernate.envers.internal.synchronization.work.AddWorkUnit; import org.hibernate.envers.internal.synchronization.work.AuditWorkUnit; @@ -39,23 +39,23 @@ import org.hibernate.persister.entity.EntityPersister; * @author Steve Ebersole */ public class EnversPostInsertEventListenerImpl extends BaseEnversEventListener implements PostInsertEventListener { - protected EnversPostInsertEventListenerImpl(AuditConfiguration enversConfiguration) { - super( enversConfiguration ); + public EnversPostInsertEventListenerImpl(EnversService enversService) { + super( enversService ); } @Override public void onPostInsert(PostInsertEvent event) { final String entityName = event.getPersister().getEntityName(); - if ( getAuditConfiguration().getEntCfg().isVersioned( entityName ) ) { + if ( getEnversService().getEntitiesConfigurations().isVersioned( entityName ) ) { checkIfTransactionInProgress( event.getSession() ); - final AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() ); + final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get( event.getSession() ); final AuditWorkUnit workUnit = new AddWorkUnit( event.getSession(), event.getPersister().getEntityName(), - getAuditConfiguration(), + getEnversService(), event.getId(), event.getPersister(), event.getState() @@ -77,6 +77,6 @@ public class EnversPostInsertEventListenerImpl extends BaseEnversEventListener i @Override public boolean requiresPostCommitHanding(EntityPersister persister) { - return getAuditConfiguration().getEntCfg().isVersioned( persister.getEntityName() ); + return getEnversService().getEntitiesConfigurations().isVersioned( persister.getEntityName() ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostUpdateEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostUpdateEventListenerImpl.java index 956bf01a38..33114b7639 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostUpdateEventListenerImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostUpdateEventListenerImpl.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.event.spi; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.synchronization.AuditProcess; import org.hibernate.envers.internal.synchronization.work.AuditWorkUnit; import org.hibernate.envers.internal.synchronization.work.ModWorkUnit; @@ -39,23 +39,23 @@ import org.hibernate.persister.entity.EntityPersister; * @author Steve Ebersole */ public class EnversPostUpdateEventListenerImpl extends BaseEnversEventListener implements PostUpdateEventListener { - protected EnversPostUpdateEventListenerImpl(AuditConfiguration enversConfiguration) { - super( enversConfiguration ); + public EnversPostUpdateEventListenerImpl(EnversService enversService) { + super( enversService ); } @Override public void onPostUpdate(PostUpdateEvent event) { final String entityName = event.getPersister().getEntityName(); - if ( getAuditConfiguration().getEntCfg().isVersioned( entityName ) ) { + if ( getEnversService().getEntitiesConfigurations().isVersioned( entityName ) ) { checkIfTransactionInProgress( event.getSession() ); - final AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() ); + final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get( event.getSession() ); final Object[] newDbState = postUpdateDBState( event ); final AuditWorkUnit workUnit = new ModWorkUnit( event.getSession(), event.getPersister().getEntityName(), - getAuditConfiguration(), + getEnversService(), event.getId(), event.getPersister(), newDbState, @@ -93,6 +93,6 @@ public class EnversPostUpdateEventListenerImpl extends BaseEnversEventListener i @Override public boolean requiresPostCommitHanding(EntityPersister persister) { - return getAuditConfiguration().getEntCfg().isVersioned( persister.getEntityName() ); + return getEnversService().getEntitiesConfigurations().isVersioned( persister.getEntityName() ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionRemoveEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionRemoveEventListenerImpl.java index 61a3c1a5ca..e352efa8fe 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionRemoveEventListenerImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionRemoveEventListenerImpl.java @@ -26,7 +26,7 @@ package org.hibernate.envers.event.spi; import java.io.Serializable; import org.hibernate.engine.spi.CollectionEntry; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.event.spi.PreCollectionRemoveEvent; import org.hibernate.event.spi.PreCollectionRemoveEventListener; @@ -42,8 +42,8 @@ public class EnversPreCollectionRemoveEventListenerImpl extends BaseEnversCollectionEventListener implements PreCollectionRemoveEventListener { - protected EnversPreCollectionRemoveEventListenerImpl(AuditConfiguration enversConfiguration) { - super( enversConfiguration ); + public EnversPreCollectionRemoveEventListenerImpl(EnversService enversService) { + super( enversService ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionUpdateEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionUpdateEventListenerImpl.java index b416349ce6..daa5748d31 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionUpdateEventListenerImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionUpdateEventListenerImpl.java @@ -24,7 +24,7 @@ package org.hibernate.envers.event.spi; import org.hibernate.engine.spi.CollectionEntry; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.event.spi.PreCollectionUpdateEvent; import org.hibernate.event.spi.PreCollectionUpdateEventListener; @@ -39,8 +39,8 @@ public class EnversPreCollectionUpdateEventListenerImpl extends BaseEnversCollectionEventListener implements PreCollectionUpdateEventListener { - protected EnversPreCollectionUpdateEventListenerImpl(AuditConfiguration enversConfiguration) { - super( enversConfiguration ); + public EnversPreCollectionUpdateEventListenerImpl(EnversService enversService) { + super( enversService ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java index 3f3a39936c..2540d9f36a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java @@ -39,7 +39,6 @@ import static org.jboss.logging.Logger.Level.WARN; */ @MessageLogger(projectCode = "HHH") public interface EnversMessageLogger extends CoreMessageLogger { - /** * Message indicating that user attempted to use the deprecated ValidTimeAuditStrategy */ diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java index acac9babe8..be5a166cb4 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.Map; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.mapper.id.IdMapper; import org.hibernate.envers.internal.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor; @@ -44,11 +44,11 @@ import org.hibernate.proxy.LazyInitializer; * @author Hernán Chanfreau */ public class EntityInstantiator { - private final AuditConfiguration verCfg; + private final EnversService enversService; private final AuditReaderImplementor versionsReader; - public EntityInstantiator(AuditConfiguration verCfg, AuditReaderImplementor versionsReader) { - this.verCfg = verCfg; + public EntityInstantiator(EnversService enversService, AuditReaderImplementor versionsReader) { + this.enversService = enversService; this.versionsReader = versionsReader; } @@ -68,15 +68,19 @@ public class EntityInstantiator { } // The $type$ property holds the name of the (versions) entity - final String type = verCfg.getEntCfg().getEntityNameForVersionsEntityName( (String) versionsEntity.get( "$type$" ) ); + final String type = enversService.getEntitiesConfigurations() + .getEntityNameForVersionsEntityName( (String) versionsEntity.get( "$type$" ) ); if ( type != null ) { entityName = type; } // First mapping the primary key - final IdMapper idMapper = verCfg.getEntCfg().get( entityName ).getIdMapper(); - final Map originalId = (Map) versionsEntity.get( verCfg.getAuditEntCfg().getOriginalIdPropName() ); + final IdMapper idMapper = enversService.getEntitiesConfigurations().get( entityName ).getIdMapper(); + final Map originalId = (Map) versionsEntity.get( + enversService.getAuditEntitiesConfiguration() + .getOriginalIdPropName() + ); // Fixes HHH-4751 issue (@IdClass with @ManyToOne relation mapping inside) // Note that identifiers are always audited @@ -93,13 +97,13 @@ public class EntityInstantiator { // If it is not in the cache, creating a new entity instance Object ret; try { - EntityConfiguration entCfg = verCfg.getEntCfg().get( entityName ); + EntityConfiguration entCfg = enversService.getEntitiesConfigurations().get( entityName ); if ( entCfg == null ) { // a relation marked as RelationTargetAuditMode.NOT_AUDITED - entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration( entityName ); + entCfg = enversService.getEntitiesConfigurations().getNotVersionEntityConfiguration( entityName ); } - final Class cls = ReflectionTools.loadClass( entCfg.getEntityClassName(), verCfg.getClassLoaderService() ); + final Class cls = ReflectionTools.loadClass( entCfg.getEntityClassName(), enversService.getClassLoaderService() ); ret = ReflectHelper.getDefaultConstructor( cls ).newInstance(); } catch (Exception e) { @@ -110,8 +114,8 @@ public class EntityInstantiator { // relation is present (which is eagerly loaded). versionsReader.getFirstLevelCache().put( entityName, revision, primaryKey, ret ); - verCfg.getEntCfg().get( entityName ).getPropertyMapper().mapToEntityFromMap( - verCfg, + enversService.getEntitiesConfigurations().get( entityName ).getPropertyMapper().mapToEntityFromMap( + enversService, ret, versionsEntity, primaryKey, @@ -128,7 +132,7 @@ public class EntityInstantiator { @SuppressWarnings({"unchecked"}) private void replaceNonAuditIdProxies(Map versionsEntity, Number revision) { - final Map originalId = (Map) versionsEntity.get( verCfg.getAuditEntCfg().getOriginalIdPropName() ); + final Map originalId = (Map) versionsEntity.get( enversService.getAuditEntitiesConfiguration().getOriginalIdPropName() ); for ( Object key : originalId.keySet() ) { final Object value = originalId.get( key ); if ( value instanceof HibernateProxy ) { @@ -136,21 +140,23 @@ public class EntityInstantiator { final LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer(); final String entityName = initializer.getEntityName(); final Serializable entityId = initializer.getIdentifier(); - if ( verCfg.getEntCfg().isVersioned( entityName ) ) { - final String entityClassName = verCfg.getEntCfg().get( entityName ).getEntityClassName(); + if ( enversService.getEntitiesConfigurations().isVersioned( entityName ) ) { + final String entityClassName = enversService.getEntitiesConfigurations().get( entityName ).getEntityClassName(); final Class entityClass = ReflectionTools.loadClass( entityClassName, - verCfg.getClassLoaderService() + enversService.getClassLoaderService() ); final ToOneDelegateSessionImplementor delegate = new ToOneDelegateSessionImplementor( - versionsReader, entityClass, entityId, revision, + versionsReader, + entityClass, + entityId, + revision, RevisionType.DEL.equals( versionsEntity.get( - verCfg.getAuditEntCfg() - .getRevisionTypePropName() + enversService.getAuditEntitiesConfiguration().getRevisionTypePropName() ) ), - verCfg + enversService ); originalId.put( key, @@ -175,8 +181,8 @@ public class EntityInstantiator { } } - public AuditConfiguration getAuditConfiguration() { - return verCfg; + public EnversService getEnversService() { + return enversService; } public AuditReaderImplementor getAuditReaderImplementor() { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java index a648efba17..e0482f2af0 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java @@ -30,7 +30,7 @@ import java.util.Map; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -115,7 +115,7 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB @Override public void mapToEntityFromMap( - AuditConfiguration verCfg, + EnversService enversService, Object obj, Map data, Object primaryKey, @@ -128,7 +128,7 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB if ( propertyData.getBeanName() == null ) { // If properties are not encapsulated in a component but placed directly in a class // (e.g. by applying tag). - delegate.mapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + delegate.mapToEntityFromMap( enversService, obj, data, primaryKey, versionsReader, revision ); return; } @@ -155,7 +155,7 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB try { final Object subObj = ReflectHelper.getDefaultConstructor( componentClass ).newInstance(); setter.set( obj, subObj, null ); - delegate.mapToEntityFromMap( verCfg, subObj, data, primaryKey, versionsReader, revision ); + delegate.mapToEntityFromMap( enversService, subObj, data, primaryKey, versionsReader, revision ); } catch ( Exception e ) { throw new AuditException( e ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiDynamicComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiDynamicComponentMapper.java index ca82beb849..f26acd55cb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiDynamicComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiDynamicComponentMapper.java @@ -3,7 +3,7 @@ package org.hibernate.envers.internal.entities.mapper; import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.MapProxyTool; @@ -86,18 +86,23 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper { } @Override + @SuppressWarnings("unchecked") public void mapToEntityFromMap( - AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { + EnversService enversService, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { Object mapProxy = MapProxyTool.newInstanceOfBeanProxyForMap( - generateClassName( - data, - dynamicComponentData.getBeanName() - ), (Map) obj, properties.keySet(), verCfg.getClassLoaderService() + generateClassName( data, dynamicComponentData.getBeanName() ), + (Map) obj, + properties.keySet(), + enversService.getClassLoaderService() ); for ( PropertyData propertyData : properties.keySet() ) { PropertyMapper mapper = properties.get( propertyData ); - mapper.mapToEntityFromMap( verCfg, mapProxy, data, primaryKey, versionsReader, revision ); + mapper.mapToEntityFromMap( enversService, mapProxy, data, primaryKey, versionsReader, revision ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java index 96c39c24e0..81295a9df1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.MappingTools; @@ -166,10 +166,14 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper { @Override public void mapToEntityFromMap( - AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { + EnversService enversService, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { for ( PropertyMapper mapper : properties.values() ) { - mapper.mapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + mapper.mapToEntityFromMap( enversService, obj, data, primaryKey, versionsReader, revision ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PropertyMapper.java index 43d6acaa14..8bf316a2d1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PropertyMapper.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; /** @@ -52,7 +52,7 @@ public interface PropertyMapper { /** * Maps properties from the given map to the given object. * - * @param verCfg Versions configuration. + * @param enversService The EnversService. * @param obj Object to map to. * @param data Data to map from. * @param primaryKey Primary key of the object to which we map (for relations) @@ -60,8 +60,12 @@ public interface PropertyMapper { * @param revision Revision at which the object is read, for reading relations */ void mapToEntityFromMap( - AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision); + EnversService enversService, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision); /** * Maps collection changes. diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java index f45f026640..ef1eb1d992 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java @@ -31,7 +31,7 @@ import org.hibernate.HibernateException; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -99,8 +99,12 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder @Override public void mapToEntityFromMap( - AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { + EnversService enversService, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { if ( data == null || obj == null ) { return; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java index 3696a30dd6..280845ff0f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java @@ -30,7 +30,7 @@ import java.util.Map; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -93,14 +93,14 @@ public class SubclassPropertyMapper implements ExtendedPropertyMapper { @Override public void mapToEntityFromMap( - AuditConfiguration verCfg, + EnversService enversService, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { - parentMapper.mapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); - main.mapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + parentMapper.mapToEntityFromMap( enversService, obj, data, primaryKey, versionsReader, revision ); + main.mapToEntityFromMap( enversService, obj, data, primaryKey, versionsReader, revision ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java index dbf7443853..ee578a0c21 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java @@ -37,7 +37,7 @@ import java.util.Set; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData; @@ -246,14 +246,20 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { } protected abstract Initializor getInitializor( - AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Object primaryKey, - Number revision, boolean removed); + EnversService enversService, + AuditReaderImplementor versionsReader, + Object primaryKey, + Number revision, + boolean removed); @Override public void mapToEntityFromMap( - AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { + EnversService enversService, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { final Setter setter = ReflectionTools.getSetter( obj.getClass(), commonCollectionMapperData.getCollectionReferencingPropertyData() @@ -263,11 +269,13 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { obj, proxyConstructor.newInstance( getInitializor( - verCfg, versionsReader, primaryKey, revision, + enversService, + versionsReader, + primaryKey, + revision, RevisionType.DEL.equals( data.get( - verCfg.getAuditEntCfg() - .getRevisionTypePropName() + enversService.getAuditEntitiesConfiguration().getRevisionTypePropName() ) ) ) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractOneToOneMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractOneToOneMapper.java index b39fe53495..61701638b5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractOneToOneMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractOneToOneMapper.java @@ -29,7 +29,7 @@ import javax.persistence.NoResultException; import org.hibernate.NonUniqueResultException; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -51,9 +51,13 @@ public abstract class AbstractOneToOneMapper extends AbstractToOneMapper { @Override public void nullSafeMapToEntityFromMap( - AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { - final EntityInfo referencedEntity = getEntityInfo( verCfg, referencedEntityName ); + EnversService enversService, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { + final EntityInfo referencedEntity = getEntityInfo( enversService, referencedEntityName ); Object value; try { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java index ef292e3280..3352d46c11 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.EntityConfiguration; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData; @@ -61,36 +61,42 @@ public abstract class AbstractToOneMapper implements PropertyMapper { @Override public void mapToEntityFromMap( - AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { + EnversService enversService, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { if ( obj != null ) { - nullSafeMapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + nullSafeMapToEntityFromMap( enversService, obj, data, primaryKey, versionsReader, revision ); } } @Override public List mapCollectionChanges( - SessionImplementor session, String referencingPropertyName, - PersistentCollection newColl, Serializable oldColl, + SessionImplementor session, + String referencingPropertyName, + PersistentCollection newColl, + Serializable oldColl, Serializable id) { return null; } /** - * @param verCfg Audit configuration. + * @param enversService The EnversService * @param entityName Entity name. * * @return Entity class, name and information whether it is audited or not. */ - protected EntityInfo getEntityInfo(AuditConfiguration verCfg, String entityName) { - EntityConfiguration entCfg = verCfg.getEntCfg().get( entityName ); + protected EntityInfo getEntityInfo(EnversService enversService, String entityName) { + EntityConfiguration entCfg = enversService.getEntitiesConfigurations().get( entityName ); boolean isRelationAudited = true; if ( entCfg == null ) { // a relation marked as RelationTargetAuditMode.NOT_AUDITED - entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration( entityName ); + entCfg = enversService.getEntitiesConfigurations().getNotVersionEntityConfiguration( entityName ); isRelationAudited = false; } - final Class entityClass = ReflectionTools.loadClass( entCfg.getEntityClassName(), verCfg.getClassLoaderService() ); + final Class entityClass = ReflectionTools.loadClass( entCfg.getEntityClassName(), enversService.getClassLoaderService() ); return new EntityInfo( entityClass, entityName, isRelationAudited ); } @@ -108,11 +114,9 @@ public abstract class AbstractToOneMapper implements PropertyMapper { /** * Parameter {@code obj} is never {@code null}. - * - * @see PropertyMapper#mapToEntityFromMap(AuditConfiguration, Object, Map, Object, AuditReaderImplementor, Number) */ public abstract void nullSafeMapToEntityFromMap( - AuditConfiguration verCfg, + EnversService enversService, Object obj, Map data, Object primaryKey, diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java index 2b11620037..fee6b9ef35 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.PropertyMapper; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.BasicCollectionInitializor; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor; @@ -43,19 +43,31 @@ public class BasicCollectionMapper extends AbstractCollect public BasicCollectionMapper( CommonCollectionMapperData commonCollectionMapperData, - Class collectionClass, Class proxyClass, - MiddleComponentData elementComponentData, boolean ordinalInId, boolean revisionTypeInId) { + Class collectionClass, + Class proxyClass, + MiddleComponentData elementComponentData, + boolean ordinalInId, + boolean revisionTypeInId) { super( commonCollectionMapperData, collectionClass, proxyClass, ordinalInId, revisionTypeInId ); this.elementComponentData = elementComponentData; } @Override protected Initializor getInitializor( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { + EnversService enversService, + AuditReaderImplementor versionsReader, + Object primaryKey, + Number revision, + boolean removed) { return new BasicCollectionInitializor( - verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, collectionClass, elementComponentData + enversService, + versionsReader, + commonCollectionMapperData.getQueryGenerator(), + primaryKey, + revision, + removed, + collectionClass, + elementComponentData ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ListCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ListCollectionMapper.java index 8468c0628b..e96cf3a315 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ListCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ListCollectionMapper.java @@ -30,7 +30,7 @@ import java.util.Map; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.PropertyMapper; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor; @@ -57,11 +57,20 @@ public final class ListCollectionMapper extends AbstractCollectionMapper i @Override protected Initializor getInitializor( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { + EnversService enversService, + AuditReaderImplementor versionsReader, + Object primaryKey, + Number revision, + boolean removed) { return new ListCollectionInitializor( - verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, elementComponentData, indexComponentData + enversService, + versionsReader, + commonCollectionMapperData.getQueryGenerator(), + primaryKey, + revision, + removed, + elementComponentData, + indexComponentData ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java index e6323e9c15..07fc8b5d32 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.PropertyMapper; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.MapCollectionInitializor; @@ -54,11 +54,21 @@ public class MapCollectionMapper extends AbstractCollectionMapper @Override protected Initializor getInitializor( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { + EnversService enversService, + AuditReaderImplementor versionsReader, + Object primaryKey, + Number revision, + boolean removed) { return new MapCollectionInitializor( - verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, collectionClass, elementComponentData, indexComponentData + enversService, + versionsReader, + commonCollectionMapperData.getQueryGenerator(), + primaryKey, + revision, + removed, + collectionClass, + elementComponentData, + indexComponentData ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedMapCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedMapCollectionMapper.java index 5b04d239d5..d7e8aed9d6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedMapCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedMapCollectionMapper.java @@ -26,7 +26,7 @@ package org.hibernate.envers.internal.entities.mapper.relation; import java.util.Comparator; import java.util.SortedMap; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.SortedMapCollectionInitializor; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -55,11 +55,22 @@ public final class SortedMapCollectionMapper extends MapCollectionMapper getInitializor( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { + EnversService enversService, + AuditReaderImplementor versionsReader, + Object primaryKey, + Number revision, + boolean removed) { return new SortedMapCollectionInitializor( - verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, collectionClass, elementComponentData, indexComponentData, comparator + enversService, + versionsReader, + commonCollectionMapperData.getQueryGenerator(), + primaryKey, + revision, + removed, + collectionClass, + elementComponentData, + indexComponentData, + comparator ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedSetCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedSetCollectionMapper.java index fd275143e2..a28a1ba059 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedSetCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedSetCollectionMapper.java @@ -26,7 +26,7 @@ package org.hibernate.envers.internal.entities.mapper.relation; import java.util.Comparator; import java.util.SortedSet; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.SortedSetCollectionInitializor; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -55,11 +55,21 @@ public final class SortedSetCollectionMapper extends BasicCollectionMapper getInitializor( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { + EnversService enversService, + AuditReaderImplementor versionsReader, + Object primaryKey, + Number revision, + boolean removed) { return new SortedSetCollectionInitializor( - verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, collectionClass, elementComponentData, comparator + enversService, + versionsReader, + commonCollectionMapperData.getQueryGenerator(), + primaryKey, + revision, + removed, + collectionClass, + elementComponentData, + comparator ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java index d26d43e3f8..2f70bd6fc6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java @@ -25,7 +25,7 @@ package org.hibernate.envers.internal.entities.mapper.relation; import java.io.Serializable; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.persister.entity.EntityPersister; @@ -48,8 +48,8 @@ public final class ToOneEntityLoader { Object entityId, Number revision, boolean removed, - AuditConfiguration verCfg) { - if ( verCfg.getEntCfg().getNotVersionEntityConfiguration( entityName ) == null ) { + EnversService enversService) { + if ( enversService.getEntitiesConfigurations().getNotVersionEntityConfiguration( entityName ) == null ) { // Audited relation, look up entity with Envers. // When user traverses removed entities graph, do not restrict revision type of referencing objects // to ADD or MOD (DEL possible). See HHH-5845. @@ -71,13 +71,13 @@ public final class ToOneEntityLoader { Object entityId, Number revision, boolean removed, - AuditConfiguration verCfg) { + EnversService enversService) { final EntityPersister persister = versionsReader.getSessionImplementor() .getFactory() .getEntityPersister( entityName ); return persister.createProxy( (Serializable) entityId, - new ToOneDelegateSessionImplementor( versionsReader, entityClass, entityId, revision, removed, verCfg ) + new ToOneDelegateSessionImplementor( versionsReader, entityClass, entityId, revision, removed, enversService ) ); } @@ -92,13 +92,13 @@ public final class ToOneEntityLoader { Object entityId, Number revision, boolean removed, - AuditConfiguration verCfg) { + EnversService enversService) { final EntityPersister persister = versionsReader.getSessionImplementor() .getFactory() .getEntityPersister( entityName ); if ( persister.hasProxy() ) { - return createProxy( versionsReader, entityClass, entityName, entityId, revision, removed, verCfg ); + return createProxy( versionsReader, entityClass, entityName, entityId, revision, removed, enversService ); } - return loadImmediate( versionsReader, entityClass, entityName, entityId, revision, removed, verCfg ); + return loadImmediate( versionsReader, entityClass, entityName, entityId, revision, removed, enversService ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java index 2f5b85c24f..a49f39a771 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java @@ -28,7 +28,7 @@ import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.entities.mapper.id.IdMapper; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -45,8 +45,11 @@ public class ToOneIdMapper extends AbstractToOneMapper { private final String referencedEntityName; private final boolean nonInsertableFake; - public ToOneIdMapper(IdMapper delegate, PropertyData propertyData, String referencedEntityName, - boolean nonInsertableFake) { + public ToOneIdMapper( + IdMapper delegate, + PropertyData propertyData, + String referencedEntityName, + boolean nonInsertableFake) { super( propertyData ); this.delegate = delegate; this.referencedEntityName = referencedEntityName; @@ -54,8 +57,11 @@ public class ToOneIdMapper extends AbstractToOneMapper { } @Override - public boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, - Object oldObj) { + public boolean mapToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { final HashMap newData = new HashMap(); // If this property is originally non-insertable, but made insertable because it is in a many-to-one "fake" @@ -71,8 +77,11 @@ public class ToOneIdMapper extends AbstractToOneMapper { } @Override - public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, - Object oldObj) { + public void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { if ( getPropertyData().isUsingModifiedFlag() ) { data.put( getPropertyData().getModifiedFlagPropertyName(), checkModified( session, newObj, oldObj ) ); } @@ -94,8 +103,13 @@ public class ToOneIdMapper extends AbstractToOneMapper { } @Override - public void nullSafeMapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { + public void nullSafeMapToEntityFromMap( + EnversService enversService, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { final Object entityId = delegate.mapToIdFromMap( data ); Object value = null; if ( entityId != null ) { @@ -103,26 +117,34 @@ public class ToOneIdMapper extends AbstractToOneMapper { value = versionsReader.getFirstLevelCache().get( referencedEntityName, revision, entityId ); } else { - final EntityInfo referencedEntity = getEntityInfo( verCfg, referencedEntityName ); + final EntityInfo referencedEntity = getEntityInfo( enversService, referencedEntityName ); boolean ignoreNotFound = false; if ( !referencedEntity.isAudited() ) { - final String referencingEntityName = verCfg.getEntCfg().getEntityNameForVersionsEntityName( (String) data.get( "$type$" ) ); - ignoreNotFound = verCfg.getEntCfg().getRelationDescription( referencingEntityName, getPropertyData().getName() ).isIgnoreNotFound(); + final String referencingEntityName = enversService.getEntitiesConfigurations().getEntityNameForVersionsEntityName( (String) data.get( "$type$" ) ); + ignoreNotFound = enversService.getEntitiesConfigurations().getRelationDescription( referencingEntityName, getPropertyData().getName() ).isIgnoreNotFound(); } if ( ignoreNotFound ) { // Eagerly loading referenced entity to silence potential (in case of proxy) // EntityNotFoundException or ObjectNotFoundException. Assigning null reference. value = ToOneEntityLoader.loadImmediate( - versionsReader, referencedEntity.getEntityClass(), referencedEntityName, - entityId, revision, RevisionType.DEL.equals( data.get( verCfg.getAuditEntCfg().getRevisionTypePropName() ) ), - verCfg + versionsReader, + referencedEntity.getEntityClass(), + referencedEntityName, + entityId, + revision, + RevisionType.DEL.equals( data.get( enversService.getAuditEntitiesConfiguration().getRevisionTypePropName() ) ), + enversService ); } else { value = ToOneEntityLoader.createProxyOrLoadImmediate( - versionsReader, referencedEntity.getEntityClass(), referencedEntityName, - entityId, revision, RevisionType.DEL.equals( data.get( verCfg.getAuditEntCfg().getRevisionTypePropName() ) ), - verCfg + versionsReader, + referencedEntity.getEntityClass(), + referencedEntityName, + entityId, + revision, + RevisionType.DEL.equals( data.get( enversService.getAuditEntitiesConfiguration().getRevisionTypePropName() ) ), + enversService ); } } @@ -131,8 +153,12 @@ public class ToOneIdMapper extends AbstractToOneMapper { setPropertyValue( obj, value ); } - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, - String idPrefix2, String prefix2) { + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { delegate.addIdsEqualToQuery( parameters, prefix1, delegate, prefix2 ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleEmbeddableComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleEmbeddableComponentMapper.java index 402a42d917..c5297a92ab 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleEmbeddableComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleEmbeddableComponentMapper.java @@ -55,12 +55,16 @@ public class MiddleEmbeddableComponentMapper implements MiddleComponentMapper, C Object dataObject, Number revision) { try { - final Object componentInstance = dataObject != null ? dataObject : ReflectHelper.getDefaultConstructor( - componentClass - ).newInstance(); + final Object componentInstance = dataObject != null + ? dataObject + : ReflectHelper.getDefaultConstructor( componentClass ).newInstance(); delegate.mapToEntityFromMap( - entityInstantiator.getAuditConfiguration(), componentInstance, data, null, - entityInstantiator.getAuditReaderImplementor(), revision + entityInstantiator.getEnversService(), + componentInstance, + data, + null, + entityInstantiator.getAuditReaderImplementor(), + revision ); return componentInstance; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java index 23f1855490..8c9dd83ecc 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java @@ -24,7 +24,7 @@ package org.hibernate.envers.internal.entities.mapper.relation.lazy; import org.hibernate.HibernateException; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.relation.ToOneEntityLoader; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -41,19 +41,22 @@ public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImpl private final Object entityId; private final Number revision; private final boolean removed; - private final AuditConfiguration verCfg; + private final EnversService enversService; public ToOneDelegateSessionImplementor( AuditReaderImplementor versionsReader, - Class entityClass, Object entityId, Number revision, boolean removed, - AuditConfiguration verCfg) { + Class entityClass, + Object entityId, + Number revision, + boolean removed, + EnversService enversService) { super( versionsReader.getSessionImplementor() ); this.versionsReader = versionsReader; this.entityClass = entityClass; this.entityId = entityId; this.revision = revision; this.removed = removed; - this.verCfg = verCfg; + this.enversService = enversService; } @Override @@ -65,7 +68,7 @@ public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImpl entityId, revision, removed, - verCfg + enversService ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java index 55f91f2542..b82e24b2e7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java @@ -25,7 +25,7 @@ package org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor; import java.util.List; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.EntityInstantiator; import org.hibernate.envers.internal.entities.mapper.relation.query.RelationQueryGenerator; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -44,7 +44,7 @@ public abstract class AbstractCollectionInitializor implements Initializor protected final EntityInstantiator entityInstantiator; public AbstractCollectionInitializor( - AuditConfiguration verCfg, + EnversService enversService, AuditReaderImplementor versionsReader, RelationQueryGenerator queryGenerator, Object primaryKey, Number revision, boolean removed) { @@ -54,7 +54,7 @@ public abstract class AbstractCollectionInitializor implements Initializor this.revision = revision; this.removed = removed; - entityInstantiator = new EntityInstantiator( verCfg, versionsReader ); + entityInstantiator = new EntityInstantiator( enversService, versionsReader ); } protected abstract T initializeCollection(int size); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java index 4923f4250d..94511ee3d1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java @@ -26,7 +26,7 @@ package org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.internal.entities.mapper.relation.query.RelationQueryGenerator; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -41,13 +41,13 @@ public class ArrayCollectionInitializor extends AbstractCollectionInitializor extends AbstractCo private final MiddleComponentData elementComponentData; public BasicCollectionInitializor( - AuditConfiguration verCfg, + EnversService enversService, AuditReaderImplementor versionsReader, RelationQueryGenerator queryGenerator, Object primaryKey, Number revision, boolean removed, Class collectionClass, MiddleComponentData elementComponentData) { - super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed ); + super( enversService, versionsReader, queryGenerator, primaryKey, revision, removed ); this.collectionClass = collectionClass; this.elementComponentData = elementComponentData; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java index 851254631d..3205a5edb8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java @@ -27,7 +27,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.internal.entities.mapper.relation.query.RelationQueryGenerator; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -42,13 +42,15 @@ public class ListCollectionInitializor extends AbstractCollectionInitializor extends AbstractCollectionI private final MiddleComponentData indexComponentData; public MapCollectionInitializor( - AuditConfiguration verCfg, + EnversService enversService, AuditReaderImplementor versionsReader, RelationQueryGenerator queryGenerator, Object primaryKey, Number revision, boolean removed, Class collectionClass, MiddleComponentData elementComponentData, MiddleComponentData indexComponentData) { - super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed ); + super( enversService, versionsReader, queryGenerator, primaryKey, revision, removed ); this.collectionClass = collectionClass; this.elementComponentData = elementComponentData; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedMapCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedMapCollectionInitializor.java index 562d4f3546..a2ce9fd807 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedMapCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedMapCollectionInitializor.java @@ -27,7 +27,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Comparator; import java.util.SortedMap; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.internal.entities.mapper.relation.query.RelationQueryGenerator; @@ -42,7 +42,7 @@ public class SortedMapCollectionInitializor extends MapCollectionInitializor collectionClass, MiddleComponentData elementComponentData, + EnversService enversService, + AuditReaderImplementor versionsReader, + RelationQueryGenerator queryGenerator, + Object primaryKey, + Number revision, + boolean removed, + Class collectionClass, + MiddleComponentData elementComponentData, Comparator comparator) { super( - verCfg, + enversService, versionsReader, queryGenerator, primaryKey, diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java index 1e49360dfd..30d99203a1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java @@ -37,7 +37,7 @@ import org.hibernate.NonUniqueResultException; import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.CrossTypeRevisionChangesReader; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -57,21 +57,22 @@ import static org.hibernate.envers.internal.tools.EntityTools.getTargetClassIfPr * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class AuditReaderImpl implements AuditReaderImplementor { - private final AuditConfiguration verCfg; + private final EnversService enversService; private final SessionImplementor sessionImplementor; private final Session session; private final FirstLevelCache firstLevelCache; private final CrossTypeRevisionChangesReader crossTypeRevisionChangesReader; public AuditReaderImpl( - AuditConfiguration verCfg, Session session, + EnversService enversService, + Session session, SessionImplementor sessionImplementor) { - this.verCfg = verCfg; + this.enversService = enversService; this.sessionImplementor = sessionImplementor; this.session = session; firstLevelCache = new FirstLevelCache(); - crossTypeRevisionChangesReader = new CrossTypeRevisionChangesReaderImpl( this, verCfg ); + crossTypeRevisionChangesReader = new CrossTypeRevisionChangesReaderImpl( this, enversService ); } private void checkSession() { @@ -124,7 +125,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { checkPositive( revision, "Entity revision" ); checkSession(); - if ( !verCfg.getEntCfg().isVersioned( entityName ) ) { + if ( !enversService.getEntitiesConfigurations().isVersioned( entityName ) ) { throw new NotAuditedException( entityName, entityName + " is not versioned!" ); } @@ -166,7 +167,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { checkNotNull( primaryKey, "Primary key" ); checkSession(); - if ( !verCfg.getEntCfg().isVersioned( entityName ) ) { + if ( !enversService.getEntitiesConfigurations().isVersioned( entityName ) ) { throw new NotAuditedException( entityName, entityName + " is not versioned!" ); } @@ -184,7 +185,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { checkPositive( revision, "Entity revision" ); checkSession(); - final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionDateQuery( session, revision ); + final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionDateQuery( session, revision ); try { final Object timestampObject = query.uniqueResult(); @@ -205,7 +206,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { checkNotNull( date, "Date of revision" ); checkSession(); - final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery( session, date ); + final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery( session, date ); try { final Number res = (Number) query.uniqueResult(); @@ -231,7 +232,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { final Set revisions = new HashSet( 1 ); revisions.add( revision ); - final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); try { final T revisionData = (T) query.uniqueResult(); @@ -261,12 +262,12 @@ public class AuditReaderImpl implements AuditReaderImplementor { } checkSession(); - final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); try { final List revisionList = query.list(); for ( T revision : revisionList ) { - final Number revNo = verCfg.getRevisionInfoNumberReader().getRevisionNumber( revision ); + final Number revNo = enversService.getRevisionInfoNumberReader().getRevisionNumber( revision ); result.put( revNo, revision ); } @@ -279,7 +280,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { @Override public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException { - if ( !verCfg.getGlobalCfg().isTrackEntitiesChangedInRevision() ) { + if ( !enversService.getGlobalConfiguration().isTrackEntitiesChangedInRevision() ) { throw new AuditException( "This API is designed for Envers default mechanism of tracking entities modified in a given revision." + " Extend DefaultTrackingModifiedEntitiesRevisionEntity, utilize @ModifiedEntityNames annotation or set " @@ -298,7 +299,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { } // Obtaining the current audit sync - final AuditProcess auditProcess = verCfg.getSyncManager().get( (EventSource) session ); + final AuditProcess auditProcess = enversService.getAuditProcessManager().get( (EventSource) session ); // And getting the current revision data return (T) auditProcess.getCurrentRevisionData( session, persist ); @@ -306,7 +307,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { @Override public AuditQueryCreator createQuery() { - return new AuditQueryCreator( verCfg, this ); + return new AuditQueryCreator( enversService, this ); } @Override @@ -320,7 +321,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { public boolean isEntityNameAudited(String entityName) { checkNotNull( entityName, "Entity name" ); checkSession(); - return (verCfg.getEntCfg().isVersioned( entityName )); + return enversService.getEntitiesConfigurations().isVersioned( entityName ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java index 6b4ab9619b..d0ebd01993 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java @@ -36,7 +36,7 @@ import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.CrossTypeRevisionChangesReader; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.tools.EntityTools; import org.hibernate.envers.query.criteria.internal.RevisionTypeAuditExpression; import org.hibernate.envers.tools.Pair; @@ -49,13 +49,13 @@ import static org.hibernate.envers.internal.tools.ArgumentsTools.checkPositive; */ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChangesReader { private final AuditReaderImplementor auditReaderImplementor; - private final AuditConfiguration verCfg; + private final EnversService enversService; public CrossTypeRevisionChangesReaderImpl( AuditReaderImplementor auditReaderImplementor, - AuditConfiguration verCfg) { + EnversService enversService) { this.auditReaderImplementor = auditReaderImplementor; - this.verCfg = verCfg; + this.enversService = enversService; } @Override @@ -127,12 +127,12 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan final Set revisions = new HashSet( 1 ); revisions.add( revision ); - final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); final Object revisionInfo = query.uniqueResult(); if ( revisionInfo != null ) { // If revision exists. - final Set entityNames = verCfg.getModifiedEntityNamesReader().getModifiedEntityNames( revisionInfo ); + final Set entityNames = enversService.getModifiedEntityNamesReader().getModifiedEntityNames( revisionInfo ); if ( entityNames != null ) { // Generate result that contains entity names and corresponding Java classes. final Set> result = new HashSet>(); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java index 4c58b34f46..698c1760e2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java @@ -30,8 +30,8 @@ import java.util.Map; import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; -import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.strategy.AuditStrategy; /** @@ -41,7 +41,7 @@ import org.hibernate.envers.strategy.AuditStrategy; */ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit { protected final SessionImplementor sessionImplementor; - protected final AuditConfiguration verCfg; + protected final EnversService enversService; protected final Serializable id; protected final String entityName; protected final AuditStrategy auditStrategy; @@ -50,23 +50,26 @@ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit { private Object performedData; protected AbstractAuditWorkUnit( - SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, RevisionType revisionType) { + SessionImplementor sessionImplementor, + String entityName, + EnversService enversService, + Serializable id, + RevisionType revisionType) { this.sessionImplementor = sessionImplementor; - this.verCfg = verCfg; + this.enversService = enversService; this.id = id; this.entityName = entityName; this.revisionType = revisionType; - this.auditStrategy = verCfg.getAuditStrategy(); + this.auditStrategy = enversService.getAuditStrategy(); } protected void fillDataWithId(Map data, Object revision) { - final AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg(); + final AuditEntitiesConfiguration entitiesCfg = enversService.getAuditEntitiesConfiguration(); final Map originalId = new HashMap(); originalId.put( entitiesCfg.getRevisionFieldName(), revision ); - verCfg.getEntCfg().get( getEntityName() ).getIdMapper().mapToMapFromId( originalId, id ); + enversService.getEntitiesConfigurations().get( getEntityName() ).getIdMapper().mapToMapFromId( originalId, id ); data.put( entitiesCfg.getRevisionTypePropName(), revisionType ); data.put( entitiesCfg.getOriginalIdPropName(), originalId ); } @@ -75,7 +78,7 @@ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit { public void perform(Session session, Object revisionData) { final Map data = generateData( revisionData ); - auditStrategy.perform( session, getEntityName(), verCfg, id, data, revisionData ); + auditStrategy.perform( session, getEntityName(), enversService, id, data, revisionData ); setPerformed( data ); } @@ -101,7 +104,10 @@ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit { public void undo(Session session) { if ( isPerformed() ) { - session.delete( verCfg.getAuditEntCfg().getAuditEntityName( getEntityName() ), performedData ); + session.delete( + enversService.getAuditEntitiesConfiguration().getAuditEntityName( getEntityName() ), + performedData + ); session.flush(); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java index e36a021665..20e5a0a06f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.tools.ArraysTools; import org.hibernate.persister.entity.EntityPersister; @@ -42,22 +42,30 @@ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit private final Map data; public AddWorkUnit( - SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, + SessionImplementor sessionImplementor, + String entityName, + EnversService enversService, Serializable id, EntityPersister entityPersister, Object[] state) { - super( sessionImplementor, entityName, verCfg, id, RevisionType.ADD ); + super( sessionImplementor, entityName, enversService, id, RevisionType.ADD ); this.data = new HashMap(); this.state = state; - this.verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map( - sessionImplementor, data, - entityPersister.getPropertyNames(), state, null + this.enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().map( + sessionImplementor, + data, + entityPersister.getPropertyNames(), + state, + null ); } public AddWorkUnit( - SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, Map data) { - super( sessionImplementor, entityName, verCfg, id, RevisionType.ADD ); + SessionImplementor sessionImplementor, + String entityName, + EnversService enversService, + Serializable id, + Map data) { + super( sessionImplementor, entityName, enversService, id, RevisionType.ADD ); this.data = data; final String[] propertyNames = sessionImplementor.getFactory() @@ -88,7 +96,7 @@ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit @Override public AuditWorkUnit merge(ModWorkUnit second) { - return new AddWorkUnit( sessionImplementor, entityName, verCfg, id, second.getData() ); + return new AddWorkUnit( sessionImplementor, entityName, enversService, id, second.getData() ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java index 3bc9cb0aed..c5a4bda8b2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; /** * @author Adam Warski (adam at warski dot org) @@ -41,9 +41,13 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A private final Map data = new HashMap(); public CollectionChangeWorkUnit( - SessionImplementor session, String entityName, String collectionPropertyName, - AuditConfiguration verCfg, Serializable id, Object entity) { - super( session, entityName, verCfg, id, RevisionType.MOD ); + SessionImplementor session, + String entityName, + String collectionPropertyName, + EnversService enversService, + Serializable id, + Object entity) { + super( session, entityName, enversService, id, RevisionType.MOD ); this.entity = entity; this.collectionPropertyName = collectionPropertyName; @@ -58,18 +62,28 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A public Map generateData(Object revisionData) { fillDataWithId( data, revisionData ); final Map preGenerateData = new HashMap( data ); - verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper() - .mapToMapFromEntity( sessionImplementor, data, entity, null ); - verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper() - .mapModifiedFlagsToMapFromEntity( sessionImplementor, data, entity, entity ); - verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper() - .mapModifiedFlagsToMapForCollectionChange( collectionPropertyName, data ); + enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().mapToMapFromEntity( + sessionImplementor, + data, + entity, + null + ); + enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().mapModifiedFlagsToMapFromEntity( + sessionImplementor, + data, + entity, + entity + ); + enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().mapModifiedFlagsToMapForCollectionChange( + collectionPropertyName, + data + ); data.putAll( preGenerateData ); return data; } public void mergeCollectionModifiedData(Map data) { - verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().mapModifiedFlagsToMapForCollectionChange( + enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().mapModifiedFlagsToMapForCollectionChange( collectionPropertyName, data ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java index 56d8a8ed2e..d94dd80c81 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.tools.ArraysTools; import org.hibernate.persister.entity.EntityPersister; @@ -43,9 +43,13 @@ public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit private final String[] propertyNames; public DelWorkUnit( - SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, EntityPersister entityPersister, Object[] state) { - super( sessionImplementor, entityName, verCfg, id, RevisionType.DEL ); + SessionImplementor sessionImplementor, + String entityName, + EnversService enversService, + Serializable id, + EntityPersister entityPersister, + Object[] state) { + super( sessionImplementor, entityName, enversService, id, RevisionType.DEL ); this.state = state; this.entityPersister = entityPersister; @@ -62,8 +66,8 @@ public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit final Map data = new HashMap(); fillDataWithId( data, revisionData ); - if ( verCfg.getGlobalCfg().isStoreDataAtDelete() ) { - verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map( + if ( enversService.getGlobalConfiguration().isStoreDataAtDelete() ) { + enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().map( sessionImplementor, data, propertyNames, @@ -72,7 +76,7 @@ public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit ); } else { - verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map( + enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().map( sessionImplementor, data, propertyNames, @@ -90,7 +94,7 @@ public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit // Return null if object's state has not changed. return null; } - return new ModWorkUnit( sessionImplementor, entityName, verCfg, id, entityPersister, second.getState(), state ); + return new ModWorkUnit( sessionImplementor, entityName, enversService, id, entityPersister, second.getState(), state ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java index 2a915c8bbf..429d815ffd 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java @@ -31,7 +31,7 @@ import java.util.Set; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.RelationDescription; /** @@ -49,13 +49,17 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp private final AuditWorkUnit nestedWorkUnit; public FakeBidirectionalRelationWorkUnit( - SessionImplementor sessionImplementor, String entityName, - AuditConfiguration verCfg, Serializable id, - String referencingPropertyName, Object owningEntity, - RelationDescription rd, RevisionType revisionType, + SessionImplementor sessionImplementor, + String entityName, + EnversService enversService, + Serializable id, + String referencingPropertyName, + Object owningEntity, + RelationDescription rd, + RevisionType revisionType, Object index, AuditWorkUnit nestedWorkUnit) { - super( sessionImplementor, entityName, verCfg, id, revisionType ); + super( sessionImplementor, entityName, enversService, id, revisionType ); this.nestedWorkUnit = nestedWorkUnit; // Adding the change for the relation. @@ -74,14 +78,14 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp FakeBidirectionalRelationWorkUnit original, Map fakeRelationChanges, AuditWorkUnit nestedWorkUnit) { - super( original.sessionImplementor, original.entityName, original.verCfg, original.id, original.revisionType ); + super( original.sessionImplementor, original.entityName, original.enversService, original.id, original.revisionType ); this.fakeRelationChanges = fakeRelationChanges; this.nestedWorkUnit = nestedWorkUnit; } public FakeBidirectionalRelationWorkUnit(FakeBidirectionalRelationWorkUnit original, AuditWorkUnit nestedWorkUnit) { - super( original.sessionImplementor, original.entityName, original.verCfg, original.id, original.revisionType ); + super( original.sessionImplementor, original.entityName, original.enversService, original.id, original.revisionType ); this.nestedWorkUnit = nestedWorkUnit; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java index cf71adc1b8..d7065770d3 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java @@ -29,7 +29,7 @@ import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.persister.entity.EntityPersister; /** @@ -44,17 +44,25 @@ public class ModWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit private final Object[] newState; public ModWorkUnit( - SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, EntityPersister entityPersister, Object[] newState, Object[] oldState) { - super( sessionImplementor, entityName, verCfg, id, RevisionType.MOD ); + SessionImplementor sessionImplementor, + String entityName, + EnversService enversService, + Serializable id, + EntityPersister entityPersister, + Object[] newState, + Object[] oldState) { + super( sessionImplementor, entityName, enversService, id, RevisionType.MOD ); this.entityPersister = entityPersister; this.oldState = oldState; this.newState = newState; - data = new HashMap(); - changes = verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map( - sessionImplementor, data, - entityPersister.getPropertyNames(), newState, oldState + this.data = new HashMap(); + this.changes = enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().map( + sessionImplementor, + data, + entityPersister.getPropertyNames(), + newState, + oldState ); } @@ -84,8 +92,13 @@ public class ModWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit // In case of multiple subsequent flushes within single transaction, modification flags need to be // recalculated against initial and final state of the given entity. return new ModWorkUnit( - second.sessionImplementor, second.getEntityName(), second.verCfg, second.id, - second.entityPersister, second.newState, this.oldState + second.sessionImplementor, + second.getEntityName(), + second.enversService, + second.id, + second.entityPersister, + second.newState, + this.oldState ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java index 73a9125c72..b8feb11a50 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java @@ -34,8 +34,8 @@ import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.CollectionEntry; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; -import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData; /** @@ -46,29 +46,36 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im private final String referencingPropertyName; public PersistentCollectionChangeWorkUnit( - SessionImplementor sessionImplementor, String entityName, - AuditConfiguration auditCfg, PersistentCollection collection, - CollectionEntry collectionEntry, Serializable snapshot, Serializable id, + SessionImplementor sessionImplementor, + String entityName, + EnversService enversService, + PersistentCollection collection, + CollectionEntry collectionEntry, + Serializable snapshot, + Serializable id, String referencingPropertyName) { super( - sessionImplementor, entityName, auditCfg, new PersistentCollectionChangeWorkUnitId( - id, - collectionEntry.getRole() - ), RevisionType.MOD + sessionImplementor, + entityName, + enversService, + new PersistentCollectionChangeWorkUnitId( id, collectionEntry.getRole() ), + RevisionType.MOD ); this.referencingPropertyName = referencingPropertyName; - collectionChanges = auditCfg.getEntCfg().get( getEntityName() ).getPropertyMapper() + collectionChanges = enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper() .mapCollectionChanges( sessionImplementor, referencingPropertyName, collection, snapshot, id ); } public PersistentCollectionChangeWorkUnit( - SessionImplementor sessionImplementor, String entityName, - AuditConfiguration verCfg, Serializable id, + SessionImplementor sessionImplementor, + String entityName, + EnversService enversService, + Serializable id, List collectionChanges, String referencingPropertyName) { - super( sessionImplementor, entityName, verCfg, id, RevisionType.MOD ); + super( sessionImplementor, entityName, enversService, id, RevisionType.MOD ); this.collectionChanges = collectionChanges; this.referencingPropertyName = referencingPropertyName; @@ -87,7 +94,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im @Override @SuppressWarnings({"unchecked"}) public void perform(Session session, Object revisionData) { - final AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg(); + final AuditEntitiesConfiguration entitiesCfg = enversService.getAuditEntitiesConfiguration(); for ( PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges ) { // Setting the revision number @@ -98,7 +105,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im session, getEntityName(), referencingPropertyName, - verCfg, + enversService, persistentCollectionChangeData, revisionData ); @@ -168,7 +175,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im else { // If the changes collide, checking if the first one isn't a DEL, and the second a subsequent ADD // If so, removing the change alltogether. - final String revTypePropName = verCfg.getAuditEntCfg().getRevisionTypePropName(); + final String revTypePropName = enversService.getAuditEntitiesConfiguration().getRevisionTypePropName(); if ( RevisionType.ADD.equals( newChangesIdMap.get( originalOriginalId ).getData().get( revTypePropName ) ) && RevisionType.DEL.equals( originalCollectionChangeData.getData().get( revTypePropName ) ) ) { newChangesIdMap.remove( originalOriginalId ); @@ -183,7 +190,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im return new PersistentCollectionChangeWorkUnit( sessionImplementor, entityName, - verCfg, + enversService, id, mergedChanges, referencingPropertyName @@ -198,7 +205,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im } private Object getOriginalId(PersistentCollectionChangeData persistentCollectionChangeData) { - return persistentCollectionChangeData.getData().get( verCfg.getAuditEntCfg().getOriginalIdPropName() ); + return persistentCollectionChangeData.getData().get( enversService.getAuditEntitiesConfiguration().getOriginalIdPropName() ); } /** 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..2fb86dc746 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 @@ -24,6 +24,7 @@ package org.hibernate.envers.internal.tools; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -69,6 +70,17 @@ public abstract class Tools { return ret; } + public static List collectionToList(Collection collection) { + if ( collection instanceof List ) { + return (List) collection; + } + else { + List list = new ArrayList(); + list.addAll( collection ); + return list; + } + } + public static boolean iteratorsContentEqual(Iterator iter1, Iterator iter2) { while ( iter1.hasNext() && iter2.hasNext() ) { if ( !iter1.next().equals( iter2.next() ) ) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java index 958be1e6cf..93739461fa 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.query.internal.impl.EntitiesAtRevisionQuery; import org.hibernate.envers.query.internal.impl.EntitiesModifiedAtRevisionQuery; @@ -39,11 +39,11 @@ import static org.hibernate.envers.internal.tools.EntityTools.getTargetClassIfPr * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class AuditQueryCreator { - private final AuditConfiguration auditCfg; + private final EnversService enversService; private final AuditReaderImplementor auditReaderImplementor; - public AuditQueryCreator(AuditConfiguration auditCfg, AuditReaderImplementor auditReaderImplementor) { - this.auditCfg = auditCfg; + public AuditQueryCreator(EnversService enversService, AuditReaderImplementor auditReaderImplementor) { + this.enversService = enversService; this.auditReaderImplementor = auditReaderImplementor; } @@ -62,7 +62,7 @@ public class AuditQueryCreator { checkNotNull( revision, "Entity revision" ); checkPositive( revision, "Entity revision" ); c = getTargetClassIfProxied( c ); - return new EntitiesAtRevisionQuery( auditCfg, auditReaderImplementor, c, revision, false ); + return new EntitiesAtRevisionQuery( enversService, auditReaderImplementor, c, revision, false ); } /** @@ -100,7 +100,7 @@ public class AuditQueryCreator { checkPositive( revision, "Entity revision" ); c = getTargetClassIfProxied( c ); return new EntitiesAtRevisionQuery( - auditCfg, + enversService, auditReaderImplementor, c, entityName, @@ -128,7 +128,7 @@ public class AuditQueryCreator { checkNotNull( revision, "Entity revision" ); checkPositive( revision, "Entity revision" ); c = getTargetClassIfProxied( c ); - return new EntitiesModifiedAtRevisionQuery( auditCfg, auditReaderImplementor, c, entityName, revision ); + return new EntitiesModifiedAtRevisionQuery( enversService, auditReaderImplementor, c, entityName, revision ); } /** @@ -149,7 +149,7 @@ public class AuditQueryCreator { checkNotNull( revision, "Entity revision" ); checkPositive( revision, "Entity revision" ); c = getTargetClassIfProxied( c ); - return new EntitiesModifiedAtRevisionQuery( auditCfg, auditReaderImplementor, c, revision ); + return new EntitiesModifiedAtRevisionQuery( enversService, auditReaderImplementor, c, revision ); } /** @@ -177,7 +177,7 @@ public class AuditQueryCreator { public AuditQuery forRevisionsOfEntity(Class c, boolean selectEntitiesOnly, boolean selectDeletedEntities) { c = getTargetClassIfProxied( c ); return new RevisionsOfEntityQuery( - auditCfg, + enversService, auditReaderImplementor, c, selectEntitiesOnly, @@ -215,7 +215,7 @@ public class AuditQueryCreator { boolean selectDeletedEntities) { c = getTargetClassIfProxied( c ); return new RevisionsOfEntityQuery( - auditCfg, + enversService, auditReaderImplementor, c, entityName, diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java index b5911bc245..8d842b83c2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java @@ -26,7 +26,7 @@ package org.hibernate.envers.query.criteria; import java.util.ArrayList; import java.util.List; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -63,16 +63,19 @@ public class AggregatedAuditExpression implements AuditCriterion, ExtendableCrit @Override public void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, propertyNameGetter ); - CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); + CriteriaTools.checkPropertyNotARelation( enversService, entityName, propertyName ); // Make sure our conditions are ANDed together even if the parent Parameters have a different connective Parameters subParams = parameters.addSubParameters( Parameters.AND ); @@ -82,8 +85,8 @@ public class AggregatedAuditExpression implements AuditCriterion, ExtendableCrit // Adding all specified conditions both to the main query, as well as to the // aggregated one. for ( AuditCriterion versionsCriteria : criterions ) { - versionsCriteria.addToQuery( auditCfg, versionsReader, entityName, qb, subParams ); - versionsCriteria.addToQuery( auditCfg, versionsReader, entityName, subQb, subQb.getRootParameters() ); + versionsCriteria.addToQuery( enversService, versionsReader, entityName, qb, subParams ); + versionsCriteria.addToQuery( enversService, versionsReader, entityName, subQb, subQb.getRootParameters() ); } // Setting the desired projection of the aggregated query @@ -97,8 +100,8 @@ public class AggregatedAuditExpression implements AuditCriterion, ExtendableCrit // Correlating subquery with the outer query by entity id. See JIRA HHH-7827. if ( correlate ) { - final String originalIdPropertyName = auditCfg.getAuditEntCfg().getOriginalIdPropName(); - auditCfg.getEntCfg().get( entityName ).getIdMapper().addIdsEqualToQuery( + final String originalIdPropertyName = enversService.getAuditEntitiesConfiguration().getOriginalIdPropName(); + enversService.getEntitiesConfigurations().get( entityName ).getIdMapper().addIdsEqualToQuery( subQb.getRootParameters(), subQb.getRootAlias() + "." + originalIdPropertyName, qb.getRootAlias() + "." + originalIdPropertyName diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java index 4caa107934..59588e7974 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java @@ -26,7 +26,7 @@ package org.hibernate.envers.query.criteria; import java.util.ArrayList; import java.util.List; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -41,14 +41,19 @@ public class AuditConjunction implements AuditCriterion, ExtendableCriterion { criterions = new ArrayList(); } + @Override public AuditConjunction add(AuditCriterion criterion) { criterions.add( criterion ); return this; } + @Override public void addToQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { Parameters andParameters = parameters.addSubParameters( Parameters.AND ); if ( criterions.size() == 0 ) { @@ -56,7 +61,7 @@ public class AuditConjunction implements AuditCriterion, ExtendableCriterion { } else { for ( AuditCriterion criterion : criterions ) { - criterion.addToQuery( verCfg, versionsReader, entityName, qb, andParameters ); + criterion.addToQuery( enversService, versionsReader, entityName, qb, andParameters ); } } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java index e71e099c6c..8c47755b21 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -33,6 +33,9 @@ import org.hibernate.envers.internal.tools.query.QueryBuilder; */ public interface AuditCriterion { void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters); + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java index 1423b5078c..f634576a0d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java @@ -26,7 +26,7 @@ package org.hibernate.envers.query.criteria; import java.util.ArrayList; import java.util.List; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -49,8 +49,11 @@ public class AuditDisjunction implements AuditCriterion, ExtendableCriterion { @Override public void addToQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { Parameters orParameters = parameters.addSubParameters( Parameters.OR ); if ( criterions.size() == 0 ) { @@ -58,7 +61,7 @@ public class AuditDisjunction implements AuditCriterion, ExtendableCriterion { } else { for ( AuditCriterion criterion : criterions ) { - criterion.addToQuery( verCfg, versionsReader, entityName, qb, orParameters ); + criterion.addToQuery( enversService, versionsReader, entityName, qb, orParameters ); } } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java index 4a6c7d5d0d..48106c1ecf 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java @@ -26,7 +26,7 @@ package org.hibernate.envers.query.criteria; import java.util.Collection; import org.hibernate.criterion.MatchMode; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.tools.Triple; import org.hibernate.envers.query.criteria.internal.BetweenAuditExpression; import org.hibernate.envers.query.criteria.internal.IlikeAuditExpression; @@ -273,8 +273,8 @@ public class AuditProperty implements AuditProjection { // Projection on this property - public Triple getData(AuditConfiguration auditCfg) { - return Triple.make( null, propertyNameGetter.get( auditCfg ), false ); + public Triple getData(EnversService enversService) { + return Triple.make( null, propertyNameGetter.get( enversService ), false ); } // Order diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/BetweenAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/BetweenAuditExpression.java index 90a2a95a97..c491c1477d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/BetweenAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/BetweenAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -45,15 +45,18 @@ public class BetweenAuditExpression implements AuditCriterion { } public void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, propertyNameGetter ); - CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); + CriteriaTools.checkPropertyNotARelation( enversService, entityName, propertyName ); Parameters subParams = parameters.addSubParameters( Parameters.AND ); subParams.addWhereWithParam( propertyName, ">=", lo ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java index 466c47dd96..aa388d0397 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java @@ -28,7 +28,7 @@ import java.util.Collections; import java.util.List; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.RelationDescription; import org.hibernate.envers.internal.entities.RelationType; @@ -43,9 +43,10 @@ import org.hibernate.type.Type; */ public abstract class CriteriaTools { public static void checkPropertyNotARelation( - AuditConfiguration verCfg, String entityName, + EnversService enversService, + String entityName, String propertyName) throws AuditException { - if ( verCfg.getEntCfg().get( entityName ).isRelation( propertyName ) ) { + if ( enversService.getEntitiesConfigurations().get( entityName ).isRelation( propertyName ) ) { throw new AuditException( "This criterion cannot be used on a property that is " + "a relation to another property." @@ -54,9 +55,10 @@ public abstract class CriteriaTools { } public static RelationDescription getRelatedEntity( - AuditConfiguration verCfg, String entityName, + EnversService enversService, + String entityName, String propertyName) throws AuditException { - RelationDescription relationDesc = verCfg.getEntCfg().getRelationDescription( entityName, propertyName ); + RelationDescription relationDesc = enversService.getEntitiesConfigurations().getRelationDescription( entityName, propertyName ); if ( relationDesc == null ) { return null; @@ -72,17 +74,16 @@ public abstract class CriteriaTools { ); } - /** - * @see #determinePropertyName(AuditConfiguration, AuditReaderImplementor, String, String) - */ public static String determinePropertyName( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, - String entityName, PropertyNameGetter propertyNameGetter) { - return determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter.get( auditCfg ) ); + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + PropertyNameGetter propertyNameGetter) { + return determinePropertyName( enversService, versionsReader, entityName, propertyNameGetter.get( enversService ) ); } /** - * @param auditCfg Audit configuration. + * @param enversService The EnversService * @param versionsReader Versions reader. * @param entityName Original entity name (not audited). * @param propertyName Property name or placeholder. @@ -90,18 +91,20 @@ public abstract class CriteriaTools { * @return Path to property. Handles identifier placeholder used by {@link org.hibernate.envers.query.criteria.AuditId}. */ public static String determinePropertyName( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, - String entityName, String propertyName) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + String propertyName) { final SessionFactoryImplementor sessionFactory = versionsReader.getSessionImplementor().getFactory(); if ( AuditId.IDENTIFIER_PLACEHOLDER.equals( propertyName ) ) { final String identifierPropertyName = sessionFactory.getEntityPersister( entityName ).getIdentifierPropertyName(); - propertyName = auditCfg.getAuditEntCfg().getOriginalIdPropName() + "." + identifierPropertyName; + propertyName = enversService.getAuditEntitiesConfiguration().getOriginalIdPropName() + "." + identifierPropertyName; } else { final List identifierPropertyNames = identifierPropertyNames( sessionFactory, entityName ); if ( identifierPropertyNames.contains( propertyName ) ) { - propertyName = auditCfg.getAuditEntCfg().getOriginalIdPropName() + "." + propertyName; + propertyName = enversService.getAuditEntitiesConfiguration().getOriginalIdPropName() + "." + propertyName; } } @@ -126,6 +129,6 @@ public abstract class CriteriaTools { final EmbeddedComponentType embeddedComponentType = (EmbeddedComponentType) identifierType; return Arrays.asList( embeddedComponentType.getPropertyNames() ); } - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IdentifierEqAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IdentifierEqAuditExpression.java index 6f81d26b01..0ee9495503 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IdentifierEqAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IdentifierEqAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -43,10 +43,15 @@ public class IdentifierEqAuditExpression implements AuditCriterion { this.equals = equals; } + @Override public void addToQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - verCfg.getEntCfg().get( entityName ).getIdMapper() - .addIdEqualsToQuery( parameters, id, verCfg.getAuditEntCfg().getOriginalIdPropName(), equals ); + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { + enversService.getEntitiesConfigurations().get( entityName ) + .getIdMapper() + .addIdEqualsToQuery( parameters, id, enversService.getAuditEntitiesConfiguration().getOriginalIdPropName(), equals ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IlikeAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IlikeAuditExpression.java index a2647a6132..a188e1f14b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IlikeAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IlikeAuditExpression.java @@ -1,6 +1,6 @@ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -17,16 +17,18 @@ public class IlikeAuditExpression implements AuditCriterion { this.value = value; } - public void addToQuery(AuditConfiguration auditCfg, + public void addToQuery( + EnversService enversService, AuditReaderImplementor versionsReader, String entityName, QueryBuilder qb, Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, - propertyNameGetter); - CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); + propertyNameGetter + ); + CriteriaTools.checkPropertyNotARelation( enversService, entityName, propertyName ); parameters.addWhereWithFunction( propertyName, " lower ", " like ", value.toLowerCase() ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/InAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/InAuditExpression.java index 8e9aca71a9..425ba5ad36 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/InAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/InAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -43,15 +43,18 @@ public class InAuditExpression implements AuditCriterion { } public void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, propertyNameGetter ); - CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); + CriteriaTools.checkPropertyNotARelation( enversService, entityName, propertyName ); parameters.addWhereWithParams( propertyName, "in (", values, ")" ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/LogicalAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/LogicalAuditExpression.java index 3888ac120d..c49c77e456 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/LogicalAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/LogicalAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -44,11 +44,14 @@ public class LogicalAuditExpression implements AuditCriterion { } public void addToQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { Parameters opParameters = parameters.addSubParameters( op ); - lhs.addToQuery( verCfg, versionsReader, entityName, qb, opParameters.addSubParameters( "and" ) ); - rhs.addToQuery( verCfg, versionsReader, entityName, qb, opParameters.addSubParameters( "and" ) ); + lhs.addToQuery( enversService, versionsReader, entityName, qb, opParameters.addSubParameters( "and" ) ); + rhs.addToQuery( enversService, versionsReader, entityName, qb, opParameters.addSubParameters( "and" ) ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotAuditExpression.java index 95075d29c5..1c1366c8a7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -40,8 +40,11 @@ public class NotAuditExpression implements AuditCriterion { } public void addToQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - criterion.addToQuery( verCfg, versionsReader, entityName, qb, parameters.addNegatedParameters() ); + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { + criterion.addToQuery( enversService, versionsReader, entityName, qb, parameters.addNegatedParameters() ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotNullAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotNullAuditExpression.java index b0d3c1f87b..d26c6276af 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotNullAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotNullAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.RelationDescription; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; @@ -42,15 +42,18 @@ public class NotNullAuditExpression implements AuditCriterion { } public void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, propertyNameGetter ); - RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( auditCfg, entityName, propertyName ); + RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( enversService, entityName, propertyName ); if ( relatedEntity == null ) { parameters.addNotNullRestriction( propertyName, true ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NullAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NullAuditExpression.java index 5caa070226..b49a10eaa2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NullAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NullAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.entities.RelationDescription; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; @@ -42,15 +42,18 @@ public class NullAuditExpression implements AuditCriterion { } public void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, propertyNameGetter ); - RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( auditCfg, entityName, propertyName ); + RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( enversService, entityName, propertyName ); if ( relatedEntity == null ) { parameters.addNullRestriction( propertyName, true ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/PropertyAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/PropertyAuditExpression.java index 71f0402336..b3547413da 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/PropertyAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/PropertyAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -45,16 +45,18 @@ public class PropertyAuditExpression implements AuditCriterion { } public void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, propertyNameGetter ); - CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); - CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, otherPropertyName ); + CriteriaTools.checkPropertyNotARelation( enversService, entityName, propertyName ); + CriteriaTools.checkPropertyNotARelation( enversService, entityName, otherPropertyName ); parameters.addWhere( propertyName, op, otherPropertyName ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RelatedAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RelatedAuditExpression.java index ea7aac824a..6109ebbb95 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RelatedAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RelatedAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.RelationDescription; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -48,16 +48,19 @@ public class RelatedAuditExpression implements AuditCriterion { @Override public void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, propertyNameGetter ); - RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( auditCfg, entityName, propertyName ); + RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( enversService, entityName, propertyName ); if ( relatedEntity == null ) { throw new AuditException( diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RevisionTypeAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RevisionTypeAuditExpression.java index cf66aa30f6..ec378eecbc 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RevisionTypeAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RevisionTypeAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; @@ -43,8 +43,11 @@ public class RevisionTypeAuditExpression implements AuditCriterion { @Override public void addToQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - parameters.addWhereWithParam( verCfg.getAuditEntCfg().getRevisionTypePropName(), op, value ); + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { + parameters.addWhereWithParam( enversService.getAuditEntitiesConfiguration().getRevisionTypePropName(), op, value ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/SimpleAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/SimpleAuditExpression.java index 4fa8a076d3..f2517d50f9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/SimpleAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/SimpleAuditExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.RelationDescription; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -47,16 +47,19 @@ public class SimpleAuditExpression implements AuditCriterion { } public void addToQuery( - AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { + EnversService enversService, + AuditReaderImplementor versionsReader, + String entityName, + QueryBuilder qb, + Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( - auditCfg, + enversService, versionsReader, entityName, propertyNameGetter ); - RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( auditCfg, entityName, propertyName ); + RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( enversService, entityName, propertyName ); if ( relatedEntity == null ) { parameters.addWhereWithParam( propertyName, op, value ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java index 272d37da94..8dcc536e3d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java @@ -33,7 +33,7 @@ import org.hibernate.FlushMode; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.Query; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.EntityInstantiator; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -64,29 +64,30 @@ public abstract class AbstractAuditQuery implements AuditQuery { protected boolean hasProjection; protected boolean hasOrder; - protected final AuditConfiguration verCfg; + protected final EnversService enversService; protected final AuditReaderImplementor versionsReader; protected AbstractAuditQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + EnversService enversService, + AuditReaderImplementor versionsReader, Class cls) { - this( verCfg, versionsReader, cls, cls.getName() ); + this( enversService, versionsReader, cls, cls.getName() ); } protected AbstractAuditQuery( - AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, String entityName) { - this.verCfg = verCfg; + EnversService enversService, + AuditReaderImplementor versionsReader, + Class cls, + String entityName) { + this.enversService = enversService; this.versionsReader = versionsReader; criterions = new ArrayList(); - entityInstantiator = new EntityInstantiator( verCfg, versionsReader ); + entityInstantiator = new EntityInstantiator( enversService, versionsReader ); entityClassName = cls.getName(); this.entityName = entityName; - versionsEntityName = verCfg.getAuditEntCfg().getAuditEntityName( - entityName - ); + versionsEntityName = enversService.getAuditEntitiesConfiguration().getAuditEntityName( entityName ); qb = new QueryBuilder( versionsEntityName, REFERENCED_ENTITY_ALIAS ); } @@ -131,10 +132,10 @@ public abstract class AbstractAuditQuery implements AuditQuery { // Projection and order public AuditQuery addProjection(AuditProjection projection) { - Triple projectionData = projection.getData( verCfg ); + Triple projectionData = projection.getData( enversService ); hasProjection = true; String propertyName = CriteriaTools.determinePropertyName( - verCfg, + enversService, versionsReader, entityName, projectionData.getSecond() @@ -145,9 +146,9 @@ public abstract class AbstractAuditQuery implements AuditQuery { public AuditQuery addOrder(AuditOrder order) { hasOrder = true; - Pair orderData = order.getData( verCfg ); + Pair orderData = order.getData( enversService ); String propertyName = CriteriaTools.determinePropertyName( - verCfg, + enversService, versionsReader, entityName, orderData.getFirst() diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java index 2bdbd2a7eb..73bad06290 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java @@ -29,8 +29,8 @@ import java.util.List; import org.hibernate.Query; import org.hibernate.envers.RevisionType; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; -import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.query.criteria.AuditCriterion; @@ -48,19 +48,21 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { private final boolean includeDeletions; public EntitiesAtRevisionQuery( - AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, - Number revision, boolean includeDeletions) { - super( verCfg, versionsReader, cls ); + EnversService enversService, + AuditReaderImplementor versionsReader, + Class cls, + Number revision, + boolean includeDeletions) { + super( enversService, versionsReader, cls ); this.revision = revision; this.includeDeletions = includeDeletions; } public EntitiesAtRevisionQuery( - AuditConfiguration verCfg, + EnversService enversService, AuditReaderImplementor versionsReader, Class cls, String entityName, Number revision, boolean includeDeletions) { - super( verCfg, versionsReader, cls, entityName ); + super( enversService, versionsReader, cls, entityName ); this.revision = revision; this.includeDeletions = includeDeletions; } @@ -84,19 +86,22 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { * (only non-deleted entities) * e.revision_type != DEL */ - AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); + AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration(); String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); MiddleIdData referencedIdData = new MiddleIdData( - verEntCfg, verCfg.getEntCfg().get( entityName ).getIdMappingData(), - null, entityName, verCfg.getEntCfg().isVersioned( entityName ) + verEntCfg, + enversService.getEntitiesConfigurations().get( entityName ).getIdMappingData(), + null, + entityName, + enversService.getEntitiesConfigurations().isVersioned( entityName ) ); // (selecting e entities at revision :revision) // --> based on auditStrategy (see above) - verCfg.getAuditStrategy().addEntityAtRevisionRestriction( - verCfg.getGlobalCfg(), + enversService.getAuditStrategy().addEntityAtRevisionRestriction( + enversService.getGlobalConfiguration(), qb, qb.getRootParameters(), revisionPropertyPath, @@ -117,7 +122,7 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { // all specified conditions for ( AuditCriterion criterion : criterions ) { - criterion.addToQuery( verCfg, versionsReader, entityName, qb, qb.getRootParameters() ); + criterion.addToQuery( enversService, versionsReader, entityName, qb, qb.getRootParameters() ); } Query query = buildQuery(); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java index 6045bc2dc2..036363a527 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.Query; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; -import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.query.criteria.AuditCriterion; @@ -20,16 +20,21 @@ public class EntitiesModifiedAtRevisionQuery extends AbstractAuditQuery { private final Number revision; public EntitiesModifiedAtRevisionQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Class cls, Number revision) { - super( verCfg, versionsReader, cls ); + EnversService enversService, + AuditReaderImplementor versionsReader, + Class cls, + Number revision) { + super( enversService, versionsReader, cls ); this.revision = revision; } public EntitiesModifiedAtRevisionQuery( - AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Class cls, String entityName, Number revision) { - super( verCfg, versionsReader, cls, entityName ); + EnversService enversService, + AuditReaderImplementor versionsReader, + Class cls, + String entityName, + Number revision) { + super( enversService, versionsReader, cls, entityName ); this.revision = revision; } @@ -43,13 +48,13 @@ public class EntitiesModifiedAtRevisionQuery extends AbstractAuditQuery { * (all specified conditions, transformed, on the "e" entity) AND * e.revision = :revision */ - AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); + AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration(); String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); qb.getRootParameters().addWhereWithParam( revisionPropertyPath, "=", revision ); // all specified conditions for ( AuditCriterion criterion : criterions ) { - criterion.addToQuery( verCfg, versionsReader, entityName, qb, qb.getRootParameters() ); + criterion.addToQuery( enversService, versionsReader, entityName, qb, qb.getRootParameters() ); } Query query = buildQuery(); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java index b60bff02c5..60886a79d1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java @@ -28,8 +28,8 @@ import java.util.List; import java.util.Map; import org.hibernate.envers.RevisionType; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; -import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.query.criteria.AuditCriterion; @@ -44,28 +44,31 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery { private final boolean selectDeletedEntities; public RevisionsOfEntityQuery( - AuditConfiguration verCfg, + EnversService enversService, AuditReaderImplementor versionsReader, - Class cls, boolean selectEntitiesOnly, + Class cls, + boolean selectEntitiesOnly, boolean selectDeletedEntities) { - super( verCfg, versionsReader, cls ); + super( enversService, versionsReader, cls ); this.selectEntitiesOnly = selectEntitiesOnly; this.selectDeletedEntities = selectDeletedEntities; } public RevisionsOfEntityQuery( - AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, String entityName, - boolean selectEntitiesOnly, boolean selectDeletedEntities) { - super( verCfg, versionsReader, cls, entityName ); + EnversService enversService, + AuditReaderImplementor versionsReader, + Class cls, String entityName, + boolean selectEntitiesOnly, + boolean selectDeletedEntities) { + super( enversService, versionsReader, cls, entityName ); this.selectEntitiesOnly = selectEntitiesOnly; this.selectDeletedEntities = selectDeletedEntities; } private Number getRevisionNumber(Map versionsEntity) { - AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); + AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration(); String originalId = verEntCfg.getOriginalIdPropName(); String revisionPropertyName = verEntCfg.getRevisionFieldName(); @@ -77,13 +80,13 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery { } else { // Not a proxy - must be read from cache or with a join - return verCfg.getRevisionInfoNumberReader().getRevisionNumber( revisionInfoObject ); + return enversService.getRevisionInfoNumberReader().getRevisionNumber( revisionInfoObject ); } } @SuppressWarnings({"unchecked"}) public List list() throws AuditException { - AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); + AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration(); /* The query that should be executed in the versions table: @@ -100,7 +103,7 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery { // all specified conditions, transformed for ( AuditCriterion criterion : criterions ) { - criterion.addToQuery( verCfg, versionsReader, entityName, qb, qb.getRootParameters() ); + criterion.addToQuery( enversService, versionsReader, entityName, qb, qb.getRootParameters() ); } if ( !hasProjection && !hasOrder ) { @@ -109,9 +112,9 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery { } if ( !selectEntitiesOnly ) { - qb.addFrom( verCfg.getAuditEntCfg().getRevisionInfoEntityName(), "r" ); + qb.addFrom( enversService.getAuditEntitiesConfiguration().getRevisionInfoEntityName(), "r" ); qb.getRootParameters().addWhere( - verCfg.getAuditEntCfg().getRevisionNumberPath(), + enversService.getAuditEntitiesConfiguration().getRevisionNumberPath(), true, "=", "r.id", diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/EntityPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/EntityPropertyName.java index daa6d925bf..c002f769e1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/EntityPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/EntityPropertyName.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.internal.property; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; /** * Used for specifying restrictions on a property of an audited entity. @@ -37,7 +37,7 @@ public class EntityPropertyName implements PropertyNameGetter { this.propertyName = propertyName; } - public String get(AuditConfiguration auditCfg) { + public String get(EnversService enversService) { return propertyName; } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/ModifiedFlagPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/ModifiedFlagPropertyName.java index 902ddeebcb..bf9fe018fc 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/ModifiedFlagPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/ModifiedFlagPropertyName.java @@ -23,8 +23,8 @@ */ package org.hibernate.envers.query.internal.property; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.metadata.MetadataTools; -import org.hibernate.envers.configuration.spi.AuditConfiguration; /** * PropertyNameGetter for modified flags @@ -38,10 +38,10 @@ public class ModifiedFlagPropertyName implements PropertyNameGetter { this.propertyNameGetter = propertyNameGetter; } - public String get(AuditConfiguration auditCfg) { + public String get(EnversService enversService) { return MetadataTools.getModifiedFlagPropertyName( - propertyNameGetter.get( auditCfg ), - auditCfg.getGlobalCfg().getModifiedFlagSuffix() + propertyNameGetter.get( enversService ), + enversService.getGlobalConfiguration().getModifiedFlagSuffix() ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/OriginalIdPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/OriginalIdPropertyName.java index a25d8300d4..fad9d8c77d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/OriginalIdPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/OriginalIdPropertyName.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.internal.property; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.query.criteria.AuditId; /** @@ -40,7 +40,7 @@ public class OriginalIdPropertyName implements PropertyNameGetter { } @Override - public String get(AuditConfiguration auditCfg) { - return auditCfg.getAuditEntCfg().getOriginalIdPropName() + "." + idPropertyName; + public String get(EnversService enversService) { + return enversService.getAuditEntitiesConfiguration().getOriginalIdPropName() + "." + idPropertyName; } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java index b8ce13b04a..9234919aa3 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.internal.property; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; /** * Provides a function to get the name of a property, which is used in a query, to apply some restrictions on it. @@ -32,9 +32,9 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; */ public interface PropertyNameGetter { /** - * @param auditCfg Audit configuration. + * @param enversService The EnversService * * @return Name of the property, to be used in a query. */ - public String get(AuditConfiguration auditCfg); + public String get(EnversService enversService); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionNumberPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionNumberPropertyName.java index 6aec37975d..6554dfa9a9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionNumberPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionNumberPropertyName.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.internal.property; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; /** * Used for specifying restrictions on the revision number, corresponding to an audit entity. @@ -32,7 +32,7 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; */ public class RevisionNumberPropertyName implements PropertyNameGetter { @Override - public String get(AuditConfiguration auditCfg) { - return auditCfg.getAuditEntCfg().getRevisionNumberPath(); + public String get(EnversService enversService) { + return enversService.getAuditEntitiesConfiguration().getRevisionNumberPath(); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionPropertyPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionPropertyPropertyName.java index 4d95a5d228..ec6ce33457 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionPropertyPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionPropertyPropertyName.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.internal.property; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; /** * Used for specifying restrictions on a property of the revision entity, which is associated with an audit entity. @@ -38,7 +38,7 @@ public class RevisionPropertyPropertyName implements PropertyNameGetter { } @Override - public String get(AuditConfiguration auditCfg) { - return auditCfg.getAuditEntCfg().getRevisionPropPath( propertyName ); + public String get(EnversService enversService) { + return enversService.getAuditEntitiesConfiguration().getRevisionPropPath( propertyName ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionTypePropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionTypePropertyName.java index f88d456c64..c35a1aa8e8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionTypePropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionTypePropertyName.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.internal.property; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; /** * Used for specifying restrictions on the revision number, corresponding to an audit entity. @@ -32,7 +32,7 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; */ public class RevisionTypePropertyName implements PropertyNameGetter { @Override - public String get(AuditConfiguration auditCfg) { - return auditCfg.getAuditEntCfg().getRevisionTypePropName(); + public String get(EnversService enversService) { + return enversService.getAuditEntitiesConfiguration().getRevisionTypePropName(); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java index d7c00b5eeb..e580bc0625 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.order; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.tools.Pair; /** @@ -31,9 +31,9 @@ import org.hibernate.envers.tools.Pair; */ public interface AuditOrder { /** - * @param auditCfg Configuration. + * @param enversService The EnversService * * @return A pair: (property name, ascending?). */ - Pair getData(AuditConfiguration auditCfg); + Pair getData(EnversService enversService); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/order/internal/PropertyAuditOrder.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/order/internal/PropertyAuditOrder.java index 1a0898e2ec..2bb4704d4b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/order/internal/PropertyAuditOrder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/order/internal/PropertyAuditOrder.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.order.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.query.internal.property.PropertyNameGetter; import org.hibernate.envers.query.order.AuditOrder; import org.hibernate.envers.tools.Pair; @@ -41,7 +41,7 @@ public class PropertyAuditOrder implements AuditOrder { } @Override - public Pair getData(AuditConfiguration auditCfg) { - return Pair.make( propertyNameGetter.get( auditCfg ), asc ); + public Pair getData(EnversService enversService) { + return Pair.make( propertyNameGetter.get( enversService ), asc ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java index a1be2c6a63..3b95b6425d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.projection; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.tools.Triple; /** @@ -31,9 +31,9 @@ import org.hibernate.envers.internal.tools.Triple; */ public interface AuditProjection { /** - * @param auditCfg Configuration. + * @param enversService The EnversService * * @return A triple: (function name - possibly null, property name, add distinct?). */ - Triple getData(AuditConfiguration auditCfg); + Triple getData(EnversService enversService); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/internal/PropertyAuditProjection.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/internal/PropertyAuditProjection.java index 60b0b2507a..fd60e4159b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/internal/PropertyAuditProjection.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/internal/PropertyAuditProjection.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.projection.internal; -import org.hibernate.envers.configuration.spi.AuditConfiguration; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.internal.tools.Triple; import org.hibernate.envers.query.internal.property.PropertyNameGetter; import org.hibernate.envers.query.projection.AuditProjection; @@ -43,8 +43,8 @@ public class PropertyAuditProjection implements AuditProjection { } @Override - public Triple getData(AuditConfiguration auditCfg) { - String propertyName = propertyNameGetter.get( auditCfg ); + public Triple getData(EnversService enversService) { + String propertyName = propertyNameGetter.get( enversService ); return Triple.make( function, propertyName, distinct ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java index 7dedd7eb78..87e6f354e1 100755 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java @@ -4,6 +4,7 @@ import java.io.Serializable; import org.hibernate.Session; import org.hibernate.collection.spi.PersistentCollection; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.GlobalConfiguration; import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData; @@ -24,13 +25,17 @@ public interface AuditStrategy { * * @param session Session, which can be used to persist the data. * @param entityName Name of the entity, in which the audited change happens - * @param auditCfg Audit configuration + * @param enversService The EnversService * @param id Id of the entity. * @param data Audit data to persist * @param revision Current revision data */ void perform( - Session session, String entityName, AuditConfiguration auditCfg, Serializable id, Object data, + Session session, + String entityName, + EnversService enversService, + Serializable id, + Object data, Object revision); /** @@ -39,13 +44,17 @@ public interface AuditStrategy { * @param session Session, which can be used to persist the data. * @param entityName Name of the entity, in which the audited change happens. * @param propertyName The name of the property holding the {@link PersistentCollection}. - * @param auditCfg Audit configuration + * @param enversService The EnversService * @param persistentCollectionChangeData Collection change data to be persisted. * @param revision Current revision data */ void performCollectionChange( - Session session, String entityName, String propertyName, AuditConfiguration auditCfg, - PersistentCollectionChangeData persistentCollectionChangeData, Object revision); + Session session, + String entityName, + String propertyName, + EnversService enversService, + PersistentCollectionChangeData persistentCollectionChangeData, + Object revision); /** @@ -114,8 +123,17 @@ public interface AuditStrategy { * @param componentDatas information about the middle-entity relation */ void addAssociationAtRevisionRestriction( - QueryBuilder rootQueryBuilder, Parameters parameters, String revisionProperty, - String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, - String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath, - String originalIdPropertyName, String alias1, boolean inclusive, MiddleComponentData... componentDatas); + QueryBuilder rootQueryBuilder, + Parameters parameters, + String revisionProperty, + String revisionEndProperty, + boolean addAlias, + MiddleIdData referencingIdData, + String versionsMiddleEntityName, + String eeOriginalIdPropertyPath, + String revisionPropertyPath, + String originalIdPropertyName, + String alias1, + boolean inclusive, + MiddleComponentData... componentDatas); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java index 139fa7e3a3..22c5c24b5a 100755 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java @@ -3,8 +3,8 @@ package org.hibernate.envers.strategy; import java.io.Serializable; import org.hibernate.Session; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.GlobalConfiguration; -import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData; import org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData; @@ -28,16 +28,26 @@ public class DefaultAuditStrategy implements AuditStrategy { sessionCacheCleaner = new SessionCacheCleaner(); } + @Override public void perform( - Session session, String entityName, AuditConfiguration auditCfg, Serializable id, Object data, + Session session, + String entityName, + EnversService enversService, + Serializable id, + Object data, Object revision) { - session.save( auditCfg.getAuditEntCfg().getAuditEntityName( entityName ), data ); + session.save( enversService.getAuditEntitiesConfiguration().getAuditEntityName( entityName ), data ); sessionCacheCleaner.scheduleAuditDataRemoval( session, data ); } + @Override public void performCollectionChange( - Session session, String entityName, String propertyName, AuditConfiguration auditCfg, - PersistentCollectionChangeData persistentCollectionChangeData, Object revision) { + Session session, + String entityName, + String propertyName, + EnversService enversService, + PersistentCollectionChangeData persistentCollectionChangeData, + Object revision) { session.save( persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData() ); sessionCacheCleaner.scheduleAuditDataRemoval( session, persistentCollectionChangeData.getData() ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java index 2558340004..ede6f3dd0c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java @@ -5,35 +5,25 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Date; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; - -import org.jboss.logging.Logger; import org.hibernate.LockOptions; import org.hibernate.Session; -import org.hibernate.action.spi.AfterTransactionCompletionProcess; import org.hibernate.action.spi.BeforeTransactionCompletionProcess; -import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; +import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; import org.hibernate.envers.configuration.internal.GlobalConfiguration; -import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData; import org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData; import org.hibernate.envers.internal.synchronization.SessionCacheCleaner; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; -import org.hibernate.event.service.spi.EventListenerRegistry; -import org.hibernate.event.spi.AutoFlushEvent; -import org.hibernate.event.spi.AutoFlushEventListener; import org.hibernate.event.spi.EventSource; -import org.hibernate.event.spi.EventType; import org.hibernate.jdbc.ReturningWork; import org.hibernate.persister.entity.Queryable; import org.hibernate.persister.entity.UnionSubclassEntityPersister; @@ -70,8 +60,6 @@ import static org.hibernate.envers.internal.entities.mapper.relation.query.Query * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class ValidityAuditStrategy implements AuditStrategy { - private static final Logger log = Logger.getLogger( ValidityAuditStrategy.class ); - /** * getter for the revision entity field annotated with @RevisionTimestamp */ @@ -83,16 +71,17 @@ public class ValidityAuditStrategy implements AuditStrategy { sessionCacheCleaner = new SessionCacheCleaner(); } + @Override public void perform( final Session session, final String entityName, - final AuditConfiguration auditCfg, + final EnversService enversService, final Serializable id, final Object data, final Object revision) { - final AuditEntitiesConfiguration audEntitiesCfg = auditCfg.getAuditEntCfg(); + final AuditEntitiesConfiguration audEntitiesCfg = enversService.getAuditEntitiesConfiguration(); final String auditedEntityName = audEntitiesCfg.getAuditEntityName( entityName ); - final String revisionInfoEntityName = auditCfg.getAuditEntCfg().getRevisionInfoEntityName(); + final String revisionInfoEntityName = enversService.getAuditEntitiesConfiguration().getRevisionInfoEntityName(); // Save the audit data session.save( auditedEntityName, data ); @@ -104,8 +93,8 @@ public class ValidityAuditStrategy implements AuditStrategy { // inserted for the first time. But in case a deleted primary key value was // reused, this guarantees correct strategy behavior: exactly one row with // null end date exists for each identifier. - final boolean reuseEntityIdentifier = auditCfg.getGlobalCfg().isAllowIdentifierReuse(); - if ( reuseEntityIdentifier || getRevisionType( auditCfg, data ) != RevisionType.ADD ) { + final boolean reuseEntityIdentifier = enversService.getGlobalConfiguration().isAllowIdentifierReuse(); + if ( reuseEntityIdentifier || getRevisionType( enversService, data ) != RevisionType.ADD ) { // Register transaction completion process to guarantee execution of UPDATE statement after INSERT. ( (EventSource) session ).getActionQueue().registerProcess( new BeforeTransactionCompletionProcess() { @Override @@ -134,9 +123,9 @@ public class ValidityAuditStrategy implements AuditStrategy { } final Type revisionInfoIdType = sessionImplementor.getFactory().getEntityPersister( revisionInfoEntityName ).getIdentifierType(); - final String revEndColumnName = rootAuditedEntityQueryable.toColumns( auditCfg.getAuditEntCfg().getRevisionEndFieldName() )[0]; + final String revEndColumnName = rootAuditedEntityQueryable.toColumns( enversService.getAuditEntitiesConfiguration().getRevisionEndFieldName() )[0]; - final boolean isRevisionEndTimestampEnabled = auditCfg.getAuditEntCfg().isRevisionEndTimestampEnabled(); + final boolean isRevisionEndTimestampEnabled = enversService.getAuditEntitiesConfiguration().isRevisionEndTimestampEnabled(); // update audit_ent set REVEND = ? [, REVEND_TSTMP = ?] where (prod_ent_id) = ? and REV <> ? and REVEND is null final Update update = new Update( sessionImplementor.getFactory().getDialect() ).setTableName( updateTableName ); @@ -145,7 +134,7 @@ public class ValidityAuditStrategy implements AuditStrategy { // set [, REVEND_TSTMP = ?] if ( isRevisionEndTimestampEnabled ) { update.addColumn( - rootAuditedEntityQueryable.toColumns( auditCfg.getAuditEntCfg().getRevisionEndTimestampFieldName() )[0] + rootAuditedEntityQueryable.toColumns( enversService.getAuditEntitiesConfiguration().getRevisionEndTimestampFieldName() )[0] ); } @@ -153,7 +142,7 @@ public class ValidityAuditStrategy implements AuditStrategy { update.addPrimaryKeyColumns( rootProductionEntityQueryable.getIdentifierColumnNames() ); // where REV <> ? update.addWhereColumn( - rootAuditedEntityQueryable.toColumns( auditCfg.getAuditEntCfg().getRevisionNumberPath() )[0], "<> ?" + rootAuditedEntityQueryable.toColumns( enversService.getAuditEntitiesConfiguration().getRevisionNumberPath() )[0], "<> ?" ); // where REVEND is null update.addWhereColumn( revEndColumnName, " is null" ); @@ -172,7 +161,7 @@ public class ValidityAuditStrategy implements AuditStrategy { int index = 1; // set REVEND = ? - final Number revisionNumber = auditCfg.getRevisionInfoNumberReader().getRevisionNumber( + final Number revisionNumber = enversService.getRevisionInfoNumberReader().getRevisionNumber( revision ); revisionInfoIdType.nullSafeSet( @@ -185,7 +174,7 @@ public class ValidityAuditStrategy implements AuditStrategy { final Object revEndTimestampObj = revisionTimestampGetter.get( revision ); final Date revisionEndTimestamp = convertRevEndTimestampToDate( revEndTimestampObj ); final Type revEndTsType = rootAuditedEntityQueryable.getPropertyType( - auditCfg.getAuditEntCfg().getRevisionEndTimestampFieldName() + enversService.getAuditEntitiesConfiguration().getRevisionEndTimestampFieldName() ); revEndTsType.nullSafeSet( preparedStatement, revisionEndTimestamp, index, sessionImplementor @@ -200,7 +189,7 @@ public class ValidityAuditStrategy implements AuditStrategy { // where REV <> ? final Type revType = rootAuditedEntityQueryable.getPropertyType( - auditCfg.getAuditEntCfg().getRevisionNumberPath() + enversService.getAuditEntitiesConfiguration().getRevisionNumberPath() ); revType.nullSafeSet( preparedStatement, revisionNumber, index, sessionImplementor ); @@ -219,7 +208,7 @@ public class ValidityAuditStrategy implements AuditStrategy { } ); - if ( rowCount != 1 && ( !reuseEntityIdentifier || ( getRevisionType( auditCfg, data ) != RevisionType.ADD ) ) ) { + if ( rowCount != 1 && ( !reuseEntityIdentifier || ( getRevisionType( enversService, data ) != RevisionType.ADD ) ) ) { throw new RuntimeException( "Cannot update previous revision for entity " + auditedEntityName + " and id " + id ); @@ -234,18 +223,22 @@ public class ValidityAuditStrategy implements AuditStrategy { return (Queryable) sessionImplementor.getFactory().getEntityPersister( entityName ); } + @Override @SuppressWarnings({"unchecked"}) public void performCollectionChange( - Session session, String entityName, String propertyName, AuditConfiguration auditCfg, + Session session, + String entityName, + String propertyName, + EnversService enversService, PersistentCollectionChangeData persistentCollectionChangeData, Object revision) { final QueryBuilder qb = new QueryBuilder( persistentCollectionChangeData.getEntityName(), MIDDLE_ENTITY_ALIAS ); - final String originalIdPropName = auditCfg.getAuditEntCfg().getOriginalIdPropName(); + final String originalIdPropName = enversService.getAuditEntitiesConfiguration().getOriginalIdPropName(); final Map originalId = (Map) persistentCollectionChangeData.getData().get( originalIdPropName ); - final String revisionFieldName = auditCfg.getAuditEntCfg().getRevisionFieldName(); - final String revisionTypePropName = auditCfg.getAuditEntCfg().getRevisionTypePropName(); + final String revisionFieldName = enversService.getAuditEntitiesConfiguration().getRevisionFieldName(); + final String revisionTypePropName = enversService.getAuditEntitiesConfiguration().getRevisionTypePropName(); // Adding a parameter for each id component, except the rev number and type. for ( Map.Entry originalIdEntry : originalId.entrySet() ) { @@ -272,7 +265,7 @@ public class ValidityAuditStrategy implements AuditStrategy { } } - addEndRevisionNullRestriction( auditCfg, qb.getRootParameters() ); + addEndRevisionNullRestriction( enversService, qb.getRootParameters() ); final List l = qb.toQuery( session ).setLockOptions( LockOptions.UPGRADE ).list(); @@ -281,7 +274,7 @@ public class ValidityAuditStrategy implements AuditStrategy { // ADD, we may need to update the last revision. if ( l.size() > 0 ) { updateLastRevision( - session, auditCfg, l, originalId, persistentCollectionChangeData.getEntityName(), revision + session, enversService, l, originalId, persistentCollectionChangeData.getEntityName(), revision ); } @@ -290,8 +283,8 @@ public class ValidityAuditStrategy implements AuditStrategy { sessionCacheCleaner.scheduleAuditDataRemoval( session, persistentCollectionChangeData.getData() ); } - private void addEndRevisionNullRestriction(AuditConfiguration auditCfg, Parameters rootParameters) { - rootParameters.addWhere( auditCfg.getAuditEntCfg().getRevisionEndFieldName(), true, "is", "null", false ); + private void addEndRevisionNullRestriction(EnversService enversService, Parameters rootParameters) { + rootParameters.addWhere( enversService.getAuditEntitiesConfiguration().getRevisionEndFieldName(), true, "is", "null", false ); } public void addEntityAtRevisionRestriction( @@ -327,24 +320,28 @@ public class ValidityAuditStrategy implements AuditStrategy { } @SuppressWarnings({"unchecked"}) - private RevisionType getRevisionType(AuditConfiguration auditCfg, Object data) { - return (RevisionType) ((Map) data).get( auditCfg.getAuditEntCfg().getRevisionTypePropName() ); + private RevisionType getRevisionType(EnversService enversService, Object data) { + return (RevisionType) ((Map) data).get( enversService.getAuditEntitiesConfiguration().getRevisionTypePropName() ); } @SuppressWarnings({"unchecked"}) private void updateLastRevision( - Session session, AuditConfiguration auditCfg, List l, - Object id, String auditedEntityName, Object revision) { + Session session, + EnversService enversService, + List l, + Object id, + String auditedEntityName, + Object revision) { // There should be one entry if ( l.size() == 1 ) { // Setting the end revision to be the current rev Object previousData = l.get( 0 ); - String revisionEndFieldName = auditCfg.getAuditEntCfg().getRevisionEndFieldName(); + String revisionEndFieldName = enversService.getAuditEntitiesConfiguration().getRevisionEndFieldName(); ((Map) previousData).put( revisionEndFieldName, revision ); - if ( auditCfg.getAuditEntCfg().isRevisionEndTimestampEnabled() ) { + if ( enversService.getAuditEntitiesConfiguration().isRevisionEndTimestampEnabled() ) { // Determine the value of the revision property annotated with @RevisionTimestamp - String revEndTimestampFieldName = auditCfg.getAuditEntCfg().getRevisionEndTimestampFieldName(); + String revEndTimestampFieldName = enversService.getAuditEntitiesConfiguration().getRevisionEndTimestampFieldName(); Object revEndTimestampObj = this.revisionTimestampGetter.get( revision ); Date revisionEndTimestamp = convertRevEndTimestampToDate( revEndTimestampObj ); 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 deleted file mode 100644 index 4d68a1b554..0000000000 --- a/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.tools.hbm2ddl; - -import java.sql.Connection; -import java.util.Properties; - -import org.hibernate.HibernateException; -import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.cfg.Configuration; -import org.hibernate.envers.configuration.spi.AuditConfiguration; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.tool.hbm2ddl.SchemaExport; - -/** - * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) - */ -public class EnversSchemaGenerator { - private final SchemaExport export; - - public EnversSchemaGenerator(MetadataImplementor metadata) { - this( metadata.getMetadataBuildingOptions().getServiceRegistry(), metadata ); - } - - public EnversSchemaGenerator(ServiceRegistry serviceRegistry, MetadataImplementor metadata) { - this.export = new SchemaExport( serviceRegistry, metadata ); - } - - 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 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.boot.model.TypeContributor b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor index 5eeaedd30c..4a66fe2ae9 100644 --- a/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor +++ b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor @@ -1 +1 @@ -org.hibernate.envers.internal.entities.TypeContributorImpl \ No newline at end of file +org.hibernate.envers.boot.internal.TypeContributorImpl \ No newline at end of file diff --git a/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.boot.spi.AdditionalJaxbMappingProducer b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.boot.spi.AdditionalJaxbMappingProducer new file mode 100644 index 0000000000..f510dc2f55 --- /dev/null +++ b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.boot.spi.AdditionalJaxbMappingProducer @@ -0,0 +1 @@ +org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl \ No newline at end of file diff --git a/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.integrator.spi.Integrator b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.integrator.spi.Integrator index 4155dd7232..4448597db5 100644 --- a/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.integrator.spi.Integrator +++ b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.integrator.spi.Integrator @@ -1 +1 @@ -org.hibernate.envers.event.spi.EnversIntegrator \ No newline at end of file +org.hibernate.envers.boot.internal.EnversIntegrator \ No newline at end of file diff --git a/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor new file mode 100644 index 0000000000..e7bf4c4097 --- /dev/null +++ b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor @@ -0,0 +1 @@ +org.hibernate.envers.boot.internal.EnversServiceContributor \ No newline at end of file diff --git a/hibernate-envers/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/hibernate-envers/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 93892568ed..fdc7cbe106 100644 --- a/hibernate-envers/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/hibernate-envers/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -4,10 +4,10 @@ xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - + - + diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversFunctionalTestCase.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversFunctionalTestCase.java index 4a703064a5..0d2d675bca 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversFunctionalTestCase.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversFunctionalTestCase.java @@ -2,14 +2,14 @@ package org.hibernate.envers.test; import java.util.Arrays; import java.util.List; +import java.util.Map; import org.hibernate.Session; -import org.hibernate.cfg.Configuration; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.configuration.EnversSettings; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -17,7 +17,7 @@ import org.junit.runners.Parameterized; * @author Strong Liu (stliu@hibernate.org) */ @RunWith(EnversRunner.class) -public abstract class BaseEnversFunctionalTestCase extends BaseCoreFunctionalTestCase { +public abstract class BaseEnversFunctionalTestCase extends BaseNonConfigCoreFunctionalTestCase { private String auditStrategy; @Parameterized.Parameters @@ -36,7 +36,9 @@ public abstract class BaseEnversFunctionalTestCase extends BaseCoreFunctionalTes return auditStrategy; } + @Override protected Session getSession() { + Session session = super.getSession(); if ( session == null || !session.isOpen() ) { return openSession(); } @@ -48,10 +50,10 @@ public abstract class BaseEnversFunctionalTestCase extends BaseCoreFunctionalTes } @Override - protected Configuration constructConfiguration() { - Configuration configuration = super.constructConfiguration(); - configuration.setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" ); - return configuration; + protected void addSettings(Map settings) { + super.addSettings( settings ); + + settings.put( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" ); } @Override 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 6cb7c20e3d..bdbf153748 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 @@ -32,14 +32,14 @@ import javax.persistence.EntityManagerFactory; import javax.transaction.SystemException; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; -import org.hibernate.cfg.Configuration; +import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; +import org.hibernate.envers.boot.internal.EnversIntegrator; import org.hibernate.envers.configuration.EnversSettings; -import org.hibernate.envers.event.spi.EnversIntegrator; import org.hibernate.internal.util.StringHelper; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; @@ -84,8 +84,8 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest return serviceRegistry; } - protected Configuration getCfg() { - return entityManagerFactoryBuilder.getHibernateConfiguration(); + protected MetadataImplementor metadata() { + return entityManagerFactoryBuilder.getMetadata(); } @BeforeClassOnce 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 6a8168241b..746f0604c5 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 @@ -38,9 +38,9 @@ public class ColumnScalePrecisionTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().commit(); id = entity.getId(); - auditTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity_AUD" ) + auditTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity_AUD" ) .getTable(); - originalTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity" ) + originalTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity" ) .getTable(); } 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..0d19b8401a 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 @@ -23,8 +23,6 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -33,6 +31,8 @@ import org.hibernate.mapping.PersistentClass; import org.junit.Assert; import org.junit.Test; +import static org.hibernate.envers.internal.tools.Tools.collectionToList; + /** * @author Adam Warski (adam at warski dot org) */ @@ -44,17 +44,8 @@ public class NoneAudited extends BaseEnversJPAFunctionalTestCase { @Test public void testRevisionInfoTableNotCreated() { - @SuppressWarnings({"unchecked"}) List pcs = iteratorToList( getCfg().getClassMappings() ); + @SuppressWarnings({"unchecked"}) List pcs = collectionToList( metadata().getEntityBindings() ); Assert.assertEquals( 1, pcs.size() ); Assert.assertTrue( pcs.get( 0 ).getClassName().contains( "BasicTestEntity3" ) ); } - - private List iteratorToList(Iterator it) { - List result = new ArrayList(); - while ( it.hasNext() ) { - result.add( it.next() ); - } - - return result; - } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/OutsideTransactionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/OutsideTransactionTest.java index 5519d305a1..71859c1dc7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/OutsideTransactionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/OutsideTransactionTest.java @@ -1,7 +1,8 @@ package org.hibernate.envers.test.integration.basic; +import java.util.Map; + import org.hibernate.Session; -import org.hibernate.cfg.Configuration; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; @@ -23,9 +24,11 @@ public class OutsideTransactionTest extends BaseEnversFunctionalTestCase { } @Override - protected void configure(Configuration configuration) { - configuration.setProperty( EnversSettings.STORE_DATA_AT_DELETE, "true" ); - configuration.setProperty( EnversSettings.REVISION_ON_COLLECTION_CHANGE, "true" ); + protected void addSettings(Map settings) { + super.addSettings( settings ); + + settings.put( EnversSettings.STORE_DATA_AT_DELETE, "true" ); + settings.put( EnversSettings.REVISION_ON_COLLECTION_CHANGE, "true" ); } @Test(expected = AuditException.class) diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java index 294f109f21..70f15283d4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.collection.norevision; import java.util.List; +import java.util.Map; import org.hibernate.Session; -import org.hibernate.cfg.Configuration; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -14,8 +14,10 @@ public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalT protected Integer personId; @Override - protected void configure(Configuration configuration) { - configuration.setProperty( EnversSettings.REVISION_ON_COLLECTION_CHANGE, getCollectionChangeValue() ); + protected void addSettings(Map settings) { + super.addSettings( settings ); + + settings.put( EnversSettings.REVISION_ON_COLLECTION_CHANGE, getCollectionChangeValue() ); } @Override 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 d0e3c30a81..ce41197798 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 @@ -33,10 +33,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" ); @@ -79,11 +79,8 @@ public class PropertiesGroupTest extends BaseEnversFunctionalTestCase { @Test public void testHistoryOfUniquePropsNotAuditedEntity() { Assert.assertEquals( - entityNotAuditedRev2, getAuditReader().find( - UniquePropsNotAuditedEntity.class, - entityNotAuditedRev2.getId(), - 2 - ) + entityNotAuditedRev2, + getAuditReader().find( UniquePropsNotAuditedEntity.class, entityNotAuditedRev2.getId(), 2 ) ); } } 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 a08bc88b16..527a821282 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 @@ -2,6 +2,7 @@ package org.hibernate.envers.test.integration.customtype; import java.util.Arrays; import java.util.List; +import java.util.Map; import org.hibernate.Session; import org.hibernate.cfg.Configuration; @@ -30,9 +31,10 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase { } @Override - protected void configure(Configuration configuration) { - super.configure( configuration ); - configuration.setProperty( Environment.HBM2DDL_AUTO, "" ); + protected void addSettings(Map settings) { + super.addSettings( settings ); + + settings.put( Environment.HBM2DDL_AUTO, "" ); } @Test @@ -47,7 +49,7 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase { @Test @Priority(1) public void dropSchema() { - dropSchema( session ); + dropSchema( getSession() ); } public void dropSchema(Session session) { 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 411cfdd0db..0e86e5a94f 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 @@ -101,11 +101,9 @@ public class ChildPrimaryKeyJoinAuditing extends BaseEnversJPAFunctionalTestCase public void testChildIdColumnName() { Assert.assertEquals( "other_id", - ((Column) getCfg() - .getClassMapping( - "org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin.ChildPrimaryKeyJoinEntity_AUD" - ) - .getKey().getColumnIterator().next()).getName() + ((Column) metadata().getEntityBinding( + "org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin.ChildPrimaryKeyJoinEntity_AUD" + ).getKey().getColumnIterator().next()).getName() ); } } \ No newline at end of file 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 327382fba6..f0a33c79f2 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 @@ -31,7 +31,7 @@ public class DiscriminatorFormulaTest extends BaseEnversJPAFunctionalTestCase { @Test @Priority(10) public void initData() { - parentAudit = getCfg().getClassMapping( + parentAudit = metadata().getEntityBinding( "org.hibernate.envers.test.integration.inheritance.single.discriminatorformula.ParentEntity_AUD" ); 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 f51f90a97d..9f73c21ab9 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 @@ -37,9 +37,7 @@ public class AuditedAbstractParentTest extends BaseEnversJPAFunctionalTestCase { @Test public void testAbstractTableExistence() { - Iterator tableIterator = getCfg().getTableMappings(); - while ( tableIterator.hasNext() ) { - Table table = tableIterator.next(); + for ( Table table : metadata().collectTableMappings() ) { if ( "AbstractEntity_AUD".equals( table.getName() ) ) { Assert.assertFalse( table.isPhysicalTable() ); return; 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 0352c455c5..cb7b3850f4 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 @@ -139,7 +139,7 @@ public class HasChangedComponents extends AbstractModifiedFlagsEntityTest { assertEquals( TestTools.makeSet( "comp1_MOD" ), TestTools.extractModProperties( - getCfg().getClassMapping( + metadata().getEntityBinding( "org.hibernate.envers.test.entities.components.ComponentTestEntity_AUD" ) ) 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 18f3754e0c..1fa5e0cfc7 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( + metadata().getEntityBinding( "org.hibernate.envers.test.integration.basic.BasicTestEntity1_AUD" ), "_CHANGED" 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 384d366e2b..e3778ef9b1 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,7 @@ 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() + metadata().getEntityBinding( "org.hibernate.envers.test.integration.naming.NamingTestEntity1_AUD" ).getTable().getName() ); } } 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 42bde825ab..e9ad60c91b 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 @@ -128,9 +128,9 @@ 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(); + Iterator columns = metadata().getEntityBinding( + "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() ); 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 98ccf115d8..4f1b967d38 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 @@ -104,7 +104,7 @@ public class OneToManyUnidirectionalNaming extends BaseEnversJPAFunctionalTestCa @Test public void testTableName() { assert MIDDLE_VERSIONS_ENTITY_NAME.equals( - getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getName() + metadata().getEntityBinding( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getName() ); } @@ -112,7 +112,7 @@ public class OneToManyUnidirectionalNaming extends BaseEnversJPAFunctionalTestCa @Test public void testJoinColumnName() { Iterator columns = - getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getColumnIterator(); + metadata().getEntityBinding( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getColumnIterator(); boolean id1Found = false; boolean id2Found = false; 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 895363ca1e..1a2b221f32 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 @@ -109,7 +109,7 @@ public class VersionsJoinTableNaming extends BaseEnversJPAFunctionalTestCase { @Test public void testTableName() { assert MIDDLE_VERSIONS_ENTITY_NAME.equals( - getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getName() + metadata().getEntityBinding( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getName() ); } @@ -117,7 +117,7 @@ public class VersionsJoinTableNaming extends BaseEnversJPAFunctionalTestCase { @Test public void testJoinColumnName() { Iterator columns = - getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getColumnIterator(); + metadata().getEntityBinding( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getColumnIterator(); boolean id1Found = false; boolean id2Found = false; 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 440c397b35..37983e1f0b 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 @@ -198,7 +198,7 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testExpectedTableNameComponent1() { - PersistentClass auditClass = getCfg().getClassMapping( + PersistentClass auditClass = metadata().getEntityBinding( COMPONENT_1_AUDIT_JOIN_TABLE_NAME ); assert auditClass != null; @@ -210,7 +210,7 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testExpectedTableNameComponent2() { - PersistentClass auditClass = getCfg().getClassMapping( + PersistentClass auditClass = metadata().getEntityBinding( COMPONENT_2_AUDIT_JOIN_TABLE_NAME ); assert auditClass != null; @@ -222,7 +222,7 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testWrongTableNameComponent1() { - PersistentClass auditClass = getCfg().getClassMapping( + PersistentClass auditClass = metadata().getEntityBinding( UNMODIFIED_COMPONENT_1_AUDIT_JOIN_TABLE_NAME ); assert auditClass == null; @@ -230,7 +230,7 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testWrongTableNameComponent2() { - PersistentClass auditClass = getCfg().getClassMapping( + PersistentClass auditClass = metadata().getEntityBinding( UNMODIFIED_COMPONENT_2_AUDIT_JOIN_TABLE_NAME ); assert auditClass == null; @@ -238,7 +238,7 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testJoinColumnNamesComponent1() { - PersistentClass auditClass = getCfg().getClassMapping( + PersistentClass auditClass = metadata().getEntityBinding( COMPONENT_1_AUDIT_JOIN_TABLE_NAME ); assert auditClass != null; @@ -265,7 +265,7 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testJoinColumnNamesComponent2() { - PersistentClass auditClass = getCfg().getClassMapping( + PersistentClass auditClass = metadata().getEntityBinding( COMPONENT_2_AUDIT_JOIN_TABLE_NAME ); assert auditClass != null; @@ -297,7 +297,7 @@ public class VersionsJoinTableRangeComponentNamingTest extends */ @Test public void testOverrideNotAudited() { - PersistentClass auditClass = getCfg().getClassMapping( + PersistentClass auditClass = metadata().getEntityBinding( VersionsJoinTableRangeComponentTestEntity.class.getName() + "_AUD" ); 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 3412b3a47d..de94c9ffe2 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 @@ -141,19 +141,17 @@ public class JoinEmbIdNaming extends BaseEnversJPAFunctionalTestCase { @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnNames() { - Iterator columns = - getCfg().getClassMapping( - "org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD" - ) - .getProperty( "reference_x" ).getColumnIterator(); + Iterator columns = metadata().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() ); - columns = getCfg().getClassMapping( + columns = metadata().getEntityBinding( "org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD" - ) - .getProperty( "reference_y" ).getColumnIterator(); + ).getProperty( "reference_y" ).getColumnIterator(); assertTrue( columns.hasNext() ); assertEquals( "YY_reference", columns.next().getName() ); 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 baac1f080f..896f1a1b64 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 @@ -141,19 +141,18 @@ 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(); + Iterator columns = metadata().getEntityBinding( + "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( + columns = metadata().getEntityBinding( "org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD" - ) - .getProperty( "reference_id2" ).getColumnIterator(); + ).getProperty( "reference_id2" ).getColumnIterator(); + assertTrue( columns.hasNext() ); assertEquals( "ID2_reference", columns.next().getName() ); assertFalse( columns.hasNext() ); 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 e8fa18936a..a9ea38d245 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 @@ -80,7 +80,7 @@ public class QuotedFieldsTest extends BaseEnversJPAFunctionalTestCase { @Test public void testEscapeEntityField() { - Table table = getCfg().getClassMapping( + Table table = metadata().getEntityBinding( "org.hibernate.envers.test.integration.naming.quotation.QuotedFieldsEntity_AUD" ).getTable(); Column column1 = getColumnByName( table, "id" ); 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 00f9ac30f6..fed22f9c97 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 @@ -92,7 +92,7 @@ public class UnversionedOptimisticLockingField extends BaseEnversJPAFunctionalTe @Test public void testMapping() { - PersistentClass pc = getCfg().getClassMapping( UnversionedOptimisticLockingFieldEntity.class.getName() + "_AUD" ); + PersistentClass pc = metadata().getEntityBinding( UnversionedOptimisticLockingFieldEntity.class.getName() + "_AUD" ); Iterator pi = pc.getPropertyIterator(); while ( pi.hasNext() ) { Property p = (Property) pi.next(); 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 9f6c6ae1cd..3baf1ae123 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 @@ -64,7 +64,7 @@ public class DifferentDBSchemaTest extends BaseEnversJPAFunctionalTestCase { @Test public void testRevinfoSchemaName() { - Table revisionTable = getCfg().getClassMapping( "org.hibernate.envers.enhanced.SequenceIdRevisionEntity" ) + Table revisionTable = metadata().getEntityBinding( "org.hibernate.envers.enhanced.SequenceIdRevisionEntity" ) .getTable(); assert SCHEMA_NAME.equals( revisionTable.getSchema() ); } 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..18b3652d04 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 @@ -50,8 +50,8 @@ 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" ) + Iterator childEntityKeyColumnsIterator = metadata() + .getEntityBinding("org.hibernate.envers.test.integration.inheritance.joined.ChildEntity_AUD" ) .getKey() .getColumnIterator(); childEntityKeyColumnsIterator.next(); 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 140c4ca473..39f87e299d 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 @@ -73,9 +73,7 @@ public class DefaultTrackingEntitiesTest extends BaseEnversJPAFunctionalTestCase @Test public void testRevEntityTableCreation() { - Iterator
tableIterator = getCfg().getTableMappings(); - while ( tableIterator.hasNext() ) { - Table table = tableIterator.next(); + for ( Table table : metadata().collectTableMappings() ) { if ( "REVCHANGES".equals( table.getName() ) ) { assert table.getColumnSpan() == 2; assert table.getColumn( new Column( "REV" ) ) != null; 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..f2d5534b85 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 @@ -2,8 +2,8 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; import java.util.ArrayList; import java.util.List; +import java.util.Map; -import org.hibernate.cfg.Configuration; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -24,8 +24,10 @@ public class EntityNamesTest extends BaseEnversFunctionalTestCase { } @Override - protected void configure(Configuration configuration) { - configuration.setProperty( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true" ); + protected void addSettings(Map settings) { + super.addSettings( settings ); + + settings.put( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true" ); } @Test 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 4df793b295..723eb041f9 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 @@ -90,7 +90,7 @@ public class BasicSecondary extends BaseEnversJPAFunctionalTestCase { public void testTableNames() { assert "secondary_AUD".equals( ((Iterator) - getCfg().getClassMapping( + metadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.SecondaryTestEntity_AUD" ) .getJoinIterator()) 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 e6db9bf15e..48623b8043 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 @@ -90,7 +90,7 @@ public class NamingSecondary extends BaseEnversJPAFunctionalTestCase { public void testTableNames() { assert "sec_versions".equals( ((Iterator) - getCfg().getClassMapping( + metadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.SecondaryNamingTestEntity_AUD" ) .getJoinIterator()) 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 478415292a..3401c7408d 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 @@ -89,11 +89,9 @@ public class EmbIdSecondary extends BaseEnversJPAFunctionalTestCase { public void testTableNames() { assert "sec_embid_versions".equals( ((Iterator) - getCfg().getClassMapping( + metadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.ids.SecondaryEmbIdTestEntity_AUD" - ) - .getJoinIterator()) - .next().getTable().getName() + ).getJoinIterator()).next().getTable().getName() ); } } \ 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 209248f8be..0620775084 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 @@ -89,7 +89,7 @@ public class MulIdSecondary extends BaseEnversJPAFunctionalTestCase { public void testTableNames() { assert "sec_mulid_versions".equals( ((Iterator) - getCfg().getClassMapping( + metadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.ids.SecondaryMulIdTestEntity_AUD" ) .getJoinIterator()) 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 8e72ffeec0..f380137469 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 @@ -49,10 +49,10 @@ public class AuditClassOverrideTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().commit(); classNotAuditedEntityId = classOverrideNotAuditedEntity.getId(); - classAuditedTable = getCfg().getClassMapping( + classAuditedTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideAuditedEntity_AUD" ).getTable(); - classNotAuditedTable = getCfg().getClassMapping( + classNotAuditedTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideNotAuditedEntity_AUD" ).getTable(); } 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 9d70e847ad..631ef7df71 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 @@ -54,13 +54,13 @@ public class AuditPropertyOverrideTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().commit(); auditedEntityId = auditedEntity.getId(); - propertyTable = getCfg().getClassMapping( + propertyTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.PropertyOverrideEntity_AUD" ).getTable(); - transitiveTable = getCfg().getClassMapping( + transitiveTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.TransitiveOverrideEntity_AUD" ).getTable(); - auditedTable = getCfg().getClassMapping( + auditedTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.AuditedSpecialEntity_AUD" ).getTable(); } 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 55fc03e2d4..28d5f349b7 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 @@ -36,7 +36,7 @@ public class MixedOverrideTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().commit(); mixedEntityId = mixedEntity.getId(); - mixedTable = getCfg().getClassMapping( + mixedTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditoverride.MixedOverrideEntity_AUD" ).getTable(); } 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 91371b8716..3aae726bc6 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 @@ -62,7 +62,7 @@ public class MultipleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { Set expectedColumns = TestTools.makeSet( "child", "parent", "relation_id", "grandparent", "id" ); Set unexpectedColumns = TestTools.makeSet( "notAudited" ); - Table table = getCfg().getClassMapping( + Table table = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ChildMultipleParentsEntity_AUD" ).getTable(); 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 1752542f3f..ea059136d3 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 @@ -63,7 +63,7 @@ public class SingleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { Set expectedColumns = TestTools.makeSet( "child", "grandparent", "id" ); Set unexpectedColumns = TestTools.makeSet( "parent", "relation_id", "notAudited" ); - Table table = getCfg().getClassMapping( + Table table = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ChildSingleParentEntity_AUD" ).getTable(); 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 6fe7d4bc8b..57c51d22e1 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 @@ -71,7 +71,7 @@ public class TotalAuditParentsTest extends BaseEnversJPAFunctionalTestCase { ); Set unexpectedColumns = TestTools.makeSet( "notAudited" ); - Table table = getCfg().getClassMapping( + Table table = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.BabyCompleteEntity_AUD" ).getTable(); 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 5a18431928..96d2bb0ed8 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 @@ -67,7 +67,7 @@ public class TransitiveAuditParentsTest extends BaseEnversJPAFunctionalTestCase @Test public void testCreatedAuditTables() { - Table explicitTransChildTable = getCfg().getClassMapping( + Table explicitTransChildTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ExplicitTransitiveChildEntity_AUD" ).getTable(); checkTableColumns( @@ -76,7 +76,7 @@ public class TransitiveAuditParentsTest extends BaseEnversJPAFunctionalTestCase explicitTransChildTable ); - Table implicitTransChildTable = getCfg().getClassMapping( + Table implicitTransChildTable = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ImplicitTransitiveChildEntity_AUD" ).getTable(); checkTableColumns( 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 619198cb0b..efa3c17ea6 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 @@ -6,7 +6,6 @@ import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; -import org.hibernate.envers.tools.hbm2ddl.EnversSchemaGenerator; import org.hibernate.testing.TestForIssue; import org.junit.Assert; @@ -24,17 +23,9 @@ public class SchemaExportTest extends BaseEnversFunctionalTestCase { return new Class[] {StrTestEntity.class}; } - protected boolean createSchema() { - // Disable schema auto generation. - return false; - } - @Test @Priority(10) public void testSchemaCreation() { - // Generate complete schema. - new EnversSchemaGenerator( configuration() ).export().create( true, true ); - // Populate database with test data. Session session = getSession(); session.getTransaction().begin(); @@ -51,10 +42,4 @@ public class SchemaExportTest extends BaseEnversFunctionalTestCase { Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestEntity.class, id ) ); Assert.assertEquals( new StrTestEntity( "data", id ), getAuditReader().find( StrTestEntity.class, id, 1 ) ); } - - @Test - @Priority(8) - public void testSchemaDrop() { - new EnversSchemaGenerator( configuration() ).export().drop( true, true ); - } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java index 29e7d2dfc0..6dfa030cc8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java @@ -35,7 +35,7 @@ import org.hibernate.dialect.Dialect; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.configuration.EnversSettings; -import org.hibernate.envers.event.spi.EnversIntegrator; +import org.hibernate.envers.boot.internal.EnversIntegrator; import org.hibernate.envers.test.AbstractEnversTest; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; diff --git a/hibernate-envers/src/test/resources/log4j.properties b/hibernate-envers/src/test/resources/log4j.properties index fa55250f40..091e82c4ba 100644 --- a/hibernate-envers/src/test/resources/log4j.properties +++ b/hibernate-envers/src/test/resources/log4j.properties @@ -9,4 +9,6 @@ log4j.logger.org.hibernate.test=info log4j.logger.org.hibernate.tool.hbm2ddl=debug # SQL Logging - HHH-6833 -log4j.logger.org.hibernate.SQL=debug \ No newline at end of file +log4j.logger.org.hibernate.SQL=debug + +log4j.logger.org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl=trace \ No newline at end of file diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java index 8e13a3c5dc..b5d6951f3d 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java @@ -121,6 +121,10 @@ public class BaseNonConfigCoreFunctionalTestCase extends BaseUnitTestCase { return session; } + protected Session getSession() { + return session; + } + protected void rebuildSessionFactory() { releaseResources(); buildResources(); diff --git a/working-5.0-migration-guide.md b/working-5.0-migration-guide.md index b8e201de68..7fd1a1ef1d 100644 --- a/working-5.0-migration-guide.md +++ b/working-5.0-migration-guide.md @@ -19,6 +19,9 @@ Working list of changes for 5.0 * `Configuration` is no longer `Serializable` * `org.hibernate.dialect.Dialect.getQuerySequencesString` expected to retrieve catalog, schema, and increment values as well * properties loaded from cfg.xml through EMF did not previously prefix names with "hibernate." this is now made consistent. +* removed AuditConfiguration in preference for new `org.hibernate.envers.boot.internal.EnversService` +* changed AuditStrategy method parameters from (removed) AuditConfiguration to (new) EnversService + TODOs =====