HHH-9654 - Adjust envers for 5.0 APIs + JAXB
This commit is contained in:
parent
8a42f8a8ae
commit
63a0f03c5a
|
@ -1113,7 +1113,7 @@ query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]></programlist
|
|||
<listitem>
|
||||
<para>
|
||||
Create your own implementation of <literal>org.hibernate.integrator.spi.Integrator</literal>,
|
||||
similar to <literal>org.hibernate.envers.event.spi.EnversIntegrator</literal>. Use your event
|
||||
similar to <literal>org.hibernate.envers.boot.internal.EnversIntegrator</literal>. Use your event
|
||||
listener classes instead of the default ones.
|
||||
</para>
|
||||
</listitem>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<blueprint default-activation="eager"
|
||||
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<bean id="integrator" class="org.hibernate.envers.event.spi.EnversIntegrator" />
|
||||
<bean id="integrator" class="org.hibernate.envers.boot.internal.EnversIntegrator" />
|
||||
<service ref="integrator" interface="org.hibernate.integrator.spi.Integrator" />
|
||||
|
||||
<bean id="typeContributor"
|
||||
class="org.hibernate.envers.internal.entities.TypeContributorImpl" />
|
||||
class="org.hibernate.envers.boot.internal.TypeContributorImpl" />
|
||||
<service ref="typeContributor" interface="org.hibernate.boot.model.TypeContributor" />
|
||||
|
||||
</blueprint>
|
|
@ -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 )
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<BindResult> bindResults = new ArrayList<BindResult>();
|
||||
// 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<AdditionalJaxbMappingProducer> 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<MappingDocument> 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" );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<JaxbHbmHibernateMapping>( 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<Document>( 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -101,7 +101,9 @@ public class JpaOrmXmlEventReader extends EventReaderDelegate {
|
|||
List<Attribute> newElementAttributeList = mapAttributes( startElement );
|
||||
List<Namespace> 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<Namespace> 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()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 <T> The result type
|
||||
*/
|
||||
public static interface Work<T> {
|
||||
/**
|
||||
* 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> T withTccl(Work<T> work) {
|
||||
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
|
|
|
@ -88,4 +88,31 @@ public interface ClassLoaderService extends Service, Stoppable {
|
|||
* @return The ordered set of discovered services.
|
||||
*/
|
||||
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract);
|
||||
|
||||
|
||||
/**
|
||||
* Hack around continued (temporary) need to sometimes set the TCCL for code we call that expects it.
|
||||
*
|
||||
* @param <T> The result type
|
||||
*/
|
||||
@Deprecated
|
||||
public static interface Work<T> {
|
||||
/**
|
||||
* 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 <T> The type of the work result
|
||||
*
|
||||
* @return The work result.
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> T withTccl(Work<T> work);
|
||||
}
|
||||
|
|
|
@ -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<MappingDocument> produceAdditionalMappings(
|
||||
MetadataImplementor metadata,
|
||||
IndexView jandexIndex,
|
||||
MappingBinder mappingBinder,
|
||||
MetadataBuildingContext buildingContext);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<MappingDocument> 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<MappingDocument> additionalMappingDocuments = new ArrayList<MappingDocument>();
|
||||
|
||||
// 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( "------------------------------------------------------------" );
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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 );
|
||||
}
|
||||
}
|
|
@ -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<Void>() {
|
||||
@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?
|
||||
}
|
||||
}
|
|
@ -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<EnversService> {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final EnversServiceInitiator INSTANCE = new EnversServiceInitiator();
|
||||
|
||||
@Override
|
||||
public EnversService initiateService(
|
||||
Map configurationValues,
|
||||
ServiceRegistryImplementor registry) {
|
||||
return new EnversServiceImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<EnversService> getServiceInitiated() {
|
||||
return EnversService.class;
|
||||
}
|
||||
}
|
|
@ -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() }
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<PersistentClass> classes = GraphTopologicalSort.sort( new PersistentClassGraphDefiner( cfg ) )
|
||||
final Iterator<PersistentClass> 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( "-----------" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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<PersistentClass, String> {
|
||||
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<PersistentClass
|
|||
|
||||
@Override
|
||||
public PersistentClass getValue(String entityName) {
|
||||
return cfg.getClassMapping( entityName );
|
||||
return metadata.getEntityBinding( entityName );
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
|
@ -77,6 +77,6 @@ public class PersistentClassGraphDefiner implements GraphDefiner<PersistentClass
|
|||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public List<PersistentClass> getValues() {
|
||||
return Tools.iteratorToList( cfg.getClassMappings() );
|
||||
return Tools.collectionToList( metadata.getEntityBindings() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<PersistentClass> 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<? extends RevisionListener> 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 ))
|
||||
|
|
|
@ -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<String, Map<Join, Element>> 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<String, EntityConfiguration>();
|
||||
notAuditedEntitiesConfigurations = new HashMap<String, EntityConfiguration>();
|
||||
entitiesJoins = new HashMap<String, Map<Join, Element>>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 <properties> tag. See HHH-6636 JIRA issue.
|
||||
createPropertiesGroupMapping( property );
|
||||
|
|
|
@ -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<Configuration, AuditConfiguration> CFGS = new WeakHashMap<Configuration, AuditConfiguration>();
|
||||
|
||||
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<Configuration, AuditConfiguration> c : new HashSet<Map.Entry<Configuration, AuditConfiguration>>(
|
||||
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?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<PersistentCollectionChangeData> collectionChanges = getAuditConfiguration()
|
||||
.getEntCfg()
|
||||
final List<PersistentCollectionChangeData> 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<String> toPropertyNames = getAuditConfiguration().getEntCfg().getToPropertyNames(
|
||||
final Set<String> 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
|
||||
)
|
||||
|
|
|
@ -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<String> toPropertyNames = enversConfiguration.getEntCfg().getToPropertyNames(
|
||||
final Set<String> 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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 <properties> 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 );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<T> implements PropertyMapper {
|
|||
}
|
||||
|
||||
protected abstract Initializor<T> 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<T> 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()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<PersistentCollectionChangeData> 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,
|
||||
|
|
|
@ -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<T extends Collection> extends AbstractCollect
|
|||
|
||||
public BasicCollectionMapper(
|
||||
CommonCollectionMapperData commonCollectionMapperData,
|
||||
Class<? extends T> collectionClass, Class<? extends T> proxyClass,
|
||||
MiddleComponentData elementComponentData, boolean ordinalInId, boolean revisionTypeInId) {
|
||||
Class<? extends T> collectionClass,
|
||||
Class<? extends T> proxyClass,
|
||||
MiddleComponentData elementComponentData,
|
||||
boolean ordinalInId,
|
||||
boolean revisionTypeInId) {
|
||||
super( commonCollectionMapperData, collectionClass, proxyClass, ordinalInId, revisionTypeInId );
|
||||
this.elementComponentData = elementComponentData;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Initializor<T> getInitializor(
|
||||
AuditConfiguration verCfg, AuditReaderImplementor versionsReader,
|
||||
Object primaryKey, Number revision, boolean removed) {
|
||||
EnversService enversService,
|
||||
AuditReaderImplementor versionsReader,
|
||||
Object primaryKey,
|
||||
Number revision,
|
||||
boolean removed) {
|
||||
return new BasicCollectionInitializor<T>(
|
||||
verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(),
|
||||
primaryKey, revision, removed, collectionClass, elementComponentData
|
||||
enversService,
|
||||
versionsReader,
|
||||
commonCollectionMapperData.getQueryGenerator(),
|
||||
primaryKey,
|
||||
revision,
|
||||
removed,
|
||||
collectionClass,
|
||||
elementComponentData
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<List> i
|
|||
|
||||
@Override
|
||||
protected Initializor<List> 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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T extends Map> extends AbstractCollectionMapper
|
|||
|
||||
@Override
|
||||
protected Initializor<T> getInitializor(
|
||||
AuditConfiguration verCfg, AuditReaderImplementor versionsReader,
|
||||
Object primaryKey, Number revision, boolean removed) {
|
||||
EnversService enversService,
|
||||
AuditReaderImplementor versionsReader,
|
||||
Object primaryKey,
|
||||
Number revision,
|
||||
boolean removed) {
|
||||
return new MapCollectionInitializor<T>(
|
||||
verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(),
|
||||
primaryKey, revision, removed, collectionClass, elementComponentData, indexComponentData
|
||||
enversService,
|
||||
versionsReader,
|
||||
commonCollectionMapperData.getQueryGenerator(),
|
||||
primaryKey,
|
||||
revision,
|
||||
removed,
|
||||
collectionClass,
|
||||
elementComponentData,
|
||||
indexComponentData
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<SortedM
|
|||
|
||||
@Override
|
||||
protected Initializor<SortedMap> 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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Sorte
|
|||
|
||||
@Override
|
||||
protected Initializor<SortedSet> 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, Object> data, Object newObj,
|
||||
Object oldObj) {
|
||||
public boolean mapToMapFromEntity(
|
||||
SessionImplementor session,
|
||||
Map<String, Object> data,
|
||||
Object newObj,
|
||||
Object oldObj) {
|
||||
final HashMap<String, Object> newData = new HashMap<String, Object>();
|
||||
|
||||
// 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<String, Object> data, Object newObj,
|
||||
Object oldObj) {
|
||||
public void mapModifiedFlagsToMapFromEntity(
|
||||
SessionImplementor session,
|
||||
Map<String, Object> 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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T> implements Initializor<T>
|
|||
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<T> implements Initializor<T>
|
|||
this.revision = revision;
|
||||
this.removed = removed;
|
||||
|
||||
entityInstantiator = new EntityInstantiator( verCfg, versionsReader );
|
||||
entityInstantiator = new EntityInstantiator( enversService, versionsReader );
|
||||
}
|
||||
|
||||
protected abstract T initializeCollection(int size);
|
||||
|
|
|
@ -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<Ob
|
|||
private final MiddleComponentData indexComponentData;
|
||||
|
||||
public ArrayCollectionInitializor(
|
||||
AuditConfiguration verCfg,
|
||||
EnversService enversService,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey, Number revision, boolean removed,
|
||||
MiddleComponentData elementComponentData,
|
||||
MiddleComponentData indexComponentData) {
|
||||
super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed );
|
||||
super( enversService, versionsReader, queryGenerator, primaryKey, revision, removed );
|
||||
|
||||
this.elementComponentData = elementComponentData;
|
||||
this.indexComponentData = indexComponentData;
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.Collection;
|
|||
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.exception.AuditException;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.query.RelationQueryGenerator;
|
||||
|
@ -45,13 +45,13 @@ public class BasicCollectionInitializor<T extends Collection> extends AbstractCo
|
|||
private final MiddleComponentData elementComponentData;
|
||||
|
||||
public BasicCollectionInitializor(
|
||||
AuditConfiguration verCfg,
|
||||
EnversService enversService,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey, Number revision, boolean removed,
|
||||
Class<? extends T> collectionClass,
|
||||
MiddleComponentData elementComponentData) {
|
||||
super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed );
|
||||
super( enversService, versionsReader, queryGenerator, primaryKey, revision, removed );
|
||||
|
||||
this.collectionClass = collectionClass;
|
||||
this.elementComponentData = elementComponentData;
|
||||
|
|
|
@ -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<Lis
|
|||
private final MiddleComponentData indexComponentData;
|
||||
|
||||
public ListCollectionInitializor(
|
||||
AuditConfiguration verCfg,
|
||||
EnversService enversService,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey, Number revision, boolean removed,
|
||||
Object primaryKey,
|
||||
Number revision,
|
||||
boolean removed,
|
||||
MiddleComponentData elementComponentData,
|
||||
MiddleComponentData indexComponentData) {
|
||||
super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed );
|
||||
super( enversService, versionsReader, queryGenerator, primaryKey, revision, removed );
|
||||
|
||||
this.elementComponentData = elementComponentData;
|
||||
this.indexComponentData = indexComponentData;
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
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.exception.AuditException;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.query.RelationQueryGenerator;
|
||||
|
@ -45,14 +45,14 @@ public class MapCollectionInitializor<T extends Map> extends AbstractCollectionI
|
|||
private final MiddleComponentData indexComponentData;
|
||||
|
||||
public MapCollectionInitializor(
|
||||
AuditConfiguration verCfg,
|
||||
EnversService enversService,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey, Number revision, boolean removed,
|
||||
Class<? extends T> 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;
|
||||
|
|
|
@ -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<Sor
|
|||
private final Comparator comparator;
|
||||
|
||||
public SortedMapCollectionInitializor(
|
||||
AuditConfiguration verCfg,
|
||||
EnversService enversService,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey, Number revision, boolean removed,
|
||||
|
@ -50,7 +50,7 @@ public class SortedMapCollectionInitializor extends MapCollectionInitializor<Sor
|
|||
MiddleComponentData elementComponentData,
|
||||
MiddleComponentData indexComponentData, Comparator comparator) {
|
||||
super(
|
||||
verCfg,
|
||||
enversService,
|
||||
versionsReader,
|
||||
queryGenerator,
|
||||
primaryKey,
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
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.exception.AuditException;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.query.RelationQueryGenerator;
|
||||
|
@ -42,12 +42,17 @@ public class SortedSetCollectionInitializor extends BasicCollectionInitializor<S
|
|||
private final Comparator comparator;
|
||||
|
||||
public SortedSetCollectionInitializor(
|
||||
AuditConfiguration verCfg, AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator, Object primaryKey, Number revision, boolean removed,
|
||||
Class<? extends SortedSet> collectionClass, MiddleComponentData elementComponentData,
|
||||
EnversService enversService,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey,
|
||||
Number revision,
|
||||
boolean removed,
|
||||
Class<? extends SortedSet> collectionClass,
|
||||
MiddleComponentData elementComponentData,
|
||||
Comparator comparator) {
|
||||
super(
|
||||
verCfg,
|
||||
enversService,
|
||||
versionsReader,
|
||||
queryGenerator,
|
||||
primaryKey,
|
||||
|
|
|
@ -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<Number> revisions = new HashSet<Number>( 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<T> 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
|
||||
|
|
|
@ -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<Number> revisions = new HashSet<Number>( 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<String> entityNames = verCfg.getModifiedEntityNamesReader().getModifiedEntityNames( revisionInfo );
|
||||
final Set<String> entityNames = enversService.getModifiedEntityNamesReader().getModifiedEntityNames( revisionInfo );
|
||||
if ( entityNames != null ) {
|
||||
// Generate result that contains entity names and corresponding Java classes.
|
||||
final Set<Pair<String, Class>> result = new HashSet<Pair<String, Class>>();
|
||||
|
|
|
@ -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<String, Object> data, Object revision) {
|
||||
final AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg();
|
||||
final AuditEntitiesConfiguration entitiesCfg = enversService.getAuditEntitiesConfiguration();
|
||||
|
||||
final Map<String, Object> originalId = new HashMap<String, Object>();
|
||||
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<String, Object> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, Object> 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<String, Object>();
|
||||
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<String, Object> data) {
|
||||
super( sessionImplementor, entityName, verCfg, id, RevisionType.ADD );
|
||||
SessionImplementor sessionImplementor,
|
||||
String entityName,
|
||||
EnversService enversService,
|
||||
Serializable id,
|
||||
Map<String, Object> 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
|
||||
|
|
|
@ -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<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
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<String, Object> generateData(Object revisionData) {
|
||||
fillDataWithId( data, revisionData );
|
||||
final Map<String, Object> preGenerateData = new HashMap<String, Object>( 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<String, Object> data) {
|
||||
verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().mapModifiedFlagsToMapForCollectionChange(
|
||||
enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().mapModifiedFlagsToMapForCollectionChange(
|
||||
collectionPropertyName,
|
||||
data
|
||||
);
|
||||
|
|
|
@ -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<String, Object> data = new HashMap<String, Object>();
|
||||
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
|
||||
|
|
|
@ -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<String, FakeRelationChange> 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;
|
||||
|
||||
|
|
|
@ -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<String, Object>();
|
||||
changes = verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map(
|
||||
sessionImplementor, data,
|
||||
entityPersister.getPropertyNames(), newState, oldState
|
||||
this.data = new HashMap<String, Object>();
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<PersistentCollectionChangeData> 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() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 <X> List<X> collectionToList(Collection<X> collection) {
|
||||
if ( collection instanceof List ) {
|
||||
return (List<X>) collection;
|
||||
}
|
||||
else {
|
||||
List<X> list = new ArrayList<X>();
|
||||
list.addAll( collection );
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean iteratorsContentEqual(Iterator iter1, Iterator iter2) {
|
||||
while ( iter1.hasNext() && iter2.hasNext() ) {
|
||||
if ( !iter1.next().equals( iter2.next() ) ) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<AuditCriterion>();
|
||||
}
|
||||
|
||||
@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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T> implements AuditProjection {
|
|||
|
||||
// Projection on this property
|
||||
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration auditCfg) {
|
||||
return Triple.make( null, propertyNameGetter.get( auditCfg ), false );
|
||||
public Triple<String, String, Boolean> getData(EnversService enversService) {
|
||||
return Triple.make( null, propertyNameGetter.get( enversService ), false );
|
||||
}
|
||||
|
||||
// Order
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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<String> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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, ")" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue