From eb2bf6e2e7a2cec2510b91d0bee2b4629d46c01f Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 17 May 2016 08:02:53 -0500 Subject: [PATCH] HHH-10664 - Prepare Envers for 5.2 - deprecation fixes, javadoc fixes, java 8 code adoption. --- .../org/hibernate/envers/AuditReader.java | 2 +- .../CrossTypeRevisionChangesReader.java | 8 ++-- ...rackingModifiedEntitiesRevisionEntity.java | 2 +- .../AdditionalJaxbMappingProducerImpl.java | 2 +- .../envers/configuration/EnversSettings.java | 40 ++++++++-------- .../internal/AuditEntitiesConfiguration.java | 2 +- .../internal/ClassesAuditingData.java | 4 +- .../internal/EntitiesConfigurator.java | 2 +- .../internal/PersistentClassGraphDefiner.java | 2 +- .../metadata/AuditEntityNameRegister.java | 2 +- .../metadata/AuditMetadataGenerator.java | 8 ++-- .../metadata/EntityXmlMappingData.java | 2 +- .../metadata/QueryGeneratorBuilder.java | 2 +- .../metadata/reader/PropertyAuditingData.java | 2 +- ...rackingModifiedEntitiesRevisionEntity.java | 2 +- .../entities/EntitiesConfigurations.java | 23 ++++------ .../entities/EntityConfiguration.java | 2 +- .../internal/entities/EntityInstantiator.java | 3 +- .../mapper/ComponentPropertyMapper.java | 2 +- .../mapper/CompositeMapperBuilder.java | 6 +-- .../mapper/ExtendedPropertyMapper.java | 2 +- .../mapper/MultiDynamicComponentMapper.java | 15 +++--- .../entities/mapper/MultiPropertyMapper.java | 14 +++--- .../entities/mapper/SimpleMapperBuilder.java | 2 +- .../entities/mapper/SinglePropertyMapper.java | 8 ++-- .../mapper/SubclassPropertyMapper.java | 2 +- .../entities/mapper/id/EmbeddedIdMapper.java | 4 +- .../entities/mapper/id/MultipleIdMapper.java | 4 +- .../mapper/id/QueryParameterData.java | 2 +- .../entities/mapper/id/SingleIdMapper.java | 2 +- .../relation/AbstractCollectionMapper.java | 14 +++--- .../relation/BasicCollectionMapper.java | 2 +- .../mapper/relation/MapCollectionMapper.java | 2 +- .../OneToOnePrimaryKeyJoinColumnMapper.java | 5 +- .../mapper/relation/ToOneEntityLoader.java | 6 ++- .../mapper/relation/ToOneIdMapper.java | 2 +- .../AbstractDelegateSessionImplementor.java | 3 +- .../query/AbstractRelationQueryGenerator.java | 4 +- .../query/RelationQueryGenerator.java | 2 +- .../internal/reader/AuditReaderImpl.java | 21 +++++---- .../CrossTypeRevisionChangesReaderImpl.java | 17 ++++--- ...ModifiedEntitiesRevisionInfoGenerator.java | 2 +- .../RevisionInfoQueryCreator.java | 46 +++++++++++++------ .../synchronization/AuditProcess.java | 17 +++---- .../synchronization/AuditProcessManager.java | 2 +- .../synchronization/EntityChangeNotifier.java | 2 +- .../work/AbstractAuditWorkUnit.java | 2 +- .../synchronization/work/AddWorkUnit.java | 6 +-- .../work/CollectionChangeWorkUnit.java | 4 +- .../synchronization/work/DelWorkUnit.java | 2 +- .../FakeBidirectionalRelationWorkUnit.java | 10 ++-- .../synchronization/work/ModWorkUnit.java | 2 +- .../PersistentCollectionChangeWorkUnit.java | 4 +- .../envers/internal/tools/EntityTools.java | 7 +-- .../envers/internal/tools/MapProxyTool.java | 13 +++--- .../internal/tools/ReflectionTools.java | 10 ++-- .../envers/internal/tools/StringTools.java | 2 +- .../envers/internal/tools/Tools.java | 12 ++--- .../envers/internal/tools/Triple.java | 2 +- .../tools/graph/GraphTopologicalSort.java | 6 +-- .../internal/tools/graph/TopologicalSort.java | 2 +- .../envers/internal/tools/graph/Vertex.java | 2 +- .../internal/tools/query/Parameters.java | 16 +++---- .../internal/tools/query/QueryBuilder.java | 24 +++++----- .../internal/tools/query/UpdateBuilder.java | 6 +-- .../hibernate/envers/query/AuditEntity.java | 8 ++-- .../criteria/AggregatedAuditExpression.java | 4 +- .../query/criteria/AuditConjunction.java | 2 +- .../query/criteria/AuditDisjunction.java | 2 +- .../query/criteria/ExtendableCriterion.java | 2 +- .../criteria/internal/CriteriaTools.java | 6 +-- .../internal/impl/AbstractAuditQuery.java | 13 +++--- .../impl/AuditAssociationQueryImpl.java | 8 ++-- .../impl/EntitiesAtRevisionQuery.java | 6 +-- .../impl/EntitiesModifiedAtRevisionQuery.java | 2 +- .../internal/property/PropertyNameGetter.java | 2 +- .../strategy/ValidityAuditStrategy.java | 12 ++--- .../java/org/hibernate/envers/tools/Pair.java | 2 +- 78 files changed, 271 insertions(+), 250 deletions(-) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java index 4d9bc74b7d..3a2778adb2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java @@ -280,5 +280,5 @@ public interface AuditReader { * marked with {@link ModifiedEntityNames} interface. * */ - public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException; + CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/CrossTypeRevisionChangesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/CrossTypeRevisionChangesReader.java index 99e4c469c4..4870eaf7cd 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/CrossTypeRevisionChangesReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/CrossTypeRevisionChangesReader.java @@ -31,7 +31,7 @@ public interface CrossTypeRevisionChangesReader { * @throws IllegalStateException If the associated entity manager is closed. * @throws IllegalArgumentException If a revision number is null, less or equal to 0. */ - public List findEntities(Number revision) throws IllegalStateException, IllegalArgumentException; + List findEntities(Number revision) throws IllegalStateException, IllegalArgumentException; /** * Find all entities changed (added, updated or removed) in a given revision. Executes n+1 SQL queries, @@ -45,7 +45,7 @@ public interface CrossTypeRevisionChangesReader { * @throws IllegalStateException If the associated entity manager is closed. * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. */ - public List findEntities(Number revision, RevisionType revisionType) throws IllegalStateException, + List findEntities(Number revision, RevisionType revisionType) throws IllegalStateException, IllegalArgumentException; /** @@ -63,7 +63,7 @@ public interface CrossTypeRevisionChangesReader { * @throws IllegalStateException If the associated entity manager is closed. * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. */ - public Map> findEntitiesGroupByRevisionType(Number revision) + Map> findEntitiesGroupByRevisionType(Number revision) throws IllegalStateException, IllegalArgumentException; @@ -77,6 +77,6 @@ public interface CrossTypeRevisionChangesReader { * @throws IllegalStateException If the associated entity manager is closed. * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. */ - public Set> findEntityTypes(Number revision) + Set> findEntityTypes(Number revision) throws IllegalStateException, IllegalArgumentException; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java index 28d6f8d514..8a57b17eaa 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java @@ -32,7 +32,7 @@ public class DefaultTrackingModifiedEntitiesRevisionEntity extends DefaultRevisi @Column(name = "ENTITYNAME") @Fetch(FetchMode.JOIN) @ModifiedEntityNames - private Set modifiedEntityNames = new HashSet(); + private Set modifiedEntityNames = new HashSet<>(); public Set getModifiedEntityNames() { return modifiedEntityNames; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java index 380efab845..8378b99c30 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java @@ -57,7 +57,7 @@ public class AdditionalJaxbMappingProducerImpl implements AdditionalJaxbMappingP return Collections.emptyList(); } - final ArrayList additionalMappingDocuments = new ArrayList(); + final ArrayList additionalMappingDocuments = new ArrayList<>(); // atm we do not have distinct origin info for envers final Origin origin = new Origin( SourceType.OTHER, "envers" ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/EnversSettings.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/EnversSettings.java index 6cff3fcf87..fa6cb3c55c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/EnversSettings.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/EnversSettings.java @@ -15,103 +15,103 @@ public interface EnversSettings { /** * Triggers revision generation when not-owned relation field changes. Defaults to {@code true}. */ - public static final String REVISION_ON_COLLECTION_CHANGE = "org.hibernate.envers.revision_on_collection_change"; + String REVISION_ON_COLLECTION_CHANGE = "org.hibernate.envers.revision_on_collection_change"; /** * Treats optimistic locking properties as unversioned. Defaults to {@code true}. */ - public static final String DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD = "org.hibernate.envers.do_not_audit_optimistic_locking_field"; + String DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD = "org.hibernate.envers.do_not_audit_optimistic_locking_field"; /** * Indicates whether entity data should be stored during removal. Defaults to {@code false}. */ - public static final String STORE_DATA_AT_DELETE = "org.hibernate.envers.store_data_at_delete"; + String STORE_DATA_AT_DELETE = "org.hibernate.envers.store_data_at_delete"; /** * Default name of the schema containing audit tables. */ - public static final String DEFAULT_SCHEMA = "org.hibernate.envers.default_schema"; + String DEFAULT_SCHEMA = "org.hibernate.envers.default_schema"; /** * Default name of the catalog containing audit tables. */ - public static final String DEFAULT_CATALOG = "org.hibernate.envers.default_catalog"; + String DEFAULT_CATALOG = "org.hibernate.envers.default_catalog"; /** * Track entity names that have been changed during each revision. Defaults to {@code false}. */ - public static final String TRACK_ENTITIES_CHANGED_IN_REVISION = "org.hibernate.envers.track_entities_changed_in_revision"; + String TRACK_ENTITIES_CHANGED_IN_REVISION = "org.hibernate.envers.track_entities_changed_in_revision"; /** * Use revision entity with native identifier generator. Defaults to {@code true} for backward compatibility. */ - public static final String USE_REVISION_ENTITY_WITH_NATIVE_ID = "org.hibernate.envers.use_revision_entity_with_native_id"; + String USE_REVISION_ENTITY_WITH_NATIVE_ID = "org.hibernate.envers.use_revision_entity_with_native_id"; /** * Globally activates modified properties flag feature. Defaults to {@code false}. */ - public static final String GLOBAL_WITH_MODIFIED_FLAG = "org.hibernate.envers.global_with_modified_flag"; + String GLOBAL_WITH_MODIFIED_FLAG = "org.hibernate.envers.global_with_modified_flag"; /** * Suffix of modified flag columns. Defaults to {@literal _MOD}. */ - public static final String MODIFIED_FLAG_SUFFIX = "org.hibernate.envers.modified_flag_suffix"; + String MODIFIED_FLAG_SUFFIX = "org.hibernate.envers.modified_flag_suffix"; /** * Fully qualified class name of user defined revision listener. */ - public static final String REVISION_LISTENER = "org.hibernate.envers.revision_listener"; + String REVISION_LISTENER = "org.hibernate.envers.revision_listener"; /** * Audit table prefix. Empty by default. */ - public static final String AUDIT_TABLE_PREFIX = "org.hibernate.envers.audit_table_prefix"; + String AUDIT_TABLE_PREFIX = "org.hibernate.envers.audit_table_prefix"; /** * Audit table suffix. Defaults to {@literal _AUD}. */ - public static final String AUDIT_TABLE_SUFFIX = "org.hibernate.envers.audit_table_suffix"; + String AUDIT_TABLE_SUFFIX = "org.hibernate.envers.audit_table_suffix"; /** * Audit strategy. Defaults to {@link org.hibernate.envers.strategy.DefaultAuditStrategy}. */ - public static final String AUDIT_STRATEGY = "org.hibernate.envers.audit_strategy"; + String AUDIT_STRATEGY = "org.hibernate.envers.audit_strategy"; /** * Revision field name. Defaults to {@literal REV}. */ - public static final String REVISION_FIELD_NAME = "org.hibernate.envers.revision_field_name"; + String REVISION_FIELD_NAME = "org.hibernate.envers.revision_field_name"; /** * Revision type field name. Defaults to {@literal REVTYPE}. */ - public static final String REVISION_TYPE_FIELD_NAME = "org.hibernate.envers.revision_type_field_name"; + String REVISION_TYPE_FIELD_NAME = "org.hibernate.envers.revision_type_field_name"; /** * Column name that will hold the end revision number in audit entities. Defaults to {@literal REVEND}. */ - public static final String AUDIT_STRATEGY_VALIDITY_END_REV_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_end_rev_field_name"; + String AUDIT_STRATEGY_VALIDITY_END_REV_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_end_rev_field_name"; /** * Store the timestamp of the end revision, until which the data was valid, * in addition to the end revision itself. Defaults to {@code false}. */ - public static final String AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP = "org.hibernate.envers.audit_strategy_validity_store_revend_timestamp"; + String AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP = "org.hibernate.envers.audit_strategy_validity_store_revend_timestamp"; /** * Column name of the timestamp of the end revision until which the data was valid. * Defaults to {@literal REVEND_TSTMP}. */ - public static final String AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name"; + String AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name"; /** * Name of column used for storing ordinal of the change in sets of embeddable elements. Defaults to {@literal SETORDINAL}. */ - public static final String EMBEDDABLE_SET_ORDINAL_FIELD_NAME = "org.hibernate.envers.embeddable_set_ordinal_field_name"; + String EMBEDDABLE_SET_ORDINAL_FIELD_NAME = "org.hibernate.envers.embeddable_set_ordinal_field_name"; /** * Guarantees proper validity audit strategy behavior when application reuses identifiers of deleted entities. * Exactly one row with {@code null} end date exists for each identifier. */ - public static final String ALLOW_IDENTIFIER_REUSE = "org.hibernate.envers.allow_identifier_reuse"; + String ALLOW_IDENTIFIER_REUSE = "org.hibernate.envers.allow_identifier_reuse"; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AuditEntitiesConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AuditEntitiesConfiguration.java index f5439e8026..18e3c94f5e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AuditEntitiesConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/AuditEntitiesConfiguration.java @@ -83,7 +83,7 @@ public class AuditEntitiesConfiguration { revisionEndTimestampFieldName = null; } - customAuditTablesNames = new HashMap(); + customAuditTablesNames = new HashMap<>(); revisionNumberPath = originalIdPropName + "." + revisionFieldName + ".id"; revisionPropBasePath = originalIdPropName + "." + revisionFieldName + "."; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/ClassesAuditingData.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/ClassesAuditingData.java index c31cf99024..7b7b7cd965 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/ClassesAuditingData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/ClassesAuditingData.java @@ -31,8 +31,8 @@ public class ClassesAuditingData { ClassesAuditingData.class.getName() ); - private final Map entityNameToAuditingData = new HashMap(); - private final Map persistentClassToAuditingData = new LinkedHashMap(); + private final Map entityNameToAuditingData = new HashMap<>(); + private final Map persistentClassToAuditingData = new LinkedHashMap<>(); /** * Stores information about auditing meta-data for the given class. diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntitiesConfigurator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntitiesConfigurator.java index fbc0b8aafd..e6ffc56138 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntitiesConfigurator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/EntitiesConfigurator.java @@ -51,7 +51,7 @@ public class EntitiesConfigurator { .iterator(); final ClassesAuditingData classesAuditingData = new ClassesAuditingData(); - final Map xmlMappings = new HashMap(); + final Map xmlMappings = new HashMap<>(); // Reading metadata from annotations while ( classes.hasNext() ) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java index a8a7b3a5ec..7e0f65cc54 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java @@ -50,7 +50,7 @@ public class PersistentClassGraphDefiner implements GraphDefiner getNeighbours(PersistentClass pc) { - final List neighbours = new ArrayList(); + final List neighbours = new ArrayList<>(); addNeighbours( neighbours, (Iterator) pc.getSubclassIterator() ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditEntityNameRegister.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditEntityNameRegister.java index a4f13acbe2..d16564b544 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditEntityNameRegister.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditEntityNameRegister.java @@ -17,7 +17,7 @@ import org.hibernate.MappingException; * @author Adam Warski (adam at warski dot org) */ public class AuditEntityNameRegister { - private final Set auditEntityNames = new HashSet(); + private final Set auditEntityNames = new HashSet<>(); /** * @param auditEntityName Name of the audit entity. diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditMetadataGenerator.java index 32e442fa99..e50ada4308 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditMetadataGenerator.java @@ -113,9 +113,9 @@ public final class AuditMetadataGenerator { this.auditEntityNameRegister = auditEntityNameRegister; - entitiesConfigurations = new HashMap(); - notAuditedEntitiesConfigurations = new HashMap(); - entitiesJoins = new HashMap>(); + entitiesConfigurations = new HashMap<>(); + notAuditedEntitiesConfigurations = new HashMap<>(); + entitiesJoins = new HashMap<>(); classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); } @@ -439,7 +439,7 @@ public final class AuditMetadataGenerator { @SuppressWarnings({"unchecked"}) private void createJoins(PersistentClass pc, Element parent, ClassAuditingData auditingData) { final Iterator joins = pc.getJoinIterator(); - final Map joinElements = new HashMap(); + final Map joinElements = new HashMap<>(); entitiesJoins.put( pc.getEntityName(), joinElements ); while ( joins.hasNext() ) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/EntityXmlMappingData.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/EntityXmlMappingData.java index bb78bd877e..de39b83a13 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/EntityXmlMappingData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/EntityXmlMappingData.java @@ -27,7 +27,7 @@ public class EntityXmlMappingData { public EntityXmlMappingData() { mainXmlMapping = DocumentHelper.createDocument(); - additionalXmlMappings = new ArrayList(); + additionalXmlMappings = new ArrayList<>(); } public Document getMainXmlMapping() { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/QueryGeneratorBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/QueryGeneratorBuilder.java index 50f444d92d..740511fd60 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/QueryGeneratorBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/QueryGeneratorBuilder.java @@ -50,7 +50,7 @@ public final class QueryGeneratorBuilder { this.auditMiddleEntityName = auditMiddleEntityName; this.revisionTypeInId = revisionTypeInId; - idDatas = new ArrayList(); + idDatas = new ArrayList<>(); } void addRelation(MiddleIdData idData) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PropertyAuditingData.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PropertyAuditingData.java index 487c72fe86..274efede00 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PropertyAuditingData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PropertyAuditingData.java @@ -27,7 +27,7 @@ public class PropertyAuditingData { private String mapKey; private AuditJoinTable joinTable; private String accessType; - private final List auditJoinTableOverrides = new ArrayList( 0 ); + private final List auditJoinTableOverrides = new ArrayList<>( 0 ); private RelationTargetAuditMode relationTargetAuditMode; private String auditMappedBy; private String relationMappedBy; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdTrackingModifiedEntitiesRevisionEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdTrackingModifiedEntitiesRevisionEntity.java index df375db413..889fb59b03 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdTrackingModifiedEntitiesRevisionEntity.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdTrackingModifiedEntitiesRevisionEntity.java @@ -33,7 +33,7 @@ public class SequenceIdTrackingModifiedEntitiesRevisionEntity extends SequenceId @Column(name = "ENTITYNAME") @Fetch(FetchMode.JOIN) @ModifiedEntityNames - private Set modifiedEntityNames = new HashSet(); + private Set modifiedEntityNames = new HashSet<>(); @SuppressWarnings("UnusedDeclaration") public Set getModifiedEntityNames() { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntitiesConfigurations.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntitiesConfigurations.java index 683e3826cb..98305a3924 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntitiesConfigurations.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntitiesConfigurations.java @@ -25,7 +25,7 @@ public class EntitiesConfigurations { private Map notAuditedEntitiesConfigurations; // Map versions entity name -> entity name - private Map entityNamesForVersionsEntityNames = new HashMap(); + private Map entityNamesForVersionsEntityNames = new HashMap<>(); public EntitiesConfigurations( Map entitiesConfigurations, @@ -38,20 +38,17 @@ public class EntitiesConfigurations { } private void generateVersionsEntityToEntityNames() { - entityNamesForVersionsEntityNames = new HashMap(); - - for ( String entityName : entitiesConfigurations.keySet() ) { - entityNamesForVersionsEntityNames.put( - entitiesConfigurations.get( entityName ).getVersionsEntityName(), - entityName - ); + entityNamesForVersionsEntityNames = new HashMap<>(); + for ( Map.Entry entry : entitiesConfigurations.entrySet() ) { + entityNamesForVersionsEntityNames.put( entry.getValue().getVersionsEntityName(), entry.getKey() ); } } private void generateBidirectionRelationInfo() { // Checking each relation if it is bidirectional. If so, storing that information. - for ( String entityName : entitiesConfigurations.keySet() ) { - final EntityConfiguration entCfg = entitiesConfigurations.get( entityName ); + for ( Map.Entry entry : entitiesConfigurations.entrySet() ) { + final String entityName = entry.getKey(); + final EntityConfiguration entCfg = entry.getValue(); // Iterating over all relations from that entity for ( RelationDescription relDesc : entCfg.getRelationsIterator() ) { // If this is an "owned" relation, checking the related entity, if it has a relation that has @@ -116,7 +113,7 @@ public class EntitiesConfigurations { private Collection getRelationDescriptions(String entityName) { final EntityConfiguration entCfg = entitiesConfigurations.get( entityName ); - Collection descriptions = new ArrayList(); + Collection descriptions = new ArrayList<>(); if ( entCfg.getParentEntityName() != null ) { // collect descriptions from super classes descriptions.addAll( getRelationDescriptions( entCfg.getParentEntityName() ) ); @@ -137,14 +134,14 @@ public class EntitiesConfigurations { } private Set getEntityAndParentsNames(String entityName) { - final Set names = new HashSet(); + final Set names = new HashSet<>(); addWithParentEntityNames( entityName, names ); return names; } public Set getToPropertyNames(String fromEntityName, String fromPropertyName, String toEntityName) { final Set entityAndParentsNames = getEntityAndParentsNames( fromEntityName ); - final Set toPropertyNames = new HashSet(); + final Set toPropertyNames = new HashSet<>(); for ( RelationDescription relationDescription : getRelationDescriptions( toEntityName ) ) { final String relToEntityName = relationDescription.getToEntityName(); final String mappedByPropertyName = relationDescription.getMappedByPropertyName(); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityConfiguration.java index 7eb9f3d300..76abc67264 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityConfiguration.java @@ -41,7 +41,7 @@ public class EntityConfiguration { this.propertyMapper = propertyMapper; this.parentEntityName = parentEntityName; - this.relations = new HashMap(); + this.relations = new HashMap<>(); } public void addToOneRelation( diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java index cc5c0995d5..06d1c25c04 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java @@ -145,7 +145,8 @@ public class EntityInstantiator { key, versionsReader.getSessionImplementor() .getFactory() - .getEntityPersister( entityName ) + .getMetamodel() + .entityPersister( entityName ) .createProxy( entityId, delegate ) ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java index 75cf80a831..512c7b5579 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java @@ -77,7 +77,7 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB if ( propertyData.isUsingModifiedFlag() ) { data.put( propertyData.getModifiedFlagPropertyName(), - delegate.mapToMapFromEntity( session, new HashMap(), newObj, oldObj ) + delegate.mapToMapFromEntity( session, new HashMap<>(), newObj, oldObj ) ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/CompositeMapperBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/CompositeMapperBuilder.java index 88f5158d85..34a3ef9e2f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/CompositeMapperBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/CompositeMapperBuilder.java @@ -14,9 +14,9 @@ import org.hibernate.envers.internal.entities.PropertyData; * @author Adam Warski (adam at warski dot org) */ public interface CompositeMapperBuilder extends SimpleMapperBuilder { - public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass); + CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass); - public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper); + void addComposite(PropertyData propertyData, PropertyMapper propertyMapper); - public Map getProperties(); + Map getProperties(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ExtendedPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ExtendedPropertyMapper.java index 97d630d39c..be32b4e7e8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ExtendedPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ExtendedPropertyMapper.java @@ -14,7 +14,7 @@ import org.hibernate.engine.spi.SessionImplementor; * @author Adam Warski (adam at warski dot org) */ public interface ExtendedPropertyMapper extends PropertyMapper, CompositeMapperBuilder { - public boolean map( + boolean map( SessionImplementor session, Map data, String[] propertyNames, diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiDynamicComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiDynamicComponentMapper.java index a9c91b5734..c6067a2229 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiDynamicComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiDynamicComponentMapper.java @@ -35,14 +35,16 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper { Object newObj, Object oldObj) { boolean ret = false; - for ( PropertyData propertyData : properties.keySet() ) { + for ( Map.Entry entry : properties.entrySet() ) { + final PropertyData propertyData = entry.getKey(); + final PropertyMapper propertyMapper = entry.getValue(); if ( newObj == null && oldObj == null ) { return false; } Object newValue = newObj == null ? null : getValue( newObj, propertyData ); Object oldValue = oldObj == null ? null : getValue( oldObj, propertyData ); - ret |= properties.get( propertyData ).mapToMapFromEntity( session, data, newValue, oldValue ); + ret |= propertyMapper.mapToMapFromEntity( session, data, newValue, oldValue ); } return ret; @@ -81,13 +83,15 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper { Map data, Object newObj, Object oldObj) { - for ( PropertyData propertyData : properties.keySet() ) { + for ( Map.Entry entry : properties.entrySet() ) { + final PropertyData propertyData = entry.getKey(); + final PropertyMapper propertyMapper = entry.getValue(); if ( newObj == null && oldObj == null ) { return; } Object newValue = newObj == null ? null : getValue( newObj, propertyData ); Object oldValue = oldObj == null ? null : getValue( oldObj, propertyData ); - properties.get( propertyData ).mapModifiedFlagsToMapFromEntity( session, data, newValue, oldValue ); + propertyMapper.mapModifiedFlagsToMapFromEntity( session, data, newValue, oldValue ); } } @@ -106,8 +110,7 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper { properties.keySet(), enversService.getClassLoaderService() ); - for ( PropertyData propertyData : properties.keySet() ) { - PropertyMapper mapper = properties.get( propertyData ); + for ( PropertyMapper mapper : properties.values() ) { mapper.mapToEntityFromMap( enversService, mapProxy, data, primaryKey, versionsReader, revision ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java index d487935189..f58bf1051c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java @@ -99,7 +99,9 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper { Object newObj, Object oldObj) { boolean ret = false; - for ( PropertyData propertyData : properties.keySet() ) { + for ( Map.Entry entry : properties.entrySet() ) { + final PropertyData propertyData = entry.getKey(); + final PropertyMapper propertyMapper = entry.getValue(); Getter getter; if ( newObj != null ) { getter = ReflectionTools.getGetter( newObj.getClass(), propertyData, session.getFactory().getServiceRegistry() ); @@ -110,8 +112,7 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper { else { return false; } - - ret |= properties.get( propertyData ).mapToMapFromEntity( + ret |= propertyMapper.mapToMapFromEntity( session, data, newObj == null ? null : getter.get( newObj ), oldObj == null ? null : getter.get( oldObj ) @@ -127,7 +128,9 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper { Map data, Object newObj, Object oldObj) { - for ( PropertyData propertyData : properties.keySet() ) { + for ( Map.Entry entry : properties.entrySet() ) { + final PropertyData propertyData = entry.getKey(); + final PropertyMapper propertyMapper = entry.getValue(); Getter getter; if ( newObj != null ) { getter = ReflectionTools.getGetter( newObj.getClass(), propertyData, session.getFactory().getServiceRegistry() ); @@ -138,8 +141,7 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper { else { return; } - - properties.get( propertyData ).mapModifiedFlagsToMapFromEntity( + propertyMapper.mapModifiedFlagsToMapFromEntity( session, data, newObj == null ? null : getter.get( newObj ), oldObj == null ? null : getter.get( oldObj ) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SimpleMapperBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SimpleMapperBuilder.java index 6769b03682..842f974043 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SimpleMapperBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SimpleMapperBuilder.java @@ -12,5 +12,5 @@ import org.hibernate.envers.internal.entities.PropertyData; * @author Adam Warski (adam at warski dot org) */ public interface SimpleMapperBuilder { - public void add(PropertyData propertyData); + void add(PropertyData propertyData); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java index cba8f0e182..ed3451f01e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java @@ -20,7 +20,7 @@ import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.ReflectionTools; import org.hibernate.envers.internal.tools.StringTools; -import org.hibernate.envers.internal.tools.Tools; +import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.property.access.spi.Setter; import org.hibernate.property.access.spi.SetterFieldImpl; @@ -57,12 +57,12 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder Object oldObj) { data.put( propertyData.getName(), newObj ); boolean dbLogicallyDifferent = true; - if ( (session.getFactory() + if ( (session.getFactory().getJdbcServices() .getDialect() instanceof Oracle8iDialect) && (newObj instanceof String || oldObj instanceof String) ) { // Don't generate new revision when database replaces empty string with NULL during INSERT or UPDATE statements. dbLogicallyDifferent = !(StringTools.isEmpty( newObj ) && StringTools.isEmpty( oldObj )); } - return dbLogicallyDifferent && !Tools.objectsEqual( newObj, oldObj ); + return dbLogicallyDifferent && !EqualsHelper.areEqual( newObj, oldObj ); } @Override @@ -72,7 +72,7 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder Object newObj, Object oldObj) { if ( propertyData.isUsingModifiedFlag() ) { - data.put( propertyData.getModifiedFlagPropertyName(), !Tools.objectsEqual( newObj, oldObj ) ); + data.put( propertyData.getModifiedFlagPropertyName(), !EqualsHelper.areEqual( newObj, oldObj ) ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java index 9bd6764ec1..fb5dece6b6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java @@ -135,7 +135,7 @@ public class SubclassPropertyMapper implements ExtendedPropertyMapper { @Override public Map getProperties() { - final Map joinedProperties = new HashMap(); + final Map joinedProperties = new HashMap<>(); joinedProperties.putAll( parentMapper.getProperties() ); joinedProperties.putAll( main.getProperties() ); return joinedProperties; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java index 3429917dc6..74222148ed 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java @@ -100,10 +100,10 @@ public class EmbeddedIdMapper extends AbstractCompositeIdMapper implements Simpl @Override public List mapToQueryParametersFromId(Object obj) { - final Map data = new LinkedHashMap(); + final Map data = new LinkedHashMap<>(); mapToMapFromId( data, obj ); - final List ret = new ArrayList(); + final List ret = new ArrayList<>(); for ( Map.Entry propertyData : data.entrySet() ) { ret.add( new QueryParameterData( propertyData.getKey(), propertyData.getValue() ) ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/MultipleIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/MultipleIdMapper.java index b77a832d14..8277bf8343 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/MultipleIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/MultipleIdMapper.java @@ -81,10 +81,10 @@ public class MultipleIdMapper extends AbstractCompositeIdMapper implements Simpl @Override public List mapToQueryParametersFromId(Object obj) { - final Map data = new LinkedHashMap(); + final Map data = new LinkedHashMap<>(); mapToMapFromId( data, obj ); - final List ret = new ArrayList(); + final List ret = new ArrayList<>(); for ( Map.Entry propertyData : data.entrySet() ) { ret.add( new QueryParameterData( propertyData.getKey(), propertyData.getValue() ) ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/QueryParameterData.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/QueryParameterData.java index 1370d34026..5010c9ed88 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/QueryParameterData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/QueryParameterData.java @@ -6,8 +6,8 @@ */ package org.hibernate.envers.internal.entities.mapper.id; -import org.hibernate.Query; import org.hibernate.internal.util.compare.EqualsHelper; +import org.hibernate.query.Query; /** * @author Adam Warski (adam at warski dot org) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java index b3f321bfac..c2c48b359e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java @@ -125,7 +125,7 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu @Override public List mapToQueryParametersFromId(Object obj) { - final List ret = new ArrayList(); + final List ret = new ArrayList<>(); ret.add( new QueryParameterData( propertyData.getName(), obj ) ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java index f14afde922..5fbc758d27 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java @@ -28,7 +28,7 @@ import org.hibernate.envers.internal.entities.mapper.PropertyMapper; import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.ReflectionTools; -import org.hibernate.envers.internal.tools.Tools; +import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.property.access.spi.Setter; /** @@ -86,7 +86,7 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { * @return Map for holding identifier data. */ protected Map createIdMap(int ordinal) { - final Map idMap = new HashMap(); + final Map idMap = new HashMap<>(); if ( ordinalInId ) { idMap.put( commonCollectionMapperData.getVerEntCfg().getEmbeddableSetOrdinalPropertyName(), ordinal ); } @@ -99,7 +99,7 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { int ordinal = 0; for ( Object changedObj : changed ) { - final Map entityData = new HashMap(); + final Map entityData = new HashMap<>(); final Map originalId = createIdMap( ordinal++ ); entityData.put( commonCollectionMapperData.getVerEntCfg().getOriginalIdPropName(), originalId ); @@ -134,13 +134,13 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { return null; } - final List collectionChanges = new ArrayList(); + final List collectionChanges = new ArrayList<>(); // Comparing new and old collection content. final Collection newCollection = getNewCollectionContent( newColl ); final Collection oldCollection = getOldCollectionContent( oldColl ); - final Set added = new HashSet(); + final Set added = new HashSet<>(); if ( newColl != null ) { added.addAll( newCollection ); } @@ -152,7 +152,7 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { addCollectionChanges( session, collectionChanges, added, RevisionType.ADD, id ); - final Set deleted = new HashSet(); + final Set deleted = new HashSet<>(); if ( oldColl != null ) { deleted.addAll( oldCollection ); } @@ -186,7 +186,7 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { if ( propertyData.isUsingModifiedFlag() ) { if ( isNotPersistentCollection( newObj ) || isNotPersistentCollection( oldObj ) ) { // Compare POJOs. - data.put( propertyData.getModifiedFlagPropertyName(), !Tools.objectsEqual( newObj, oldObj ) ); + data.put( propertyData.getModifiedFlagPropertyName(), !EqualsHelper.areEqual( newObj, oldObj ) ); } else if ( isFromNullToEmptyOrFromEmptyToNull( (PersistentCollection) newObj, (Serializable) oldObj ) ) { data.put( propertyData.getModifiedFlagPropertyName(), true ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java index a35293e383..43f30dcdf6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java @@ -42,7 +42,7 @@ public class BasicCollectionMapper extends AbstractCollect Object primaryKey, Number revision, boolean removed) { - return new BasicCollectionInitializor( + return new BasicCollectionInitializor<>( enversService, versionsReader, commonCollectionMapperData.getQueryGenerator(), diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java index 174252e1e0..fa1bee0c94 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java @@ -42,7 +42,7 @@ public class MapCollectionMapper extends AbstractCollectionMapper Object primaryKey, Number revision, boolean removed) { - return new MapCollectionInitializor( + return new MapCollectionInitializor<>( enversService, versionsReader, commonCollectionMapperData.getQueryGenerator(), diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOnePrimaryKeyJoinColumnMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOnePrimaryKeyJoinColumnMapper.java index 040de7d932..ab3aed377d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOnePrimaryKeyJoinColumnMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOnePrimaryKeyJoinColumnMapper.java @@ -58,9 +58,8 @@ public class OneToOnePrimaryKeyJoinColumnMapper extends AbstractOneToOneMapper { private Object createNotAuditedEntityReference( AuditReaderImplementor versionsReader, Class entityClass, String entityName, Serializable primaryKey) { - final EntityPersister entityPersister = versionsReader.getSessionImplementor().getFactory().getEntityPersister( - entityName - ); + final EntityPersister entityPersister = versionsReader.getSessionImplementor().getFactory().getMetamodel() + .entityPersister( entityName ); if ( entityPersister.hasProxy() ) { // If possible create a proxy. Returning complete object may affect performance. return versionsReader.getSession().load( entityClass, primaryKey ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java index c3b8fd45c2..286028499b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java @@ -57,7 +57,8 @@ public final class ToOneEntityLoader { EnversService enversService) { final EntityPersister persister = versionsReader.getSessionImplementor() .getFactory() - .getEntityPersister( entityName ); + .getMetamodel() + .entityPersister( entityName ); return persister.createProxy( (Serializable) entityId, new ToOneDelegateSessionImplementor( versionsReader, entityClass, entityId, revision, removed, enversService ) @@ -78,7 +79,8 @@ public final class ToOneEntityLoader { EnversService enversService) { final EntityPersister persister = versionsReader.getSessionImplementor() .getFactory() - .getEntityPersister( entityName ); + .getMetamodel() + .entityPersister( entityName ); if ( persister.hasProxy() ) { return createProxy( versionsReader, entityClass, entityName, entityId, revision, removed, enversService ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java index d1c6d0836b..371bfbc22c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java @@ -45,7 +45,7 @@ public class ToOneIdMapper extends AbstractToOneMapper { Map data, Object newObj, Object oldObj) { - final HashMap newData = new HashMap(); + final HashMap newData = new HashMap<>(); // If this property is originally non-insertable, but made insertable because it is in a many-to-one "fake" // bi-directional relation, we always store the "old", unchaged data, to prevent storing changes made diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java index 5b59c97113..7e1fd87da5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java @@ -9,7 +9,6 @@ package org.hibernate.envers.internal.entities.mapper.relation.lazy; import java.io.Serializable; import org.hibernate.HibernateException; -import org.hibernate.Session; import org.hibernate.engine.spi.SessionDelegatorBaseImpl; import org.hibernate.engine.spi.SessionImplementor; @@ -18,7 +17,7 @@ import org.hibernate.engine.spi.SessionImplementor; */ public abstract class AbstractDelegateSessionImplementor extends SessionDelegatorBaseImpl implements SessionImplementor { public AbstractDelegateSessionImplementor(SessionImplementor delegate) { - super( delegate, (Session) delegate ); + super( delegate ); } public abstract Object doImmediateLoad(String entityName); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/AbstractRelationQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/AbstractRelationQueryGenerator.java index caf4458d6e..d4ff1d22d4 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/AbstractRelationQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/AbstractRelationQueryGenerator.java @@ -9,13 +9,13 @@ package org.hibernate.envers.internal.entities.mapper.relation.query; import java.util.Collections; import java.util.Map; -import org.hibernate.Query; import org.hibernate.envers.RevisionType; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; import org.hibernate.envers.internal.entities.mapper.id.QueryParameterData; import org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.QueryBuilder; +import org.hibernate.query.Query; import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.DEL_REVISION_TYPE_PARAMETER; import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REVISION_PARAMETER; @@ -70,7 +70,7 @@ public abstract class AbstractRelationQueryGenerator implements RelationQueryGen } protected String queryToString(QueryBuilder query) { - return queryToString( query, Collections.emptyMap() ); + return queryToString( query, Collections.emptyMap() ); } protected String queryToString(QueryBuilder query, Map queryParamValues) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/RelationQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/RelationQueryGenerator.java index 80ce308eaf..7d8eb28bc6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/RelationQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/RelationQueryGenerator.java @@ -6,8 +6,8 @@ */ package org.hibernate.envers.internal.entities.mapper.relation.query; -import org.hibernate.Query; import org.hibernate.envers.internal.reader.AuditReaderImplementor; +import org.hibernate.query.Query; /** * TODO: cleanup implementations and extract common code diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java index 4a379afe57..b27e8b2e73 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java @@ -12,9 +12,9 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; + import javax.persistence.NoResultException; -import org.hibernate.Criteria; import org.hibernate.HibernateException; import org.hibernate.NonUniqueResultException; import org.hibernate.Session; @@ -29,6 +29,7 @@ import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.query.AuditQueryCreator; import org.hibernate.event.spi.EventSource; import org.hibernate.proxy.HibernateProxy; +import org.hibernate.query.Query; import static org.hibernate.envers.internal.tools.ArgumentsTools.checkNotNull; import static org.hibernate.envers.internal.tools.ArgumentsTools.checkPositive; @@ -174,7 +175,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { checkPositive( revision, "Entity revision" ); checkSession(); - final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionDateQuery( session, revision ); + final Query query = enversService.getRevisionInfoQueryCreator().getRevisionDateQuery( session, revision ); try { final Object timestampObject = query.uniqueResult(); @@ -195,7 +196,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { checkNotNull( date, "Date of revision" ); checkSession(); - final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery( session, date ); + final Query query = enversService.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery( session, date ); try { final Number res = (Number) query.uniqueResult(); @@ -219,9 +220,9 @@ public class AuditReaderImpl implements AuditReaderImplementor { checkPositive( revision, "Entity revision" ); checkSession(); - final Set revisions = new HashSet( 1 ); + final Set revisions = new HashSet<>( 1 ); revisions.add( revision ); - final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + final Query query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); try { final T revisionData = (T) query.uniqueResult(); @@ -243,7 +244,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { throws IllegalArgumentException, IllegalStateException { revisionEntityClass = getTargetClassIfProxied( revisionEntityClass ); - final Map result = new HashMap( revisions.size() ); + final Map result = new HashMap<>( revisions.size() ); for ( Number revision : revisions ) { checkNotNull( revision, "Entity revision" ); @@ -251,13 +252,13 @@ public class AuditReaderImpl implements AuditReaderImplementor { } checkSession(); - final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + final Query query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); try { - final List revisionList = query.list(); - for ( T revision : revisionList ) { + final List revisionList = query.getResultList(); + for ( Object revision : revisionList ) { final Number revNo = enversService.getRevisionInfoNumberReader().getRevisionNumber( revision ); - result.put( revNo, revision ); + result.put( revNo, (T) revision ); } return result; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java index 79af7020f0..f1b1adc58e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java @@ -14,7 +14,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.CrossTypeRevisionChangesReader; @@ -23,6 +22,7 @@ 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; +import org.hibernate.query.Query; import static org.hibernate.envers.internal.tools.ArgumentsTools.checkNotNull; import static org.hibernate.envers.internal.tools.ArgumentsTools.checkPositive; @@ -45,7 +45,7 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan @SuppressWarnings({"unchecked"}) public List findEntities(Number revision) throws IllegalStateException, IllegalArgumentException { final Set> entityTypes = findEntityTypes( revision ); - final List result = new ArrayList(); + final List result = new ArrayList<>(); for ( Pair type : entityTypes ) { result.addAll( auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision( @@ -64,7 +64,7 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan public List findEntities(Number revision, RevisionType revisionType) throws IllegalStateException, IllegalArgumentException { final Set> entityTypes = findEntityTypes( revision ); - final List result = new ArrayList(); + final List result = new ArrayList<>(); for ( Pair type : entityTypes ) { result.addAll( auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision( @@ -83,9 +83,9 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan public Map> findEntitiesGroupByRevisionType(Number revision) throws IllegalStateException, IllegalArgumentException { final Set> entityTypes = findEntityTypes( revision ); - final Map> result = new HashMap>(); + final Map> result = new HashMap<>(); for ( RevisionType revisionType : RevisionType.values() ) { - result.put( revisionType, new ArrayList() ); + result.put( revisionType, new ArrayList<>() ); for ( Pair type : entityTypes ) { final List list = auditReaderImplementor.createQuery() .forEntitiesModifiedAtRevision( type.getSecond(), type.getFirst(), revision ) @@ -108,9 +108,9 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan final Session session = auditReaderImplementor.getSession(); final SessionImplementor sessionImplementor = auditReaderImplementor.getSessionImplementor(); - final Set revisions = new HashSet( 1 ); + final Set revisions = new HashSet<>( 1 ); revisions.add( revision ); - final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + final Query query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); final Object revisionInfo = query.uniqueResult(); if ( revisionInfo != null ) { @@ -118,13 +118,12 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan final Set entityNames = enversService.getModifiedEntityNamesReader().getModifiedEntityNames( revisionInfo ); if ( entityNames != null ) { // Generate result that contains entity names and corresponding Java classes. - final Set> result = new HashSet>(); + final Set> result = new HashSet<>(); for ( String entityName : entityNames ) { result.add( Pair.make( entityName, EntityTools.getEntityClass( sessionImplementor, - session, entityName ) ) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java index f44b91b4ab..9b7b5d9e63 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java @@ -54,7 +54,7 @@ public class DefaultTrackingModifiedEntitiesRevisionInfoGenerator extends Defaul super.entityChanged( entityClass, entityName, entityId, revisionType, revisionEntity ); Set modifiedEntityNames = (Set) modifiedEntityNamesGetter.get( revisionEntity ); if ( modifiedEntityNames == null ) { - modifiedEntityNames = new HashSet(); + modifiedEntityNames = new HashSet<>(); modifiedEntityNamesSetter.set( revisionEntity, modifiedEntityNames, null ); } modifiedEntityNames.add( entityName ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoQueryCreator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoQueryCreator.java index d688bb1308..15fe5d4748 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoQueryCreator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoQueryCreator.java @@ -9,16 +9,22 @@ package org.hibernate.envers.internal.revisioninfo; import java.util.Date; import java.util.Set; -import org.hibernate.Criteria; import org.hibernate.Session; -import org.hibernate.criterion.Projections; -import org.hibernate.criterion.Restrictions; +import org.hibernate.query.Query; /** * @author Adam Warski (adam at warski dot org) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + * @author Chris Cranford */ public class RevisionInfoQueryCreator { + private static final String REVISION_DATE_QUERY = "SELECT %s FROM %s WHERE %s = :revision"; + private static final String REVISION_DATE_QUERY_PARAMETER = "revision"; + private static final String REVISION_NUMBER_FOR_DATE_QUERY = "SELECT MAX(%s) FROM %s WHERE %s <= :date"; + private static final String REVISION_NUMBER_FOR_DATE_QUERY_PARAMETER = "date"; + private static final String REVISIONS_QUERY = "FROM %s WHERE %s IN (:revisions)"; + private static final String REVISIONS_QUERY_PARAMETER = "revisions"; + private final String revisionInfoEntityName; private final String revisionInfoIdName; private final String revisionInfoTimestampName; @@ -33,21 +39,31 @@ public class RevisionInfoQueryCreator { this.timestampAsDate = timestampAsDate; } - public Criteria getRevisionDateQuery(Session session, Number revision) { - return session.createCriteria( revisionInfoEntityName ).setProjection( - Projections.property( + public Query getRevisionDateQuery(Session session, Number revision) { + return session.createQuery( + String.format( + REVISION_DATE_QUERY, + revisionInfoTimestampName, + revisionInfoEntityName, + revisionInfoIdName + ) + ).setParameter( REVISION_DATE_QUERY_PARAMETER, revision ); + } + + public Query getRevisionNumberForDateQuery(Session session, Date date) { + return session.createQuery( + String.format( + REVISION_NUMBER_FOR_DATE_QUERY, + revisionInfoIdName, + revisionInfoEntityName, revisionInfoTimestampName ) - ) - .add( Restrictions.eq( revisionInfoIdName, revision ) ); + ).setParameter( REVISION_NUMBER_FOR_DATE_QUERY_PARAMETER, timestampAsDate ? date : date.getTime() ); } - public Criteria getRevisionNumberForDateQuery(Session session, Date date) { - return session.createCriteria( revisionInfoEntityName ).setProjection( Projections.max( revisionInfoIdName ) ) - .add( Restrictions.le( revisionInfoTimestampName, timestampAsDate ? date : date.getTime() ) ); - } - - public Criteria getRevisionsQuery(Session session, Set revisions) { - return session.createCriteria( revisionInfoEntityName ).add( Restrictions.in( revisionInfoIdName, revisions ) ); + public Query getRevisionsQuery(Session session, Set revisions) { + return session.createQuery( + String.format( REVISIONS_QUERY, revisionInfoEntityName, revisionInfoIdName ) + ).setParameter( REVISIONS_QUERY_PARAMETER, revisions ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcess.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcess.java index 82a9d15b07..52a7dc112d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcess.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcess.java @@ -10,15 +10,16 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Queue; + import javax.persistence.FlushModeType; -import org.hibernate.ConnectionReleaseMode; import org.hibernate.Session; import org.hibernate.action.spi.BeforeTransactionCompletionProcess; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.internal.revisioninfo.RevisionInfoGenerator; import org.hibernate.envers.internal.synchronization.work.AuditWorkUnit; import org.hibernate.envers.tools.Pair; +import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.jboss.logging.Logger; /** @@ -41,9 +42,9 @@ public class AuditProcess implements BeforeTransactionCompletionProcess { this.revisionInfoGenerator = revisionInfoGenerator; this.session = session; - workUnits = new LinkedList(); - undoQueue = new LinkedList(); - usedIds = new HashMap, AuditWorkUnit>(); + workUnits = new LinkedList<>(); + undoQueue = new LinkedList<>(); + usedIds = new HashMap<>(); entityChangeNotifier = new EntityChangeNotifier( revisionInfoGenerator, session ); } @@ -136,10 +137,10 @@ public class AuditProcess implements BeforeTransactionCompletionProcess { if ( FlushModeType.COMMIT.equals( session.getFlushMode() ) ) { Session temporarySession = null; try { - temporarySession = ( (Session) session ).sessionWithOptions() - .transactionContext() + temporarySession = session.sessionWithOptions() + .connection() .autoClose( false ) - .connectionReleaseMode( ConnectionReleaseMode.AFTER_TRANSACTION ) + .connectionHandlingMode( PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION ) .openSession(); executeInSession( temporarySession ); temporarySession.flush(); @@ -151,7 +152,7 @@ public class AuditProcess implements BeforeTransactionCompletionProcess { } } else { - executeInSession( (Session) session ); + executeInSession( session ); // Explicitly flushing the session, as the auto-flush may have already happened. session.flush(); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcessManager.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcessManager.java index fed261f9b9..d69520c066 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcessManager.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcessManager.java @@ -25,7 +25,7 @@ public class AuditProcessManager { private final RevisionInfoGenerator revisionInfoGenerator; public AuditProcessManager(RevisionInfoGenerator revisionInfoGenerator) { - auditProcesses = new ConcurrentHashMap(); + auditProcesses = new ConcurrentHashMap<>(); this.revisionInfoGenerator = revisionInfoGenerator; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/EntityChangeNotifier.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/EntityChangeNotifier.java index 5bae19959c..6ad492f92e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/EntityChangeNotifier.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/EntityChangeNotifier.java @@ -44,7 +44,7 @@ public class EntityChangeNotifier { // Notify about a change in collection owner entity. entityId = ( (PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) entityId ).getOwnerId(); } - final Class entityClass = EntityTools.getEntityClass( sessionImplementor, session, vwu.getEntityName() ); + final Class entityClass = EntityTools.getEntityClass( sessionImplementor, vwu.getEntityName() ); revisionInfoGenerator.entityChanged( entityClass, vwu.getEntityName(), diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java index 4f7b7ea29b..0fdfe666c0 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java @@ -49,7 +49,7 @@ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit { protected void fillDataWithId(Map data, Object revision) { final AuditEntitiesConfiguration entitiesCfg = enversService.getAuditEntitiesConfiguration(); - final Map originalId = new HashMap(); + final Map originalId = new HashMap<>(); originalId.put( entitiesCfg.getRevisionFieldName(), revision ); enversService.getEntitiesConfigurations().get( getEntityName() ).getIdMapper().mapToMapFromId( originalId, id ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java index 04b44b5d49..a4eb3aa0bb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java @@ -31,7 +31,7 @@ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit Serializable id, EntityPersister entityPersister, Object[] state) { super( sessionImplementor, entityName, enversService, id, RevisionType.ADD ); - this.data = new HashMap(); + this.data = new HashMap<>(); this.state = state; this.enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().map( sessionImplementor, @@ -51,8 +51,8 @@ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit super( sessionImplementor, entityName, enversService, id, RevisionType.ADD ); this.data = data; - final String[] propertyNames = sessionImplementor.getFactory() - .getEntityPersister( getEntityName() ) + final String[] propertyNames = sessionImplementor.getFactory().getMetamodel() + .entityPersister( getEntityName() ) .getPropertyNames(); this.state = ArraysTools.mapToArray( data, propertyNames ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java index 39504c3ecf..c9eff90e38 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java @@ -21,7 +21,7 @@ import org.hibernate.envers.boot.internal.EnversService; public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { private Object entity; private final String collectionPropertyName; - private final Map data = new HashMap(); + private final Map data = new HashMap<>(); public CollectionChangeWorkUnit( SessionImplementor session, @@ -44,7 +44,7 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A @Override public Map generateData(Object revisionData) { fillDataWithId( data, revisionData ); - final Map preGenerateData = new HashMap( data ); + final Map preGenerateData = new HashMap<>( data ); enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().mapToMapFromEntity( sessionImplementor, data, diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java index baa1858e8a..2a9731231c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java @@ -46,7 +46,7 @@ public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit @Override public Map generateData(Object revisionData) { - final Map data = new HashMap(); + final Map data = new HashMap<>(); fillDataWithId( data, revisionData ); if ( enversService.getGlobalConfiguration().isStoreDataAtDelete() ) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java index c2d10f5a3a..c99f960489 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java @@ -46,7 +46,7 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp this.nestedWorkUnit = nestedWorkUnit; // Adding the change for the relation. - fakeRelationChanges = new HashMap(); + fakeRelationChanges = new HashMap<>(); fakeRelationChanges.put( referencingPropertyName, new FakeRelationChange( owningEntity, @@ -72,7 +72,7 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp this.nestedWorkUnit = nestedWorkUnit; - fakeRelationChanges = new HashMap( original.getFakeRelationChanges() ); + fakeRelationChanges = new HashMap<>( original.getFakeRelationChanges() ); } public AuditWorkUnit getNestedWorkUnit() { @@ -92,7 +92,7 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp public Map generateData(Object revisionData) { // Generating data with the nested work unit. This data contains all data except the fake relation. // Making a defensive copy not to modify the data held by the nested work unit. - final Map nestedData = new HashMap( nestedWorkUnit.generateData( revisionData ) ); + final Map nestedData = new HashMap<>( nestedWorkUnit.generateData( revisionData ) ); // Now adding data for all fake relations. for ( FakeRelationChange fakeRelationChange : fakeRelationChanges.values() ) { @@ -129,8 +129,8 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp // Now merging the fake relation changes from both work units. final Map secondFakeRelationChanges = second.getFakeRelationChanges(); - final Map mergedFakeRelationChanges = new HashMap(); - final Set allPropertyNames = new HashSet( fakeRelationChanges.keySet() ); + final Map mergedFakeRelationChanges = new HashMap<>(); + final Set allPropertyNames = new HashSet<>( fakeRelationChanges.keySet() ); allPropertyNames.addAll( secondFakeRelationChanges.keySet() ); for ( String propertyName : allPropertyNames ) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java index 0f298aa449..41c7bc8652 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java @@ -39,7 +39,7 @@ public class ModWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit this.entityPersister = entityPersister; this.oldState = oldState; this.newState = newState; - this.data = new HashMap(); + this.data = new HashMap<>(); this.changes = enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().map( sessionImplementor, data, diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java index 7b44539bc6..b8b5c24a08 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java @@ -138,7 +138,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im // First building a map from the ids of the collection-entry-entities from the "second" collection changes, // to the PCCD objects. That way, we will be later able to check if an "original" collection change // should be added, or if it is overshadowed by a new one. - final Map newChangesIdMap = new HashMap(); + final Map newChangesIdMap = new HashMap<>(); for ( PersistentCollectionChangeData persistentCollectionChangeData : getCollectionChanges() ) { newChangesIdMap.put( getOriginalId( persistentCollectionChangeData ), @@ -147,7 +147,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im } // This will be the list with the resulting (merged) changes. - final List mergedChanges = new ArrayList(); + final List mergedChanges = new ArrayList<>(); // Including only those original changes, which are not overshadowed by new ones. for ( PersistentCollectionChangeData originalCollectionChangeData : original.getCollectionChanges() ) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java index 9dd1886a72..27befabb9b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java @@ -11,6 +11,7 @@ import org.hibernate.Session; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.proxy.HibernateProxy; @@ -22,7 +23,7 @@ public abstract class EntityTools { final Object id1 = getIdentifier( session, entityName, obj1 ); final Object id2 = getIdentifier( session, entityName, obj2 ); - return Tools.objectsEqual( id1, id2 ); + return EqualsHelper.areEqual( id1, id2 ); } public static Object getIdentifier(SessionImplementor session, String entityName, Object obj) { @@ -85,8 +86,8 @@ public abstract class EntityTools { /** * @return Java class mapped to specified entity name. */ - public static Class getEntityClass(SessionImplementor sessionImplementor, Session session, String entityName) { - final EntityPersister entityPersister = sessionImplementor.getFactory().getEntityPersister( entityName ); + public static Class getEntityClass(SessionImplementor sessionImplementor, String entityName) { + final EntityPersister entityPersister = sessionImplementor.getFactory().getMetamodel().entityPersister( entityName ); return entityPersister.getMappedClass(); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MapProxyTool.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MapProxyTool.java index 84ab73185f..f1b8174b2f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MapProxyTool.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MapProxyTool.java @@ -36,16 +36,15 @@ public final class MapProxyTool { } /** + * Creates instance of map proxy class. This proxy class will be a java bean with properties from propertyDatas. + * Instance will proxy calls to instance of the map passed as parameter. + * * @param className Name of the class to construct (should be unique within class loader) * @param map instance that will be proxied by java bean * @param propertyDatas properties that should java bean declare - * @param classLoaderService + * @param classLoaderService class loader service * * @return new instance of proxy - * - * @author Lukasz Zuchowski (author at zuchos dot com) - * Creates instance of map proxy class. This proxy class will be a java bean with properties from propertyDatas. - * Instance will proxy calls to instance of the map passed as parameter. */ public static Object newInstanceOfBeanProxyForMap( String className, @@ -66,7 +65,7 @@ public final class MapProxyTool { } private static Map> prepareProperties(Set propertyDatas) { - Map> properties = new HashMap>(); + Map> properties = new HashMap<>(); for ( PropertyData propertyData : propertyDatas ) { properties.put( propertyData.getBeanName(), Object.class ); } @@ -88,7 +87,7 @@ public final class MapProxyTool { * * @param className name of the class that will be generated/loaded * @param properties list of properties that should be exposed via java bean - * @param classLoaderService + * @param classLoaderService class loader service * * @return proxy class that wraps map into java bean */ diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java index 82219da0b9..72c6bd7d4a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java @@ -26,15 +26,15 @@ import org.hibernate.service.ServiceRegistry; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public abstract class ReflectionTools { - private static final Map, Getter> GETTER_CACHE = new ConcurrentReferenceHashMap, Getter>( + private static final Map, Getter> GETTER_CACHE = new ConcurrentReferenceHashMap<>( 10, ConcurrentReferenceHashMap.ReferenceType.SOFT, ConcurrentReferenceHashMap.ReferenceType.SOFT ); - private static final Map, Setter> SETTER_CACHE = new ConcurrentReferenceHashMap, Setter>( - 10, - ConcurrentReferenceHashMap.ReferenceType.SOFT, - ConcurrentReferenceHashMap.ReferenceType.SOFT + private static final Map, Setter> SETTER_CACHE = new ConcurrentReferenceHashMap<>( + 10, + ConcurrentReferenceHashMap.ReferenceType.SOFT, + ConcurrentReferenceHashMap.ReferenceType.SOFT ); private static PropertyAccessStrategy getAccessStrategy(Class cls, ServiceRegistry serviceRegistry, String accessorType) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java index fed73fa9a5..621a44ddb8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java @@ -63,7 +63,7 @@ public abstract class StringTools { /** * Capitalizes first letter of the string * - * @param fieldName + * @param fieldName field name * * @return capitalized string */ diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java index 5d2949e42a..e603e3b328 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java @@ -27,15 +27,15 @@ import org.hibernate.internal.util.compare.EqualsHelper; */ public abstract class Tools { public static Map newHashMap() { - return new HashMap(); + return new HashMap<>(); } public static Set newHashSet() { - return new HashSet(); + return new HashSet<>(); } public static Map newLinkedHashMap() { - return new LinkedHashMap(); + return new LinkedHashMap<>(); } /** @@ -49,7 +49,7 @@ public abstract class Tools { } public static List iteratorToList(Iterator iter) { - final List ret = new ArrayList(); + final List ret = new ArrayList<>(); while ( iter.hasNext() ) { ret.add( iter.next() ); } @@ -62,7 +62,7 @@ public abstract class Tools { return (List) collection; } else { - List list = new ArrayList(); + List list = new ArrayList<>(); list.addAll( collection ); return list; } @@ -91,7 +91,7 @@ public abstract class Tools { * @return A list of pairs: ((0, element_at_index_0), (1, element_at_index_1), ...) */ public static List> listToIndexElementPairList(List list) { - final List> ret = new ArrayList>(); + final List> ret = new ArrayList<>(); final Iterator listIter = list.iterator(); for ( int i = 0; i < list.size(); i++ ) { ret.add( Pair.make( i, listIter.next() ) ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Triple.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Triple.java index 8cbc794362..94365839a7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Triple.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Triple.java @@ -65,6 +65,6 @@ public class Triple { } public static Triple make(T1 obj1, T2 obj2, T3 obj3) { - return new Triple( obj1, obj2, obj3 ); + return new Triple<>( obj1, obj2, obj3 ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphTopologicalSort.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphTopologicalSort.java index 82441b70cc..6e148e05bb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphTopologicalSort.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphTopologicalSort.java @@ -27,12 +27,12 @@ public final class GraphTopologicalSort { */ public static List sort(GraphDefiner definer) { final List values = definer.getValues(); - final Map> vertices = new HashMap>(); + final Map> vertices = new HashMap<>(); // Creating a vertex for each representation for ( V v : values ) { final R rep = definer.getRepresentation( v ); - vertices.put( rep, new Vertex( rep ) ); + vertices.put( rep, new Vertex<>( rep ) ); } // Connecting neighbourhooding vertices @@ -47,7 +47,7 @@ public final class GraphTopologicalSort { final List sortedReps = new TopologicalSort().sort( vertices.values() ); // Transforming the sorted representations to sorted values - final List sortedValues = new ArrayList( sortedReps.size() ); + final List sortedValues = new ArrayList<>( sortedReps.size() ); for ( R rep : sortedReps ) { sortedValues.add( definer.getValue( rep ) ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/TopologicalSort.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/TopologicalSort.java index 2e345efab8..1af56681fa 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/TopologicalSort.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/TopologicalSort.java @@ -38,7 +38,7 @@ public class TopologicalSort { } public List sort(Collection> vertices) { - sorted = new ArrayList( vertices.size() ); + sorted = new ArrayList<>( vertices.size() ); time = 1; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/Vertex.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/Vertex.java index 71ef444757..633e2d751d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/Vertex.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/Vertex.java @@ -23,7 +23,7 @@ public class Vertex { public Vertex(R representation) { this.representation = representation; - this.neighbours = new ArrayList>(); + this.neighbours = new ArrayList<>(); this.startTime = 0; this.endTime = 0; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java index 037009d86b..d1f16557c9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java @@ -58,10 +58,10 @@ public class Parameters { this.connective = connective; this.queryParamCounter = queryParamCounter; - subParameters = new ArrayList(); - negatedParameters = new ArrayList(); - expressions = new ArrayList(); - localQueryParamValues = new HashMap(); + subParameters = new ArrayList<>(); + negatedParameters = new ArrayList<>(); + expressions = new ArrayList<>(); + localQueryParamValues = new HashMap<>(); } // Only for deep copy purpose. @@ -70,16 +70,16 @@ public class Parameters { this.connective = other.connective; this.queryParamCounter = other.queryParamCounter.deepCopy(); - subParameters = new ArrayList( other.subParameters.size() ); + subParameters = new ArrayList<>( other.subParameters.size() ); for ( Parameters p : other.subParameters ) { subParameters.add( p.deepCopy() ); } - negatedParameters = new ArrayList( other.negatedParameters.size() ); + negatedParameters = new ArrayList<>( other.negatedParameters.size() ); for ( Parameters p : other.negatedParameters ) { negatedParameters.add( p.deepCopy() ); } - expressions = new ArrayList( other.expressions ); - localQueryParamValues = new HashMap( other.localQueryParamValues ); + expressions = new ArrayList<>( other.expressions ); + localQueryParamValues = new HashMap<>( other.localQueryParamValues ); } public Parameters deepCopy() { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/QueryBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/QueryBuilder.java index b010ec2673..a3777232de 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/QueryBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/QueryBuilder.java @@ -11,13 +11,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.envers.RevisionType; import org.hibernate.envers.internal.entities.RevisionTypeType; import org.hibernate.envers.internal.tools.MutableInteger; import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.envers.internal.tools.Triple; +import org.hibernate.query.Query; import org.hibernate.type.CustomType; /** @@ -41,7 +41,7 @@ public class QueryBuilder { /** * "where" parameters for this query. Each parameter element of the list for one alias from the "from" part. */ - private final List parameters = new ArrayList(); + private final List parameters = new ArrayList<>(); /** * A list of triples (from entity name, alias name, whether to select the entity). @@ -73,9 +73,9 @@ public class QueryBuilder { final Parameters rootParameters = new Parameters( alias, "and", paramCounter ); parameters.add( rootParameters ); - froms = new ArrayList>(); - orders = new ArrayList>(); - projections = new ArrayList(); + froms = new ArrayList<>(); + orders = new ArrayList<>(); + projections = new ArrayList<>(); addFrom( entityName, alias, true ); } @@ -90,9 +90,9 @@ public class QueryBuilder { this.parameters.add( params.deepCopy() ); } - froms = new ArrayList>( other.froms ); - orders = new ArrayList>( other.orders ); - projections = new ArrayList( other.projections ); + froms = new ArrayList<>( other.froms ); + orders = new ArrayList<>( other.orders ); + projections = new ArrayList<>( other.projections ); } public QueryBuilder deepCopy() { @@ -209,7 +209,7 @@ public class QueryBuilder { } private List getSelectAliasList() { - final List aliasList = new ArrayList(); + final List aliasList = new ArrayList<>(); for ( Triple from : froms ) { if ( from.getThird() ) { aliasList.add( from.getSecond() ); @@ -224,7 +224,7 @@ public class QueryBuilder { } private List getFromList() { - final List fromList = new ArrayList(); + final List fromList = new ArrayList<>(); for ( Triple from : froms ) { fromList.add( from.getFirst() + " " + from.getSecond() ); } @@ -233,7 +233,7 @@ public class QueryBuilder { } private List getOrderList() { - final List orderList = new ArrayList(); + final List orderList = new ArrayList<>(); for ( Triple order : orders ) { orderList.add( order.getFirst() + "." + order.getSecond() + " " + (order.getThird() ? "asc" : "desc") ); } @@ -243,7 +243,7 @@ public class QueryBuilder { public Query toQuery(Session session) { final StringBuilder querySb = new StringBuilder(); - final Map queryParamValues = new HashMap(); + final Map queryParamValues = new HashMap<>(); build( querySb, queryParamValues ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/UpdateBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/UpdateBuilder.java index 67dbf5d9e3..a5148cf419 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/UpdateBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/UpdateBuilder.java @@ -9,9 +9,9 @@ package org.hibernate.envers.internal.tools.query; import java.util.HashMap; import java.util.Map; -import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.envers.internal.tools.MutableInteger; +import org.hibernate.query.Query; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) @@ -32,7 +32,7 @@ public class UpdateBuilder { this.alias = alias; this.paramCounter = paramCounter; rootParameters = new Parameters( alias, "and", paramCounter ); - updates = new HashMap(); + updates = new HashMap<>(); } public Parameters getRootParameters() { @@ -68,7 +68,7 @@ public class UpdateBuilder { public Query toQuery(Session session) { final StringBuilder querySb = new StringBuilder(); - final Map queryParamValues = new HashMap(); + final Map queryParamValues = new HashMap<>(); build( querySb, queryParamValues ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java index 003d2f1d2b..ddad1a61bf 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java @@ -44,7 +44,7 @@ public class AuditEntity { * @param propertyName Name of the property. */ public static AuditProperty property(String propertyName) { - return new AuditProperty( new EntityPropertyName( propertyName ) ); + return new AuditProperty<>( new EntityPropertyName( propertyName ) ); } /** @@ -52,7 +52,7 @@ public class AuditEntity { * audited entity. */ public static AuditProperty revisionNumber() { - return new AuditProperty( new RevisionNumberPropertyName() ); + return new AuditProperty<>( new RevisionNumberPropertyName() ); } /** @@ -62,7 +62,7 @@ public class AuditEntity { * @param propertyName Name of the property. */ public static AuditProperty revisionProperty(String propertyName) { - return new AuditProperty( new RevisionPropertyPropertyName( propertyName ) ); + return new AuditProperty<>( new RevisionPropertyPropertyName( propertyName ) ); } /** @@ -70,7 +70,7 @@ public class AuditEntity { * audited entity. */ public static AuditProperty revisionType() { - return new AuditProperty( new RevisionTypePropertyName() ); + return new AuditProperty<>( new RevisionTypePropertyName() ); } /** diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java index b17d5cf5fe..b716f7568a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java @@ -30,10 +30,10 @@ public class AggregatedAuditExpression implements AuditCriterion, ExtendableCrit public AggregatedAuditExpression(PropertyNameGetter propertyNameGetter, AggregatedMode mode) { this.propertyNameGetter = propertyNameGetter; this.mode = mode; - criterions = new ArrayList(); + criterions = new ArrayList<>(); } - public static enum AggregatedMode { + public enum AggregatedMode { MAX, MIN } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java index 583d478dc3..5e36ea8145 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java @@ -21,7 +21,7 @@ public class AuditConjunction implements AuditCriterion, ExtendableCriterion { private List criterions; public AuditConjunction() { - criterions = new ArrayList(); + criterions = new ArrayList<>(); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java index bd986c27e9..e32c4944a8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java @@ -21,7 +21,7 @@ public class AuditDisjunction implements AuditCriterion, ExtendableCriterion { private List criterions; public AuditDisjunction() { - criterions = new ArrayList(); + criterions = new ArrayList<>(); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java index 9ed4957131..7547fbb619 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java @@ -11,5 +11,5 @@ package org.hibernate.envers.query.criteria; * @author Adam Warski (adam at warski dot org) */ public interface ExtendableCriterion { - public ExtendableCriterion add(AuditCriterion criterion); + ExtendableCriterion add(AuditCriterion criterion); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java index 345c8f9f22..5002ae6d2b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java @@ -81,7 +81,7 @@ public abstract class CriteriaTools { final SessionFactoryImplementor sessionFactory = versionsReader.getSessionImplementor().getFactory(); if ( AuditId.IDENTIFIER_PLACEHOLDER.equals( propertyName ) ) { - final String identifierPropertyName = sessionFactory.getEntityPersister( entityName ).getIdentifierPropertyName(); + final String identifierPropertyName = sessionFactory.getMetamodel().entityPersister( entityName ).getIdentifierPropertyName(); propertyName = enversService.getAuditEntitiesConfiguration().getOriginalIdPropName() + "." + identifierPropertyName; } else { @@ -101,12 +101,12 @@ public abstract class CriteriaTools { * @return List of property names representing entity identifier. */ private static List identifierPropertyNames(SessionFactoryImplementor sessionFactory, String entityName) { - final String identifierPropertyName = sessionFactory.getEntityPersister( entityName ).getIdentifierPropertyName(); + final String identifierPropertyName = sessionFactory.getMetamodel().entityPersister( entityName ).getIdentifierPropertyName(); if ( identifierPropertyName != null ) { // Single id. return Arrays.asList( identifierPropertyName ); } - final Type identifierType = sessionFactory.getEntityPersister( entityName ).getIdentifierType(); + final Type identifierType = sessionFactory.getMetamodel().entityPersister( entityName ).getIdentifierType(); if ( identifierType instanceof EmbeddedComponentType ) { // Multiple ids. final EmbeddedComponentType embeddedComponentType = (EmbeddedComponentType) identifierType; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java index 9424d0be83..ebcd7c9330 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; import javax.persistence.criteria.JoinType; @@ -18,7 +19,6 @@ import org.hibernate.CacheMode; import org.hibernate.FlushMode; import org.hibernate.LockMode; import org.hibernate.LockOptions; -import org.hibernate.Query; import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.internal.entities.EntityInstantiator; @@ -32,6 +32,7 @@ import org.hibernate.envers.query.criteria.internal.CriteriaTools; import org.hibernate.envers.query.order.AuditOrder; import org.hibernate.envers.query.projection.AuditProjection; import org.hibernate.envers.tools.Pair; +import org.hibernate.query.Query; import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REFERENCED_ENTITY_ALIAS; @@ -53,9 +54,9 @@ public abstract class AbstractAuditQuery implements AuditQueryImplementor { protected final EnversService enversService; protected final AuditReaderImplementor versionsReader; - protected final List> associationQueries = new ArrayList>(); - protected final Map> associationQueryMap = new HashMap>(); - protected final List> projections = new ArrayList>(); + protected final List> associationQueries = new ArrayList<>(); + protected final Map> associationQueryMap = new HashMap<>(); + protected final List> projections = new ArrayList<>(); protected AbstractAuditQuery( EnversService enversService, @@ -72,7 +73,7 @@ public abstract class AbstractAuditQuery implements AuditQueryImplementor { this.enversService = enversService; this.versionsReader = versionsReader; - criterions = new ArrayList(); + criterions = new ArrayList<>(); entityInstantiator = new EntityInstantiator( enversService, versionsReader ); entityClassName = cls.getName(); @@ -160,7 +161,7 @@ public abstract class AbstractAuditQuery implements AuditQueryImplementor { public AuditAssociationQuery traverseRelation(String associationName, JoinType joinType) { AuditAssociationQueryImpl result = associationQueryMap.get( associationName ); if (result == null) { - result = new AuditAssociationQueryImpl( enversService, versionsReader, this, qb, entityName, associationName, joinType, REFERENCED_ENTITY_ALIAS ); + result = new AuditAssociationQueryImpl<>( enversService, versionsReader, this, qb, entityName, associationName, joinType, REFERENCED_ENTITY_ALIAS ); associationQueries.add( result ); associationQueryMap.put( associationName, result ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AuditAssociationQueryImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AuditAssociationQueryImpl.java index 565ccfa6b1..5ca1f42054 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AuditAssociationQueryImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AuditAssociationQueryImpl.java @@ -51,10 +51,10 @@ public class AuditAssociationQueryImpl private final IdMapper ownerAssociationIdMapper; private final String ownerAlias; private final String alias; - private final List criterions = new ArrayList(); + private final List criterions = new ArrayList<>(); private final Parameters parameters; - private final List> associationQueries = new ArrayList>(); - private final Map>> associationQueryMap = new HashMap>>(); + private final List> associationQueries = new ArrayList<>(); + private final Map>> associationQueryMap = new HashMap<>(); private boolean hasProjections; private boolean hasOrders; @@ -104,7 +104,7 @@ public class AuditAssociationQueryImpl JoinType joinType) { AuditAssociationQueryImpl> result = associationQueryMap.get( associationName ); if ( result == null ) { - result = new AuditAssociationQueryImpl>( + result = new AuditAssociationQueryImpl<>( enversService, auditReader, this, diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java index 62477330ca..a7ff2e542e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java @@ -6,10 +6,9 @@ */ package org.hibernate.envers.query.internal.impl; -import java.util.Arrays; +import java.util.Collection; import java.util.List; -import org.hibernate.Query; import org.hibernate.envers.RevisionType; import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; @@ -17,6 +16,7 @@ import org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData; import org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.query.criteria.AuditCriterion; +import org.hibernate.query.Query; import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REFERENCED_ENTITY_ALIAS; import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REFERENCED_ENTITY_ALIAS_DEF_AUD_STR; @@ -120,7 +120,7 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { Query query = buildQuery(); // add named parameter (used for ValidityAuditStrategy and association queries) - List params = Arrays.asList( query.getNamedParameters() ); + Collection params = query.getParameterMetadata().getNamedParameterNames(); if ( params.contains( REVISION_PARAMETER ) ) { query.setParameter( REVISION_PARAMETER, revision ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java index ab54d82a06..b986a3a525 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java @@ -8,12 +8,12 @@ package org.hibernate.envers.query.internal.impl; import java.util.List; -import org.hibernate.Query; import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; import org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.query.criteria.AuditCriterion; +import org.hibernate.query.Query; /** * In comparison to {@link EntitiesAtRevisionQuery} this query returns an empty collection if an entity diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java index d7f25667df..7a68739b42 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java @@ -19,5 +19,5 @@ public interface PropertyNameGetter { * * @return Name of the property, to be used in a query. */ - public String get(EnversService enversService); + String get(EnversService enversService); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java index d2d17db8a9..9b59b90011 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java @@ -128,13 +128,13 @@ public class ValidityAuditStrategy implements AuditStrategy { updateTableName = rootAuditedEntityQueryable.getTableName(); } - final Type revisionInfoIdType = sessionImplementor.getFactory().getEntityPersister( revisionInfoEntityName ).getIdentifierType(); + final Type revisionInfoIdType = sessionImplementor.getFactory().getMetamodel().entityPersister( revisionInfoEntityName ).getIdentifierType(); final String revEndColumnName = rootAuditedEntityQueryable.toColumns( enversService.getAuditEntitiesConfiguration().getRevisionEndFieldName() )[0]; final boolean isRevisionEndTimestampEnabled = enversService.getAuditEntitiesConfiguration().isRevisionEndTimestampEnabled(); // update audit_ent set REVEND = ? [, REVEND_TSTMP = ?] where (prod_ent_id) = ? and REV <> ? and REVEND is null - final Update update = new Update( sessionImplementor.getFactory().getDialect() ).setTableName( updateTableName ); + final Update update = new Update( sessionImplementor.getFactory().getJdbcServices().getDialect() ).setTableName( updateTableName ); // set REVEND = ? update.addColumn( revEndColumnName ); // set [, REVEND_TSTMP = ?] @@ -156,7 +156,7 @@ public class ValidityAuditStrategy implements AuditStrategy { // Now lets execute the sql... final String updateSql = update.toStatementString(); - int rowCount = ( (Session) sessionImplementor ).doReturningWork( + int rowCount = sessionImplementor.doReturningWork( new ReturningWork() { @Override public Integer execute(Connection connection) throws SQLException { @@ -206,7 +206,7 @@ public class ValidityAuditStrategy implements AuditStrategy { .getJdbcCoordinator().getResultSetReturn().executeUpdate( preparedStatement ); } finally { - sessionImplementor.getJdbcCoordinator().getResourceRegistry().release( + sessionImplementor.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( preparedStatement ); sessionImplementor.getJdbcCoordinator().afterStatementExecution(); @@ -227,7 +227,7 @@ public class ValidityAuditStrategy implements AuditStrategy { } private Queryable getQueryable(String entityName, SessionImplementor sessionImplementor) { - return (Queryable) sessionImplementor.getFactory().getEntityPersister( entityName ); + return (Queryable) sessionImplementor.getFactory().getMetamodel().entityPersister( entityName ); } @Override @@ -258,7 +258,7 @@ public class ValidityAuditStrategy implements AuditStrategy { } final SessionFactoryImplementor sessionFactory = ( (SessionImplementor) session ).getFactory(); - final Type propertyType = sessionFactory.getEntityPersister( entityName ).getPropertyType( propertyName ); + final Type propertyType = sessionFactory.getMetamodel().entityPersister( entityName ).getPropertyType( propertyName ); if ( propertyType.isCollectionType() ) { CollectionType collectionPropertyType = (CollectionType) propertyType; // Handling collection of components. diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/tools/Pair.java b/hibernate-envers/src/main/java/org/hibernate/envers/tools/Pair.java index de29e0b83f..63929080ff 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/tools/Pair.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/tools/Pair.java @@ -61,6 +61,6 @@ public class Pair { } public static Pair make(T1 obj1, T2 obj2) { - return new Pair( obj1, obj2 ); + return new Pair<>( obj1, obj2 ); } }